# How to escape to latex within minted comments?

I am using the minted package for typesetting matlab source code.

There is an escapeinside option for the listing environment provided by minted to escape to regular TeX commands.

However, this does not work on comment lines. Here is a MWE illustrating the problem.

\documentclass{article}
\usepackage{minted}
\usepackage{amsmath}

\begin{document}

The code for computing mass-energy relationship is given in listing~\ref{listing:massenergy}.

$$\label{eq:massenergy} e = mc^2$$
\begin{listing}
\begin{minted}[mathescape,autogobble,escapeinside=||,frame=single]{matlab}
e = m*c^2; % |see equation~\eqref{eq:massenergy}| does not work!
|see equation~\eqref{eq:massenergy}| works
\end{minted}
\caption{Mass-Energy source code listing}
\label{listing:massenergy}
\end{listing}

\end{document}


Here is the output produced

How can one escape to TeX/LaTeX inside minted comment lines?

• The documentation about escapeinside says “Escaping does not work inside strings and comments (for comments, there is texcomments).” – egreg May 27 '18 at 14:44

The documentation of minted about escapeinside says

Escaping does not work inside strings and comments (for comments, there is texcomments).

\documentclass{article}
\usepackage{minted}
\usepackage{amsmath}

\begin{document}

The code for computing mass-energy relationship is given
in listing~\ref{listing:massenergy}.

$$\label{eq:massenergy} e = mc^2$$

\begin{listing}[htp]