texlive[41329] Master/texmf-dist: minted (8jun16)

commits+karl at tug.org commits+karl at tug.org
Fri Jun 10 00:52:48 CEST 2016


Revision: 41329
          http://tug.org/svn/texlive?view=revision&revision=41329
Author:   karl
Date:     2016-06-10 00:52:48 +0200 (Fri, 10 Jun 2016)
Log Message:
-----------
minted (8jun16)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/minted/README
    trunk/Master/texmf-dist/doc/latex/minted/minted.pdf
    trunk/Master/texmf-dist/source/latex/minted/minted.dtx
    trunk/Master/texmf-dist/source/latex/minted/minted.ins
    trunk/Master/texmf-dist/tex/latex/minted/minted.sty
    trunk/Master/texmf-dist/tex/latex/minted/minted1.sty

Modified: trunk/Master/texmf-dist/doc/latex/minted/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/minted/README	2016-06-09 22:52:34 UTC (rev 41328)
+++ trunk/Master/texmf-dist/doc/latex/minted/README	2016-06-09 22:52:48 UTC (rev 41329)
@@ -1,4 +1,4 @@
-minted \x97 highlighted source code for LaTeX
+minted - highlighted source code for LaTeX
 
 minted is a package that facilitates expressive syntax highlighting in LaTeX
 using the Pygments library.  The package also provides options to customize 

Modified: trunk/Master/texmf-dist/doc/latex/minted/minted.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/minted/minted.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/minted/minted.dtx	2016-06-09 22:52:34 UTC (rev 41328)
+++ trunk/Master/texmf-dist/source/latex/minted/minted.dtx	2016-06-09 22:52:48 UTC (rev 41329)
@@ -1,6 +1,6 @@
 % \iffalse meta-comment
 %
-% Copyright (C) 2013-2015 by Geoffrey M. Poore <gpoore at gmail.com>
+% Copyright (C) 2013-2016 by Geoffrey M. Poore <gpoore at gmail.com>
 % Copyright (C) 2010-2011 by Konrad Rudolph <konrad_rudolph at madrat.net>
 % ---------------------------------------------------------------------------
 % This work may be distributed and/or modified under the
@@ -31,7 +31,7 @@
 %<package>\NeedsTeXFormat{LaTeX2e}
 %<package>\ProvidesPackage{minted}
 %<*package>
-    [2015/09/09 v2.1 Yet another Pygments shim for LaTeX]
+    [2016/06/08 v2.2 Yet another Pygments shim for LaTeX]
 %</package>
 %<*driver>
 \documentclass{ltxdoc}
@@ -40,7 +40,6 @@
 %\DisableCrossrefs
 %\RecordChanges
 %\OnlyDescription
-\usepackage{fixltx2e}
 \usepackage[utf8]{inputenc}
 \usepackage[T1]{fontenc}
 \usepackage{lmodern}
@@ -171,7 +170,7 @@
 %</driver>
 % \fi
 %
-% \CheckSum{3283}
+% \CheckSum{3835}
 %
 % \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
@@ -191,6 +190,24 @@
 %
 %
 %
+%
+% \begin{changelog}{v2.2}{2016/06/08}
+% \item All uses of \texttt{\string\ShellEscape} (\texttt{\string\write18}) no longer wrap file names and paths with double quotes.  This allows a cache directory to be specified relative to a user's home directory, for example, \texttt{\string~/minted\_cache}.  \texttt{cachedir} and \texttt{outputdir} paths containing spaces will now require explicit quoting of the parts of the paths that contain spaces, since \texttt{minted} no longer supplies quoting.  See the updated documentation for examples (\#89).
+% \item Added \texttt{breakbefore}, \texttt{breakbeforegroup}, \texttt{breakbeforesymbolpre}, and \texttt{breakbeforesymbolpost}.  These parallel \texttt{breakafter*}.  It is possible to use \texttt{breakbefore} and \texttt{breakafter} for the same character, so long as \texttt{breakbeforegroup} and \texttt{breakaftergroup} have the same setting (\#117).
+% \item Added package options \texttt{finalizecache} and \texttt{frozencache}.  These allow the cache to be prepared for (\texttt{finalizecache}) and then used (\texttt{frozencache}) in an environment in which \texttt{-shell-escape}, Python, and/or Pygments are not available.  Note that this only works if \texttt{minted} content does not need to be modified, and if no settings that depend on Pygments or Python need to be changed (\#113).
+% \item Style names containing hyphens and underscores (\texttt{paraiso-light}, \texttt{paraiso-dark}, \texttt{algol\_nu}) now work (\#111).
+% \item The \texttt{shellesc} package is now loaded, when available, for compatibility with \texttt{luatex} 0.87+ (TeX Live 2016+, etc.).  \texttt{\string\ShellEscape} is now used everywhere instead of \texttt{\string\immediate\string\write18}.  If \texttt{shellesc} is not available, then a \texttt{\string\ShellEscape} macro is created.  When \texttt{shellesc} is loaded, there is a check for versions before v0.01c to patch a bug in v0.01b (present in TeX Live 2015) (\#112).
+% \item The \texttt{bgcolor} option now uses the \texttt{snugshade*} environment from the \texttt{framed} package, so \texttt{bgcolor} is now compatible with page breaks.  When \texttt{bgcolor} is in use, immediately preceding text will no longer push the \texttt{minted} environment into the margin, and there is now adequate spacing from surrounding text (\#121).
+% \item Added missing support for \texttt{fancyvrb}'s \texttt{labelposition} (\#102).
+% \item Improved fix for TikZ externalization, thanks to Patrick Vogt (\#73).
+% \item Fixed \texttt{breakautoindent}; it was disabled in version 2.1 due to a bug in \texttt{breakanywhere}.
+% \item Properly fixed handling of \texttt{\string\MintedPygmentize} (\#62).
+% \item Added note on incompatibility of \texttt{breaklines} and \texttt{obeytabs} options.  Trying to use these together will now result in a package error (\#99).  Added note on issues with \texttt{obeytabs} and multiline comments (\#88).  Due to the various \texttt{obeytabs} issues, the docs now discourage using \texttt{obeytabs}.
+% \item Added note to FAQ on \texttt{fancybox} and \texttt{fancyvrb} conflict (\#87).
+% \item Added note to docs on the need for \texttt{\string\VerbatimEnvironment} in environment definitions based on \texttt{minted} environments.
+% \end{changelog}
+%
+%
 % \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}.
@@ -449,6 +466,8 @@
 %   \item xstring
 %   \item xcolor
 %   \item lineno
+%   \item framed
+%   \item shellesc (for luatex 0.87+)
 % \end{list}
 % \endgroup
 % \end{multicols}
@@ -715,9 +734,35 @@
 % \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.
 %
-% Note that this directory is relative to the |outputdir|, if an |outputdir| is specified.
+% Special characters must be escaped.  For example, |cachedir=~/mintedcache| would not work because the tilde |~| would be converted into the \LaTeX\ commands for a non-breaking space, rather than being treated literally.  Instead, use |\string~/mintedcache|, |\detokenize{~/mintedcache}|, or an equivalent solution.
 %
+% Paths may contain spaces, but only if the entire \meta{directory} is wrapped in curly braces |{}|, and only if the spaces are quoted.  For example,
+%\begin{Verbatim}
+%cachedir = {\detokenize{~/"minted cache"/"with spaces"}}
+%\end{Verbatim}
 %
+% Note that the cache directory is relative to the |outputdir|, if an |outputdir| is specified.
+%
+%
+% \DescribeMacro{finalizecache=\meta{boolean} (default: false)}
+% In some cases, it may be desirable to use \pkg{minted} in an environment in which |-shell-escape| is not allowed.  A document might be submitted to a publisher or preprint server or used with an online service that does not support |-shell-escape|.  This is possible as long as \pkg{minted} content does not need to be modified.
+%
+% Compiling with the |finalizecache| option prepares the cache for use in an environment without |-shell-escape|.\footnote{Ordinarily, cache files are named using an MD5 hash of highlighting settings and highlighted text.  \texttt{finalizecache} renames cache files using a \texttt{listing<number>.pygtex} scheme.  This makes it simpler to match up document content and cache files, and is also necessary for the \texttt{XeTeX} engine since it lacks the built-in MD5 capabilities that \texttt{pdfTeX} and \texttt{LuaTeX} have.}  Once this has been done, the |finalizecache| option may be swapped for the |frozencache| option, which will then use the frozen (static) cache in the future, without needing |-shell-escape|.
+%
+%
+% \DescribeMacro{frozencache=\meta{boolean} (default: false)}
+% Use a frozen (static) cache created with the |finalizecache| option.  When |frozencache| is on, |-shell-escape| is not needed, and Python and Pygments are not required.  In addition, any external files accessed through |\inputminted| are no longer necessary.
+%
+% \textbf{This option must be used with care.  A document \emph{must} be in final form, as far as \pkg{minted} is concerned, \emph{before} \texttt{frozencache} is turned on, and the document \emph{must} have been compiled with \texttt{finalizecache}.   When this option is on, \pkg{minted} content cannot be modified, except by editing the cache files directly.  Changing any \pkg{minted} settings that require Pygments or Python is not possible.  If \pkg{minted} content is incorrectly modified after \texttt{frozencache} is turned on, \pkg{minted} \emph{cannot} detect the modification.}
+% 
+% If you are using |frozencache|, and want to verify that \pkg{minted} settings or content have not been modified in an invalid fashion, you can test the cache using the following procedure.
+% \begin{enumerate}
+% \item Obtain a copy of the cache used with |frozencache|.
+% \item Compile the document in an environment that supports |-shell-escape|, with |finalizecache=true| and |frozencache=false|.  This essentially regenerates the frozen (static) cache.
+% \item Compare the original cache with the newly generated cache.  Under Linux and OS X, you could use |diff|; under Windows, you probably want |fc|.  If \pkg{minted} content and settings have not been modified in an invalid fashion, all files will be identical (assuming that compatible versions of Pygments are used for both caches).
+% \end{enumerate}
+%
+%
 % \DescribeMacro{draft=\meta{boolean} (default: false)}
 % This uses \pkg{fancyvrb} alone for all typesetting; \app{Pygments} is not used.  This trades syntax highlighting and some other \app{minted} features for faster compiling.  Performance should be essentially the same as using \pkg{fancyvrb} directly; no external temporary files are used.  Note that if you are not changing much code between compiles, the difference in performance between caching and draft mode may be minimal.  Also note that |draft| settings are typically inherited from the document class.
 %
@@ -777,9 +822,9 @@
 %
 %
 % \DescribeMacro{outputdir=\meta{directory} (default: \meta{none})}
-% The |-output-directory| and |-aux-directory| (MiKTeX) command-line options for \LaTeX\ causes problems for \pkg{minted}, because the \pkg{minted} temporary files are saved in |<outputdir>|, but \pkg{minted} still looks for them in the document root directory.  There is no way to access the value of the command-line option so that \pkg{minted} can automatically look in the right place.  But it is possible to allow the output directory to be specified manually as a package option.
+% The |-output-directory| and |-aux-directory| (MiKTeX) command-line options for \LaTeX\ cause problems for \pkg{minted}, because the \pkg{minted} temporary files are saved in |<outputdir>|, but \pkg{minted} still looks for them in the document root directory.  There is no way to access the value of the command-line option so that \pkg{minted} can automatically look in the right place.  But it is possible to allow the output directory to be specified manually as a package option.
 %
-% The output directory should be specified using an absolute path or a path relative to the document root directory.  Paths should use forward spaces, even under Windows.  Paths that include spaces are not allowed.
+% The output directory should be specified using an absolute path or a path relative to the document root directory.  Paths should use forward spaces, even under Windows.  Special characters must be escaped, while spaces require quoting and need the entire \meta{directory} to be wrapped in curly braces |{}|.  See |cachedir| above for examples of escaping and quoting.
 %
 %
 % \DescribeMacro{section}
@@ -875,6 +920,8 @@
 %   \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}).
 %
+% For an alternative, see \texttt{breakbefore}.  When \texttt{breakbefore} and \texttt{breakafter} are used for the same character, \texttt{breakbeforegroup} and \texttt{breakaftergroup} must both have the same setting.
+%
 % \begin{longexample}
 %   \begin{minted}[breaklines, breakafter=d]{python}
 %   some_string = 'SomeTextThatGoesOnAndOnForSoLongThatItCouldNeverFitOnOneLine'
@@ -882,7 +929,7 @@
 % \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.
+%     When \texttt{breakafter} is used, group all adjacent identical characters together, and only allow a break after the last character.  When \texttt{breakbefore} and \texttt{breakafter} are used for the same character, \texttt{breakbeforegroup} and \texttt{breakaftergroup} must both have the same setting.
 %
 %   \item[breakaftersymbolpre (string) (+\string\,\string\footnotesize\string\ensuremath\{\_\string\rfloor\}, \,\footnotesize\ensuremath{_\rfloor}+)]
 %     The symbol inserted pre-break for breaks inserted by \texttt{breakafter}.
@@ -907,6 +954,27 @@
 %
 %   \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[breakbefore (string) (+\meta{none}+)]
+%     Break lines before specified characters, not just at spaces, when \texttt{breaklines=true}.  For example, \texttt{breakbefore=A} would allow breaks before capital A's.  Special characters given to \texttt{breakbefore} should be backslash-escaped (usually \texttt{\hashchar}, \texttt{\{}, \texttt{\}}, \texttt{\%}, \texttt{[}, \texttt{]}; the backslash \texttt{\textbackslash} may be obtained via \texttt{\textbackslash\textbackslash}).
+%
+%  For an alternative, see \texttt{breakafter}.  When \texttt{breakbefore} and \texttt{breakafter} are used for the same character, \texttt{breakbeforegroup} and \texttt{breakaftergroup} must both have the same setting.
+%
+% \begin{longexample}
+%   \begin{minted}[breaklines, breakbefore=A]{python}
+%   some_string = 'SomeTextThatGoesOnAndOnForSoLongThatItCouldNeverFitOnOneLine'
+%   \end{minted}
+% \end{longexample}
+%
+%   \item[breakbeforegroup] (boolean) (+true+)
+%     When \texttt{breakbefore} is used, group all adjacent identical characters together, and only allow a break before the first character.  When \texttt{breakbefore} and \texttt{breakafter} are used for the same character, \texttt{breakbeforegroup} and \texttt{breakaftergroup} must both have the same setting.
+%
+%   \item[breakbeforesymbolpre (string) (+\string\,\string\footnotesize\string\ensuremath\{\_\string\rfloor\}, \,\footnotesize\ensuremath{_\rfloor}+)]
+%     The symbol inserted pre-break for breaks inserted by \texttt{breakbefore}.
+%
+%   \item[breakbeforesymbolpost (string) (+\meta{none}+)]
+%     The symbol inserted post-break for breaks inserted by \texttt{breakbefore}.
+%
 %   \item[breakbytoken (boolean) (+false+)]
 %   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.
 %
@@ -917,8 +985,12 @@
 %   \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}.  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.)
+%     Automatically break long lines in \texttt{minted} environments and \texttt{\string\mint} commands, and wrap longer lines in \texttt{\string\mintinline}.
 %
+% \textbf{This is not compatible with the option \texttt{obeytabs}.}  Additional information about the incompatibility is on \href{https://github.com/gpoore/minted/issues/99}{GitHub}.
+%
+% 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.
 %   \begin{minted}[breaklines]{python}
@@ -998,10 +1070,10 @@
 %     The separation between the \texttt{breaksymbolright} and the adjacent code.
 %
 %   \item[bgcolor (string) (\meta{none})]
-%     Background color of the listing.
-%     Notice that the value of this option must \emph{not} be a color command. Instead, it must be a color
-%     \emph{name}, given as a string, of a previously-defined color:
+%     Background color of the listing.  Be aware that this option has several limitations (described below); see ``Framing alternatives'' below for more powerful alternatives.
 %
+%     The value of this option must \emph{not} be a color command. Instead, it must be a color \emph{name}, given as a string, of a previously-defined color:
+%
 % \begin{example}
 %   \definecolor{bg}{rgb}{0.95,0.95,0.95}
 %   \begin{minted}[bgcolor=bg]{php}
@@ -1011,11 +1083,15 @@
 %   \end{minted}
 % \end{example}
 %
-% This option puts \texttt{minted} environments and \texttt{\string\mint} commands in a minipage with a colored background.  It puts \texttt{\string\mintinline} inside a \texttt{\string\colorbox}.  If you want to use \texttt{\string\setminted} to set background colors, and only want background colors on \texttt{minted} and \texttt{\string\mint}, you may use \texttt{\string\setmintedinline\{bgcolor=\{\}\}} to turn off the coloring for inline commands.
+% This option puts \texttt{minted} environments and \texttt{\string\mint} commands in a \texttt{snugshade*} environment from the \pkg{framed} package, which supports breaks across pages.  (Prior to \pkg{minted} 2.2, a \texttt{minipage} was used, which prevented page breaks and gave undesirable spacing from surrounding text.)  Be aware that if \texttt{bgcolor} is used with \texttt{breaklines=true}, and a line break occurs just before a page break, then text may extend below the colored background in some instances.  It is best to use a more advanced framing package in those cases; see ``Framing alternatives'' below.
 %
-% \textbf{This option will prevent \texttt{breaklines} from working with \texttt{\string\mintinline}.}  A \texttt{\string\colorbox} cannot break across lines.
+% This option puts \texttt{\string\mintinline} inside a \texttt{\string\colorbox}, which \textbf{does not allow line breaks}.  If you want to use \texttt{\string\setminted} to set background colors, and only want background colors on \texttt{minted} and \texttt{\string\mint}, you may use \texttt{\string\setmintedinline\{bgcolor=\{\}\}} to turn off the coloring for inline commands.
 %
-% \textbf{This option will prevent environments from breaking across pages.}  If you want support for page breaks and advanced options, you should consider a framing package such as \pkg{framed}, \pkg{mdframed}, or \pkg{tcolorbox}.  It is easy to add framing to \pkg{minted} commands and environments using the \pkg{etoolbox} package.  For example, using \pkg{mdframed}:
+% ~
+%
+% \textbf{Framing alternatives}
+%
+% If you want more reliable and advanced options for background colors and framing, you should consider a more advanced framing package such as \pkg{mdframed} or \pkg{tcolorbox}.  It is easy to add framing to \pkg{minted} commands and environments using the \pkg{etoolbox} package, which is automatically loaded by \pkg{minted}.  For example, using \pkg{mdframed}:
 %\begin{Verbatim}
 %\BeforeBeginEnvironment{minted}{\begin{mdframed}}
 %\AfterEndEnvironment{minted}{\end{mdframed}}
@@ -1024,7 +1100,16 @@
 %\begin{Verbatim}
 %\surroundwithmdframed{minted}
 %\end{Verbatim}
-% \pkg{tcolorbox} even provides a built-in framing environment with \pkg{minted} support.
+% \pkg{tcolorbox} even provides a built-in framing environment with \pkg{minted} support.  Simply use \texttt{\string\tcbuselibrary\{minted\}} in the preamble, and then put code within a \texttt{tcblisting} environment:
+%\begin{Verbatim}
+%\begin{tcblisting}{<tcb options>,
+%                   minted language=<language>,
+%                   minted style=<style>,
+%                   minted options={<option list>} }
+%<code>
+%\end{tcblisting}
+%\end{Verbatim}
+% \pkg{tcolorbox} provides other commands and environments for fine-tuning listing appearance and for working with external code files.
 %
 %   \item[codetagify (list of strings) (highlight +XXX+, +TODO+, +BUG+, and +NOTE+)]
 %     Highlight special code tags in comments and docstrings.
@@ -1113,7 +1198,15 @@
 %   \item[numbersep (dimension) (+12pt+)]
 %     Gap between numbers and start of line.
 %   \item[obeytabs (boolean) (+false+)]
+% \textbf{\textcolor{red}{Due to the many issues with \pkg{fancyvrb}'s implementation of \texttt{obeytabs}, this option should be avoided if possible.}}
+%
 %     Treat tabs as tabs instead of converting them to spaces.
+%
+% \textbf{This is not compatible with the option \texttt{breaklines}.}
+%
+% \textbf{This will cause errors with tabbed indentation inside multiline comments.}
+%
+% There is a \href{https://github.com/gpoore/minted/issues/99}{GitHub issue} with additional technical details.
 %   \item[outencoding (string) (system-specific)]
 %     Sets the file encoding that \app{Pygments} uses for highlighted output.  Overrides any encoding previously set via +encoding+.
 %   \item[python3 (boolean) (+false+)] \appliesto{PythonConsoleLexer}
@@ -1198,6 +1291,12 @@
 % If this name clashes with another environment or if you want to choose an own name for another reason, you may
 % do so by specifying it as the first argument: \cmd\newminted\oarg{environment name}\marg{language}\marg{options}.
 %
+% Like normal \pkg{minted} environments, environments created with |\newminted| may be used within other environment definitions.  Since the \pkg{minted} environments use \pkg{fancyvrb} internally, any environment based on them must include the \pkg{fancyvrb} command |\VerbatimEnvironment|.  This allows \pkg{fancyvrb} to determine the name of the environment that is being defined, and correctly find its end.  It is best to include this command at the beginning of the definition.  For example,
+%\begin{Verbatim}
+%\newminted{cpp}{gobble=2,linenos}
+%\newenvironment{env}{\VerbatimEnvironment\begin{cppcode}}{\end{cppcode}}
+%\end{Verbatim}
+%
 % \DescribeMacro{\newmint}
 % The above macro only defines shortcuts for the |minted| environment.
 % The main reason is that the short command form |\mint| often needs different options---at the very least, it
@@ -1236,7 +1335,9 @@
 % 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 ``Font Warning:  Some font shapes were not available'' message, or bold or italic seem to be missing.}  This due to a limitation in the font that is currently in use for typesetting code.  In some cases, the default font shapes that \LaTeX\ substitutes are perfectly adequate, and the warning may be ignored.  In other cases, the font substitutions may not clearly indicate bold or italic text, and you will want to switch to a different font.  See The \LaTeX\ Font Catalogue's section on \href{http://www.tug.dk/FontCatalogue/typewriterfonts.html}{Typewriter Fonts} for alternatives.  If you like the default \LaTeX\ fonts, the \pkg{lmodern} package is a good place to start.  The \pkg{beramono} and \pkg{courier} packages may also be good options.
 % \item \textbf{I receive a ``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{Weird things happen when I use the \pkg{fancybox} package.}  \pkg{fancybox} conflicts with \pkg{fancyvrb}, which \pkg{minted} uses internally.  When using \pkg{fancybox}, make sure that it is loaded before \pkg{minted} (or before \pkg{fancyvrb}, if \pkg{fancyvrb} is not loaded by \pkg{minted}).
 % \item \textbf{When I use \pkg{minted} with KOMA-Script document classes, I get warnings about \texttt{\string\float at 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.
@@ -1306,6 +1407,7 @@
 %
 % \item \textbf{I want extended characters in frame labels, but am getting errors.}  This can happen with \pkg{minted} <2.0 and Python 2.7, due to a \href{https://bitbucket.org/birkenfeld/pygments-main/issue/801/python-2-fails-to-detect-terminal-encoding}{terminal encoding issue with Pygments}.  It should work with any version of Python with \pkg{minted} 2.0+, which processes labels internally and does not send them to Python.
 % \item \textbf{\texttt{minted} environments have extra vertical space inside \texttt{tabular}.}  It is possible to \href{https://github.com/gpoore/minted/issues/82}{create a custom environment} that eliminates the extra space.  However, a general solution that behaves as expected in the presence of adjacent text remains to be found.
+% \item \textbf{I'm receiving a warning from \texttt{lineno.sty} that ``Command \texttt{\string\@parboxrestore} has changed.''}  This can happen when \pkg{minted} is loaded after \pkg{csquotes}.  Try loading \pkg{minted} first.  If you receive this message when you are not using \pkg{csquotes}, you may want to experiment with the order of loading packages and might also open an issue.
 % \end{itemize}
 %
 %
@@ -1315,7 +1417,7 @@
 %
 % Konrad Rudolph:  Special thanks to Philipp Stephani and the rest of the guys from \texttt{comp.text.tex} and \texttt{tex.stackexchange.com}.
 %
-% Geoffrey Poore:  Thanks to Marco Daniel for the code on \url{tex.stackexchange.com} that inspired automatic line breaking.
+% Geoffrey Poore:  Thanks to Marco Daniel for the code on \url{tex.stackexchange.com} that inspired automatic line breaking.  Thanks to Patrick Vogt for improving TikZ externalization compatibility.
 %
 % \PrintChangelog
 %
@@ -1343,6 +1445,13 @@
 \RequirePackage{etoolbox}
 \RequirePackage{xstring}
 \RequirePackage{lineno}
+\RequirePackage{framed}
+\IfFileExists{shellesc.sty}
+ {\RequirePackage{shellesc}
+  \@ifpackagelater{shellesc}{2016/04/29}
+   {}
+   {\protected\def\ShellEscape{\immediate\write18 }}}
+ {\protected\def\ShellEscape{\immediate\write18 }}
 %    \end{macrocode}
 %
 % Make sure that either |color| or |xcolor| is loaded by the beginning of the document.
@@ -1387,7 +1496,7 @@
 %
 %
 % \begin{macro}{\minted at 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.
+% 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 at jobname]
 \StrSubstitute{\minted at jobname}{*}{_}[\minted at jobname]
@@ -1408,6 +1517,22 @@
 % \end{macro}
 %
 %
+% \begin{macro}{finalizecache}
+% Define an option that switches the naming of cache files from an MD5-based system to a |listing<number>| scheme.  Compiling with this option is a prerequisite to turning on |frozencache|.
+%    \begin{macrocode}
+\DeclareBoolOption{finalizecache}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{frozencache}
+% Define an option that uses a fixed set of cache files, using |listing<number>| file naming with |\write18| disabled.  This is convenient for working with a document in an environment in which |\write18| support is disabled and \pkg{minted} content does not need to be modified.
+%    \begin{macrocode}
+\DeclareBoolOption{frozencache}
+%    \end{macrocode}
+% \end{macro}
+%
+%
 % \begin{macro}{\minted at outputdir}
 % The |-output-directory| command-line option for \LaTeX\ causes problems for \pkg{minted}, because the \pkg{minted} temporary files are saved in the output directory, but \pkg{minted} still looks for them in the document root directory.  There is no way to access the value of the command-line option.  But it is possible to allow the output directory to be specified manually as a package option.  A trailing slash is automatically appended to the |outputdir|, so that it may be directly joined to |cachedir|.  This may be redundant if the user-supplied value already ends with a slash, but doubled slashes are ignored under *nix and Windows, so it isn't a problem.
 %    \begin{macrocode}
@@ -1452,18 +1577,32 @@
 % \end{macro}
 %
 %
-% 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.
+% 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.  Two checks are done for externalization.  The first, using |\tikzifexternalizing|, works if externalization is set before \pkg{minted} is loaded.  The second, using |\tikzexternalrealjob|, works if externalization is set after \pkg{minted} is loaded.
 %
 %    \begin{macrocode}
 \ProcessKeyvalOptions*
 \ifthenelse{\boolean{minted at newfloat}}{\RequirePackage{newfloat}}{}
-\ifcsname tikzexternalrealjob\endcsname
-  \minted at drafttrue
-  \minted at cachefalse
+\ifcsname tikzifexternalizing\endcsname 
+  \tikzifexternalizing{\minted at drafttrue\minted at cachefalse}{}
 \else
+  \ifcsname tikzexternalrealjob\endcsname
+    \minted at drafttrue
+    \minted at cachefalse
+  \else
+  \fi
 \fi
-\ifthenelse{\boolean{minted at cache}}{%
-  \AtEndOfPackage{\ProvideDirectory{\minted at outputdir\minted at cachedir}}}{}
+\ifthenelse{\boolean{minted at finalizecache}}%
+ {\ifthenelse{\boolean{minted at frozencache}}%
+   {\PackageError{minted}%
+     {Options "finalizecache" and "frozencache" are not compatible}%
+     {Options "finalizecache" and "frozencache" are not compatible}}%
+   {}}%
+ {}
+\ifthenelse{\boolean{minted at cache}}%
+ {\ifthenelse{\boolean{minted at frozencache}}%
+   {}%
+   {\AtEndOfPackage{\ProvideDirectory{\minted at outputdir\minted at cachedir}}}}%
+ {}
 %    \end{macrocode}
 %
 %
@@ -1480,11 +1619,12 @@
      was^^Jprobably given a file that does not exist--otherwise, you may need 
      ^^Jthe outputdir package option, or may be using an incompatible build
      tool\ifwindows,^^Jor may be using the kpsewhich option without having
-     PowerShell installed\fi}%
+     PowerShell installed\fi,^^Jor may be using frozencache with a missing file}%
     {This could be caused by using -output-directory or -aux-directory
      ^^Jwithout setting minted's outputdir, or by using a build tool that
      ^^Jchanges paths in ways minted cannot detect\ifwindows, or by using the
-     ^^Jkpsewhich option without PowerShell\fi.}}%
+     ^^Jkpsewhich option without PowerShell\fi,
+     ^^Jor using frozencache with a missing file.}}%
 }
 %    \end{macrocode}
 % \end{macro}
@@ -1558,14 +1698,20 @@
 % At the end of the document, save the list of cache files and clean the cache.  If in draft mode, don't clean up the cache and save the old cache file list for next time.  This allows draft mode to be switched on and off without requiring that all highlighted content be regenerated.  The saving and cleaning operations may be called without conditionals, since their definitions already contain all necessary checks for their correct operation.
 %    \begin{macrocode}
 \ifthenelse{\boolean{minted at draft}}%
-  {\AtEndDocument{%
+ {\AtEndDocument{%
+    \ifcsname minted at oldcachelist\endcsname
+      \StrSubstitute{\minted at oldcachelist}{,}{,^^J }[\minted at cachelist]
+      \minted at savecachelist
+    \fi}}%
+ {\ifthenelse{\boolean{minted at frozencache}}%
+   {\AtEndDocument{%
       \ifcsname minted at oldcachelist\endcsname
-        \let\minted at cachelist\minted at oldcachelist
+        \StrSubstitute{\minted at oldcachelist}{,}{,^^J }[\minted at cachelist]
         \minted at savecachelist
       \fi}}%
-  {\AtEndDocument{%
-      \minted at savecachelist
-      \minted at cleancache}}%
+   {\AtEndDocument{%
+    \minted at savecachelist
+    \minted at cleancache}}}%
 %    \end{macrocode}
 %
 %
@@ -1582,15 +1728,15 @@
 \ifwindows
   \providecommand{\DeleteFile}[2][]{%
     \ifthenelse{\equal{#1}{}}%
-      {\IfFileExists{#2}{\immediate\write18{del "#2"}}{}}%
+      {\IfFileExists{#2}{\ShellEscape{del #2}}{}}%
       {\IfFileExists{#1/#2}{%
         \StrSubstitute{#1}{/}{\@backslashchar}[\minted at windir]
-        \immediate\write18{del "\minted at windir\@backslashchar #2"}}{}}}
+        \ShellEscape{del \minted at windir\@backslashchar #2}}{}}}
 \else
   \providecommand{\DeleteFile}[2][]{%
     \ifthenelse{\equal{#1}{}}%
-      {\IfFileExists{#2}{\immediate\write18{rm "#2"}}{}}%
-      {\IfFileExists{#1/#2}{\immediate\write18{rm "#1/#2"}}{}}}
+      {\IfFileExists{#2}{\ShellEscape{rm #2}}{}}%
+      {\IfFileExists{#1/#2}{\ShellEscape{rm #1/#2}}{}}}
 \fi
 %    \end{macrocode}
 % \end{macro}
@@ -1604,10 +1750,10 @@
 \ifwindows
   \newcommand{\ProvideDirectory}[1]{%
     \StrSubstitute{#1}{/}{\@backslashchar}[\minted at windir]
-    \immediate\write18{if not exist "\minted at windir" mkdir "\minted at windir"}}
+    \ShellEscape{if not exist \minted at windir\space mkdir \minted at windir}}
 \else
   \newcommand{\ProvideDirectory}[1]{%
-    \immediate\write18{mkdir -p "#1"}}
+    \ShellEscape{mkdir -p #1}}
 \fi
 %    \end{macrocode}
 % \end{macro}
@@ -1639,9 +1785,9 @@
 %
 %    \begin{macrocode}
     \DeleteFile{\minted at jobname.aex}
-    \immediate\write18{for \string^\@percentchar i in (#1.exe #1.bat #1.cmd)
-      do set >"\minted at jobname.aex" <nul: /p 
-      x=\string^\@percentchar \string~$PATH:i>>"\minted at jobname.aex"}
+    \ShellEscape{for \string^\@percentchar i in (#1.exe #1.bat #1.cmd)
+      do set > \minted at jobname.aex <nul: /p 
+      x=\string^\@percentchar \string~$PATH:i>> \minted at jobname.aex}
     %$ <- balance syntax highlighting
     \immediate\openin\minted at appexistsfile\minted at jobname.aex
     \expandafter\def\expandafter\@tmp at cr\expandafter{\the\endlinechar}
@@ -1659,7 +1805,7 @@
 % 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 "\minted at jobname.aex"}
+    \ShellEscape{which #1 && touch \minted at jobname.aex}
     \IfFileExists{\minted at jobname.aex}
       {\AppExiststrue
         \DeleteFile{\minted at jobname.aex}}
@@ -1824,7 +1970,7 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% This covers the typical options that must be passed to Pygments.  But some, particularly |escapeinside|, need more work.  Since their arguments may contain escaped characters, expansion rather than detokenization is needed.  Getting expansion to work as desired in a |\write18| context requires the redefinition of some characters
+% This covers the typical options that must be passed to Pygments.  But some, particularly |escapeinside|, need more work.  Since their arguments may contain escaped characters, expansion rather than detokenization is needed.  Getting expansion to work as desired in a |\write18| context requires the redefinition of some characters.
 %
 % \begin{macro}{\minted at escchars}
 % We need to define versions of common escaped characters that will work correctly under expansion for use in |\write18|.
@@ -2128,7 +2274,7 @@
 % \begin{macro}{\minted at 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.
+% We have to do some tricks with |\endlinechar| to prevent |\input| from inserting unwanted whitespace.  That is primarily for inline commands, where it would introduce a line break.  There is also the very unorthodox |\let\def\gdef| to make sure that macros are defined globally.  The catcodes for |-| and |_| must be changed during macro definition to accomodate style names like |paraiso-light|, |paraiso-dark|, and |algol_nu|.
 %
 % 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.
 %
@@ -2139,42 +2285,51 @@
     \expandafter\gdef%
       \csname minted at styleloaded@\ifstrempty{#1}{default-pyg-prefix}{#1}\endcsname{}%
     \ifthenelse{\boolean{minted at cache}}%
-      {\IfFileExists
+     {\IfFileExists
        {\minted at outputdir\minted at 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 at outputdir@windows\minted at 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 at outputdir\minted at cachedir/%
-                 \ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle"}%
-        \fi
+        \ifthenelse{\boolean{minted at frozencache}}%
+         {\PackageError{minted}%
+           {Missing style definition for #1 with frozencache}%
+           {Missing style definition for #1 with frozencache}}%
+         {\ifwindows
+            \ShellEscape{%
+              \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex 
+              -P commandprefix=PYG#1
+              > \minted at outputdir@windows\minted at cachedir@windows\@backslashchar%
+                   \ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}%
+          \else
+            \ShellEscape{%
+              \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex 
+              -P commandprefix=PYG#1
+              > \minted at outputdir\minted at cachedir/%
+                   \ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}%
+          \fi}%
         }%
         \begingroup
         \let\def\gdef
+        \catcode`\_=11
+        \catcode`\-=11
         \endlinechar=-1\relax
         \minted at input{%
           \minted at outputdir\minted at cachedir/\ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}%
         \endgroup
         \minted at addcachefile{\ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}}%
-      {\ifwindows
-          \immediate\write18{%
+     {%
+        \ifwindows
+          \ShellEscape{%
             \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
-            -P commandprefix=PYG#1 > "\minted at outputdir@windows\minted at jobname.out.pyg"}%
+            -P commandprefix=PYG#1 > \minted at outputdir@windows\minted at jobname.out.pyg}%
         \else
-          \immediate\write18{%
+          \ShellEscape{%
             \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
-            -P commandprefix=PYG#1 > "\minted at outputdir\minted at jobname.out.pyg"}%
+            -P commandprefix=PYG#1 > \minted at outputdir\minted at jobname.out.pyg}%
         \fi
         \begingroup
         \let\def\gdef
+        \catcode`\_=11
+        \catcode`\-=11
         \endlinechar=-1\relax
         \minted at input{\minted at outputdir\minted at jobname.out.pyg}%
         \endgroup}%
@@ -2184,9 +2339,9 @@
 %    \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|.  
+% At the beginning of the document, create the symbol macros with |PYG| prefix and generate the |default| style.  This must wait until |\AtBeginDocument|, because the existence of |pygmentize| isn't tested and may not be final until |\AtEndPreamble|.
 %    \begin{macrocode}
-\AtBeginDocument{\minted at checkstyle{}}
+\AtBeginDocument{\minted at checkstyle{}\setminted{style=default}}
 %    \end{macrocode}
 %
 %
@@ -2344,6 +2499,7 @@
 \minted at def@optfv{fontseries}
 \minted at def@optfv{formatcom}
 \minted at def@optfv{label}
+\minted at def@optfv{labelposition}
 \minted at def@optfv at switch{numberblanklines}
 \minted at def@optfv at switch{showspaces}
 \minted at def@optfv at switch{resetmargins}
@@ -2363,6 +2519,10 @@
 \minted at def@optfv{breaksymbolright}
 \minted at def@optfv{breaksymbolsepright}
 \minted at def@optfv{breaksymbolindentright}
+\minted at def@optfv{breakbefore}
+\minted at def@optfv{breakbeforesymbolpre}
+\minted at def@optfv{breakbeforesymbolpost}
+\minted at def@optfv at switch{breakbeforegroup}
 \minted at def@optfv{breakafter}
 \minted at def@optfv at switch{breakaftergroup}
 \minted at def@optfv{breakaftersymbolpre}
@@ -2380,7 +2540,7 @@
 \minted at def@opt at switch{breakbytokenanywhere}
 %    \end{macrocode}
 %
-% |bgcolor|:  The old |bgcolor| is retained for compatibility.  A dedicated framing package will often be preferable.
+% |bgcolor|.  The original, |minipage|- and |\colorbox|-based solution was replaced with a |framed|-based solution in version 2.2.  A dedicated framing package will often be preferable.
 %    \begin{macrocode}
 \minted at def@opt{bgcolor}
 %    \end{macrocode}
@@ -2584,6 +2744,64 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\FV at BreakBefore}
+% Allow line breaking (almost) anywhere, but only before specified characters.
+%    \begin{macrocode}
+\define at key{FV}{breakbefore}{%
+  \ifstrempty{#1}%
+   {\let\FV at BreakBefore\@empty
+    \let\FancyVerbBreakStart\relax
+    \let\FancyVerbBreakStop\relax}%
+   {\def\FV at BreakBefore{#1}%
+    \let\FancyVerbBreakStart\FV at Break
+    \let\FancyVerbBreakStop\FV at EndBreak
+    \let\FV at Break@Token\FV at Break@BeforeAfterToken}%
+}
+\fvset{breakbefore={}}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{FV at BreakBeforeGroup}
+% Determine whether breaking before specified characters is always allowed before each individual character, or is only allowed before the first in a group of identical characters.
+%    \begin{macrocode}
+\newboolean{FV at BreakBeforeGroup}
+\define at booleankey{FV}{breakbeforegroup}%
+ {\FV at BreakBeforeGrouptrue}%
+ {\FV at BreakBeforeGroupfalse}%
+\fvset{breakbeforegroup=true}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV at BreakBeforePrep}
+% We need a way to break before 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 at FormattingPrep|, which is inside a group and before processing starts.  The macro is added to |\FV at FormattingPrep| below, after |\FV at BreakAfterPrep| is defined.
+%
+% The procedure here is a bit roundabout.  We need to use |\FV at 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 at EscChars|.
+%    \begin{macrocode}
+\def\FV at BreakBeforePrep{%
+  \ifx\FV at BreakBefore\@empty\relax
+  \else
+    \gdef\FV at BreakBefore@Def{}%
+    \begingroup
+    \def\FV at BreakBefore@Process##1##2\FV at Undefined{%
+      \expandafter\FV at BreakBefore@Process at i\expandafter{##1}%
+      \expandafter\ifx\expandafter\relax\detokenize{##2}\relax
+      \else
+        \FV at BreakBefore@Process##2\FV at Undefined
+      \fi
+    }%
+    \def\FV at BreakBefore@Process at i##1{%
+      \g at addto@macro\FV at BreakBefore@Def{%
+        \@namedef{FV at BreakBefore@Token\detokenize{##1}}{}}%
+    }%
+    \FV at EscChars
+    \expandafter\FV at BreakBefore@Process\FV at BreakBefore\FV at Undefined
+    \endgroup
+    \FV at BreakBefore@Def
+  \fi
+}
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\FV at BreakAfter}
 % Allow line breaking (almost) anywhere, but only after specified characters.
 %    \begin{macrocode}
@@ -2595,7 +2813,7 @@
    {\def\FV at BreakAfter{#1}%
     \let\FancyVerbBreakStart\FV at Break
     \let\FancyVerbBreakStop\FV at EndBreak
-    \let\FV at Break@Token\FV at Break@AfterToken}%
+    \let\FV at Break@Token\FV at Break@BeforeAfterToken}%
 }
 \fvset{breakafter={}}
 %    \end{macrocode}
@@ -2630,6 +2848,20 @@
       \fi
     }%
     \def\FV at BreakAfter@Process at i##1{%
+      \ifcsname FV at BreakBefore@Token\detokenize{##1}\endcsname
+        \ifthenelse{\boolean{FV at BreakBeforeGroup}}%
+         {\ifthenelse{\boolean{FV at BreakAfterGroup}}%
+           {}%
+           {\PackageError{minted}%
+            {Conflicting breakbeforegroup and breakaftergroup for "\detokenize{##1}"}%
+            {Conflicting breakbeforegroup and breakaftergroup for "\detokenize{##1}"}}}%
+         {\ifthenelse{\boolean{FV at BreakAfterGroup}}%
+           {\PackageError{minted}%
+             {Conflicting breakbeforegroup and breakaftergroup for "\detokenize{##1}"}%
+             {Conflicting breakbeforegroup and breakaftergroup for "\detokenize{##1}"}}%
+           {}}%
+      \else
+      \fi
       \g at addto@macro\FV at BreakAfter@Def{%
         \@namedef{FV at BreakAfter@Token\detokenize{##1}}{}}%
     }%
@@ -2639,11 +2871,16 @@
     \FV at BreakAfter@Def
   \fi
 }
-\expandafter\def\expandafter\FV at FormattingPrep\expandafter{%
-  \expandafter\FV at BreakAfterPrep\FV at FormattingPrep}
 %    \end{macrocode}
 % \end{macro}
 %
+% Now that |\FV at BreakBeforePrep| and |\FV at BreakAfterPrep| are defined, add them to |\FV at FormattingPrep|.  The ordering here is important, since |\FV at BreakAfterPrep| contains compatibility checks with |\FV at BreakBeforePrep|, and thus must be used after it.
+%    \begin{macrocode}
+\expandafter\def\expandafter\FV at FormattingPrep\expandafter{%
+  \expandafter\FV at BreakBeforePrep\expandafter\FV at BreakAfterPrep\FV at FormattingPrep}
+%    \end{macrocode}
+%
+%
 % \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}
@@ -2666,6 +2903,28 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\FancyVerbBreakBeforeSymbolPre}
+% The pre-break symbol for breaks introduced by |breakbefore|.
+%    \begin{macrocode}
+\define at key{FV}{breakbeforesymbolpre}{%
+  \ifstrempty{#1}%
+    {\def\FancyVerbBreakBeforeSymbolPre{}}%
+    {\def\FancyVerbBreakBeforeSymbolPre{\hbox{#1}}}}
+\fvset{breakbeforesymbolpre={\,\footnotesize\ensuremath{_\rfloor}}}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FancyVerbBreakBeforeSymbolPost}
+% The post-break symbol for breaks introduced by |breakbefore|.
+%    \begin{macrocode}
+\define at key{FV}{breakbeforesymbolpost}{%
+  \ifstrempty{#1}%
+    {\def\FancyVerbBreakBeforeSymbolPost{}}%
+    {\def\FancyVerbBreakBeforeSymbolPost{\hbox{#1}}}}
+\fvset{breakbeforesymbolpost={}}
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\FancyVerbBreakAfterSymbolPre}
 % The pre-break symbol for breaks introduced by |breakafter|.
 %    \begin{macrocode}
@@ -2700,6 +2959,15 @@
 % \end{macro}
 %
 %
+% \begin{macro}{\FancyVerbBreakBeforeBreak}
+% The macro governing breaking for |breakbefore=true|.
+%    \begin{macrocode}
+\newcommand{\FancyVerbBreakBeforeBreak}{%
+  \discretionary{\FancyVerbBreakBeforeSymbolPre}%
+   {\FancyVerbBreakBeforeSymbolPost}{}}
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\FancyVerbBreakAfterBreak}
 % The macro governing breaking for |breakafter=true|.
 %    \begin{macrocode}
@@ -2759,13 +3027,14 @@
 % \end{macro}
 %
 %
-% Define the macros that actually perform |breakanywhere|.
+% Define the macros that actually perform |breakanywhere|, |breakbefore|, and |breakafter|.
 %
 % \begin{macro}{\FV at 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 at Tmp|.  After scanning is complete, |\FV at 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.}
+% The entry macro for breaking lines, either anywhere or before/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 at Tmp|.  After scanning is complete, |\FV at 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 at Break{%
   \def\FV at Tmp{}%
+  \let\FV at LastToken\minted at undefined
   \FV at Break@Scan
 }
 %    \end{macrocode}
@@ -2809,6 +3078,7 @@
 \catcode`\$=3%
 \gdef\FV at Break@Math$#1${%
   \g at addto@macro{\FV at Tmp}{$#1$}%
+  \let\FV at LastToken\minted at undefined
   \FV at Break@Scan}
 \endgroup
 %    \end{macrocode}
@@ -2819,12 +3089,13 @@
 %    \begin{macrocode}
 \def\FV at Break@Group#1{%
   \g at addto@macro{\FV at Tmp}{{#1}}%
+  \ifstrempty{#1}{}{\let\FV at LastToken\minted at undefined}%
   \FV at Break@Scan}
 %    \end{macrocode}
 % \end{macro}
 %
 % \begin{macro}{\FV at Break@Token}
-% This macro is |\let| to |\FV at Break@AnyToken| or |\FV at Break@AfterToken| by the |breakanywhere| and |breakafter| options, so it is not explicitly defined.
+% This macro is |\let| to |\FV at Break@AnyToken| or |\FV at Break@BeforeAfterToken| by the |breakanywhere| and |breakbefore|/|breakafter| options, so it is not explicitly defined.
 % \end{macro}
 %
 % \begin{macro}{\FV at Break@AnyToken}
@@ -2851,23 +3122,63 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\FV at Break@AfterToken}
+% \begin{macro}{\FV at Break@BeforeAfterToken}
 % 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 at Break@AfterToken#1{%
-  \ifcsname FV at BreakAfter@Token\detokenize{#1}\endcsname
-    \let\FV at Break@Next\FV at Break@AfterTokenBreak
+\def\FV at Break@BeforeAfterToken#1{%
+  \ifcsname FV at BreakBefore@Token\detokenize{#1}\endcsname
+    \let\FV at Break@Next\FV at Break@BeforeTokenBreak
   \else
-    \let\FV at Break@Next\FV at Break@AfterTokenNoBreak
+    \ifcsname FV at BreakAfter@Token\detokenize{#1}\endcsname
+      \let\FV at Break@Next\FV at Break@AfterTokenBreak
+    \else
+      \let\FV at Break@Next\FV at Break@BeforeAfterTokenNoBreak
+    \fi
   \fi
   \FV at Break@Next{#1}%
 }
-\def\FV at Break@AfterTokenNoBreak#1{%
+\def\FV at Break@BeforeAfterTokenNoBreak#1{%
   \g at addto@macro{\FV at Tmp}{#1}%
+  \let\FV at LastToken#1%
   \FV at Break@Scan}
+\def\FV at Break@BeforeTokenBreak#1{%
+  \ifthenelse{\boolean{FV at BreakBeforeGroup}}%
+   {\ifx#1\FV at LastToken\relax
+      \ifcsname FV at BreakAfter@Token\detokenize{#1}\endcsname
+        \let\FV at Break@Next\FV at Break@BeforeTokenBreak at AfterRescan
+        \def\FV at RescanToken{#1}%
+      \else
+        \g at addto@macro{\FV at Tmp}{#1}%
+        \let\FV at Break@Next\FV at Break@Scan
+        \let\FV at LastToken#1%
+      \fi
+    \else
+      \ifcsname FV at BreakAfter@Token\detokenize{#1}\endcsname
+        \g at addto@macro{\FV at Tmp}{\FancyVerbBreakBeforeBreak}%
+        \let\FV at Break@Next\FV at Break@BeforeTokenBreak at AfterRescan
+        \def\FV at RescanToken{#1}%
+      \else
+        \g at addto@macro{\FV at Tmp}{\FancyVerbBreakBeforeBreak#1}%
+        \let\FV at Break@Next\FV at Break@Scan
+        \let\FV at LastToken#1%
+      \fi
+    \fi}%
+   {\ifcsname FV at BreakAfter@Token\detokenize{#1}\endcsname
+      \g at addto@macro{\FV at Tmp}{\FancyVerbBreakBeforeBreak}%
+      \let\FV at Break@Next\FV at Break@BeforeTokenBreak at AfterRescan
+      \def\FV at RescanToken{#1}%
+    \else
+      \g at addto@macro{\FV at Tmp}{\FancyVerbBreakBeforeBreak#1}%
+      \let\FV at Break@Next\FV at Break@Scan
+      \let\FV at LastToken#1%
+    \fi}%
+  \FV at Break@Next}
+\def\FV at Break@BeforeTokenBreak at AfterRescan{%
+  \expandafter\FV at Break@AfterTokenBreak\FV at RescanToken}
 \def\FV at Break@AfterTokenBreak#1{%
+  \let\FV at LastToken#1%
   \@ifnextchar\FV at Space%
    {\g at addto@macro{\FV at Tmp}{#1}\FV at Break@Scan}%
    {\ifthenelse{\boolean{FV at BreakAfterGroup}}%
@@ -2877,7 +3188,6 @@
       \else
         \ifx\@let at token\bgroup\relax
           \g at addto@macro{\FV at Tmp}{#1}%
-          \let\FV at TmpToken#1%
           \let\FV at Break@Next\FV at Break@AfterTokenBreak at Group
         \else
           \g at addto@macro{\FV at Tmp}{#1\FancyVerbBreakAfterBreak}%
@@ -2892,10 +3202,10 @@
   \g at addto@macro{\FV at Tmp}{{#1}}%
   \ifstrempty{#1}%
    {\let\FV at Break@Next\FV at Break@AfterTokenBreak at Group@i}%
-   {\let\FV at Break@Next\FV at Break@Scan}%
+   {\let\FV at Break@Next\FV at Break@Scan\let\FV at LastToken\minted at undefined}%
   \FV at Break@Next}
 \def\FV at Break@AfterTokenBreak at Group@i{%
-  \@ifnextchar\FV at TmpToken%
+  \@ifnextchar\FV at LastToken%
    {\FV at Break@Scan}%
    {\g at addto@macro{\FV at Tmp}{\FancyVerbBreakAfterBreak}%
     \FV at Break@Scan}}
@@ -2953,7 +3263,8 @@
       \ifthenelse{\boolean{FV at BreakAutoIndent}}%
        {\hspace*{-\wd\FV at LineIndentBox}}%
        {}%
-      \strut#1\nobreak\strut
+      \strut\FancyVerbFormatText{%
+        \FancyVerbBreakStart#1\FancyVerbBreakStop}\nobreak\strut
       \end{internallinenumbers*}
     }%
     \ifdefempty{\FancyVerbBreakSymbolRight}{}%
@@ -2976,6 +3287,10 @@
 % If a line is too wide, then it is passed to |\FV at SaveLineBox|.  If there is no right-hand break symbol, then the saved result in |\FV at LineBox| may be used immediately.  If there is a right-hand break symbol, then the line must be processed a second time, so that the right-hand break symbol may be removed from the final segment of the broken line (since it does not continue).  During the first use of |\FV at SaveLineBox|, the counter |FancyVerbLineBreakLast| is set to the internal line number of the last segment of the broken line.  During the second use of |\FV at SaveLineBox|, we disable this (|\let\FV at SetLineBreakLast\relax|) so that the value of |FancyVerbLineBreakLast| remains fixed and thus may be used to determine when a right-hand break symbol should be inserted.
 %    \begin{macrocode}
 \def\FV at ListProcessLine@Break#1{%
+  \ifx\FV at ObeyTabsInit\relax\else
+    \PackageError{minted}%
+     {the options obeytabs and breaklines are not compatible}{}%
+  \fi
   \hbox to \hsize{%
   \kern\leftmargin
   \hbox to \linewidth{%
@@ -2990,12 +3305,10 @@
   \sbox{\FV at LineBox}{\FancyVerbFormatLine{\FancyVerbFormatText{#1}}}%
   \ifdim\wd\FV at LineBox>\linewidth
     \setcounter{FancyVerbLineBreakLast}{0}%
-    \FV at SaveLineBox{\FancyVerbFormatText{%
-      \FancyVerbBreakStart#1\FancyVerbBreakStop}}%
+    \FV at SaveLineBox{#1}%
     \ifdefempty{\FancyVerbBreakSymbolRight}{}{%
       \let\FV at SetLineBreakLast\relax
-      \FV at SaveLineBox{\FancyVerbFormatText{%
-        \FancyVerbBreakStart#1\FancyVerbBreakStop}}}%
+      \FV at SaveLineBox{#1}}%
     \FV at LeftListNumber
     \FV at LeftListFrame
     \FancyVerbFormatLine{\usebox{\FV at LineBox}}%
@@ -3044,18 +3357,19 @@
 \newsavebox{\minted at bgbox}
 %    \end{macrocode}
 %
-% Now we can define the environment that captures a code fragment inside a minipage and applies a background color.
+% Now we can define the environment that applies a background color.  Prior to \pkg{minted} 2.2, this involved a |minipage|.  However, that approach was problematic because it did not allow linebreaks, would be pushed into the margin by immediately preceding text, and had very different whitespace separation from preceding and following text compared to no background color.  In version 2.2, this was replaced with an approach based on \pkg{framed}.  |\FV at NumberSep| is adjusted by |\fboxsep| to ensure that line numbers remain in the same location in the margin regardless of whether |bgcolor| is used.
 %
 %    \begin{macrocode}
-\newenvironment{minted at colorbg}[1]{
-    %\setlength{\fboxsep}{-\fboxrule}
-    \def\minted at bgcol{#1}
-    \noindent
-    \begin{lrbox}{\minted at bgbox}
-    \begin{minipage}{\linewidth-2\fboxsep}}
- {\end{minipage}
-    \end{lrbox}%
-    \colorbox{\minted at bgcol}{\usebox{\minted at bgbox}}}
+\newenvironment{minted at colorbg}[1]{%
+  \setlength{\OuterFrameSep}{0pt}%
+  \colorlet{shadecolor}{#1}%
+  \let\minted at tmp\FV at NumberSep
+  \edef\FV at NumberSep{%
+    \the\numexpr\dimexpr\minted at tmp+\number\fboxsep\relax sp\relax}%
+  \medskip
+  \begin{snugshade*}}
+ {\end{snugshade*}%
+  \medskip\noindent}
 %    \end{macrocode}
 % \end{environment}
 %
@@ -3129,6 +3443,14 @@
 % \end{macro}
 %
 %
+% \begin{macro}{minted at pygmentizecounter}
+% We need a counter to keep track of how many files have been pygmentized.  This is primarily used with |finalizecache| for naming cache files sequentially in |listing<number>.pygtex| form.
+%    \begin{macrocode}
+\newcounter{minted at pygmentizecounter}
+%    \end{macrocode}
+% \end{macro}
+%
+%
 % \begin{macro}{\minted at pygmentize}
 %
 % Pygmentize a file (default: |\minted at outputdir\minted at jobname.pyg|) using the options provided.
@@ -3143,6 +3465,7 @@
 %
 %    \begin{macrocode}
 \newcommand{\minted at pygmentize}[2][\minted at outputdir\minted at jobname.pyg]{%
+  \stepcounter{minted at pygmentizecounter}%
   \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}%
     {\def\minted at codefile{\minted at outputdir\minted at jobname.pyg}}%
     {\def\minted at codefile{#1}}%
@@ -3157,16 +3480,16 @@
     -f latex -P commandprefix=PYG -F tokenmerge
     \minted at optlistcl@g \csname minted at optlistcl@lang\minted at lang\endcsname
     \minted at optlistcl@inlines
-    \minted at optlistcl@cmd -o "\minted at outputdir\minted at infile"
+    \minted at optlistcl@cmd -o \minted at outputdir\minted at infile\space
     \ifminted at kpsewhich
       \ifwindows
-        \detokenize{$}(kpsewhich "\minted at codefile")%
+        \detokenize{$}(kpsewhich \minted at codefile)%
       \else
-        \detokenize{`}kpsewhich "\minted at codefile" 
-          \detokenize{||} "\minted at codefile"\detokenize{`}%
+        \detokenize{`}kpsewhich \minted at codefile\space 
+          \detokenize{||} \minted at codefile\detokenize{`}%
       \fi
     \else
-      "\minted at codefile"
+      \minted at codefile
     \fi}%
   % For debugging, uncomment: %%%%
   % \immediate\typeout{\minted at cmd}%
@@ -3173,71 +3496,112 @@
   % %%%%
   \ifthenelse{\boolean{minted at cache}}%
     {%
-      \ifx\XeTeXinterchartoks\minted at undefined
-        \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}%
-          {\edef\minted at hash{\pdf at filemdfivesum{#1}%
-            \pdf at mdfivesum{\minted at cmd autogobble}}}%
-          {\edef\minted at hash{\pdf at filemdfivesum{#1}%
-            \pdf at mdfivesum{\minted at cmd}}}%
+      \ifminted at frozencache
       \else
-        \immediate\openout\minted at code\minted at jobname.mintedcmd\relax
-        \immediate\write\minted at code{\minted at cmd}%
-        \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}%
-          {\immediate\write\minted at code{autogobble}}{}%
-        \immediate\closeout\minted at code
-        %Cheating a little here by using ASCII codes to write `{` and `}`
-        %in the Python code
-        \def\minted at hashcmd{%
-          \detokenize{python -c "import hashlib;
-            hasher = hashlib.sha1();
-            f = open(\"}\minted at outputdir\minted at jobname.mintedcmd\detokenize{\", \"rb\");
-            hasher.update(f.read());
-            f.close();
-            f = open(\"}#1\detokenize{\", \"rb\");
-            hasher.update(f.read());
-            f.close();
-            f = open(\"}\minted at outputdir\minted at jobname.mintedmd5\detokenize{\", \"w\");
-            macro = \"\\edef\\minted at hash\" + chr(123) + hasher.hexdigest() + chr(125) + \"\";
-            f.write(\"\\makeatletter\" + macro + \"\\makeatother\\endinput\n\");
-            f.close();"}}%
-        \immediate\write18{\minted at hashcmd}%
-        \minted at input{\minted at outputdir\minted at jobname.mintedmd5}%
+        \ifx\XeTeXinterchartoks\minted at undefined
+          \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}%
+            {\edef\minted at hash{\pdf at filemdfivesum{#1}%
+              \pdf at mdfivesum{\minted at cmd autogobble}}}%
+            {\edef\minted at hash{\pdf at filemdfivesum{#1}%
+              \pdf at mdfivesum{\minted at cmd}}}%
+        \else
+          \immediate\openout\minted at code\minted at jobname.mintedcmd\relax
+          \immediate\write\minted at code{\minted at cmd}%
+          \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}%
+            {\immediate\write\minted at code{autogobble}}{}%
+          \immediate\closeout\minted at code 
+          \edef\minted at argone@esc{#1}%
+          \StrSubstitute{\minted at argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at argone@esc]%
+          \StrSubstitute{\minted at argone@esc}{"}{\@backslashchar"}[\minted at argone@esc]%
+          \edef\minted at tmpfname@esc{\minted at outputdir\minted at jobname}%
+          \StrSubstitute{\minted at tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at tmpfname@esc]%
+          \StrSubstitute{\minted at tmpfname@esc}{"}{\@backslashchar"}[\minted at tmpfname@esc]%
+          %Cheating a little here by using ASCII codes to write `{` and `}`
+          %in the Python code
+          \def\minted at hashcmd{%
+            \detokenize{python -c "import hashlib; import os;
+              hasher = hashlib.sha1();
+              f = open(os.path.expanduser(os.path.expandvars(\"}\minted at tmpfname@esc.mintedcmd\detokenize{\")), \"rb\");
+              hasher.update(f.read());
+              f.close();
+              f = open(os.path.expanduser(os.path.expandvars(\"}\minted at argone@esc\detokenize{\")), \"rb\");
+              hasher.update(f.read());
+              f.close();
+              f = open(os.path.expanduser(os.path.expandvars(\"}\minted at tmpfname@esc.mintedmd5\detokenize{\")), \"w\");
+              macro = \"\\edef\\minted at hash\" + chr(123) + hasher.hexdigest() + chr(125) + \"\";
+              f.write(\"\\makeatletter\" + macro + \"\\makeatother\\endinput\n\");
+              f.close();"}}%
+          \ShellEscape{\minted at hashcmd}%
+          \minted at input{\minted at outputdir\minted at jobname.mintedmd5}%
+        \fi
+        \edef\minted at infile{\minted at cachedir/\minted at hash.pygtex}%
+        \IfFileExists{\minted at infile}{}{%
+          \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}{%
+            \edef\minted at argone@esc{#1}%
+            \StrSubstitute{\minted at argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at argone@esc]%
+            \StrSubstitute{\minted at argone@esc}{"}{\@backslashchar"}[\minted at argone@esc]%
+            \edef\minted at tmpfname@esc{\minted at outputdir\minted at jobname}%
+            \StrSubstitute{\minted at tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at tmpfname@esc]%
+            \StrSubstitute{\minted at tmpfname@esc}{"}{\@backslashchar"}[\minted at tmpfname@esc]%
+            %Need a version of open() that supports encoding under Python 2
+            \edef\minted at autogobblecmd{%
+              \detokenize{python -c "import sys; import os;
+              import textwrap;
+              from io import open;
+              f = open(os.path.expanduser(os.path.expandvars(\"}\minted at argone@esc\detokenize{\")), \"r\", encoding=\"}\minted at encoding\detokenize{\");
+              t = f.read();
+              f.close();
+              f = open(os.path.expanduser(os.path.expandvars(\"}\minted at tmpfname@esc.pyg\detokenize{\")), \"w\", encoding=\"}\minted at encoding\detokenize{\");
+              f.write(textwrap.dedent(t));
+              f.close();"}%
+            }%
+            \ShellEscape{\minted at autogobblecmd}}{}%
+          \ShellEscape{\minted at cmd}}%
       \fi
-      \edef\minted at infile{\minted at cachedir/\minted at hash.pygtex}%
-      \IfFileExists{\minted at infile}{}{%
-        \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}{%
-          %Need a version of open() that supports encoding under Python 2
-          \edef\minted at autogobblecmd{%
-            \detokenize{python -c "import sys;
-            import textwrap;
-            from io import open;
-            f = open(\"}#1\detokenize{\", \"r\", encoding=\"}\minted at encoding\detokenize{\");
-            t = f.read();
-            f.close();
-            f = open(\"}\minted at outputdir\minted at jobname.pyg\detokenize{\", \"w\", encoding=\"}\minted at encoding\detokenize{\");
-            f.write(textwrap.dedent(t));
-            f.close();"}%
-          }%
-          \immediate\write18{\minted at autogobblecmd}}{}%
-        \immediate\write18{\minted at cmd}}%
-      \expandafter\minted at addcachefile\expandafter{\minted at hash.pygtex}%
+      \ifthenelse{\boolean{minted at finalizecache}}%
+       {%
+          \edef\minted at cachefilename{listing\arabic{minted at pygmentizecounter}.pygtex}%
+          \edef\minted at actualinfile{\minted at cachedir/\minted at cachefilename}%
+          \ifwindows
+            \StrSubstitute{\minted at infile}{/}{\@backslashchar}[\minted at infile@windows]
+            \StrSubstitute{\minted at actualinfile}{/}{\@backslashchar}[\minted at actualinfile@windows]
+            \ShellEscape{move /y \minted at infile@windows\space\minted at actualinfile@windows}%
+          \else
+            \ShellEscape{mv -f \minted at infile\space\minted at actualinfile}%
+          \fi
+          \let\minted at infile\minted at actualinfile
+          \expandafter\minted at addcachefile\expandafter{\minted at cachefilename}%
+       }%
+       {\ifthenelse{\boolean{minted at frozencache}}%
+         {%
+            \edef\minted at cachefilename{listing\arabic{minted at pygmentizecounter}.pygtex}%
+            \edef\minted at infile{\minted at cachedir/\minted at cachefilename}%
+            \expandafter\minted at addcachefile\expandafter{\minted at cachefilename}}%
+         {\expandafter\minted at addcachefile\expandafter{\minted at hash.pygtex}}%
+       }%
       \minted at inputpyg}%
     {%
       \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}{%
+        \edef\minted at argone@esc{#1}%
+        \StrSubstitute{\minted at argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at argone@esc]%
+        \StrSubstitute{\minted at argone@esc}{"}{\@backslashchar"}[\minted at argone@esc]%
+        \edef\minted at tmpfname@esc{\minted at outputdir\minted at jobname}%
+        \StrSubstitute{\minted at tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at tmpfname@esc]%
+        \StrSubstitute{\minted at tmpfname@esc}{"}{\@backslashchar"}[\minted at tmpfname@esc]%
         %Need a version of open() that supports encoding under Python 2
         \edef\minted at autogobblecmd{%
-          \detokenize{python -c "import sys;
+          \detokenize{python -c "import sys; import os;
           import textwrap;
           from io import open;
-          f = open(\"}#1\detokenize{\", \"r\", encoding=\"}\minted at encoding\detokenize{\");
+          f = open(os.path.expanduser(os.path.expandvars(\"}\minted at argone@esc\detokenize{\")), \"r\", encoding=\"}\minted at encoding\detokenize{\");
           t = f.read();
           f.close();
-          f = open(\"}\minted at outputdir\minted at jobname.pyg\detokenize{\", \"w\", encoding=\"}\minted at encoding\detokenize{\");
+          f = open(os.path.expanduser(os.path.expandvars(\"}\minted at tmpfname@esc.pyg\detokenize{\")), \"w\", encoding=\"}\minted at encoding\detokenize{\");
           f.write(textwrap.dedent(t));
           f.close();"}%
         }%
-        \immediate\write18{\minted at autogobblecmd}}{}%
-      \immediate\write18{\minted at cmd}%
+        \ShellEscape{\minted at autogobblecmd}}{}%
+      \ShellEscape{\minted at cmd}%
       \minted at inputpyg}%
 }
 %    \end{macrocode}
@@ -3249,6 +3613,62 @@
 % 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 at SpaceMMode{ }
+\def\minted at BreakBeforePrep@extension{%
+  \ifcsname FV at BreakBefore@Token\@backslashchar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZbs}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at underscorechar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZus}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@charlb\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZob}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@charrb\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZcb}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{^}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZca}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at ampchar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZam}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{<}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZlt}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{>}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZgt}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at hashchar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZsh}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@percentchar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZpc}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at dollarchar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZdl}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{-}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZhy}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{'}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZsq}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{"}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZdq}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at tildechar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZti}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{@}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZat}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{[}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZlb}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{]}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZrb}}{}%
+  \fi
+}
 \def\minted at BreakAfterPrep@extension{%
   \ifcsname FV at BreakAfter@Token\@backslashchar\endcsname
     \@namedef{FV at BreakAfter@Token\detokenize{\PYGZbs}}{}%
@@ -3306,6 +3726,9 @@
   \fi
 }
 \newcommand{\minted at inputpyg}{%
+  \let\FV at BreakBeforePrep@orig\FV at BreakBeforePrep
+  \def\FV at BreakBeforePrep{%
+    \FV at BreakBeforePrep@orig\minted at BreakBeforePrep@extension}%
   \let\FV at BreakAfterPrep@orig\FV at BreakAfterPrep
   \def\FV at BreakAfterPrep{%
     \FV at BreakAfterPrep@orig\minted at BreakAfterPrep@extension}%
@@ -3318,12 +3741,20 @@
      \expandafter\def\csname PYG\minted at get@opt{style}{default}\endcsname##1##2{%
        \minted at orig@PYG at breakanywhere{##1}%
          {\FancyVerbBreakStart##2\FancyVerbBreakStop}}}{}%
-  \ifx\FV at BreakAfter\@empty
+  \ifx\FV at BreakBefore\@empty
+    \ifx\FV at BreakAfter\@empty
+    \else
+      \expandafter\let\expandafter\minted at orig@PYG at breakbeforeafter%
+        \csname PYG\minted at get@opt{style}{default}\endcsname
+      \expandafter\def\csname PYG\minted at get@opt{style}{default}\endcsname##1##2{%
+        \minted at orig@PYG at breakbeforeafter{##1}%
+         {\FancyVerbBreakStart##2\FancyVerbBreakStop}}%
+    \fi
   \else
-    \expandafter\let\expandafter\minted at orig@PYG at breakafter%
+    \expandafter\let\expandafter\minted at orig@PYG at breakbeforeafter%
       \csname PYG\minted at get@opt{style}{default}\endcsname
     \expandafter\def\csname PYG\minted at get@opt{style}{default}\endcsname##1##2{%
-      \minted at orig@PYG at breakafter{##1}%
+      \minted at orig@PYG at breakbeforeafter{##1}%
        {\FancyVerbBreakStart##2\FancyVerbBreakStop}}%
   \fi
   \ifthenelse{\boolean{minted at isinline}}%
@@ -3826,27 +4257,32 @@
 %
 %    \begin{macrocode}
 \AtEndOfPackage{%
-  \ifthenelse{\boolean{minted at draft}}{}{%
-    \ifnum\pdf at shellescape=1\relax\else
-      \PackageError{minted}%
-       {You must invoke LaTeX with the
-        -shell-escape flag}%
-       {Pass the -shell-escape flag to LaTeX. Refer to the minted.sty
-        documentation for more information.}%
-    \fi
-    \setminted{style=default}%
-  }%
+  \ifthenelse{\boolean{minted at draft}}%
+   {}%
+   {%
+    \ifthenelse{\boolean{minted at frozencache}}{}{%
+      \ifnum\pdf at shellescape=1\relax\else
+        \PackageError{minted}%
+         {You must invoke LaTeX with the
+          -shell-escape flag}%
+         {Pass the -shell-escape flag to LaTeX. Refer to the minted.sty
+          documentation for more information.}%
+      \fi}%
+   }%
 }
 \AtEndPreamble{%
-  \ifthenelse{\boolean{minted at draft}}{}{%
-    \TestAppExists{pygmentize}%
-    \ifAppExists\else
-      \PackageError{minted}%
-       {You must have `pygmentize' installed
-        to use this package}%
-       {Refer to the installation instructions in the minted
-        documentation for more information.}%
-    \fi
+  \ifthenelse{\boolean{minted at draft}}%
+   {}%
+   {%
+    \ifthenelse{\boolean{minted at frozencache}}{}{%
+      \TestAppExists{\MintedPygmentize}%
+      \ifAppExists\else
+        \PackageError{minted}%
+         {You must have `pygmentize' installed
+          to use this package}%
+         {Refer to the installation instructions in the minted
+          documentation for more information.}%
+      \fi}%
   }%
 }
 %    \end{macrocode}
@@ -3857,14 +4293,20 @@
 %
 % Clean up temp files.  What actually needs to be done depends on caching and engine.
 %    \begin{macrocode}
-\AtEndDocument{
-  \ifx\XeTeXinterchartoks\minted at undefined
-  \else
-    \DeleteFile[\minted at outputdir]{\minted at jobname.mintedcmd}%
-    \DeleteFile[\minted at outputdir]{\minted at jobname.mintedmd5}%
-  \fi
-  \DeleteFile[\minted at outputdir]{\minted at jobname.pyg}%
-  \DeleteFile[\minted at outputdir]{\minted at jobname.out.pyg}%
+\AfterEndDocument{%
+  \ifthenelse{\boolean{minted at draft}}%
+   {}%
+   {\ifthenelse{\boolean{minted at frozencache}}%
+     {}
+     {\ifx\XeTeXinterchartoks\minted at undefined
+      \else
+        \DeleteFile[\minted at outputdir]{\minted at jobname.mintedcmd}%
+        \DeleteFile[\minted at outputdir]{\minted at jobname.mintedmd5}%
+      \fi
+      \DeleteFile[\minted at outputdir]{\minted at jobname.pyg}%
+      \DeleteFile[\minted at outputdir]{\minted at jobname.out.pyg}%
+     }%
+   }%
 }
 %    \end{macrocode}
 %

Modified: trunk/Master/texmf-dist/source/latex/minted/minted.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/minted/minted.ins	2016-06-09 22:52:34 UTC (rev 41328)
+++ trunk/Master/texmf-dist/source/latex/minted/minted.ins	2016-06-09 22:52:48 UTC (rev 41329)
@@ -3,7 +3,7 @@
 \askforoverwritefalse
 
 \preamble
-Copyright 2013--2015 Geoffrey M. Poore
+Copyright 2013--2016 Geoffrey M. Poore
 Copyright 2010--2011 Konrad Rudolph
 
 This work may be distributed and/or modified under the

Modified: trunk/Master/texmf-dist/tex/latex/minted/minted.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/minted/minted.sty	2016-06-09 22:52:34 UTC (rev 41328)
+++ trunk/Master/texmf-dist/tex/latex/minted/minted.sty	2016-06-09 22:52:48 UTC (rev 41329)
@@ -5,7 +5,7 @@
 %% The original source files were:
 %%
 %% minted.dtx  (with options: `package')
-%% Copyright 2013--2015 Geoffrey M. Poore
+%% Copyright 2013--2016 Geoffrey M. Poore
 %% Copyright 2010--2011 Konrad Rudolph
 %% 
 %% This work may be distributed and/or modified under the
@@ -27,7 +27,7 @@
 %% and the derived file minted.sty.
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{minted}
-    [2015/09/09 v2.1 Yet another Pygments shim for LaTeX]
+    [2016/06/08 v2.2 Yet another Pygments shim for LaTeX]
 \RequirePackage{keyval}
 \RequirePackage{kvoptions}
 \RequirePackage{fancyvrb}
@@ -39,6 +39,13 @@
 \RequirePackage{etoolbox}
 \RequirePackage{xstring}
 \RequirePackage{lineno}
+\RequirePackage{framed}
+\IfFileExists{shellesc.sty}
+ {\RequirePackage{shellesc}
+  \@ifpackagelater{shellesc}{2016/04/29}
+   {}
+   {\protected\def\ShellEscape{\immediate\write18 }}}
+ {\protected\def\ShellEscape{\immediate\write18 }}
 \AtBeginDocument{%
   \@ifpackageloaded{color}{}{%
     \@ifpackageloaded{xcolor}{}{\RequirePackage{xcolor}}}%
@@ -55,6 +62,8 @@
 \define at key{minted}{cachedir}{%
   \@namedef{minted at cachedir}{#1}%
   \StrSubstitute{\minted at cachedir}{/}{\@backslashchar}[\minted at cachedir@windows]}
+\DeclareBoolOption{finalizecache}
+\DeclareBoolOption{frozencache}
 \let\minted at outputdir\@empty
 \let\minted at outputdir@windows\@empty
 \define at key{minted}{outputdir}{%
@@ -67,13 +76,27 @@
 \DeclareComplementaryOption{final}{draft}
 \ProcessKeyvalOptions*
 \ifthenelse{\boolean{minted at newfloat}}{\RequirePackage{newfloat}}{}
-\ifcsname tikzexternalrealjob\endcsname
-  \minted at drafttrue
-  \minted at cachefalse
+\ifcsname tikzifexternalizing\endcsname
+  \tikzifexternalizing{\minted at drafttrue\minted at cachefalse}{}
 \else
+  \ifcsname tikzexternalrealjob\endcsname
+    \minted at drafttrue
+    \minted at cachefalse
+  \else
+  \fi
 \fi
-\ifthenelse{\boolean{minted at cache}}{%
-  \AtEndOfPackage{\ProvideDirectory{\minted at outputdir\minted at cachedir}}}{}
+\ifthenelse{\boolean{minted at finalizecache}}%
+ {\ifthenelse{\boolean{minted at frozencache}}%
+   {\PackageError{minted}%
+     {Options "finalizecache" and "frozencache" are not compatible}%
+     {Options "finalizecache" and "frozencache" are not compatible}}%
+   {}}%
+ {}
+\ifthenelse{\boolean{minted at cache}}%
+ {\ifthenelse{\boolean{minted at frozencache}}%
+   {}%
+   {\AtEndOfPackage{\ProvideDirectory{\minted at outputdir\minted at cachedir}}}}%
+ {}
 \newcommand{\minted at input}[1]{%
   \IfFileExists{#1}%
    {\input{#1}}%
@@ -81,11 +104,12 @@
      was^^Jprobably given a file that does not exist--otherwise, you may need
      ^^Jthe outputdir package option, or may be using an incompatible build
      tool\ifwindows,^^Jor may be using the kpsewhich option without having
-     PowerShell installed\fi}%
+     PowerShell installed\fi,^^Jor may be using frozencache with a missing file}%
     {This could be caused by using -output-directory or -aux-directory
      ^^Jwithout setting minted's outputdir, or by using a build tool that
      ^^Jchanges paths in ways minted cannot detect\ifwindows, or by using the
-     ^^Jkpsewhich option without PowerShell\fi.}}%
+     ^^Jkpsewhich option without PowerShell\fi,
+     ^^Jor using frozencache with a missing file.}}%
 }
 \newcommand{\minted at infile}{\minted at jobname.out.pyg}
 \newcommand{\minted at cachelist}{}
@@ -116,34 +140,40 @@
   \fi
 }
 \ifthenelse{\boolean{minted at draft}}%
-  {\AtEndDocument{%
+ {\AtEndDocument{%
+    \ifcsname minted at oldcachelist\endcsname
+      \StrSubstitute{\minted at oldcachelist}{,}{,^^J }[\minted at cachelist]
+      \minted at savecachelist
+    \fi}}%
+ {\ifthenelse{\boolean{minted at frozencache}}%
+   {\AtEndDocument{%
       \ifcsname minted at oldcachelist\endcsname
-        \let\minted at cachelist\minted at oldcachelist
+        \StrSubstitute{\minted at oldcachelist}{,}{,^^J }[\minted at cachelist]
         \minted at savecachelist
       \fi}}%
-  {\AtEndDocument{%
-      \minted at savecachelist
-      \minted at cleancache}}%
+   {\AtEndDocument{%
+    \minted at savecachelist
+    \minted at cleancache}}}%
 \ifwindows
   \providecommand{\DeleteFile}[2][]{%
     \ifthenelse{\equal{#1}{}}%
-      {\IfFileExists{#2}{\immediate\write18{del "#2"}}{}}%
+      {\IfFileExists{#2}{\ShellEscape{del #2}}{}}%
       {\IfFileExists{#1/#2}{%
         \StrSubstitute{#1}{/}{\@backslashchar}[\minted at windir]
-        \immediate\write18{del "\minted at windir\@backslashchar #2"}}{}}}
+        \ShellEscape{del \minted at windir\@backslashchar #2}}{}}}
 \else
   \providecommand{\DeleteFile}[2][]{%
     \ifthenelse{\equal{#1}{}}%
-      {\IfFileExists{#2}{\immediate\write18{rm "#2"}}{}}%
-      {\IfFileExists{#1/#2}{\immediate\write18{rm "#1/#2"}}{}}}
+      {\IfFileExists{#2}{\ShellEscape{rm #2}}{}}%
+      {\IfFileExists{#1/#2}{\ShellEscape{rm #1/#2}}{}}}
 \fi
 \ifwindows
   \newcommand{\ProvideDirectory}[1]{%
     \StrSubstitute{#1}{/}{\@backslashchar}[\minted at windir]
-    \immediate\write18{if not exist "\minted at windir" mkdir "\minted at windir"}}
+    \ShellEscape{if not exist \minted at windir\space mkdir \minted at windir}}
 \else
   \newcommand{\ProvideDirectory}[1]{%
-    \immediate\write18{mkdir -p "#1"}}
+    \ShellEscape{mkdir -p #1}}
 \fi
 \newboolean{AppExists}
 \newread\minted at appexistsfile
@@ -150,9 +180,9 @@
 \newcommand{\TestAppExists}[1]{
   \ifwindows
     \DeleteFile{\minted at jobname.aex}
-    \immediate\write18{for \string^\@percentchar i in (#1.exe #1.bat #1.cmd)
-      do set >"\minted at jobname.aex" <nul: /p
-      x=\string^\@percentchar \string~$PATH:i>>"\minted at jobname.aex"}
+    \ShellEscape{for \string^\@percentchar i in (#1.exe #1.bat #1.cmd)
+      do set > \minted at jobname.aex <nul: /p
+      x=\string^\@percentchar \string~$PATH:i>> \minted at jobname.aex}
     %$ <- balance syntax highlighting
     \immediate\openin\minted at appexistsfile\minted at jobname.aex
     \expandafter\def\expandafter\@tmp at cr\expandafter{\the\endlinechar}
@@ -165,7 +195,7 @@
     \immediate\closein\minted at appexistsfile
     \DeleteFile{\minted at jobname.aex}
   \else
-    \immediate\write18{which "#1" && touch "\minted at jobname.aex"}
+    \ShellEscape{which #1 && touch \minted at jobname.aex}
     \IfFileExists{\minted at jobname.aex}
       {\AppExiststrue
         \DeleteFile{\minted at jobname.aex}}
@@ -473,42 +503,51 @@
     \expandafter\gdef%
       \csname minted at styleloaded@\ifstrempty{#1}{default-pyg-prefix}{#1}\endcsname{}%
     \ifthenelse{\boolean{minted at cache}}%
-      {\IfFileExists
+     {\IfFileExists
        {\minted at outputdir\minted at 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 at outputdir@windows\minted at 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 at outputdir\minted at cachedir/%
-                 \ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle"}%
-        \fi
+        \ifthenelse{\boolean{minted at frozencache}}%
+         {\PackageError{minted}%
+           {Missing style definition for #1 with frozencache}%
+           {Missing style definition for #1 with frozencache}}%
+         {\ifwindows
+            \ShellEscape{%
+              \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
+              -P commandprefix=PYG#1
+              > \minted at outputdir@windows\minted at cachedir@windows\@backslashchar%
+                   \ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}%
+          \else
+            \ShellEscape{%
+              \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
+              -P commandprefix=PYG#1
+              > \minted at outputdir\minted at cachedir/%
+                   \ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}%
+          \fi}%
         }%
         \begingroup
         \let\def\gdef
+        \catcode`\_=11
+        \catcode`\-=11
         \endlinechar=-1\relax
         \minted at input{%
           \minted at outputdir\minted at cachedir/\ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}%
         \endgroup
         \minted at addcachefile{\ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}}%
-      {\ifwindows
-          \immediate\write18{%
+     {%
+        \ifwindows
+          \ShellEscape{%
             \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
-            -P commandprefix=PYG#1 > "\minted at outputdir@windows\minted at jobname.out.pyg"}%
+            -P commandprefix=PYG#1 > \minted at outputdir@windows\minted at jobname.out.pyg}%
         \else
-          \immediate\write18{%
+          \ShellEscape{%
             \MintedPygmentize\space -S \ifstrempty{#1}{default}{#1} -f latex
-            -P commandprefix=PYG#1 > "\minted at outputdir\minted at jobname.out.pyg"}%
+            -P commandprefix=PYG#1 > \minted at outputdir\minted at jobname.out.pyg}%
         \fi
         \begingroup
         \let\def\gdef
+        \catcode`\_=11
+        \catcode`\-=11
         \endlinechar=-1\relax
         \minted at input{\minted at outputdir\minted at jobname.out.pyg}%
         \endgroup}%
@@ -515,7 +554,7 @@
   \fi
 }
 \ifthenelse{\boolean{minted at draft}}{\renewcommand{\minted at checkstyle}[1]{}}{}
-\AtBeginDocument{\minted at checkstyle{}}
+\AtBeginDocument{\minted at checkstyle{}\setminted{style=default}}
 \newcommand{\minted at patch@PYGZsq}{%
   \ifcsname PYGZsq\endcsname
     \ifx\upquote at cmtt\minted at undefined\else
@@ -627,6 +666,7 @@
 \minted at def@optfv{fontseries}
 \minted at def@optfv{formatcom}
 \minted at def@optfv{label}
+\minted at def@optfv{labelposition}
 \minted at def@optfv at switch{numberblanklines}
 \minted at def@optfv at switch{showspaces}
 \minted at def@optfv at switch{resetmargins}
@@ -645,6 +685,10 @@
 \minted at def@optfv{breaksymbolright}
 \minted at def@optfv{breaksymbolsepright}
 \minted at def@optfv{breaksymbolindentright}
+\minted at def@optfv{breakbefore}
+\minted at def@optfv{breakbeforesymbolpre}
+\minted at def@optfv{breakbeforesymbolpost}
+\minted at def@optfv at switch{breakbeforegroup}
 \minted at def@optfv{breakafter}
 \minted at def@optfv at switch{breakaftergroup}
 \minted at def@optfv{breakaftersymbolpre}
@@ -731,6 +775,44 @@
   \let\[\FV at leftsquarebracket
   \let\]\FV at rightsquarebracket
 } %$ <- highlighting
+\define at key{FV}{breakbefore}{%
+  \ifstrempty{#1}%
+   {\let\FV at BreakBefore\@empty
+    \let\FancyVerbBreakStart\relax
+    \let\FancyVerbBreakStop\relax}%
+   {\def\FV at BreakBefore{#1}%
+    \let\FancyVerbBreakStart\FV at Break
+    \let\FancyVerbBreakStop\FV at EndBreak
+    \let\FV at Break@Token\FV at Break@BeforeAfterToken}%
+}
+\fvset{breakbefore={}}
+\newboolean{FV at BreakBeforeGroup}
+\define at booleankey{FV}{breakbeforegroup}%
+ {\FV at BreakBeforeGrouptrue}%
+ {\FV at BreakBeforeGroupfalse}%
+\fvset{breakbeforegroup=true}
+\def\FV at BreakBeforePrep{%
+  \ifx\FV at BreakBefore\@empty\relax
+  \else
+    \gdef\FV at BreakBefore@Def{}%
+    \begingroup
+    \def\FV at BreakBefore@Process##1##2\FV at Undefined{%
+      \expandafter\FV at BreakBefore@Process at i\expandafter{##1}%
+      \expandafter\ifx\expandafter\relax\detokenize{##2}\relax
+      \else
+        \FV at BreakBefore@Process##2\FV at Undefined
+      \fi
+    }%
+    \def\FV at BreakBefore@Process at i##1{%
+      \g at addto@macro\FV at BreakBefore@Def{%
+        \@namedef{FV at BreakBefore@Token\detokenize{##1}}{}}%
+    }%
+    \FV at EscChars
+    \expandafter\FV at BreakBefore@Process\FV at BreakBefore\FV at Undefined
+    \endgroup
+    \FV at BreakBefore@Def
+  \fi
+}
 \define at key{FV}{breakafter}{%
   \ifstrempty{#1}%
    {\let\FV at BreakAfter\@empty
@@ -739,7 +821,7 @@
    {\def\FV at BreakAfter{#1}%
     \let\FancyVerbBreakStart\FV at Break
     \let\FancyVerbBreakStop\FV at EndBreak
-    \let\FV at Break@Token\FV at Break@AfterToken}%
+    \let\FV at Break@Token\FV at Break@BeforeAfterToken}%
 }
 \fvset{breakafter={}}
 \newboolean{FV at BreakAfterGroup}
@@ -760,6 +842,20 @@
       \fi
     }%
     \def\FV at BreakAfter@Process at i##1{%
+      \ifcsname FV at BreakBefore@Token\detokenize{##1}\endcsname
+        \ifthenelse{\boolean{FV at BreakBeforeGroup}}%
+         {\ifthenelse{\boolean{FV at BreakAfterGroup}}%
+           {}%
+           {\PackageError{minted}%
+            {Conflicting breakbeforegroup and breakaftergroup for "\detokenize{##1}"}%
+            {Conflicting breakbeforegroup and breakaftergroup for "\detokenize{##1}"}}}%
+         {\ifthenelse{\boolean{FV at BreakAfterGroup}}%
+           {\PackageError{minted}%
+             {Conflicting breakbeforegroup and breakaftergroup for "\detokenize{##1}"}%
+             {Conflicting breakbeforegroup and breakaftergroup for "\detokenize{##1}"}}%
+           {}}%
+      \else
+      \fi
       \g at addto@macro\FV at BreakAfter@Def{%
         \@namedef{FV at BreakAfter@Token\detokenize{##1}}{}}%
     }%
@@ -770,7 +866,7 @@
   \fi
 }
 \expandafter\def\expandafter\FV at FormattingPrep\expandafter{%
-  \expandafter\FV at BreakAfterPrep\FV at FormattingPrep}
+  \expandafter\FV at BreakBeforePrep\expandafter\FV at BreakAfterPrep\FV at FormattingPrep}
 \define at key{FV}{breakanywheresymbolpre}{%
   \ifstrempty{#1}%
     {\def\FancyVerbBreakAnywhereSymbolPre{}}%
@@ -781,6 +877,16 @@
     {\def\FancyVerbBreakAnywhereSymbolPost{}}%
     {\def\FancyVerbBreakAnywhereSymbolPost{\hbox{#1}}}}
 \fvset{breakanywheresymbolpost={}}
+\define at key{FV}{breakbeforesymbolpre}{%
+  \ifstrempty{#1}%
+    {\def\FancyVerbBreakBeforeSymbolPre{}}%
+    {\def\FancyVerbBreakBeforeSymbolPre{\hbox{#1}}}}
+\fvset{breakbeforesymbolpre={\,\footnotesize\ensuremath{_\rfloor}}}
+\define at key{FV}{breakbeforesymbolpost}{%
+  \ifstrempty{#1}%
+    {\def\FancyVerbBreakBeforeSymbolPost{}}%
+    {\def\FancyVerbBreakBeforeSymbolPost{\hbox{#1}}}}
+\fvset{breakbeforesymbolpost={}}
 \define at key{FV}{breakaftersymbolpre}{%
   \ifstrempty{#1}%
     {\def\FancyVerbBreakAfterSymbolPre{}}%
@@ -794,6 +900,9 @@
 \newcommand{\FancyVerbBreakAnywhereBreak}{%
   \discretionary{\FancyVerbBreakAnywhereSymbolPre}%
    {\FancyVerbBreakAnywhereSymbolPost}{}}
+\newcommand{\FancyVerbBreakBeforeBreak}{%
+  \discretionary{\FancyVerbBreakBeforeSymbolPre}%
+   {\FancyVerbBreakBeforeSymbolPost}{}}
 \newcommand{\FancyVerbBreakAfterBreak}{%
   \discretionary{\FancyVerbBreakAfterSymbolPre}%
    {\FancyVerbBreakAfterSymbolPost}{}}
@@ -823,6 +932,7 @@
 }
 \def\FV at Break{%
   \def\FV at Tmp{}%
+  \let\FV at LastToken\minted at undefined
   \FV at Break@Scan
 }
 \def\FV at EndBreak{\FV at Tmp}
@@ -847,26 +957,68 @@
 \catcode`\$=3%
 \gdef\FV at Break@Math$#1${%
   \g at addto@macro{\FV at Tmp}{$#1$}%
+  \let\FV at LastToken\minted at undefined
   \FV at Break@Scan}
 \endgroup
 \def\FV at Break@Group#1{%
   \g at addto@macro{\FV at Tmp}{{#1}}%
+  \ifstrempty{#1}{}{\let\FV at LastToken\minted at undefined}%
   \FV at Break@Scan}
 \def\FV at Break@AnyToken#1{%
   \g at addto@macro{\FV at Tmp}{\FancyVerbBreakAnywhereBreak#1}%
   \FV at Break@Scan}
-\def\FV at Break@AfterToken#1{%
-  \ifcsname FV at BreakAfter@Token\detokenize{#1}\endcsname
-    \let\FV at Break@Next\FV at Break@AfterTokenBreak
+\def\FV at Break@BeforeAfterToken#1{%
+  \ifcsname FV at BreakBefore@Token\detokenize{#1}\endcsname
+    \let\FV at Break@Next\FV at Break@BeforeTokenBreak
   \else
-    \let\FV at Break@Next\FV at Break@AfterTokenNoBreak
+    \ifcsname FV at BreakAfter@Token\detokenize{#1}\endcsname
+      \let\FV at Break@Next\FV at Break@AfterTokenBreak
+    \else
+      \let\FV at Break@Next\FV at Break@BeforeAfterTokenNoBreak
+    \fi
   \fi
   \FV at Break@Next{#1}%
 }
-\def\FV at Break@AfterTokenNoBreak#1{%
+\def\FV at Break@BeforeAfterTokenNoBreak#1{%
   \g at addto@macro{\FV at Tmp}{#1}%
+  \let\FV at LastToken#1%
   \FV at Break@Scan}
+\def\FV at Break@BeforeTokenBreak#1{%
+  \ifthenelse{\boolean{FV at BreakBeforeGroup}}%
+   {\ifx#1\FV at LastToken\relax
+      \ifcsname FV at BreakAfter@Token\detokenize{#1}\endcsname
+        \let\FV at Break@Next\FV at Break@BeforeTokenBreak at AfterRescan
+        \def\FV at RescanToken{#1}%
+      \else
+        \g at addto@macro{\FV at Tmp}{#1}%
+        \let\FV at Break@Next\FV at Break@Scan
+        \let\FV at LastToken#1%
+      \fi
+    \else
+      \ifcsname FV at BreakAfter@Token\detokenize{#1}\endcsname
+        \g at addto@macro{\FV at Tmp}{\FancyVerbBreakBeforeBreak}%
+        \let\FV at Break@Next\FV at Break@BeforeTokenBreak at AfterRescan
+        \def\FV at RescanToken{#1}%
+      \else
+        \g at addto@macro{\FV at Tmp}{\FancyVerbBreakBeforeBreak#1}%
+        \let\FV at Break@Next\FV at Break@Scan
+        \let\FV at LastToken#1%
+      \fi
+    \fi}%
+   {\ifcsname FV at BreakAfter@Token\detokenize{#1}\endcsname
+      \g at addto@macro{\FV at Tmp}{\FancyVerbBreakBeforeBreak}%
+      \let\FV at Break@Next\FV at Break@BeforeTokenBreak at AfterRescan
+      \def\FV at RescanToken{#1}%
+    \else
+      \g at addto@macro{\FV at Tmp}{\FancyVerbBreakBeforeBreak#1}%
+      \let\FV at Break@Next\FV at Break@Scan
+      \let\FV at LastToken#1%
+    \fi}%
+  \FV at Break@Next}
+\def\FV at Break@BeforeTokenBreak at AfterRescan{%
+  \expandafter\FV at Break@AfterTokenBreak\FV at RescanToken}
 \def\FV at Break@AfterTokenBreak#1{%
+  \let\FV at LastToken#1%
   \@ifnextchar\FV at Space%
    {\g at addto@macro{\FV at Tmp}{#1}\FV at Break@Scan}%
    {\ifthenelse{\boolean{FV at BreakAfterGroup}}%
@@ -876,7 +1028,6 @@
       \else
         \ifx\@let at token\bgroup\relax
           \g at addto@macro{\FV at Tmp}{#1}%
-          \let\FV at TmpToken#1%
           \let\FV at Break@Next\FV at Break@AfterTokenBreak at Group
         \else
           \g at addto@macro{\FV at Tmp}{#1\FancyVerbBreakAfterBreak}%
@@ -891,10 +1042,10 @@
   \g at addto@macro{\FV at Tmp}{{#1}}%
   \ifstrempty{#1}%
    {\let\FV at Break@Next\FV at Break@AfterTokenBreak at Group@i}%
-   {\let\FV at Break@Next\FV at Break@Scan}%
+   {\let\FV at Break@Next\FV at Break@Scan\let\FV at LastToken\minted at undefined}%
   \FV at Break@Next}
 \def\FV at Break@AfterTokenBreak at Group@i{%
-  \@ifnextchar\FV at TmpToken%
+  \@ifnextchar\FV at LastToken%
    {\FV at Break@Scan}%
    {\g at addto@macro{\FV at Tmp}{\FancyVerbBreakAfterBreak}%
     \FV at Break@Scan}}
@@ -935,7 +1086,8 @@
       \ifthenelse{\boolean{FV at BreakAutoIndent}}%
        {\hspace*{-\wd\FV at LineIndentBox}}%
        {}%
-      \strut#1\nobreak\strut
+      \strut\FancyVerbFormatText{%
+        \FancyVerbBreakStart#1\FancyVerbBreakStop}\nobreak\strut
       \end{internallinenumbers*}
     }%
     \ifdefempty{\FancyVerbBreakSymbolRight}{}%
@@ -944,6 +1096,10 @@
 }
 \def\FancyVerbFormatText#1{#1}
 \def\FV at ListProcessLine@Break#1{%
+  \ifx\FV at ObeyTabsInit\relax\else
+    \PackageError{minted}%
+     {the options obeytabs and breaklines are not compatible}{}%
+  \fi
   \hbox to \hsize{%
   \kern\leftmargin
   \hbox to \linewidth{%
@@ -958,12 +1114,10 @@
   \sbox{\FV at LineBox}{\FancyVerbFormatLine{\FancyVerbFormatText{#1}}}%
   \ifdim\wd\FV at LineBox>\linewidth
     \setcounter{FancyVerbLineBreakLast}{0}%
-    \FV at SaveLineBox{\FancyVerbFormatText{%
-      \FancyVerbBreakStart#1\FancyVerbBreakStop}}%
+    \FV at SaveLineBox{#1}%
     \ifdefempty{\FancyVerbBreakSymbolRight}{}{%
       \let\FV at SetLineBreakLast\relax
-      \FV at SaveLineBox{\FancyVerbFormatText{%
-        \FancyVerbBreakStart#1\FancyVerbBreakStop}}}%
+      \FV at SaveLineBox{#1}}%
     \FV at LeftListNumber
     \FV at LeftListFrame
     \FancyVerbFormatLine{\usebox{\FV at LineBox}}%
@@ -984,15 +1138,16 @@
 \fi
 \fi
 \newsavebox{\minted at bgbox}
-\newenvironment{minted at colorbg}[1]{
-    %\setlength{\fboxsep}{-\fboxrule}
-    \def\minted at bgcol{#1}
-    \noindent
-    \begin{lrbox}{\minted at bgbox}
-    \begin{minipage}{\linewidth-2\fboxsep}}
- {\end{minipage}
-    \end{lrbox}%
-    \colorbox{\minted at bgcol}{\usebox{\minted at bgbox}}}
+\newenvironment{minted at colorbg}[1]{%
+  \setlength{\OuterFrameSep}{0pt}%
+  \colorlet{shadecolor}{#1}%
+  \let\minted at tmp\FV at NumberSep
+  \edef\FV at NumberSep{%
+    \the\numexpr\dimexpr\minted at tmp+\number\fboxsep\relax sp\relax}%
+  \medskip
+  \begin{snugshade*}}
+ {\end{snugshade*}%
+  \medskip\noindent}
 \newwrite\minted at code
 \newcommand{\minted at savecode}[1]{
   \immediate\openout\minted at code\minted at jobname.pyg\relax
@@ -1020,7 +1175,9 @@
 \ifcsname MintedPygmentize\endcsname\else
   \newcommand{\MintedPygmentize}{pygmentize}
 \fi
+\newcounter{minted at pygmentizecounter}
 \newcommand{\minted at pygmentize}[2][\minted at outputdir\minted at jobname.pyg]{%
+  \stepcounter{minted at pygmentizecounter}%
   \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}%
     {\def\minted at codefile{\minted at outputdir\minted at jobname.pyg}}%
     {\def\minted at codefile{#1}}%
@@ -1035,16 +1192,16 @@
     -f latex -P commandprefix=PYG -F tokenmerge
     \minted at optlistcl@g \csname minted at optlistcl@lang\minted at lang\endcsname
     \minted at optlistcl@inlines
-    \minted at optlistcl@cmd -o "\minted at outputdir\minted at infile"
+    \minted at optlistcl@cmd -o \minted at outputdir\minted at infile\space
     \ifminted at kpsewhich
       \ifwindows
-        \detokenize{$}(kpsewhich "\minted at codefile")%
+        \detokenize{$}(kpsewhich \minted at codefile)%
       \else
-        \detokenize{`}kpsewhich "\minted at codefile"
-          \detokenize{||} "\minted at codefile"\detokenize{`}%
+        \detokenize{`}kpsewhich \minted at codefile\space
+          \detokenize{||} \minted at codefile\detokenize{`}%
       \fi
     \else
-      "\minted at codefile"
+      \minted at codefile
     \fi}%
   % For debugging, uncomment: %%%%
   % \immediate\typeout{\minted at cmd}%
@@ -1051,74 +1208,171 @@
   % %%%%
   \ifthenelse{\boolean{minted at cache}}%
     {%
-      \ifx\XeTeXinterchartoks\minted at undefined
-        \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}%
-          {\edef\minted at hash{\pdf at filemdfivesum{#1}%
-            \pdf at mdfivesum{\minted at cmd autogobble}}}%
-          {\edef\minted at hash{\pdf at filemdfivesum{#1}%
-            \pdf at mdfivesum{\minted at cmd}}}%
+      \ifminted at frozencache
       \else
-        \immediate\openout\minted at code\minted at jobname.mintedcmd\relax
-        \immediate\write\minted at code{\minted at cmd}%
-        \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}%
-          {\immediate\write\minted at code{autogobble}}{}%
-        \immediate\closeout\minted at code
-        %Cheating a little here by using ASCII codes to write `{` and `}`
-        %in the Python code
-        \def\minted at hashcmd{%
-          \detokenize{python -c "import hashlib;
-            hasher = hashlib.sha1();
-            f = open(\"}\minted at outputdir\minted at jobname.mintedcmd\detokenize{\", \"rb\");
-            hasher.update(f.read());
-            f.close();
-            f = open(\"}#1\detokenize{\", \"rb\");
-            hasher.update(f.read());
-            f.close();
-            f = open(\"}\minted at outputdir\minted at jobname.mintedmd5\detokenize{\", \"w\");
-            macro = \"\\edef\\minted at hash\" + chr(123) + hasher.hexdigest() + chr(125) + \"\";
-            f.write(\"\\makeatletter\" + macro + \"\\makeatother\\endinput\n\");
-            f.close();"}}%
-        \immediate\write18{\minted at hashcmd}%
-        \minted at input{\minted at outputdir\minted at jobname.mintedmd5}%
+        \ifx\XeTeXinterchartoks\minted at undefined
+          \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}%
+            {\edef\minted at hash{\pdf at filemdfivesum{#1}%
+              \pdf at mdfivesum{\minted at cmd autogobble}}}%
+            {\edef\minted at hash{\pdf at filemdfivesum{#1}%
+              \pdf at mdfivesum{\minted at cmd}}}%
+        \else
+          \immediate\openout\minted at code\minted at jobname.mintedcmd\relax
+          \immediate\write\minted at code{\minted at cmd}%
+          \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}%
+            {\immediate\write\minted at code{autogobble}}{}%
+          \immediate\closeout\minted at code
+          \edef\minted at argone@esc{#1}%
+          \StrSubstitute{\minted at argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at argone@esc]%
+          \StrSubstitute{\minted at argone@esc}{"}{\@backslashchar"}[\minted at argone@esc]%
+          \edef\minted at tmpfname@esc{\minted at outputdir\minted at jobname}%
+          \StrSubstitute{\minted at tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at tmpfname@esc]%
+          \StrSubstitute{\minted at tmpfname@esc}{"}{\@backslashchar"}[\minted at tmpfname@esc]%
+          %Cheating a little here by using ASCII codes to write `{` and `}`
+          %in the Python code
+          \def\minted at hashcmd{%
+            \detokenize{python -c "import hashlib; import os;
+              hasher = hashlib.sha1();
+              f = open(os.path.expanduser(os.path.expandvars(\"}\minted at tmpfname@esc.mintedcmd\detokenize{\")), \"rb\");
+              hasher.update(f.read());
+              f.close();
+              f = open(os.path.expanduser(os.path.expandvars(\"}\minted at argone@esc\detokenize{\")), \"rb\");
+              hasher.update(f.read());
+              f.close();
+              f = open(os.path.expanduser(os.path.expandvars(\"}\minted at tmpfname@esc.mintedmd5\detokenize{\")), \"w\");
+              macro = \"\\edef\\minted at hash\" + chr(123) + hasher.hexdigest() + chr(125) + \"\";
+              f.write(\"\\makeatletter\" + macro + \"\\makeatother\\endinput\n\");
+              f.close();"}}%
+          \ShellEscape{\minted at hashcmd}%
+          \minted at input{\minted at outputdir\minted at jobname.mintedmd5}%
+        \fi
+        \edef\minted at infile{\minted at cachedir/\minted at hash.pygtex}%
+        \IfFileExists{\minted at infile}{}{%
+          \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}{%
+            \edef\minted at argone@esc{#1}%
+            \StrSubstitute{\minted at argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at argone@esc]%
+            \StrSubstitute{\minted at argone@esc}{"}{\@backslashchar"}[\minted at argone@esc]%
+            \edef\minted at tmpfname@esc{\minted at outputdir\minted at jobname}%
+            \StrSubstitute{\minted at tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at tmpfname@esc]%
+            \StrSubstitute{\minted at tmpfname@esc}{"}{\@backslashchar"}[\minted at tmpfname@esc]%
+            %Need a version of open() that supports encoding under Python 2
+            \edef\minted at autogobblecmd{%
+              \detokenize{python -c "import sys; import os;
+              import textwrap;
+              from io import open;
+              f = open(os.path.expanduser(os.path.expandvars(\"}\minted at argone@esc\detokenize{\")), \"r\", encoding=\"}\minted at encoding\detokenize{\");
+              t = f.read();
+              f.close();
+              f = open(os.path.expanduser(os.path.expandvars(\"}\minted at tmpfname@esc.pyg\detokenize{\")), \"w\", encoding=\"}\minted at encoding\detokenize{\");
+              f.write(textwrap.dedent(t));
+              f.close();"}%
+            }%
+            \ShellEscape{\minted at autogobblecmd}}{}%
+          \ShellEscape{\minted at cmd}}%
       \fi
-      \edef\minted at infile{\minted at cachedir/\minted at hash.pygtex}%
-      \IfFileExists{\minted at infile}{}{%
-        \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}{%
-          %Need a version of open() that supports encoding under Python 2
-          \edef\minted at autogobblecmd{%
-            \detokenize{python -c "import sys;
-            import textwrap;
-            from io import open;
-            f = open(\"}#1\detokenize{\", \"r\", encoding=\"}\minted at encoding\detokenize{\");
-            t = f.read();
-            f.close();
-            f = open(\"}\minted at outputdir\minted at jobname.pyg\detokenize{\", \"w\", encoding=\"}\minted at encoding\detokenize{\");
-            f.write(textwrap.dedent(t));
-            f.close();"}%
-          }%
-          \immediate\write18{\minted at autogobblecmd}}{}%
-        \immediate\write18{\minted at cmd}}%
-      \expandafter\minted at addcachefile\expandafter{\minted at hash.pygtex}%
+      \ifthenelse{\boolean{minted at finalizecache}}%
+       {%
+          \edef\minted at cachefilename{listing\arabic{minted at pygmentizecounter}.pygtex}%
+          \edef\minted at actualinfile{\minted at cachedir/\minted at cachefilename}%
+          \ifwindows
+            \StrSubstitute{\minted at infile}{/}{\@backslashchar}[\minted at infile@windows]
+            \StrSubstitute{\minted at actualinfile}{/}{\@backslashchar}[\minted at actualinfile@windows]
+            \ShellEscape{move /y \minted at infile@windows\space\minted at actualinfile@windows}%
+          \else
+            \ShellEscape{mv -f \minted at infile\space\minted at actualinfile}%
+          \fi
+          \let\minted at infile\minted at actualinfile
+          \expandafter\minted at addcachefile\expandafter{\minted at cachefilename}%
+       }%
+       {\ifthenelse{\boolean{minted at frozencache}}%
+         {%
+            \edef\minted at cachefilename{listing\arabic{minted at pygmentizecounter}.pygtex}%
+            \edef\minted at infile{\minted at cachedir/\minted at cachefilename}%
+            \expandafter\minted at addcachefile\expandafter{\minted at cachefilename}}%
+         {\expandafter\minted at addcachefile\expandafter{\minted at hash.pygtex}}%
+       }%
       \minted at inputpyg}%
     {%
       \ifthenelse{\equal{\minted at get@opt{autogobble}{false}}{true}}{%
+        \edef\minted at argone@esc{#1}%
+        \StrSubstitute{\minted at argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at argone@esc]%
+        \StrSubstitute{\minted at argone@esc}{"}{\@backslashchar"}[\minted at argone@esc]%
+        \edef\minted at tmpfname@esc{\minted at outputdir\minted at jobname}%
+        \StrSubstitute{\minted at tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted at tmpfname@esc]%
+        \StrSubstitute{\minted at tmpfname@esc}{"}{\@backslashchar"}[\minted at tmpfname@esc]%
         %Need a version of open() that supports encoding under Python 2
         \edef\minted at autogobblecmd{%
-          \detokenize{python -c "import sys;
+          \detokenize{python -c "import sys; import os;
           import textwrap;
           from io import open;
-          f = open(\"}#1\detokenize{\", \"r\", encoding=\"}\minted at encoding\detokenize{\");
+          f = open(os.path.expanduser(os.path.expandvars(\"}\minted at argone@esc\detokenize{\")), \"r\", encoding=\"}\minted at encoding\detokenize{\");
           t = f.read();
           f.close();
-          f = open(\"}\minted at outputdir\minted at jobname.pyg\detokenize{\", \"w\", encoding=\"}\minted at encoding\detokenize{\");
+          f = open(os.path.expanduser(os.path.expandvars(\"}\minted at tmpfname@esc.pyg\detokenize{\")), \"w\", encoding=\"}\minted at encoding\detokenize{\");
           f.write(textwrap.dedent(t));
           f.close();"}%
         }%
-        \immediate\write18{\minted at autogobblecmd}}{}%
-      \immediate\write18{\minted at cmd}%
+        \ShellEscape{\minted at autogobblecmd}}{}%
+      \ShellEscape{\minted at cmd}%
       \minted at inputpyg}%
 }
 \def\FV at SpaceMMode{ }
+\def\minted at BreakBeforePrep@extension{%
+  \ifcsname FV at BreakBefore@Token\@backslashchar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZbs}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at underscorechar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZus}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@charlb\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZob}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@charrb\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZcb}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{^}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZca}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at ampchar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZam}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{<}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZlt}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{>}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZgt}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at hashchar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZsh}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@percentchar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZpc}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at dollarchar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZdl}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{-}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZhy}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{'}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZsq}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{"}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZdq}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at tildechar\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZti}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{@}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZat}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{[}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZlb}}{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{]}\endcsname
+    \@namedef{FV at BreakBefore@Token\detokenize{\PYGZrb}}{}%
+  \fi
+}
 \def\minted at BreakAfterPrep@extension{%
   \ifcsname FV at BreakAfter@Token\@backslashchar\endcsname
     \@namedef{FV at BreakAfter@Token\detokenize{\PYGZbs}}{}%
@@ -1176,6 +1430,9 @@
   \fi
 }
 \newcommand{\minted at inputpyg}{%
+  \let\FV at BreakBeforePrep@orig\FV at BreakBeforePrep
+  \def\FV at BreakBeforePrep{%
+    \FV at BreakBeforePrep@orig\minted at BreakBeforePrep@extension}%
   \let\FV at BreakAfterPrep@orig\FV at BreakAfterPrep
   \def\FV at BreakAfterPrep{%
     \FV at BreakAfterPrep@orig\minted at BreakAfterPrep@extension}%
@@ -1188,12 +1445,20 @@
      \expandafter\def\csname PYG\minted at get@opt{style}{default}\endcsname##1##2{%
        \minted at orig@PYG at breakanywhere{##1}%
          {\FancyVerbBreakStart##2\FancyVerbBreakStop}}}{}%
-  \ifx\FV at BreakAfter\@empty
+  \ifx\FV at BreakBefore\@empty
+    \ifx\FV at BreakAfter\@empty
+    \else
+      \expandafter\let\expandafter\minted at orig@PYG at breakbeforeafter%
+        \csname PYG\minted at get@opt{style}{default}\endcsname
+      \expandafter\def\csname PYG\minted at get@opt{style}{default}\endcsname##1##2{%
+        \minted at orig@PYG at breakbeforeafter{##1}%
+         {\FancyVerbBreakStart##2\FancyVerbBreakStop}}%
+    \fi
   \else
-    \expandafter\let\expandafter\minted at orig@PYG at breakafter%
+    \expandafter\let\expandafter\minted at orig@PYG at breakbeforeafter%
       \csname PYG\minted at get@opt{style}{default}\endcsname
     \expandafter\def\csname PYG\minted at get@opt{style}{default}\endcsname##1##2{%
-      \minted at orig@PYG at breakafter{##1}%
+      \minted at orig@PYG at breakbeforeafter{##1}%
        {\FancyVerbBreakStart##2\FancyVerbBreakStop}}%
   \fi
   \ifthenelse{\boolean{minted at isinline}}%
@@ -1469,37 +1734,48 @@
 \providecommand{\listoflistings}{\listof{listing}{\listoflistingscaption}}
 \fi
 \AtEndOfPackage{%
-  \ifthenelse{\boolean{minted at draft}}{}{%
-    \ifnum\pdf at shellescape=1\relax\else
-      \PackageError{minted}%
-       {You must invoke LaTeX with the
-        -shell-escape flag}%
-       {Pass the -shell-escape flag to LaTeX. Refer to the minted.sty
-        documentation for more information.}%
-    \fi
-    \setminted{style=default}%
-  }%
+  \ifthenelse{\boolean{minted at draft}}%
+   {}%
+   {%
+    \ifthenelse{\boolean{minted at frozencache}}{}{%
+      \ifnum\pdf at shellescape=1\relax\else
+        \PackageError{minted}%
+         {You must invoke LaTeX with the
+          -shell-escape flag}%
+         {Pass the -shell-escape flag to LaTeX. Refer to the minted.sty
+          documentation for more information.}%
+      \fi}%
+   }%
 }
 \AtEndPreamble{%
-  \ifthenelse{\boolean{minted at draft}}{}{%
-    \TestAppExists{pygmentize}%
-    \ifAppExists\else
-      \PackageError{minted}%
-       {You must have `pygmentize' installed
-        to use this package}%
-       {Refer to the installation instructions in the minted
-        documentation for more information.}%
-    \fi
+  \ifthenelse{\boolean{minted at draft}}%
+   {}%
+   {%
+    \ifthenelse{\boolean{minted at frozencache}}{}{%
+      \TestAppExists{\MintedPygmentize}%
+      \ifAppExists\else
+        \PackageError{minted}%
+         {You must have `pygmentize' installed
+          to use this package}%
+         {Refer to the installation instructions in the minted
+          documentation for more information.}%
+      \fi}%
   }%
 }
-\AtEndDocument{
-  \ifx\XeTeXinterchartoks\minted at undefined
-  \else
-    \DeleteFile[\minted at outputdir]{\minted at jobname.mintedcmd}%
-    \DeleteFile[\minted at outputdir]{\minted at jobname.mintedmd5}%
-  \fi
-  \DeleteFile[\minted at outputdir]{\minted at jobname.pyg}%
-  \DeleteFile[\minted at outputdir]{\minted at jobname.out.pyg}%
+\AfterEndDocument{%
+  \ifthenelse{\boolean{minted at draft}}%
+   {}%
+   {\ifthenelse{\boolean{minted at frozencache}}%
+     {}
+     {\ifx\XeTeXinterchartoks\minted at undefined
+      \else
+        \DeleteFile[\minted at outputdir]{\minted at jobname.mintedcmd}%
+        \DeleteFile[\minted at outputdir]{\minted at jobname.mintedmd5}%
+      \fi
+      \DeleteFile[\minted at outputdir]{\minted at jobname.pyg}%
+      \DeleteFile[\minted at outputdir]{\minted at jobname.out.pyg}%
+     }%
+   }%
 }
 \endinput
 %%

Modified: trunk/Master/texmf-dist/tex/latex/minted/minted1.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/minted/minted1.sty	2016-06-09 22:52:34 UTC (rev 41328)
+++ trunk/Master/texmf-dist/tex/latex/minted/minted1.sty	2016-06-09 22:52:48 UTC (rev 41329)
@@ -5,7 +5,7 @@
 %% The original source files were:
 %%
 %% minted.dtx  (with options: `packageone')
-%% Copyright 2013--2015 Geoffrey M. Poore
+%% Copyright 2013--2016 Geoffrey M. Poore
 %% Copyright 2010--2011 Konrad Rudolph
 %% 
 %% This work may be distributed and/or modified under the



More information about the tex-live-commits mailing list