Markdown to PDF using Pandoc since Xetex Deprecation

8.8k Views Asked by At

On my MacBook (OSX Mountain Lion), I used to use this Pandoc command to convert Markdown to PDF:

$ markdown2pdf -N -o pandoc_output.pdf  --xetex --toc --template=mytemplate.tex myfile.md

But markdown2pdf no longer works, and --xetex option in markdown2pdf -N -o ../../Desktop/pandoc_output.pdf --xetex --toc --template=mytemplate-headers-garamond_date.tex is deprecated.

If I do this:

$ pandoc -N -o Desktop/pandoc_output.pdf  --xetex --toc --template=mytemplate.tex myfile.md

I get this:

pandoc: unrecognized option `--xetex'

But if I take out --xetex and do this:

$ pandoc -N -o Desktop/pandoc_output.pdf  --toc --template=mytemplate.tex myfile.md

then I get this:

pandoc: Error producing PDF from TeX source.
! Package hyperref Error: Wrong driver option `xetex',
(hyperref)                because XeTeX is not detected.

See the hyperref package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.3925 \ProcessKeyvalOptions{Hyp}

What's the solution?

3

There are 3 best solutions below

1
Mohamed Ragab On BEST ANSWER

Try --pdf-engine=xelatex instead of --xetex.

Prior to Pandoc 2.0, released in 2017, this option was called --latex-engine. If you have a very old version of Pandoc (check with pandoc --version), you may need to use this option instead.

0
John MacFarlane On

See the pandoc User's Guide (or man page) for the --latex-engine option.

0
George D Girton On

The prior answers to this question were helpful to me, as I had installed pandoc a couple years ago, but never Tex Live. Consequently I had no idea if I had installed it correctly, so putting in the entire path helped me to see that it was working, as follows:

pandoc --latex-engine=/usr/local/texlive/2012basic/bin/universal-darwin/xelatex

This is the default install location for the BasicTex setup which you download from the Pandoc install page.

I had also forgotten about using pandoc -D Latex >my-latex-template.tex to generate a template. After giving a .tex template instead of my .html one (which caused a 'you don't have BEGIN {' error) , I got .PDF: In other words, the default template worked.

Also, I had inaccurately entered -t pdf (not shown above) to set pdf as an output format, but this was not correct. The output format is Latex, which is then translated to PDF. It is not necessary to specify an output format with the dash -t option.

I hope this record of my minor stumbles saves someone some time.