Playing With Docbook Again

November 14, 2011

Some notes about installing DocBook tools on OS X Lion.

I used to write my documents and slides almost exclusively with $\LaTeX$ and Context. Needless to say, this means tweaking default layout a lot (who said that $\LaTeX$ allows for a perfect separation between layout and content?!), so that for small-size documents I now tend to rely on Pandoc.

Lastly, I tried to use Pandoc for outputing DocBook document which I find pretty convenient for web display. It’s been almost three years now since the latest time I wrote xml files. Pandoc is already very helpful for $\LaTeX$ (with or without the xetex backend), and I even created basic templates for writing Beamer slides in Markdown. For DocBook, I can produce a fairly decent output using xsltproc which comes with OS X. In the Makefile for a tutorial on exploratory data analysis with R, I put something like:

xsltproc --xinclude --stringparam html.stylesheet docbook-xsl.css -o eda_r.html \ eda_r.xml

It works like a charm. However, I would like to use xmlto which is built around xsltproc but handles everything in a smoother way.

Installing the pre-requisites

We need to install gettext and getopt (with support for --longoptions, contrary to the default /usr/bin/getopt that ships with OS X).

First of all, get the latest source tarball of gettext from GNU website.

To compile gettext, you have to run the classical combo:

$ ./configure
$ make
$ make check
$ sudo make install

I had to patch gettext-tools/gnulib-lib/stpncpy.c as follows:

 #ifndef weak_alias
-# define __stpncpy stpncpy
+# define __stpncpy gnu_stpncpy

Then, go forward with getopt, which is available at http:/

$ wget
$ tar xzvf getopt-1.1.4.tar.gz
$ cd getopt-1.1.4

In the Makefile, update the LDFLAGS so it reads LDFLAGS=-lintl (which is used for internationalization support in other packages). An alternative would be to type directly LDFLAGS="-lintl" make -e. Yes, that’s a bunch of external dependencies for a small program that basically acts as a wrapper around xsltproc.

Now, we can install xmlto. Before that, we need to install the Docbook stylesheets, as well as DocBook 4.2 files. This is well explained here and I follow those instructions. Basically, this means to:

This results in /etc/xml/catalog now reading like this:

$ less /etc/xml/catalog 
<?xml version="1.0"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<nextCatalog catalog="file:///usr/local/share/docbook/xsl/1.76.1/catalog.xml"/>
<nextCatalog catalog="file:///usr/local/share/docbook/xml/4.2/catalog.xml"/>
<nextCatalog catalog="file:///usr/local/share/docbook/xml/4.4/catalog.xml"/>

That’s it!

Testing the installation

I used a template (article) I found and tested xmlto by running the following command:

$ xmlto html-nochunks sample.xml

Trying pdf backend gave me some error that I need to investigate, though. However, it works well with fop.

$ xsltproc --xinclude --output \
  /usr/local/share/docbook/xsl/1.76.1/fo/docbook.xsl \
$ fop sample.pdf


There are other tools that can be installed for those interested in managing DocBook documents, especially when PDF is the expected output format. I can think of jade, but there are also dblatex and dbcontext, see DocBook to LaTeX Publishing. Apache fop works well too.

See Also

» Apple weekend miscellanies » Installing numpy+scipy on OS X Lion » Welcome OS X Lion » Compiling Gnuplot on OS X » Yet another interactive shell for numerical computing