6

Is there a way to do really casual peudocode in Latex? By casual I mean pseudocode that's more like a list of plain English steps, with occasional conditional/looping operators.

I've looked at the algorithm package and its variants (algoritmic, algoritmicx, etc) and they're all too restrictive for really casual pseudo-code. I basically want to just list some steps with a few conditions, but the packages all seem to require that every line be some algorithm operator (if, while, for) or mathematical operation.

I'd like a lot of my lines to just be plain English, like "Load input images", but occasionally I want to be able to add a loop or condition so I want something more advanced than a basic bullet list. I'd also like it to be in a nice looking environment like the algorithm environments so I can refer to it by a label.

As an example, I'd like to be able to write pseudocode something like the following, where operators like For would get highlighted nicely and the whole thing's in an algorithm environment, but otherwise it's just plain English:

Algorithm to make egg salad

  • Boil N Eggs

  • For (Each boiled egg) {

    • Crack and peel shell

    • Add to bowl

    }

  • Add mayonnaise and mix contents of bowl.

3
  • OK, had a look through the algorithmicx package more carefully, and discovered the State and Statex commands which look like they do what I want, in that they allow lines of plain english text (Statex leaves out the line numbering). Is there another option I should consider? Thanks.
    – SSilk
    Jul 18, 2011 at 2:48
  • please don't write an "answer" to further explain your question. Instead, please edit your question or write a comment to it. I converted your answer to a comment.
    – Stefan Kottwitz
    Jul 18, 2011 at 8:33
  • Sorry about that. I wrote this post and response in a bit of a frustrated late-night daze. When I looked at it again today I realized I had totally neglected to put in an example of what I was trying to do. Thanks.
    – SSilk
    Jul 19, 2011 at 22:54

2 Answers 2

3

Coming back to this question after a few weeks, I was ultimately able to do what I wanted using the State and Statex commands of the algorithmicx package, both of which allow you to just write a line of whatever text you want.

Statex supresses line numbering if it's being used, so if you want lines in your algorithm that are sort of like headings and don't entail a step in the algorithm, then you can place bold text on a Statex line and it works nicely. I realize that's not typical of pseudo-code, but what I was trying to make was fairly plain-english pseudo-code to outline a high-level algorithm.

0

I think the Listings package is positioned between algorithm and a simple list. Have you tried that?

3
  • Thanks. I will check it out, although I may be able to do what I wanted with State/ Statex in the algorithmicx package.
    – SSilk
    Jul 19, 2011 at 4:14
  • Hi Neil, I just looked at the documentation for Listings, and from what I'm seeing, it's mainly aimed at syntax highlighting for source code. Am I missing some features of it? Thanks.
    – SSilk
    Jul 19, 2011 at 22:57
  • I guess it depends on how much structure you need. With Listings you can pick some pretty pseudo-codish languages like ruby.
    – Neil
    Jul 22, 2011 at 13:28

You must log in to answer this question.

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