summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-09-10 20:56:54 +0000
committerKarl Berry <karl@freefriends.org>2015-09-10 20:56:54 +0000
commitb9de8b37ede65e75de420bd3814aa62f4e1017d6 (patch)
treee567f16f699ad973eec5a2a6bf459936100e9e37 /Master/texmf-dist/source
parentd55d075d6e1c947a2332b90c36d75147a6919180 (diff)
minted (10sep15)
git-svn-id: svn://tug.org/texlive/trunk@38339 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source')
-rw-r--r--Master/texmf-dist/source/latex/minted/minted.dtx975
1 files changed, 763 insertions, 212 deletions
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 @@
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\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]
%</package>
%<*driver>
\documentclass{ltxdoc}
@@ -156,6 +156,7 @@
\MakeShortVerb{\|}%
\par}
+\edef\hashchar{\string#}
\makeatother
\newcommand{\hide}[1]{}
@@ -170,7 +171,7 @@
%</driver>
% \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" <nul: /p
- x=\string^\@percentchar \string~$PATH:i>>"\jobname.aex"}
+ do set >"\minted@jobname.aex" <nul: /p
+ x=\string^\@percentchar \string~$PATH:i>>"\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<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.}
+% \begin{macrocode}
+\newcommand{\minted@checkstyle}[1]{%
+ \ifcsname minted@styleloaded@\ifstrempty{#1}{default-pyg-prefix}{#1}\endcsname\else
+ \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}%
+ {}%
+ {%
+ \ifwindows
+ \immediate\write18{%
+ \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
+ \immediate\write18{%
+ \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
+ \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
+ \immediate\write18{%
+ \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
+ -P commandprefix=PYG#1 > "\minted@outputdir@windows\minted@jobname.out.pyg"}%
+ \else
+ \immediate\write18{%
+ \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
+ -P commandprefix=PYG#1 > "\minted@outputdir\minted@jobname.out.pyg"}%
+ \fi
+ \begingroup
+ \let\def\gdef
+ \endlinechar=-1\relax
+ \minted@input{\minted@outputdir\minted@jobname.out.pyg}%
+ \endgroup}%
+ \fi
+}
+\ifthenelse{\boolean{minted@draft}}{\renewcommand{\minted@checkstyle}[1]{}}{}
+% \end{macrocode}
+% \end{macro}
+%
+% At the beginning of the document, create the symbol macros with |PYG| prefix. This must wait until |\AtBeginDocument|, because the existence of |pygmentize| isn't tested and may not be final until |\AtEndPreamble|.
+% \begin{macrocode}
+\AtBeginDocument{\minted@checkstyle{}}
+% \end{macrocode}
+%
+%
+% \begin{macro}{\minted@patch@PYGZsq}
+% Patch the \pkg{Pygments} single quote macro for \pkg{upquote}. The single quote macro from Pygments 1.6+ needs to be patched if the \pkg{upquote} package is in use. The conditionals for the patch definition are borrowed from \pkg{upquote}. Patching is done |\AtBeginDocument|, after the macros will have been created. Patching is only attempted if the macro exists, so that there is a graceful fallback in the event of a custom \pkg{Pygments} stylesheet.
+% \begin{macrocode}
+\newcommand{\minted@patch@PYGZsq}{%
+ \ifcsname PYGZsq\endcsname
+ \ifx\upquote@cmtt\minted@undefined\else
+ \ifx\encodingdefault\upquote@OTone
+ \ifx\ttdefault\upquote@cmtt
+ \expandafter\ifdefstring\expandafter{\csname PYGZsq\endcsname}{\char`\'}%
+ {\expandafter\gdef\csname PYGZsq\endcsname{\char13 }}{}%
+ \else
+ \expandafter\ifdefstring\expandafter{\csname PYGZsq\endcsname}{\char`\'}%
+ {\expandafter\gdef\csname PYGZsq\endcsname{\textquotesingle}}{}%
+ \fi
+ \else
+ \expandafter\ifdefstring\expandafter{\csname PYGZsq\endcsname}{\char`\'}%
+ {\expandafter\gdef\csname PYGZsq\endcsname{\textquotesingle}}{}%
+ \fi
+ \fi
+ \fi
+}
+\ifthenelse{\boolean{minted@draft}}{}{\AtBeginDocument{\minted@patch@PYGZsq}}
+% \end{macrocode}
+% \end{macro}
+%
+%
% \begin{macro}{\minted@def@opt@switch}
% And we need a switch version.
%
@@ -2183,8 +2241,52 @@
}
% \end{macrocode}
% \end{macro}
-
-
+%
+%
+% \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}
+%
+%
% \noindent Actual option definitions. Some of these must be defined conditionally depending on whether we are in |draft| mode; in |draft| mode, we need to emulate Pygments functionality with \LaTeX, particularly with \pkg{fancyvrb}, when possible. For example, gobbling must be performed by Pygments when |draft| is off, but when |draft| is on, \pkg{fancyvrb} can perform gobbling.
%
% Lexers.
@@ -2210,17 +2312,13 @@
\minted@def@optcl{keywordcase}{-F keywordcase:case}{#1}
% \end{macrocode}
%
-% \LaTeX\ formatter. Since \pkg{fancyvrb} currently doesn't have a |linenos| key, we create one (but only after checking to make sure that another package hasn't already patched this).
+% \LaTeX\ formatter.
% \begin{macrocode}
\minted@def@optcl@switch{texcl}{-P texcomments}
\minted@def@optcl@switch{texcomments}{-P texcomments}
\minted@def@optcl@switch{mathescape}{-P mathescape}
-\ifcsname KV@FV@linenos\endcsname\else
-\define@booleankey{FV}{linenos}%
- {\@nameuse{FV@Numbers@left}}{\@nameuse{FV@Numbers@none}}
-\fi
\minted@def@optfv@switch{linenos}
-\minted@def@optcl@style
+\minted@def@opt@style
% \end{macrocode}
%
% \pkg{fancyvrb} options.
@@ -2265,6 +2363,13 @@
\minted@def@optfv{breaksymbolright}
\minted@def@optfv{breaksymbolsepright}
\minted@def@optfv{breaksymbolindentright}
+\minted@def@optfv{breakafter}
+\minted@def@optfv@switch{breakaftergroup}
+\minted@def@optfv{breakaftersymbolpre}
+\minted@def@optfv{breakaftersymbolpost}
+\minted@def@optfv@switch{breakanywhere}
+\minted@def@optfv{breakanywheresymbolpre}
+\minted@def@optfv{breakanywheresymbolpost}
% \end{macrocode}
%
% Finally, options specific to \pkg{minted}.
@@ -2272,6 +2377,7 @@
% An option to force |breaklines| to work at the Pygments token level, rather than at the character level. This is useful in keeping things like strings from being split between lines.
% \begin{macrocode}
\minted@def@opt@switch{breakbytoken}
+\minted@def@opt@switch{breakbytokenanywhere}
% \end{macrocode}
%
% |bgcolor|: The old |bgcolor| is retained for compatibility. A dedicated framing package will often be preferable.
@@ -2298,13 +2404,19 @@
%
% The line breaking defined here is used in \pkg{minted}'s |minted| environment and |\mint| command, which use |Verbatim| internally. The |\mintinline| command implements line wrapping using a slightly different system (essentially, |BVerbatim|, with the |\vbox| |\let| to |\relax|). This is implemented separately within \pkg{minted}, rather than as an extension to \pkg{fancyvrb}, for simplicity and because |BVerbatim| wouldn't be itself without the box. Likewise, |breaklines| is not applied to |fancyvrb|'s |\Verb| or short verb, since their implementation is different from that of |\mintinline|. Ideally, an extension of |fancyvrb| would add line breaking to these, or (probable better) provide equivalent commands that support breaks.
%
+% \subsubsection{Setup}
+%
% \textbf{All of the additions to \pkg{fancyvrb} should be defined conditionally.} If an extension to \pkg{fancyvrb} (such as that proposed above) is loaded before \pkg{minted}, and if this extension provides |breaklines|, then we don't want to overwrite that definition and create a conflict. We assume that any extension of \pkg{fancyvrb} would use the \pkg{keyval} package, since that is what \pkg{fancyvrb} currently uses, and test for the existence of a \pkg{fancyrvb} \pkg{keyval} key |breaklines|.
% \begin{macrocode}
\ifcsname KV@FV@breaklines\endcsname\else
% \end{macrocode}
%
+%
+% \subsubsection{Line breaking}
+%
% Begin by defining keys, with associated macros, bools, and dimens.
% \begin{macro}{FV@BreakLines}
+% Turn line breaking on of off.
% \begin{macrocode}
\newboolean{FV@BreakLines}
\let\FV@ListProcessLine@Orig\FV@ListProcessLine
@@ -2417,6 +2529,186 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{FV@BreakAnywhere}
+% Allow line breaking (almost) anywhere.
+% \begin{macrocode}
+\newboolean{FV@BreakAnywhere}
+\define@booleankey{FV}{breakanywhere}%
+ {\FV@BreakAnywheretrue
+ \let\FancyVerbBreakStart\FV@Break
+ \let\FancyVerbBreakStop\FV@EndBreak
+ \let\FV@Break@Token\FV@Break@AnyToken}%
+ {\FV@BreakAnywherefalse
+ \let\FancyVerbBreakStart\relax
+ \let\FancyVerbBreakStop\relax}
+\fvset{breakanywhere=false}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FancyVerbBreakStart}
+% \begin{macrocode}
+\let\FancyVerbBreakStart\relax
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FancyVerbBreakStop}
+% \begin{macrocode}
+\let\FancyVerbBreakStop\relax
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV@EscChars}
+% We need to define versions of common escaped characters that reduce to raw characters.
+% \begin{macrocode}
+\edef\FV@hashchar{\string#}
+\edef\FV@dollarchar{\string$}
+\edef\FV@ampchar{\string&}
+\edef\FV@underscorechar{\string_}
+\edef\FV@tildechar{\string~}
+\edef\FV@leftsquarebracket{\string[}
+\edef\FV@rightsquarebracket{\string]}
+\newcommand{\FV@EscChars}{%
+ \let\#\FV@hashchar
+ \let\%\@percentchar
+ \let\{\@charlb
+ \let\}\@charrb
+ \let\$\FV@dollarchar
+ \let\&\FV@ampchar
+ \let\_\FV@underscorechar
+ \let\\\@backslashchar
+ \let~\FV@tildechar
+ \let\~\FV@tildechar
+ \let\[\FV@leftsquarebracket
+ \let\]\FV@rightsquarebracket
+} %$ <- highlighting
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV@BreakAfter}
+% Allow line breaking (almost) anywhere, but only after specified characters.
+% \begin{macrocode}
+\define@key{FV}{breakafter}{%
+ \ifstrempty{#1}%
+ {\let\FV@BreakAfter\@empty
+ \let\FancyVerbBreakStart\relax
+ \let\FancyVerbBreakStop\relax}%
+ {\def\FV@BreakAfter{#1}%
+ \let\FancyVerbBreakStart\FV@Break
+ \let\FancyVerbBreakStop\FV@EndBreak
+ \let\FV@Break@Token\FV@Break@AfterToken}%
+}
+\fvset{breakafter={}}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{FV@BreakAfterGroup}
+% Determine whether breaking after specified characters is always allowed after each individual character, or is only allowed after groups of identical characters.
+% \begin{macrocode}
+\newboolean{FV@BreakAfterGroup}
+\define@booleankey{FV}{breakaftergroup}%
+ {\FV@BreakAfterGrouptrue}%
+ {\FV@BreakAfterGroupfalse}%
+\fvset{breakaftergroup=true}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV@BreakAfterPrep}
+% We need a way to break after characters if they have been specified as breaking characters. It would be possible to do that via a nested conditional, but that would be messy. It is much simpler to create an empty macro whose name contains the character, and test for the existence of this macro. This needs to be done inside a |\begingroup...\endgroup| so that the macros do not have to be cleaned up manually. A good place to do this is in |\FV@FormattingPrep|, which is inside a group and before processing starts.
+%
+% The procedure here is a bit roundabout. We need to use |\FV@EscChars| to handle character escapes, but the character redefinitions need to be kept local, requiring that we work within a |\begingroup...\endgroup|. So we loop through the breaking tokens and assemble a macro that will itself define character macros. Only this defining macro is declared global, and it contains \emph{expanded} characters so that there is no longer any dependence on |\FV@EscChars|.
+% \begin{macrocode}
+\def\FV@BreakAfterPrep{%
+ \ifx\FV@BreakAfter\@empty\relax
+ \else
+ \gdef\FV@BreakAfter@Def{}%
+ \begingroup
+ \def\FV@BreakAfter@Process##1##2\FV@Undefined{%
+ \expandafter\FV@BreakAfter@Process@i\expandafter{##1}%
+ \expandafter\ifx\expandafter\relax\detokenize{##2}\relax
+ \else
+ \FV@BreakAfter@Process##2\FV@Undefined
+ \fi
+ }%
+ \def\FV@BreakAfter@Process@i##1{%
+ \g@addto@macro\FV@BreakAfter@Def{%
+ \@namedef{FV@BreakAfter@Token\detokenize{##1}}{}}%
+ }%
+ \FV@EscChars
+ \expandafter\FV@BreakAfter@Process\FV@BreakAfter\FV@Undefined
+ \endgroup
+ \FV@BreakAfter@Def
+ \fi
+}
+\expandafter\def\expandafter\FV@FormattingPrep\expandafter{%
+ \expandafter\FV@BreakAfterPrep\FV@FormattingPrep}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FancyVerbBreakAnywhereSymbolPre}
+% The pre-break symbol for breaks introduced by |breakanywhere|. That is, the symbol before breaks that occur between characters, rather than at spaces.
+% \begin{macrocode}
+\define@key{FV}{breakanywheresymbolpre}{%
+ \ifstrempty{#1}%
+ {\def\FancyVerbBreakAnywhereSymbolPre{}}%
+ {\def\FancyVerbBreakAnywhereSymbolPre{\hbox{#1}}}}
+\fvset{breakanywheresymbolpre={\,\footnotesize\ensuremath{_\rfloor}}}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FancyVerbBreakAnywhereSymbolPost}
+% The post-break symbol for breaks introduced by |breakanywhere|.
+% \begin{macrocode}
+\define@key{FV}{breakanywheresymbolpost}{%
+ \ifstrempty{#1}%
+ {\def\FancyVerbBreakAnywhereSymbolPost{}}%
+ {\def\FancyVerbBreakAnywhereSymbolPost{\hbox{#1}}}}
+\fvset{breakanywheresymbolpost={}}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FancyVerbBreakAfterSymbolPre}
+% The pre-break symbol for breaks introduced by |breakafter|.
+% \begin{macrocode}
+\define@key{FV}{breakaftersymbolpre}{%
+ \ifstrempty{#1}%
+ {\def\FancyVerbBreakAfterSymbolPre{}}%
+ {\def\FancyVerbBreakAfterSymbolPre{\hbox{#1}}}}
+\fvset{breakaftersymbolpre={\,\footnotesize\ensuremath{_\rfloor}}}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FancyVerbBreakAfterSymbolPost}
+% The post-break symbol for breaks introduced by |breakafter|.
+% \begin{macrocode}
+\define@key{FV}{breakaftersymbolpost}{%
+ \ifstrempty{#1}%
+ {\def\FancyVerbBreakAfterSymbolPost{}}%
+ {\def\FancyVerbBreakAfterSymbolPost{\hbox{#1}}}}
+\fvset{breakaftersymbolpost={}}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FancyVerbBreakAnywhereBreak}
+% When |breakanywhere=true|, line breaks may occur at almost any location. This is the macro that governs the breaking in those cases. By default, |\discretionary| is used. |\discretionary| takes three arguments: a character to insert before the break, a character to insert after the break, and a character to insert if there is no break.
+%
+% |\discretionary| will generally only insert breaks when breaking at spaces simply cannot make lines short enough (this may be tweaked to some extent with hyphenation settings). This can produce a somewhat ragged appearance in some cases. If you want breaks exactly at the margin (or as close as possible) regardless of whether a break at a space is an option, you may want to use |\allowbreak| instead.
+% \begin{macrocode}
+\newcommand{\FancyVerbBreakAnywhereBreak}{%
+ \discretionary{\FancyVerbBreakAnywhereSymbolPre}%
+ {\FancyVerbBreakAnywhereSymbolPost}{}}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\FancyVerbBreakAfterBreak}
+% The macro governing breaking for |breakafter=true|.
+% \begin{macrocode}
+\newcommand{\FancyVerbBreakAfterBreak}{%
+ \discretionary{\FancyVerbBreakAfterSymbolPre}%
+ {\FancyVerbBreakAfterSymbolPost}{}}
+% \end{macrocode}
+% \end{macro}
+%
% Define helper macros.
% \begin{macro}{\FV@LineBox}
% A box for saving a line of code, so that its dimensions may be determined and thus we may figure out if it needs line breaking.
@@ -2467,6 +2759,150 @@
% \end{macro}
%
%
+% Define the macros that actually perform |breakanywhere|.
+%
+% \begin{macro}{\FV@Break}
+% The entry macro for breaking lines, either anywhere or after specified characters. The current line (or argument) will be scanned token by token/group by group, and accumulated (with added potential breaks) in |\FV@Tmp|. After scanning is complete, |\FV@Tmp| will be inserted. It would be possible to insert each token/group into the document immediately after it is scanned, instead of accumulating them in a ``buffer.'' But that would interfere with macros. Even in the current approach, macros that take optional arguments are problematic.\footnote{Through a suitable definition that tracks the current state and looks for square brackets, this might be circumvented. Then again, in verbatim contexts, macro use should be minimal, so the restriction to macros without optional arguments should generally not be an issue.}
+% \begin{macrocode}
+\def\FV@Break{%
+ \def\FV@Tmp{}%
+ \FV@Break@Scan
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV@EndBreak}
+% \begin{macrocode}
+\def\FV@EndBreak{\FV@Tmp}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV@Break@Scan}
+% Look ahead via |\@ifnextchar|. Don't do anything if we're at the end of the region to be scanned. Otherwise, invoke a macro to deal with what's next based on whether it is math, or a group, or something else.
+%
+% This and some following macros are defined inside of groups, to ensure proper catcodes.
+% \begin{macrocode}
+\begingroup
+\catcode`\$=3%
+\gdef\FV@Break@Scan{%
+ \@ifnextchar\FV@EndBreak%
+ {}%
+ {\ifx\@let@token$\relax
+ \let\FV@Break@Next\FV@Break@Math
+ \else
+ \ifx\@let@token\bgroup\relax
+ \let\FV@Break@Next\FV@Break@Group
+ \else
+ \let\FV@Break@Next\FV@Break@Token
+ \fi
+ \fi
+ \FV@Break@Next}%
+}
+\endgroup
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV@Break@Math}
+% Grab an entire math span, and insert it into |\FV@Tmp|. Due to grouping, this works even when math contains things like |\text{$x$}|. After dealing with the math span, continue scanning.
+% \begin{macrocode}
+\begingroup
+\catcode`\$=3%
+\gdef\FV@Break@Math$#1${%
+ \g@addto@macro{\FV@Tmp}{$#1$}%
+ \FV@Break@Scan}
+\endgroup
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV@Break@Group}
+% Grab the group, and insert it into |\FV@Tmp| (as a group) before continuing scanning.
+% \begin{macrocode}
+\def\FV@Break@Group#1{%
+ \g@addto@macro{\FV@Tmp}{{#1}}%
+ \FV@Break@Scan}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV@Break@Token}
+% This macro is |\let| to |\FV@Break@AnyToken| or |\FV@Break@AfterToken| by the |breakanywhere| and |breakafter| options, so it is not explicitly defined.
+% \end{macro}
+%
+% \begin{macro}{\FV@Break@AnyToken}
+% Deal with breaking around any token.
+%
+% If it is ever necessary, it would be possible to create a more sophisticated version involving catcode checks via |\ifcat|. Something like this:
+%\begin{Verbatim}
+%\begingroup
+%\catcode`\a=11%
+%\catcode`\+=12%
+%\gdef\FV@Break...
+% \ifcat\noexpand#1a%
+% \g@addto@macro{\FV@Tmp}...
+% \else
+%...
+%\endgroup
+%\end{Verbatim}
+%
+% This doesn't break macros with \emph{mandatory} arguments, because |\FancyVerbBreakAnywhereBreak| is inserted \emph{before} the token. Groups themselves are added without any special handling. So a macro would end up right next to its original arguments, without anything being inserted. Optional arguments will cause this approach to fail; there is currently no attempt to identify them, since that is a much harder problem.
+% \begin{macrocode}
+\def\FV@Break@AnyToken#1{%
+ \g@addto@macro{\FV@Tmp}{\FancyVerbBreakAnywhereBreak#1}%
+ \FV@Break@Scan}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV@Break@AfterToken}
+% Deal with breaking around only specified tokens. This is a bit trickier. We only break if a macro corresponding to the token exists. We also need to check whether the specified token should be grouped, that is, whether breaks are allowed between identical characters. All of this has to be written carefully so that nothing is accidentally inserted into the stream for future scanning.
+%
+% Dealing with tokens followed by empty groups (for example, |\x{}|) is particularly challenging when we want to avoid breaks between identical characters. When a token is followed by a group, we need to save the current token for later reference (|\x| in the example), then capture and save the following group, and then---only if the group was empty---see if the following token is identical to the old saved token.
+% \begin{macrocode}
+\def\FV@Break@AfterToken#1{%
+ \ifcsname FV@BreakAfter@Token\detokenize{#1}\endcsname
+ \let\FV@Break@Next\FV@Break@AfterTokenBreak
+ \else
+ \let\FV@Break@Next\FV@Break@AfterTokenNoBreak
+ \fi
+ \FV@Break@Next{#1}%
+}
+\def\FV@Break@AfterTokenNoBreak#1{%
+ \g@addto@macro{\FV@Tmp}{#1}%
+ \FV@Break@Scan}
+\def\FV@Break@AfterTokenBreak#1{%
+ \@ifnextchar\FV@Space%
+ {\g@addto@macro{\FV@Tmp}{#1}\FV@Break@Scan}%
+ {\ifthenelse{\boolean{FV@BreakAfterGroup}}%
+ {\ifx\@let@token#1\relax
+ \g@addto@macro{\FV@Tmp}{#1}%
+ \let\FV@Break@Next\FV@Break@Scan
+ \else
+ \ifx\@let@token\bgroup\relax
+ \g@addto@macro{\FV@Tmp}{#1}%
+ \let\FV@TmpToken#1%
+ \let\FV@Break@Next\FV@Break@AfterTokenBreak@Group
+ \else
+ \g@addto@macro{\FV@Tmp}{#1\FancyVerbBreakAfterBreak}%
+ \let\FV@Break@Next\FV@Break@Scan
+ \fi
+ \fi}%
+ {\g@addto@macro{\FV@Tmp}{#1\FancyVerbBreakAfterBreak}%
+ \let\FV@Break@Next\FV@Break@Scan}%
+ \FV@Break@Next}%
+}
+\def\FV@Break@AfterTokenBreak@Group#1{%
+ \g@addto@macro{\FV@Tmp}{{#1}}%
+ \ifstrempty{#1}%
+ {\let\FV@Break@Next\FV@Break@AfterTokenBreak@Group@i}%
+ {\let\FV@Break@Next\FV@Break@Scan}%
+ \FV@Break@Next}
+\def\FV@Break@AfterTokenBreak@Group@i{%
+ \@ifnextchar\FV@TmpToken%
+ {\FV@Break@Scan}%
+ {\g@addto@macro{\FV@Tmp}{\FancyVerbBreakAfterBreak}%
+ \FV@Break@Scan}}
+% \end{macrocode}
+% \end{macro}
+%
+%
% And finally the really important things.
%
% \begin{macro}{\FV@makeLineNumber}
@@ -2517,7 +2953,7 @@
\ifthenelse{\boolean{FV@BreakAutoIndent}}%
{\hspace*{-\wd\FV@LineIndentBox}}%
{}%
- \strut#1\strut
+ \strut#1\nobreak\strut
\end{internallinenumbers*}
}%
\ifdefempty{\FancyVerbBreakSymbolRight}{}%
@@ -2527,6 +2963,13 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\FancyVerbFormatText}
+% The introduction of line breaks introduces an issue for |\FancyVerbFormatLine|. Does it format the entire line (outside the |\parbox|), or only the text part of the line (inside the |\parbox|)? Since both might be desirable, |\FancyVerbFormatLine| is assigned to the entire line, and a new macro |\FancyVerbFormatText| is assigned to the text, within the |\parbox|.
+% \begin{macrocode}
+\def\FancyVerbFormatText#1{#1}
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}{\FV@ListProcessLine@Break}
% This macro is based on |\FV@ListProcessLine| and follows it as closely as possible. The |\linewidth| is reduced by |\FV@FrameSep| and |\FV@FrameRule| so that text will not overrun frames. This is done conditionally based on which frames are in use. We save the current line in a box, and only do special things if the box is too wide. For uniformity, all text is placed in a |\parbox|, even if it doesn't need to be wrapped.
%
@@ -2544,13 +2987,15 @@
\advance\linewidth by -\FV@FrameSep
\advance\linewidth by -\FV@FrameRule
\fi
- \sbox{\FV@LineBox}{\FancyVerbFormatLine{#1}}%
+ \sbox{\FV@LineBox}{\FancyVerbFormatLine{\FancyVerbFormatText{#1}}}%
\ifdim\wd\FV@LineBox>\linewidth
\setcounter{FancyVerbLineBreakLast}{0}%
- \FV@SaveLineBox{#1}%
+ \FV@SaveLineBox{\FancyVerbFormatText{%
+ \FancyVerbBreakStart#1\FancyVerbBreakStop}}%
\ifdefempty{\FancyVerbBreakSymbolRight}{}{%
\let\FV@SetLineBreakLast\relax
- \FV@SaveLineBox{#1}}%
+ \FV@SaveLineBox{\FancyVerbFormatText{%
+ \FancyVerbBreakStart#1\FancyVerbBreakStop}}}%
\FV@LeftListNumber
\FV@LeftListFrame
\FancyVerbFormatLine{\usebox{\FV@LineBox}}%
@@ -2560,7 +3005,7 @@
\FV@LeftListNumber
\FV@LeftListFrame
\FancyVerbFormatLine{%
- \parbox[t]{\linewidth}{\noindent\strut#1\strut}}%
+ \parbox[t]{\linewidth}{\noindent\strut\FancyVerbFormatText{#1}\strut}}%
\FV@RightListFrame
\FV@RightListNumber
\fi}%
@@ -2568,6 +3013,19 @@
% \end{macrocode}
% \end{macro}
%
+%
+% \subsection{\texttt{linenos}}
+% Since \pkg{fancyvrb} currently doesn't have a |linenos| key, we create one that mimics |numbers=left| (but only after checking to make sure that another package hasn't already patched this).
+% \begin{macrocode}
+\ifcsname KV@FV@linenos\endcsname\else
+\define@booleankey{FV}{linenos}%
+ {\@nameuse{FV@Numbers@left}}{\@nameuse{FV@Numbers@none}}
+\fi
+% \end{macrocode}
+%
+%
+% \subsection{Cleanup}
+%
% Finally, end the conditional creation of \pkg{fancyvrb} extensions.
% \begin{macrocode}
\fi
@@ -2615,7 +3073,7 @@
% Save code to be pygmentized to a file.
% \begin{macrocode}
\newcommand{\minted@savecode}[1]{
- \immediate\openout\minted@code\jobname.pyg\relax
+ \immediate\openout\minted@code\minted@jobname.pyg\relax
\immediate\write\minted@code{\expandafter\detokenize\expandafter{#1}}%
\immediate\closeout\minted@code}
% \end{macrocode}
@@ -2662,16 +3120,18 @@
%
%
% \begin{macro}{\MintedPygmentize}
-% We need a way to customize the executable/script that is called to perform highlighting. Typically, we will want |pygmentize|. But advanced users might wish to use a custom Python script instead.
+% We need a way to customize the executable/script that is called to perform highlighting. Typically, we will want |pygmentize|. But advanced users might wish to use a custom Python script instead. The command is only defined if it does not exist. In general, the command should be |\renewcommand|ed after the package is loaded, but this way, it will work if defined before \pkg{minted} is loaded.
% \begin{macrocode}
-\newcommand{\MintedPygmentize}{pygmentize}
+\ifcsname MintedPygmentize\endcsname\else
+ \newcommand{\MintedPygmentize}{pygmentize}
+\fi
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\minted@pygmentize}
%
-% Pygmentize a file (default: |\minted@outputdir\jobname.pyg|) using the options provided.
+% Pygmentize a file (default: |\minted@outputdir\minted@jobname.pyg|) using the options provided.
%
% Unfortunately, the logic for caching is a little complex due to operations that are OS- and engine-dependent.
%
@@ -2682,9 +3142,9 @@
% \textbf{This macro must always be checked carefully whenever it is modified.} Under no circumstances should |#1| be written to or opened by Python in write mode. When |\inputminted| is used, |#1| will be an external file that is brought in for highlighting, so it must be left intact.
%
% \begin{macrocode}
-\newcommand{\minted@pygmentize}[2][\minted@outputdir\jobname.pyg]{%
+\newcommand{\minted@pygmentize}[2][\minted@outputdir\minted@jobname.pyg]{%
\ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}%
- {\def\minted@codefile{\minted@outputdir\jobname.pyg}}%
+ {\def\minted@codefile{\minted@outputdir\minted@jobname.pyg}}%
{\def\minted@codefile{#1}}%
\ifthenelse{\boolean{minted@isinline}}%
{\def\minted@optlistcl@inlines{%
@@ -2694,7 +3154,7 @@
\def\minted@cmd{%
\ifminted@kpsewhich\ifwindows powershell\space\fi\fi
\MintedPygmentize\space -l #2
- -f latex -F tokenmerge
+ -f latex -P commandprefix=PYG -F tokenmerge
\minted@optlistcl@g \csname minted@optlistcl@lang\minted@lang\endcsname
\minted@optlistcl@inlines
\minted@optlistcl@cmd -o "\minted@outputdir\minted@infile"
@@ -2720,7 +3180,7 @@
{\edef\minted@hash{\pdf@filemdfivesum{#1}%
\pdf@mdfivesum{\minted@cmd}}}%
\else
- \immediate\openout\minted@code\jobname.mintedcmd\relax
+ \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}}{}%
@@ -2730,18 +3190,18 @@
\def\minted@hashcmd{%
\detokenize{python -c "import hashlib;
hasher = hashlib.sha1();
- f = open(\"}\minted@outputdir\jobname.mintedcmd\detokenize{\", \"rb\");
+ f = open(\"}\minted@outputdir\minted@jobname.mintedcmd\detokenize{\", \"rb\");
hasher.update(f.read());
f.close();
f = open(\"}#1\detokenize{\", \"rb\");
hasher.update(f.read());
f.close();
- f = open(\"}\minted@outputdir\jobname.mintedmd5\detokenize{\", \"w\");
+ f = open(\"}\minted@outputdir\minted@jobname.mintedmd5\detokenize{\", \"w\");
macro = \"\\edef\\minted@hash\" + chr(123) + hasher.hexdigest() + chr(125) + \"\";
f.write(\"\\makeatletter\" + macro + \"\\makeatother\\endinput\n\");
f.close();"}}%
\immediate\write18{\minted@hashcmd}%
- \minted@input{\minted@outputdir\jobname.mintedmd5}%
+ \minted@input{\minted@outputdir\minted@jobname.mintedmd5}%
\fi
\edef\minted@infile{\minted@cachedir/\minted@hash.pygtex}%
\IfFileExists{\minted@infile}{}{%
@@ -2754,7 +3214,7 @@
f = open(\"}#1\detokenize{\", \"r\", encoding=\"}\minted@encoding\detokenize{\");
t = f.read();
f.close();
- f = open(\"}\minted@outputdir\jobname.pyg\detokenize{\", \"w\", encoding=\"}\minted@encoding\detokenize{\");
+ f = open(\"}\minted@outputdir\minted@jobname.pyg\detokenize{\", \"w\", encoding=\"}\minted@encoding\detokenize{\");
f.write(textwrap.dedent(t));
f.close();"}%
}%
@@ -2772,7 +3232,7 @@
f = open(\"}#1\detokenize{\", \"r\", encoding=\"}\minted@encoding\detokenize{\");
t = f.read();
f.close();
- f = open(\"}\minted@outputdir\jobname.pyg\detokenize{\", \"w\", encoding=\"}\minted@encoding\detokenize{\");
+ f = open(\"}\minted@outputdir\minted@jobname.pyg\detokenize{\", \"w\", encoding=\"}\minted@encoding\detokenize{\");
f.write(textwrap.dedent(t));
f.close();"}%
}%
@@ -2784,40 +3244,127 @@
% \end{macro}
%
% \begin{macro}{\minted@inputpyg}
-% For increased clarity, the actual |\input| process is separated out into its own macro. The |bgcolor| option needs to be dealt with in different ways depending on whether we are using |\mintinline|. Also, if we are not inline, then the |breakbytoken| option may apply. 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. |\FV@Space| is also patched for math mode, so that space characters will vanish rather than appear as literal spaces within math mode.
+% For increased clarity, the actual |\input| process is separated out into its own macro. 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. |\FV@Space| is also patched for math mode, so that space characters will vanish rather than appear as literal spaces within math mode. To simplify the logic, |breakbytoken| is turned on if |breakbytokenanywhere| is on.
+%
+% At the last possible moment, |\PYG| is |\let| to |\PYG<style>|. All modifications to the style macro for breaking are made to |\PYG<style>| rather than |\PYG|, so that the |\let|ing that must ultimately take place will indeed do what is intended.
% \begin{macrocode}
\def\FV@SpaceMMode{ }
+\def\minted@BreakAfterPrep@extension{%
+ \ifcsname FV@BreakAfter@Token\@backslashchar\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZbs}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\FV@underscorechar\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZus}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\@charlb\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZob}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\@charrb\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZcb}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\detokenize{^}\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZca}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\FV@ampchar\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZam}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\detokenize{<}\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZlt}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\detokenize{>}\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZgt}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\FV@hashchar\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZsh}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\@percentchar\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZpc}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\FV@dollarchar\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZdl}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\detokenize{-}\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZhy}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\detokenize{'}\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZsq}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\detokenize{"}\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZdq}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\FV@tildechar\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZti}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\detokenize{@}\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZat}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\detokenize{[}\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZlb}}{}%
+ \fi
+ \ifcsname FV@BreakAfter@Token\detokenize{]}\endcsname
+ \@namedef{FV@BreakAfter@Token\detokenize{\PYGZrb}}{}%
+ \fi
+}
\newcommand{\minted@inputpyg}{%
+ \let\FV@BreakAfterPrep@orig\FV@BreakAfterPrep
+ \def\FV@BreakAfterPrep{%
+ \FV@BreakAfterPrep@orig\minted@BreakAfterPrep@extension}%
\everymath\expandafter{\the\everymath\let\FV@Space\FV@SpaceMMode}%
+ \ifthenelse{\equal{\minted@get@opt{breakbytokenanywhere}{false}}{true}}%
+ {\setkeys{minted@opt@cmd}{breakbytoken=true}}{}%
+ \ifthenelse{\boolean{FV@BreakAnywhere}}%
+ {\expandafter\let\expandafter\minted@orig@PYG@breakanywhere%
+ \csname PYG\minted@get@opt{style}{default}\endcsname
+ \expandafter\def\csname PYG\minted@get@opt{style}{default}\endcsname##1##2{%
+ \minted@orig@PYG@breakanywhere{##1}%
+ {\FancyVerbBreakStart##2\FancyVerbBreakStop}}}{}%
+ \ifx\FV@BreakAfter\@empty
+ \else
+ \expandafter\let\expandafter\minted@orig@PYG@breakafter%
+ \csname PYG\minted@get@opt{style}{default}\endcsname
+ \expandafter\def\csname PYG\minted@get@opt{style}{default}\endcsname##1##2{%
+ \minted@orig@PYG@breakafter{##1}%
+ {\FancyVerbBreakStart##2\FancyVerbBreakStop}}%
+ \fi
\ifthenelse{\boolean{minted@isinline}}%
{\ifthenelse{\equal{\minted@get@opt{breaklines}{false}}{true}}%
{\let\FV@BeginVBox\relax
\let\FV@EndVBox\relax
\def\FV@BProcessLine##1{\FancyVerbFormatLine{##1}}%
\ifthenelse{\equal{\minted@get@opt{breakbytoken}{false}}{true}}%
- {\expandafter\let\expandafter\minted@orig@PYG%
- \csname PYG\minted@get@opt{style}{default}\endcsname
- \expandafter\def\csname PYG\minted@get@opt{style}{default}\endcsname##1##2{%
- \allowbreak{}\hbox{\minted@orig@PYG{##1}{##2}}}%
+ {\minted@inputpyg@breakbytoken
\minted@inputpyg@inline}%
{\minted@inputpyg@inline}}%
{\minted@inputpyg@inline}}%
{\ifthenelse{\equal{\minted@get@opt{breaklines}{false}}{true}}%
{\ifthenelse{\equal{\minted@get@opt{breakbytoken}{false}}{true}}%
- {\expandafter\let\expandafter\minted@orig@PYG%
- \csname PYG\minted@get@opt{style}{default}\endcsname
- \expandafter\def\csname PYG\minted@get@opt{style}{default}\endcsname##1##2{%
- \allowbreak{}\hbox{\minted@orig@PYG{##1}{##2}}}%
+ {\minted@inputpyg@breakbytoken
\minted@inputpyg@block}%
{\minted@inputpyg@block}}%
{\minted@inputpyg@block}}%
}
+\def\minted@inputpyg@breakbytoken{%
+ \expandafter\let\expandafter\minted@orig@PYG@breakbytoken%
+ \csname PYG\minted@get@opt{style}{default}\endcsname
+ \ifthenelse{\equal{\minted@get@opt{breakbytokenanywhere}{false}}{true}}%
+ {\let\minted@orig@allowbreak\allowbreak
+ \def\allowbreak{\let\allowbreak\minted@orig@allowbreak}%
+ \expandafter\def\csname PYG\minted@get@opt{style}{default}\endcsname##1##2{%
+ \allowbreak{}\leavevmode\hbox{\minted@orig@PYG@breakbytoken{##1}{##2}}}}%
+ {\expandafter\def\csname PYG\minted@get@opt{style}{default}\endcsname##1##2{%
+ \leavevmode\hbox{\minted@orig@PYG@breakbytoken{##1}{##2}}}}%
+}
\def\minted@inputpyg@inline{%
+ \expandafter\let\expandafter\PYG%
+ \csname PYG\minted@get@opt{style}{default}\endcsname
\ifthenelse{\equal{\minted@get@opt{bgcolor}{}}{}}%
{\minted@input{\minted@outputdir\minted@infile}}%
- {\colorbox{\minted@get@opt{bgcolor}{}}{\minted@input{\minted@outputdir\minted@infile}}}%
+ {\colorbox{\minted@get@opt{bgcolor}{}}{%
+ \minted@input{\minted@outputdir\minted@infile}}}%
}
\def\minted@inputpyg@block{%
+ \expandafter\let\expandafter\PYG%
+ \csname PYG\minted@get@opt{style}{default}\endcsname
\ifthenelse{\equal{\minted@get@opt{bgcolor}{}}{}}%
{\minted@input{\minted@outputdir\minted@infile}}%
{\begin{minted@colorbg}{\minted@get@opt{bgcolor}{}}%
@@ -2916,7 +3463,7 @@
% The |\mintinline| and |\mint| commands will need to write the code they capture to a temporary file for highlighting. It will be convenient to be able to accomplish this via a simple macro, since that makes it simpler to deal with any expansion of what is to be written. This isn't needed for the |minted| environment, because the (patched) |VerbatimOut| is used.
% \begin{macrocode}
\newcommand{\minted@writecmdcode}[1]{%
- \immediate\openout\minted@code\jobname.pyg\relax
+ \immediate\openout\minted@code\minted@jobname.pyg\relax
\immediate\write\minted@code{\detokenize{#1}}%
\immediate\closeout\minted@code}
% \end{macrocode}
@@ -3073,7 +3620,7 @@
\minted@configlang{#2}%
\setkeys{minted@opt@cmd}{#1}%
\minted@fvset
- \begin{VerbatimOut}[codes={\catcode`\^^I=12}]{\jobname.pyg}}%
+ \begin{VerbatimOut}[codes={\catcode`\^^I=12}]{\minted@jobname.pyg}}%
{\end{VerbatimOut}%
\minted@langlinenoson
\minted@pygmentize{\minted@lang}%
@@ -3089,7 +3636,7 @@
{\newcommand{\inputminted}[3][]{%
\begingroup
\minted@configlang{#2}%
- \setkeys{minted@optcmd}{#1}%
+ \setkeys{minted@opt@cmd}{#1}%
\minted@fvset
\VerbatimInput{#3}%
\endgroup}}%
@@ -3275,7 +3822,7 @@
%
% \subsection{Epilogue}
%
-% Check whether LaTeX was invoked with |-shell-escape| option, make sure |pygmentize| exists, and set the default style.
+% Check whether LaTeX was invoked with |-shell-escape| option, set the default style, and make sure |pygmentize| exists. Checking for |pygmentize| must wait until the end of the preamble, in case it is specified via |\MintedPygmentize| (which would typically be after the package is loaded).
%
% \begin{macrocode}
\AtEndOfPackage{%
@@ -3287,7 +3834,12 @@
{Pass the -shell-escape flag to LaTeX. Refer to the minted.sty
documentation for more information.}%
\fi
- \TestAppExists{pygmentize}
+ \setminted{style=default}%
+ }%
+}
+\AtEndPreamble{%
+ \ifthenelse{\boolean{minted@draft}}{}{%
+ \TestAppExists{pygmentize}%
\ifAppExists\else
\PackageError{minted}%
{You must have `pygmentize' installed
@@ -3295,7 +3847,6 @@
{Refer to the installation instructions in the minted
documentation for more information.}%
\fi
- \setminted{style=default}%
}%
}
% \end{macrocode}
@@ -3309,11 +3860,11 @@
\AtEndDocument{
\ifx\XeTeXinterchartoks\minted@undefined
\else
- \DeleteFile[\minted@outputdir]{\jobname.mintedcmd}%
- \DeleteFile[\minted@outputdir]{\jobname.mintedmd5}%
+ \DeleteFile[\minted@outputdir]{\minted@jobname.mintedcmd}%
+ \DeleteFile[\minted@outputdir]{\minted@jobname.mintedmd5}%
\fi
- \DeleteFile[\minted@outputdir]{\jobname.pyg}%
- \DeleteFile[\minted@outputdir]{\jobname.out.pyg}%
+ \DeleteFile[\minted@outputdir]{\minted@jobname.pyg}%
+ \DeleteFile[\minted@outputdir]{\minted@jobname.out.pyg}%
}
% \end{macrocode}
%