# Changelog — minted LaTeX package ## v3.4.0 (2024/11/17) * Replaced temp counter with a macro to prevent issues with commands and environments such as `\text` from `amsmath` that modify counter behavior (#423). * When `highlightmode` causes all code to be highlighted at once, duplicate highlighting is now detected and skipped. ## v3.3.0 (2024/11/10) * Fixed a bug from v3.2.0 that caused errors with unrestricted shell escape (#420). * Improved error messages mention the possibility of MiKTeX being used with `-aux-directory` or `-output-directory` without setting a `TEXMF_OUTPUT_DIRECTORY` environment variable (#419). * Updated documentation on shell escape for TeX Live. The `latexminted` executable has been added to TeX Live's list of trusted executables, so `-shell-escape` is no longer required. * Added support for `fancyvrb` options `reflabel` and `vspace` (#421). ## v3.2.0 (2024/10/29) * Fixed compatibility with `\includeonly` by replacing buffer length counters with macros (#414). As part of this, the minimum supported `latex2pydata` LaTeX package is now 0.3.0 and the minimum supported `fvextra` is now 1.9.0. * Added new options that allow keywords to be added to a lexer (#416): `extrakeywords`, `extrakeywordsconstant`, `extrakeywordsdeclaration`, `extrakeywordsnamespace`, `extrakeywordspseudo`, `extrakeywordsreserved`, `extrakeywordstype`. This covers all keyword tokens supported by Pygments (https://pygments.org/docs/tokens/#keyword-tokens). * Many performance improvements. When combined with `latexrestricted` v0.6.0, these can give a cumulative speedup of over 40% in the case when no code needs to be highlighted. - Temp files and the cache are now only cleaned up when necessary at the end of the document. Previously, this occurred at the end of each compile, unnecessarily increasing compile time. - In `latexminted.py`, switched from `platform.system()` to `sys.platform` for better performance in detecting operating system. Performance reference: https://github.com/python/cpython/issues/95531. - In `latexminted.py` with TeX Live, the value of `TEXMFOUTPUT` is no longer retrieved with `kpsewhich` unless it is actually used. Also fixed a bug in parsing `TEXMFOUTPUT` value (whitespace is now stripped). * The `debug` package option now records shell escape commands in the log. * In config detection, error messages now mention `.errlog.minted` file when it exists. ## v3.1.2 (2024/10/07) * There is now only a single `\read` allocation for reading temporary files when `highlightmode` is set to `fast` or `fastfirst`. Previously, there was one allocation per temp file, which could cause allocation errors when several temp files were highlighted during the same compile (#413). ## v3.1.1 (2024/10/03) * Fixed bugs in processing temporary files regardless of `highlightmode` from v3.1.0. With `highlightmode=fastfirst` (default), this would cause an error during the first compile, but then all subsequent compiles would complete correctly. ## v3.1.0 (2024/10/03) * All timestamp comparisons that are part of communicating with the `latexminted` Python executable now use timestamps that have been processed with `\detokenize` (#405). * Option processing now wraps values in curly braces to prevent escaping issues when options are passed on to other packages for further processing (#407). * Fixed compatibility with `dvilualatex` (#406). * Temporary files with common file extensions are now automatically detected and processed correctly regardless of `highlightmode` (#401). Previously, `highlightmode=immediate` was needed for working with temp files that are overwritten or deleted during compilation; the default `highlightmode=fastfirst` gave an error message during the first compile but worked correctly during subsequent compiles. * Fixed bug when `cache=false`. When caching is disabled, `highlightmode` is now set to `immediate`. * The minimum supported `latexminted` version is now 0.2.0. The new `latexminted` subcommand `cleantemp` is now used instead of `clean` when the cache does not require cleaning. This prevents errors when `cache=false`. * Fixed docs for `breakbeforeinrun` and `breakafterinrun` (#408). These had not been properly updated after `fvextra` renamed the options. ## v3.0.0 (2024/09/22) * Backward compatibility: The new `minted2` package provides the features of `minted` v2.9, the final release before v3. No additional v2 releases are planned; no changes to the `minted2` package are expected. * `minted` v3 is a complete rewrite from v2.9. `minted` v3 includes significant changes from `minted` v2 on the LaTeX side, and also uses a new `minted`-specific Python executable called `latexminted` to perform 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 highlight code 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. * Installing the `minted` package now also installs the `latexminted` Python executable and all required Python libraries, including Pygments, within your TeX distribution. These require Python >= 3.8. If the default Python version on `PATH` is < 3.8, then the `latexminted` Python executable will attempt to locate a more recent version and run itself with that version in a subprocess. Manually installing Python libraries is only necessary if you want to use plugin packages for Pygments. In that case, install the `latexminted` Python package in a Python installation. This automatically installs `latex2pydata`, `latexrestricted`, and Pygments as dependencies. `latexminted` is available from the [Python Package Index (PyPI)](https://pypi.org/project/latexminted/). Then install plugin packages for Pygments within the same Python installation. * The new `latexminted` Python executable is designed to be compatible with the security requirements for restricted shell escape, so that in the future TeX distributions can enable `latexminted` without requiring `-shell-escape`. It is possible to benefit from these enhanced security capabilities immediately and avoid the need for `-shell-escape`. - TeX Live: Copy the variable `shell_escape_commands` from the distribution `texmf.cnf` (typically something like `/texmf-dist/web2c/texmf.cnf`) into the user `texmf.cnf` (typically something like `/texmf.cnf`), and then add `latexminted` to the end of the `shell_escape_commands` list. The location of the `texmf.cnf` files can be determined by running `kpsewhich -all texmf.cnf`. - MiKTeX: Add a line `AllowedShellCommands[] = latexminted` to the existing list of allowed commands in `miktex.ini`. You may want to modify the user-scoped configuration instead of the system-wide configuration. See the [MiKTeX documentation](https://docs.miktex.org/manual/miktex.ini.html) for more details, particularly `initexmf --edit-config-file `. * Errors and warnings that occur within Python are now reported as `minted` package errors and warnings within LaTeX in nearly all cases. It should no longer be necessary to look through the compile log for Python errors and warnings. A temp file `*.errlog.minted` containing Python traceback information is created in some cases when errors cannot be fully reported within LaTeX or more details may be needed. * [`latex2pydata`](https://github.com/gpoore/latex2pydata) is now required for passing data from LaTeX to Python and then processing it within Python. This consists of a LaTeX package, available from [CTAN](https://ctan.org/pkg/latex2pydata), and a Python package, available from [PyPI](https://pypi.org/project/latex2pydata/). The LaTeX package can typically be installed with your TeX distribution's package manager. The Python package is automatically installed within your TeX distribution when `minted` is installed. * On the LaTeX side, all syntax highlighting settings are now serialized in Python literal format using `latex2pydata` and then saved to a temp file, which is loaded on the Python side. Settings are no longer passed to the Python side using command-line arguments. Temp files for passing data to Python are now named using MD5 hashes, instead of using a sanitized version of document `\jobname`. This eliminates an entire class of security issues and bugs related to escaping and quoting command-line arguments (#180, #276, #298, #322, #338, #354). It also eliminates bugs related to processing settings as a sequence of command-line options, since `pygmentize` accumulates some options that are used multiple times rather than overwriting earlier values with later values (#258, #337). * Options are now handled with `pgfkeys` and `pgfopts`, instead of `keyval` and `kvoptions`. * Temporary files are no longer created unless the cache needs to be updated (or caching is disabled). All MD5 hashing of code now takes place in memory instead of using one temp file per command/environment. All temporary files are cleaned up automatically when compiling completes without interruption. All temporary files now have names of the form `_..minted`. `` is an MD5 hash of `\jobname` (if `\jobname` is wrapped in double or single quotation marks, these are stripped before the MD5 is computed). `` is the role of the temp file: `data` (data passed to Python), `config` (detected system configuration), `style` (highlighting style definition), `highlight` (highlighted code), or `message` (message passed back to LaTeX by Python executable). `` can also be `errlog` when the Python executable encounters an unexpected error that it is not designed to report to the LaTeX side; this is not automatically cleaned up. There are no more `.pyg` and `.out.pyg` files. * Several package options are no longer supported and result in errors or warnings. - `finalizecache`: No longer needed. The `frozencache` package option now uses the regular cache, rather than requiring a new, special cache containing files with sequentially numbered names (#342). 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=.//_minted`). - `outputdir`: No longer needed (#268). TeX Live 2024+ saves a custom output directory from `-output-directory` in the environment variable [`TEXMF_OUTPUT_DIRECTORY`](https://tug.org/texinfohtml/web2c.html#Output-file-location). The environment variable `TEXMF_OUTPUT_DIRECTORY` can be set manually in other cases. - `kpsewhich`: No longer needed. `kpsewhich` is now automatically invoked as necessary by the `latexminted` Python executable in locating files. - `draft` and `final`: These no longer have any effect and result in a warning. They will soon be removed altogether. Improvements in caching have largely eliminated the overhead that `draft` mode was designed to avoid, while new features that are implemented purely within Python have made it impossible in some cases to typeset code using only LaTeX. The new package options `placeholder` and `verbatim` offer alternatives when maximum compilation speed is needed or the `latexminted` Python executable is unavailable. * New package options: - `debug`: Keep temp files from highlighting to aid in debugging. Also write current file name and line number to log before `\input` of highlighted code (#348). - `highlightmode`: Determines when code is highlighted. 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 is needed). `immediate` should be used when typesetting code in external temp files that are overwritten during compilation. When code is highlighted at the end of the document with `fast` or `fastfirst`, any error 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. - `placeholder`: Instead of typesetting code, insert a placeholder. This is enabled automatically when working with PGF/TikZ externalization. - `verbatim`: Instead of highlighting code, attempt to typeset it verbatim without using the `latexminted` Python executable. This is not guaranteed to be an accurate representation of the code, since some features such as `autogobble` require Python. * `bgcolor` now uses the new `bgcolor` option from `fvextra` v1.8, rather than `snugshade*` from `framed`. This resolves incompatibilities between `bgcolor` and `xleftmargin`/`xrightmargin` (#214), eliminates unneeded whitespace before/after the background (#220), prevents text from overflowing the background (#278), and provides uniform background height for `\mintinline` (#397). 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` for setting height of background color in inline contexts. * Renamed package options `langlinenos` to `lexerlinenos` and `inputlanglinenos` to `inputlexerlinenos`. The old names are still supported. * 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. The new `latexminted` Python executable improves cache management so that a shared cache functions correctly. A cache file that is shared by multiple documents will not be deleted if one document ceases to use the file. Document-specific caching as in `minted` v2 can be restored using the package option `cachedir`. For example, for files whose names do not contain spaces, simply use `cachedir=\detokenize{_minted-}\jobname`. For files with names that do contain spaces, use a copy of `\jobname` in which the wrapping quotation marks have been removed or replaced with other characters and the spaces have been replaced with placeholders such as `_`. * Cache file names now take the form `_highlight.minted` and `