3

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
  • 1
    The documentation about escapeinside says “Escaping does not work inside strings and comments (for comments, there is texcomments).”
    – egreg
    May 27, 2018 at 14:44

1 Answer 1

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

1
  • 1
    Indeed this is the case. I am sorry I missed this. Thank you for pointing this out. Marked the answer as accepted. Thanks again! May 27, 2018 at 14:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .