Math symbols in listings

MathLatexListings

Math Problem Overview


I have a problem with LaTeX – I don't know how to put mathematical equations and symbols in listings. I use the listings package and it's offers great looking listings, but it doesn't allow math symbols in $ ... $. Another package, algorithms, allows math, but listings doesn't look as good as with listings (the problem is that algorithms demands to get new line after every if, then, etc.)

Math Solutions


Solution 1 - Math

You can use the option mathescape for your environment which gives you the ability to use the normal latex behavior of the $-signs. Try:

\begin{lstlisting}[mathescape]
...
\end{lstlisting}

For more info, take a look into the listings package manual.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichalView Question on Stackoverflow
Solution 1 - MathmropaView Answer on Stackoverflow