This question describes how to use tikzmarks inside minted code. However if the code spans longer than one page the result is not correct.
Is there a way to fix this?
MWE:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{minted}
\begin{document}
\begin{minted}[escapeinside=??]{py}
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long?\tikzmark{mark}? function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
\end{minted}
\begin{tikzpicture}[remember picture]
\draw[overlay, latex-, thick] (pic cs:mark) --++ (1,1);
\end{tikzpicture}
\end{document}
New MWE
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{minted}
\newcommand{\mymarkright}[2]{\tikzmark{#1}%
\begin{tikzpicture}[overlay, remember picture]
\draw [overlay, latex-, thick] (pic cs:#1) --++ (0.5,-0.5) node[anchor=west, align=center, rectangle, fill=red!30, draw] {#2};
\end{tikzpicture}}
\begin{document}
\begin{minted}[escapeinside=??]{py}
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long?\mymarkright{a}{Here goes\\some text}? function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
def function1(args):
# this is a a long function
\end{minted}
\end{document}