4

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}.

\begin{equation}\label{eq:massenergy}
    e = mc^2
\end{equation}
\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

comments in minted is a problem

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

  • 1
    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

1 Answers1

6

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}.

\begin{equation}\label{eq:massenergy}
    e = mc^2
\end{equation}

\begin{listing}[htp]
\begin{minted}[frame=single,texcomments]{matlab}
e = m*c^2; % see equation \eqref{eq:massenergy}
\end{minted}
\caption{Mass-Energy source code listing}
\label{listing:massenergy}
\end{listing}

\end{document}

enter image description here

egreg
  • 1,121,712