Pandoc and LaTeX

In a previous post, I described some basic ideas how to make the PDF output of LaTeX a little bit prettier. Unfortunately, the text needs to be written in plain TeX which is cumbersome at best. But why not write Markdown and use yours truly’s favorite converter Pandoc to do the dirty job of generating TeX? The best thing with this setup: Pandoc does not process raw TeX commands and environments such as \newpage or $$ but outputs them verbatim into the final file. Thus, for most tasks you can write Markdown but if it’s necessary, you can simply add high-quality TikZ figures or plots made with PGFPlots.

To integrate the stylistic changes, I prepared a TeX template for Pandoc’s simple template engine and a Makefile. You can check out both in the current (empty) directory with

$ git clone git://gist.github.com/4194445.git .
$ rm -rf .git

Now place any Markdown files in here and make a nicely laid out PDF document.

You might have noticed the title and author variables in the template which will result in correspond \title{} and \author{} calls in the TeX document. To enter this data in your Markdown file, you have to use Pandoc’s title block extension and put it on top of your Markdown file like this:

% Multi line
  titles must begin with a leading space
% Brian Griffin
  Glenn Quagmire

Unfortunately, there are also some caveats with Pandoc:

  • Although Pandoc has a $lang$ variable to be used for the document class and babel package, the language is not detected reliably.
  • The bibliography feature is not working for me right now, because the Pandoc dependency for managing bibliographies is not available for Ubuntu 12.04.
  • The template is and cannot be very portable. For example, I assume that the TikZ package is already installed.

For me, these are only minor problems and for smaller documents such as reports I now write Markdown and convert that rather than typing the document in a word processor or as raw LaTeX.