Skip to content

Commit 1cf04c0

Browse files
committed
fixed catcode issues with Pygments macros in .dtx files or with babel magyar; improved code typesetting in documentation; improved changelog for v2.6
1 parent e2a394a commit 1cf04c0

2 files changed

Lines changed: 29 additions & 15 deletions

File tree

source/minted.dtx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
%<package>\NeedsTeXFormat{LaTeX2e}
3232
%<package>\ProvidesPackage{minted}
3333
%<*package>
34-
[2021/12/23 v2.6dev Yet another Pygments shim for LaTeX]
34+
[2021/12/24 v2.6dev Yet another Pygments shim for LaTeX]
3535
%</package>
3636
%<*driver>
3737
\documentclass{ltxdoc}
@@ -49,10 +49,6 @@
4949
\usepackage[svgnames]{xcolor}
5050
\usepackage{textcomp}
5151
\usepackage[cache, langlinenos]{minted}
52-
% Need to set the style here so that it is defined and brought in here.
53-
% If the style is set later, then docstrip interferes with any comments in
54-
% the style definition so that they appear as literal text in the document.
55-
\setminted{style=default}
5652

5753
\usepackage{environ}
5854
\usepackage{graphicx}
@@ -61,6 +57,20 @@
6157

6258

6359
\makeatletter
60+
% The typesetting for macrocode doesn't use \@noligs, which upquote modifies.
61+
% So apply the upquote fix to \verbatim@nolig@list as well, which is in macrocode.
62+
\begingroup
63+
\catcode`'=\active
64+
\catcode``=\active
65+
\g@addto@macro\verbatim@nolig@list{%
66+
\let'\textquotesingle
67+
\let`\textasciigrave
68+
\ifx\encodingdefault\upquote@OTone
69+
\ifx\ttdefault\upquote@cmtt
70+
\def'{\char13 }%
71+
\def`{\char18 }%
72+
\fi\fi}
73+
\endgroup
6474
6575
% Create a short verbatim pipe that handles quotation marks properly
6676
\begingroup
@@ -195,7 +205,7 @@
195205
%</driver>
196206
% \fi
197207
%
198-
% \CheckSum{2587}
208+
% \CheckSum{2593}
199209
%
200210
% \CharacterTable
201211
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -218,11 +228,11 @@
218228
%
219229
% \begin{changelog}{v2.6}{2021/12/??}
220230
% \item \texttt{autogobble} automatically uses \texttt{python} or \texttt{python3} executables, depending on availability, instead of requiring \texttt{python}. A custom executable can be specified by redefining \texttt{\string\MintedPython} (\#277, \#287).
231+
% \item Fixed \texttt{autogobble} compatibility with \texttt{fancyvrb} 4.0+ (\#315, \#316).
232+
% \item Pygments style names may now contain arbitrary non-whitespace characters. Previously, style names containing digits and some punctuation characters were incompatible (\#210, \#294, \#299, \#317). Pygments macros are now only defined just before use locally within \texttt{minted} commands and environments, rather than globally. Pygments macros now always use a \texttt{\string\PYG} prefix regardless of style, rather than a prefix of the form \texttt{\string\PYG<style>} (for example, what was previously \texttt{\string\PYGdefault} is now simply \texttt{\string\PYG}).
221233
% \item Removed Python-based MD5 hashing for XeTeX, which was necessary before XeTeX added \texttt{\string\mdfivesum} in 2017.
222234
% \item The default for \texttt{stripnl} is now \texttt{false}, so that original code is preserved exactly by default (\#198).
223235
% \item Added support for \texttt{fontencoding} option from \texttt{fvextra} (\#208).
224-
% \item Pygments style names may now contain arbitrary non-whitespace characters. Previously, style names containing digits and some punctuation characters were incompatible (\#210, \#294, \#299, \#317).
225-
% \item Fixed \texttt{autogobble} compatibility with \texttt{fancyvrb} 4.0+ (\#315, \#316).
226236
% \item Added note to FAQ about getting \texttt{texi2pdf} to work with \texttt{minted} given \texttt{texi2pdf}'s assumptions about temp files (\#186).
227237
% \item Reimplemented \texttt{bgcolor} option to be compatible with \texttt{color} package.
228238
% \end{changelog}
@@ -556,6 +566,8 @@
556566
% \item framed
557567
% \item shellesc (for luatex 0.87+)
558568
% \item catchfile
569+
%
570+
% ~
559571
% \end{list}
560572
% \endgroup
561573
% \end{multicols}
@@ -2453,11 +2465,13 @@
24532465
%
24542466
% Takes a single argument that is the detokenized style name. Getting the detokenized style name here requires expansion (|\edef|) in an earlier macro (currently |\minted@defstyle|) to convert |\minted@get@opt{style}{default}| into detokenized text. The |style| value is always wrapped in |\detokenize| when it is set, so expansion automatically detokenizes. Detokenization can be important depending on active characters. Expansion is important because the style name may be used with caching, so we need the current value retrieved by |\minted@get@opt|, not the value at the end of the document when cache data is written to the |.aux| file.
24552467
%
2456-
% Certain catcodes are required when loading Pygments style definitions from file. |catchfile| should automatically set everything to correct default values, except for |@| and |\endlinechar| which are handled manually. If a different approach to handling macros is ever used in the future, these require special handling:
2468+
% Certain catcodes are required when loading Pygments style definitions from file.
24572469
% \begin{itemize}
2458-
% \item Backtick |`| is made active by some \pkg{babel} package options, such as |magyar|.
2470+
% \item At sign |@| would be handled by the |\makeatletter| within the Pygments style definition if the style was brought in via |\input|, but |\makeatletter| doesn't affect tokenization with the |catchfile| approach.
24592471
% \item Percent |%| may not have its normal meaning within a |.dtx| file.
2472+
% \item Backtick |`| is made active by some \pkg{babel} package options, such as |magyar|.
24602473
% \end{itemize}
2474+
% |\endlinechar| also requires special handling to avoid introducing unwanted spaces.
24612475
%
24622476
% The |\ifx\PYG\relax| tests detect outdated style definitions from \pkg{minted} <2.6 and replace them when possible, and also detect missing styles. Before \pkg{minted} 2.6, style macros used a |\PYG<style>| prefix and were defined globally. Starting with 2.6, styles are redefined upon every use (within groups), and all styles use macros with a |\PYG| prefix. This allows more robust treatment of style names that involve punctuation characters and numbers.
24632477
% \begin{macrocode}
@@ -2485,7 +2499,7 @@
24852499
}%
24862500
}%
24872501
\CatchFileDef{\minted@tmp@filecontents}%
2488-
{\minted@pygstylepath@load}{\catcode`@=11\endlinechar=-1}%
2502+
{\minted@pygstylepath@load}{\catcode`@=11\catcode`\%=14\catcode``=12\endlinechar=-1}%
24892503
\begingroup
24902504
\let\PYG\relax
24912505
\minted@tmp@filecontents
@@ -2500,7 +2514,7 @@
25002514
> \minted@pygstylepath@save
25012515
}%
25022516
\CatchFileDef{\minted@tmp@filecontents}%
2503-
{\minted@pygstylepath@load}{\catcode`@=11\endlinechar=-1}%
2517+
{\minted@pygstylepath@load}{\catcode`@=11\catcode`\%=14\catcode``=12\endlinechar=-1}%
25042518
\minted@tmp@filecontents
25052519
\ifx\PYG\relax
25062520
\PackageError{minted}%

source/minted.sty

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
%% and the derived file minted.sty.
2828
\NeedsTeXFormat{LaTeX2e}
2929
\ProvidesPackage{minted}
30-
[2021/12/22 v2.6dev Yet another Pygments shim for LaTeX]
30+
[2021/12/24 v2.6dev Yet another Pygments shim for LaTeX]
3131
\RequirePackage{keyval}
3232
\RequirePackage{kvoptions}
3333
\RequirePackage{fvextra}
@@ -518,7 +518,7 @@
518518
}%
519519
}%
520520
\CatchFileDef{\minted@tmp@filecontents}%
521-
{\minted@pygstylepath@load}{\catcode`@=11\endlinechar=-1}%
521+
{\minted@pygstylepath@load}{\catcode`@=11\catcode`\%=14\catcode``=12\endlinechar=-1}%
522522
\begingroup
523523
\let\PYG\relax
524524
\minted@tmp@filecontents
@@ -533,7 +533,7 @@
533533
> \minted@pygstylepath@save
534534
}%
535535
\CatchFileDef{\minted@tmp@filecontents}%
536-
{\minted@pygstylepath@load}{\catcode`@=11\endlinechar=-1}%
536+
{\minted@pygstylepath@load}{\catcode`@=11\catcode`\%=14\catcode``=12\endlinechar=-1}%
537537
\minted@tmp@filecontents
538538
\ifx\PYG\relax
539539
\PackageError{minted}%

0 commit comments

Comments
 (0)