[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Groff algorithm
From: |
Damian McGuckin |
Subject: |
Re: Groff algorithm |
Date: |
Wed, 13 Jan 2021 08:44:23 +1100 (AEDT) |
User-agent: |
Alpine 2.02 (LRH 1266 2009-07-14) |
On Tue, 12 Jan 2021, M Douglas McIlroy 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.
When documenting an algorithm, code or pseudo-code, within a report or
document, lots of people (including myself) follow Doug's ideas (almost)
to the letter. But these are usually only code snippets or at most a
single routine which fits in less than one page.
For pretty printing actual code written in some language, I use vgrind(1)
which is just a preprocessor to groff. You would have to define your own
'pseudo-language' for vgrind to make it work in your scenario.
Regards - Damian
Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer