I know this is an "ancient" question but I would like to answer it to help those who get here like me. :)
minted nows provides a macro called escapeinside (also texcl and texcomments for LaTeX in comments, please check the document for more):
escapeinside (string) (default: ⟨none ⟩)
Escape to LaTeX between the two characters specified in (string). All code between the two characters will be interpreted as LaTeX and typeset accordingly. This allows for additional formatting. The escape characters need not be identical. Special LaTeX characters must be escaped when they are used as the escape characters (for example, escapeinside=\#\%). Requires Pygments 2.0+.
Escaping does not work inside strings and comments (for comments, there is texcomments)....
An example given in the document is:
\begin{minted}[escapeinside=||]{py}
def f(x):
y = x|\colorbox{green}{**}|2
return y
\end{minted}
I've tried that. We can also use \label{refname} to create a line reference using esacpeinside like this:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{minted}
\begin{document}
\begin{minted}[escapeinside=||,linenos,gobble=0]{c}
void hello() |\label{line:hello_start}|
{
printf("Hello minted!\n");
} |\label{line:hello_end}|
int main()
{
hello(); |\label{line:invoke}|
return 0;
}
\end{minted}
The code at Line~\ref{line:invoke} invokes a function defined
between Line~\ref{line:hello_start} and Line~\ref{line:hello_end}.
\end{document}
The example on Overleaf.
Hope this helps. :)
mintedusesfancyvrb, so the documentation offancyvrbwill help you.+ – Marco Daniel Mar 04 '13 at 19:24texcl=trueto allow LaTeX in comments, and then put a\labelin a comment and\refthat. Unfortunately, Pygments doesn't allow LaTeX anywhere except for comments (though that feature has been requested). So Pygments is a bit more limited thanlistingsin that respect. (You could always take the direct output of pygmentize and add\label's by hand, but that's probably not what you were looking for.) – G. Poore Mar 04 '13 at 20:05