# Getting Math Operators to work in verbatim

I'm very new to Latex and I'm looking to simply have math operators appear with in verbatim tags as follows:

\begin{verbatim}
24:     max:=0
25:     for i:=n downto 1 do
26:         found:=false
27:         clique($S_i$ \cap N($v_i$); 1)
28:         c[i]:=max
29:     end for
30:     return
\end{verbatim}


but $S_i$ appears as is and not with a subscript? How can I render the i as a subscript?

Two possibilities: using the fancyvrb or listings packages that allow you to escape math and also give you automatic numbering:

\documentclass{article}
\usepackage{fancyvrb}
\usepackage{listings}

\lstset{
basicstyle=\ttfamily,
mathescape=true,
columns=fullflexible,
numberstyle=\ttfamily\footnotesize
}

\renewcommand\theFancyVerbLine{\footnotesize\arabic{FancyVerbLine}:}
\renewcommand\thelstnumber{\arabic{lstnumber}:}

\begin{document}

\begin{Verbatim}[numbers=left,firstnumber=24,codes={\catcode$=3\catcode_=8}] max:=0 for i:=n downto 1 do found:=false clique($S_i$\cap N($v_i$); 1) c[i]:=max end for return \end{Verbatim} \begin{lstlisting}[numbers=left,firstnumber=24] max:=0 for i:=n downto 1 do found:=false clique($S_i$\cap N($v_i\$); 1)
c[i]:=max
end for
return
\end{lstlisting}

\end{document}


I wasn't sure about the \cap part, so I left it as in the original.