jgm / skylighting

A Haskell syntax highlighting library with tokenizers derived from KDE syntax highlighting descriptions
194 stars 62 forks source link

Underscore within highlighted inline code in certain contexts causes problems for LaTeX output. #78

Closed mpark closed 5 years ago

mpark commented 5 years ago

pandoc 2.7.3

Given:

~~`foo_bar`{.cpp}~~

Generated LaTeX:

$ pandoc foo.md --to latex
\sout{\mbox{\VERB|\NormalTok{foo_bar}|}}

Problem generating PDF:

$ pandoc foo.md --output foo.pdf
Error producing PDF.
! Missing $ inserted.
<inserted text>
                $
l.92 \sout{\mbox{\VERB|\NormalTok{foo_bar}|}}
mpark commented 5 years ago

Also the case within title:

---
title: "`foo_bar`{.cpp}"
---

Generated LaTeX:

$ pandoc foo.md --to latex --self-contained
# ...
\title{\VERB|\NormalTok{foo_bar}|}
\date{}

\begin{document}
\maketitle

Problem generating PDF:

$ pandoc foo.md --output foo.pdf
Error producing PDF.
! Missing $ inserted.
<inserted text>
                $
l.91
mpark commented 5 years ago

In both cases, escaping the _ in the LaTeX source seems to solve the problem.

jgm commented 5 years ago

To be clear: this is not generally a problem, it just occurs when the highlighted code is embedded in strikeout or occurs in a title (perhaps other contexts as well, but in most contexts this works).

mpark commented 5 years ago

Yep, I've updated the title. It seems like verb has trouble being passed to other commands: https://truonglatex.wordpress.com/2011/07/26/stack-size-limit-error-with-hyperref/

Seems like this may have been the cause in #5574.

jgm commented 5 years ago

I'll transfer this to skylighting, since the escapes need to be added there. (I found some other missing escapes too.)