The minted package:Highlighted source code in LATEX
Geoffrey M. Poore

gpoore@gmail.com
github.com/gpoore/minted
Originally created and maintained (2009–2013) byKonrad Rudolph
v3.0.0 from 2024/09/22
Abstract

minted provides syntax highlighting using the Pygments library. It also provides
options for customizing the highlighted source code output, including features
implemented in Python such as selecting snippets of code with regular expressions.

The original development of minted version 3 was funded by a TEX Development
Fund grant from the TEX Users Group in 2023.

LicenseLaTeX Project Public License (LPPL) version 1.3c.

1Contents
1 Introduction

4

2 Installation
2.1
Package manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2Manual installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Option 1 (recommended): Install latexminted within Python
2.2.1
installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.2
Option 2: Install latexminted within TEX installation . . . . . . .

44
5

3 Migrating from minted version 2

64 Basic usage
4.1
The latexminted Python executable and shell escape . . . . . . . . . .
4.2
A minimal complete example . . . . . . . . . . . . . . . . . . . . . . . . .
4.3
Formatting source code . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4Using different styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5
Supported languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7
7
8
9
10
10

5 Floating listings

10

6 Configuration
6.1
minted config file .latexminted_config . . . . . . . . . . . . . . . . .
6.2macOS compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12
12
14

7 Options
7.1
Package options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.2
Setting options for commands and environments . . . . . . . . . . . . .
7.3
Command and environment options . . . . . . . . . . . . . . . . . . . .

14
14
16
18

8 Defining shortcuts

31

9 FAQ and Troubleshooting

33

10 Acknowledgements

36

11 Implementation
11.1 Required packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.2 Exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.3 Python executable and minimum supported version . . . . . . . . . . .
11.4 Timestamp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.5 Jobname MD5 and derived file names . . . . . . . . . . . . . . . . . . . .
11.6 Package options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.6.1 Package option definitions . . . . . . . . . . . . . . . . . . . . . .
11.6.2 Package options that are no longer supported or deprecated . .
11.6.3 Package option processing . . . . . . . . . . . . . . . . . . . . . .
11.7 Util . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.7.1 Check whether a string matches the regex ^[0-9A-Za-z_-]+$
11.8 State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.9 Calling minted executable . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.10 Config detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

36
36
36
37
37
38
40
40
43
44
44
45
46
46
48

2

5
5

11.11 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.11.1 Option processing . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.11.2 Option handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.11.3 Option definitions . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.12 Caching, styles, and highlighting . . . . . . . . . . . . . . . . . . . . . . .
11.12.1 Cache management . . . . . . . . . . . . . . . . . . . . . . . . . .
11.12.2 Style definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.12.3 Lexer-specific line numbering . . . . . . . . . . . . . . . . . . . .
11.12.4 Highlighting code . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.13 Public API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.14 Command shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.15 Float support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

50
50
58
58
62
62
63
67
68
71
75
77

1 Introduction
minted provides syntax highlighting using the Pygments library. The general strategy is
to wrap code in a command or environment that captures it verbatim, like this:\begin{minted}{<language>}<code>\end{minted}
Then the code is passed to Python, highlighted with Pygments, and passed back to
LATEX for inclusion in the document. Here is an example with Ruby code, showing the
LATEX source and then the highlighted output:\begin{minted}{ruby}class Foodef initpi = Math::PI@var = "Pi = #{pi}..."
end
end\end{minted}

class Foodef initpi = Math::PI@var = "Pi = #{pi}..."
end
end

Because minted uses Pygments and other Python software, it can provide more
highlighting features than are practical in syntax highlighting packages like listings thatare implemented purely in LATEX. In the past, this reliance on external software brought
several disadvantages, including a requirement for separately installing Pygments. Asof minted version 3, all Python software including Pygments is bundled with the LATEX
package when it is installed with a TEX package manager, and no dependencies must be
installed separately.

2 Installation
2.1 Package manager
Installation will typically be simpler and faster using your TEX distribution’s package
manager. Start your package manager’s graphical user interface, or use the relevant
command below:• TeX Live: tlmgr install minted• MiKTeX: mpm --admin --install=minted
When the minted package is installed, it includes the latexminted Python executable
and all required Python libraries including Pygments. For these to function correctly,
Python 3.8+ must be installed and on PATH when the latexminted executable runs.
Note that if you plan to use Pygments plugin packages, you will need to install thelatexminted Python package and dependencies including Pygments within a Python
installation. The Python libraries installed by a TEX package manager within a TEX
installation are not compatible with plugin packages. After installing latexminted within
a Python installation, make sure that its latexminted executable has precedence on
PATH.
4The minted package has the LATEX package dependencies listed below. Dependingon your TEX distribution and configuration, these may be installed automatically whenminted is installed.
• catchfile• etoolbox• float• fvextra• latex2pydata• newfloat• pdftexcmds• pgfkeys• pgfopts• shellesc• xcolor

2.2 Manual installation
minted source files are available at github.com/gpoore/minted. There is also
ctan.org/pkg/minted.
Install minted.sty (and minted2.sty and minted1.sty if desired) within yourTEX installation. For TeX Live, it may be best to put style files under TEXMFLOCAL, which
can be located by running kpsewhich --var-value TEXMFLOCAL. For example, you
might put the files in <texlive>/<year>/texmf-local/tex/latex/local/minted.
For further details, consult your TEX distribution’s documentation, or an online
guide such as en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages or
texfaq.org. After installing the .sty files, make TEX aware of the new files by runningtexhash or mktexlsr (TeX Live), or initexmf --update-fndb (MiKTeX).
Next, install the Python side of the package. Python 3.8+ is required. There are two
options: Install the latexminted package and dependencies within a Python installation(typically easier, and required for compatibility with Pygments plugin packages), or
install them within your TEX installation.
Note that if you are only using the minted2 package for backward compatibility
with minted version 2, you do not need latexminted. minted2 only requires the Pygments package, which can be installed with something like pip install pygments,
conda install anaconda::pygments, or brew install pygments, depending on
your operating system and Python distribution. You may need to modify the command
depending on system versus user installation and depending on virtual environments.
2.2.1 Option 1 (recommended): Install latexminted within Python installation
If your Python distribution is compatible with The Python Package Index (PyPI), this canbe accomplished by running pip install latexminted. This will install latexminted
plus all dependencies including Pygments. You may need to modify the command
depending on whether you want a system or user (--user) installation, depending onwhether you are using virtual environments, and depending on whether something likepip3 is needed instead of pip.
If you cannot or do not wish to use PyPI via pip, install the following packages
manually or from other sources.
• latexminted: https://pypi.org/project/latexminted/• latexrestricted: https://pypi.org/project/latexrestricted/• latex2pydata: https://pypi.org/project/latex2pydata/• Pygments: https://pypi.org/project/Pygments/
2.2.2 Option 2: Install latexminted within TEX installation
This approach is more involved and essentially replicates the process that is performed
automatically when using a TEX package manager.
5Install the latexminted.py executable within your TEX installation. (It is part ofthe minted LATEX package, separate from the latexminted Python package.) This should
typically be within a scripts directory. When TeX Live installs minted with its package
manager, this is something like <texlive>/<year>/texmf-dist/scripts/minted.
Download Python wheels (*.whl) for the following Python packages, and placethem in the same location as latexminted.py.
• latexminted: https://pypi.org/project/latexminted/• latexrestricted: https://pypi.org/project/latexrestricted/• latex2pydata: https://pypi.org/project/latex2pydata/• Pygments: https://pypi.org/project/Pygments/
Under non-Windows operating systems, create a symlink called latexminted in the
TEX binary directory or another appropriate location that points to latexminted.py.
When TeX Live installs minted with its package manager, this is something like
<texlive>/<year>/bin/<architecture>.
Under Windows, a launcher executable for latexminted.py needs to be created. When TeX Live installs minted with its package manager, it creates a copy ofrunscript.exe named latexminted.exe within the TEX binary directory, which issomething like <texlive>/<year>/bin/windows.

3 Migrating from minted version 2
minted version 3 is a complete rewrite from version 2.9. A brief summary of changes isprovided below. For full details, see CHANGELOG_MINTED_LATEX_PACKAGE.md.
Backward compatibility
The new minted2 package provides the features of minted version 2.9, the final release
before version 3. No additional version 2 releases are planned; no changes to theminted2 package are expected.
New features and changes• Version 3 uses a new minted-specific Python executable called latexminted toperform syntax highlighting. This executable is specifically designed to meet the
security requirements for restricted shell escape programs. Once it has passed a
security review and is accepted by TEX distributions, it will be possible to highlightcode without -shell-escape and its attendant security vulnerabilities.
Syntax highlighting is still performed with Pygments, but the pygmentize executable included with Pygments is no longer used.
When minted is installed with a TEX package manager, the new latexminted
executable and all Python libraries including Pygments are installed within the
TEX installation. A separate step to install Pygments is no longer necessary.
• Temporary files are no longer created unless code needs to be highlighted. Thereis a new naming scheme for temporary files and for cache files.
• New package options: debug (additional debug info during compilation),
highlightmode (modify when code is highlighted for faster compilation),

6

placeholder (insert a placeholder instead of code), and verbatim (insert verbatim approximation of code).
• Renamed package options langlinenos to lexerlinenos and inputlanglinenos
to inputlexerlinenos. The old names are still supported.
• bgcolor now uses the new bgcolor option from fvextra v1.8. Because bgcolor
now introduces no additional whitespace or padding, existing documents may
require some modification. Added new option bgcolorpadding for modifying
padding in background color regions. Added new option bgcolorvphantom forsetting height of background color in inline contexts. When more sophisticatedbackground colors are needed, tcolorbox or a similar package should be used.
• The default cache directory name is now _minted. All files within a directory
now share the same cache, instead of having separate per-document caches.
Document-specific caching as in minted version 2 can be restored using the
package option cachedir.
• \newminted now creates an environment that takes an optional argument consisting of options, instead of taking no argument.
• File encoding changes: The new latexminted executable assumes that LATEX
output files are UTF-8, and saves highlighted code as UTF-8. That is, LaTeX should
be configured so that everything is UTF-8. The encoding option now defaults to
UTF-8. It is only used in decoding files for \inputminted and commands basedon it. The outencoding option is no longer supported.
• Added new options for including ranges of code based on literal string delimiters or regular expressions: rangestartstring, rangestartafterstring,
rangestopstring, rangestopbeforestring, rangeregex.
• There is now support for custom lexers in standalone Python files. See the documentation for the new .latexminted_config configuration files for details.
• Several package options are no longer supported and result in errors or warnings.
The package options finalizecache, outputdir, and kpsewhich are no longer
needed given new minted version 3 capabilities. The package options draft andfinal no longer have any effect and will soon be removed altogether. The new
package options placeholder and verbatim are available in cases where using
highlighted code should be completely avoided.

4 Basic usage
4.1 The latexminted Python executable and shell escapeThe minted package operates by passing code to the latexminted Python executable,
which performs syntax highlighting and then returns the highlighted code in LATEX
format.
Currently, latexminted requires special permission to run. LATEX must be calledwith the -shell-escape option (TeX Live) or the -enable-write18 option (MiKTeX).
Note that using -shell-escape or -enable-write18 allows LATEX to run potentially7

arbitrary commands on your system. These should only be used when necessary, with
documents from trusted sources.
latexminted is designed to be compatible with the security requirements for restricted shell escape. Once latexminted finishes the security review for restricted
shell escape executables, it will function automatically without -shell-escape or-enable-write18, so long as the default restricted shell escape has not been disabled.
It is possible to benefit from these enhanced security capabilities immediately andavoid the need for -shell-escape or -enable-write18 by manually designating
latexminted as a trusted executable.
• TeX Live: Copy the variable shell_escape_commands from the distribution
texmf.cnf (something like <texlive>/<yr>/texmf-dist/web2c/texmf.cnf)
into the user texmf.cnf (something like <texlive>/<yr>/texmf.cnf), andthen add latexminted to the shell_escape_commands list. The location of thetexmf.cnf files can be determined by running kpsewhich -all texmf.cnf.
Note that under Windows, this only works when latexminted is installed within
a TeX Live installation; it is not compatible with latexminted being installed ina Python installation.
• MiKTeX: Add a line AllowedShellCommands[] = latexminted to the existing
list of allowed commands in miktex.ini. You may want to modify the userscoped configuration instead of the system-wide configuration. See the MiKTeX
documentation for more details, particularly initexmf --edit-config-fileand initexmf --set-config-value.
For the latexminted Python executable to correctly inherit security settings fromLATEX, there are requirements for system configuration when multiple TEX installations
are present.
• With MiKTeX on systems with multiple MiKTeX installations, the desired MiKTeX
installation must be the first MiKTeX installation on PATH.
• With TeX Live on Windows systems with multiple TeX Live installations, thedesired TeX Live installation must be the first TeX Live installation on PATH.
See the latexrestricted documentation for details.

4.2 A minimal complete example
The following file minimal.tex shows the basic usage of minted.

\documentclass{article}\usepackage{minted}\usepackage[svgnames]{xcolor}\begin{document}\begin{minted}[bgcolor=Beige, bgcolorpadding=0.5em]{c}int main() {printf("hello, world");
return 0;}
8

\end{minted}\end{document}This document can be compiled by running “pdflatex -shell-escape minimal”
to produce the following output in minimal.pdf:

int main() {printf("hello, world");
return 0;}

4.3 Formatting source code
minted (env.) The minted environment highlights a block of code:\begin{minted}{python}def boring(args = None):pass\end{minted}

def boring(args = None):pass

The environment accepts a number of optional arguments in key=value notation.
These are described in section 7.2.
To use minted with a language that is not supported by Pygments, or simply todisable highlighting, set the language to text: \begin{minted}{text}.
\mint
For a single line of source code, you can use \mint as a shorthand for minted:\mint{python}/import this/import thisThis typesets a single line of code using a command rather than an environment, so
it saves a little typing, but its output is equivalent to that of the minted environment.
The code is delimited by a pair of identical characters, similar to how \verb works.
The complete syntax is \mint[〈options〉]{〈language〉}〈delim〉〈code〉〈delim〉, where
the code delimiter can be almost any punctuation character. The 〈code〉 may also bedelimited with paired curly braces {}, so long as 〈code〉 itself does not contain unpaired
curly braces.
Note that the \mint command is not for inline use. Rather, it is a shortcut forminted when only a single line of code is present. The \mintinline command isprovided for inline use.
\mintinline
Code can be typeset inline:

print("Hello!")\mintinline{py}{print("Hello!")}The syntax is \mintinline[〈options〉]{〈language〉}〈delim〉〈code〉〈delim〉. The delimiters can be a single repeated character, just like for \verb. They can also be a pairof curly braces, {}. Curly braces are required when \mintinline is used in a movable
argument, such as in a \section.
Unlike \verb, \mintinline can usually be used inside other commands. The main
exception is when the code contains the percent % or hash # characters, or unpaired
curly braces. For example, \mintinline typically works in \footnote and \section!

9Note that some document classes or packages, such as memoir, redefine \section or
have options that modify it in ways that are incompatible with \mintinline. If you
use \mintinline inside \section or otherwise in a movable argument, you should
experiment to make sure it is compatible with your document configuration. You may
also want to consider fvextra’s \Verb or \EscVerb as an alternative.
The code typesetting for \mintinline is based on fvextra’s \Verb. See the fvextra
documentation on \Verb for additional details about functionality and limitations.
\inputminted
Finally, there’s the \inputminted command to input external files. Its syntax is\inputminted[〈options〉]{〈language〉}{〈filename〉}.

4.4 Using different styles\usemintedstyle\setminted

Instead of using the default highlighting style you may choose another style provided
by Pygments. There are two equivalent ways to do this:\usemintedstyle{name}\setminted{style=name}The \setminted approach has the advantage that other minted options are accepted as well; \usemintedstyle is restricted to style modifications. The full syntax is\usemintedstyle[〈language〉]{〈style〉} and \setminted[〈language〉]{〈key=value〉}.
The style may be set for the document as a whole (no language specified), or only for aparticular language. Note that the style may also be set via the optional argument foreach command and environment.
Highlighting styles with examples are at pygments.org/styles. It is possible to preview your code with different styles using the online demo at pygments.org/demo.
Available styles can also be listed by running the command pygmentize -L styles.
It is also possible to create your own styles. See the instructions on the Pygments website. minted only supports style names that match the regular expression^[0-9A-Za-z_-]+$.

4.5 Supported languages
Pygments supports hundreds of different programming languages, template languages,
and other markup languages. The list of currently supported languages is at pygments.org/docs/lexers/. You can also run pygmentize -L lexers.

5 Floating listings
listing (env.) minted provides a listing environment that can be used to wrap code blocks. Thisputs the code in a floating box similar to a figure or table, with default placement tbp.
You can also provide a \caption and a \label:

10\begin{listing}[H]\mint{cl}/(car (cons 1 '(2)))/\caption{Example of a listing.}\label{lst:example}\end{listing}
Listing \ref{lst:example} contains an example of a listing.

(car (cons 1 '(2)))
Listing 1: Example of a listing.
Listing 1 contains an example of a listing.
The default listing placement can be modified easily. When the package option
newfloat=false (default), the float package is used to create the listing environment. Placement can be modified by redefining \fps@listing. For example,\makeatletter\renewcommand{\fps@listing}{htp}\makeatother

When newfloat=true, the more powerful newfloat package is used to create thelisting environment. In that case, newfloat commands are available to customize
listing:\SetupFloatingEnvironment{listing}{placement=htp}\listoflistings

The \listoflistings macro will insert a list of all (floated) listings in the document:

List of Listings\listoflistings
1

Example of a listing. . .

11

Customizing the listing environment
By default, the listing environment is created using the float package. In that case, the\listingscaption and \listoflistingscaption macros described below may be
used to customize the caption and list of listings. If minted is loaded with the newfloat
option, then the listing environment will be created with the more powerful newfloat
package instead. newfloat is part of caption, which provides many options for customizing captions.
When newfloat is used to create the listing environment, customization shouldbe achieved using newfloat’s \SetupFloatingEnvironment command. For example,
the string “Listing” in the caption could be changed to “Program code” using\SetupFloatingEnvironment{listing}{name=Program code}11And “List of Listings” could be changed to “List of Program Code” with
\SetupFloatingEnvironment{listing}{listname=List of Program Code}\listingscaption

Refer to the newfloat and caption documentation for additional information.
This allows the string “Listing” in a listing’s caption to be customized. It only applies
when package option newfloat=false. For example:\renewcommand{\listingscaption}{Program code}\listoflistingscaption

This allows the caption of the listings list, “List of Listings,” to be customized. It only
applies when package option newfloat=false. For example:\renewcommand{\listoflistingscaption}{List of Program Code}

6 Configuration
6.1 minted config file .latexminted_config
Several minted settings with security implications can be customized with a config
file .latexminted_config. This config file is loaded by the latexminted Python
executable when it runs.
The latexminted Python executable looks for .latexminted_config files in thefollowing locations:• User home directory, as found by Python’s pathlib.Path.home().
• TEXMFHOME. With MiKTeX on systems with multiple MiKTeX installations, this willbe the TEXMFHOME from the first MiKTeX installation on PATH. With TeX Live on
Windows systems with multiple TeX Live installations, this will be the TEXMFHOME
from the first TeX Live installation on PATH. In all other cases, TEXMFHOME will correspond to the currently active TEX installation. See the latexrestricted documentation for details. latexrestricted is used by the latexminted Python executableto retrieve the value of TEXMFHOME.
• The current TEX working directory. Note that enable_cwd_config must be
set true in the .latexminted_config in the user home directory or in the
TEXMFHOME directory to enable this; .latexminted_config in the current TEX
working directory is not enabled by default for security reasons. Even when aconfig file in the current TEX working directory is enabled, it cannot be used tomodify certain security-related settings.
Overall configuration is derived by merging all config files, with later files in the list
above having precedence over earlier files. Boolean and string values are overwritten bylater config files. Collection values (currently only sets derived from lists) are mergedwith earlier values.
The .latexminted_config file may be in Python literal format (dicts and lists ofstrings and bools), JSON, or TOML (requires Python 3.11+). It must be encoded as
UTF-8.

12

Config settingssecurity: dict[str, str | bool] These settings relate to latexminted security.
They can only be set in .latexminted_config in the user home directory orin TEXMFHOME. They cannot be set in .latexminted_config in the current TEX
working directory.

enable_cwd_config: bool = False Load a .latexminted_config file fromthe current TEX working directory if it exists. This is disabled by default because the config file can enable custom_lexers, which is equivalent toarbitrary code execution.

file_path_analysis: "resolve" | "string" = "resolve" This specifies
how latexminted determines whether files are readable and writable. Relative file paths are always treated as being relative to the current TEX working
directory.
With resolve, any symlinks in file paths are resolved with the file systembefore paths are compared with permitted LATEX read/write locations. Arbitrary relative paths including “..” are allowed so long as the final location ispermitted.
With string, paths are analyzed as strings in comparing them with permitted LATEX read/write locations. This follows the approach taken in TEX’s filesystem security. Paths cannot contain “..” to access a parent directory, even
if the parent directory is a valid location. Because symlinks are not resolved
with the file system, it is possible to access locations outside permitted
LATEX read/write locations, if the permitted locations contain symlinks toelsewhere.

permitted_pathext_file_extensions: list[str] As a security measure
under Windows, LATEX cannot write files with file extensions in PATHEXT,
such as .bat and .exe. This setting allows latexminted to write files
with the specified file extensions, overriding LATEX security. File extensions
should be in the form “.<ext>”, for example, “.bat”. This setting is used in
extracting source code from LATEX documents and saving it in standalone
source files.
When these file extensions are enabled for writing, as a security measurelatexminted will only allow them to be created in subdirectories of the current TEX working directory, TEXMFOUTPUT, and TEXMF_OUTPUT_DIRECTORY.
These files cannot be created directly under the TEX working directory,
TEXMFOUTPUT, and TEXMF_OUTPUT_DIRECTORY because those locations are
more likely to be used as a working directory in a shell, and thus writing
executable files in those locations would increase the risk of accidental code
execution.

custom_lexers: dict[str, str | list[str]] This is a mapping of custom lexer
file names to SHA256 hashes. Only custom lexers with these file names andthe corresponding hashes are permitted. Lists of hashes are allowed to permit
multiple versions of a lexer with a given file name. All other custom lexers are prohibited, because loading custom lexers is equivalent to arbitrary code execution.
For example:"custom_lexers": {13}"mylexer.py": "<sha256>"

By default, it is assumed that custom lexer files implement a class CustomLexer.
This can be modified by including the lexer class name with the file name, separated by a colon, when the lexer is used. For example:\inputminted{./<path>/mylexer.py:LexerClass}{<file>}

Note that custom_lexers only applies to custom lexers in standalone Python
files. Lexers that are installed within Python as plugin packages work automatically with Pygments and do not need to be enabled separately. However, in thatcase it is necessary to install latexminted and Pygments within a Python installation. When TEX package managers install latexminted and Pygments within a TEX
installation, these are not compatible with Pygments plugin packages.

6.2 macOS compatibility
If you are using minted with some versions/configurations of macOS, and are using
caching with a large number of code blocks (> 256), you may receive a Python error
during syntax highlighting that looks like this:OSError: [Errno 24] Too many open files:
This is due to the way files are handled by the operating system, combined with theway that caching works. To resolve this, you may use one of the following commands toincrease the number of files that may be used:• launchctl limit maxfiles• ulimit -n

7 Options
7.1 Package options
chapter To control how LATEX counts the listing floats, you can pass either the chapter or
section option when loading the minted package. For example, the following willcause listings to be counted by chapter:\usepackage[chapter]{minted}
cache=〈boolean 〉minted works by saving code to a temporary file, highlighting it with Pygments, and(default: true) then passing the result back to LATEX for inclusion in the document. This process canbecome quite slow if there are several chunks of code to highlight. To avoid this, thepackage provides a cache option. This is on by default.
The cache option creates a directory _minted in the document’s root directory (thismay be customized with the cachedir option). Files of highlighted code are stored
in this directory, so that the code will not have to be highlighted again in the future.
Cache files that are no longer used are automatically deleted. In most cases, caching
will significantly speed up document compilation.

14

cachedir=〈directory 〉This allows the directory in which cache files are stored to be customized. Paths(default: _minted) should use forward slashes, even under Windows. Special characters must be escapedwith \string or \detokenize.
Note that the cache directory is relative to -output-directory or equivalently the
TEXMF_OUTPUT_DIRECTORY environment variable, if that is set.
debug=〈boolean 〉Provide additional information for aid in debugging. This keeps temp files that are(default: false) used in generating highlighted code and also writes additional information to the log.
frozencache=〈boolean 〉Use a frozen (static) cache. When frozencache=true, Python and Pygments are(default: false) not required, and any external files accessed through \inputminted are no longer
necessary. If a cache file is missing, an error will be reported and there will be noattempt to generate the missing cache file.
When using frozencache with -output-directory, the cachedir package
option should be used to specify a full relative path to the cache (for example,
cachedir=./<output_directory>/_minted).
highlightmode=〈string 〉Determines when code is highlighted.
(default: fastfirst)
The default is fastfirst. If a cache for the document exists, then code is highlighted immediately. If a cache for the document does not exist, then typeset a placeholder instead of code and highlight all code at the end of the document. This will
require a second compile before code is typeset, but because all code is highlighted
at once, there is less overhead and the total time required can be significantly less for
documents that include many code snippets.
The alternatives are fast (always highlight at end of document, requiring a second compile) and immediate (always highlight immediately, so no second compile isneeded). immediate should be used when typesetting code in external temp files thatare overwritten during compilation.
When code is highlighted at the end of the document with fast or fastfirst, anyerror and warning messages will refer to a location at the end of the document rather
than the original code location, since highlighting occurred at the end of the document.
In this case, messages are supplemented with original LATEX source file names and line
numbers to aid in debugging.
inputlexerlinenos=〈boolean 〉This enables lexerlinenos and causes it to apply to \inputminted (and custom(default: false) commands based on it) in addition to minted environments and \mint commands(and custom environments/commands based on them).
The regular lexerlinenos option treats all code within a document’s .tex files as
having one set of line numbering per language, and then treats each inputted source
file as having its own separate numbering. inputlexerlinenos defines a single numbering per lexer, regardless of where code originates.
lexerlinenos=〈boolean 〉This allows all minted environments and \mint commands (and custom environ(default: false) ments/commands based on them) for a given lexer (language) to share line numbering
when firstnumber=last, so that each subsequent command/environment has line
numbering that continues from the previous one. This does not apply to \inputminted(and custom commands based on it); see the package option inputlexerlinenos forthat.
minted uses the fancyvrb package behind the scenes for the code typesetting. 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 thatallows line numbering to pick up where it left off. The lexerlinenos option makes
firstnumber work for each lexer (language) individually with all minted and \mintusages. For example, consider the code and output below.

15\begin{minted}[linenos]{python}def f(x):return x**2
\end{minted}\begin{minted}[linenos]{ruby}def func
puts "message"
end\end{minted}\begin{minted}[linenos, firstnumber=last]{python}def g(x):return 2*x\end{minted}

1
2

def f(x):return x**2

def func
puts "message"
3 end
1
2

3
4

def g(x):return 2*x

Without the lexerlinenos option, the line numbering in the second Python environment would not pick up where the first Python environment left off. Rather, it would
pick up with the Ruby line numbering.
newfloat=〈boolean 〉By default, the listing environment is created using the float package. The(default: false) newfloat option creates the environment using newfloat instead. This provides better
integration with the caption package.
placeholder=〈boolean 〉Instead of typesetting code, insert a placeholder. This is enabled automatically when
(default: false) working with PGF/TikZ externalization.
sectionTo control how LATEX counts the listing floats, you can pass either the section or
chapter option when loading the minted package.
verbatim=〈boolean 〉Instead of highlighting code, attempt to typeset it verbatim without using the(default: false) latexminted Python executable. This is not guaranteed to be an accurate representation of the code, since some features such as autogobble require Python.

7.2 Setting options for commands and environments
All minted highlighting commands and environment accept the same set of options.
Options are specified as a comma-separated list of key=value pairs. For example, we
can specify that the lines should be numbered:16\begin{minted}[linenos=true]{c++}#include <iostream>
int main() {std::cout << "Hello "<< "world"<< std::endl;}\end{minted}# include <iostream>
int main() {3
std::cout << "Hello "4<< "world"
5<< std::endl;
6 }1
2

An option value of true may also be omitted entirely (including the “=”).
\mint accepts the same options:\mint[linenos]{perl}|$x=~/foo/|

1$x=~/foo/

Here’s another example: we want to use the LATEX math mode inside comments:\begin{minted}[mathescape]{py}# Returns $\sum_{i=1}^{n}i$def sum_from_one_to(n):r = range(1, n + 1)
return sum(r)\end{minted}# Returns ni=1 i
def sum_from_one_to(n):r = range(1, n + 1)
return sum(r)PTo make your LATEX code more readable you might want to indent the code insidea minted environment. The option gobble removes a specified number of charactersfrom the output. There is also an autogobble option that automatically removes
indentation (dedents code).

\begin{minted}[showspaces]{py}def boring(args = None):pass\end{minted}

def boring(args = None):pass

versusversusdef boring(args = None):pass\begin{minted}[gobble=4,
showspaces]{py}def boring(args = None):pass\end{minted}\setminted

You may wish to set options for the document as a whole, or for an entire lexer(language). This is possible via \setminted[〈lexer〉]{〈key=value,...〉}. Lexer-specificoptions override document-wide options. Individual command and environment
options override lexer-specific options.
\setmintedinline
You may wish to set separate options for \mintinline, either for the document as
a whole or for a specific lexer (language). This is possible via \setmintedinline. The
syntax is \setmintedinline[〈lexer〉]{〈key=value,...〉}. Lexer-specific options override
document-wide options. Individual command options override lexer-specific options.
All settings specified with \setmintedinline override those set with \setminted.

17

That is, inline settings always have a higher precedence than general settings.

7.3 Command and environment options
Following is a full list of available options. Several options are simply passed on to
Pygments, fancyvrb, and fvextra for processing. In those cases, more details may be in
the documentation for those software packages.
autogobble(default: false)
Remove (gobble) all common leading whitespace from code. Essentially a version of
gobble that automatically determines what should be removed. Good for code thatoriginally is not indented, but is manually indented after being pasted into a LATEX
document.

(boolean)...text.
\begin{minted}[autogobble]{py}def f(x):return x**2
\end{minted}...text.

def f(x):return x**2

When autogobble and gobble are used together, the effect is cumulative. First
autogobble removes all common indentation, and then gobble is applied.
autogobble and gobble operate on code before the highlighting process begins(before lexing), treating the code purely as text. Meanwhile, gobblefilter operates on
the token stream generated by a lexer. If the removed characters are simply indentation
coming from how the code was entered within LATEX, then autogobble and gobble
should typically be preferred. If the removed characters are syntactically significant,then gobblefilter may be better. Which approach is preferable may also depend on
the implementation details of the lexer.
baselinestretch(dimension)(default: 〈document default 〉)Value to use for baselinestretch inside the listing.
beameroverlays(boolean)(default: false)
Give the < and > characters their normal text meanings when used with escapeinside
and texcomments, so that beamer overlays of the form \only<1>{...} will work.

bgcolor(string)(default: none)
Background color behind commands and environments. This is only a basic, lightweight
implementation of background colors using \colorbox. For more control of background colors, consider tcolorbox or a similar package, or a custom background color
implementation.
bgcolor prevents line breaks for \mintinline. If you want to use \setminted
to set background colors, and only want background colors on minted and \mint,
you may use \setmintedinline{bgcolor=none} to turn off the coloring for inline
commands.
The value of this option must not be a color command. Instead, it must be a color
name, given as a string, of a previously-defined color:18\definecolor{bg}{rgb}{.9, .9, .9}\begin{minted}[bgcolor=bg]{php}<?phpecho "Hello, $x";?>\end{minted}<?php
echo "Hello, $x";?>

As an alternative to bgcolor, tcolorbox provides a built-in framing environment
with minted support. Simply use \tcbuselibrary{minted} in the preamble, and thenput code within a tcblisting environment:\begin{tcblisting}{<tcb options>,
minted language=<language>,minted style=<style>,
minted options={<option list>} }<code>\end{tcblisting}tcolorbox provides other commands and environments for fine-tuning listing appearance and for working with external code files.
(default: none)
Padding when bgcolor is set. For inline commands and for environments based on
BVerbatim, this sets \fboxsep for the \colorbox that is used to create the backgroundcolor. For environments based on Verbatim, fancyvrb’s frame options are used instead,particularly framesep and fillcolor. See the fvextra documentation for implementation details.

bgcolorpadding(length)bgcolorvphantom(macro)(default: \vphantom{\"Apgjy})\vphantom or similar macro such as \strut that is inserted at the beginning of eachline of code using bgcolor. This allows the height of the background for each lineof code to be customized. This is primarily useful for customizing the backgroundfor \mintinline and other inline code. It will typically have no effect on minted
environments and other block code unless it is set to a size larger than \strut.

breakafter(string)(default: 〈none 〉)Break lines after specified characters, not just at spaces, when breaklines=true.
For example, breakafter=-/ would allow breaks after any hyphens or slashes.
Special characters given to breakafter should be backslash-escaped (usually #, {, }, %,[, ]; the backslash \ may be obtained via \\).
For an alternative, see breakbefore. When breakbefore and breakafter areused for the same character, breakbeforeinrun and breakafterinrun must bothhave the same setting.

\begin{minted}[breaklines, breakafter=d]{python}
some_string = 'SomeTextThatGoesOnAndOnForSoLongThatItCouldNeverFitOnOneLine'\end{minted}

some_string = 'SomeTextThatGoesOnAndOnForSoLongThatItCould ⌋,→NeverFitOnOneLine'19

breakafterinrun (boolean)(default: true)
When breakafter is used, group all adjacent identical characters together, and only
allow a break after the last character. When breakbefore and breakafter are used forthe same character, breakbeforeinrun and breakafterinrun must both have thesame setting.
breakaftersymbolpost
breakaftersymbolpre
breakanywhere(string)
The symbol inserted post-break for breaks inserted by breakafter.

(default: 〈none 〉)(string)(default: \,\footnotesize\ensuremath{_\rfloor},
The symbol inserted pre-break for breaks inserted by breakafter.
(boolean)
Break lines anywhere, not just at spaces, when breaklines=true.

⌋)(default: false)\begin{minted}[breaklines, breakanywhere]{python}
some_string = 'SomeTextThatGoesOnAndOnForSoLongThatItCouldNeverFitOnOneLine'\end{minted}

some_string = 'SomeTextThatGoesOnAndOnForSoLongThatItCouldNever ⌋,→FitOnOneLine'
breakanywhereinlinestretch (length)(default: 〈none 〉)Stretch glue to insert at potential breakanywhere break locations in inline contexts, togive better line widths and avoid overfull \hbox. This allows the spacing between adjacent non-space characters to stretch, so it should not be used when column alignmentis important. For typical line lengths, values between 0.01em and 0.02em should be
sufficient to provide a cumulative stretch per line that is equal to or greater than thewidth of one character.
This is typically not needed in cases where an overfull \hbox only overflows bytiny amount, perhaps a fraction of a pt. In those cases, the overfull \hbox could be
ignored, \hfuzz could be set to 1pt or 2pt to suppress tiny overfull \hbox warnings, or
breakanywheresymbolpre might be redefined to adjust spacing.
breakanywheresymbolpost(string)(default: 〈none 〉)The symbol inserted post-break for breaks inserted by breakanywhere.

breakanywheresymbolpre(string)(default: \,\footnotesize\ensuremath{_\rfloor},
The symbol inserted pre-break for breaks inserted by breakanywhere.

breakautoindent

breakbefore⌋)(boolean)(default: true)
When a line is broken, automatically indent the continuation lines to the indentationlevel of the first line. When breakautoindent and breakindent are used together, theindentations add. This indentation is combined with breaksymbolindentleft to givethe total actual left indentation. Does not apply to \mintinline.
(string)(default: 〈none 〉)Break lines before specified characters, not just at spaces, when breaklines=true.
For example, breakbefore=A would allow breaks before capital A’s. Special characters given to breakbefore should be backslash-escaped (usually #, {, }, %, [, ]; the20

backslash \ may be obtained via \\).
For an alternative, see breakafter. When breakbefore and breakafter are used
for the same character, breakbeforeinrun and breakafterinrun must both havethe same setting.

\begin{minted}[breaklines, breakbefore=A]{python}
some_string = 'SomeTextThatGoesOnAndOnForSoLongThatItCouldNeverFitOnOneLine'\end{minted}

some_string = 'SomeTextThatGoesOn ⌋,→AndOnForSoLongThatItCouldNeverFitOnOneLine'
breakbeforeinrun (boolean)(default: true)
When breakbefore is used, group all adjacent identical characters together, and only
allow a break before the first character. When breakbefore and breakafter are used
for the same character, breakbeforeinrun and breakafterinrun must both havethe same setting.
breakbeforesymbolpost(string)(default: 〈none 〉)The symbol inserted post-break for breaks inserted by breakbefore.

breakbeforesymbolpre(string)(default: \,\footnotesize\ensuremath{_\rfloor},
The symbol inserted pre-break for breaks inserted by breakbefore.

⌋)

breakbytoken(boolean)(default: false)
Only break lines at locations that are not within tokens; prevent tokens from being split
by line breaks. By default, breaklines causes line breaking at the space nearest themargin. While this minimizes the number of line breaks that are necessary, it can beinconvenient if a break occurs in the middle of a string or similar token.
This does not allow line breaks between immediately adjacent tokens; for that, see
breakbytokenanywhere.
A complete list of Pygments tokens is available at pygments.org/docs/tokens. If the
breaks provided by breakbytoken occur in unexpected locations, it may indicate a bug
or shortcoming in the Pygments lexer for the language.

breakbytokenanywhere(boolean)(default: false)
Like breakbytoken, but also allows line breaks between immediately adjacent tokens,
not just between tokens that are separated by spaces. Using breakbytokenanywherewith breakanywhere is redundant.

breakindent(dimension)(default: 〈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 \mintinline.

breakindentnchars(integer)(default: 0)
This allows breakindent to be specified as an integer number of characters rather thanas a dimension (assumes a fixed-width font).
21

breaklines(boolean)(default: false)
Automatically break long lines in minted environments and \mint commands, andwrap longer lines in \mintinline.
By default, automatic breaks occur at space characters. Use breakanywhere to enable breaking anywhere; use breakbytoken, breakbytokenanywhere, breakbefore,
and breakafter for more fine-tuned breaking. Using escapeinside to escape to LATEX
and then insert a manual break is also an option. For example, use escapeinside=||,and then insert |\\| at the appropriate point. (Note that escapeinside does not workwithin strings.)...text.
\begin{minted}[breaklines]{py}def f(x):return 'Some text ' + str(x)\end{minted}...text.

def f(x):return 'Some text ' +,→str(x)Breaking in minted and \mint may be customized in several ways. To customize
the indentation of broken lines, see breakindent and breakautoindent. To customize the line continuation symbols, use breaksymbolleft and breaksymbolright.
To customize the separation between the continuation symbols and the code, use
breaksymbolsepleft and breaksymbolsepright. To customize the extra indentation that is supplied to make room for the break symbols, use breaksymbolindentleft
and breaksymbolindentright. Since only the left-hand symbol is used by default,
it may also be modified using the alias options breaksymbol, breaksymbolsep, andbreaksymbolindent. Note than none of these options applies to \mintinline, since
they are not relevant in the inline context.
An example using these options to customize the minted environment is shown
below. This uses the \carriagereturn symbol from the dingbat package.

\begin{minted}[breaklines,
breakautoindent=false,
breaksymbolleft=\raisebox{0.8ex}{\small\reflectbox{\carriagereturn}},breaksymbolindentleft=0pt,
breaksymbolsepleft=0pt,
breaksymbolright=\small\carriagereturn,breaksymbolindentright=0pt,
breaksymbolsepright=0pt]{python}def f(x):return 'Some text ' + str(x) + ' some more text ' +,→str(x) + ' even more text that goes on for a while'\end{minted}

def f(x):return 'Some text ' + str(x) + ' some more text ' +str(x) + ' even more text that goes on for a while'CC

Automatic line breaks are limited with Pygments styles that use a colored back-22

ground behind large chunks of text. This coloring is accomplished with \colorbox,
which cannot break across lines. It may be possible to create an alternative to\colorbox that supports line breaks, perhaps with TikZ, but the author is unaware of asatisfactory solution. The only current alternative is to redefine \colorbox so that it
does nothing. For example,\AtBeginEnvironment{minted}{\renewcommand{\colorbox}[3][]{#3}}uses the etoolbox package to redefine \colorbox within all minted environments.
breaksymbol
breaksymbolindent(default: breaksymbolleft)(string)
Alias for breaksymbolleft.

(dimension)
Alias for breaksymbolindentleft.

(default: 〈breaksymbolindentleftnchars 〉)breaksymbolindentnchars(integer)(default: 〈breaksymbolindentleftnchars 〉)Alias for breaksymbolindentleftnchars.

breaksymbolindentleft(dimension)(default: 〈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 \mintinline.

breaksymbolindentleftnchars (integer)(default: 4)
This allows breaksymbolindentleft to be specified as an integer number of characters rather than as a dimension (assumes a fixed-width font).
breaksymbolindentright(dimension)(default: 〈breaksymbolindentrightnchars 〉)The extra right indentation that is provided to make room for breaksymbolright. This
indentation is only applied when there is a breaksymbolright.

breaksymbolindentrightnchars(integer)(default: 4)
This allows breaksymbolindentright to be specified as an integer number of characters rather than as a dimension (assumes a fixed-width font).
breaksymbolleft(string)(default: \tiny\ensuremath{\hookrightarrow}, ,→)The symbol used at the beginning (left) of continuation lines when breaklines=true.
To have no symbol, simply set breaksymbolleft to an empty string (“=,” or “={}”).
The symbol is wrapped within curly braces {} when used, so there is no danger offormatting commands such as \tiny “escaping.”
The \hookrightarrow and \hookleftarrow may be further customized by theuse of the \rotatebox command provided by graphicx. Additional arrow-type symbols
that may be useful are available in the dingbat (\carriagereturn) and mnsymbol(hook and curve arrows) packages, among others.
Does not apply to \mintinline.

breaksymbolright(string)(default: 〈none 〉)The symbol used at breaks (right) when breaklines=true. Does not appear at the endof the very last segment of a broken line.

breaksymbolsep
breaksymbolsepnchars(dimension)
Alias for breaksymbolsepleft.

(integer)(default: 〈breaksymbolsepleftnchars 〉)(default: 〈breaksymbolsepleftnchars 〉)23

Alias for breaksymbolsepleftnchars.
breaksymbolsepleft(dimension)(default: 〈breaksymbolsepleftnchars 〉)The separation between the breaksymbolleft and the adjacent text.

breaksymbolsepleftnchars(integer)(default: 2)
Allows breaksymbolsepleft to be specified as an integer number of characters rather
than as a dimension (assumes a fixed-width font).

breaksymbolsepright(dimension)(default: 〈breaksymbolseprightnchars 〉)The minimum separation between the breaksymbolright and the adjacent text. Thisis 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 thanbreaksymbolsepright. This ensures that break symbols have the same spacing fromthe margins on both left and right. If the same spacing from text is desired instead,breaksymbolsepright may be adjusted. (See the definition of \FV@makeLineNumberin fvextra for implementation details.)

breaksymbolseprightnchars(integer)(default: 2)
Allows breaksymbolsepright to be specified as an integer number of characters rather
than as a dimension (assumes a fixed-width font).

codetagify(default: XXX,TODO,FIXME,BUG,NOTE)
Highlight special code tags in comments and docstrings.
The value must be a list of strings, either comma-delimited or space-delimited.
The value must be a single macro that gives the desired text when fully expanded, or astring that is interpreted literally except that backslash escapes of ASCII punctuation
characters are allowed to give the literal characters (“\\” for backslash, “\#” for “#”, andso on).

curlyquotes(boolean)(single macro or backslash-escaped string)(default: false)
By default, the backtick ` and typewriter single quotation mark ' always appear literally, instead of becoming the left and right curly single quotation marks ‘’. This
option allows these characters to be replaced by the curly quotation marks when that isdesirable.
(default: UTF-8)
File encoding used by \inputminted and derived commands when reading files.

encoding(string)

envname(string)(default: Verbatim, or VerbEnv for inline)
This is the name of the environment that wraps typeset code. By default, it is
Verbatim in block contexts and VerbEnv in inline contexts (\setminted versus\setmintedinline). This is compatible with fancyvrb’s BVerbatim.
There are two requirements for using a custom environment other than Verbatim
and BVerbatim in block contexts:• For minted and \mint support, the custom environment must be created with
fancyvrb’s \DefineVerbatimEnvironment or otherwise defined in a mannercompatible with fancyvrb’s environment implementation conventions.
• For \inputminted support, a corresponding \〈envname〉Insert commandmust be defined, using fancyvrb’s \CustomVerbatimCommand or otherwise following fancyvrb command conventions. For example, using a custom variant of24

BVerbatim involves creating both a custom environment as well as a corresponding variant of \BVerbatimInput.
There is currently only limited support for using an environment other than

VerbEnv in inline contexts. If an environment other than VerbEnv is specified, it
will be used for highlighted code, but will not be used if code is typeset verbatim insteador if highlighting fails and a verbatim fallback is needed. In both of those cases, \Verbis currently used.
Note that envname is the name of the environment that wraps typeset code, but it
is not the name of the environment that literally appears in highlighted code output.
Highlighted code output uses the MintedVerbatim environment by default, and thenMintedVerbatim is redefined based on envname. This allows a single cache file tobe used in multiple contexts. The name of the environment that literally appears inhighlighted code output can be modified with literalenvname, but there should be
few if any situations where that is actually necessary.
escapeinside(single macro or backslash-escaped two-character string)(default: 〈none 〉)Escape to LATEX between the two characters specified. All code between the two characters will be interpreted as LATEX and typeset accordingly. This allows for additional
formatting. The escape characters need not be identical.
The value must be a single macro that gives the desired text when fully expanded, ora string that is interpreted literally except that backslash escapes of ASCII punctuation
characters are allowed to give the literal characters (“\\” for backslash, “\#” for “#”,and so on). Special LATEX characters must be escaped when they are used as the escapecharacters (for example, escapeinside=\#\%).
Escaping does not work inside strings and comments (for comments, there is
texcomments). Escaping is “fragile” with some lexers. Due to the way that Pygments
implements escapeinside, any “escaped” LATEX code that resembles a string or comment for the current lexer may break escapeinside. There is a Pygments issue for thiscase. Additional details and a limited workaround for some scenarios are available on
the minted GitHub site.

\setminted{escapeinside=||}\begin{minted}{py}def f(x):y = x|\colorbox{green}{**}|2
return y\end{minted}

def f(x):y = x ** 2return y

Note that when math is used inside escapes, any active characters beyond thosethat are normally active in verbatim can cause problems. Any package that relies on
special active characters in math mode (for example, icomma) will produce errors along
the lines of “TeX capacity exceeded” and “\leavevmode\kern\z@”. This may be
fixed by modifying \@noligs, as described at https://tex.stackexchange.com/
questions/223876.
firstline

firstnumber(integer)(default: 1)
The first line to be shown. All lines before that line are ignored and do not appear in the
output.
(default: auto = 1)

(auto | last | integer)Line number of the first line.
25

fontencoding
fontfamily
fontseries(font encoding)(default: 〈doc encoding 〉)Set font encoding used for typesetting code. For example, fontencoding=T1.
(family name)
The font family to use. tt, courier and helvetica are pre-defined.

(series name)(default: tt)(default: auto – the same as the current font)

The font series to use.
fontshape(font shape)(default: auto – the same as the current font)

The font shape to use.
fontsize
formatcom(font size)(default: auto – the same as the current font)
The size of the font to use, as a size command, e.g. \footnotesize.
(command)(default: 〈none 〉)A format to execute before printing verbatim text.
frame

framerule(none | leftline | topline | bottomline | lines | single)(default: none)
The type of frame to put around the source code listing. For more sophisticated framing,
consider tcolorbox.
(default: 0.4pt)(dimension)
Width of the frame.

framesep(default: \fboxsep)(dimension)
Distance between frame and content.

funcnamehighlighting(boolean)[For PHP only] If true, highlights built-in function names.

(default: true)

gobble(default: 0)
Remove the first n characters from each input line.
When autogobble and gobble are used together, the effect is cumulative. First
autogobble removes all common indentation, and then gobble is applied.
autogobble and gobble operate on code before the highlighting process begins(before lexing), treating the code purely as text. Meanwhile, gobblefilter operates on
the token stream generated by a lexer. If the removed characters are simply indentation
coming from how the code was entered within LATEX, then autogobble and gobble
should typically be preferred. If the removed characters are syntactically significant,then gobblefilter may be better. Which approach is preferable may also depend on
the implementation details of the lexer.

gobblefilter(integer)(default: 0)
Remove the first n characters from each input line, using the Pygments gobble filter.
autogobble and gobble operate on code before the highlighting process begins(before lexing), treating the code purely as text. Meanwhile, gobblefilter operates on
the token stream generated by a lexer. If the removed characters are simply indentation
coming from how the code was entered within LATEX, then autogobble and gobble
should typically be preferred. If the removed characters are syntactically significant,then gobblefilter may be better. Which approach is preferable may also depend on
the implementation details of the lexer.

highlightcolor(integer)(default: LightCyan)(string)26

Set the color used for highlightlines, using a predefined color name from color or
xcolor, or a color defined via \definecolor.
highlightlines(string)(default: 〈none 〉)This highlights a single line or a range of lines based on line numbers. For example,
highlightlines={1, 3-4}. The line numbers refer to the line numbers that would
appear if linenos=true, etc. They do not refer to original or actual line numbers before
adjustment by firstnumber.
The highlighting color can be customized with highlightcolor.

ignorelexererrors(boolean)(default: false)
When lexer errors are shown in highlighted output (default), they are typically displayed
as red boxes that surround the relevant text. When lexer errors are ignored, the literaltext that caused lexer errors is shown but there is no indication that it caused errors.
\begin{minted}{python}variable = !!!
\end{minted}

variable = !!!

\begin{minted}[ignorelexererrors=true]{python}variable = !!!
\end{minted}

variable = !!!
keywordcase(default: none)(lower | upper | capitalize | none)
Changes capitalization of keywords.

label(string)(default: empty )Add a label to the top, the bottom or both of the frames around the code. See the
fancyvrb documentation for more information and examples. Note: This does not add a\label to the current listing. To achieve that, use a floating environment (section 5)
instead.

labelposition(none | topline | bottomline | all)(default: topline, all, or none)
Location for the label. Default: topline if one label is defined, all if two are defined,
none otherwise. See the fancyvrb documentation for more information.

lastline(integer)(default: 〈last line of input 〉)The last line to be shown.
linenos(boolean)(default: false)
Enables line numbers. In order to customize the display style of line numbers, you needto redefine the \theFancyVerbLine macro:27

\renewcommand{\theFancyVerbLine}{\sffamily\textcolor[rgb]{0.5,0.5,1.0}{\scriptsize\oldstylenums{\arabic{FancyVerbLine}}}}def all(iterable):for i in iterable:
13
if not i:14
return False
15
return True
11
12\begin{minted}[linenos,
firstnumber=11]{python}def all(iterable):for i in iterable:
if not i:return False
return True\end{minted}
listparameters(macro)(default: 〈empty 〉)fancyvrb option for setting list-related lengths to modify spacing around lines of code.
For example, listparameters=\setlength{\topsep}{0pt} will remove space before and after a minted environment.

literalenvname(string)(default: MintedVerbatim)
This is the name of the environment that literally appears in highlighted code output asa wrapper around the code. It is redefined to be equivalent to envname. There should be
few if any situations where modifying literalenvname rather than envname is actuallynecessary.

literatecomment(single macro or backslash-escaped string)(default: 〈none 〉)This is for compatibility with literate programming formats, such as the .dtx format commonly used for writing LATEX packages. If all lines of code begin with〈literatecomment〉, then 〈literatecomment〉 is removed from the beginning of all lines.
For example, for .dtx, literatecomment=\%.
The value must be a single macro that gives the desired text when fully expanded, ora string that is interpreted literally except that backslash escapes of ASCII punctuation
characters are allowed to give the literal characters (“\\” for backslash, “\#” for “#”, andso on).
(default: false)
Enable LATEX math mode inside comments. Usage as in package listings. See the note
under escapeinside regarding math and ligatures.

mathescape(boolean)numberblanklines(boolean)(default: true)

Enables or disables numbering of blank lines.
numberfirstline
numbers

numbersep(boolean)
Always number the first line, regardless of stepnumber.

(default: false)(left | right | both | none)(default: none)
Essentially the same as linenos, except the side on which the numbers appear may be
specified.
(default: 12pt)(dimension)
Gap between numbers and start of line.
28

obeytabs(boolean)(default: false)
Treat tabs as tabs instead of converting them to spaces—that is, expand them to tab
stops determined by tabsize. While this will correctly expand tabs within leading
indentation, usually it will not correctly expand tabs that are preceded by anythingother than spaces or other tabs. It should be avoided in those case.

python3(boolean)(default: true)[For PythonConsoleLexer only] Specifies whether Python 3 highlighting is applied.

rangeregex

rangeregexmatchnumber

rangeregexdotall(single macro or backslash-escaped string)(default: 〈none 〉)Select code that matches this regular expression.
The value must be a single macro that gives the desired text when fully expanded, ora string that is interpreted literally except that backslash escapes of ASCII punctuation
characters are allowed to give the literal characters (“\\” for backslash, “\#” for “#”, andso on).
If line numbers are displayed, they are based on the range of code that is selected;
code that is discarded in selecting the range is not considered in calculating line numbers.
(default: 1)
If there are multiple non-overlapping matches for rangeregex, this determines which
is used.

(integer)(boolean)“.” matches any character including the newline.

(default: false)

rangeregexmultiline(boolean)(default: false)“^” and “$” match at internal newlines, not just at the start/end of the string.

rangestartafterstring(single macro or backslash-escaped string)(default: 〈none 〉)Select code starting immediately after this string.
The value must be a single macro that gives the desired text when fully expanded, ora string that is interpreted literally except that backslash escapes of ASCII punctuation
characters are allowed to give the literal characters (“\\” for backslash, “\#” for “#”, andso on).
If line numbers are displayed, they are based on the range of code that is selected;
code that is discarded in selecting the range is not considered in calculating line numbers.

rangestartstring(single macro or backslash-escaped string)

rangestopbeforestring(single macro or backslash-escaped string)(default: 〈none 〉)Select code starting with this string.
The value must be a single macro that gives the desired text when fully expanded, ora string that is interpreted literally except that backslash escapes of ASCII punctuation
characters are allowed to give the literal characters (“\\” for backslash, “\#” for “#”, andso on).
If line numbers are displayed, they are based on the range of code that is selected;
code that is discarded in selecting the range is not considered in calculating line numbers.
(default: 〈none 〉)Select code ending immediately before this string.
The value must be a single macro that gives the desired text when fully expanded, ora string that is interpreted literally except that backslash escapes of ASCII punctuation29

characters are allowed to give the literal characters (“\\” for backslash, “\#” for “#”, andso on).
If line numbers are displayed, they are based on the range of code that is selected;
code that is discarded in selecting the range is not considered in calculating line numbers.
rangestopstring

resetmargins(single macro or backslash-escaped string)(default: 〈none 〉)Select code ending with this string.
The value must be a single macro that gives the desired text when fully expanded, ora string that is interpreted literally except that backslash escapes of ASCII punctuation
characters are allowed to give the literal characters (“\\” for backslash, “\#” for “#”, andso on).
If line numbers are displayed, they are based on the range of code that is selected;
code that is discarded in selecting the range is not considered in calculating line numbers.
(default: false)(boolean)
Resets the left margin inside other environments.

rulecolor(default: black)(color command)
The color of the frame.

(default: false)
Forces the whole listing to appear on the same page, even if it doesn’t fit.

samepage(boolean)showspaces(boolean)

showtabs(boolean)space(default: false)

Enables visible spaces: visible␣spaces.
Enables visible tabs—only works in combination with obeytabs.

(default: false)(default: \textvisiblespace, ␣)Redefine the visible space character. Note that this is only used if showspaces=true.

(macro)spacecolor(string)(default: none)
Set the color of visible spaces. By default (none), they take the color of their surroundings.

startinline(boolean)(default: false)[For PHP only] Specifies that the code starts in PHP mode, i.e., leading <?php is omitted.

stepnumber(integer)(default: 1)

Interval at which line numbers appear.
stepnumberfromfirst(boolean)(default: false)
By default, when line numbering is used with stepnumber ̸= 1, only line numbers thatare a multiple of stepnumber are included. This offsets the line numbering from thefirst line, so that the first line, and all lines separated from it by a multiple of stepnumber,are numbered.

stepnumberoffsetvalues(default: false)
By default, when line numbering is used with stepnumber ̸= 1, only line numbers thatare a multiple of stepnumber are included. Using firstnumber to offset the numbering
will change which lines are numbered and which line gets which number, but will not(boolean)30

change which numbers appear. This option causes firstnumber to be ignored indetermining which line numbers are a multiple of stepnumber. firstnumber is stillused in calculating the actual numbers that appear. As a result, the line numbers thatappear will be a multiple of stepnumber, plus firstnumber minus 1.
stripall(default: false)(boolean)
Strip all leading and trailing whitespace from the input.

stripnl(default: false)(boolean)
Strip leading and trailing newlines from the input.

style (string)
Sets the stylesheet used by Pygments.

(default: 〈default 〉)tab(default: fancyvrb’s \FancyVerbTab, −〉|)
Redefine the visible tab character. Note that this is only used if showtabs=true.
\rightarrowfill, −−→, may be a nice alternative.

tabcolor(default: black)Set the color of visible tabs. If tabcolor=none, tabs take the color of their surroundings.
This is typically undesirable for tabs that indent multiline comments or strings.

tabsize(integer)(default: 8)
The number of spaces a tab is equivalent to. If obeytabs is not active, tabs will be
converted into this number of spaces. If obeytabs is active, tab stops will be set thisnumber of space characters apart.

(macro)(string)(default: false)
Enables LATEX code inside comments. Usage as in package listings. See the note underescapeinside regarding math and ligatures.

texcl(boolean)texcomments(boolean)xleftmargin(dimension)(default: false)
Enables LATEX code inside comments. The newer name for texcl. See the note underescapeinside regarding math and ligatures.
texcomments fails with multiline C/C++ preprocessor directives, and may fail insome other circumstances. This is because preprocessor directives are tokenized as
Comment.Preproc, so texcomments causes preprocessor directives to be treated as
literal LATEX code. An issue has been opened at the Pygments site; additional details arealso available on the minted GitHub site.
(default: 0)

Indentation to add before the listing.
xrightmargin(default: 0)(dimension)
Indentation to add after the listing.

8 Defining shortcuts
Large documents with many listings may use the same lexer and the same set of options
for most listings. minted therefore defines a set of commands that lets you define
shortcuts for the highlighting commands and environments. Each shortcut is specific
to one lexer.
\newminted\newminted defines a new alias for the minted environment:

31

\newminted{cpp}{gobble=2,linenos}
template <typename T>
T id(T value) {3
return value;
4 }\begin{cppcode}
template <typename T>
T id(T value) {return value;}\end{cppcode}1
2

If you want to provide extra options on the fly, or override existing default options,
you can do that, too:\newminted{cpp}{gobble=2,linenos}\begin{cppcode}[linenos=false,
frame=single]
int const answer = 42;\end{cppcode}

int const answer = 42;

The default name of the environment is 〈lexer〉code. If this name clashes withanother environment or if you want to choose a different name, you can use an optional
argument: \newminted[〈environment name〉]{〈lexer〉}{〈options〉}.
Like normal minted environments, environments created with \newminted may
be used within other environment definitions. Since the minted environments use
fancyvrb internally, any environment based on them must include the fancyvrb command \VerbatimEnvironment. This allows fancyvrb to determine the name of theenvironment that is being defined, and correctly find its end. It is best to include thiscommand at the beginning of the definition. For example,\newminted{cpp}{gobble=2,linenos}\newenvironment{env}{\VerbatimEnvironment\begin{cppcode}}{\end{cppcode}}\newmint

A shortcut for \mint is defined using \newmint[〈macro name〉]{〈lexer〉}{〈options〉}.
The arguments and usage are identical to \newminted. If no 〈macro name〉 is specified,〈lexer〉 is used.

\newmint{perl}{showspaces}\perl/my $foo = $bar;/\newmintinline

my $foo = $bar;

This creates custom versions of \mintinline. The syntax is the same as that for\newmint: \newmintinline[〈macro name〉]{〈lexer〉}{〈options〉}. If a 〈macro name〉is not specified, then the created macro is called 〈lexer〉inline.

\newmintinline{perl}{showspaces}\perlinline/my $foo = $bar;/\newmintedfile

my $foo = $bar;

This creates custom versions of \inputminted. The syntax is\newmintedfile[〈macro name〉]{〈lexer〉}{〈options〉}
If no 〈macro name〉 is given, then the macro is called 〈lexer〉file.

32

9 FAQ and Troubleshooting
In some cases, minted may not give the desired result due to other document settings
that it cannot control, or due to limitations in LATEX or the PDF format. Common issues
are described below, with workarounds or solutions. You may also wish to searchtex.stackexchange.com or ask a question there, if you are working with minted in a
non-typical context.
• I can’t copy and paste code out of a PDF created with minted. The line numbers
also get copied, or whitespace is lost, or something else happens that makes thecode incorrect. There is no known method that always guarantees correct copy
and paste for code in a PDF. This does not depend on whether minted is used. You
may want to search tex.stackexchange.com to find current approaches (and theirlimitations). You may also want to consider using attachfile or a similar package
to bundle source code files as part of your PDF.
• There are intermittent “I can’t write on file” errors. This can be caused by using
minted in a directory that is synchronized with Dropbox or a similar file syncing
program. These programs can try to sync minted’s temporary files while it stillneeds to be able to modify them. The solution is to turn off file syncing or use a
directory that is not synced.
• I receive a “Font Warning: Some font shapes were not available” message, orbold or italic seem to be missing. This is due to a limitation in the font that iscurrently in use for typesetting code. In some cases, the default font shapes thatLATEX substitutes are perfectly adequate, and the warning may be ignored. In othercases, 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
Typewriter Fonts for alternatives. If you like the default LATEX fonts, the lmodern
package is a good place to start. The beramono and courier packages may also be
good options.
• I receive a “Too many open files” error under macOS when using caching. See
the note on macOS under Section 6.2.
• Weird things happen when I use the fancybox package. fancybox conflicts with
fancyvrb, which minted uses internally. When using fancybox, make sure that it isloaded before minted (or before fancyvrb, if fancyvrb is not loaded by minted).
• When I use minted with KOMA-Script document classes, I get warnings about\float@addtolists. minted uses the float package to produce floated listings,
but this conflicts with the way KOMA-Script does floats. Load the package scrhack
to resolve the conflict. Or use minted’s newfloat package option.
• Tilde characters ~ 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.
• I’m getting errors with math, something like TeX capacity exceeded and\leavevmode\kern\z@. This is due to ligatures being disabled within verbatim
content. See the note under escapeinside.

33• With mathescape and the breqn package (or another special math package),the document never finishes compiling or there are other unexpected results.
Some math packages like breqn give certain characters like the comma special
meanings in math mode. These can conflict with minted. In the breqn and commacase, this can be fixed by redefining the comma within minted environments:\AtBeginEnvironment{minted}{\catcode`\,=12\mathcode`\,="613B}

Other packages/special characters may need their own modifications.
• 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 forframes that contain minted commands and environments. fragile=singleslide
works best, but it disables overlays. fragile works by saving the contents of eachframe to a temp file and then reusing them. This approach allows overlays, butwill 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.
• I’m trying to create several new minted commands/environments, and wantthem all to have the same settings. I’m saving the settings in a macro andthen using the macro when defining the commands/environments. But it’s
failing. This is due to the way that key-value processing operates. See this andthis for more information. It is still possible to do what you want; you just needto expand the options macro before passing it to the commands that create the
new commands/environments. An example is shown below. The \expandafteris the vital part.
\def\args{linenos,frame=single,fontsize=\footnotesize,style=bw}\newcommand{\makenewmintedfiles}[1]{%\newmintedfile[inputlatex]{latex}{#1}%\newmintedfile[inputc]{c}{#1}%}\expandafter\makenewmintedfiles\expandafter{\args}• I want to use \mintinline in a context that normally doesn’t allow verbatim
content. The \mintinline command will already work in many places that do
not allow normal verbatim commands like \verb, so make sure to try it first. If it
doesn’t work, one of the simplest alternatives is to save your code in a box, andthen use it later. For example,\newsavebox\mybox\begin{lrbox}{\mybox}\mintinline{cpp}{std::cout}\end{lrbox}\commandthatdoesnotlikeverbatim{Text \usebox{\mybox}}34

• Extended characters do not work inside minted commands and environments,
even when the inputenc package is used. Version 2.0 adds support for extended
characters under the pdfTeX engine. But if you need characters that are notsupported by inputenc, you should use the XeTeX or LuaTeX engines instead.
• The polyglossia package is doing undesirable things to code. (For example,
adding extra space around colons in French.) You may need to put your code
within \begin{english}...\end{english}. This may done for all minted
environments using etoolbox in the preamble:\usepackage{etoolbox}\BeforeBeginEnvironment{minted}{\begin{english}}\AfterEndEnvironment{minted}{\end{english}}• Tabs are being turned into the character sequence ^^I. This happens when you
use XeLaTeX. You need to use the -8bit command-line option so that tabs may
be written correctly to temporary files. See https://tex.stackexchange.com/
questions/58732/how-to-output-a-tabulation-into-a-file for moreon XeLaTeX’s handling of tab characters.
• The caption package produces an error when \captionof and other commands are used in combination with minted. Load the caption package with theoption compatibility=false. Or better yet, use minted’s newfloat package
option, which provides better caption compatibility.
• I need a listing environment that supports page breaks. The built-in listing
environment is a standard float; it doesn’t support page breaks. You will probably
want to define a new environment for long floats. For example,\usepackage{caption}\newenvironment{longlisting}{\captionsetup{type=listing}}{}With the caption package, it is best to use minted’s newfloat package option.
See https://tex.stackexchange.com/a/53540/10742 for more on listing
environments with page breaks.
• I want to use the command-line option -output-directory, or MiKTeX’s-aux-directory, but am getting errors. With TeX Live 2024+, this should work
automatically. Otherwise, set the environment variable TEXMF_OUTPUT_DIRECTORY
to the desired location.
• minted environments have extra vertical space inside tabular. It is possible tocreate a custom environment that eliminates the extra space. However, a generalsolution that behaves as expected in the presence of adjacent text remains to befound.
• I’m receiving a warning from lineno.sty that “Command \@parboxrestore
has changed.” This can happen when minted is loaded after csquotes. Try loading
minted first. If you receive this message when you are not using csquotes, you
may want to experiment with the order of loading packages and might also open
an issue.

35• I’m using texi2pdf, and getting “Cannot stat” errors from tar: This is due tothe way that texi2pdf handles temporary files. minted automatically cleans up
its temporary files, but texi2pdf assumes that any temporary file that is evercreated will still exist at the end of the run, so it tries to access the files thatminted has deleted. It’s possible to disable minted’s temp file cleanup by adding\renewcommand{\DeleteFile}[2][]{} after the \usepackage{minted}.

10 Acknowledgements
Konrad Rudolph: Special thanks to Philipp Stephani and the rest of the guys fromcomp.text.tex and tex.stackexchange.com.
Geoffrey Poore:• Thanks to Marco Daniel for the code on tex.stackexchange.com that inspired
automatic line breaking.
• Thanks to Patrick Vogt for improving TikZ externalization compatibility.
• Thanks to @muzimuzhi for assistance with GitHub issues.
• Thanks to @jfbu for suggestions and discussion regarding support for arbitrary
Pygments style names (#210, #294, #299, #317), and for debugging assistance.

11 Implementation
11.1 Required packages
1 \RequirePackage{catchfile}
2 \RequirePackage{etoolbox}
3 \RequirePackage{fvextra}[2024/09/05]
4 \RequirePackage{latex2pydata}[2024/05/16]
5 \RequirePackage{pdftexcmds}
6 \RequirePackage{pgfkeys}
7 \RequirePackage{pgfopts}
8 \RequirePackage{shellesc}

Make sure that either color or xcolor is loaded by the beginning of the document.

9 \AtEndPreamble{%
10\IfPackageLoadedTF{color}%
11
{}%
12
{\IfPackageLoadedTF{xcolor}{}{\RequirePackage{xcolor}}}}11.2 Exception handling\minted@error
13 \def\minted@error#1{\PackageError{minted}{#1}{}}\minted@fatalerror\batchmode\read -1 to \minted@fatalerror@exitnow forces an immediate
exit with “! Emergency stop [...] cannot \read from terminal in nonstop
modes.”
14 \def\minted@fatalerror#1{%

36

15
16

\minted@error{#1}%\batchmode\read -1 to \minted@fatalerror@exitnow}\minted@warning
17 \def\minted@warning#1{\PackageWarning{minted}{#1}}11.3 Python executable and minimum supported version\MintedExecutable
Name of minted Python executable.
18 \edef\MintedExecutable{\detokenize{latexminted}}\minted@executable@minversion
19 \edef\minted@executable@minversion{\detokenize{0.1.0}}\minted@executable@minmajor\minted@executable@minminor\minted@executable@minpatch
20 \def\minted@executable@setminversioncomponents{%
21\expandafter\minted@executable@setminversioncomponents@i
22\minted@executable@minversion\relax}
23 \begingroup24 \catcode`\.=12
25 \gdef\minted@executable@setminversioncomponents@i#1.#2.#3\relax{%26\def\minted@executable@minmajor{#1}%27\def\minted@executable@minminor{#2}%28\def\minted@executable@minpatch{#3}}29 \endgroup30 \minted@executable@setminversioncomponents\minted@executable@version
31 \let\minted@executable@version\relax

minted@executable@exists
32 \newbool{minted@executable@exists}

minted@executable@issupported
33 \newbool{minted@executable@issupported}

11.4 Timestamp
Timestamp for current compile. This could eventually be simplified to use \c_sys_timestamp_str
for all engines; that macro is in l3kernel from 2023-08-29.

\minted@timestamp
34 \begingroup35 \catcode`\-=1236 \catcode`\+=1237 \catcode`\:=1238 \def\minted@creationdatetotimestamp#1{%
39\expandafter\minted@creationdatetotimestamp@i#1-\relax}
40 \def\minted@creationdatetotimestamp@i#1:#2-#3\relax{%
41\minted@creationdatetotimestamp@ii#2+\relax}
42 \def\minted@creationdatetotimestamp@ii#1+#2\relax{%

37

43
#1}
44 \expandafter\ifx\csname pdftexversion\endcsname\relax
45 \else46\xdef\minted@timestamp{\minted@creationdatetotimestamp{\pdfcreationdate}}47 \fi48 \expandafter\ifx\csname XeTeXrevision\endcsname\relax
49 \else50\xdef\minted@timestamp{\minted@creationdatetotimestamp{\creationdate}}
51 \fi52 \expandafter\ifx\csname directlua\endcsname\relax
53 \else54\xdef\minted@timestamp{\minted@creationdatetotimestamp{\pdffeedback creationdate}}
55 \fi56 \endgroup
57 \ifcsname minted@timestamp\endcsname
58 \else
59\begingroup60\newcounter{minted@timestamp@hr}
61\newcounter{minted@timestamp@min}62\setcounter{minted@timestamp@min}{\number\time}
63\loop\unless\ifnum\value{minted@timestamp@min}<60\relax
64\addtocounter{minted@timestamp@hr}{1}65\addtocounter{minted@timestamp@min}{-60}66\repeat67\xdef\minted@timestamp{%
68\the\year
69\ifnum\month<10 0\fi\the\month70\ifnum\day<10 0\fi\the\day71\ifnum\value{minted@timestamp@hr}<10 0\fi\theminted@timestamp@hr
72\ifnum\value{minted@timestamp@min}<10 0\fi\theminted@timestamp@min}73\endgroup
74 \fi11.5 Jobname MD5 and derived file names\MintedJobnameMdfive

MD5 hash of \jobname. If \jobname contains spaces so that LATEX inserts wrapping
quotes (single or double) within \jobname, these quotes are stripped, so that only thestem (basename without file extension) of the file path is hashed. This makes it simple
to calculate the hash externally outside of LATEX.
\MintedJobnameMdfive is used for creating temp files rather than \jobname to
avoid shell escaping issues. Under restricted shell escape, shell commands are quoted
and escaped by LATEX itself, so using \jobname would work correctly in most cases.
However, when full shell escape is enabled, no command escaping is performed by
LATEX, so minted would have to quote/escape \jobname in a platform-specific manner.
(See for example web2c.info and texmfmp.c in the TeX Live source for shell escape
implementation details.) It is simpler to avoid escaping issues altogether, including edgecases in the restricted shell escape scenario, by using an MD5 hash that is guaranteed
to consist only of ASCII alphanumeric characters.
75 \begingroup76 \catcode`\"=1277 \catcode`\'=1238

78 \gdef\minted@setjobnamemdfive#1#2\FV@Sentinel{%
79\ifx#1"\relax
80\let\minted@next\minted@setjobnamemdfive@dquoted
81\else\ifx#1'\relax
82\let\minted@next\minted@setjobnamemdfive@squoted
83
\else
84
\let\minted@next\minted@setjobnamemdfive@uquoted
85\fi\fi86\minted@next#1#2\FV@Sentinel}
87 \gdef\minted@setjobnamemdfive@dquoted#1#2\FV@Sentinel{%88\minted@setjobnamemdfive@dquoted@i#2"\FV@Sentinel}
89 \gdef\minted@setjobnamemdfive@dquoted@i#1"#2\FV@Sentinel{%90\if\relax\detokenize{#2}\relax
91\edef\MintedJobnameMdfive{\pdf@mdfivesum{\jobname}}%92\else\if\relax\detokenize\expandafter{\@gobble#2}\relax
93\edef\MintedJobnameMdfive{\pdf@mdfivesum{#1}}%
94
\else
95
\edef\MintedJobnameMdfive{\pdf@mdfivesum{\jobname}}%96\fi\fi}97 \gdef\minted@setjobnamemdfive@squoted#1#2\FV@Sentinel{%98\minted@setjobnamemdfive@squoted@i#2'\FV@Sentinel}
99 \gdef\minted@setjobnamemdfive@squoted@i#1'#2\FV@Sentinel{%100\if\relax\detokenize{#2}\relax
101\edef\MintedJobnameMdfive{\pdf@mdfivesum{\jobname}}%102\else\if\relax\detokenize\expandafter{\@gobble#2}\relax
103\edef\MintedJobnameMdfive{\pdf@mdfivesum{#1}}%
104
\else
105
\edef\MintedJobnameMdfive{\pdf@mdfivesum{\jobname}}%106\fi\fi}107 \gdef\minted@setjobnamemdfive@uquoted#1\FV@Sentinel{%108\edef\MintedJobnameMdfive{\pdf@mdfivesum{#1}}}
109 \endgroup110 \expandafter\minted@setjobnamemdfive\jobname\FV@Sentinel\MintedCacheIndexFilename
Index file in cache. Used to detect whether cache exists.
111 \edef\MintedCacheIndexFilename{%
112\detokenize{_}\MintedJobnameMdfive\detokenize{.index.minted}}\MintedConfigFilename
File containing config info such as Python executable version. Written by the Pythonside, read by the LATEX side, and then immediately deleted.
113 \edef\MintedConfigFilename{%
114\detokenize{_}\MintedJobnameMdfive\detokenize{.config.minted}}\MintedDataFilename
Temp file for data. Written by the LATEX side, read by the Python side. Frequently
overwritten, so only cleaned up at the end of the compile.
115 \edef\MintedDataFilename{%
116\detokenize{_}\MintedJobnameMdfive\detokenize{.data.minted}}\MintedErrlogFilename
Log file created when the Python side encounters an unexpected error that it is notdesigned to report to the LATEX side.
117 \edef\MintedErrlogFilename{%39\detokenize{_}\MintedJobnameMdfive\detokenize{.errlog.minted}}

118\MintedMessageFilename
Messages from the Python side to the LaTeX side. Deleted immediately after reading.
119 \edef\MintedMessageFilename{%
120\detokenize{_}\MintedJobnameMdfive\detokenize{.message.minted}}

11.6 Package options\minted@pgfopts
121 \def\minted@pgfopts#1{%
122\pgfkeys{/minted/pkg/.cd,#1}}

11.6.1 Package option definitions\minted@float@within

Control the section numbering of the listing float.

123 \minted@pgfopts{
124
chapter/.code=\def\minted@float@within{chapter},
125
chapter/.value forbidden,
126
section/.code=\def\minted@float@within{section},127
section/.value forbidden,
128 }minted@newfloat
Use newfloat rather than float to create a floating listing environment.
129 \newbool{minted@newfloat}
130 \minted@pgfopts{
131
newfloat/.is if=minted@newfloat,
132 }minted@debug
Keep temp files for aid in debugging.
133 \newbool{minted@debug}
134 \minted@pgfopts{
135
debug/.is if=minted@debug,
136 }minted@cache
Determine whether highlighted content is cached.
137 \newbool{minted@cache}
138 \booltrue{minted@cache}
139 \minted@pgfopts{
140
cache/.is if=minted@cache,
141 }\minted@cachedir
Set the directory in which cached content is saved.
142 \edef\minted@cachedir{\detokenize{_minted}}
143 \minted@pgfopts{
144
cachedir/.estore in=\minted@cachedir,
145 }

40

minted@frozencache
When a cache file is missing, raise an error instead of attempting to update the cache.
This is intended for editing a document with a pre-existing cache in an environment inwhich \ShellEscape support is disabled or the minted executable is not available.
146 \newbool{minted@frozencache}
147 \minted@pgfopts{
148
frozencache/.is if=minted@frozencache,
149 }minted@lexerlinenos
Make all minted environments and \mint commands for a given lexer share cumulative line numbering (if firstnumber=last). langlinenos is for backward compatility with minted v2.
150 \newbool{minted@lexerlinenos}
151 \minted@pgfopts{
152
lexerlinenos/.is if=minted@lexerlinenos,
153
langlinenos/.is if=minted@lexerlinenos,
154 }minted@inputlexerlinenos
Enable lexerlinenos and make it apply to \inputminted. inputlanglinenos isfor backward compatility with minted v2.
155 \newbool{minted@inputlexerlinenos}
156 \minted@pgfopts{
157
inputlexerlinenos/.is if=minted@inputlexerlinenos,
158
inputlanglinenos/.is if=minted@inputlexerlinenos,
159 }minted@placeholder\minted@insertplaceholder
Cause all commands and environments to insert a placeholder rather than typesetting code. This functionality is primarily intended for use with PGF/TikZ externalization,
when all non-PGF/TikZ features should be disabled.
160 \newbool{minted@placeholder}
161 \minted@pgfopts{
162
placeholder/.is if=minted@placeholder,
163 }164 \gdef\minted@insertplaceholder{%165\ifbool{minted@isinline}%
166{\begingroup167\fvset{extra=true}\Verb[formatcom=\color{red}\bfseries]{<MINTED>}%168\endgroup}%169{\begingroup170\par\noindent
171\fvset{extra=true}\Verb[formatcom=\color{red}\bfseries]{<MINTED>}%
172
\par
173
\endgroup}}%minted@verbatim
Typeset all code verbatim using fancyvrb; do not use Python at all.
174 \newbool{minted@verbatim}
175 \minted@pgfopts{
176
verbatim/.is if=minted@verbatim,
177 }

41

\minted@highlightmode@init\minted@fasthighlightmode@checkstart\minted@fasthighlightmode@checkend
Determine whether highlighting is performed immediately or at the end of the compile. Immediately means more overhead during the compile, but no second compile isrequired. Highlighting at the end of the compile means a second compile is required,
but also makes highlighing much faster since there is only a single \ShellEscape.
\minted@highlightmode@init is invoked within \minted@detectconfig if the
Python executable is available and enabled. For the fastfirst case, \minted@highlightmode@init
requires the \minted@cachepath that is set within \minted@detectconfig.
\minted@fasthighlightmode@checkend is invoked \AfterEndDocument with\minted@clean; the \AtEndDocument is created with the definition of \minted@cleanso that everything is in the correct order.
178 \newbool{minted@fasthighlightmode}
179 \newbool{minted@fasthighlightmode@open}
180 \minted@pgfopts{
181
highlightmode/.is choice,182
highlightmode/fast/.code=
183\let\minted@highlightmode@init\minted@highlightmode@init@fast,184
highlightmode/fastfirst/.code=
185\let\minted@highlightmode@init\minted@highlightmode@init@fastfirst,
186
highlightmode/immediate/.code=
187\let\minted@highlightmode@init\minted@highlightmode@init@immediate,188 }189 \def\minted@highlightmode@init@fast{%
190\global\booltrue{minted@fasthighlightmode}}191 \def\minted@highlightmode@init@fastfirst{%
192\IfFileExists{\minted@cachepath\MintedCacheIndexFilename}%
193{\global\boolfalse{minted@fasthighlightmode}}194{\global\booltrue{minted@fasthighlightmode}}}195 \def\minted@highlightmode@init@immediate{%
196\global\boolfalse{minted@fasthighlightmode}}197 \let\minted@highlightmode@init\minted@highlightmode@init@fastfirst
198 \def\minted@fasthighlightmode@checkstart{%
199\ifbool{minted@fasthighlightmode}%
200{\pydatawritelistopen
201\global\booltrue{minted@fasthighlightmode@open}}%
202
{}%
203
\global\let\minted@fasthighlightmode@checkstart\relax}
204 \def\minted@fasthighlightmode@checkend{%
205\ifbool{minted@fasthighlightmode@open}%
206{\pydatasetfilename{\MintedDataFilename}%
207\pydatawritelistclose
208\pydataclosefilename{\MintedDataFilename}%
209\global\boolfalse{minted@fasthighlightmode@open}%
210\global\boolfalse{minted@fasthighlightmode}%211\begingroup212\minted@exec@batch213\ifx\minted@exec@warning\relax
214
\else
215
\expandafter\minted@exec@warning
216
\fi
217
\ifx\minted@exec@error\relax

42

218
219
220
221
222
223
224

\else
\expandafter\minted@exec@error\fi\endgroup\global\boolfalse{minted@canexec}}%{}%\global\let\minted@fasthighlightmode@checkend\relax}

11.6.2 Package options that are no longer supported or deprecated
finalizecache Old, no longer needed option from minted v2.
225 \minted@pgfopts{
226
finalizecache/.code=\minted@error{%227
Package option "finalizecache" is no longer needed with minted v3+},
228 }kpsewhich Old, no longer needed option from minted v2.
229 \minted@pgfopts{
230
kpsewhich/.code=\minted@error{%
231
Package option "kpsewhich" is no longer needed with minted v3+},
232 }outputdir Old, no longer needed option from minted v2.
The empty \minted@outputdir is for backward compatibility with packages that
depend on minted v2 internals.
233 \minted@pgfopts{
234
outputdir/.code=\minted@error{%235
Package option "outputdir" is no longer needed with minted v3+;236
the output directory is automatically detected for TeX Live 2024+,
237
and the environment variable \detokenize{TEXMF_OUTPUT_DIRECTORY}238
can be set manually in other cases},239 }240 \def\minted@outputdir{}draft Old, no longer supported option from minted v2. Improvements in caching combined with the new minted v3 package options placeholder and verbatim provide
better alternatives.
241 \minted@pgfopts{
242
draft/.code=\minted@warning{%
243
Package option "draft" no longer has any effect with minted v3+},
244 }final Old, no longer supported option from minted v2. Improvements in caching combined with the new minted v3 package options placeholder and verbatim provide
better alternatives.
245 \minted@pgfopts{
246
final/.code=\minted@warning{%
247
Package option "final" no longer has any effect with minted v3+},
248 }

43

11.6.3 Package option processing
249 \ProcessPgfOptions{/minted/pkg}
250 \ifbool{minted@cache}{}{\def\minted@cachedir{}}%251 \ifbool{minted@newfloat}{\RequirePackage{newfloat}}{\RequirePackage{float}}
252 \ifcsname tikzifexternalizing\endcsname
253\ifx\tikzifexternalizing\relax
254
\else
255
\tikzifexternalizing{\booltrue{minted@placeholder}}{}256\fi
257 \fi

11.7 Util\minted@styleprefix
Prefix for generating Pygments style names.
258 \def\minted@styleprefix{PYG}

minted@tmpcnt
Temp counter.
259 \newcounter{minted@tmpcnt}\minted@forcsvlist

Wrapper for etoolbox \forcsvlist. Syntax: \minted@forcsvlist{〈handler〉}{〈listmacro〉}.

260 \def\minted@forcsvlist#1#2{%
261\if\relax\detokenize\expandafter{\@gobble#2}\relax
262\expandafter\minted@forcsvlist@exp
263
\else
264
\expandafter\minted@forcsvlist@i
265
\fi
266
{#2}{#1}}
267 \def\minted@forcsvlist@exp#1#2{%
268\expandafter\minted@forcsvlist@i\expandafter{#1}{#2}}269 \def\minted@forcsvlist@i#1#2{%
270\forcsvlist{#2}{#1}}\minted@apptoprovidecs
271 \def\minted@apptoprovidecs#1#2{%
272\ifcsname#1\endcsname
273
\else
274
\expandafter\def\csname#1\endcsname{}%
275
\fi
276
\expandafter\let\expandafter\minted@tmp\csname#1\endcsname277\expandafter\def\expandafter\minted@tmp\expandafter{\minted@tmp#2}%
278\expandafter\let\csname#1\endcsname\minted@tmp}\minted@const@pgfkeysnovalue279 \def\minted@const@pgfkeysnovalue{\pgfkeysnovalue}\minted@ensureatletter
280 \def\minted@ensureatletter#1{%
281\edef\minted@tmpatcat{\the\catcode`\@}%
282\catcode`\@=11\relax
283
#1%
284
\catcode`\@=\minted@tmpatcat\relax}4411.7.1 Check whether a string matches the regex ^[0-9A-Za-z_-]+$
These macros are used to restrict possible names of highlighting styles on the LATEX side.

\minted@is<char_category><codepoint_decimal>

Create macros used in determining whether a given character is part of a specified
set of characters.
285 % [0-9]286 \setcounter{minted@tmpcnt}{48}287 \loop\unless\ifnum\value{minted@tmpcnt}>57\relax
288\expandafter\let\csname minted@isnum\arabic{minted@tmpcnt}\endcsname\relax
289\expandafter\let\csname minted@isalphanum\arabic{minted@tmpcnt}\endcsname\relax
290\expandafter\let
291\csname minted@isalphanumhyphenunderscore\arabic{minted@tmpcnt}\endcsname\relax
292\stepcounter{minted@tmpcnt}
293 \repeat
294 % [A-Z]
295 \setcounter{minted@tmpcnt}{65}296 \loop\unless\ifnum\value{minted@tmpcnt}>90\relax
297\expandafter\let\csname minted@isalpha\arabic{minted@tmpcnt}\endcsname\relax
298\expandafter\let\csname minted@isalphanum\arabic{minted@tmpcnt}\endcsname\relax
299\expandafter\let
300\csname minted@isalphanumhyphenunderscore\arabic{minted@tmpcnt}\endcsname\relax
301\stepcounter{minted@tmpcnt}
302 \repeat
303 % [a-z]304 \setcounter{minted@tmpcnt}{97}305 \loop\unless\ifnum\value{minted@tmpcnt}>122\relax
306\expandafter\let\csname minted@isalpha\arabic{minted@tmpcnt}\endcsname\relax
307\expandafter\let\csname minted@isalphanum\arabic{minted@tmpcnt}\endcsname\relax
308\expandafter\let309\csname minted@isalphanumhyphenunderscore\arabic{minted@tmpcnt}\endcsname\relax
310\stepcounter{minted@tmpcnt}
311 \repeat
312 % [-]
313 \expandafter\let\csname minted@isalphanumhyphenunderscore45\endcsname\relax
314 % [_]
315 \expandafter\let\csname minted@isalphanumhyphenunderscore95\endcsname\relax\minted@ifalphanumhyphenunderscore
Conditional based on whether first argument is ASCII alphanumeric, hyphen, or
underscore.
316 \def\minted@ifalphanumhyphenunderscore#1#2#3{%317\if\relax\detokenize{#1}\relax
318\expandafter\@firstoftwo
319
\else
320
\expandafter\@secondoftwo
321
\fi
322
{#3}%
323
{\expandafter\minted@ifalphanumhyphenunderscore@i\detokenize{#1}\FV@Sentinel{#2}{#3}}}
324 \def\minted@ifalphanumhyphenunderscore@i#1#2\FV@Sentinel{%325\if\relax#2\relax
326\expandafter\minted@ifalphanumhyphenunderscore@iii
327
\else
328
\expandafter\minted@ifalphanumhyphenunderscore@ii

45

329
\fi
330
#1#2\FV@Sentinel}
331 \def\minted@ifalphanumhyphenunderscore@ii#1#2\FV@Sentinel{%332\ifcsname minted@isalphanumhyphenunderscore\number`#1\endcsname
333\expandafter\minted@ifalphanumhyphenunderscore@i
334
\else
335
\expandafter\minted@ifalphanumhyphenunderscore@false
336
\fi
337
#2\FV@Sentinel}
338 \def\minted@ifalphanumhyphenunderscore@iii#1\FV@Sentinel{%339\ifcsname minted@isalphanumhyphenunderscore\number`#1\endcsname
340\expandafter\minted@ifalphanumhyphenunderscore@true
341
\else
342
\expandafter\minted@ifalphanumhyphenunderscore@false
343
\fi
344
\FV@Sentinel}
345 \def\minted@ifalphanumhyphenunderscore@true\FV@Sentinel#1#2{#1}346 \def\minted@ifalphanumhyphenunderscore@false#1\FV@Sentinel#2#3{#3}

11.8 State\minted@lexer
Current lexer (language). Should be the empty macro if not set; it is used within\ifcsname...\endcsname to check for the existence of lexer-specific settings macros.
347 \let\minted@lexer\@empty

minted@isinline
Whether in command or environment.
348 \newbool{minted@isinline}

minted@tmpcodebufferlength
Length of buffer in which code to be highlighted is stored.
349 \newcounter{minted@tmpcodebufferlength}11.9 Calling minted executable
minted@canexec
350 \newbool{minted@canexec}
351 \booltrue{minted@canexec}
352 \ifnum\csname c_sys_shell_escape_int\endcsname=0\relax
353\boolfalse{minted@canexec}
354 \fi
355 \ifbool{minted@frozencache}{\boolfalse{minted@canexec}}{}356 \ifbool{minted@placeholder}{\boolfalse{minted@canexec}}{}357 \ifbool{minted@verbatim}{\boolfalse{minted@canexec}}{}\minted@ShellEscapeMaybeMessages\minted@ShellEscapeNoMessages
358 \def\minted@ShellEscapeMaybeMessages#1{%359\let\minted@exec@warning\relax
360\let\minted@exec@error\relax
361\ifbool{minted@canexec}{\ShellEscape{#1}\minted@inputexecmessages}{}}362 \def\minted@ShellEscapeNoMessages#1{%
363\ifbool{minted@canexec}{\ShellEscape{#1}}{}}

46

\minted@execarg@debug\minted@execarg@timestamp
364 \def\minted@execarg@debug{%365\ifbool{minted@debug}{\detokenize{ --debug }}{}}
366 \def\minted@execarg@timestamp{%
367\detokenize{ --timestamp }\minted@timestamp\detokenize{ }}\minted@exec@cleanfile
Clean (delete) a temp file in all locations where it might be expected to exist. Only
files under the working directory, TEXMFOUTPUT, or TEXMF_OUTPUT_DIRECTORY can becleaned, and only if their names match the regex[0-9a-zA-Z_-]+\.(?:config|data|errlog|highlight|message|style)\.minted

The identifier immediately before the .minted file extension describes the role of the
file. Files ending with .errlog.minted are not automatically cleaned up at the end of
a compile, but are deleted at the beginning as part of config detection.
368 \def\minted@exec@cleanfile#1{%
369\minted@ShellEscapeNoMessages{%
370\MintedExecutable\detokenize{ cleanfile }\minted@execarg@debug#1}}\minted@inputexecmessages

If temp file containing warning and/or error messages exists, \input and thendelete.
371 \def\minted@inputexecmessages{%372\minted@ensureatletter{\InputIfFileExists{\MintedMessageFilename}{}{}}}\minted@exec@batch

Run in batch mode, for highlightmode=fast or highlightmode=fastfirst.

373 \def\minted@exec@batch{%374\minted@ShellEscapeMaybeMessages{%
375\MintedExecutable
376\detokenize{ batch }\minted@execarg@timestamp\minted@execarg@debug
377\MintedJobnameMdfive}}\minted@exec@config
Detect configuration.
378 \def\minted@exec@config{%
379\minted@ShellEscapeMaybeMessages{%
380\MintedExecutable
381\detokenize{ config }\minted@execarg@timestamp\minted@execarg@debug
382\MintedJobnameMdfive}}\minted@exec@styledefCreate style definition.
383 \def\minted@exec@styledef{%384\minted@ShellEscapeMaybeMessages{%
385\MintedExecutable
386\detokenize{ styledef }\minted@execarg@timestamp\minted@execarg@debug
387\MintedJobnameMdfive}}\minted@exec@highlight
Highlight code.
388 \def\minted@exec@highlight{%
389\minted@ShellEscapeMaybeMessages{%

47

390
391
392

\MintedExecutable\detokenize{ highlight }\minted@execarg@timestamp\minted@execarg@debug\MintedJobnameMdfive}}\minted@exec@clean
Clean output directory and cache.
393 \def\minted@exec@clean{%394\minted@ShellEscapeNoMessages{%
395\MintedExecutable396\detokenize{ clean }\minted@execarg@timestamp\minted@execarg@debug
397\MintedJobnameMdfive}}11.10 Config detection
minted@diddetectconfig
398 \newbool{minted@diddetectconfig}\minted@detectconfig
When the minted@canexec bool is defined, it is set false if shell escape is completely disabled (\c_sys_shell_escape_int=0) or if execution is disabled by package
options, so those cases don’t need to be handled here.
If the Python executable is available, then it will create a .config.minted file tonotify the LATEX side that it is present. This .config.minted file always contains a timestamp \minted@executable@timestamp, which is the timestamp passed directly tothe executable as a command-line option. If the executable finds a .data.minted file,then it will extract the timestamp from this file and save it in the .config.minted fileas \minted@config@timestamp; otherwise, the .config.minted file will not containthis timestamp. When LATEX loads the .config.minted file, the presence and values ofthese timestamps is used to determine whether the executable is present and whether
the correct .data.minted file was located by the executable.
399 \def\minted@detectconfig{%
400\ifbool{minted@diddetectconfig}%
401
{}%
402
{\ifx\minted@cachedir\@empty
403\gdef\minted@cachepath{}%
404
\else
405
\gdef\minted@cachepath{\minted@cachedir/}%
406
\fi
407
\ifbool{minted@canexec}{\begingroup\minted@detectconfig@i\endgroup}{}%408\global\booltrue{minted@diddetectconfig}}}
409 \def\minted@detectconfig@i{%
410\global\let\minted@executable@version\relax
411\global\let\minted@executable@timestamp\relax
412\global\let\minted@config@timestamp\relax
413\pydatasetfilename{\MintedDataFilename}%414\pydatawritedictopen
415\pydatawritekeyvalue{command}{config}%
416\pydatawritekeyedefvalue{jobname}{\jobname}%
417\pydatawritekeyedefvalue{timestamp}{\minted@timestamp}%
418\pydatawritekeyedefvalue{cachedir}{\minted@cachedir}%419\pydatawritedictclose
420\pydataclosefilename{\MintedDataFilename}%
421\minted@exec@config

48

422
\minted@ensureatletter{%
423\InputIfFileExists{\MintedConfigFilename}{}{}}%
424\ifx\minted@executable@version\relax
425\expandafter\minted@detectconfig@noexecutable
426
\else
427
\expandafter\minted@detectconfig@ii
428\fi}
429 \def\minted@detectconfig@noexecutable{%
430\global\boolfalse{minted@canexec}%
431\ifnum\csname c_sys_shell_escape_int\endcsname=1\relax
432\minted@error{minted v3+ executable is not installed or is not added to PATH}%
433
\else
434
\minted@error{minted v3+ executable is not installed, is not added to PATH,
435
or is not permitted with restricted shell escape}%436\fi}
437 \def\minted@detectconfig@ii{%
438\ifx\minted@timestamp\minted@config@timestamp439\expandafter\minted@detectconfig@iii
440
\else
441
\expandafter\minted@detectconfig@wrongtimestamp442\fi}
443 \def\minted@detectconfig@wrongtimestamp{%
444\ifx\minted@timestamp\minted@executable@timestamp
445\minted@exec@cleanfile{\MintedConfigFilename}%
446\global\boolfalse{minted@canexec}%
447\minted@error{minted v3 Python executable could not find output directory;
448
upgrade to TeX distribution that supports \detokenize{TEXMF_OUTPUT_DIRECTORY}
449
or set environment variable \detokenize{TEXMF_OUTPUT_DIRECTORY} manually)}%
450
\else
451
\expandafter\minted@detectconfig@noexecutable452\fi}
453 \def\minted@detectconfig@iii{%
454\minted@exec@cleanfile{\MintedConfigFilename}%455\ifx\minted@exec@warning\relax
456
\else
457
\expandafter\minted@exec@warning
458
\fi
459
\ifx\minted@exec@error\relax
460\expandafter\minted@detectconfig@iv
461
\else
462
\expandafter\minted@detectconfig@error463\fi}
464 \def\minted@detectconfig@error{%465\global\boolfalse{minted@canexec}%
466\minted@exec@error}
467 \def\minted@detectconfig@iv{%
468\expandafter\minted@detectconfig@v\minted@executable@version\relax}469 \begingroup
470 \catcode`\.=12471 \gdef\minted@detectconfig@v#1.#2.#3\relax{%472\def\minted@executable@major{#1}%473\def\minted@executable@minor{#2}%474\def\minted@executable@patch{#3}%475\minted@detectconfig@vi}49476 \endgroup477 \def\minted@detectconfig@vi{%
478\ifnum\minted@executable@major>\minted@executable@minmajor\relax
479\global\booltrue{minted@executable@issupported}%
480\else\ifnum\minted@executable@major=\minted@executable@minmajor\relax
481\ifnum\minted@executable@minor>\minted@executable@minminor\relax
482\global\booltrue{minted@executable@issupported}%
483\else\ifnum\minted@executable@minor=\minted@executable@minminor\relax
484\ifnum\minted@executable@patch<\minted@executable@minpatch\relax
485
\else
486
\global\booltrue{minted@executable@issupported}%
487
\fi
488
\fi\fi489\fi\fi490\ifbool{minted@executable@issupported}%
491{\ifx\minted@config@cachepath\relax
492\expandafter\@firstoftwo
493
\else
494
\expandafter\@secondoftwo
495
\fi
496
{\global\boolfalse{minted@canexec}%
497\minted@error{minted Python executable returned incomplete configuration data;
498
this may indicate a bug in minted or file corruption}}%499{\global\let\minted@cachepath\minted@config@cachepath
500\minted@highlightmode@init}}%
501{\global\boolfalse{minted@canexec}%
502\minted@error{minted Python executable is version \minted@executable@version,503
but version \minted@executable@minversion+ is required}}}11.11 Options
11.11.1 Option processing\minted@optcats\minted@optkeyslist@<optcat>
Option categories, along with lists of keys for each.
• fv: Passed on to fancyvrb. Options are stored in scope-specific lists, rather thanin individual per-option macros.
• py: Passed to Python. Options are stored in scope-specific, individual per-option
macros. Some of these are passed to fancyvrb when the Python executable isn’t
available or is disabled.
• tex: Processed in LATEX. Options are stored in scope-specific, individual peroption macros.
504 \begingroup505 \catcode`\,=12506 \gdef\minted@optcats{fv,py,tex}507 \endgroup508 \def\minted@do#1{\expandafter\def\csname minted@optkeyslist@#1\endcsname{}}509 \minted@forcsvlist{\minted@do}{\minted@optcats}50

\minted@optscopes\minted@optscopes@onlyblock
Scopes for options. cmd scope is the scope of a single command or environment.
510 \begingroup
511 \catcode`\,=12512 \gdef\minted@optscopes{global,lexer,globalinline,lexerinline,cmd}
513 \gdef\minted@optscopes@onlyblock{global,lexer,cmd}
514 \endgroup\minted@iflexerscope
515 \let\minted@iflexerscope@lexer\relax
516 \let\minted@iflexerscope@lexerinline\relax
517 \def\minted@iflexerscope#1#2#3{%
518\ifcsname minted@iflexerscope@#1\endcsname519\expandafter\@firstoftwo
520
\else
521
\expandafter\@secondoftwo
522
\fi
523
{#2}{#3}}\mintedpgfkeyscreate
Core macro for defining options.
Syntax: \mintedpgfkeyscreate[〈processor〉]{〈option category〉}{〈key(=value)?
list〉}.
• Optional 〈processor〉 is a macro that processes 〈value〉. It can take two forms.
1. It can take a single argument. In this case, it is used to wrap 〈value〉:\processor{〈value〉}. It is not invoked until 〈value〉 wrapped in 〈processor〉
is actually used.
2. It can take two arguments. The first is the 〈csname〉 that the processed〈value〉 should be stored in, and the second is 〈value〉. In this case,〈processor〉 is invoked immediately and stores the processed 〈value〉 in〈csname〉. See \minted@opthandler@deforrestrictedescape for an example of implementing this sort of 〈processor〉.
〈processor〉 is only supported for py and tex options.
• 〈option category〉 is fv (for fancyvrb), py (Python side of minted), or tex (LATEX
side of minted).
• If only 〈key〉 is given, then 〈value〉 defaults to \pgfkeysnovalue. In that case,
options are defined so that they can be used in the future, but they are ignored
until an explicit 〈value〉 is provided later. fv options are typically defined onlywith 〈key〉. py and tex options are currently required to have an initial 〈value〉.
If a 〈key〉 is given an initial 〈value〉 when it is defined, then that 〈value〉 is stored
for the 〈key〉 in the global scope. When an initial value is needed for a different
scope such as lexer or inline, \pgfkeys is used directly (\setminted and\setmintedinline don’t yet exist).
• py only: A default value for 〈key〉 (value used when only 〈key〉 is given without avalue) can be specified with the syntax key<default>=value. Default values for
fv options are already defined in fancyvrb, and currently the few tex options are
the sort that always need an explicit value for clarity.
51524 \def\minted@addoptkey#1#2{%
525\ifcsname minted@optkeyslist@#1\endcsname
526
\else
527
\minted@fatalerror{Defining options under category "#1" is not supported}%
528
\fi
529
\expandafter\let\expandafter\minted@tmp\csname minted@optkeyslist@#1\endcsname
530\ifx\minted@tmp\@empty
531\def\minted@tmp{#2}%
532
\else
533
\expandafter\def\expandafter\minted@tmp\expandafter{\minted@tmp,#2}%
534
\fi
535
\expandafter\let\csname minted@optkeyslist@#1\endcsname\minted@tmp}
536 \newcommand*{\mintedpgfkeyscreate}[3][]{%
537\mintedpgfkeyscreate@i{#1}{#2}{#3}}538 \begingroup539 \catcode`\==12
540 \gdef\mintedpgfkeyscreate@i#1#2#3{%541\def\minted@do##1{%
542\minted@do@i##1=\FV@Sentinel}%543\def\minted@do@i##1=##2\FV@Sentinel{%544\minted@do@ii##1<>\FV@Sentinel}%545\def\minted@do@ii##1<##2>##3\FV@Sentinel{%546\minted@addoptkey{#2}{##1}}%
547\minted@forcsvlist{\minted@do}{#3}%548\csname minted@pgfkeyscreate@#2\endcsname{#1}{#3}}549 \endgroup\minted@pgfkeyscreate@fv\minted@fvoptlist@<scope>(@<lexer>)?
\minted@usefvopts\minted@usefvoptsnopy
Syntax: \minted@pgfkeyscreate@fv{〈key(=value)? list〉}.
Options are stored in scope-specific lists. They are applied by passing these lists to\fvset. Individual option values are not retrievable.
The \begingroup\fvset{...}\endgroup checks fancyvrb options at definition
time so that any errors are caught immediately instead of when the options are usedlater elsewhere.
\minted@usefvopts applies options via \fvset. \minted@useadditionalfvoptsnopy
applies additional options that are usually handled on the Python side and is intended
for situations where Python is not available or is not used, such as purely verbatim
typesetting.
550 \def\minted@pgfkeyscreate@fv#1#2{%
551\if\relax\detokenize{#1}\relax
552
\else
553
\minted@fatalerror{Processor macros are not supported in defining fancyvrb options}%
554
\fi
555
\minted@forcsvlist{\minted@pgfkeycreate@fv}{#2}}556 \begingroup557 \catcode`\==12558 \gdef\minted@pgfkeycreate@fv#1{%
559\minted@pgfkeycreate@fv@i#1=\FV@Sentinel}
560 \gdef\minted@pgfkeycreate@fv@i#1=#2\FV@Sentinel{%561\if\relax\detokenize{#2}\relax

52

562
\expandafter\minted@pgfkeycreate@fv@ii
563
\else
564
\expandafter\minted@pgfkeycreate@fv@iii
565
\fi
566
{#1}#2\FV@Sentinel}
567 \gdef\minted@pgfkeycreate@fv@ii#1\FV@Sentinel{%568\minted@pgfkeycreate@fv@iv{#1}{\minted@const@pgfkeysnovalue}}569 \gdef\minted@pgfkeycreate@fv@iii#1#2=\FV@Sentinel{%
570\minted@pgfkeycreate@fv@iv{#1}{#2}}571 \endgroup572 \def\minted@pgfkeycreate@fv@iv#1#2{%573\def\minted@do##1{%
574\minted@iflexerscope{##1}%
575{\minted@do@i{##1}{@\minted@lexer}}%
576{\minted@do@i{##1}{}}}%
577\def\minted@do@i##1##2{%
578\pgfkeys{%579/minted/##1/.cd,580#1/.code=581\def\minted@tmp{####1}%
582\ifx\minted@tmp\minted@const@pgfkeysnovalue583\begingroup\fvset{#1}\endgroup584\minted@apptoprovidecs{minted@fvoptlist@##1##2}{#1,}%
585
\else
586
\begingroup\fvset{#1=####1}\endgroup587\minted@apptoprovidecs{minted@fvoptlist@##1##2}{#1=####1,}%
588
\fi,
589
}%
590
}%
591
\minted@forcsvlist{\minted@do}{\minted@optscopes}%592\ifx\minted@const@pgfkeysnovalue#2\relax
593
\else
594
\pgfkeys{%595/minted/global/.cd,596#1=#2,
597
}%
598
\fi}
599 \def\minted@usefvopts{%
600\ifbool{minted@isinline}%
601{\minted@forcsvlist{\minted@usefvopts@do}{\minted@optscopes}}%602{\minted@forcsvlist{\minted@usefvopts@do}{\minted@optscopes@onlyblock}}}
603 \def\minted@usefvopts@do#1{%
604\minted@iflexerscope{#1}%605{\ifcsname minted@fvoptlist@#1@\minted@lexer\endcsname606\expandafter
607\let\expandafter\minted@tmp\csname minted@fvoptlist@#1@\minted@lexer\endcsname608\expandafter\fvset\expandafter{\minted@tmp}%
609
\fi}%
610
{\ifcsname minted@fvoptlist@#1\endcsname611\expandafter
612\let\expandafter\minted@tmp\csname minted@fvoptlist@#1\endcsname613\expandafter\fvset\expandafter{\minted@tmp}%
614
\fi}}
615 \def\minted@useadditionalfvoptsnopy{%

53

616
\edef\minted@tmp{\mintedpyoptvalueof{gobble}}%617\ifx\minted@tmp\minted@const@pgfkeysnovalue
618
\else
619
\expandafter\minted@useadditionalfvoptsnopy@fvsetvk
620\expandafter{\minted@tmp}{gobble}%
621
\fi
622
\edef\minted@tmp{\mintedpyoptvalueof{mathescape}}%623\ifx\minted@tmp\minted@const@pgfkeysnovalue
624
\else
625
\expandafter\minted@useadditionalfvoptsnopy@fvsetvk
626\expandafter{\minted@tmp}{mathescape}%627\fi}
628 \def\minted@useadditionalfvoptsnopy@fvsetvk#1#2{%
629\fvset{#2=#1}}\minted@pgfkeyscreate@py\mintedpyoptvalueof
Syntax: \minted@pgfkeyscreate@py{〈processor〉}{〈key(<default>)?=initial valuelist〉}.
Currently, initial values are required. The key processing macros are written
to handle the possibility of optional initial values: If no initial value is set, use\pgfkeysnovalue, which is skipped in passing data to the Python side to invoke defaults.
\mintedpyoptvalueof is used for retrieving values via \edef.
630 \def\minted@pgfkeyscreate@py#1#2{%
631\minted@forcsvlist{\minted@pgfkeycreate@py{#1}}{#2}}632 \begingroup
633 \catcode`\==12634 \catcode`\<=12635 \catcode`\>=12636 \gdef\minted@pgfkeycreate@py#1#2{%
637\minted@pgfkeycreate@py@i{#1}#2=\FV@Sentinel}
638 \gdef\minted@pgfkeycreate@py@i#1#2=#3\FV@Sentinel{%639\if\relax\detokenize{#3}\relax
640\expandafter\minted@pgfkeycreate@py@ii
641
\else
642
\expandafter\minted@pgfkeycreate@py@iii
643
\fi
644
{#1}{#2}#3\FV@Sentinel}
645 \gdef\minted@pgfkeycreate@py@ii#1#2\FV@Sentinel{%
646\minted@pgfkeycreate@py@iv{#1}{\pgfkeysnovalue}#2<>\FV@Sentinel}
647 \gdef\minted@pgfkeycreate@py@iii#1#2#3=\FV@Sentinel{%648\minted@pgfkeycreate@py@iv{#1}{#3}#2<>\FV@Sentinel}
649 \gdef\minted@pgfkeycreate@py@iv#1#2#3<#4>#5\FV@Sentinel{%650\if\relax\detokenize{#4}\relax
651\expandafter\@firstoftwo
652
\else
653
\expandafter\@secondoftwo
654
\fi
655
{\minted@pgfkeycreate@py@v{#1}{#3}{#2}{\minted@const@pgfkeysnovalue}}%656{\minted@pgfkeycreate@py@v{#1}{#3}{#2}{#4}}}
657 \endgroup658 \def\minted@pgfkeycreate@py@v#1#2#3#4{%659\def\minted@do##1{%

54

660
\minted@iflexerscope{##1}%
661{\minted@do@i{##1}{@\minted@lexer}}%
662{\minted@do@i{##1}{}}}
663\def\minted@do@i##1##2{%
664\if\relax\detokenize{#1}\relax
665\pgfkeys{%666/minted/##1/.cd,667#2/.code=\expandafter\def\csname minted@pyopt@##1##2@#2\endcsname{####1},
668
}%
669
\else
670
\pgfkeys{%671/minted/##1/.cd,672#2/.code=673\def\minted@tmp{####1}%
674\ifx\minted@tmp\minted@const@pgfkeysnovalue
675\expandafter\let\csname minted@pyopt@##1##2@#2\endcsname\minted@tmp
676\else\ifcsname minted@opthandler@immediate@\string#1\endcsname677#1{minted@pyopt@##1##2@#2}{####1}%
678
\else
679
\expandafter\def\csname minted@pyopt@##1##2@#2\endcsname{#1{####1}}%
680\fi\fi,
681
}%
682
\fi
683
\ifx\minted@const@pgfkeysnovalue#4\relax
684\pgfkeys{%685/minted/##1/.cd,
686#2/.value required,
687
}%
688
\else
689
\pgfkeys{%690/minted/##1/.cd,691#2/.default=#4,
692
}%
693
\fi
694
}%
695
\minted@forcsvlist{\minted@do}{\minted@optscopes}%696\pgfkeys{%697/minted/global/.cd,698#2=#3,
699}}
700 \def\mintedpyoptvalueof#1{%
701\ifbool{minted@isinline}%702{\minted@pyoptvalueof@inline{#1}}%
703{\minted@pyoptvalueof@block{#1}}}
704 \def\minted@pyoptvalueof@inline#1{%
705\ifcsname minted@pyopt@cmd@#1\endcsname
706\unexpanded\expandafter\expandafter\expandafter{%707\csname minted@pyopt@cmd@#1\endcsname}%
708\else\ifcsname minted@pyopt@lexerinline@\minted@lexer @#1\endcsname709\unexpanded\expandafter\expandafter\expandafter{%710\csname minted@pyopt@lexerinline@\minted@lexer @#1\endcsname}%
711\else\ifcsname minted@pyopt@globalinline@#1\endcsname712\unexpanded\expandafter\expandafter\expandafter{%713\csname minted@pyopt@globalinline@#1\endcsname}%

55

714
\else\ifcsname minted@pyopt@lexer@\minted@lexer @#1\endcsname
715\unexpanded\expandafter\expandafter\expandafter{%716\csname minted@pyopt@lexer@\minted@lexer @#1\endcsname}%
717
\else
718
\unexpanded\expandafter\expandafter\expandafter{%719\csname minted@pyopt@global@#1\endcsname}%
720\fi\fi\fi\fi}
721 \def\minted@pyoptvalueof@block#1{%
722\ifcsname minted@pyopt@cmd@#1\endcsname723\unexpanded\expandafter\expandafter\expandafter{%724\csname minted@pyopt@cmd@#1\endcsname}%
725\else\ifcsname minted@pyopt@lexer@\minted@lexer @#1\endcsname
726\unexpanded\expandafter\expandafter\expandafter{%727\csname minted@pyopt@lexer@\minted@lexer @#1\endcsname}%
728
\else
729
\unexpanded\expandafter\expandafter\expandafter{%730\csname minted@pyopt@global@#1\endcsname}%731\fi\fi}\minted@pgfkeyscreate@tex\mintedtexoptvalueof\minted@usetexoptsnonpygments
Syntax: \minted@pgfkeyscreate@tex{〈processor〉}{〈key=initial value list〉}.
Currently, initial values are required. The key processing macros are written
to handle the possibility of optional initial values: If no initial value is set, use\pgfkeysnovalue.
\mintedtexoptvalueof is used for retrieving values via \edef.
\minted@usetexoptsnonpygments applies the tex options that aren’t used by
Pygments. It is initially empty and is redefined after tex options are defined. Unlike the\minted@usefvopts case, it isn’t possible to simply loop through all defined options;more specialized per-option handling is required, since some options are handled inseparate Pygments-related macros and there is no equivalent of \fvset.
732 \def\minted@pgfkeyscreate@tex#1#2{%
733\minted@forcsvlist{\minted@pgfkeycreate@tex{#1}}{#2}}734 \begingroup735 \catcode`\==12736 \gdef\minted@pgfkeycreate@tex#1#2{%
737\minted@pgfkeycreate@tex@i{#1}#2=\FV@Sentinel}
738 \gdef\minted@pgfkeycreate@tex@i#1#2=#3\FV@Sentinel{%739\if\relax\detokenize{#3}\relax
740\expandafter\minted@pgfkeycreate@tex@ii
741
\else
742
\expandafter\minted@pgfkeycreate@tex@iii
743
\fi
744
{#1}{#2}#3\FV@Sentinel}
745 \gdef\minted@pgfkeycreate@tex@ii#1#2\FV@Sentinel{%746\minted@pgfkeycreate@tex@iv{#1}{#2}{\pgfkeysnovalue}}
747 \gdef\minted@pgfkeycreate@tex@iii#1#2#3=\FV@Sentinel{%748\minted@pgfkeycreate@tex@iv{#1}{#2}{#3}}749 \endgroup750 \def\minted@pgfkeycreate@tex@iv#1#2#3{%751\def\minted@do##1{%
752\minted@iflexerscope{##1}%

56

753
{\minted@do@i{##1}{@\minted@lexer}}%
754{\minted@do@i{##1}{}}}
755\def\minted@do@i##1##2{%
756\if\relax\detokenize{#1}\relax
757\pgfkeys{%758/minted/##1/.cd,759#2/.code=\expandafter\def\csname minted@texopt@##1##2@#2\endcsname{####1},
760#2/.value required,
761
}%
762
\else
763
\pgfkeys{%764/minted/##1/.cd,765#2/.code=766\def\minted@tmp{####1}%
767\ifx\minted@tmp\minted@const@pgfkeysnovalue
768\expandafter\let\csname minted@texopt@##1##2@#2\endcsname\minted@tmp
769\else\ifcsname minted@opthandler@immediate@\string#1\endcsname
770#1{minted@texopt@##1##2@#2}{####1}%
771
\else
772
\expandafter\def\csname minted@texopt@##1##2@#2\endcsname{#1{####1}}%773\fi\fi,774#2/.value required,
775
}%
776
\fi
777
}%
778
\minted@forcsvlist{\minted@do}{\minted@optscopes}%779\pgfkeys{%780/minted/global/.cd,781#2=#3,
782}}
783 \def\mintedtexoptvalueof#1{%
784\ifbool{minted@isinline}%
785{\minted@texoptvalueof@inline{#1}}%
786{\minted@texoptvalueof@block{#1}}}
787 \def\minted@texoptvalueof@inline#1{%
788\ifcsname minted@texopt@cmd@#1\endcsname789\unexpanded\expandafter\expandafter\expandafter{%790\csname minted@texopt@cmd@#1\endcsname}%
791\else\ifcsname minted@texopt@lexerinline@\minted@lexer @#1\endcsname792\unexpanded\expandafter\expandafter\expandafter{%793\csname minted@texopt@lexerinline@\minted@lexer @#1\endcsname}%
794\else\ifcsname minted@texopt@globalinline@#1\endcsname
795\unexpanded\expandafter\expandafter\expandafter{%796\csname minted@texopt@globalinline@#1\endcsname}%
797\else\ifcsname minted@texopt@lexer@\minted@lexer @#1\endcsname
798\unexpanded\expandafter\expandafter\expandafter{%799\csname minted@texopt@lexer@\minted@lexer @#1\endcsname}%
800
\else
801
\unexpanded\expandafter\expandafter\expandafter{%802\csname minted@texopt@global@#1\endcsname}%803\fi\fi\fi\fi}
804 \def\minted@texoptvalueof@block#1{%
805\ifcsname minted@texopt@cmd@#1\endcsname
806\unexpanded\expandafter\expandafter\expandafter{%

57

807
\csname minted@texopt@cmd@#1\endcsname}%
808\else\ifcsname minted@texopt@lexer@\minted@lexer @#1\endcsname
809\unexpanded\expandafter\expandafter\expandafter{%810\csname minted@texopt@lexer@\minted@lexer @#1\endcsname}%
811
\else
812
\unexpanded\expandafter\expandafter\expandafter{%813\csname minted@texopt@global@#1\endcsname}%814\fi\fi}815 \def\minted@usetexoptsnonpygments{}

11.11.2 Option handlers\minted@opthandler@deforrestrictedescape
Syntax: \minted@opthandler@deforrestrictedescape{〈csname〉}{〈value〉}. 〈value〉is processed and then the result is stored in 〈csname〉.
Leave 〈value〉 unchanged if a single macro. Otherwise process it with \FVExtraDetokenizeREscVArg,
which performs backslash escapes but restricted to ASCII symbols and punctuation.
This guarantees exact output (no issues with spaces due to detokenizing alphabeticalcontrol sequences).
The \minted@opthandler@immediate@<macro_name> tells option processing to
invoke the macro immediately, instead of simply storing it as a value wrapper that will
only be invoked when the value is used. This provides immediate error messages in theevent of invalid escapes. \FVExtraDetokenizeREscVArg is not fully expandable, so
waiting to invoke it later when 〈value〉 is expanded (\edef) isn’t an option.
816 \def\minted@opthandler@deforrestrictedescape#1#2{%
817\if\relax\detokenize{#2}\relax
818\expandafter\def\csname#1\endcsname{#2}%819\else\if\relax\detokenize\expandafter{\@gobble#2}\relax
820\ifcat\relax\noexpand#2%
821\expandafter\expandafter\expandafter\minted@opthandler@deforrestrictedescape@i822\expandafter\@gobble\string#2\FV@Sentinel{#1}{#2}%
823
\else
824
\FVExtraDetokenizeREscVArg{\expandafter\def\csname#1\endcsname}{#2}%
825
\fi
826
\else
827
\FVExtraDetokenizeREscVArg{\expandafter\def\csname#1\endcsname}{#2}%828\fi\fi}829 \def\minted@opthandler@deforrestrictedescape@i#1#2\FV@Sentinel#3#4{%
830\ifcsname minted@isalpha\number`#1\endcsname
831\expandafter\def\csname#3\endcsname{#4}%
832
\else
833
\FVExtraDetokenizeREscVArg{\expandafter\def\csname#3\endcsname}{#4}%834\fi}
835 \expandafter\let\csname
836
minted@opthandler@immediate@\string\minted@opthandler@deforrestrictedescape837\endcsname\relax

11.11.3 Option definitions

fancyvrb• tabcolor: Visible tabs should have a specified color so that they don’t change
colors when used to indent multiline strings or comments.
58838 \mintedpgfkeyscreate{fv}{839baselinestretch,840
beameroverlays,
841
backgroundcolor,842
backgroundcolorvphantom,
843
bgcolor,844
bgcolorpadding,845
bgcolorvphantom,
846
breakafter,
847
breakafterinrun,
848
breakaftersymbolpost,849
breakaftersymbolpre,
850
breakanywhere,851
breakanywhereinlinestretch,852
breakanywheresymbolpost,853
breakanywheresymbolpre,
854
breakautoindent,
855
breakbefore,856
breakbeforeinrun,
857
breakbeforesymbolpost,858
breakbeforesymbolpre,859
breakbytoken,
860
breakbytokenanywhere,861
breakindent,
862
breakindentnchars,
863
breaklines,
864
breaksymbol,
865
breaksymbolindent,
866
breaksymbolindentleft,
867
breaksymbolindentleftnchars,
868
breaksymbolindentnchars,
869
breaksymbolindentright,
870
breaksymbolindentrightnchars,
871
breaksymbolleft,
872
breaksymbolright,
873
breaksymbolsep,
874
breaksymbolsepleft,
875
breaksymbolsepleftnchars,
876
breaksymbolsepnchars,
877
breaksymbolsepright,
878
breaksymbolseprightnchars,879
curlyquotes,
880
fillcolor,881
firstline,882
firstnumber,883
fontencoding,884
fontfamily,
885
fontseries,
886
fontshape,
887
fontsize,
888
formatcom,
889
frame,
890
framerule,891
framesep,59

892
highlightcolor,893
highlightlines,
894
label,
895
labelposition,896
lastline,897
linenos,898
listparameters,
899
numberblanklines,
900
numberfirstline,
901
numbers,902
numbersep,
903
obeytabs,904
resetmargins,905
rulecolor,906
samepage,907
showspaces,908
showtabs,
909
space,
910
spacecolor,911
stepnumber,
912
stepnumberfromfirst,
913
stepnumberoffsetvalues,
914
tab,
915
tabcolor=black,916
tabsize,917
xleftmargin,918
xrightmargin,
919 }minted (passed to Python)• PHP should use startinline for \mintinline.
920 \mintedpgfkeyscreate{py}{921autogobble<true>=false,922
encoding=utf8,
923
funcnamehighlighting<true>=true,924
gobble=0,925
gobblefilter=0,926
keywordcase=none,
927
literalenvname=MintedVerbatim,
928
mathescape<true>=false,929
python3<true>=true,
930
rangeregexmatchnumber=1,
931
rangeregexdotall<true>=false,932
rangeregexmultiline<true>=false,
933
startinline<true>=false,
934
stripall<true>=false,
935
stripnl<true>=false,
936
texcl<true>=false,
937
texcomments<true>=false,
938 }939 \mintedpgfkeyscreate[\minted@opthandler@deforrestrictedescape]{py}{940codetagify=,

60

941
escapeinside=,942
literatecomment=,
943
rangestartstring=,
944
rangestartafterstring=,
945
rangestopstring=,
946
rangestopbeforestring=,
947
rangeregex=,948 }949 \let\minted@tmplexer\minted@lexer
950 \def\minted@lexer{php}951 \pgfkeys{
952/minted/lexerinline/.cd,953
startinline=true,954 }955 \let\minted@lexer\minted@tmplexer

minted (kept in LATEX)• The \minted@def@optcl is for backward compatibility with versions of tcolorbox
that used this to define an envname option under minted v2.
956 \mintedpgfkeyscreate{tex}{957
envname=Verbatim,
958
ignorelexererrors=false,959
style=default,
960 }961 \pgfkeys{
962/minted/globalinline/.cd,963
envname=VerbEnv,
964 }965 \expandafter\def\expandafter\minted@usetexoptsnonpygments\expandafter{%
966\minted@usetexoptsnonpygments
967\edef\minted@literalenvname{\mintedpyoptvalueof{literalenvname}}%968\edef\minted@envname{\mintedtexoptvalueof{envname}}%969\expandafter\def\expandafter\minted@literalenv\expandafter{%970\csname \minted@literalenvname\endcsname}%
971\expandafter\def\expandafter\minted@endliteralenv\expandafter{%972\csname end\minted@literalenvname\endcsname}%
973\expandafter\expandafter\expandafter
974\let\expandafter\minted@literalenv\csname \minted@envname\endcsname975\expandafter\expandafter\expandafter
976\let\expandafter\minted@endliteralenv\csname end\minted@envname\endcsname}%
977 \ifcsname minted@def@optcl\endcsname
978\ifx\minted@def@optcl\relax979\let\minted@def@optcl\minted@undefined980\fi981 \fi
982 \providecommand{\minted@def@optcl}[4][]{%
983\minted@warning{Macro \string\minted@def@optcl\space is deprecated with minted v3984
and no longer has any effect}}6111.12 Caching, styles, and highlighting
11.12.1 Cache management\minted@addcachefilename\minted@cachefile<n>Track cache files that are used, so that unused files can be removed.
985 \newcounter{minted@numcachefiles}
986 \def\minted@addcachefilename#1{%
987\ifbool{minted@canexec}%
988{\stepcounter{minted@numcachefiles}%989\expandafter
990\xdef\csname minted@cachefile\arabic{minted@numcachefiles}\endcsname{#1}}%
991{}}\minted@clean
If the Python executable is available and was used, clean up temp files. If a cache isin use, also update the cache index and remove unused cache files.
Only create a .data.minted file if there is a cache list to save. Otherwise, no file isneeded.
Runs \AfterEndDocument so that all typesetting is complete, and thus the cache
list is complete. \minted@fasthighlightmode@checkend is placed within the same
\AfterEndDocument to guarantee correct ordering.
992 \def\minted@clean{%993\ifbool{minted@canexec}%
994{\ifbool{minted@diddetectconfig}{\minted@clean@i}{}}%
995{}}
996 \def\minted@clean@i{%997\ifnum\value{minted@numcachefiles}>0\relax
998\expandafter\minted@savecachelist
999
\fi
1000
\ifbool{minted@fasthighlightmode}%
1001
{}%
1002
{\minted@exec@clean
1003\global\boolfalse{minted@canexec}}}
1004 \def\minted@savecachelist{%1005\pydatasetfilename{\MintedDataFilename}%
1006\minted@fasthighlightmode@checkstart1007\pydatawritedictopen
1008\pydatawritekeyvalue{command}{clean}%1009\pydatawritekeyedefvalue{jobname}{\jobname}%
1010\pydatawritekeyedefvalue{timestamp}{\minted@timestamp}%
1011\pydatawritekeyedefvalue{cachepath}{\minted@cachepath}%1012\pydatawritekey{cachefiles}%1013\pydatawritemlvaluestart1014\pydatawritemlvalueline{[}%1015\setcounter{minted@tmpcnt}{1}%1016\loop\unless\ifnum\value{minted@tmpcnt}>\value{minted@numcachefiles}\relax
1017\expandafter\minted@savecachelist@writecachefile\expandafter{%1018\csname minted@cachefile\arabic{minted@tmpcnt}\endcsname}%
1019\expandafter\global\expandafter
1020\let\csname minted@cachefile\arabic{minted@tmpcnt}\endcsname\minted@undefined1021\stepcounter{minted@tmpcnt}%
1022\repeat62

1023\setcounter{minted@numcachefiles}{0}%1024\pydatawritemlvalueline{]}%1025\pydatawritemlvalueend1026\pydatawritedictclose
1027\ifbool{minted@fasthighlightmode}{}{\pydataclosefilename{\MintedDataFilename}}}1028 \begingroup1029 \catcode`\"=121030 \catcode`\,=121031 \gdef\minted@savecachelist@writecachefile#1{%
1032\expandafter\pydatawritemlvalueline\expandafter{\expandafter"#1",}}1033 \endgroup1034 \AfterEndDocument{%
1035\minted@clean
1036\minted@fasthighlightmode@checkend}

11.12.2 Style definitions\minted@patch@PygmentsStyledef
The macros generated by Pygments must be patched: the single quote macro isredefined for upquote compatibility, and the hyphen is redefined to prevent unintended
line breaks under LuaTeX.
1037 \def\minted@patch@PygmentsZsq{%
1038\ifcsname\minted@styleprefix Zsq\endcsname1039\ifcsstring{\minted@styleprefix Zsq}{\char`\'}{\minted@patch@PygmentsZsq@i}{}%
1040
\fi}
1041 \begingroup
1042 \catcode`\'=\active
1043 \gdef\minted@patch@PygmentsZsq@i{\def\PYGZsq{'}}1044 \endgroup1045 \def\minted@patch@PygmentsZhy{%1046\ifcsname\minted@styleprefix Zhy\endcsname
1047\ifcsstring{\minted@styleprefix Zhy}{\char`\-}{\def\PYGZhy{\mbox{-}}}{}%
1048
\fi}
1049 \def\minted@patch@ignorelexererrors{%
1050\edef\minted@tmp{\mintedtexoptvalueof{ignorelexererrors}}%1051\ifdefstring{\minted@tmp}{true}%1052{\expandafter\let\csname\minted@styleprefix @tok@err\endcsname\relax}%1053{}}
1054 \def\minted@patch@PygmentsStyledef{%
1055\minted@patch@PygmentsZsq
1056\minted@patch@PygmentsZhy
1057\minted@patch@ignorelexererrors}\minted@VerbatimPygments
Enable fancyvrb features for Pygments macros.
1058 \def\minted@VerbatimPygments{%
1059\expandafter\minted@VerbatimPygments@i\expandafter{%1060\csname\minted@styleprefix\endcsname}}
1061 \def\minted@VerbatimPygments@i#1{%
1062\VerbatimPygments{#1}{#1}}\minted@standardcatcodes

Set standard catcodes. Used before \input of style definitions and in reading theoptional argument of environments that wrap Pygments output.

63

1063 \def\minted@standardcatcodes{%1064\catcode`\\=01065\catcode`\{=11066\catcode`\}=21067\catcode`\#=61068\catcode`\ =101069\catcode`\@=111070\catcode`\`=121071\catcode`\==121072\catcode`\+=121073\catcode`\.=121074\catcode`\,=121075\catcode`\[=121076\catcode`\]=121077\catcode`\%=14}\minted@defstyle
Define highlighting style macros.
1078 \def\minted@defstyle{%
1079\edef\minted@tmp{\mintedtexoptvalueof{style}}%1080\expandafter\minted@defstyle@i\expandafter{\minted@tmp}}
1081 \def\minted@defstyle@i#1{%
1082\minted@ifalphanumhyphenunderscore{#1}%1083{\minted@defstyle@ii{#1}}%
1084{\minted@error{Highlighting style is set to "#1" but only style names with
1085
alphanumeric characters, hyphens, and underscores are supported;
1086
falling back to default style}%
1087\minted@defstyle@ii{default}}}
1088 \def\minted@defstyle@ii#1{%
1089\ifcsname minted@styledef@#1\endcsname1090\expandafter\@firstoftwo
1091
\else
1092
\expandafter\@secondoftwo
1093
\fi
1094
{\csname minted@styledef@#1\endcsname
1095\minted@patch@PygmentsStyledef
1096\minted@VerbatimPygments}%
1097{\minted@defstyle@load{#1}}}\minted@defstyle@load
Certain catcodes are required when loading Pygments style definitions from file.
• At sign @ would be handled by the \makeatletter within the Pygments styledefinition if the style were brought in via \input, but \makeatletter doesn’t
affect tokenization with the catchfile approach.
• Percent % may not have its normal meaning within a .dtx file.
• Backtick ` is made active by some babel package options, such as magyar.
• Catcodes for other symbolic/non-alphanumeric characters may (probably rarely)
not have their normal definitions.

\endlinechar also requires special handling to avoid introducing unwanted spaces.
The \begingroup...\endgroup around \minted@exec@styledef and associated messages is necessary to prevent errors related to the message file. If a style64does not exist, then the Python executable will create a _<hash>.message.minted file,which is brought in via \InputIfFileExists and generates an error message. After
this, there is an attempt to load the default style. If the default style needs to be generated, then \InputIfFileExists will attempt to bring in a _<hash>.message.minted
file regardless of whether it exists, unless it is wrapped in the \begingroup...\endgroup.
1098 \def\minted@catchfiledef#1#2{%
1099\CatchFileDef{#1}{#2}{\minted@standardcatcodes\endlinechar=-1}}
1100 \def\minted@defstyle@load#1{%
1101\minted@detectconfig
1102\ifbool{minted@cache}%1103{\edef\minted@styledeffilename{#1\detokenize{.style.minted}}%1104\edef\minted@styledeffilepath{\minted@cachepath\minted@styledeffilename}%
1105\IfFileExists{\minted@styledeffilepath}%
1106{\minted@defstyle@input{#1}}%
1107{\ifbool{minted@canexec}%
1108{\minted@defstyle@generate{#1}}%
1109{\minted@error{Missing definition for highlighting style "#1" (minted executable1110
is unavailable or disabled); attempting to substitute fallback style}%
1111\minted@defstyle@fallback{#1}}}}%
1112{\edef\minted@styledeffilename{%
1113\detokenize{_}\MintedJobnameMdfive\detokenize{.style.minted}}%1114\let\minted@styledeffilepath\minted@styledeffilename
1115\ifbool{minted@canexec}%
1116{\minted@defstyle@generate{#1}}%
1117{\minted@error{Missing definition for highlighting style "#1" (minted executable1118
is unavailable or disabled); attempting to substitute fallback style}%1119\minted@defstyle@fallback{#1}}}}1120 \def\minted@defstyle@input#1{%
1121\begingroup1122\minted@catchfiledef{\minted@tmp}{\minted@styledeffilepath}%
1123\minted@tmp
1124\ifcsname\minted@styleprefix\endcsname1125\expandafter\@firstoftwo
1126
\else
1127
\expandafter\@secondoftwo
1128
\fi
1129
{\expandafter\global\expandafter\let\csname minted@styledef@#1\endcsname\minted@tmp
1130\endgroup1131\ifbool{minted@cache}{\minted@addcachefilename{\minted@styledeffilename}}{}%
1132\csname minted@styledef@#1\endcsname1133\minted@patch@PygmentsStyledef1134\minted@VerbatimPygments}%
1135{\endgroup1136\ifbool{minted@canexec}%
1137{\minted@warning{Invalid or corrupted style definition file1138"\minted@styledeffilename"; attempting to regenerate}%
1139\minted@defstyle@generate{#1}}%
1140{\minted@error{Invalid or corrupted style definition file1141"\minted@styledeffilename"; attempting to substitute fallback style1142(minted executable is unavailable or disabled)}%1143\minted@defstyle@fallback{#1}}}}1144 \def\minted@defstyle@generate#1{%
1145\pydatasetfilename{\MintedDataFilename}%

65

1146
\minted@fasthighlightmode@checkstart
1147\pydatawritedictopen
1148\pydatawritekeyvalue{command}{styledef}%
1149\pydatawritekeyedefvalue{jobname}{\jobname}%
1150\pydatawritekeyedefvalue{timestamp}{\minted@timestamp}%
1151\pydatawritekeyedefvalue{currentfilepath}{\CurrentFilePath}%1152\pydatawritekeyedefvalue{currentfile}{\CurrentFile}%1153\pydatawritekeyedefvalue{inputlineno}{\the\inputlineno}%1154\pydatawritekeyedefvalue{cachepath}{\minted@cachepath}%
1155\pydatawritekeyedefvalue{styledeffilename}{\minted@styledeffilename}%
1156\pydatawritekeyvalue{style}{#1}%1157\pydatawritekeyedefvalue{commandprefix}{\minted@styleprefix}%
1158\pydatawritedictclose
1159\ifbool{minted@fasthighlightmode}%
1160{\minted@defstyle@fallback{#1}}%
1161{\pydataclosefilename{\MintedDataFilename}%
1162\begingroup1163\minted@exec@styledef
1164\ifx\minted@exec@warning\relax
1165
\else
1166
\expandafter\minted@exec@warning
1167
\fi
1168
\ifx\minted@exec@error\relax
1169\expandafter\minted@defstyle@generate@i
1170
\else
1171
\expandafter\minted@defstyle@generate@error
1172
\fi
1173
{#1}}}
1174 \def\minted@defstyle@generate@i#1{%
1175\endgroup1176\begingroup1177\minted@catchfiledef{\minted@tmp}{\minted@styledeffilepath}%
1178\minted@tmp
1179\ifcsname\minted@styleprefix\endcsname1180\expandafter\@firstoftwo
1181
\else
1182
\expandafter\@secondoftwo
1183
\fi
1184
{\expandafter\global\expandafter\let\csname minted@styledef@#1\endcsname\minted@tmp
1185\endgroup1186\ifbool{minted@cache}{\minted@addcachefilename{\minted@styledeffilename}}{}%
1187\csname minted@styledef@#1\endcsname
1188\minted@patch@PygmentsStyledef1189\minted@VerbatimPygments}%
1190{\endgroup
1191\minted@error{Failed to create style definition file "\minted@styledeffilename"1192(no error message, see "\MintedErrlogFilename" if it exists);
1193
attempting to substitute fallback style}%
1194\minted@defstyle@fallback{#1}}}
1195 \def\minted@defstyle@generate@error#1{%
1196\minted@exec@error
1197\endgroup1198\minted@defstyle@fallback{#1}}1199 \def\minted@defstyle@fallback#1{%

66

1200
1201
1202
1203
1204
1205
1206
1207
1208

\ifstrequal{#1}{default}%{\expandafter\global\expandafter\let\csname minted@styledef@default\endcsname\minted@styledeffallback}%{\ifcsname minted@styledef@default\endcsname\else\minted@defstyle@load{default}%\fi\expandafter\let\expandafter\minted@tmp\csname minted@styledef@default\endcsname\expandafter\global\expandafter\let\csname minted@styledef@#1\endcsname\minted@tmp}}\minted@styledeffallback

Basic style definition to make .highlight.minted cache files usable if no styles
exist, not even the default style, and no styles can be generated.

1209 \def\minted@styledeffallback{%
1210\expandafter\def\csname\minted@styleprefix\endcsname##1##2{##2}%
1211\expandafter\def\csname\minted@styleprefix Zbs\endcsname{\char`\\}%
1212\expandafter\def\csname\minted@styleprefix Zus\endcsname{\char`\_}%
1213\expandafter\def\csname\minted@styleprefix Zob\endcsname{\char`\{}%
1214\expandafter\def\csname\minted@styleprefix Zcb\endcsname{\char`\}}%
1215\expandafter\def\csname\minted@styleprefix Zca\endcsname{\char`\^}%
1216\expandafter\def\csname\minted@styleprefix Zam\endcsname{\char`\&}%
1217\expandafter\def\csname\minted@styleprefix Zlt\endcsname{\char`\<}%
1218\expandafter\def\csname\minted@styleprefix Zgt\endcsname{\char`\>}%
1219\expandafter\def\csname\minted@styleprefix Zsh\endcsname{\char`\#}%
1220\expandafter\def\csname\minted@styleprefix Zpc\endcsname{\char`\%}%
1221\expandafter\def\csname\minted@styleprefix Zdl\endcsname{\char`\$}%
1222\expandafter\def\csname\minted@styleprefix Zhy\endcsname{\char`\-}%
1223\expandafter\def\csname\minted@styleprefix Zsq\endcsname{\char`\'}%
1224\expandafter\def\csname\minted@styleprefix Zdq\endcsname{\char`\"}%
1225\expandafter\def\csname\minted@styleprefix Zti\endcsname{\char`\~}%
1226\minted@patch@PygmentsStyledef
1227\minted@VerbatimPygments}

11.12.3 Lexer-specific line numbering

minted@FancyVerbLineTemp

Temporary counter for storing and then restoring the value of FancyVerbLine.
When using the lexerlinenos option, we need to store the current value of FancyVerbLine,then set FancyVerbLine to the current value of a lexer-specific counter, and finallyrestore FancyVerbLine to its initial value after the current chunk of code has beentypeset.

1228 \newcounter{minted@FancyVerbLineTemp}\minted@lexerlinenoson\minted@lexerlinenosoff\minted@inputlexerlinenoson\minted@inputlexerlinenosoff

Line counters on a per-lexer basis for minted and \mintinline; line counters on a
per-lexer basis for \inputminted.

1229 \def\minted@lexerlinenoson{%1230\ifcsname c@minted@lexer\minted@lexer\endcsname
1231
\else
1232
\newcounter{minted@lexer\minted@lexer}%

67

1233
\fi
1234
\setcounter{minted@FancyVerbLineTemp}{\value{FancyVerbLine}}%1235\setcounter{FancyVerbLine}{\value{minted@lexer\minted@lexer}}}
1236 \def\minted@lexerlinenosoff{%1237\setcounter{minted@lexer\minted@lexer}{\value{FancyVerbLine}}%1238\setcounter{FancyVerbLine}{\value{minted@FancyVerbLineTemp}}}1239 \ifbool{minted@inputlexerlinenos}%
1240 {\let\minted@inputlexerlinenoson\minted@lexerlinenoson
1241\let\minted@inputlexerlinenosoff\minted@lexerlinenosoff}%
1242 {\let\minted@inputlexerlinenoson\relax
1243\let\minted@inputlexerlinenosoff\relax1244\ifbool{minted@lexerlinenos}
1245
{}%
1246
{\let\minted@lexerlinenoson\relax
1247\let\minted@lexerlinenosoff\relax}}\minted@codewrapper

Wrapper around typeset code. \minted@inputfilepath will exist when the codeis brought in from an external file.

1248 \def\minted@codewrapper#1{%
1249\ifcsname minted@inputfilepath\endcsname
1250\minted@inputlexerlinenoson
1251
\else
1252
\minted@lexerlinenoson
1253
\fi
1254
#1%
1255
\ifcsname minted@inputfilepath\endcsname
1256\minted@inputlexerlinenosoff
1257
\else
1258
\minted@lexerlinenosoff
1259
\fi}

11.12.4 Highlighting code

\minted@highlight\minted@highlightinputfile

Highlight code previously stored in buffer minted@tmpdatabuffer, or code in an
external file.
\minted@defstyle will invoke \minted@detectconfig the first time a style isloaded, so no separate \minted@detectconfig is needed.
The default \minted@highlight@fallback inserts a placeholder. Typically commands/environments will redefine the fallback locally to inserted a verbatim approximation of code that could not be highlighted.
Python-related options are buffered/written under a pyopt namespace. This prevents the possibility of naming collisions between options and other data that must be
passed to Python.
Some data such as jobname, timestamp, and cachepath should be written to file,
but not used in hashing because otherwise it would unnecessarily make the cache files
dependent on irrelevant data.

1260 \def\minted@debug@input{%
1261\ifbool{minted@debug}%1262{\immediate\typeout{%
1263
minted debug: \string\input\space at

68

1264
\ifx\CurrentFile\@empty\else\CurrentFile\space\fi line \the\inputlineno}}%1265{}}
1266 \def\minted@highlight{%
1267\minted@defstyle1268\pydatasetbuffername{minted@tmpdatabuffer}%
1269\pydatabufferkeyvalue{command}{highlight}%
1270\pydatabufferkey{code}%1271\pydatabuffermlvaluestart1272\setcounter{minted@tmpcnt}{1}%1273\loop\unless\ifnum\value{minted@tmpcnt}>\value{minted@tmpcodebufferlength}\relax
1274\expandafter\let\expandafter
1275\minted@tmp\csname minted@tmpcodebufferline\arabic{minted@tmpcnt}\endcsname
1276\expandafter\pydatabuffermlvalueline\expandafter{\minted@tmp}%
1277\stepcounter{minted@tmpcnt}%
1278\repeat1279\pydatabuffermlvalueend
1280\minted@highlight@i}
1281 \def\minted@highlightinputfile{%
1282\minted@defstyle1283\edef\minted@inputfilemdfivesum{\pdf@filemdfivesum{\minted@inputfilepath}}%1284\ifx\minted@inputfilemdfivesum\@empty
1285\expandafter\@firstoftwo
1286
\else
1287
\expandafter\@secondoftwo
1288
\fi
1289
{\minted@error{Cannot find input file "\minted@inputfilepath"; inserting placeholder}%1290\minted@insertplaceholder}%1291{\pydatasetbuffername{minted@tmpdatabuffer}%
1292\pydatabufferkeyvalue{command}{highlight}%
1293\pydatabufferkeyedefvalue{inputfilepath}{\minted@inputfilepath}%1294\pydatabufferkeyedefvalue{inputfilemdfivesum}{\minted@inputfilemdfivesum}%
1295\minted@highlight@i}}1296 \def\minted@def@FV@GetKeyValues@standardcatcodes{%1297\let\minted@FV@GetKeyValues@orig\FV@GetKeyValues
1298\def\FV@GetKeyValues##1{%
1299\begingroup
1300\minted@standardcatcodes
1301\minted@FV@GetKeyValues@i{##1}}%
1302\def\minted@FV@GetKeyValues@i##1[##2]{%
1303\endgroup1304\let\FV@GetKeyValues\minted@FV@GetKeyValues@orig
1305\let\minted@FV@GetKeyValues@i\minted@undefined
1306\FV@GetKeyValues{##1}[##2]}}
1307 \def\minted@highlight@i{%1308\pydatabufferkeyedefvalue{pyopt.lexer}{\minted@lexer}%
1309\pydatabufferkeyedefvalue{pyopt.commandprefix}{\minted@styleprefix}%1310\minted@forcsvlist{\minted@highlight@bufferpykeys}{\minted@optkeyslist@py}%
1311\ifbool{minted@cache}%1312{\edef\minted@highlightfilename{\pydatabuffermdfivesum\detokenize{.highlight.minted}}%1313\edef\minted@highlightfilepath{\minted@cachepath\minted@highlightfilename}%
1314\IfFileExists{\minted@highlightfilepath}%
1315{\minted@codewrapper{%1316\minted@def@FV@GetKeyValues@standardcatcodes
1317\minted@debug@input

69

1318
\input{\minted@highlightfilepath}}%1319\minted@addcachefilename{\minted@highlightfilename}}%1320{\ifbool{minted@canexec}%
1321{\minted@highlight@create}%1322{\minted@error{Cannot highlight code (minted executable is unavailable or1323
disabled); attempting to typeset without highlighting}%
1324\minted@highlight@fallback}}}%1325{\edef\minted@highlightfilename{%
1326\detokenize{_}\MintedJobnameMdfive\detokenize{.highlight.minted}}%1327\let\minted@highlightfilepath\minted@highlightfilename1328\ifbool{minted@canexec}%
1329{\minted@highlight@create}%
1330{\minted@error{Cannot highlight code (minted executable is unavailable or1331
disabled); attempting to typeset without highlighting}%
1332\minted@highlight@fallback}}%
1333\pydataclearbuffername{minted@tmpdatabuffer}}
1334 \def\minted@highlight@bufferpykeys#1{%
1335\edef\minted@tmp{\mintedpyoptvalueof{#1}}%
1336\ifx\minted@tmp\minted@const@pgfkeysnovalue
1337
\else
1338
\pydatabufferkeyedefvalue{pyopt.#1}{\minted@tmp}%
1339
\fi}
1340 \def\minted@highlight@create{%1341\pydatasetfilename{\MintedDataFilename}%
1342\minted@fasthighlightmode@checkstart1343\pydatawritedictopen
1344\pydatawritebuffer
1345\pydatawritekeyedefvalue{jobname}{\jobname}%
1346\pydatawritekeyedefvalue{timestamp}{\minted@timestamp}%1347\pydatawritekeyedefvalue{currentfilepath}{\CurrentFilePath}%1348\pydatawritekeyedefvalue{currentfile}{\CurrentFile}%1349\pydatawritekeyedefvalue{inputlineno}{\the\inputlineno}%
1350\pydatawritekeyedefvalue{cachepath}{\minted@cachepath}%
1351\pydatawritekeyedefvalue{highlightfilename}{\minted@highlightfilename}%1352\pydatawritedictclose
1353\ifbool{minted@fasthighlightmode}%1354{\minted@insertplaceholder}%1355{\pydataclosefilename{\MintedDataFilename}%
1356\begingroup1357\minted@exec@highlight1358\IfFileExists{\minted@highlightfilepath}%
1359{\ifx\minted@exec@warning\relax
1360
\else
1361
\expandafter\minted@exec@warning
1362
\fi
1363
\ifx\minted@exec@error\relax
1364
\else
1365
\expandafter\minted@exec@error
1366
\fi
1367
\endgroup1368\minted@codewrapper{%1369\minted@def@FV@GetKeyValues@standardcatcodes
1370\minted@debug@input
1371\input{\minted@highlightfilepath}}%

70

1372
\ifbool{minted@cache}{\minted@addcachefilename{\minted@highlightfilename}}{}}%
1373{\ifx\minted@exec@warning\relax
1374
\else
1375
\expandafter\minted@exec@warning
1376
\fi
1377
\ifx\minted@exec@error\relax
1378\minted@error{Minted executable failed during syntax highlighting1379
but returned no error message (see if "\MintedErrlogFilename" exists)}%
1380
\else
1381
\expandafter\minted@exec@error
1382
\fi
1383
\endgroup1384\minted@highlight@fallback}}}
1385 \def\minted@highlight@fallback{%
1386\minted@insertplaceholder}11.13 Public API\setminted
Set global or lexer-level options.
1387 \newcommand{\setminted}[2][]{%
1388\ifstrempty{#1}%1389{\pgfkeys{/minted/global/.cd,#2}}%
1390{\let\minted@tmplexer\minted@lexer
1391\edef\minted@lexer{#1}%1392\pgfkeys{/minted/lexer/.cd,#2}%1393\let\minted@lexer\minted@tmplexer}}\setmintedinline

Set global or lexer-level options, but only for inline (\mintinline) content. Thesesettings will override the corresponding \setminted settings.

1394 \newcommand{\setmintedinline}[2][]{%
1395\ifstrempty{#1}%1396{\pgfkeys{/minted/globalinline/.cd,#2}}%
1397{\let\minted@tmplexer\minted@lexer
1398\edef\minted@lexer{#1}%1399\pgfkeys{/minted/lexerinline/.cd,#2}%
1400\let\minted@lexer\minted@tmplexer}}\usemintedstyle

Set style. This is a holdover from minted v1, before \setminted could be used to set
the style.

1401 \newcommand{\usemintedstyle}[2][]{\setminted[#1]{style=#2}}\mintinline

Define an inline command. This is modeled after the reimplemented \Verb fromfvextra. See the fvextra documentation for details about expansion handling, argument

reading, and (re)tokenization.
Everything needs to be within a \begingroup...\endgroup to prevent settingsfrom escaping.
\RobustMintInlineProcess@verbatim doesn’t need an explicit \FVExtraRetokenizeVArg
step because this is done when the code is inserted into \Verb.
1402 \def\mintinline{%
1403\FVExtraRobustCommand\RobustMintInline\FVExtraUnexpandedReadStarOArgMArgBVArg}

71

1404 \FVExtrapdfstringdefDisableCommands{%1405\def\RobustMintInline{}}1406 \newrobustcmd{\RobustMintInline}[2][]{%
1407\ifbool{FVExtraRobustCommandExpanded}%1408{\@ifnextchar\bgroup
1409{\FVExtraReadVArg{\RobustMintInlineProcess{#1}{#2}}}%1410{\minted@error{Inline delimiters must be paired curly braces in this context}}}%1411{\FVExtraReadVArg{\RobustMintInlineProcess{#1}{#2}}}}1412 \def\RobustMintInlineProcess@highlight#1#2#3{%
1413\begingroup1414\booltrue{minted@isinline}%
1415\ifstrempty{#1}{}{\pgfkeys{/minted/cmd/.cd,#1}}%
1416\edef\minted@lexer{#2}%1417\minted@usefvopts
1418\minted@usetexoptsnonpygments
1419\FVExtraDetokenizeVArg{%
1420\FVExtraRetokenizeVArg{\RobustMintInlineProcess@highlight@i}{\FV@CatCodes}}{#3}}1421 \def\RobustMintInlineProcess@highlight@i#1{%
1422\expandafter\def\csname minted@tmpcodebufferline1\endcsname{#1}%1423\setcounter{minted@tmpcodebufferlength}{1}%1424\let\minted@highlight@fallback\RobustMintInlineProcess@highlight@fallback
1425\minted@highlight1426\setcounter{minted@tmpcodebufferlength}{0}%1427\endgroup}
1428 \def\RobustMintInlineProcess@highlight@fallback{%
1429\minted@useadditionalfvoptsnopy
1430\fvset{extra=true}%
1431\minted@codewrapper{%1432\expandafter\let\expandafter\minted@tmp\csname minted@tmpcodebufferline1\endcsname1433\expandafter\Verb\expandafter{\minted@tmp}}}1434 \def\RobustMintInlineProcess@placeholder#1#2#3{%
1435\begingroup1436\booltrue{minted@isinline}%
1437\minted@insertplaceholder
1438\endgroup}
1439 \def\RobustMintInlineProcess@verbatim#1#2#3{%
1440\begingroup1441\booltrue{minted@isinline}%
1442\ifstrempty{#1}{}{\pgfkeys{/minted/cmd/.cd,#1}}%
1443\edef\minted@lexer{#2}%1444\minted@usefvopts
1445\minted@useadditionalfvoptsnopy
1446\minted@usetexoptsnonpygments
1447\fvset{extra=true}%
1448\minted@codewrapper{\Verb{#3}}%
1449\endgroup}1450 \ifbool{minted@placeholder}%1451 {\let\RobustMintInlineProcess\RobustMintInlineProcess@placeholder}%1452 {\ifbool{minted@verbatim}%
1453{\let\RobustMintInlineProcess\RobustMintInlineProcess@verbatim}%
1454{\let\RobustMintInlineProcess\RobustMintInlineProcess@highlight}}\mint

Highlight a single line of code. This is essentially a shortcut for the minted environment when there is only a single line of code. The implementation follows \mintinline
72

for argument reading and processing, but then typesets the code as an environment
rather than command. The \@doendpe ensures proper paragraph indentation for following text (immediately following text with no intervening blank lines does not begin a
new paragraph).
1455 \def\mint{%
1456\FVExtraRobustCommand\RobustMint\FVExtraUnexpandedReadStarOArgMArgBVArg}
1457 \FVExtrapdfstringdefDisableCommands{%1458\def\RobustMint{}}
1459 \newrobustcmd{\RobustMint}[2][]{%
1460\ifbool{FVExtraRobustCommandExpanded}%
1461{\@ifnextchar\bgroup
1462{\FVExtraReadVArg{\RobustMintProcess{#1}{#2}}}%
1463{\minted@error{Delimiters must be paired curly braces in this context}}}%1464{\FVExtraReadVArg{\RobustMintProcess{#1}{#2}}}}1465 \def\RobustMintProcess@highlight#1#2#3{%
1466\begingroup1467\ifstrempty{#1}{}{\pgfkeys{/minted/cmd/.cd,#1}}%
1468\edef\minted@lexer{#2}%1469\minted@usefvopts
1470\minted@usetexoptsnonpygments
1471\FVExtraDetokenizeVArg{%
1472\FVExtraRetokenizeVArg{\RobustMintProcess@highlight@i}{\FV@CatCodes}}{#3}}1473 \def\RobustMintProcess@highlight@i#1{%
1474\expandafter\def\csname minted@tmpcodebufferline1\endcsname{#1}%1475\setcounter{minted@tmpcodebufferlength}{1}%1476\let\minted@highlight@fallback\RobustMintProcess@highlight@fallback
1477\minted@highlight1478\setcounter{minted@tmpcodebufferlength}{0}%1479\endgroup}
1480 \def\RobustMintProcess@highlight@fallback{%
1481\minted@useadditionalfvoptsnopy
1482\minted@codewrapper{%1483\VerbatimInsertBuffer[buffername=minted@tmpcodebuffer,insertenvname=\minted@envname]}}1484 \def\RobustMintProcess@placeholder#1#2#3{%
1485\minted@insertplaceholder}1486 \def\RobustMintProcess@verbatim#1#2#3{%
1487\begingroup1488\ifstrempty{#1}{}{\pgfkeys{/minted/cmd/.cd,#1}}%
1489\edef\minted@lexer{#2}%1490\minted@usefvopts
1491\minted@useadditionalfvoptsnopy
1492\minted@usetexoptsnonpygments
1493\FVExtraDetokenizeVArg{%
1494\FVExtraRetokenizeVArg{\RobustMintProcess@verbatim@i}{\FV@CatCodes}}{#3}}1495 \def\RobustMintProcess@verbatim@i#1{%
1496\expandafter\def\csname minted@tmpcodebufferline1\endcsname{#1}%1497\setcounter{minted@tmpcodebufferlength}{1}%1498\minted@codewrapper{%
1499\VerbatimInsertBuffer[buffername=minted@tmpcodebuffer,insertenvname=\minted@envname]}%1500\setcounter{minted@tmpcodebufferlength}{0}%1501\endgroup}1502 \ifbool{minted@placeholder}%1503 {\let\RobustMintProcess\RobustMintProcess@placeholder}%1504 {\ifbool{minted@verbatim}%73

{\let\RobustMintProcess\RobustMintProcess@verbatim}%{\let\RobustMintProcess\RobustMintProcess@highlight}}

1505
1506

minted (env.)
Highlight a longer piece of code inside a verbatim environment.
1507 \newenvironment{minted}[2][]%1508 {\VerbatimEnvironment
1509\MintedBegin{#1}{#2}}%
1510 {\MintedEnd}
1511 \def\MintedBegin@highlight#1#2{%
1512\ifstrempty{#1}{}{\pgfkeys{/minted/cmd/.cd,#1}}%
1513\edef\minted@lexer{#2}%1514\minted@usefvopts
1515\minted@usetexoptsnonpygments
1516\begin{VerbatimBuffer}[buffername=minted@tmpcodebuffer,globalbuffer=true]}
1517 \def\MintedEnd@highlight{%
1518\end{VerbatimBuffer}%
1519\let\minted@highlight@fallback\MintedEnv@highlight@fallback
1520\minted@highlight1521\VerbatimClearBuffer[buffername=minted@tmpcodebuffer]}
1522 \def\MintedEnv@highlight@fallback{%
1523\minted@useadditionalfvoptsnopy
1524\minted@codewrapper{%
1525\VerbatimInsertBuffer[buffername=minted@tmpcodebuffer,insertenvname=\minted@envname]}}1526 \def\MintedBegin@placeholder#1#2{%
1527\begin{VerbatimBuffer}[buffername=minted@tmpcodebuffer]}
1528 \def\MintedEnd@placeholder{%1529\end{VerbatimBuffer}%
1530\minted@insertplaceholder}1531 \def\MintedBegin@verbatim#1#2{%
1532\ifstrempty{#1}{}{\pgfkeys{/minted/cmd/.cd,#1}}%
1533\edef\minted@lexer{#2}%1534\minted@usefvopts
1535\minted@useadditionalfvoptsnopy
1536\minted@usetexoptsnonpygments
1537\begin{\minted@envname}}
1538 \def\MintedEnd@verbatim{%
1539\end{\minted@envname}}
1540 \ifbool{minted@placeholder}%1541 {\let\MintedBegin\MintedBegin@placeholder
1542\let\MintedEnd\MintedEnd@placeholder}%1543 {\ifbool{minted@verbatim}%
1544{\let\MintedBegin\MintedBegin@verbatim
1545\let\MintedEnd\MintedEnd@verbatim}%
1546{\let\MintedBegin\MintedBegin@highlight1547\let\MintedEnd\MintedEnd@highlight}}\inputminted
Highlight an external source file.
1548 \def\minted@readinputmintedargs#1#{%
1549\minted@readinputmintedargs@i{#1}}1550 \def\minted@readinputmintedargs@i#1#2#3{%
1551\FVExtraAlwaysUnexpanded{\minted@readinputmintedargs#1{#2}{#3}}}
1552 \FVExtrapdfstringdefDisableCommands{%1553\makeatletter

74

1554
\def\minted@readinputmintedargs@i#1#2#3{%
1555\detokenize{<input from file "}#3\detokenize{">}}%
1556\makeatother}
1557 \def\inputminted{%
1558\FVExtraRobustCommand\RobustInputMinted\minted@readinputmintedargs}
1559 \FVExtrapdfstringdefDisableCommands{%1560\def\RobustInputMinted{}}1561 \newrobustcmd{\RobustInputMinted}[3][]{%
1562\RobustInputMintedProcess{#1}{#2}{#3}}1563 \def\RobustInputMintedProcess@highlight#1#2#3{%
1564\begingroup1565\ifstrempty{#1}{}{\pgfkeys{/minted/cmd/.cd,#1}}%
1566\edef\minted@lexer{#2}%1567\edef\minted@inputfilepath{#3}%1568\minted@usefvopts
1569\minted@usetexoptsnonpygments
1570\let\minted@highlight@fallback\RobustInputMintedProcess@highlight@fallback
1571\minted@highlightinputfile1572\endgroup}1573 \def\RobustInputMintedProcess@highlight@fallback{%
1574\minted@useadditionalfvoptsnopy
1575\minted@codewrapper{%1576\csname\minted@envname Input\endcsname{\minted@inputfilepath}}}1577 \def\RobustInputMintedProcess@placeholder#1#2#3{%
1578\minted@insertplaceholder}1579 \def\RobustInputMintedProcess@verbatim#1#2#3{%
1580\begingroup1581\ifstrempty{#1}{}{\pgfkeys{/minted/cmd/.cd,#1}}%
1582\edef\minted@lexer{#2}%1583\edef\minted@inputfilepath{#3}%1584\minted@usefvopts
1585\minted@useadditionalfvoptsnopy
1586\minted@usetexoptsnonpygments
1587\minted@codewrapper{%1588\csname\minted@envname Input\endcsname{\minted@inputfilepath}}%1589\endgroup}
1590 \ifbool{minted@placeholder}%1591 {\let\RobustInputMintedProcess\RobustInputMintedProcess@placeholder}%1592 {\ifbool{minted@verbatim}%
1593{\let\RobustInputMintedProcess\RobustInputMintedProcess@verbatim}%
1594{\let\RobustInputMintedProcess\RobustInputMintedProcess@highlight}}

11.14 Command shortcuts
Allow the user to define shortcuts for the highlighting commands.

\newminted

Define a new language-specific alias for the minted environment.
The starred * version of the environment takes a mandatory argument containing
options. It is retained for backward compatibility purposes with minted v1 and v2.
minted v3 added support for an optional argument to the standard environment, so thestarred version is no longer necessary.
The ^^M is needed because \FVExtraReadOArgBeforeVEnv strips a following ^^M(basically the newline), but fancyvrb environments expect ^^M before the start of envi-

75ronment contents.
1595 \newcommand{\newminted}[3][]{%
1596\ifstrempty{#1}%1597{\newminted@i{#2code}{#2}{#3}}%
1598{\newminted@i{#1}{#2}{#3}}}
1599 \begingroup1600 \catcode`\^^M=\active%
1601 \gdef\newminted@i#1#2#3{%
1602\expandafter\def\csname#1@i\endcsname##1{%
1603\begin{minted}[#3,##1]{#2}^^M}%
1604\newenvironment{#1}%1605{\VerbatimEnvironment%
1606\FVExtraReadOArgBeforeVEnv{\csname#1@i\endcsname}}%1607{\end{minted}}%1608\newenvironment{#1*}[1]%1609{\VerbatimEnvironment%
1610\begin{minted}[#3,##1]{#2}}%
1611{\end{minted}}}%1612 \endgroup\newmint

Define a new language-specific alias for the \mint short form.

1613 \newcommand{\newmint}[3][]{%
1614\ifstrempty{#1}%1615{\edef\minted@tmp{#2}}%
1616{\edef\minted@tmp{#1}}1617\expandafter\newmint@i\expandafter{\minted@tmp}{#2}{#3}}1618 \def\newmint@i#1#2#3{%
1619\expandafter\newcommand\csname#1\endcsname{%
1620\expandafter\FVExtraRobustCommand\csname RobustNewMint#1\endcsname
1621\FVExtraUnexpandedReadStarOArgBVArg}%
1622\FVExtrapdfstringdefDisableCommands{%
1623\expandafter\def\csname RobustNewMint#1\endcsname{}}%1624\expandafter\newrobustcmd\csname RobustNewMint#1\endcsname{%
1625\FVExtraReadOArgBeforeVArg{\csname RobustNewMint#1@i\endcsname}}%1626\expandafter\def\csname RobustNewMint#1@i\endcsname##1{%
1627\ifbool{FVExtraRobustCommandExpanded}%1628{\@ifnextchar\bgroup
1629{\FVExtraReadVArg{\csname RobustNewMint#1@ii\endcsname{##1}}}%
1630{\minted@error{Delimiters must be paired curly braces in this context}}}%1631{\FVExtraReadVArg{\csname RobustNewMint#1@ii\endcsname{##1}}}}1632\expandafter\def\csname RobustNewMint#1@ii\endcsname##1##2{%
1633\RobustMintProcess{#3,##1}{#2}{##2}}}\newmintedfile

Define a new language-specific alias for \inputminted.

1634 \def\minted@readnewmintedfileargs#1#{%
1635\minted@readnewmintedfileargs@i{#1}}1636 \def\minted@readnewmintedfileargs@i#1#2{%
1637\FVExtraAlwaysUnexpanded{\minted@readnewmintedfileargs#1{#2}}}
1638 \FVExtrapdfstringdefDisableCommands{%
1639\makeatletter
1640\def\minted@readnewmintedfileargs@i#1#2{%
1641\detokenize{<input from file "}#2\detokenize{">}}%
1642\makeatother}76

1643 \newcommand{\newmintedfile}[3][]{%
1644\ifstrempty{#1}%1645{\edef\minted@tmp{#2file}}%1646{\edef\minted@tmp{#1}}%
1647\expandafter\newmintedfile@i\expandafter{\minted@tmp}{#2}{#3}}
1648 \def\newmintedfile@i#1#2#3{%
1649\expandafter\newcommand\csname#1\endcsname{%
1650\expandafter\FVExtraRobustCommand\csname RobustNewMintedFile#1\endcsname
1651\minted@readnewmintedfileargs}%
1652\FVExtrapdfstringdefDisableCommands{%
1653\expandafter\def\csname RobustNewMintedFile#1\endcsname{}}%1654\expandafter\newrobustcmd\csname RobustNewMintedFile#1\endcsname[2][]{%
1655\RobustInputMintedProcess{#3,##1}{#2}{##2}}}\newmintinline

Define an alias for \mintinline.

1656 \newcommand{\newmintinline}[3][]{%
1657\ifstrempty{#1}%1658{\edef\minted@tmp{#2inline}}%1659{\edef\minted@tmp{#1}}%
1660\expandafter\newmintinline@i\expandafter{\minted@tmp}{#2}{#3}}1661 \def\newmintinline@i#1#2#3{%
1662\expandafter\newcommand\csname#1\endcsname{%
1663\expandafter\FVExtraRobustCommand\csname RobustNewMintInline#1\endcsname
1664\FVExtraUnexpandedReadStarOArgBVArg}%
1665\FVExtrapdfstringdefDisableCommands{%
1666\expandafter\def\csname RobustNewMintInline#1\endcsname{}}%1667\expandafter\newrobustcmd\csname RobustNewMintInline#1\endcsname{%
1668\FVExtraReadOArgBeforeVArg{\csname RobustNewMintInline#1@i\endcsname}}%1669\expandafter\def\csname RobustNewMintInline#1@i\endcsname##1{%
1670\ifbool{FVExtraRobustCommandExpanded}%
1671{\@ifnextchar\bgroup
1672{\FVExtraReadVArg{\csname RobustNewMintInline#1@ii\endcsname{##1}}}%
1673{\minted@error{Inline delimiters must be paired curly braces in this context}}}%1674{\FVExtraReadVArg{\csname RobustNewMintInline#1@ii\endcsname{##1}}}}1675\expandafter\def\csname RobustNewMintInline#1@ii\endcsname##1##2{%
1676\RobustMintInlineProcess{#3,##1}{#2}{##2}}}

11.15 Float support
listing (env.)
Define a new floating environment to use for floated listings. This is defined conditionally based on the newfloat package option.
1677 \ifbool{minted@newfloat}%
1678 {\@ifundefined{minted@float@within}%1679{\DeclareFloatingEnvironment[fileext=lol,placement=tbp]{listing}}%
1680{\def\minted@tmp#1{%
1681\DeclareFloatingEnvironment[fileext=lol,placement=tbp,within=#1]{listing}}%1682\expandafter\minted@tmp\expandafter{\minted@float@within}}}%1683 {\@ifundefined{minted@float@within}%1684{\newfloat{listing}{tbp}{lol}}%
1685{\newfloat{listing}{tbp}{lol}[\minted@float@within]}}

77

The following macros only apply when listing is created with the float package. When listing is created with newfloat, its properties should be modified using
newfloat’s \SetupFloatingEnvironment.
1686 \ifminted@newfloat\else\listingcaption
The name that is displayed before each individual listings caption and its number.
The macro \listingscaption can be redefined by the user.
1687 \newcommand{\listingscaption}{Listing}

The following definition should not be changed by the user.
1688 \floatname{listing}{\listingscaption}\listoflistingscaption
The caption that is displayed for the list of listings.
1689 \newcommand{\listoflistingscaption}{List of Listings}\listoflistings

Used to produce a list of listings (like \listoffigures etc.). This may well clash
with other packages (for example, listings) but we choose to ignore this since these two
packages shouldn’t be used together in the first place.

1690 \providecommand{\listoflistings}{\listof{listing}{\listoflistingscaption}}

Again, the preceding macros only apply when float is used to create listings, so weneed to end the conditional.
1691 \fi78