4

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?

7

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}

enter image description here

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

0

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.