[Tex/LaTex] Minted mathescape

minted

Please consider the following code:

\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}[mathescape=true]{text}
$A\wedge B$
\end{minted}
\end{document}

When I try to compile this code using XeLaTeX (other engines not tested),
I receive the verbatim output $A\wedge B$ instead of the mathematical
equivalent. Can someone point me in the right direction, since this
example follows the instructions of the minted manual? The code has
been tested with minted v2.

Best Answer

That's the expected result since, according to the minted (v2.0 from 2015/01/31) documentation, mathescape=true enables LaTeX math mode inside comments. Outside comments you can use escapeinside (beware that this requires Pygments version 2.0+):

\documentclass{article}
\usepackage{minted}

\begin{document}

\begin{minted}[escapeinside=||,mathescape=true]{text}
test
$A\wedge B$
test
|$A\wedge B$|
test
\end{minted}

\begin{minted}[escapeinside=||,mathescape=true]{python}
test
$A\wedge B$
test
# $A\wedge B$
test
|$A\wedge B$|
test
\end{minted}

\end{document}

The result (using Pygments 2.0.2):

enter image description here

Related Question