[Tex/LaTex] How to highlight (color/draw attention to) a particular snippet in Minted

mintedsourcecode

I'm currently doing some work on error messages in programming languages. As such, I'm showing faulty pieces of code, alongside the compiler-errors accompanying them.

I'm using minted for the code snippets, but ideally, in addition to normal syntax highlighting, I'd like to highlight the sections of the code at which the error is located, by underlining them, putting a red box around them, shading their background, etc.

Is this possible using Minted?

Best Answer

The minted documentation has an example using escapeinside. I’m just copying it here:

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

Highlights as

screenshot