Search code examples
pandoc

pandoc error when converting markdown to pdf


Following is the minimum content and still produce the issue:

test.md

NUM | Note
---|---
002 | %9$B5#
002 | %9$B5#

Convert to PDF using pandoc:

$ pandoc test.md -o test.pdf
Error producing PDF.
! You can't use `macro parameter character #' in math mode.
l.76 002 & \%9\(B5#

VSCode, MacDown have no issue displaying it. But pandoc give error.

Is there command line option to get around this? Or other command line tools?

Version:

  • pandoc 3.1.2
  • basictex: 2023.0314

Solution

  • In pandoc's Markdown, dollar signs $ are used to mark up math formulæ, which gets in the way in your case. However, there are many Markdown versions available in pandoc, and they can be tweaked to your liking.

    It seems that you are using a fairly standard version of Markdown that does not require any of pandoc's advanced Markdown extensions, so the easiest solution would be to specify “GitHub Flavored Markdown” as input format:

    pandoc --from=gfm test.md -o test.pdf
    

    Other alternatives: plain CommonMark with the pipe_tables extension enabled (--from=commonmark+pipe_tables) or pandoc's Markdown without the tex_math_dollars extension (--from=markdown-tex_math_dollars). Or use your current command but backslash-escape the dollars characters: %9\$B5#.