CWEB(1)
π CWEB β ctangle & cweave
okay so bestie, this is the CWEB(1) page from the General Commands Manual β it's the whole glow-up guide for ctangle and cweave πΈ
β¨ SYNOPSIS β¨
ctangle [options] webfile[.w] [{changefile[.ch]|-} [outfile[.c]]]
cweave [options] webfile[.w] [{changefile[.ch]|-} [outfile[.tex]]]
π¦ DESCRIPTION π¦
ctangle takes your CWEB source doc and turns it into an actual C/C++ program that you can compile the normal way, no cap. And the output file has #line specifications inside it, so when you're debugging you're debugging in terms of your CWEB source file β which is honestly iconic of it π
cweave takes that same CWEB file and turns it into a TeX file that you can format and print the usual way. It handles all the typographic details β page layout, indentation, italics, boldface, etc. β like a total main character, and it auto-gathers extensive cross-index info for you π₯
CWEB lets you write one single document that holds everything you need both to produce a compilable C/C++ program and to produce a beautifully formatted doc describing that program in as much detail as you could ever want. So you get both, from one file. Slay. β¨
Heads up tho: to use CWEB you really should already know TeX and C/C++. Like, both. That's the vibe check π«Ά
π USAGE π
Your command line should have one, two, or three names on it:
- Name #1 β the CWEB input file. (
.wgets added if there's no extension.) - Name #2 β a change file. (
.chgets added if there's no extension.) This change file overrides parts of the CWEB file, as described in the documentation. - Name #3 β overrides the default output file name. By default that output file is the same name as the input file (but on the current directory), with the extension
.tex.
And here's a lil trick π if you only wanna change the output file name but you don't actually have a change file to apply, just use - as the second argument. iykyk π
π DIFFERENCES TO ORIGINAL CWEB π
CWEBbin tries so hard to be a drop-in replacement for CWEB, so honestly you shouldn't notice any differences when you invoke the programs, and the resulting output should be the same too. But there are a few differences worth noting:
- Options
--help,--quiet,--verbose,--version, and flags+c,-i,-o,+u, and+lXare new in CWEBbin and TeX Live. - Option
+lXcomes with several wrapper files forcwebmac.tex, with translated captions for German (+ld), French (+lf), and Italian (+li). π§ - File lookup with the environment variable
CWEBINPUTSis extended to permit several, colon-separated, paths β see ENVIRONMENT below. - If properly configured, the main programs
ctangleandcweaveare localized with the "GNU gettext utilities".
π₯ OPTIONS π₯
okay so the rules: options on the command line can be turned off with - (if they're on by default) or turned on with + (if they're off by default). Also, options are processed left to right, so a sequence like --verbose -h will only show the banner line (+b) and the progress report (+p), but leave out the happy message (-h). Order matters, bestie β¨
π the first batch β common to both ctangle and cweave
+bβ print banner line on terminal+hβ print success message on completion+pβ print progress report messages+q/-qβ shortcut for-bhp; also--quiet+v/-vβ shortcut for+bhp; also--verbose(this one's the default π)+cβ check temporary output for changes+sβ print usage statistics--helpβ display help message and exit--versionβ output version information and exit
π ctangle-only β two more
+kβ keep separators in numeric literals in the output+uβ transliterate UTF-8 characters in C code
π cweave-only β eight more
-eβ do not enclose C/C++ material in\PB{...}-fβ do not force a newline after every C/C++ statement in output-Fβ do not force a compound statement to start on a new line-iβ suppress indentation of parameter declarations-oβ suppress separation of declarations and statements-xβ omit indices, section names, table of contents+lX/-lXβ use macros for language X as ofXcwebmac.tex+tβ treattypenamein a template liketypedef
πΈ ENVIRONMENT πΈ
The environment variable CWEBINPUTS is used to search for the input files β or the system default if CWEBINPUTS isn't set. See tex(1) for the details of the searching.
And to avoid conflicts with other programs that also use the CWEBINPUTS environment, you can be more specific and use CWEBINPUTS_cweb for special requirements in CWEB π«Ά
If prepared for NLS support, ctangle and cweave use the environment variable TEXMFLOCALEDIR to configure the parent directory where the "GNU gettext utilities" search for translation catalogs.
These variables are preconfigured in TeX Live's texmf.cnf. π
π§ FILES π§
The location of the files mentioned below varies from system to system. Use the kpsewhich utility to find their locations.
cwebmac.texβ the default TeX macros\inputin the first line of thecweaveoutput file.cwebman.texβ the CWEB user manual, available in PDF from CTAN.
π SEE ALSO π
- The CWEB System of Structured Documentation: by Donald E. Knuth and Silvio Levy (hardcopy version of
cwebman.texand the source code listings ofcommon.w,ctangle.w, andcweave.w). - Literate Programming: by D. E. Knuth.
- Weaving a Program: by Wayne Sewell.
π AUTHORS π
Don Knuth wrote WEB for TeX and Pascal.
Silvio Levy designed and developed CWEB by adapting the WEB conventions to C and by recoding everything in CWEB. Knuth began using CWEB and made further refinements.
Many other helpers are acknowledged in the CWEB manual.
Contemporary development on https://github.com/ascherer/cweb.
β and that's the whole thing, bestie β this page is from Web2c 2026, dated April 30, 2025, and it's literally giving CWEB(1) energy. go weave something gorgeous π
β¨π
π¦ where this page comes from
- alpine 3.24: texmf-dist-binextra-doc 2026.0-r0 Β· LPPL-1.0 AND LPPL-1.1 AND LPPL-1.2 AND LPPL-1.3a AND LPPL-1.3c AND GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms