2

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?

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.