WEB is the original literate-programming tool that Donald Knuth built to write TeX, and CWEB is its later adaptation for the C family of languages. As Knuth’s Stanford pages put it, CWEB is “a version of WEB for documenting C, C++, and Java programs,” combining the typesetting power of TeX with general-purpose programming. Both systems treat a program “as a communication to human beings rather than as a set of instructions to a computer.”
The defining feature of these tools is that a single source file feeds two separate processors that produce two different outputs. In CWEB the source file has a .w extension. One processor, CTANGLE, reads the .w file and produces a compilable .c program, rearranging the named code fragments into the order the compiler requires and stripping away the prose. The other processor, CWEAVE, reads the same .w file and produces a .tex file, a fully formatted, prettyprinted, cross-indexed document with an automatically generated index of identifiers and section names. The original WEB used the same pair, named TANGLE and WEAVE, to emit Pascal source and a TeX document respectively, as Knuth described in his 1984 Computer Journal paper introducing the WEB system by example.
This split is what makes literate programming practical. The programmer maintains only the woven narrative, ordering code in whatever sequence best explains the design, while tangle quietly assembles a correct, compiler-ready file behind the scenes. Because both the human document and the machine source come from one master, the documentation cannot fall out of date relative to the code, eliminating the perennial problem of comments that no longer match their program.
Knuth created WEB in the early 1980s as part of building TeX and METAFONT, which are themselves enormous WEB programs; their complete annotated listings were published as Volumes B and D of Computers and Typesetting. The fuller technical description, “The WEB System of Structured Documentation,” appeared as a Stanford computer science technical report in 1983 and included the WEB source for TANGLE and WEAVE themselves, a characteristic act of self-documentation.
CWEB, developed with Silvio Levy, broadened the approach beyond Pascal so that mainstream C programmers could use it. Knuth’s pages note that later versions added PDF support with clickable hyperlinks, turning a woven program into navigable hypertext. The WEB and CWEB tools remain the canonical implementations of Knuth’s literate-programming methodology and the reference point against which later documentation-driven systems are measured.