Skip to content

Incompatibility with minted v3 #44

@The-Compiler

Description

@The-Compiler

By default, minted v3 requires a second compile to highlight code properly:

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.

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:

Image

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 minted command that inserts the placeholder to abort memoizing:
\usepackage{etoolbox}
\makeatletter
\pretocmd{\minted@insertplaceholder}{\mmzAbort}{}{\errmessage{patch failed}}
\makeatother

Is there a good way for memoize to support this properly? Should it perhaps handle minted automatically?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions