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?


  • You could give the ulineno package a try...
    – user31729
    Apr 13, 2017 at 14:45
  • 1
    This depends on your pseudo-code. Why don't you use one of the standard packages?
    – Bernard
    Apr 13, 2017 at 14:45
  • 1
    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.
    – yoyostein
    Apr 13, 2017 at 16:44

1 Answer 1


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





if (x > 2) {
  do something
} else {
  do something else



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


and use Verbatim without options.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .