Noweb doesn't support pretty-printing the way that CWEB does (it's
language-independent), and I missed that feature a lot. So I wrote a
noweb prettyprinter, dpp. A portion of the dpp documentation
Here are some of the features of dpp:
To use dpp, just provide the `-filter dpp' option to
noweave. There are a few options:
- Keywords are typeset in bold, variables in italics,
comments in roman, strings in typewriter.
- Some punctuation is prettyprinted as well.
- Keywords are definable by the user with the `@ %keyword'
- All instances of code quoting ([[...]]) are
prettyprinted, including quotes inside comments and chunk names.
- Comments are optionally fed straight to TeX, so that you use
(for example) TeX's extensive math typesetting capabilities.
- Indentation and line-breaking are not messed with.
- dpp is written in Perl, which you may or may not consider
To tell dpp about a user-defined keyword such as Elephant,
simply insert a line such as `@ %keyword Elephant' into the
.nw file. Multiple keywords may be specified on a single line.
- `-tex' will send your comments to TeX rather than print
them verbatim. It is off by default to avoid nasty surprises
for people running their programs through dpp for the
- `-cw' compresses whitespace in the code. It compresses
all whitespace not at the beginning of a line to one space, and
expands whitespace between code and comments to four characters.
Basically, it undoes hand-formatting that looks good when
monospaced but bad in a proportional font.
- `-N root' turns off prettyprinting for the chunk
named root and all of its descendants. This way you can
include a makefile or test data in your .nw file without
having it printed like C code.
The current version of dpp is 0.2.1, and you can find it here. You'll need noweb first, of course. If
there's something egregiously wrong with the newest version, you can
try version 0.2.0. And if you're really
brave, you can get the latest development
Since the whole point of literate programs is that they are nice to
read, I've made a .pdf of dpp available here.
One warning: for now, you need to use the noweb.sty from noweb 2.8,
not 2.8a, since the newer 2.8a redefines \nwlbrace and \nwrbrace in a
way that I have yet to deal with.
Here is an example of what dpp output looks
like. It was slightly modified from Norman Ramsey's noweb port of
Don Knuth's CWEB version of the UNIX program wc. The zip
file contains the original .nw file and a .dvi file.
I appreciate hearing any comments about dpp, good or bad. Bug reports
are especially welcome!
Go back to Dan's noweb page
Go back to Dan's home page
Last updated 19 Feb 1998