views:

346

answers:

1

Hi,

I have a problem with Latex -- I don't know how to put mathematical equations and symbols in listings. I use --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 in --listings-- (the problem is that --algorithms-- demands to get new line after every --if--, --then--, etc.)

Thanks for reply

Michal

+6  A: 

I am not a 100% sure but I think you can use the option mathescape for your environment which should give you the ability to use the normal latex behavior of the $-signs. Have you tried

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

or did you take a look into the listings package manual?

mropa
This is the right solution. I used it with success, and it is properly documented in ftp://ftp.tex.ac.uk/tex-archive/macros/latex/contrib/listings/listings.pdf, p. 38
tonio
Thanks! [mathescape] did the job!
Michal