0

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.

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

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:

enter image description here

\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.

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.