7

How can I get mathematical symbols in verbatim mode? If I use them, for example \equiv, it is just reproduced as is in the pdf.

2
  • 1
    It sounds like you don't really want verbatim (which means produce the output, erm, verbatim). What do you really want?
    – TH.
    Apr 21 '11 at 5:10
  • 2
    I want to include some code. For that I want to use the verbatim mode so that I dont have to do all the indentation, etc. And in that code, there are some symbols. What can I do?
    – n1kh1lp
    Apr 21 '11 at 5:11
7

You can use alltt, fancyvrb or listings package for this purpose.

For fancyvrb, see manual "4.1.16 Catcode characters". Example:

\begin{Verbatim}[commandchars=\\\{\},
  codes={\catcode‘$=3\catcode‘^=7}]
x=1/sqrt(z**2) ! $\frac{1}{\sqrt{z^2}}$
\end{Verbatim}

It is easier to use listings package, see manual "4.14 Escaping to LaTeX". Example:

\begin{lstlisting}[mathescape]
// calculate $a_{ij}$
$a_{ij} = a_{jj}/a_{ij}$;
\end{lstlisting}
2

If you include the alltt package like this:

\usepackage{alltt} %verbatim boxes with latex commands

Then create math within an alltt environment using \ensuremath{...}

\begin{alltt}\small\center
\ensuremath{\neg}((P \ensuremath{\wedge} S) \ensuremath{\oplus} S)
\end{alltt}
1

I think you might try the alltt package.

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.