pygments / pygments/pygments

`LatexFormatter`'s `mathescape` does not escape backslashes inside `gnuplot` comment

Open
#2,825 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.2k
Forks
885
PR merge metrics
No merged PRs in 30d

Description

LatexFormatter's mathescape does not escape backslashes inside gnuplot comment. This causes an unexpected error when compiling with LaTeX.

For example, let's consider the following gnuplot code:

# $\alpha$

pygmentize this with the following command:

python -m pygments -f latex -l gnuplot -O mathescape test.gnuplot

Expected result is:

\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
\PY{c}{\PYZsh{} $\alpha$}
\end{Verbatim}

However, actual result is:

\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
\PY{c}{\PYZsh{}}\PY{c}{ $}\PY{c}{\PYZbs{}}\PY{c}{alpha$}
\end{Verbatim}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the LatexFormatter entry point and reproduce the issue using the shown pygmentize command with the gnuplot input. Trace how mathescape handles the comment, then verify that the generated output matches the expected LaTeX and compiles without an unexpected error.

Written by the indexing model from the issue text.

Assessment

Tech stack
latex, python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.