The LaTeX package Minted allows to use the syntax highlighter pygment to display code in a LaTeX document. It is extremely versatile, and in our latest paper, my coauthors and I used it extensively.

To use minted in a LaTeX project, one (NO LONGER, see edit) has to modify a standard LaTeX compiler workflow in two ways.

  1. The LaTeX compiler must be passed the --shell-escape command, and
  2. The package minted must be told where the LaTeX auxiliary files are.

In my workflow (described here), these two things are done respectively by

  1. passing the argument --latex-args=--shell-escape to latexrun, and
  2. importing minted with the option outputdir=latex.out, as \usepackage[outputdir=latex.out]{minted}.

Usage

Using Minted is relatively straightforward: to display code by itself, one uses the minted environment as follows:

\begin{minted}{julia}
"""
    my_function(x, y, z)

This is the docstring of my function
"""
function my_function(x, y, z)
  # this is a complicated function
  sleep(5)
  return x + y - z
end
\end{minted}

To display code inline, one writes something like \mintinline{julia}{my_function(1, 2, 3) == 0}.

If necessary, one can escape minted and execute LaTeX code inside a minted environment, by passing a symbol to the escapeinside keyword. This looks like the following:

\begin{minted}[escapeinside=||]{julia}
"""
    my_function(x, y, z)

This is the docstring of my function
"""
function my_function(x, y, z)
  # this is a complicated function
  sleep(5)
  |\textrm{Here I display latex code inside minted!}|
  |$\int_{0}^{\infty} f(x)dx = 0$ - It even handles mathmode.|
  return x + y - z
end
\end{minted}

EDIT

The first draft of this post was quite old. The latest version of minted does not need the --shell-escape argument, and it finds the auxiliary files automatically, so it is no longer necessary to modify one’s latex workflow in any way: one just needs to have pygmentize installed.

EDIT BIS (2026-05-26)

I am ageing at a remarkable speed. It is once again time for a highly specific post about my problems with the minted package.

While I was trying to compile a known good document using TeXLive 2026, minted kept throwing the following error:

[...] minted Python executable is version 0.6.0, but version 0.7.0+ is required

Running tlmgr update --all did not solve the issue, and neither did a clean install of MacTeX.

After actually reading the documentation, I learned that the LaTeX package minted ships with some Python code called “latexminted”, which actually parses the source code; this must be the code that is on version 0.6.0 on my machine, causing the error. Problem found!

How to update it though?

Good question: my package manager brew does not ship latexminted, and apparently brew’s version of mactex is currently (May 26th, 2026) shipping the correct version; so how is my machine running the wrong one?

Apparently, when I was a lot less tech-savy I installed latexminted globally via pip, and that was the default version running! pip does not offer an “update all” function, and it does not notify the user that newer versions of the package are available.

The solution is simply to remove the pip version of latexminted from my machine, as this will force the use of the version that ships (and gets updates!) with tlmgr.

An instructive way to waste 30 minutes.