How to find errors after post-processing with Pandoc?

I use pandoc to post-process the markdown files that I make with Scrivener. Sometimes there will be an error and the Error Log will produce something like:

Error producing PDF.
! Missing $ inserted.
<inserted text> 
l.1582 \$\eta

Sometimes what comes after that “l.1582” be unique in my document, and I can use that to hunt down the error in the source Scrivener documents. But sometimes it won’t be, and I’d like to know whether I can use the “l.1582” tag to determine the location of the error in the markdown document that Pandoc is processing. But I can’t figure out what that “l.1582” means, or how to use the information it conveys.

I’d be grateful for any/all help! Thanks!

This has nothing to do with Pandoc, but with the LaTeX engine that is converting the .tex to .PDF

So lets make a test doc we know will fail (an unknown environment called mystery):

title: LaTeX Test
author: Jane Doe


These are the voyages of the Starship Enterprise. Its continuing mission, to explore strange new worlds, to seek out new life and new civilizations, to boldly go where no one has gone before.  

And lets compile it:

▷ pandoc -s --pdf-engine=xelatex -o test.pdf
Error producing PDF.
! Undefined control sequence.
l.59 \mystery

Exception: pandoc exited with 43

l.59 refers to the line from the .tex file source Pandoc produced from the .md file, but the error is coming from the TeX engine as it tries to make the PDF:

56. \begin{document}
57. \maketitle
59. \mystery{Hello!}
61. These are the voyages of the Starship Enterprise...

The error is telling us the control sequence is undefined (as we knew it would be).

If you want to see more details, you should pass --verbose to pandoc:

▷ pandoc --verbose -s --pdf-engine=xelatex -o test.pdf
[makePDF] temp dir:
[makePDF] Command line:
xelatex "-halt-on-error" "-interaction" "nonstopmode" "-output-directory" "/private/var/folders/bf/l6n8fnvd7zl5qsvlwgy7sk7w0000gn/T/tex2pdf.-da421d9db3324ed9" "/private/var/folders/bf/l6n8fnvd7zl5qsvlwgy7sk7w0000gn/T/tex2pdf.-da421d9db3324ed9/input.tex"
! Undefined control sequence.
l.59 \mysterious
No pages of output.
Transcript written on /private/var/folders/bf/l6n8fnvd7zl5qsvlwgy7sk7w0000gn/T/

Error producing PDF.
! Undefined control sequence.
l.59 \mysterious

The detailed log file is saved, you can also redirect the verbose output from the terminal to a log so you can examine it at your leisure later on. This is one thing scrivomatic does with the -b option (redirect all verbose output to a latex log saved alongside your main output).


Thanks so much! That helps tremendously. Now I can just compile the raw tex source file and then navigate to the line of the error to investigate. Exactly what I needed!

Just wanted to add here for folks who find this thread that one can output for investigation the temporary latex file that Pandoc works on. To do that, add this argument to your pandoc call: --pdf-engine-opt=-outdir=foo. The temp latex files will then be in foo . Found that little protip here.