From b9de8b37ede65e75de420bd3814aa62f4e1017d6 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 10 Sep 2015 20:56:54 +0000 Subject: minted (10sep15) git-svn-id: svn://tug.org/texlive/trunk@38339 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/source/latex/minted/minted.dtx | 975 ++++++++++++++++++----- 1 file changed, 763 insertions(+), 212 deletions(-) (limited to 'Master/texmf-dist/source') diff --git a/Master/texmf-dist/source/latex/minted/minted.dtx b/Master/texmf-dist/source/latex/minted/minted.dtx index 29826af3f10..e0db8bd3bd5 100644 --- a/Master/texmf-dist/source/latex/minted/minted.dtx +++ b/Master/texmf-dist/source/latex/minted/minted.dtx @@ -31,7 +31,7 @@ %\NeedsTeXFormat{LaTeX2e} %\ProvidesPackage{minted} %<*package> - [2015/01/31 v2.0 Yet another Pygments shim for LaTeX] + [2015/09/09 v2.1 Yet another Pygments shim for LaTeX] % %<*driver> \documentclass{ltxdoc} @@ -156,6 +156,7 @@ \MakeShortVerb{\|}% \par} +\edef\hashchar{\string#} \makeatother \newcommand{\hide}[1]{} @@ -170,7 +171,7 @@ % % \fi % -% \CheckSum{2686} +% \CheckSum{3283} % % \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 @@ -189,6 +190,20 @@ % Right brace \} Tilde \~} % % +% +% \begin{changelog}{v2.1}{2015/09/09} +% \item Changing the highlighting style now no longer involves re-highlighing code. Style may be changed with almost no overhead. +% \item Improved control of automatic line breaks. New option \texttt{breakanywhere} allows line breaks anywhere when \texttt{breaklines=true}. The pre-break and post-break symbols for these types of breaks may be set with \texttt{breakanywheresymbolpre} and \texttt{breakanywheresymbolpost} (\#79). New option \texttt{breakafter} allows specifying characters after which line breaks are allowed. Breaks between adjacent, identical characters may be controlled with \texttt{breakaftergroup}. The pre-break and post-break symbols for these types of breaks may be set with \texttt{breakaftersymbolpre} and \texttt{breakaftersymbolpost}. +% \item \texttt{breakbytoken} now only breaks lines between tokens that are separated by spaces, matching the documentation. The new option \texttt{breakbytokenanywhere} allows for breaking between tokens that are immediately adjacent. Fixed a bug in \texttt{\string\mintinline} that produced a following linebreak when \texttt{\string\mintinline} was the first thing in a paragraph and \texttt{breakbytoken} was true (\#77). +% \item Fixed a bug in draft mode option handling for \texttt{\string\inputminted} (\#75). +% \item Fixed a bug with \texttt{\string\MintedPygmentize} when a custom \texttt{pygmentize} was specified and there was no \texttt{pygmentize} on the default path (\#62). +% \item Added note to docs on caching large numbers of code blocks under OS~X (\#78). +% \item Added discussion of current limitations of \texttt{texcomments} (\#66) and \texttt{escapeinside} (\#70). +% \item PGF/Ti\textit{k}Z externalization is automatically detected and supported (\#73). +% \item The package is now compatible with \LaTeX\ files whose names contain spaces (\#85). +% \end{changelog} +% +% % \begin{changelog}{v2.0}{2015/01/31} % \item Added the compatibility package \texttt{minted1}, which provides the \pkg{minted} 1.7 code. This may be loaded when 1.7 compatibility is required. This package works with other packages that \texttt{\string\RequirePackage\{minted\}}, so long as it is loaded first. % \item Moved all old \texttt{\string\changes} into \texttt{changelog}. @@ -440,6 +455,7 @@ % % % \subsection{Installing \pkg{minted}} +% \label{sec:installing:installing} % % You can probably install \pkg{minted} with your \TeX\ distribution's package manager. Otherwise, or if you want the absolute latest version, you can install it manually by following the directions below. % @@ -474,6 +490,7 @@ % \section{Basic usage} % % \subsection{Preliminary} +% \label{sec:basic:preliminary} % % Since \pkg{minted} makes calls to the outside world (that is, \app{Pygments}), you need to tell the % \LaTeX{} processor about this by passing it the |-shell-escape| option or it won't allow such calls. @@ -493,6 +510,15 @@ % You should be aware that using |-shell-escape| allows \LaTeX\ to run potentially arbitrary commands on your system. It is probably best to use |-shell-escape| only when you need it, and to use it only with documents from trusted sources. % % +% \subsubsection*{Working with OS X} +% +% If you are using \pkg{minted} with some versions/configurations of OS X, and are using caching with a large number of code blocks ($>256$), you may receive an error like +%\begin{Verbatim} +%OSError: [Errno 24] Too many open files: +%\end{Verbatim} +% This is due to the way files are handled by the operating system, combined with the way that caching works. To resolve this, you may use the OS X commands |launchctl limit maxfiles| or |ulimit -n| to increase the number of files that may be used. +% +% % % \subsection{A minimal complete example} % @@ -681,13 +707,13 @@ % \DescribeMacro{cache=\meta{boolean} (default: true)} % \pkg{minted} works by saving code to a temporary file, highlighting the code via \app{Pygments} and saving the output to another temporary file, and inputting the output into the \LaTeX\ document. This process can become quite slow if there are several chunks of code to highlight. To avoid this, the package provides a |cache| option. This is on by default. % -% The |cache| option creates a directory |_minted-|\meta{jobname} in the document's root directory (this may be customized with the |cachedir| option). Files of highlighted code are stored in this directory, so that the code will not have to be highlighted again in the future. In most cases, caching will significantly speed up document compilation. +% The |cache| option creates a directory |_minted-|\meta{jobname} in the document's root directory (this may be customized with the |cachedir| option).\footnote{The directory is actually named using a ``sanitized'' copy of \meta{jobname}, in which spaces and asterisks have been replaced by underscores, and double quotation marks have been stripped. If the file name contains spaces, \texttt{\string\jobname} will contain a quote-wrapped name, except under older versions of MiKTeX which used the name with spaces replaced by asterisks. Using a ``sanitized'' \meta{jobname} is simpler than accomodating the various escaping conventions.} Files of highlighted code are stored in this directory, so that the code will not have to be highlighted again in the future. In most cases, caching will significantly speed up document compilation. % % Cached files that are no longer in use are automatically deleted.\footnote{This depends on the main auxiliary file not being deleted or becoming corrupted. If that happens, you could simply delete the cache directory and start over.} % % % \DescribeMacro{cachedir=\meta{directory} (def:~\_minted-\meta{jobname})} -% This allows the directory in which cached files are stored to be specified. Paths should use forward spaces, even under Windows. Paths that include spaces are not allowed. +% This allows the directory in which cached files are stored to be specified. Paths should use forward spaces, even under Windows. % % Note that this directory is relative to the |outputdir|, if an |outputdir| is specified. % @@ -845,14 +871,53 @@ % % \item[baselinestretch (+auto+\textbar dimension) (+auto+)] % Value to use as for baselinestretch inside the listing. +% +% \item[breakafter (string) (+\meta{none}+)] +% Break lines after specified characters, not just at spaces, when \texttt{breaklines=true}. For example, \texttt{breakafter=-/} would allow breaks after any hyphens or slashes. Special characters given to \texttt{breakafter} should be backslash-escaped (usually \texttt{\hashchar}, \texttt{\{}, \texttt{\}}, \texttt{\%}, \texttt{[}, \texttt{]}; the backslash \texttt{\textbackslash} may be obtained via \texttt{\textbackslash\textbackslash}). +% +% \begin{longexample} +% \begin{minted}[breaklines, breakafter=d]{python} +% some_string = 'SomeTextThatGoesOnAndOnForSoLongThatItCouldNeverFitOnOneLine' +% \end{minted} +% \end{longexample} +% +% \item[breakaftergroup] (boolean) (+true+) +% When \texttt{breakafter} is used, group all adjacent identical characters together, and only allow a break after the last character. +% +% \item[breakaftersymbolpre (string) (+\string\,\string\footnotesize\string\ensuremath\{\_\string\rfloor\}, \,\footnotesize\ensuremath{_\rfloor}+)] +% The symbol inserted pre-break for breaks inserted by \texttt{breakafter}. +% +% \item[breakaftersymbolpost (string) (+\meta{none}+)] +% The symbol inserted post-break for breaks inserted by \texttt{breakafter}. +% +% \item[breakanywhere (boolean) (+false+)] +% Break lines anywhere, not just at spaces, when \texttt{breaklines=true}. +% +% \begin{longexample} +% \begin{minted}[breaklines, breakanywhere]{python} +% some_string = 'SomeTextThatGoesOnAndOnForSoLongThatItCouldNeverFitOnOneLine' +% \end{minted} +% \end{longexample} +% +% \item[breakanywheresymbolpre (string) (+\string\,\string\footnotesize\string\ensuremath\{\_\string\rfloor\}, \,\footnotesize\ensuremath{_\rfloor}+)] +% The symbol inserted pre-break for breaks inserted by \texttt{breakanywhere}. +% +% \item[breakanywheresymbolpost (string) (+\meta{none}+)] +% The symbol inserted post-break for breaks inserted by \texttt{breakanywhere}. +% % \item[breakautoindent (boolean) (+true+)] % When a line is broken, automatically indent the continuation lines to the indentation level of the first line. When \texttt{breakautoindent} and \texttt{breakindent} are used together, the indentations add. This indentation is combined with \texttt{breaksymbolindentleft} to give the total actual left indentation. Does not apply to \texttt{\string\mintinline}. % \item[breakbytoken (boolean) (+false+)] -% Only break lines at spaces that are not within tokens; prevent tokens from being split by line breaks. By default, line breaking occurs at the space nearest the margin. While this minimizes the number of line breaks that are necessary, it can be inconvenient if the break occurs in the middle of a string or similar token. This is not compatible with \texttt{draft} mode. A complete list of Pygments tokens is available at \url{http://pygments.org/docs/tokens/}. +% Only break lines at locations that are not within tokens; prevent tokens from being split by line breaks. By default, \texttt{breaklines} causes line breaking at the space nearest the margin. While this minimizes the number of line breaks that are necessary, it can be inconvenient if a break occurs in the middle of a string or similar token. +% +% This is not compatible with \texttt{draft} mode. A complete list of Pygments tokens is available at \url{http://pygments.org/docs/tokens/}. If the breaks provided by \texttt{breakbytoken} occur in unexpected locations, it may indicate a bug or shortcoming in the Pygments lexer for the language. +% +% \item[breakbytokenanywhere (boolean) (+false+)] +% Like \texttt{breakbytoken}, but also allows line breaks between immediately adjacent tokens, not just between tokens that are separated by spaces. Using \texttt{breakbytokenanywhere} with \texttt{breakanywhere} is redundant. % \item[breakindent (dimension) (+0pt+)] % When a line is broken, indent the continuation lines by this amount. When \texttt{breakautoindent} and \texttt{breakindent} are used together, the indentations add. This indentation is combined with \texttt{breaksymbolindentleft} to give the total actual left indentation. Does not apply to \texttt{\string\mintinline}. % \item[breaklines (boolean) (+false+)] -% Automatically break long lines in \texttt{minted} environments and \texttt{\string\mint} commands, and wrap longer lines in \texttt{\string\mintinline}. Currently, automatic breaks \emph{only} occur at space characters. By default, the break will be at the space character closest to the margin. You can prevent space characters within tokens (for example, within strings) from being used as a break location with the option \texttt{breakbytoken} (this is not compatible with \texttt{draft} mode). If you need breaks at another location, you may use \texttt{escapeinside} to escape to \LaTeX\ and then insert a manual break. For example, use \texttt{escapeinside=||}, and then insert \texttt{|\textbackslash\textbackslash|} at the appropriate point. (Note that \texttt{escapeinside} does not work within strings.) +% Automatically break long lines in \texttt{minted} environments and \texttt{\string\mint} commands, and wrap longer lines in \texttt{\string\mintinline}. By default, automatic breaks occur at space characters. Use \texttt{breakanywhere} to enable breaking anywhere; use \texttt{breakbytoken}, \texttt{breakbytokenanywhere}, and \texttt{breakafter} for more fine-tuned breaking. Using \texttt{escapeinside} to escape to \LaTeX\ and then insert a manual break is also an option. For example, use \texttt{escapeinside=||}, and then insert \texttt{|\textbackslash\textbackslash|} at the appropriate point. (Note that \texttt{escapeinside} does not work within strings.) % % \begin{example} % ...text. @@ -890,7 +955,7 @@ %\end{Verbatim} % uses the \pkg{etoolbox} package to redefine \texttt{\string\colorbox} within all \texttt{minted} environments. % -% Automatic line breaks will not work with \texttt{showspaces=true}. You may be able to change the definition of \texttt{\string\FV@Space} if you need this; see the \pkg{fancyvrb} implementation for details. +% Automatic line breaks will not work with \texttt{showspaces=true} unless you use \texttt{breakanywhere}. You may be able to change the definition of \texttt{\string\FV@Space} if you need this; see the \pkg{fancyvrb} implementation for details. % % \item[breaksymbol (string) (+breaksymbolleft+)] % Alias for \texttt{breaksymbolleft}. @@ -966,7 +1031,9 @@ % \item[encoding (string) (system-specific)] % Sets the file encoding that \app{Pygments} expects. See also +outencoding+. % \item[escapeinside (string) (\meta{none})] -% Escape to \LaTeX\ between the two characters specified in \texttt{\string(string\string)}. All code between the two characters will be interpreted as \LaTeX\ and typeset accordingly. This allows for additional formatting. Escaping does not work inside strings and comments (for comments, there is \texttt{texcomments}). The escape characters need not be identical. Special \LaTeX\ characters must be escaped when they are used as the escape characters (for example, \texttt{escapeinside=\textbackslash\#\textbackslash\%}). Requires \app{Pygments} 2.0\string+. +% Escape to \LaTeX\ between the two characters specified in \texttt{\string(string\string)}. All code between the two characters will be interpreted as \LaTeX\ and typeset accordingly. This allows for additional formatting. The escape characters need not be identical. Special \LaTeX\ characters must be escaped when they are used as the escape characters (for example, \texttt{escapeinside=\textbackslash\#\textbackslash\%}). Requires \app{Pygments} 2.0\string+. +% +% \textbf{Escaping does not work inside strings and comments (for comments, there is \texttt{texcomments}). As of Pygments 2.0.2, this means that escaping is ``fragile'' with some lexers.} Due to the way that Pygments implements \texttt{escapeinside}, any ``escaped'' \LaTeX\ code that resembles a string or comment for the current lexer may break \texttt{escapeinside}. There is a \href{https://bitbucket.org/birkenfeld/pygments-main/issue/1118}{Pygments issue} for this case. Additional details and a limited workaround for some scenarios are available on the \href{https://github.com/gpoore/minted/issues/70#issuecomment-111729930}{\pkg{minted} GitHub site}. % % \begin{example} % \begin{minted}[escapeinside=||]{py} @@ -1078,6 +1145,8 @@ % Usage as in package \pkg{listings}. See the note under \texttt{escapeinside} regarding math and ligatures. % \item[texcomments (boolean) (+false+)] % Enables \LaTeX{} code inside comments. The newer name for +texcl+. See the note under \texttt{escapeinside} regarding math and ligatures. +% +% As of Pygments 2.0.2, \texttt{texcomments} fails with multiline C/C\detokenize{++} preprocessor directives, and may fail in some other circumstances. This is because preprocessor directives are \href{http://pygments.org/docs/tokens/}{tokenized as \texttt{Comment.Preproc}}, so \texttt{texcomments} causes preprocessor directives to be treated as literal \LaTeX\ code. \href{https://bitbucket.org/birkenfeld/pygments-main/issue/1086/wrong-processing-of-in-c-c-macros-if-is}{An issue has been opened} at the Pygments site; additional details are also available on the \href{https://github.com/gpoore/minted/issues/66}{\pkg{minted} GitHub site}. % \item[xleftmargin (dimension) (+0+)] % Indentation to add before the listing. % \item[xrightmargin (dimension) (+0+)] @@ -1167,6 +1236,7 @@ % In some cases, \pkg{minted} may not give the desired result due to other document settings that it cannot control. Common issues are described below, with workarounds or solutions. You may also wish to search \href{http://tex.stackexchange.com/}{tex.stackexchange.com} or ask a question there, if you are working with \pkg{minted} in a non-typical context. % % \begin{itemize} +% \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{When I use \pkg{minted} with KOMA-Script document classes, I get warnings about \texttt{\string\float@addtolists}.} \pkg{minted} uses the \pkg{float} package to produce floated listings, but this conflicts with the way KOMA-Script does floats. Load the package \pkg{scrhack} to resolve the conflict. Or use \pkg{minted}'s |newfloat| package option. % \item \textbf{Tilde characters \texttt{\string~} are raised, almost like superscripts.} % This is a font issue. You need a different font encoding, possibly with a different font. Try |\usepackage[T1]{fontenc}|, perhaps with |\usepackage{lmodern}|, or something similar. @@ -1235,6 +1305,7 @@ % \item \textbf{I want to use the command-line option \texttt{-output-directory}, or MiKTeX's \texttt{-aux-directory}, but am getting errors.} Use the package option |outputdir| to specify the location of the output directory. Unfortunately, there is no way for \pkg{minted} to detect the output directory automatically. % % \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. % \end{itemize} % % @@ -1315,12 +1386,19 @@ % \end{macro} % % -% \begin{macro}{\minted@cachedir} -% Set the directory in which cached content is saved. The default uses a |minted-| prefix followed by a sanitized |\jobname| (spaces and asterisks replaced). +% \begin{macro}{\minted@jobname} +% At various points, temporary files and directories will need to be named after the main |.tex| file. The typical way to do this is to use |\jobname|. However, if the file name contains spaces, then |\jobname| will contain the name wrapped in quotes (older versions of MiKTeX replace spaces with asterisks instead, and \texttt{XeTeX} apparently \href{http://tex.stackexchange.com/a/93829/10742}{allows double quotes within file names}, in which case names are wrapped in single quotes}). While that is perfectly fine for working with \LaTeX\ internally, it causes problems with |\write18|, since quotes will end up in unwanted locations in shell commands. It would be possible to strip the wrapping quotation marks when they are present, and maintain any spaces in the file name. But it is simplest to create a ``sanitized'' version of |\jobname| in which spaces and asterisks are replaced by underscores, and double quotes are stripped. % \begin{macrocode} \StrSubstitute{\jobname}{ }{_}[\minted@jobname] +\StrSubstitute{\minted@jobname}{*}{_}[\minted@jobname] \StrSubstitute{\minted@jobname}{"}{}[\minted@jobname] -\StrSubstitute{\minted@jobname}{*}{-}[\minted@jobname] +% \end{macrocode} +% \end{macro} +% +% +% \begin{macro}{\minted@cachedir} +% Set the directory in which cached content is saved. The default uses a |minted-| prefix followed by the sanitized |\minted@jobname|. +% \begin{macrocode} \newcommand{\minted@cachedir}{\detokenize{_}minted-\minted@jobname} \let\minted@cachedir@windows\minted@cachedir \define@key{minted}{cachedir}{% @@ -1374,11 +1452,16 @@ % \end{macro} % % -% Process package options. Proceed with everything that immediately relies upon them. +% Process package options. Proceed with everything that immediately relies upon them. If PGF/Ti\textit{k}Z externalization is in use, switch on |draft| mode and turn off |cache|. Externalization involves compiling the \emph{entire} document; all parts not related to the current image are ``silently thrown away.'' \pkg{minted} needs to cooperate with that by not writing any temp files or creating any directories. % % \begin{macrocode} \ProcessKeyvalOptions* \ifthenelse{\boolean{minted@newfloat}}{\RequirePackage{newfloat}}{} +\ifcsname tikzexternalrealjob\endcsname + \minted@drafttrue + \minted@cachefalse +\else +\fi \ifthenelse{\boolean{minted@cache}}{% \AtEndOfPackage{\ProvideDirectory{\minted@outputdir\minted@cachedir}}}{} % \end{macrocode} @@ -1410,7 +1493,7 @@ % \begin{macro}{\minted@infile} % Define a default name for files of highlighted content that are brought it. Caching will redefine this. We start out with the default, non-caching value. % \begin{macrocode} -\newcommand{\minted@infile}{\jobname.out.pyg} +\newcommand{\minted@infile}{\minted@jobname.out.pyg} % \end{macrocode} % \end{macro} % @@ -1555,12 +1638,12 @@ % otherwise, it will contain the full path of the application. % % \begin{macrocode} - \DeleteFile{\jobname.aex} + \DeleteFile{\minted@jobname.aex} \immediate\write18{for \string^\@percentchar i in (#1.exe #1.bat #1.cmd) - do set >"\jobname.aex" >"\jobname.aex"} + do set >"\minted@jobname.aex" >"\minted@jobname.aex"} %$ <- balance syntax highlighting - \immediate\openin\minted@appexistsfile\jobname.aex + \immediate\openin\minted@appexistsfile\minted@jobname.aex \expandafter\def\expandafter\@tmp@cr\expandafter{\the\endlinechar} \endlinechar=-1\relax \readline\minted@appexistsfile to \minted@apppathifexists @@ -1569,17 +1652,17 @@ {\AppExistsfalse} {\AppExiststrue} \immediate\closein\minted@appexistsfile - \DeleteFile{\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} - \immediate\write18{which "#1" && touch "\jobname.aex"} - \IfFileExists{\jobname.aex} + \immediate\write18{which "#1" && touch "\minted@jobname.aex"} + \IfFileExists{\minted@jobname.aex} {\AppExiststrue - \DeleteFile{\jobname.aex}} + \DeleteFile{\minted@jobname.aex}} {\AppExistsfalse} \fi } @@ -1751,6 +1834,8 @@ \edef\minted@ampchar{\string&} \edef\minted@underscorechar{\string_} \edef\minted@tildechar{\string~} +\edef\minted@leftsquarebracket{\string[} +\edef\minted@rightsquarebracket{\string]} \newcommand{\minted@escchars}{% \let\#\minted@hashchar \let\%\@percentchar @@ -1762,9 +1847,11 @@ \let\\\@backslashchar \let~\minted@tildechar \let\~\minted@tildechar + \let\[\minted@leftsquarebracket + \let\]\minted@rightsquarebracket } %$ <- highlighting % \end{macrocode} -% \end{macro} +% \end{macro} % % % \begin{macro}{\minted@def@optcl@e} @@ -1827,108 +1914,6 @@ % \end{macro} % % -% \begin{macro}{\minted@def@optcl@style} -% -% Define an option for styles. These are defined independently because styles need slightly different syntax. Also, it is conventient to create style macros when styles are set. Otherwise, it would be necessary to check for the existence of style macros at the beginning of every command or environment. -% \begin{macrocode} -\newcommand{\minted@def@optcl@style}{% - \define@key{minted@opt@g}{style}{% - \minted@addto@optlistcl{\minted@optlistcl@g}% - {-P style=##1 -P commandprefix=PYG##1}% - \minted@checkstyle{##1}% - \@namedef{minted@opt@g:style}{##1}}% - \define@key{minted@opt@g@i}{style}{% - \minted@addto@optlistcl{\minted@optlistcl@g@i}% - {-P style=##1 -P commandprefix=PYG##1}% - \minted@checkstyle{##1}% - \@namedef{minted@opt@g@i:style}{##1}}% - \define@key{minted@opt@lang}{style}{% - \minted@addto@optlistcl@lang{minted@optlistcl@lang\minted@lang}% - {-P style=##1 -P commandprefix=PYG##1}% - \minted@checkstyle{##1}% - \@namedef{minted@opt@lang\minted@lang:style}{##1}}% - \define@key{minted@opt@lang@i}{style}{% - \minted@addto@optlistcl@lang{minted@optlistcl@lang\minted@lang @i}% - {-P style=##1 -P commandprefix=PYG##1}% - \minted@checkstyle{##1}% - \@namedef{minted@opt@lang\minted@lang @i:style}{##1}}% - \define@key{minted@opt@cmd}{style}{% - \minted@addto@optlistcl{\minted@optlistcl@cmd}% - {-P style=##1 -P commandprefix=PYG##1}% - \minted@checkstyle{##1}% - \@namedef{minted@opt@cmd:style}{##1}}% -} -% \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\minted@checkstyle} -% Make sure that style macros exist. -% -% 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. And we patch the single quote macro from Pygments 1.6+ if the \pkg{upquote} package is in use. The conditionals for the patch definition are borrowed from \pkg{upquote}. If we are in the preamble, we check for patching twice, once immediately and once at the beginning of the document, so that \pkg{upquote} will be detected even if it is loaded after \pkg{minted}. -% \begin{macrocode} -\newcommand{\minted@patch@Zsq}[1]{% - \ifx\upquote@cmtt\minted@undefined\else - \ifx\encodingdefault\upquote@OTone - \ifx\ttdefault\upquote@cmtt - \expandafter\ifdefstring\expandafter{\csname PYG#1Zsq\endcsname}{\char`\'}% - {\expandafter\gdef\csname PYG#1Zsq\endcsname{\char13 }}{}% - \else - \expandafter\ifdefstring\expandafter{\csname PYG#1Zsq\endcsname}{\char`\'}% - {\expandafter\gdef\csname PYG#1Zsq\endcsname{\textquotesingle}}{}% - \fi - \else - \expandafter\ifdefstring\expandafter{\csname PYG#1Zsq\endcsname}{\char`\'}% - {\expandafter\gdef\csname PYG#1Zsq\endcsname{\textquotesingle}}{}% - \fi - \fi -} -\newcommand{\minted@checkstyle}[1]{% - \ifcsname minted@styleloaded@#1\endcsname\else - \expandafter\gdef\csname minted@styleloaded@#1\endcsname{}% - \ifthenelse{\boolean{minted@cache}}% - {\IfFileExists{\minted@outputdir\minted@cachedir/#1.pygstyle}{}{% - \ifwindows - \immediate\write18{\MintedPygmentize\space -S #1 -f latex - -P commandprefix=PYG#1 - > "\minted@outputdir@windows\minted@cachedir@windows\@backslashchar#1.pygstyle"}% - \else - \immediate\write18{\MintedPygmentize\space -S #1 -f latex - -P commandprefix=PYG#1 - > "\minted@outputdir\minted@cachedir/#1.pygstyle"}% - \fi - }% - \begingroup - \let\def\gdef - \endlinechar=-1\relax - \minted@input{\minted@outputdir\minted@cachedir/#1.pygstyle}% - \endgroup - \minted@addcachefile{#1.pygstyle}}% - {\ifwindows - \immediate\write18{\MintedPygmentize\space -S #1 -f latex - -P commandprefix=PYG#1 > "\minted@outputdir@windows\jobname.out.pyg"}% - \else - \immediate\write18{\MintedPygmentize\space -S #1 -f latex - -P commandprefix=PYG#1 > "\minted@outputdir\jobname.out.pyg"}% - \fi - \begingroup - \let\def\gdef - \endlinechar=-1\relax - \minted@input{\minted@outputdir\jobname.out.pyg}% - \endgroup}% - \ifx\@onlypreamble\@notprerr - \minted@patch@Zsq{#1}% - \else - \minted@patch@Zsq{#1}% - \AtBeginDocument{\minted@patch@Zsq{#1}}% - \fi - \fi -} -\ifthenelse{\boolean{minted@draft}}{\renewcommand{\minted@checkstyle}[1]{}}{} -% \end{macrocode} -% \end{macro} -% -% % \begin{macro}{\minted@def@optcl@switch} % % Define a switch or boolean option that is passed to Pygments, which is |true| when no value is specified. @@ -2095,48 +2080,6 @@ % % Before actually creating the option-definition macro, we need a few helper macros. % -% \begin{macro}{\minted@get@opt} -% We need a way to traverse the hierarchy of values for a given key and return the current value that has precedence. In doing this, we need to specify a default value to use if no value is found. When working with \pkg{minted}-specific values, there should generally be a default value; in those cases, an empty default may be supplied. But the macro should also work with Pygments settings, which are stored in macros of the same form and will sometimes need to be accessed (for example, |encoding|). In the Pygments case, there may very well be no default values on the \LaTeX\ side, because we are falling back on Pygments' own built-in defaults. There is no need to duplicate those when very few Pygments values are ever needed; it is simpler to specify the default fallback when accessing the macro value. -% -% From a programming perspective, the default argument value needs to be mandatory, so that |\minted@get@opt| can be fully expandable. This significantly simplifies accessing options. -% \begin{macrocode} -\def\minted@get@opt#1#2{% - \ifcsname minted@opt@cmd:#1\endcsname - \csname minted@opt@cmd:#1\endcsname - \else - \ifminted@isinline - \ifcsname minted@opt@lang\minted@lang @i:#1\endcsname - \csname minted@opt@lang\minted@lang @i:#1\endcsname - \else - \ifcsname minted@opt@g@i:#1\endcsname - \csname minted@opt@g@i:#1\endcsname - \else - \ifcsname minted@opt@lang\minted@lang:#1\endcsname - \csname minted@opt@lang\minted@lang:#1\endcsname - \else - \ifcsname minted@opt@g:#1\endcsname - \csname minted@opt@g:#1\endcsname - \else - #2% - \fi - \fi - \fi - \fi - \else - \ifcsname minted@opt@lang\minted@lang:#1\endcsname - \csname minted@opt@lang\minted@lang:#1\endcsname - \else - \ifcsname minted@opt@g:#1\endcsname - \csname minted@opt@g:#1\endcsname - \else - #2% - \fi - \fi - \fi - \fi -}% -% \end{macrocode} -% \end{macro} % % \begin{macro}{\minted@def@opt} % Finally, on to the actual option definitions for \pkg{minted}-specific options. @@ -2158,6 +2101,121 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}{\minted@def@opt@style} +% Define an option for styles. These are defined independently because styles need slightly different handling. It is conventient to create style macros when styles are set. Otherwise, it would be necessary to check for the existence of style macros at the beginning of every command or environment. +% \begin{macrocode} +\newcommand{\minted@def@opt@style}{% + \define@key{minted@opt@g}{style}{% + \minted@checkstyle{##1}% + \@namedef{minted@opt@g:style}{##1}}% + \define@key{minted@opt@g@i}{style}{% + \minted@checkstyle{##1}% + \@namedef{minted@opt@g@i:style}{##1}}% + \define@key{minted@opt@lang}{style}{% + \minted@checkstyle{##1}% + \@namedef{minted@opt@lang\minted@lang:style}{##1}}% + \define@key{minted@opt@lang@i}{style}{% + \minted@checkstyle{##1}% + \@namedef{minted@opt@lang\minted@lang @i:style}{##1}}% + \define@key{minted@opt@cmd}{style}{% + \minted@checkstyle{##1}% + \@namedef{minted@opt@cmd:style}{##1}}% +} +% \end{macrocode} +% \end{macro} +% +% +% \begin{macro}{\minted@checkstyle} +% Make sure that style macros exist. +% +% 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. +% +% 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. +% +% The typical style macros created by |\minted@checkstyle|, which are of the form |\PYG