Both syntax highlighting and elegant algorithm specifications would make great preprocessors. ;-) I find the latter works best when used tastefully (and never, *ever* in a manual page).
It'd be trivial to write an Awk script for replacing basic-looking keywords, substituting them with proper placement and formatting controls: .begin algorithm IsMultipleOf (input, value) assert value is Integer assert value is >= 0 value := 10 result := undefined unless input % value return true else return false .end This might expand to pic(1) instructions, eqn(1), or a list of steps for human consumption like this one <https://tc39.es/ecma262/#sec-stringindexof>. I vaguely recall somebody wrote a preprocessor to format *BNF grammars into a pic(1) drawing that looked extremely spiffy. Sadly, I never saved the link⦠On Wed, 13 Jan 2021 at 07:23, M Douglas McIlroy < [email protected]> wrote: > > I wonder how I can format a nice algorithm in the usual sense in groff. > > I want to write pseudocode...\ > > It all depends on what you mean by "nice". If it's just a properly indented > listing, most of the standard macro packages have adequate support. > For example, in the -ms package (man 7 groff_ms) bracket the code with > .DS and .DE and use .ta to set tabs. However,. groff will not serve as a > pretty-printer and decide how code should be indented. > > It's customary also to use a constant-width font for programs: .ft CW. But > you > may not want to do so for pseudocode. > > If you want syntax highlighting, e.g. bold keywords of (heaven forfend) > syntax > colorization. it will be painful, but straightforward: use \f and \m > escapes to > change font and color. > > Doug >
