diff options
author | Karl Berry <karl@freefriends.org> | 2017-07-20 21:22:54 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-07-20 21:22:54 +0000 |
commit | 63ad53fb1eb73d728d93f083d65fd585cd295978 (patch) | |
tree | eaa63654f927aee6c24df715f0236b34d5d1488f /Master/texmf-dist/source/latex/minted/minted.dtx | |
parent | 801f243e1382ba3fc8798cc8e38db540c8dc9d6e (diff) |
minted (20jul17)
git-svn-id: svn://tug.org/texlive/trunk@44855 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/minted/minted.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/minted/minted.dtx | 261 |
1 files changed, 170 insertions, 91 deletions
diff --git a/Master/texmf-dist/source/latex/minted/minted.dtx b/Master/texmf-dist/source/latex/minted/minted.dtx index 4cbc252fa30..3a15d7c1e69 100644 --- a/Master/texmf-dist/source/latex/minted/minted.dtx +++ b/Master/texmf-dist/source/latex/minted/minted.dtx @@ -1,6 +1,6 @@ % \iffalse meta-comment % -% Copyright (C) 2013-2016 by Geoffrey M. Poore <gpoore@gmail.com> +% Copyright (C) 2013-2017 by Geoffrey M. Poore <gpoore@gmail.com> % Copyright (C) 2010-2011 by Konrad Rudolph <konrad_rudolph@madrat.net> % --------------------------------------------------------------------------- % This work may be distributed and/or modified under the @@ -31,7 +31,7 @@ %<package>\NeedsTeXFormat{LaTeX2e} %<package>\ProvidesPackage{minted} %<*package> - [2016/10/31 v2.4.1 Yet another Pygments shim for LaTeX] + [2017/07/19 v2.5 Yet another Pygments shim for LaTeX] %</package> %<*driver> \documentclass{ltxdoc} @@ -163,7 +163,7 @@ \def\minted@printopt#1(#2) (#3){% \vspace{0.1in}% \leavevmode% - \marginpar{\raggedleft\texttt{\textcolor{minted@linkcolor}{#1}}\ }% + \marginpar{\raggedleft\texttt{\textcolor{minted@linkcolor}{\small #1}}\ }% \kern-\parindent\textsf{(#2)}\hfill(default: \texttt{#3})\\} \newenvironment{optionlist}% @@ -195,7 +195,7 @@ %</driver> % \fi % -% \CheckSum{2614} +% \CheckSum{2604} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -216,6 +216,19 @@ % % % +% \begin{changelog}{v2.5}{2017/07/19} +% \item The default placement for the \texttt{listing} float is now \texttt{tbp} instead of \texttt{h}, to parallel \texttt{figure} and \texttt{table} and also avoid warnings caused by \texttt{h} (\#165). The documentation now contains information about changing default placement. The \texttt{float} package is no longer loaded when the \texttt{newfloat} package option is used. +% \item Added support for \texttt{*nchars} options from \texttt{fvextra} v1.3 that allow setting \texttt{breaklines}-related indentation in terms of a number of characters, rather than as a fixed dimension. +% \item Fixed incompatibility with \texttt{babel magyar} (\#158). +% \item Added support for \texttt{beamer} overlays with \texttt{beameroverlays} option (\#155). +% \item Comments in the Pygments \LaTeX\ style files no longer appear as literal text when \texttt{minted} is used in \texttt{.dtx} files (\#161). +% \item \texttt{autogobble} now works with package option \texttt{kpsewhich} (\#151). Under Windows, the \texttt{kpsewhich} option no longer requires PowerShell. +% \item Fixed a bug that prevented \texttt{finalizecache} from working with \texttt{outputdir} (\#149). +% \item Fixed a bug with \texttt{firstline} and \texttt{lastline} that prevented them from working with the \texttt{minted} environment (\#145). +% \item Added note on \texttt{breqn} conflicts to FAQ (\#163). +% \end{changelog} +% +% % \begin{changelog}{v2.4.1}{2016/10/31} % \item Single quotation marks in \texttt{\string\jobname} are now replaced with underscores in \texttt{\string\minted@jobname} to prevent quoting errors (\#137). % \item The \texttt{autogobble} option now takes \texttt{firstline} and \texttt{lastline} into account (\#130). @@ -697,8 +710,7 @@ % \section{Floating listings}\label{sec:float} % % \DescribeEnv{listing} -% \pkg{minted} provides the |listing| environment to wrap around a source code block. This puts the code into a floating box. You can also provide a |\caption| and a |\label| for such a listing in the usual way (that is, -% as for the |table| and |figure| environments): +% \pkg{minted} provides the |listing| environment to wrap around a source code block. This puts the code into a floating box, with the default placement |tbp| like figures and tables. You can also provide a |\caption| and a |\label| for such a listing in the usual way (that is, as for the |figure| and |table| environments): % \begin{VerbatimOut}[gobble=1]{minted.doc.out} % \begin{listing}[H] % \mint{cl}/(car (cons 1 '(2)))/ @@ -718,6 +730,18 @@ % \end{minipage}} % \hfill\hfill % +% The default |listing| placement can be modified easily. When the package option |newfloat=false| (default), the \pkg{float} package is used to create the |listing| environment. Placement can be modified by redefining |\fps@listing|. For example, +%\begin{verbatim} +%\makeatletter +%\renewcommand{\fps@listing}{htp} +%\makeatother +%\end{verbatim} +% When |newfloat=true|, the more powerful \pkg{newfloat} package is used to create the |listing| environment. In that case, \pkg{newfloat} commands are available to customize |listing|: +%\begin{verbatim} +%\SetupFloatingEnvironment{listing}{placement=htp} +%\end{verbatim} +% +% % \DescribeMacro{\listoflistings} % The |\listoflistings| macro will insert a list of all (floated) listings in the document: % @@ -825,8 +849,6 @@ % % This option does \emph{not} make \pkg{minted} work with the |-output-directory| and |-aux-directory| command-line options for \LaTeX. For those, see the |outputdir| package option. % -% Under Windows, this option currently requires that PowerShell be installed. It may need to be installed in versions of Windows prior to Windows 7. -% % % \DescribeMacro{langlinenos=\meta{boolean} (default:~false)} % \pkg{minted} uses the \pkg{fancyvrb} package behind the scenes for the code typesetting. \pkg{fancyvrb} provides an option |firstnumber| that allows the starting line number of an environment to be specified. For convenience, there is an option |firstnumber=last| that allows line numbering to pick up where it left off. The |langlinenos| option makes |firstnumber| work for each language individually with all |minted| and |\mint| usages. For example, consider the code and output below. @@ -959,6 +981,11 @@ % \item[baselinestretch (dimension) (\meta{document default})] % Value to use as for baselinestretch inside the listing. % +% +% \item[beameroverlays (boolean) (false)] +% Give the |<| and |>| characters their normal text meanings when used with |escapeinside| and |texcomments|, so that \pkg{beamer} overlays of the form |\only<1>{...}| will work. +% +% % \item[breakafter (string) (\meta{none})] % Break lines after specified characters, not just at spaces, when \texttt{breaklines=true}. Does not apply to |\mintinline|. % @@ -1032,8 +1059,13 @@ % \item[breakbytokenanywhere (boolean) (false)] % Like \texttt{breakbytoken}, but also allows line breaks between immediately adjacent tokens, not just between tokens that are separated by spaces. Using \texttt{breakbytokenanywhere} with \texttt{breakanywhere} is redundant. % -% \item[breakindent (dimension) (0pt)] -% When a line is broken, indent the continuation lines by this amount. When \texttt{breakautoindent} and \texttt{breakindent} are used together, the indentations add. This indentation is combined with \texttt{breaksymbolindentleft} to give the total actual left indentation. Does not apply to \texttt{\string\mintinline}. +% \item[breakindent (dimension) (\meta{breakindentnchars})] +% When a line is broken, indent the continuation lines by this amount. When |breakautoindent| and |breakindent| are used together, the indentations add. This indentation is combined with |breaksymbolindentleft| to give the total actual left indentation. +% +% Does not apply to \texttt{\string\mintinline}. +% +% \item[breakindentnchars (integer) (0)] +% This allows |breakindent| to be specified as an integer number of characters rather than as a dimension (assumes a fixed-width font). % % \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}. @@ -1091,32 +1123,49 @@ % \item[breaksymbolright (string) (\meta{none})] % The symbol used at breaks (right) when \texttt{breaklines=true}. Does not appear at the end of the very last segment of a broken line. % -% \item[breaksymbolindent (dimension) (breaksymbolindentleft)] -% Alias for \texttt{breaksymbolindentleft}. % -% \item[breaksymbolindentleft (dimension) (\meta{width of 4 characters in default teletype font})] -% The extra left indentation that is provided to make room for \texttt{breaksymbolleft}. This indentation is only applied when there is a \texttt{breaksymbolleft}. +% \item[breaksymbolindent (dimension) (\meta{breaksymbolindentleftnchars})] +% Alias for |breaksymbolindentleft|. +% +% \item[breaksymbolindentnchars (integer) (\meta{breaksymbolindentleftnchars})] +% Alias for |breaksymbolindentleftnchars|. % -% This may be set to the width of a specific number of (fixed-width) characters by using an approach such as -%\begin{Verbatim} -%\newdimen\temporarydimen -%\settowidth{\temporarydimen}{\ttfamily aaaa} -%\end{Verbatim} -% and then using \texttt{breaksymbolindentleft=\string\temporarydimen}. +% +% \item[breaksymbolindentleft (dimension) (\meta{breaksymbolindentleftnchars})] +% The extra left indentation that is provided to make room for |breaksymbolleft|. This indentation is only applied when there is a |breaksymbolleft|. % % Does not apply to \texttt{\string\mintinline}. % -% \item[breaksymbolindentright (dimension) (\meta{width of 4 characters in default teletype font})] -% The extra right indentation that is provided to make room for \texttt{breaksymbolright}. This indentation is only applied when there is a \texttt{breaksymbolright}. +% \item[breaksymbolindentleftnchars (integer) (4)] +% This allows |breaksymbolindentleft| to be specified as an integer number of characters rather than as a dimension (assumes a fixed-width font). +% +% \item[breaksymbolindentright (dimension) (\meta{breaksymbolindentrightnchars})] +% The extra right indentation that is provided to make room for |breaksymbolright|. This indentation is only applied when there is a |breaksymbolright|. +% +% \item[breaksymbolindentrightnchars (integer) (4)] +% This allows |breaksymbolindentright| to be specified as an integer number of characters rather than as a dimension (assumes a fixed-width font). +% +% +% \item[breaksymbolsep (dimension) (\meta{breaksymbolsepleftnchars})] +% Alias for |breaksymbolsepleft|. +% +% \item[breaksymbolsepnchars (integer) (\meta{breaksymbolsepleftnchars})] +% Alias for |breaksymbolsepleftnchars|. % -% \item[breaksymbolsep (dimension) (breaksymbolsepleft)] -% Alias for \texttt{breaksymbolsepleft} % -% \item[breaksymbolsepleft (dimension) (1em)] -% The separation between the \texttt{breaksymbolleft} and the adjacent code. Does not apply to \texttt{\string\mintinline}. +% \item[breaksymbolsepleft (dimension) (\meta{breaksymbolsepleftnchars})] +% The separation between the |breaksymbolleft| and the adjacent text. +% +% \item[breaksymbolsepleftnchars (integer) (2)] +% Allows |breaksymbolsepleft| to be specified as an integer number of characters rather than as a dimension (assumes a fixed-width font). +% +% +% \item[breaksymbolsepright (dimension) (\meta{breaksymbolseprightnchars})] +% The \emph{minimum} separation between the |breaksymbolright| and the adjacent text. This is the separation between |breaksymbolright| and the furthest extent to which adjacent text could reach. In practice, |\linewidth| will typically not be an exact integer multiple of the character width (assuming a fixed-width font), so the actual separation between the |breaksymbolright| and adjacent text will generally be larger than |breaksymbolsepright|. This ensures that break symbols have the same spacing from the margins on both left and right. If the same spacing from text is desired instead, |breaksymbolsepright| may be adjusted. (See the definition of |\FV@makeLineNumber| in \pkg{fvextra} for implementation details.) +% +% \item[breaksymbolseprightnchars (integer) (2)] +% Allows |breaksymbolsepright| to be specified as an integer number of characters rather than as a dimension (assumes a fixed-width font). % -% \item[breaksymbolsepright (dimension) (1em)] -% The separation between the \texttt{breaksymbolright} and the adjacent code. % % \item[bgcolor (string) (\meta{none})] % Background color of the listing. Be aware that this option has several limitations (described below); see ``Framing alternatives'' below for more powerful alternatives. @@ -1431,8 +1480,10 @@ % 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{There are intermittent ``I can't write on file'' errors.} This can be caused by using \pkg{minted} in a directory that is synchronized with Dropbox or a similar file syncing program. These programs can try to sync \pkg{minted}'s temporary files while it still needs to be able to modify them. The solution is to turn off file syncing or use a directory that is not synced. % \item \textbf{I receive a ``Font Warning: Some font shapes were not available'' message, or bold or italic seem to be missing.} This due to a limitation in the font that is currently in use for typesetting code. In some cases, the default font shapes that \LaTeX\ substitutes are perfectly adequate, and the warning may be ignored. In other cases, the font substitutions may not clearly indicate bold or italic text, and you will want to switch to a different font. See The \LaTeX\ Font Catalogue's section on \href{http://www.tug.dk/FontCatalogue/typewriterfonts.html}{Typewriter Fonts} for alternatives. If you like the default \LaTeX\ fonts, the \pkg{lmodern} package is a good place to start. The \pkg{beramono} and \pkg{courier} packages may also be good options. % \item \textbf{I receive a ``Too many open files'' error under OS X when using caching.} See the note on OS X under Section~\ref{sec:basic:preliminary}. +% \item \textbf{TeXShop can't find \texttt{pygmentize}.} You may need to create a symlink. See \url{https://tex.stackexchange.com/questions/279214}. % \item \textbf{Weird things happen when I use the \pkg{fancybox} package.} \pkg{fancybox} conflicts with \pkg{fancyvrb}, which \pkg{minted} uses internally. When using \pkg{fancybox}, make sure that it is loaded before \pkg{minted} (or before \pkg{fancyvrb}, if \pkg{fancyvrb} is not loaded by \pkg{minted}). % \item \textbf{When I use \pkg{minted} with KOMA-Script document classes, I get warnings about \texttt{\string\float@addtolists}.} \pkg{minted} uses the \pkg{float} package to produce floated listings, but this conflicts with the way KOMA-Script does floats. Load the package \pkg{scrhack} to resolve the conflict. Or use \pkg{minted}'s |newfloat| package option. % \item \textbf{Tilde characters \texttt{\string~} are raised, almost like superscripts.} @@ -1440,6 +1491,12 @@ % % \item \textbf{I'm getting errors with math, something like \texttt{TeX capacity exceeded} and \texttt{\string\leavevmode \string\kern \string\z@}.} This is due to ligatures being disabled within verbatim content. See the note under |escapeinside|. % +% \item \textbf{With \texttt{mathescape} and the \pkg{breqn} package (or another special math package), the document never finishes compiling or there are other unexpected results.} Some math packages like \pkg{breqn} give certain characters like the comma special meanings in math mode. These can conflict with \pkg{minted}. In the \pkg{breqn} and comma case, this can be fixed by redefining the comma within |minted| environments: +%\begin{verbatim} +%\AtBeginEnvironment{minted}{\catcode`\,=12\mathcode`\,="613B} +%\end{verbatim} +%Other packages/special characters may need their own modifications. +% % \item \textbf{I'm getting errors with Beamer.} Due to how Beamer treats verbatim content, you may need to use either the |fragile| or |fragile=singleslide| options for frames that contain \pkg{minted} commands and environments. |fragile=singleslide| works best, but it disables overlays. |fragile| works by saving the contents of each frame to a temp file and then reusing them. This approach allows overlays, but will break if you have the string |\end{frame}| at the beginning of a line (for example, in a |minted| environment). To work around that, you can indent the content of the environment (so that the |\end{frame}| is preceded by one or more spaces) and then use the |gobble| or |autogobble| options to remove the indentation. % % \item \textbf{Tabs are eaten by Beamer.} This is due to \href{https://bitbucket.org/rivanvx/beamer/issue/310/tab-characters-in-listings-lost-when-using}{a bug in Beamer's treatment of verbatim content}. Upgrade Beamer or use the linked patch. Otherwise, try |fragile=singleslide| if you don't need overlays, or consider using \cmd\inputminted\ or converting the tabs into spaces. @@ -1530,7 +1587,6 @@ \RequirePackage{keyval} \RequirePackage{kvoptions} \RequirePackage{fvextra} -\RequirePackage{float} \RequirePackage{ifthen} \RequirePackage{calc} \IfFileExists{shellesc.sty} @@ -1675,7 +1731,7 @@ % % \begin{macrocode} \ProcessKeyvalOptions* -\ifthenelse{\boolean{minted@newfloat}}{\RequirePackage{newfloat}}{} +\ifthenelse{\boolean{minted@newfloat}}{\RequirePackage{newfloat}}{\RequirePackage{float}} \ifcsname tikzifexternalizing\endcsname \tikzifexternalizing{\minted@drafttrue\minted@cachefalse}{} \else @@ -1712,12 +1768,10 @@ {\PackageError{minted}{Missing Pygments output; \string\inputminted\space 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,^^Jor may be using frozencache with a missing file}% + tool,^^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, + ^^Jchanges paths in ways minted cannot detect, ^^Jor using frozencache with a missing file.}}% } % \end{macrocode} @@ -2346,7 +2400,7 @@ % \begin{macro}{\minted@checkstyle} % Make sure that style macros exist. % -% We have to do some tricks with |\endlinechar| to prevent |\input| from inserting unwanted whitespace. That is primarily for inline commands, where it would introduce a line break. There is also the very unorthodox |\let\def\gdef| to make sure that macros are defined globally. The catcodes for |-| and |_| must be changed during macro definition to accomodate style names like |paraiso-light|, |paraiso-dark|, and |algol_nu|. +% We have to do some tricks with |\endlinechar| to prevent |\input| from inserting unwanted whitespace. That is primarily for inline commands, where it would introduce a line break. There is also the very unorthodox |\let\def\gdef| to make sure that macros are defined globally. The catcodes for |-| and |_| must be changed during macro definition to accomodate style names like |paraiso-light|, |paraiso-dark|, and |algol_nu|. The catcode for |%| must be changed to the default value in case \pkg{minted} is being used in a |.dtx| file; otherwise, \LaTeX\ comments in the Pygments style files will appear as literal text. % % If a style is not given, then revert to the |default| style, but create macros with prefix |PYG|, and create |default-pyg-prefix.pygstyle| if caching is on. This allows a graceful fallback in the event that style is empty. It is also purposefully used to create a complete set of macros with prefix |PYG|, so that the symbol macros may be used, as described next. % @@ -2386,8 +2440,10 @@ }% \begingroup \let\def\gdef + \catcode\string``=12 \catcode`\_=11 \catcode`\-=11 + \catcode`\%=14 \endlinechar=-1\relax \minted@input{% \minted@outputdir\minted@cachedir/\ifstrempty{#1}{default-pyg-prefix}{#1}.pygstyle}% @@ -2405,8 +2461,10 @@ \fi \begingroup \let\def\gdef + \catcode\string``=12 \catcode`\_=11 \catcode`\-=11 + \catcode`\%=14 \endlinechar=-1\relax \minted@input{\minted@outputdir\minted@jobname.out.pyg}% \endgroup}% @@ -2542,7 +2600,7 @@ \minted@def@opt{style} % \end{macrocode} % -% \pkg{fancyvrb} options. +% \pkg{fancyvrb} and \pkg{fvextra} options. % \begin{macrocode} \minted@def@optfv{frame} \minted@def@optfv{framesep} @@ -2573,6 +2631,7 @@ \minted@def@optfv{tab} \minted@def@optfv{tabcolor} \minted@def@optfv{highlightcolor} +\minted@def@optfv@switch{beameroverlays} \minted@def@optfv@switch{curlyquotes} \minted@def@optfv@switch{numberfirstline} \minted@def@optfv@switch{numberblanklines} @@ -2587,16 +2646,23 @@ \minted@def@optfv@switch{breakbytoken} \minted@def@optfv@switch{breakbytokenanywhere} \minted@def@optfv{breakindent} +\minted@def@optfv{breakindentnchars} \minted@def@optfv@switch{breakautoindent} \minted@def@optfv{breaksymbol} \minted@def@optfv{breaksymbolsep} +\minted@def@optfv{breaksymbolsepnchars} \minted@def@optfv{breaksymbolindent} +\minted@def@optfv{breaksymbolindentnchars} \minted@def@optfv{breaksymbolleft} \minted@def@optfv{breaksymbolsepleft} +\minted@def@optfv{breaksymbolsepleftnchars} \minted@def@optfv{breaksymbolindentleft} +\minted@def@optfv{breaksymbolindentleftnchars} \minted@def@optfv{breaksymbolright} \minted@def@optfv{breaksymbolsepright} +\minted@def@optfv{breaksymbolseprightnchars} \minted@def@optfv{breaksymbolindentright} +\minted@def@optfv{breaksymbolindentrightnchars} \minted@def@optfv{breakbefore} \minted@def@optfv{breakbeforesymbolpre} \minted@def@optfv{breakbeforesymbolpost} @@ -2765,7 +2831,11 @@ \csname minted@optlistcl@lang\minted@lang @i\endcsname}}% {\let\minted@optlistcl@inlines\@empty}% \def\minted@cmd{% - \ifminted@kpsewhich\ifwindows powershell\space\fi\fi + \ifminted@kpsewhich + \ifwindows + \detokenize{for /f "usebackq tokens=*"}\space\@percentchar\detokenize{a in (`kpsewhich}\space\minted@codefile\detokenize{`) do}\space + \fi + \fi \MintedPygmentize\space -l #2 -f latex -P commandprefix=PYG -F tokenmerge \minted@optlistcl@g \csname minted@optlistcl@lang\minted@lang\endcsname @@ -2773,7 +2843,7 @@ \minted@optlistcl@cmd -o \minted@outputdir\minted@infile\space \ifminted@kpsewhich \ifwindows - \detokenize{$}(kpsewhich \minted@codefile)% + \@percentchar\detokenize{a}% \else \detokenize{`}kpsewhich \minted@codefile\space \detokenize{||} \minted@codefile\detokenize{`}% @@ -2835,29 +2905,7 @@ \edef\minted@infile{\minted@cachedir/\minted@hash.pygtex}% \IfFileExists{\minted@infile}{}{% \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}{% - \edef\minted@argone@esc{#1}% - \StrSubstitute{\minted@argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@argone@esc]% - \StrSubstitute{\minted@argone@esc}{"}{\@backslashchar"}[\minted@argone@esc]% - \edef\minted@tmpfname@esc{\minted@outputdir\minted@jobname}% - \StrSubstitute{\minted@tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@tmpfname@esc]% - \StrSubstitute{\minted@tmpfname@esc}{"}{\@backslashchar"}[\minted@tmpfname@esc]% - %Need a version of open() that supports encoding under Python 2 - \edef\minted@autogobblecmd{% - \detokenize{python -c "import sys; import os; - import textwrap; - from io import open; - f = open(os.path.expanduser(os.path.expandvars(\"}\minted@argone@esc\detokenize{\")), \"r\", encoding=\"}\minted@encoding\detokenize{\"); - t = f.readlines(); - f.close(); - f = open(os.path.expanduser(os.path.expandvars(\"}\minted@tmpfname@esc.pyg\detokenize{\")), \"w\", encoding=\"}\minted@encoding\detokenize{\"); - fvstartnum = }\ifx\FancyVerbStartNum\z@ 0\else\FancyVerbStartNum\fi\detokenize{; - fvstopnum = }\ifx\FancyVerbStopNum\z@ 0\else\FancyVerbStopNum\fi\detokenize{; - s = fvstartnum-1 if fvstartnum != 0 else 0; - e = fvstopnum if fvstopnum != 0 else len(t); - [f.write(textwrap.dedent(\"\".join(x))) for x in (t[0:s], t[s:e], t[e:]) if x]; - f.close();"}% - }% - \ShellEscape{\minted@autogobblecmd}}{}% + \minted@autogobble{#1}}{}% \ShellEscape{\minted@cmd}}% \fi \ifthenelse{\boolean{minted@finalizecache}}% @@ -2867,9 +2915,9 @@ \ifwindows \StrSubstitute{\minted@infile}{/}{\@backslashchar}[\minted@infile@windows] \StrSubstitute{\minted@actualinfile}{/}{\@backslashchar}[\minted@actualinfile@windows] - \ShellEscape{move /y \minted@infile@windows\space\minted@actualinfile@windows}% + \ShellEscape{move /y \minted@outputdir\minted@infile@windows\space\minted@outputdir\minted@actualinfile@windows}% \else - \ShellEscape{mv -f \minted@infile\space\minted@actualinfile}% + \ShellEscape{mv -f \minted@outputdir\minted@infile\space\minted@outputdir\minted@actualinfile}% \fi \let\minted@infile\minted@actualinfile \expandafter\minted@addcachefile\expandafter{\minted@cachefilename}% @@ -2884,35 +2932,66 @@ \minted@inputpyg}% {% \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}{% - \edef\minted@argone@esc{#1}% - \StrSubstitute{\minted@argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@argone@esc]% - \StrSubstitute{\minted@argone@esc}{"}{\@backslashchar"}[\minted@argone@esc]% - \edef\minted@tmpfname@esc{\minted@outputdir\minted@jobname}% - \StrSubstitute{\minted@tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@tmpfname@esc]% - \StrSubstitute{\minted@tmpfname@esc}{"}{\@backslashchar"}[\minted@tmpfname@esc]% - %Need a version of open() that supports encoding under Python 2 - \edef\minted@autogobblecmd{% - \detokenize{python -c "import sys; import os; - import textwrap; - from io import open; - f = open(os.path.expanduser(os.path.expandvars(\"}\minted@argone@esc\detokenize{\")), \"r\", encoding=\"}\minted@encoding\detokenize{\"); - t = f.readlines(); - f.close(); - f = open(os.path.expanduser(os.path.expandvars(\"}\minted@tmpfname@esc.pyg\detokenize{\")), \"w\", encoding=\"}\minted@encoding\detokenize{\"); - fvstartnum = }\ifx\FancyVerbStartNum\z@ 0\else\FancyVerbStartNum\fi\detokenize{; - fvstopnum = }\ifx\FancyVerbStopNum\z@ 0\else\FancyVerbStopNum\fi\detokenize{; - s = fvstartnum-1 if fvstartnum != 0 else 0; - e = fvstopnum if fvstopnum != 0 else len(t); - [f.write(textwrap.dedent(\"\".join(x))) for x in (t[0:s], t[s:e], t[e:]) if x]; - f.close();"}% - }% - \ShellEscape{\minted@autogobblecmd}}{}% + \minted@autogobble{#1}}{}% \ShellEscape{\minted@cmd}% \minted@inputpyg}% } % \end{macrocode} % \end{macro} % +% +% \begin{macro}{\minted@autogobble} +% Remove common leading whitespace. +% \begin{macrocode} +\def\minted@autogobble#1{% + \edef\minted@argone@esc{#1}% + \StrSubstitute{\minted@argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@argone@esc]% + \StrSubstitute{\minted@argone@esc}{"}{\@backslashchar"}[\minted@argone@esc]% + \edef\minted@tmpfname@esc{\minted@outputdir\minted@jobname}% + \StrSubstitute{\minted@tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@tmpfname@esc]% + \StrSubstitute{\minted@tmpfname@esc}{"}{\@backslashchar"}[\minted@tmpfname@esc]% + %Need a version of open() that supports encoding under Python 2 + \edef\minted@autogobblecmd{% + \ifminted@kpsewhich + \ifwindows + \detokenize{for /f "usebackq tokens=*" }\@percentchar\detokenize{a in (`kpsewhich} #1\detokenize{`) do}\space + \fi + \fi + \detokenize{python -c "import sys; import os; + import textwrap; + from io import open; + fname = }% + \ifminted@kpsewhich + \detokenize{sys.argv[1];}\space% + \else + \detokenize{os.path.expanduser(os.path.expandvars(\"}\minted@argone@esc\detokenize{\"));}\space% + \fi + \detokenize{f = open(fname, \"r\", encoding=\"}\minted@encoding\detokenize{\") if os.path.isfile(fname) else None; + t = f.readlines() if f is not None else None; + t_opt = t if t is not None else []; + f.close() if f is not None else None; + tmpfname = os.path.expanduser(os.path.expandvars(\"}\minted@tmpfname@esc.pyg\detokenize{\")); + f = open(tmpfname, \"w\", encoding=\"}\minted@encoding\detokenize{\") if t is not None else None; + fvstartnum = }\ifx\FancyVerbStartNum\z@ 0\else\FancyVerbStartNum\fi\detokenize{; + fvstopnum = }\ifx\FancyVerbStopNum\z@ 0\else\FancyVerbStopNum\fi\detokenize{; + s = fvstartnum-1 if fvstartnum != 0 else 0; + e = fvstopnum if fvstopnum != 0 else len(t_opt); + [f.write(textwrap.dedent(\"\".join(x))) for x in (t_opt[0:s], t_opt[s:e], t_opt[e:]) if x and t is not None]; + f.close() if t is not None else os.remove(tmpfname);"}% + \ifminted@kpsewhich + \ifwindows + \space\@percentchar\detokenize{a}% + \else + \space\detokenize{`}kpsewhich #1\space\detokenize{||} #1\detokenize{`}% + \fi + \fi + }% + \ShellEscape{\minted@autogobblecmd}% +} +% \end{macrocode} +% \end{macro} +% +% % \begin{macro}{\minted@inputpyg} % For increased clarity, the actual |\input| process is separated out into its own macro. % @@ -3198,7 +3277,7 @@ \minted@configlang{#2}% \setkeys{minted@opt@cmd}{#1}% \minted@fvset - \begin{VerbatimOut}[codes={\catcode`\^^I=12}]{\minted@jobname.pyg}}% + \begin{VerbatimOut}[codes={\catcode`\^^I=12},firstline,lastline]{\minted@jobname.pyg}}% {\end{VerbatimOut}% \minted@langlinenoson \minted@pygmentize{\minted@lang}% @@ -3342,13 +3421,13 @@ % \begin{macrocode} \ifthenelse{\boolean{minted@newfloat}}% {\@ifundefined{minted@float@within}% - {\DeclareFloatingEnvironment[fileext=lol,placement=h]{listing}}% + {\DeclareFloatingEnvironment[fileext=lol,placement=tbp]{listing}}% {\def\minted@tmp#1{% - \DeclareFloatingEnvironment[fileext=lol,placement=h, within=#1]{listing}}% + \DeclareFloatingEnvironment[fileext=lol,placement=tbp, within=#1]{listing}}% \expandafter\minted@tmp\expandafter{\minted@float@within}}}% {\@ifundefined{minted@float@within}% - {\newfloat{listing}{h}{lol}}% - {\newfloat{listing}{h}{lol}[\minted@float@within]}} + {\newfloat{listing}{tbp}{lol}}% + {\newfloat{listing}{tbp}{lol}[\minted@float@within]}} % \end{macrocode} % \end{environment} % |