gpoore / minted

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

escapeinside breaks when using \ref with a hypen #303

Closed lucc closed 1 year ago

lucc commented 3 years ago

If I \ref a label that contains a minus character from within minted (with escapeinside) the compilation breaks. Other labels work fine.

The mwe.tex:

\documentclass{article}
\usepackage{minted}
\begin{document}
\section{First}\label{first}
\section{Second}\label{with-hyphen}
\begin{minted}[escapeinside=||]{python}
# | see \ref{first} |
print(1)
\end{minted}
\begin{minted}[escapeinside=||]{python}
# | see \ref{with-hyphen} (remove this line to make it compile) |
print(2)
\end{minted}
\LaTeX{} can reference \ref{with-hyphen}.
\end{document}

Compile with pdflatex -shell-escape -interaction nonstopmode mwe.tex

The log
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021/NixOS.org) (preloaded format=pdflatex 2021.7.17)  27 JUL 2021 12:43
entering extended mode
 \write18 enabled.
 %&-line parsing enabled.
**mwe.tex
(./mwe.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-02-18>
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/base/size10.clo
File: size10.clo 2020/04/10 v1.4m Standard LaTeX file (size option)
)
\c@part=\count179
\c@section=\count180
\c@subsection=\count181
\c@subsubsection=\count182
\c@paragraph=\count183
\c@subparagraph=\count184
\c@figure=\count185
\c@table=\count186
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/minted/minted.sty
Package: minted 2017/07/19 v2.5 Yet another Pygments shim for LaTeX

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/graphics/keyval.sty
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks15
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/kvoptions/kvoptions.sty
Package: kvoptions 2020-10-07 v3.14 Key value format for package options (HO)

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/generic/ltxcmds/ltxcmds.sty
Package: ltxcmds 2020-05-10 v1.25 LaTeX kernel commands for general use (HO)
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/generic/kvsetkeys/kvsetkeys.sty
Package: kvsetkeys 2019/12/15 v1.18 Key value parser (HO)
))
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/fvextra/fvextra.sty
Package: fvextra 2019/02/04 v1.4 fvextra - extensions and patches for fancyvrb

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/base/ifthen.sty
Package: ifthen 2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/etoolbox/etoolbox.sty
Package: etoolbox 2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
\etb@tempcnta=\count187
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/fancyvrb/fancyvrb.sty
Package: fancyvrb 2021/01/20 v3.7 verbatim text (tvz,hv)
\FV@CodeLineNo=\count188
\FV@InFile=\read2
\FV@TabBox=\box47
\c@FancyVerbLine=\count189
\FV@StepNumber=\count190
\FV@OutFile=\write3
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/upquote/upquote.sty
Package: upquote 2012/04/19 v1.3 upright-quote and grave-accent glyphs in verba
tim
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/lineno/lineno.sty
Package: lineno 2005/11/02 line numbers on paragraphs v4.41
\linenopenalty=\count191
\output=\toks16
\linenoprevgraf=\count192
\linenumbersep=\dimen139
\linenumberwidth=\dimen140
\c@linenumber=\count193
\c@pagewiselinenumber=\count194
\c@LN@truepage=\count195
\c@internallinenumber=\count196
\c@internallinenumbers=\count197
\quotelinenumbersep=\dimen141
\bframerule=\dimen142
\bframesep=\dimen143
\bframebox=\box48
LaTeX Info: Redefining \\ on input line 3056.
)
\c@FV@TrueTabGroupLevel=\count198
\c@FV@TrueTabCounter=\count199
\FV@TabBox@Group=\box49
\FV@TmpLength=\skip49
\c@FV@HighlightLinesStart=\count266
\c@FV@HighlightLinesStop=\count267
\FV@LoopCount=\count268
\FV@NCharsBox=\box50
\FV@BreakIndent=\dimen144
\FV@BreakIndentNChars=\count269
\FV@BreakSymbolSepLeft=\dimen145
\FV@BreakSymbolSepLeftNChars=\count270
\FV@BreakSymbolSepRight=\dimen146
\FV@BreakSymbolSepRightNChars=\count271
\FV@BreakSymbolIndentLeft=\dimen147
\FV@BreakSymbolIndentLeftNChars=\count272
\FV@BreakSymbolIndentRight=\dimen148
\FV@BreakSymbolIndentRightNChars=\count273
\c@FancyVerbLineBreakLast=\count274
\FV@LineBox=\box51
\FV@LineIndentBox=\box52
\FV@LineWidth=\dimen149
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/tools/calc.sty
Package: calc 2017/05/25 v4.3 Infix arithmetic (KKT,FJ)
\calc@Acount=\count275
\calc@Bcount=\count276
\calc@Adimen=\dimen150
\calc@Bdimen=\dimen151
\calc@Askip=\skip50
\calc@Bskip=\skip51
LaTeX Info: Redefining \setlength on input line 80.
LaTeX Info: Redefining \addtolength on input line 81.
\calc@Ccount=\count277
\calc@Cskip=\skip52
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/tools/shellesc.sty
Package: shellesc 2019/11/08 v1.0c unified shell escape interface for LaTeX
Package shellesc Info: Unrestricted shell escape enabled on input line 75.
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/ifplatform/ifplatform.sty
Package: ifplatform 2017/10/13 v0.4a Testing for the operating system

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/generic/pdftexcmds/pdftexcmds.sty
Package: pdftexcmds 2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO
)

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/generic/infwarerr/infwarerr.sty
Package: infwarerr 2019/12/03 v1.5 Providing info/warning/error messages (HO)
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/generic/iftex/iftex.sty
Package: iftex 2020/03/06 v1.0d TeX engine tests
)
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode found.
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/generic/catchfile/catchfile.sty
Package: catchfile 2019/12/09 v1.8 Catch the contents of a file (HO)

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/generic/etexcmds/etexcmds.sty
Package: etexcmds 2019/12/15 v1.7 Avoid name clashes with e-TeX commands (HO)
))
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/generic/iftex/ifluatex.sty
Package: ifluatex 2019/10/25 v1.5 ifluatex legacy package. Use iftex instead.
)
runsystem(uname -s > "mwe.w18")...executed.

 (./mwe.w18)
runsystem(rm -- "mwe.w18")...executed.

)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/generic/xstring/xstring.sty
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/generic/xstring/xstring.tex
\integerpart=\count278
\decimalpart=\count279
)
Package: xstring 2019/02/06 v1.83 String manipulations (CT)
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/framed/framed.sty
Package: framed 2011/10/22 v 0.96: framed or shaded text with page breaks
\OuterFrameSep=\skip53
\fb@frw=\dimen152
\fb@frh=\dimen153
\FrameRule=\dimen154
\FrameSep=\dimen155
)
(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/float/float.sty
Package: float 2001/11/08 v1.3d Float enhancements (AL)
\c@float@type=\count280
\float@exts=\toks17
\float@box=\box53
\@float@everytoks=\toks18
\@floatcapt=\box54
)
\minted@appexistsfile=\read3
\minted@bgbox=\box55
\minted@code=\write4
\c@minted@FancyVerbLineTemp=\count281
\c@minted@pygmentizecounter=\count282
\@float@every@listing=\toks19
\c@listing=\count283
)
runsystem(mkdir -p _minted-mwe)...executed.

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/xcolor/xcolor.sty
Package: xcolor 2016/05/11 v2.12 LaTeX color extensions (UK)

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/graphics-cfg/color.cfg
File: color.cfg 2016/01/02 v1.6 sample color configuration
)
Package xcolor Info: Driver file: pdftex.def on input line 225.

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/graphics-def/pdftex.def
File: pdftex.def 2020/10/05 v1.2a Graphics/color driver for pdftex
)
Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1348.
Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1352.
Package xcolor Info: Model `RGB' extended on input line 1364.
Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1366.
Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1367.
Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1368.
Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1369.
Package xcolor Info: Model `Gray' substituted by `gray' on input line 1370.
Package xcolor Info: Model `wave' substituted by `hsb' on input line 1371.
)
runsystem(which pygmentize && touch mwe.aex)...executed.

runsystem(rm mwe.aex)...executed.

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/latex/l3backend/l3backend-pdftex.def
File: l3backend-pdftex.def 2021-03-18 L3 backend support: PDF output (pdfTeX)
\l__color_backend_stack_int=\count284
\l__pdf_internal_box=\box56
) (./mwe.aux)
\openout1 = `mwe.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.

(/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf/
tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count285
\scratchdimen=\dimen156
\scratchbox=\box57
\nofMPsegments=\count286
\nofMParguments=\count287
\everyMPshowfont=\toks20
\MPscratchCnt=\count288
\MPscratchDim=\dimen157
\MPnumerator=\count289
\makeMPintoPDFobject=\count290
\everyMPtoPDFconversion=\toks21
)
\openout3 = `mwe.pyg'.

 (./_minted-mwe/default-pyg-prefix.pygstyle) (./_minted-mwe/default.pygstyle)
(./_minted-mwe/066464FAF71284E7A6A8F7210E1B43DC5113A323AE379C640C9631CAF780D311
.pygtex)
\openout3 = `mwe.pyg'.

runsystem(pygmentize -l python -f latex -P commandprefix=PYG -F tokenmerge -P "
escapeinside=||" -o _minted-mwe/AC4D7D6E75D48A62E4DC368132AE2CC25113A323AE379C6
40C9631CAF780D311.pygtex mwe.pyg)...executed.

(./_minted-mwe/AC4D7D6E75D48A62E4DC368132AE2CC25113A323AE379C640C9631CAF780D311
.pygtex
! Missing \endcsname inserted.
 
                   \unhbox 
l.2 ...en} (remove this line to make it compile) }

The control sequence marked  should
not appear between \csname and \endcsname.

LaTeX Warning: Reference `\voidb@x ' on page 1 undefined on input line 2.

! Extra \endcsname.
\ref ...pandafter \@setref \csname r@#1\endcsname 
                                                  \@firstoftwo {#1}
l.2 ...en} (remove this line to make it compile) }

I'm ignoring this, since I wasn't doing a \csname.

)
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <7> on input line 14.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 14.
runsystem(rm _minted-mwe/CCB2B99281944A964BD9149F07174AF85113A323AE379C640C9631
CAF780D311.pygtex)...executed.

 [1

{/nix/store/72xlznpdkwmd5za0mx6q8209jvc4i9sy-texlive-combined-2021/share/texmf-
var/fonts/map/pdftex/updmap/pdftex.map}] (./mwe.aux)

LaTeX Warning: There were undefined references.

runsystem(rm mwe.pyg)...executed.

 ) 
Here is how much of TeX's memory you used:
 5027 strings out of 478994
 95645 string characters out of 5836551
 424491 words of memory out of 5000000
 22460 multiletter control sequences out of 15000+600000
 404679 words of font info for 32 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 85i,5n,88p,265b,385s stack positions out of 5000i,500n,10000p,200000b,80000s

Output written on mwe.pdf (1 page, 54082 bytes).
PDF statistics:
 32 PDF objects out of 1000 (max. 8388607)
 22 compressed objects within 1 object stream
 0 named destinations out of 1000 (max. 500000)
 1 words of extra memory for PDF output out of 10000 (max. 10000000)

The result: mwe

gpoore commented 3 years ago

This is likely related to the minus character being handled specially to support style names with hyphens. There is an existing issue related to that (#294); fixing that will likely fix this reference issue as well.

lucc commented 3 years ago

It is not critical for me as I was able to rename my labels, just wanted to report it.

muzimuzhi commented 3 years ago

I once proposed that pygments uses \csname ... \endcsname in its latex formatter in https://github.com/pygments/pygments/issues/1770, though received no responses. The proposed change is https://github.com/muzimuzhi/pygments/commit/c068d4770ab3333101474397ceca1a362910c143 .