Wandmalfarbe/pandoc-latex-template

Error if there is an underscore in logo file name

wiesener opened this issue · 3 comments

If I add a logo file name with underscore it gives error:

File not found:

\T1\textunderscore

Pandoc interprets every metadata value as Markdown and converts it to the output format before inserting it in the document. Unfortunately the underscore gets converted to \_. In the template the following LaTeX is produced

\includegraphics[width=120pt, left]{logo\_underscore.pdf}

with the following error message:

Error producing PDF.
! Package pdftex.def Error: File `logo\T1\textunderscoreunderscore.pdf' not fou
nd: using draft setting.

See the pdftex.def package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.333 ...[width=120pt, left]{logo\_underscore.pdf}

This is a known and documented behaviour (see jgm/pandoc#3504 or jgm/pandoc#1685).

Raw content to include in the document’s header may be specified using header-includes; however, it is important to mark up this content as raw code for a particular output format, using the raw_attribute extension), or it will be interpreted as markdown. For example:

header-includes:
- |
```{=latex}
\let\oldsection\section
\renewcommand{\section}[1]{\clearpage\oldsection{#1}}
```

You can tell pandoc that you want to pass the metadata value to LaTeX unparsed (as raw LaTeX) so the following code should work:

logo: "`logo_underscore.pdf`{=latex}"

I am having similar issue, but in my case I am trying to add the logo in the command line using

--metadata logo="__assets__/my_logo.png"

The .tex file produced will have

    \includegraphics[width=100pt, left]{\_\_assets\_\_/my\_logo.png}

which does not work. However, if I edit the lines into

    \includegraphics[width=100pt, left]{__assets__/my_logo.png}

the .pdf is produced without errors. I saw there is a workaround when using the YAML metadata in the .md files, but how would one make it work using the command line arguments?

I am having similar issue, but in my case I am trying to add the logo in the command line using

--metadata logo="__assets__/my_logo.png"

I don't know how to pass raw latex via the --metadata option. The manual mentions the following:

But unlike --variable, --metadata affects the metadata of the underlying document (which is accessible from filters and may be printed in some output formats) and metadata values will be escaped when inserted into the template.

I think it is worth a question on pandoc-discuss or in the pandoc issue tracker.