1. Georg Brandl
  2. pygments-main
  3. Issues
Issue #1348 new

Category code safety

Enrico Gregorio
created an issue

When latex.py writes off its .pygstyle files it has

\makeatletter
\def\PYGdefault@reset{\let\PYGdefault@it=\relax \let\PYGdefault@bf=\relax%
    \let\PYGdefault@ul=\relax \let\PYGdefault@tc=\relax%
    \let\PYGdefault@bc=\relax \let\PYGdefault@ff=\relax}

[...]

\def\PYGdefaultZti{\char`\~}
% for compatibility with earlier versions
\def\PYGdefaultZat{@}
\def\PYGdefaultZlb{[}
\def\PYGdefaultZrb{]}
\makeatother

Under some circumstances, the % might not be interpreted as a comment character, see

https://tex.stackexchange.com/questions/368441/minted-compatibility-issue

It would be possible to avoid this issue by adding some code, namely

\makeatletter
\chardef\PYGdefault@savedpercentcode=\catcode`\%
\catcode`\%=14
\def\PYGdefault@reset{\let\PYGdefault@it=\relax \let\PYGdefault@bf=\relax%
    \let\PYGdefault@ul=\relax \let\PYGdefault@tc=\relax%
    \let\PYGdefault@bc=\relax \let\PYGdefault@ff=\relax}

[...]

\def\PYGdefaultZti{\char`\~}
% for compatibility with earlier versions
\def\PYGdefaultZat{@}
\def\PYGdefaultZlb{[}
\def\PYGdefaultZrb{]}
\catcode`\%=\PYGdefault@savedpercentcode
\makeatother

The two lines after \makeatletter save the current category code of %, then change it to be a comment character. The category code is restored at the end, with the line above \makeatother.

Comments (0)

  1. Log in to comment