October 23, 2013

Pandoc, LaTeX to PDF, and the Euro symbol

Pandoc is a terrific tool for converting text material from one format to another. I profess a little less love for LaTeX as I am less familiar with it and its secrets appear to be frustratingly arcane. If you want to get Pandoc to create a PDF with a Euro currency symbol in it then the following may save you some anguish.

Pandoc uses LaTeX to render PDF files and LaTeX can have an uneasy relationship with the Euro symbol. Here’s what I’ve learned so far; it may not be ‘correct’, but it worked.

Update your LaTeX

I’m not sure how important this was but go ahead, it can’t hurt. I’m assuming you’re using OSX and a MacTeX installation. Somewhere in /Applications/TeX you should find the TeX Live Utility, run it and let it update. (Probably a good idea to also check that your Pandoc is up to date too.)

Install the Eurosym package

I tried many different LaTeX / Pandoc invocations to try and get the utf-8 Euro symbol to ‘just work’ and failed at every turn. If you’re at the end of your tether just open a terminal and run sudo tlmgr install eurosym. This will install the Euro Symbol Package for LaTeX.

Pandoc should now render your Euro-strewn PDF without complaint. If you are using a custom template for your LaTeX, you might want to read on.

Declare your Euro intentions

Somewhere in your LaTeX template you will have to add:

$if(euro)$
  \usepackage{eurosym}
$endif$

If you want a basic, well (and amusingly) commented template use this one but remember to add the euro declaration. (You can just put \usepackage{eurosym} somewhere, but encasing it in an $if statement is better form, I gather.) Fiddling about with this template will also allow you to declare custom fonts, get rid of the page number in the footer and shrink LaTeX’s wide margins to your own taste. Just remember to pass --template=your.template.name to Pandoc when you’re convering to PDF.

Declare your XeLaTeX intentions

Make sure that your template has %!TEX TS-program = xelatex at the top. XeLaTeX seems to be a bit more worldly than plain old LaTeX and allows more exotic configurations. Or something. Similarly, if you’re running into bother with the Pandoc to PDF translation you might benefit from adding --latex-engine=xelatex to your command: it forces Pandoc’s hand.