[Tex/LaTex] Is it possible to use tikzmark inside minted

codemintedtikz-pgftikzmark

As I've pointed out in a related question, I'd like to have some arrows pointing to parts of a source-code listing.

I know this is possible with the listings package, but is it possible with minted? That is, is there a way that I can insert a mark at a specific point inside the code minted is displaying?

Best Answer

Yes, it appears to work, you just need to specify an escape character (? here) to minted so you can insert the \tikzmark.

enter image description here

\documentclass{article}
\usepackage{minted}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}


\begin{minted}[escapeinside=??]{py}
def f(x):
    y = x?\tikzmark{here}?2
return y
\end{minted}


See this bit:
\begin{tikzpicture}[remember picture]
\draw[overlay, ->, line width=5pt, red] (0,0) -- (pic cs:here);
\end{tikzpicture}
\end{document}
Related Question