I have to say I find the idea of representing pseudocode for a CS book using a <poem> construct to be somewhat funny.
But I really feel that is not the way to go. The PreText tags are, at least in my opinion, first and foremost semantic constructs, that indicate what their contents mean in complete isolation with what the visual appearance of those contents in a certain medium might be. A poem tag suggests exactly that the contents are to be a poem, and a program tag suggests exactly that the contents are to be a program. What you have is a program and using anything else feels to me fundamentally wrong.
The other related part is to consider that the PreText source is meant to be consumed in other ways beyond a print or web form. The fact that some of the lines in that algorithm are to be indented is something that ideally would be communicated in the syntax. Admittedly the way to do that at the moment is not ideal, by using spaces in a verbatim context where spaces are considered significant. I don’t even want to imagine how a screen reader would read that block, but I don’t suppose it would be understandable. But that may all be too big of a slice to address here, and it’s a general problem with all code blocks I think. But what I am getting that it so keep in mind that the design of PreText is to consider these other forms of consuming the document and attempting to provide something that would work in all, braille being one of those particularly hard to think about for those of us who are not visually impaired.
I feel that expecting the program/input tags to treat math content in them in some appropriate way is a dangerous path, even if it could be done. I would tend to expect such blocks to show you exactly the code you might use to produce a math content, so I am not sure where I would start there.
Spitballing here, but I wonder if what we might do is have an actual “pseudocode” tag, to be used in place of program, and where:
- whitespace and newlines are treated literally
- numbering of the lines can be enabled
- math syntax is allowed and properly converted, but expected to be inline, probably?
- perhaps one or two more tags allowed, to allow indicating a keyword (to be bold), variable (italic?) etc?
Rendered in HTML I would expect that to be a non-verbatim block that uses mono-spaced font, treats each line as an isolated item, and has some way to support indenting, possibly by using white-space: pre; on the CSS side. But this is really just throwing ideas out, really.
And I understand that adding a new construct is not a small thing. But I really would not want to see poem used for pseudocode (unless it’s pseudocode that rhymes, of course).
Jacob, out of curiosity, is your pseudocode so math-complex that the simple text form you presented for the sieve would not be applicable? I guess what I am suggesting, at the risk of butting in and without knowing the particulars of what you are working with, is that if I were to be writing pseudocode for a CS course then I would just use the program/verbatim approach, and basically just use “pseudomath” in the pseudocode. But I can see that getting hairy if the math is complex.
Hope I haven’t ruffled too many feathers.
Haris
Charilaos Skiadas
Professor in Mathematics and Computer Science
Hanover College