gpoore / minted

minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.
1.74k stars 126 forks source link

Effect of multiple `gobble=<int>` accumulate, not overwrite #337

Closed muzimuzhi closed 1 month ago

muzimuzhi commented 2 years ago

The total effect of \setminted{gobble=1, gobble=2} is gobble=3, but the expected is gobble=2.

From https://tex.stackexchange.com/q/650135

Example:

\documentclass{article}
\usepackage{minted}
\parindent=0pt

\begin{document}
\subsection*{minted works wrong}

\setminted{gobble=1, gobble=2}
expected: 3456
\begin{minted}{text}
123456
\end{minted}

\subsection*{fvextra is ok}
\fvset{gobble=1, gobble=2}
expected: 3456
\begin{Verbatim}
123456
\end{Verbatim}
\end{document}

image

Currently gobble is defined by https://github.com/gpoore/minted/blob/d46f1ba2d248f2f3504bcc795dd39c613bd3c5a0/source/minted.dtx#L2662-L2664 Hence \setminted{gobble=1, gobble=2} will become pygmentize options -F gobble:n=1 -F gobble:n=2.

gpoore commented 2 years ago

I don't know if there is an easy way to fix this. The current system for working with pygmentize is based on the assumption that later options override earlier ones instead of combining. So one solution would involve a complete redesign of pygmentize option handling. Another possibility is to do gobble in LaTeX when writing the code to the temp file. That is possible, but will require special handling of UTF-8 code points for pdflatex.

I expect that there are other bugs related to pygmentize options combining rather than overriding, so even if it's possible to fix this by switching the processing to the LaTeX side, the pygmentize processing probably needs to be reimplemented anyway.

muzimuzhi commented 2 years ago

So one solution would involve a complete redesign of pygmentize option handling.

+1 to a general fix for \minted@def@optcl.

gpoore commented 1 month ago

This is fixed in minted v3.0, which is available as a beta on GitHub and will have a final release soon.