jgm/pandoc

Inserting "//" in header-includes command

vscalon opened this issue · 7 comments

The previous version of pandoc that I was using from Ubuntu 23.10 (pandoc 2.17) don't show this problem. For the new version on 24.04 ( 3.1.3), the issue is present.

Running a script with this includes:

header-includes:
    \usepackage{mathtools,graphics}
    \usepackage[top=1.5cm, bottom=2cm, left=2cm, right=2cm]{geometry}
    \DeclareMathSymbol{,}{\mathpunct}{letters}{"3B}
    \DeclareMathSymbol{.}{\mathord}{letters}{"3B}
    \DeclareMathSymbol{\decimal}{\mathord}{letters}{"3A}
    \pagestyle{empty}

The compilation fails for output as pdf or latex. In lattex version, the problem is a "\\" inclusion in line:

\usepackage{mathtools,graphics} \usepackage[top=1.5cm, bottom=2cm, left=2cm, right=2cm]{geometry}\\
\DeclareMathSymbol{,}{\mathpunct}{letters}{"3B}
\DeclareMathSymbol{.}{\mathord}{letters}{"3B}
\DeclareMathSymbol{\decimal}{\mathord}{letters}{"3A} \pagestyle{empty}

Removing the "\\", the problem is solved and there is no more problems in latex compilation process.

Not sure what's causing this, but you can avoid issues like this by marking your header-includes as raw LaTeX; otherwise it might be read as Markdown, which can have unexpected consequences.

header-includes: |
    ``` {=latex}
    \usepackage{mathtools,graphics}
    \usepackage[top=1.5cm, bottom=2cm, left=2cm, right=2cm]{geometry}
    \DeclareMathSymbol{,}{\mathpunct}{letters}{"3B}
    \DeclareMathSymbol{.}{\mathord}{letters}{"3B}
    \DeclareMathSymbol{\decimal}{\mathord}{letters}{"3A}
    \pagestyle{empty}
    ```  

Note the pipe character after header-includes. (Interestingly, just adding the pipe character is enough to fix the issue at hand.)

jgm commented

This is the right solution.

bpj commented

You could use a defaults file. Metadata and variables in them is not parsed as Markdown. Isn't it so @jgm and @tarleb?

jgm commented

You could put it in the variables section of a defaults file.
(Not in the metadata section -- for there they will not be passed through verbatim, but rendered as strings, so that the backslashes will be escaped.)

Note the pipe character after header-includes. (Interestingly, just adding the pipe character is enough to fix the issue at hand.)

Using only the pipe character as suggested by tarleb, one can fix the problem. But, this procedure is not cited in the pandoc manual.
However, it would be interesting if someone could find and fix this bug.

jgm commented

I'm quite confused about why the LineBreak is being parsed there (that's what generates the \\). The parsed YAML looks like this:

Right [Object (fromList [("header-includes",String "\\usepackage{mathtools,graphics} \\usepackage[top=1.5cm, bottom=2cm, left=2cm, right=2cm]{geometry} \\DeclareMathSymbol{,}{\\mathpunct}{letters}{\"3B} \\DeclareMathSymbol{.}{\\mathord}{letters}{\"3B} \\DeclareMathSymbol{\\decimal}{\\mathord}{letters}{\"3A} \\pagestyle{empty}")])]

There is nothing there that our markdown parser would interpret as a LineBreak...so, a mystery for now.

I think the "//" appears only in the first command line of the header, after the usepackage{} (if exists). I don't know why either. Pandoc 2.17 doesn't have this problem.