summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/minted
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-12-25 21:41:49 +0000
committerKarl Berry <karl@freefriends.org>2021-12-25 21:41:49 +0000
commit0f274cbeb1205f6b677c117e09b1252da1355bad (patch)
treea4317757a85f7e8b3aba38537db1f1d545501f43 /Master/texmf-dist/source/latex/minted
parent43ddd4df96cdf35191e9f41a03df50b788b8d725 (diff)
minted (25dec21)
git-svn-id: svn://tug.org/texlive/trunk@61405 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/minted')
-rw-r--r--Master/texmf-dist/source/latex/minted/Makefile38
-rw-r--r--Master/texmf-dist/source/latex/minted/minted.dtx422
-rw-r--r--Master/texmf-dist/source/latex/minted/minted.ins2
3 files changed, 309 insertions, 153 deletions
diff --git a/Master/texmf-dist/source/latex/minted/Makefile b/Master/texmf-dist/source/latex/minted/Makefile
new file mode 100644
index 00000000000..ae199e79d50
--- /dev/null
+++ b/Master/texmf-dist/source/latex/minted/Makefile
@@ -0,0 +1,38 @@
+TEXFLAGS = -e '$$pdflatex=q/pdflatex %O -shell-escape %S/' -pdf
+LATEXMK = latexmk
+
+PACKAGE = minted.dtx \
+ minted.ins \
+ minted.pdf \
+ README \
+ Makefile
+
+.PHONY: minted all doc dist clean cleanall
+
+minted: minted.sty
+
+doc: minted.pdf
+
+all: minted doc
+
+minted.sty: minted.ins minted.dtx
+ tex minted.ins
+
+minted.pdf: minted.sty minted.gls minted.dtx
+ $(LATEXMK) $(TEXFLAGS) minted.dtx
+
+minted.gls: minted.glo
+ makeindex -s gglo.ist -o minted.gls minted.glo
+
+minted.glo: minted.dtx minted.sty
+ $(LATEXMK) $(TEXFLAGS) minted.dtx
+
+dist: $(PACKAGE)
+ @$(RM) minted.zip
+ @zip minted-$(shell grep '^\\ProvidesPackage' < minted.sty | grep -o '\<v[[:digit:]]*\.[[:digit:]]*\>').zip $(PACKAGE)
+
+clean:
+ @$(RM) *.aux *.log *.out *.toc *.fdb_latexmk *.ilg *.glo *.gls *.lol
+
+cleanall: clean
+ @$(RM) minted.sty minted.zip
diff --git a/Master/texmf-dist/source/latex/minted/minted.dtx b/Master/texmf-dist/source/latex/minted/minted.dtx
index 3a15d7c1e69..3d2ac0219d0 100644
--- a/Master/texmf-dist/source/latex/minted/minted.dtx
+++ b/Master/texmf-dist/source/latex/minted/minted.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment
%
-% Copyright (C) 2013-2017 by Geoffrey M. Poore <gpoore@gmail.com>
+% Copyright (C) 2013-2021 by Geoffrey M. Poore <gpoore@gmail.com>
% Copyright (C) 2010-2011 by Konrad Rudolph <konrad_rudolph@madrat.net>
% ---------------------------------------------------------------------------
% This work may be distributed and/or modified under the
@@ -31,7 +31,7 @@
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{minted}
%<*package>
- [2017/07/19 v2.5 Yet another Pygments shim for LaTeX]
+ [2021/12/24 v2.6 Yet another Pygments shim for LaTeX]
%</package>
%<*driver>
\documentclass{ltxdoc}
@@ -49,10 +49,6 @@
\usepackage[svgnames]{xcolor}
\usepackage{textcomp}
\usepackage[cache, langlinenos]{minted}
-% Need to set the style here so that it is defined and brought in here.
-% If the style is set later, then docstrip interferes with any comments in
-% the style definition so that they appear as literal text in the document.
-\setminted{style=default}
\usepackage{environ}
\usepackage{graphicx}
@@ -61,6 +57,20 @@
\makeatletter
+% The typesetting for macrocode doesn't use \@noligs, which upquote modifies.
+% So apply the upquote fix to \verbatim@nolig@list as well, which is in macrocode.
+\begingroup
+\catcode`'=\active
+\catcode``=\active
+\g@addto@macro\verbatim@nolig@list{%
+ \let'\textquotesingle
+ \let`\textasciigrave
+ \ifx\encodingdefault\upquote@OTone
+ \ifx\ttdefault\upquote@cmtt
+ \def'{\char13 }%
+ \def`{\char18 }%
+ \fi\fi}
+\endgroup
% Create a short verbatim pipe that handles quotation marks properly
\begingroup
@@ -98,8 +108,8 @@
\g@addto@macro\changestext{\end{itemize}}%
}
\newcommand{\PrintChangelog}{%
- \addcontentsline{toc}{section}{Version History}
\section*{Version History}%
+ \addcontentsline{toc}{section}{Version History}
\label{sec:version-history}
\begin{description}%
\changestext
@@ -195,7 +205,7 @@
%</driver>
% \fi
%
-% \CheckSum{2604}
+% \CheckSum{2593}
%
% \CharacterTable
% {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
@@ -216,6 +226,18 @@
%
%
%
+% \begin{changelog}{v2.6}{2021/12/24}
+% \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).
+% \item Fixed \texttt{autogobble} compatibility with \texttt{fancyvrb} 4.0+ (\#315, \#316).
+% \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}).
+% \item Removed Python-based MD5 hashing for XeTeX, which was necessary before XeTeX added \texttt{\string\mdfivesum} in 2017.
+% \item The default for \texttt{stripnl} is now \texttt{false}, so that original code is preserved exactly by default (\#198).
+% \item Added support for \texttt{fontencoding} option from \texttt{fvextra} (\#208).
+% \item Added note to FAQ about getting \texttt{texi2pdf} to work with \texttt{minted} given \texttt{texi2pdf}'s assumptions about temp files (\#186).
+% \item Reimplemented \texttt{bgcolor} option to be compatible with \texttt{color} package.
+% \end{changelog}
+%
+%
% \begin{changelog}{v2.5}{2017/07/19}
% \item The default placement for the \texttt{listing} float is now \texttt{tbp} instead of \texttt{h}, to parallel \texttt{figure} and \texttt{table} and also avoid warnings caused by \texttt{h} (\#165). The documentation now contains information about changing default placement. The \texttt{float} package is no longer loaded when the \texttt{newfloat} package option is used.
% \item Added support for \texttt{*nchars} options from \texttt{fvextra} v1.3 that allow setting \texttt{breaklines}-related indentation in terms of a number of characters, rather than as a fixed dimension.
@@ -543,6 +565,9 @@
% \item lineno
% \item framed
% \item shellesc (for luatex 0.87+)
+% \item catchfile
+%
+% ~
% \end{list}
% \endgroup
% \end{multicols}
@@ -815,6 +840,11 @@
% Compiling with the |finalizecache| option prepares the cache for use in an environment without |-shell-escape|.\footnote{Ordinarily, cache files are named using an MD5 hash of highlighting settings and highlighted text. \texttt{finalizecache} renames cache files using a \texttt{listing<number>.pygtex} scheme. This makes it simpler to match up document content and cache files, and is also necessary for the XeTeX engine since prior to TeX Live 2016 it lacked the built-in MD5 capabilities that pdfTeX and LuaTeX have.} Once this has been done, the |finalizecache| option may be swapped for the |frozencache| option, which will then use the frozen (static) cache in the future, without needing |-shell-escape|.
%
%
+% \DescribeMacro{fontencoding=\meta{encoding} (default:~\meta{doc~encoding})}
+% Set font encoding used for typesetting code.
+%
+% For example, |fontencoding=T1|.
+%
% \DescribeMacro{frozencache=\meta{boolean} (default:~false)}
% Use a frozen (static) cache created with the |finalizecache| option. When |frozencache| is on, |-shell-escape| is not needed, and Python and Pygments are not required. In addition, any external files accessed through |\inputminted| are no longer necessary.
%
@@ -1361,7 +1391,7 @@
%
% \item[stripall (boolean) (false)]
% Strip all leading and trailing whitespace from the input.
-% \item[stripnl (boolean) (true)]
+% \item[stripnl (boolean) (false)]
% Strip leading and trailing newlines from the input.
%
%
@@ -1481,7 +1511,7 @@
%
% \begin{itemize}
% \item \textbf{There are intermittent ``I can't write on file'' errors.} This can be caused by using \pkg{minted} in a directory that is synchronized with Dropbox or a similar file syncing program. These programs can try to sync \pkg{minted}'s temporary files while it still needs to be able to modify them. The solution is to turn off file syncing or use a directory that is not synced.
-% \item \textbf{I receive a ``Font Warning: Some font shapes were not available'' message, or bold or italic seem to be missing.} This due to a limitation in the font that is currently in use for typesetting code. In some cases, the default font shapes that \LaTeX\ substitutes are perfectly adequate, and the warning may be ignored. In other cases, the font substitutions may not clearly indicate bold or italic text, and you will want to switch to a different font. See The \LaTeX\ Font Catalogue's section on \href{http://www.tug.dk/FontCatalogue/typewriterfonts.html}{Typewriter Fonts} for alternatives. If you like the default \LaTeX\ fonts, the \pkg{lmodern} package is a good place to start. The \pkg{beramono} and \pkg{courier} packages may also be good options.
+% \item \textbf{I receive a ``Font Warning: Some font shapes were not available'' message, or bold or italic seem to be missing.} This is due to a limitation in the font that is currently in use for typesetting code. In some cases, the default font shapes that \LaTeX\ substitutes are perfectly adequate, and the warning may be ignored. In other cases, the font substitutions may not clearly indicate bold or italic text, and you will want to switch to a different font. See The \LaTeX\ Font Catalogue's section on \href{http://www.tug.dk/FontCatalogue/typewriterfonts.html}{Typewriter Fonts} for alternatives. If you like the default \LaTeX\ fonts, the \pkg{lmodern} package is a good place to start. The \pkg{beramono} and \pkg{courier} packages may also be good options.
% \item \textbf{I receive a ``Too many open files'' error under OS X when using caching.} See the note on OS X under Section~\ref{sec:basic:preliminary}.
% \item \textbf{TeXShop can't find \texttt{pygmentize}.} You may need to create a symlink. See \url{https://tex.stackexchange.com/questions/279214}.
% \item \textbf{Weird things happen when I use the \pkg{fancybox} package.} \pkg{fancybox} conflicts with \pkg{fancyvrb}, which \pkg{minted} uses internally. When using \pkg{fancybox}, make sure that it is loaded before \pkg{minted} (or before \pkg{fancyvrb}, if \pkg{fancyvrb} is not loaded by \pkg{minted}).
@@ -1558,16 +1588,24 @@
% \item \textbf{I want extended characters in frame labels, but am getting errors.} This can happen with \pkg{minted} <2.0 and Python 2.7, due to a \href{https://bitbucket.org/birkenfeld/pygments-main/issue/801/python-2-fails-to-detect-terminal-encoding}{terminal encoding issue with Pygments}. It should work with any version of Python with \pkg{minted} 2.0+, which processes labels internally and does not send them to Python.
% \item \textbf{\texttt{minted} environments have extra vertical space inside \texttt{tabular}.} It is possible to \href{https://github.com/gpoore/minted/issues/82}{create a custom environment} that eliminates the extra space. However, a general solution that behaves as expected in the presence of adjacent text remains to be found.
% \item \textbf{I'm receiving a warning from \texttt{lineno.sty} that ``Command \texttt{\string\@parboxrestore} has changed.''} This can happen when \pkg{minted} is loaded after \pkg{csquotes}. Try loading \pkg{minted} first. If you receive this message when you are not using \pkg{csquotes}, you may want to experiment with the order of loading packages and might also open an issue.
+% \item \textbf{I'm using \app{texi2pdf}, and getting ``Cannot stat'' errors from \app{tar}}: This is due to the way that \app{texi2pdf} handles temporary files. \pkg{minted} automatically cleans up its temporary files, but \app{texi2pdf} assumes that any temporary file that is ever created will still exist at the end of the run, so it tries to access the files that \pkg{minted} has deleted. It's possible to disable minted's temp file cleanup by adding |\renewcommand{\DeleteFile}[2][]{}| after the |\usepackage{minted}|.
% \end{itemize}
%
%
%
%
% \section*{Acknowledgements}
+% \addcontentsline{toc}{section}{Acknowledgements}
%
-% Konrad Rudolph: Special thanks to Philipp Stephani and the rest of the guys from \texttt{comp.text.tex} and \texttt{tex.stackexchange.com}.
+% \textbf{Konrad Rudolph:} Special thanks to Philipp Stephani and the rest of the guys from \texttt{comp.text.tex} and \texttt{tex.stackexchange.com}.
%
-% Geoffrey Poore: Thanks to Marco Daniel for the code on \url{tex.stackexchange.com} that inspired automatic line breaking. Thanks to Patrick Vogt for improving TikZ externalization compatibility.
+% \textbf{Geoffrey Poore:}
+% \begin{itemize}
+% \item Thanks to Marco Daniel for the code on \url{tex.stackexchange.com} that inspired automatic line breaking.
+% \item Thanks to Patrick Vogt for improving TikZ externalization compatibility.
+% \item Thanks to \textsf{@muzimuzhi} for assistance with GitHub issues.
+% \item Thanks to \textsf{@jfbu} for suggestions and discussion regarding support for arbitrary Pygments style names (\#210, \#294, \#299, \#317), and for debugging assistance.
+% \end{itemize}
%
% \PrintChangelog
%
@@ -1601,6 +1639,7 @@
\RequirePackage{xstring}
\RequirePackage{lineno}
\RequirePackage{framed}
+\RequirePackage{catchfile}
% \end{macrocode}
%
% Make sure that either |color| or |xcolor| is loaded by the beginning of the document.
@@ -1923,7 +1962,7 @@
% \begin{macrocode}
\newboolean{AppExists}
\newread\minted@appexistsfile
-\newcommand{\TestAppExists}[1]{
+\newcommand{\TestAppExists}[1]{%
\ifwindows
% \end{macrocode}
%
@@ -1932,32 +1971,32 @@
% otherwise, it will contain the full path of the application.
%
% \begin{macrocode}
- \DeleteFile{\minted@jobname.aex}
+ \DeleteFile{\minted@jobname.aex}%
\ShellEscape{for \string^\@percentchar i in (#1.exe #1.bat #1.cmd)
do set > \minted@jobname.aex <nul: /p
- x=\string^\@percentchar \string~$PATH:i>> \minted@jobname.aex}
+ x=\string^\@percentchar \string~$PATH:i>> \minted@jobname.aex}%
%$ <- balance syntax highlighting
\immediate\openin\minted@appexistsfile\minted@jobname.aex
- \expandafter\def\expandafter\@tmp@cr\expandafter{\the\endlinechar}
+ \expandafter\def\expandafter\@tmp@cr\expandafter{\the\endlinechar}%
\endlinechar=-1\relax
\readline\minted@appexistsfile to \minted@apppathifexists
\endlinechar=\@tmp@cr
- \ifthenelse{\equal{\minted@apppathifexists}{}}
- {\AppExistsfalse}
- {\AppExiststrue}
+ \ifthenelse{\equal{\minted@apppathifexists}{}}%
+ {\AppExistsfalse}%
+ {\AppExiststrue}%
\immediate\closein\minted@appexistsfile
- \DeleteFile{\minted@jobname.aex}
+ \DeleteFile{\minted@jobname.aex}%
\else
% \end{macrocode}
%
% On Unix-like systems, we do a straightforward |which| test and create a file upon success, whose existence we can then check.
%
% \begin{macrocode}
- \ShellEscape{which #1 && touch \minted@jobname.aex}
- \IfFileExists{\minted@jobname.aex}
+ \ShellEscape{which #1 && touch \minted@jobname.aex}%
+ \IfFileExists{\minted@jobname.aex}%
{\AppExiststrue
- \DeleteFile{\minted@jobname.aex}}
- {\AppExistsfalse}
+ \DeleteFile{\minted@jobname.aex}}%
+ {\AppExistsfalse}%
\fi
}
% \end{macrocode}
@@ -2397,81 +2436,112 @@
% \end{macro}
%
%
-% \begin{macro}{\minted@checkstyle}
-% Make sure that style macros exist.
+% \begin{macro}{\minted@def@opt@detok}
+% Same as |\minted@def@opt|, except wraps argument in |\detokenize|.
+% \begin{macrocode}
+\newcommand{\minted@def@opt@detok}[2][]{%
+ \define@key{minted@opt@g}{#2}{%
+ \@namedef{minted@opt@g:#2}{\detokenize{##1}}}
+ \define@key{minted@opt@g@i}{#2}{%
+ \@namedef{minted@opt@g@i:#2}{\detokenize{##1}}}
+ \define@key{minted@opt@lang}{#2}{%
+ \@namedef{minted@opt@lang\minted@lang:#2}{\detokenize{##1}}}
+ \define@key{minted@opt@lang@i}{#2}{%
+ \@namedef{minted@opt@lang\minted@lang @i:#2}{\detokenize{##1}}}
+ \define@key{minted@opt@cmd}{#2}{%
+ \@namedef{minted@opt@cmd:#2}{\detokenize{##1}}}
+ \ifstrempty{#1}{}{\@namedef{minted@opt@g:#2}{\detokenize{#1}}}%
+}
+% \end{macrocode}
+% \end{macro}
%
-% We have to do some tricks with |\endlinechar| to prevent |\input| from inserting unwanted whitespace. That is primarily for inline commands, where it would introduce a line break. There is also the very unorthodox |\let\def\gdef| to make sure that macros are defined globally. The catcodes for |-| and |_| must be changed during macro definition to accomodate style names like |paraiso-light|, |paraiso-dark|, and |algol_nu|. The catcode for |%| must be changed to the default value in case \pkg{minted} is being used in a |.dtx| file; otherwise, \LaTeX\ comments in the Pygments style files will appear as literal text.
%
-% If a style is not given, then revert to the |default| style, but create macros with prefix |PYG|, and create |default-pyg-prefix.pygstyle| if caching is on. This allows a graceful fallback in the event that style is empty. It is also purposefully used to create a complete set of macros with prefix |PYG|, so that the symbol macros may be used, as described next.
+% \begin{macro}{\minted@generate@PYGdef}
+% Generate Pygments style definition with |pygmentize| if a cached version does not exist. Load the style definition into a global macro of the form
+%\begin{Verbatim}
+%\csname minted@PYGdef@<style>\endcsname
+%\end{Verbatim}
+% to allow styles to be defined later. Styles are not defined globally to avoid naming issues with style names that involve punctuation characters and numbers. Rather, styles are redefined upon every use (within groups), and all styles use macros with a |\PYG| prefix.
%
-% The typical style macros created by |\minted@checkstyle|, which are of the form |\PYG<style>|, are used indirectly. All code is highlighted with |commandprefix=PYG|, so that it uses |\PYG|. Then |\PYG| is |\let| to |\PYG<style>| as appropriate. This way, code need not be highlighted again when the style is changed. This has the disadvantage that none of the |\PYG<symbol>| macros will be defined; rather, only |\PYG<style><symbol>| macros will be defined. It would be possible to |\let| |\PYG<symbol>| to |\PYG<style><symbol>|, but it is simpler to define a complete set of symbol macros using the |PYG| prefix, so that all symbol macros will be defined by default.\footnote{It would be possible to hard-code the symbol macros in \pkg{minted} itself, but that would have the disadvantage of tying \pkg{minted} more closely to a particular version of \pkg{Pygments}. Similarly, \texttt{\string\let}ing symbol macros assumes a complete, fixed list of symbol macros. The current approach is harder to break than these alternatives; the worst-case scenario should be needing to purge the cache, rather than dealing with an undefined macro.}
+% 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.
%
-% Whenever |\minted@checkstyle| is invoked with a named style and style macros need to be created, there is a check to see if the |PYG| prefix macros have been created, and they are generated if they do not yet exist. This is important when |\MintedPygmentize| is used to call a custom |pygmentize|; we want to wait as late as possible to use |pygmentize|, so we don't want to generate the |\PYG| macros until the last possible moment. When the |\PYG| macros are actually created, the single quote macro is patched after loading.
+% Certain catcodes are required when loading Pygments style definitions from file.
+% \begin{itemize}
+% \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.
+% \item Percent |%| may not have its normal meaning within a |.dtx| file.
+% \item Backtick |`| is made active by some \pkg{babel} package options, such as |magyar|.
+% \end{itemize}
+% |\endlinechar| also requires special handling to avoid introducing unwanted spaces.
%
-% It isn't necessary to set the initial style to |default|, because the current style is always obtained via |\minted@get@opt{style}{default}|, so |default| is always the fallback value and need not be set explicitly. |\minted@checkstyle| is used in each command/environment, so that using |pygmentize| can be delayed as long as possible.
+% 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.
% \begin{macrocode}
-\newcommand{\minted@checkstyle}[1]{%
- \ifcsname minted@styleloaded@\ifstrempty{#1}{default-pyg-prefix}{#1}\endcsname\else
- \ifstrempty{#1}{}{\ifcsname PYG\endcsname\else\minted@checkstyle{}\fi}%
- \expandafter\gdef%
- \csname minted@styleloaded@\ifstrempty{#1}{default-pyg-prefix}{#1}\endcsname{}%
- \ifthenelse{\boolean{minted@cache}}%
- {\IfFileExists
- {\minted@outputdir\minted@cachedir/\ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}%
- {}%
- {%
- \ifthenelse{\boolean{minted@frozencache}}%
- {\PackageError{minted}%
- {Missing style definition for #1 with frozencache}%
- {Missing style definition for #1 with frozencache}}%
- {\ifwindows
- \ShellEscape{%
- \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
- -P commandprefix=PYG#1
- > \minted@outputdir@windows\minted@cachedir@windows\@backslashchar%
- \ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}%
- \else
- \ShellEscape{%
- \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
- -P commandprefix=PYG#1
- > \minted@outputdir\minted@cachedir/%
- \ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}%
- \fi}%
- }%
- \begingroup
- \let\def\gdef
- \catcode\string``=12
- \catcode`\_=11
- \catcode`\-=11
- \catcode`\%=14
- \endlinechar=-1\relax
- \minted@input{%
- \minted@outputdir\minted@cachedir/\ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}%
- \endgroup
- \minted@addcachefile{\ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}}%
- {%
- \ifwindows
- \ShellEscape{%
- \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
- -P commandprefix=PYG#1 > \minted@outputdir@windows\minted@jobname.out.pyg}%
- \else
- \ShellEscape{%
- \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
- -P commandprefix=PYG#1 > \minted@outputdir\minted@jobname.out.pyg}%
- \fi
- \begingroup
- \let\def\gdef
- \catcode\string``=12
- \catcode`\_=11
- \catcode`\-=11
- \catcode`\%=14
- \endlinechar=-1\relax
- \minted@input{\minted@outputdir\minted@jobname.out.pyg}%
- \endgroup}%
- \ifstrempty{#1}{\minted@patch@PYGZsq}{}%
+\newcommand{\minted@generate@PYGdef}[1]{%
+ \ifthenelse{\boolean{minted@cache}}%
+ {\def\minted@pygstylepath@load{\minted@outputdir\minted@cachedir/#1.pygstyle}%
+ \minted@addcachefile{#1.pygstyle}}%
+ {\def\minted@pygstylepath@load{\minted@outputdir\minted@jobname.out.pyg}}%
+ \ifwindows
+ \StrSubstitute{\minted@pygstylepath@load}%
+ {/}{\@backslashchar}[\minted@pygstylepath@save]%
+ \else
+ \let\minted@pygstylepath@save\minted@pygstylepath@load
+ \fi
+ \IfFileExists{\minted@pygstylepath@load}%
+ {}%
+ {\ifthenelse{\boolean{minted@frozencache}}%
+ {\PackageError{minted}%
+ {Missing style definition for #1 with frozencache}%
+ {Missing style definition for #1 with frozencache}}%
+ {}%
+ \ShellEscape{%
+ \MintedPygmentize\space -S #1 -f latex -P commandprefix=PYG
+ > \minted@pygstylepath@save
+ }%
+ }%
+ \CatchFileDef{\minted@tmp@filecontents}%
+ {\minted@pygstylepath@load}{\catcode`@=11\catcode`\%=14\catcode``=12\endlinechar=-1}%
+ \begingroup
+ \let\PYG\relax
+ \minted@tmp@filecontents
+ \ifx\PYG\relax
+ \ifthenelse{\boolean{minted@frozencache}}%
+ {\PackageError{minted}%
+ {Outdated style definition for #1 with frozencache}%
+ {Outdated style definition for #1 with frozencache}}%
+ {}%
+ \ShellEscape{%
+ \MintedPygmentize\space -S #1 -f latex -P commandprefix=PYG
+ > \minted@pygstylepath@save
+ }%
+ \CatchFileDef{\minted@tmp@filecontents}%
+ {\minted@pygstylepath@load}{\catcode`@=11\catcode`\%=14\catcode``=12\endlinechar=-1}%
+ \minted@tmp@filecontents
+ \ifx\PYG\relax
+ \PackageError{minted}%
+ {Cannot find Pygments style #1}%
+ {Cannot find Pygments style #1}%
+ \fi
\fi
+ \expandafter\global\expandafter\let\csname minted@PYGdef@#1\endcsname%
+ \minted@tmp@filecontents
+ \endgroup
}
-\ifthenelse{\boolean{minted@draft}}{\renewcommand{\minted@checkstyle}[1]{}}{}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\minted@defstyle}
+% Define Pygments style macros. These are defined locally rather than globally, and redefined upon every use. Patch single quote macro if needed.
+% \begin{macrocode}
+\newcommand{\minted@defstyle}[1]{%
+ \edef\minted@style{#1}%
+ \ifcsname minted@PYGdef@\minted@style\endcsname\else
+ \expandafter\minted@generate@PYGdef\expandafter{\minted@style}%
+ \fi
+ \csname minted@PYGdef@\minted@style\endcsname
+ \minted@patch@PYGZsq
+}
+\ifthenelse{\boolean{minted@draft}}{\renewcommand{\minted@defstyle}[1]{}}{}
% \end{macrocode}
% \end{macro}
%
@@ -2597,7 +2667,7 @@
\minted@def@optcl@switch{texcomments}{-P texcomments}
\minted@def@optcl@switch{mathescape}{-P mathescape}
\minted@def@optfv@switch{linenos}
-\minted@def@opt{style}
+\minted@def@opt@detok{style}
% \end{macrocode}
%
% \pkg{fancyvrb} and \pkg{fvextra} options.
@@ -2674,6 +2744,7 @@
\minted@def@optfv@switch{breakanywhere}
\minted@def@optfv{breakanywheresymbolpre}
\minted@def@optfv{breakanywheresymbolpost}
+\minted@def@optfv{fontencoding}
% \end{macrocode}
%
% Finally, options specific to \pkg{minted}.
@@ -2700,6 +2771,22 @@
%
% \subsection{Internal helpers}
%
+% \begin{environment}{minted@snugshade*}
+% Define a custom version of \pkg{framed}'s |snugshade*| that takes a color as argument. This avoids the need to redefine |shadecolor|.
+% \begin{macrocode}
+\newenvironment{minted@snugshade*}[1]{%
+ \def\FrameCommand##1{\hskip\@totalleftmargin
+ \colorbox{#1}{##1}%
+ \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
+ \MakeFramed{\advance\hsize-\width
+ \@totalleftmargin\z@ \linewidth\hsize
+ \advance\labelsep\fboxsep
+ \@setminipage}%
+ }{\par\unskip\@minipagefalse\endMakeFramed}
+% \end{macrocode}
+% \end{environment}
+%
+%
% \begin{environment}{\minted@bgbox}
%
% Define an environment that may be wrapped around a |minted| environment to assign a background color. This is retained as a holdover from version 1.0. In most cases, it is probably better to use a dedicated framing package, such as \pkg{tcolorbox} or \pkg{mdframed}.
@@ -2715,13 +2802,12 @@
% \begin{macrocode}
\newenvironment{minted@colorbg}[1]{%
\setlength{\OuterFrameSep}{0pt}%
- \colorlet{shadecolor}{#1}%
\let\minted@tmp\FV@NumberSep
\edef\FV@NumberSep{%
\the\numexpr\dimexpr\minted@tmp+\number\fboxsep\relax sp\relax}%
\medskip
- \begin{snugshade*}}
- {\end{snugshade*}%
+ \begin{minted@snugshade*}{#1}}
+ {\end{minted@snugshade*}%
\medskip\noindent}
% \end{macrocode}
% \end{environment}
@@ -2804,6 +2890,73 @@
% \end{macro}
%
%
+% \begin{macro}{\MintedPython}
+% Python executable to be used for |autogobble|.
+% \begin{macrocode}
+\ifwindows
+ \newcommand{\MintedPython}{python}
+\else
+ \newcommand{\MintedPython}{python3}
+\fi
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\minted@check@MintedPython}
+% Check that |\MintedPython| is a valid executable before use. Swap |python| for |python3| and vice versa depending on what is available.
+% \begin{macrocode}
+\newcommand{\minted@check@MintedPython}{%
+ \ifcsname minted@MintedPython@\MintedPython\endcsname
+ \else
+ \let\minted@altpython\minted@undefined
+ \ifdefstring{\MintedPython}{python}{\def\minted@altpython{python3}}{}%
+ \ifdefstring{\MintedPython}{python3}{\def\minted@altpython{python}}{}%
+ \ifx\minted@altpython\minted@undefined\relax
+ \TestAppExists{\MintedPython}%
+ \ifAppExists
+ \expandafter\global\expandafter\let%
+ \csname minted@MintedPython@\MintedPython\endcsname\relax
+ \else
+ \PackageError{minted}%
+ {Failed to find Python executable \MintedPython;
+ check Python installation (including PATH),
+ or redefine \string\MintedPython}%
+ {Failed to find Python executable \MintedPython;
+ check Python installation (including PATH),
+ or redefine \string\MintedPython}%
+ \fi
+ \else
+ \ifcsname minted@MintedPython@\minted@altpython\endcsname
+ \let\MintedPython\minted@altpython
+ \else
+ \TestAppExists{\MintedPython}%
+ \ifAppExists
+ \expandafter\global\expandafter\let%
+ \csname minted@MintedPython@\MintedPython\endcsname\relax
+ \else
+ \TestAppExists{\minted@altpython}%
+ \ifAppExists
+ \expandafter\global\expandafter\let%
+ \csname minted@MintedPython@\minted@altpython\endcsname\relax
+ \let\MintedPython\minted@altpython
+ \else
+ \PackageError{minted}%
+ {Failed to find Python executables python or python3;
+ check Python installation (including PATH),
+ or redefine \string\MintedPython}%
+ {Failed to find Python executables python or python3;
+ check Python installation (including PATH),
+ or redefine \string\MintedPython}%
+ \fi
+ \fi
+ \fi
+ \fi
+ \fi
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
% \begin{macro}{\minted@pygmentize}
%
% Pygmentize a file (default: |\minted@outputdir\minted@jobname.pyg|) using the options provided.
@@ -2820,7 +2973,7 @@
%
% \begin{macrocode}
\newcommand{\minted@pygmentize}[2][\minted@outputdir\minted@jobname.pyg]{%
- \minted@checkstyle{\minted@get@opt{style}{default}}%
+ \minted@defstyle{\minted@get@opt{style}{default}}%
\stepcounter{minted@pygmentizecounter}%
\ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}%
{\def\minted@codefile{\minted@outputdir\minted@jobname.pyg}}%
@@ -2858,50 +3011,15 @@
{%
\ifminted@frozencache
\else
- \ifx\XeTeXinterchartoks\minted@undefined
- \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}%
- {\edef\minted@hash{\pdf@filemdfivesum{#1}%
- \pdf@mdfivesum{\minted@cmd autogobble(\ifx\FancyVerbStartNum\z@ 0\else\FancyVerbStartNum\fi-\ifx\FancyVerbStopNum\z@ 0\else\FancyVerbStopNum\fi)}}}%
- {\edef\minted@hash{\pdf@filemdfivesum{#1}%
- \pdf@mdfivesum{\minted@cmd}}}%
- \else
- \ifx\mdfivesum\minted@undefined
- \immediate\openout\minted@code\minted@jobname.mintedcmd\relax
- \immediate\write\minted@code{\minted@cmd}%
- \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}%
- {\immediate\write\minted@code{autogobble(\ifx\FancyVerbStartNum\z@ 0\else\FancyVerbStartNum\fi-\ifx\FancyVerbStopNum\z@ 0\else\FancyVerbStopNum\fi)}}{}%
- \immediate\closeout\minted@code
- \edef\minted@argone@esc{#1}%
- \StrSubstitute{\minted@argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@argone@esc]%
- \StrSubstitute{\minted@argone@esc}{"}{\@backslashchar"}[\minted@argone@esc]%
- \edef\minted@tmpfname@esc{\minted@outputdir\minted@jobname}%
- \StrSubstitute{\minted@tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@tmpfname@esc]%
- \StrSubstitute{\minted@tmpfname@esc}{"}{\@backslashchar"}[\minted@tmpfname@esc]%
- %Cheating a little here by using ASCII codes to write `{` and `}`
- %in the Python code
- \def\minted@hashcmd{%
- \detokenize{python -c "import hashlib; import os;
- hasher = hashlib.sha1();
- f = open(os.path.expanduser(os.path.expandvars(\"}\minted@tmpfname@esc.mintedcmd\detokenize{\")), \"rb\");
- hasher.update(f.read());
- f.close();
- f = open(os.path.expanduser(os.path.expandvars(\"}\minted@argone@esc\detokenize{\")), \"rb\");
- hasher.update(f.read());
- f.close();
- f = open(os.path.expanduser(os.path.expandvars(\"}\minted@tmpfname@esc.mintedmd5\detokenize{\")), \"w\");
- macro = \"\\edef\\minted@hash\" + chr(123) + hasher.hexdigest() + chr(125) + \"\";
- f.write(\"\\makeatletter\" + macro + \"\\makeatother\\endinput\n\");
- f.close();"}}%
- \ShellEscape{\minted@hashcmd}%
- \minted@input{\minted@outputdir\minted@jobname.mintedmd5}%
- \else
- \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}%
- {\edef\minted@hash{\mdfivesum file {#1}%
- \mdfivesum{\minted@cmd autogobble(\ifx\FancyVerbStartNum\z@ 0\else\FancyVerbStartNum\fi-\ifx\FancyVerbStopNum\z@ 0\else\FancyVerbStopNum\fi)}}}%
- {\edef\minted@hash{\mdfivesum file {#1}%
- \mdfivesum{\minted@cmd}}}%
- \fi
- \fi
+ \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}%
+ {\edef\minted@hash{%
+ \pdf@filemdfivesum{#1}%
+ \pdf@mdfivesum{\minted@cmd\space%
+ autogobble(\the\numexpr\FancyVerbStartNum\relax-%
+ \the\numexpr\FancyVerbStopNum\relax)}}}%
+ {\edef\minted@hash{%
+ \pdf@filemdfivesum{#1}%
+ \pdf@mdfivesum{\minted@cmd}}}%
\edef\minted@infile{\minted@cachedir/\minted@hash.pygtex}%
\IfFileExists{\minted@infile}{}{%
\ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}{%
@@ -2951,20 +3069,21 @@
\StrSubstitute{\minted@tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@tmpfname@esc]%
\StrSubstitute{\minted@tmpfname@esc}{"}{\@backslashchar"}[\minted@tmpfname@esc]%
%Need a version of open() that supports encoding under Python 2
+ \minted@check@MintedPython
\edef\minted@autogobblecmd{%
\ifminted@kpsewhich
\ifwindows
\detokenize{for /f "usebackq tokens=*" }\@percentchar\detokenize{a in (`kpsewhich} #1\detokenize{`) do}\space
\fi
- \fi
- \detokenize{python -c "import sys; import os;
+ \fi
+ \MintedPython\detokenize{ -c "import sys; import os;
import textwrap;
from io import open;
fname = }%
\ifminted@kpsewhich
- \detokenize{sys.argv[1];}\space%
+ \detokenize{sys.argv[1];}\space
\else
- \detokenize{os.path.expanduser(os.path.expandvars(\"}\minted@argone@esc\detokenize{\"));}\space%
+ \detokenize{os.path.expanduser(os.path.expandvars(\"}\minted@argone@esc\detokenize{\"));}\space
\fi
\detokenize{f = open(fname, \"r\", encoding=\"}\minted@encoding\detokenize{\") if os.path.isfile(fname) else None;
t = f.readlines() if f is not None else None;
@@ -2972,10 +3091,10 @@
f.close() if f is not None else None;
tmpfname = os.path.expanduser(os.path.expandvars(\"}\minted@tmpfname@esc.pyg\detokenize{\"));
f = open(tmpfname, \"w\", encoding=\"}\minted@encoding\detokenize{\") if t is not None else None;
- fvstartnum = }\ifx\FancyVerbStartNum\z@ 0\else\FancyVerbStartNum\fi\detokenize{;
- fvstopnum = }\ifx\FancyVerbStopNum\z@ 0\else\FancyVerbStopNum\fi\detokenize{;
- s = fvstartnum-1 if fvstartnum != 0 else 0;
- e = fvstopnum if fvstopnum != 0 else len(t_opt);
+ fvstartnum = }\the\numexpr\FancyVerbStartNum\detokenize{;
+ fvstopnum = }\the\numexpr\FancyVerbStopNum\detokenize{;
+ s = max(0, fvstartnum-1);
+ e = min(s, fvstopnum if fvstopnum > 0 else len(t_opt));
[f.write(textwrap.dedent(\"\".join(x))) for x in (t_opt[0:s], t_opt[s:e], t_opt[e:]) if x and t is not None];
f.close() if t is not None else os.remove(tmpfname);"}%
\ifminted@kpsewhich
@@ -3000,9 +3119,7 @@
% The |bgcolor| option needs to be dealt with in different ways depending on whether we are using |\mintinline|. It is simplest to apply this option here, so that the macro redefinitions may be local and thus do not need to be manually reset later.
% \begin{macrocode}
\newcommand{\minted@inputpyg}{%
- \expandafter\let\expandafter\minted@PYGstyle%
- \csname PYG\minted@get@opt{style}{default}\endcsname
- \VerbatimPygments{\PYG}{\minted@PYGstyle}%
+ \VerbatimPygments{\PYG}{\PYG}%
\ifthenelse{\boolean{minted@isinline}}%
{\ifthenelse{\equal{\minted@get@opt{breaklines}{false}}{true}}%
{\let\FV@BeginVBox\relax
@@ -3089,10 +3206,11 @@
%
% Now that the settings macros exist, we go ahead and create any needed defaults.
%
-% PHP should use |startinline| for |\mintinline|. Visible tabs should have a specified color so that they don't change colors when used to indent multiline strings or comments.
+% PHP should use |startinline| for |\mintinline|. Visible tabs should have a specified color so that they don't change colors when used to indent multiline strings or comments. Leading/trailing empty lines should be preserved by default.
% \begin{macrocode}
\setmintedinline[php]{startinline=true}
\setminted{tabcolor=black}
+\setminted{stripnl=false}
% \end{macrocode}
%
% \begin{macro}{\usemintedstyle}
diff --git a/Master/texmf-dist/source/latex/minted/minted.ins b/Master/texmf-dist/source/latex/minted/minted.ins
index 190154a6523..af12d42e4a3 100644
--- a/Master/texmf-dist/source/latex/minted/minted.ins
+++ b/Master/texmf-dist/source/latex/minted/minted.ins
@@ -3,7 +3,7 @@
\askforoverwritefalse
\preamble
-Copyright 2013--2017 Geoffrey M. Poore
+Copyright 2013--2021 Geoffrey M. Poore
Copyright 2010--2011 Konrad Rudolph
This work may be distributed and/or modified under the