-
Notifications
You must be signed in to change notification settings - Fork 5
Description
By default, minted v3 requires a second compile to highlight code properly:
highlightmode: Determines when code is highlighted. The default isfastfirst. 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 arefast(always highlight at end of document, requiring a second compile) andimmediate(always highlight immediately, so no second compile is needed).immediateshould be used when typesetting code in external temp files that are overwritten during compilation.
However, memoize extracts the externs after the first compilation, which means that all externs still have the <MINTED> placeholder instead of highlighted code:
\documentclass{article}
\usepackage[extract=python]{memoize}
\usepackage{minted}[2024/09/22]
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node {\mintinline{text}|test|};
\end{tikzpicture}
\end{document}cached result:
The only workarounds I've found are:
- Compile once, delete the cached memoize pictures (but not the minted cache!), compile again
- Disable caching selectively for tikzpictures which use minted (obviously error-prone, especially because the issue depends on two different caches being in the correct state)
- Pass
[highlightmode=immediate]to minted, which will however significantly increase the time for the first compile (2min 50s -> 5min 45s for a full `latexmk' run in my case). From what I can gather, there is no way to only set that option for a single minted call either. - Patching the internal
mintedcommand that inserts the placeholder to abort memoizing:
\usepackage{etoolbox}
\makeatletter
\pretocmd{\minted@insertplaceholder}{\mmzAbort}{}{\errmessage{patch failed}}
\makeatotherIs there a good way for memoize to support this properly? Should it perhaps handle minted automatically?
