Skip to content

Commit

Permalink
replaced temp counter with a macro (#423); when highlightmode causes …
Browse files Browse the repository at this point in the history
…all code to be highlighted at once, duplicate highlighting is now detected and skipped
  • Loading branch information
gpoore committed Nov 18, 2024
1 parent b430cba commit e83d765
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 72 deletions.
11 changes: 11 additions & 0 deletions latex/CHANGELOG_MINTED_LATEX_PACKAGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Changelog — minted LaTeX package


## v3.4.0 (dev)

* Replaced temp counter with a macro to prevent issues with commands
and environments such as `\text` from `amsmath` that modify counter
behavior (#423).

* When `highlightmode` causes all code to be highlighted at once, duplicate
highlighting is now detected and skipped.



## v3.3.0 (2024/11/10)

* Fixed a bug from v3.2.0 that caused errors with unrestricted shell escape
Expand Down
85 changes: 48 additions & 37 deletions latex/minted/minted.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{minted}
%<*package>
[2024/11/10 v3.3.0 Yet another Pygments shim for LaTeX]
[2024/11/17 v3.4.0dev1 Yet another Pygments shim for LaTeX]
%</package>
%<*driver>
\documentclass{ltxdoc}
Expand Down Expand Up @@ -2220,10 +2220,10 @@
% \end{macro}
%
%
% \begin{macro}{minted@tmpcnt}
% Temp counter.
% \begin{macro}{\minted@tempindex}
% Temp index for looping.
% \begin{macrocode}
\newcounter{minted@tmpcnt}
\def\minted@tempindex{0}
% \end{macrocode}
% \end{macro}
%
Expand Down Expand Up @@ -2287,31 +2287,31 @@
% Create macros used in determining whether a given character is part of a specified set of characters.
% \begin{macrocode}
% [0-9]
\setcounter{minted@tmpcnt}{48}
\loop\unless\ifnum\value{minted@tmpcnt}>57\relax
\expandafter\let\csname minted@isnum\arabic{minted@tmpcnt}\endcsname\relax
\expandafter\let\csname minted@isalphanum\arabic{minted@tmpcnt}\endcsname\relax
\def\minted@tempindex{48}
\loop\unless\ifnum\minted@tempindex>57\relax
\expandafter\let\csname minted@isnum\minted@tempindex\endcsname\relax
\expandafter\let\csname minted@isalphanum\minted@tempindex\endcsname\relax
\expandafter\let
\csname minted@isalphanumhyphenunderscore\arabic{minted@tmpcnt}\endcsname\relax
\stepcounter{minted@tmpcnt}
\csname minted@isalphanumhyphenunderscore\minted@tempindex\endcsname\relax
\edef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}
\repeat
% [A-Z]
\setcounter{minted@tmpcnt}{65}
\loop\unless\ifnum\value{minted@tmpcnt}>90\relax
\expandafter\let\csname minted@isalpha\arabic{minted@tmpcnt}\endcsname\relax
\expandafter\let\csname minted@isalphanum\arabic{minted@tmpcnt}\endcsname\relax
\def\minted@tempindex{65}
\loop\unless\ifnum\minted@tempindex>90\relax
\expandafter\let\csname minted@isalpha\minted@tempindex\endcsname\relax
\expandafter\let\csname minted@isalphanum\minted@tempindex\endcsname\relax
\expandafter\let
\csname minted@isalphanumhyphenunderscore\arabic{minted@tmpcnt}\endcsname\relax
\stepcounter{minted@tmpcnt}
\csname minted@isalphanumhyphenunderscore\minted@tempindex\endcsname\relax
\edef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}
\repeat
% [a-z]
\setcounter{minted@tmpcnt}{97}
\loop\unless\ifnum\value{minted@tmpcnt}>122\relax
\expandafter\let\csname minted@isalpha\arabic{minted@tmpcnt}\endcsname\relax
\expandafter\let\csname minted@isalphanum\arabic{minted@tmpcnt}\endcsname\relax
\def\minted@tempindex{97}
\loop\unless\ifnum\minted@tempindex>122\relax
\expandafter\let\csname minted@isalpha\minted@tempindex\endcsname\relax
\expandafter\let\csname minted@isalphanum\minted@tempindex\endcsname\relax
\expandafter\let
\csname minted@isalphanumhyphenunderscore\arabic{minted@tmpcnt}\endcsname\relax
\stepcounter{minted@tmpcnt}
\csname minted@isalphanumhyphenunderscore\minted@tempindex\endcsname\relax
\edef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}
\repeat
% [-]
\expandafter\let\csname minted@isalphanumhyphenunderscore45\endcsname\relax
Expand Down Expand Up @@ -3406,13 +3406,13 @@
\pydatawritekey{cachefiles}%
\pydatawritemlvaluestart
\pydatawritemlvalueline{[}%
\setcounter{minted@tmpcnt}{1}%
\loop\unless\ifnum\value{minted@tmpcnt}>\minted@numcachefiles\relax
\gdef\minted@tempindex{1}%
\loop\unless\ifnum\minted@tempindex>\minted@numcachefiles\relax
\expandafter\minted@savecachelist@writecachefile\expandafter{%
\csname minted@cachefile\arabic{minted@tmpcnt}\endcsname}%
\csname minted@cachefile\minted@tempindex\endcsname}%
\expandafter\global\expandafter
\let\csname minted@cachefile\arabic{minted@tmpcnt}\endcsname\minted@undefined
\stepcounter{minted@tmpcnt}%
\let\csname minted@cachefile\minted@tempindex\endcsname\minted@undefined
\xdef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}%
\repeat
\pydatawritemlvalueline{]}%
\pydatawritemlvalueend
Expand Down Expand Up @@ -3765,12 +3765,12 @@
\pydatabufferkeyvalue{command}{highlight}%
\pydatabufferkey{code}%
\pydatabuffermlvaluestart
\setcounter{minted@tmpcnt}{1}%
\loop\unless\ifnum\value{minted@tmpcnt}>\minted@tmpcodebufferlength\relax
\gdef\minted@tempindex{1}%
\loop\unless\ifnum\minted@tempindex>\minted@tmpcodebufferlength\relax
\expandafter\let\expandafter
\minted@tmp\csname minted@tmpcodebufferline\arabic{minted@tmpcnt}\endcsname
\minted@tmp\csname minted@tmpcodebufferline\minted@tempindex\endcsname
\expandafter\pydatabuffermlvalueline\expandafter{\minted@tmp}%
\stepcounter{minted@tmpcnt}%
\xdef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}%
\repeat
\pydatabuffermlvalueend
\minted@highlight@i}
Expand Down Expand Up @@ -3814,8 +3814,19 @@
\input{\minted@highlightfilepath}}%
\minted@addcachefilename{\minted@highlightfilename}}%
{\ifbool{minted@canexec}%
{\minted@iffasthighlightmode@buffertempfile
\minted@highlight@create}%
{\ifbool{minted@fasthighlightmode}%
{\ifcsname minted@processedfilename@\minted@highlightfilename\endcsname
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\minted@insertplaceholder}%
{\expandafter\global\expandafter\let
\csname minted@processedfilename@\minted@highlightfilename\endcsname\relax
\minted@iffasthighlightmode@buffertempfile
\minted@highlight@create}}%
{\minted@iffasthighlightmode@buffertempfile
\minted@highlight@create}}%
{\minted@error{Cannot highlight code (minted executable is unavailable or
disabled); attempting to typeset without highlighting}%
\minted@highlight@fallback}}}%
Expand Down Expand Up @@ -3985,12 +3996,12 @@
\def\minted@iffasthighlightmode@buffertempfile@v{%
\pydatabufferkey{code}%
\pydatabuffermlvaluestart
\setcounter{minted@tmpcnt}{1}%
\loop\unless\ifnum\value{minted@tmpcnt}>\minted@tmpcodebufferlength\relax
\gdef\minted@tempindex{1}%
\loop\unless\ifnum\minted@tempindex>\minted@tmpcodebufferlength\relax
\expandafter\let\expandafter
\minted@tmp\csname minted@tmpcodebufferline\arabic{minted@tmpcnt}\endcsname
\minted@tmp\csname minted@tmpcodebufferline\minted@tempindex\endcsname
\expandafter\pydatabuffermlvalueline\expandafter{\minted@tmp}%
\stepcounter{minted@tmpcnt}%
\xdef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}%
\repeat
\pydatabuffermlvalueend
\VerbatimClearBuffer[buffername=minted@tmpcodebuffer]}
Expand Down
81 changes: 46 additions & 35 deletions latex/minted/minted.sty
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{minted}
[2024/11/10 v3.3.0 Yet another Pygments shim for LaTeX]
[2024/11/17 v3.4.0dev1 Yet another Pygments shim for LaTeX]
\RequirePackage{catchfile}
\RequirePackage{etoolbox}
\RequirePackage{fvextra}[2024/10/16]
Expand Down Expand Up @@ -289,7 +289,7 @@
\fi
\fi
\def\minted@styleprefix{PYG}
\newcounter{minted@tmpcnt}
\def\minted@tempindex{0}
\def\minted@forcsvlist#1#2{%
\if\relax\detokenize\expandafter{\@gobble#2}\relax
\expandafter\minted@forcsvlist@exp
Expand All @@ -315,29 +315,29 @@
\catcode`\@=11\relax
#1%
\catcode`\@=\minted@tmpatcat\relax}
\setcounter{minted@tmpcnt}{48}
\loop\unless\ifnum\value{minted@tmpcnt}>57\relax
\expandafter\let\csname minted@isnum\arabic{minted@tmpcnt}\endcsname\relax
\expandafter\let\csname minted@isalphanum\arabic{minted@tmpcnt}\endcsname\relax
\def\minted@tempindex{48}
\loop\unless\ifnum\minted@tempindex>57\relax
\expandafter\let\csname minted@isnum\minted@tempindex\endcsname\relax
\expandafter\let\csname minted@isalphanum\minted@tempindex\endcsname\relax
\expandafter\let
\csname minted@isalphanumhyphenunderscore\arabic{minted@tmpcnt}\endcsname\relax
\stepcounter{minted@tmpcnt}
\csname minted@isalphanumhyphenunderscore\minted@tempindex\endcsname\relax
\edef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}
\repeat
\setcounter{minted@tmpcnt}{65}
\loop\unless\ifnum\value{minted@tmpcnt}>90\relax
\expandafter\let\csname minted@isalpha\arabic{minted@tmpcnt}\endcsname\relax
\expandafter\let\csname minted@isalphanum\arabic{minted@tmpcnt}\endcsname\relax
\def\minted@tempindex{65}
\loop\unless\ifnum\minted@tempindex>90\relax
\expandafter\let\csname minted@isalpha\minted@tempindex\endcsname\relax
\expandafter\let\csname minted@isalphanum\minted@tempindex\endcsname\relax
\expandafter\let
\csname minted@isalphanumhyphenunderscore\arabic{minted@tmpcnt}\endcsname\relax
\stepcounter{minted@tmpcnt}
\csname minted@isalphanumhyphenunderscore\minted@tempindex\endcsname\relax
\edef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}
\repeat
\setcounter{minted@tmpcnt}{97}
\loop\unless\ifnum\value{minted@tmpcnt}>122\relax
\expandafter\let\csname minted@isalpha\arabic{minted@tmpcnt}\endcsname\relax
\expandafter\let\csname minted@isalphanum\arabic{minted@tmpcnt}\endcsname\relax
\def\minted@tempindex{97}
\loop\unless\ifnum\minted@tempindex>122\relax
\expandafter\let\csname minted@isalpha\minted@tempindex\endcsname\relax
\expandafter\let\csname minted@isalphanum\minted@tempindex\endcsname\relax
\expandafter\let
\csname minted@isalphanumhyphenunderscore\arabic{minted@tmpcnt}\endcsname\relax
\stepcounter{minted@tmpcnt}
\csname minted@isalphanumhyphenunderscore\minted@tempindex\endcsname\relax
\edef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}
\repeat
\expandafter\let\csname minted@isalphanumhyphenunderscore45\endcsname\relax
\expandafter\let\csname minted@isalphanumhyphenunderscore95\endcsname\relax
Expand Down Expand Up @@ -1133,13 +1133,13 @@
\pydatawritekey{cachefiles}%
\pydatawritemlvaluestart
\pydatawritemlvalueline{[}%
\setcounter{minted@tmpcnt}{1}%
\loop\unless\ifnum\value{minted@tmpcnt}>\minted@numcachefiles\relax
\gdef\minted@tempindex{1}%
\loop\unless\ifnum\minted@tempindex>\minted@numcachefiles\relax
\expandafter\minted@savecachelist@writecachefile\expandafter{%
\csname minted@cachefile\arabic{minted@tmpcnt}\endcsname}%
\csname minted@cachefile\minted@tempindex\endcsname}%
\expandafter\global\expandafter
\let\csname minted@cachefile\arabic{minted@tmpcnt}\endcsname\minted@undefined
\stepcounter{minted@tmpcnt}%
\let\csname minted@cachefile\minted@tempindex\endcsname\minted@undefined
\xdef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}%
\repeat
\pydatawritemlvalueline{]}%
\pydatawritemlvalueend
Expand Down Expand Up @@ -1394,12 +1394,12 @@
\pydatabufferkeyvalue{command}{highlight}%
\pydatabufferkey{code}%
\pydatabuffermlvaluestart
\setcounter{minted@tmpcnt}{1}%
\loop\unless\ifnum\value{minted@tmpcnt}>\minted@tmpcodebufferlength\relax
\gdef\minted@tempindex{1}%
\loop\unless\ifnum\minted@tempindex>\minted@tmpcodebufferlength\relax
\expandafter\let\expandafter
\minted@tmp\csname minted@tmpcodebufferline\arabic{minted@tmpcnt}\endcsname
\minted@tmp\csname minted@tmpcodebufferline\minted@tempindex\endcsname
\expandafter\pydatabuffermlvalueline\expandafter{\minted@tmp}%
\stepcounter{minted@tmpcnt}%
\xdef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}%
\repeat
\pydatabuffermlvalueend
\minted@highlight@i}
Expand Down Expand Up @@ -1443,8 +1443,19 @@
\input{\minted@highlightfilepath}}%
\minted@addcachefilename{\minted@highlightfilename}}%
{\ifbool{minted@canexec}%
{\minted@iffasthighlightmode@buffertempfile
\minted@highlight@create}%
{\ifbool{minted@fasthighlightmode}%
{\ifcsname minted@processedfilename@\minted@highlightfilename\endcsname
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\minted@insertplaceholder}%
{\expandafter\global\expandafter\let
\csname minted@processedfilename@\minted@highlightfilename\endcsname\relax
\minted@iffasthighlightmode@buffertempfile
\minted@highlight@create}}%
{\minted@iffasthighlightmode@buffertempfile
\minted@highlight@create}}%
{\minted@error{Cannot highlight code (minted executable is unavailable or
disabled); attempting to typeset without highlighting}%
\minted@highlight@fallback}}}%
Expand Down Expand Up @@ -1603,12 +1614,12 @@
\def\minted@iffasthighlightmode@buffertempfile@v{%
\pydatabufferkey{code}%
\pydatabuffermlvaluestart
\setcounter{minted@tmpcnt}{1}%
\loop\unless\ifnum\value{minted@tmpcnt}>\minted@tmpcodebufferlength\relax
\gdef\minted@tempindex{1}%
\loop\unless\ifnum\minted@tempindex>\minted@tmpcodebufferlength\relax
\expandafter\let\expandafter
\minted@tmp\csname minted@tmpcodebufferline\arabic{minted@tmpcnt}\endcsname
\minted@tmp\csname minted@tmpcodebufferline\minted@tempindex\endcsname
\expandafter\pydatabuffermlvalueline\expandafter{\minted@tmp}%
\stepcounter{minted@tmpcnt}%
\xdef\minted@tempindex{\the\numexpr\minted@tempindex+1\relax}%
\repeat
\pydatabuffermlvalueend
\VerbatimClearBuffer[buffername=minted@tmpcodebuffer]}
Expand Down

0 comments on commit e83d765

Please sign in to comment.