Docbook, MathML and PDF

by Sebastien Mirolo on Fri, 8 Jun 2012

I finally decided today to convert an old Microsoft Word documents to docbook. This document contrary to previous ones I converted recently is full of mathematical formulas. I thus ended-up trying to get the docbook MathML extension to work on my system.

Using FOP, I managed to get a .fo followed by a .pdf output relatively quickly. Unfortunately where there should had been equations, there were only blanks. Trials and errors invariably lead to a blank page or one of the following two errors:

java.lang.RuntimeException: Content is not allowed in prolog.
WARNING: Unknown formatting object \
  "{http://www.w3.org/1998/Math/MathML}..." encountered

Finally I figured out I just had to install jeuclid alongside fop as such:

$ which fop
/opt/local/bin/fop
$ ls /opt/local/share/java/fop/1.0/lib/*.jar
$ cp ~/Downloads/jeuclid-fop-3.1.9/*.jar /opt/local/share/java/fop/1.0/lib/

Now when I transform the following sample docbook with mathml elements, I get the desired output.

$ cat example.book
<?xml version="1.0"?>
<section xmlns="http://docbook.org/ns/docbook" 
	 xmlns:xlink="http://www.w3.org/1999/xlink"
	 xmlns:mml="http://www.w3.org/1998/Math/MathML">
<inlineequation>
<mml:math>
<mml:mrow>
  <mml:mrow>
    <mml:mi>x</mml:mi>
    <mml:mo>+</mml:mo>
    <mml:mi>y</mml:mi>
  </mml:mrow>
  <mml:mo>=</mml:mo>
  <mml:mn>2</mml:mn>
</mml:mrow>
</mml:math>
</inlineequation>
</section>
$ xsltproc -xinclude --stringparam use.extensions 0 \
    --stringparam fop1.extensions 1 \
	--output example.fo /opt/local/share/xsl/docbook-xsl/fo/docbook.xsl \
	 example.book
$ fop -fo example.fo -pdf example.pdf

There is a very good presentation of MathML here.

by Sebastien Mirolo on Fri, 8 Jun 2012