# Easy way to add line numbers for pseudocode algorithm

I have some pseudocode entered in LaTeX in a very primitive and naive way (not using any of the algorithm, algorithmic packages).

Is there an easy way to add line numbers to the code, without rewriting them in the format for the packages?

Thanks.

• You could give the ulineno package a try...
– user31729
Apr 13, 2017 at 14:45
• This depends on your pseudo-code. Why don't you use one of the standard packages? Apr 13, 2017 at 14:45
• Are you using verbatim? Could you elaborate on your "very primitive and naive way"?
– Werner
Apr 13, 2017 at 15:58
• @Werner Yes, essentially verbatim. For example "if" is just written as "if" rather than /If as required in the packages. Apr 13, 2017 at 16:44

If your "very primitive and naive way" is akin to verbatim, then the easiest way is to switch to fancyvrb. Instead of using verbatim, use Verbatim and add the option numbers=left:

\documentclass{article}

\usepackage{fancyvrb,lipsum}

\begin{document}

\lipsum[1]

\begin{Verbatim}[numbers=left]
if (x > 2) {
do something
} else {
do something else
}
\end{Verbatim}

\lipsum[2]

\end{document}


If you don't want to add the option numbers=left to each Verbatim, you can

\RecustomVerbatimEnvironment{Verbatim}{Verbatim}{numbers=left}


and use Verbatim without options.