CWEB(1)

πŸ“¦ version 2026.0, in alpine 3.24

πŸ’… 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. (.w gets added if there's no extension.)
  • Name #2 β€” a change file. (.ch gets 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 +lX are new in CWEBbin and TeX Live.
  • Option +lX comes with several wrapper files for cwebmac.tex, with translated captions for German (+ld), French (+lf), and Italian (+li). 🧚
  • File lookup with the environment variable CWEBINPUTS is extended to permit several, colon-separated, paths β€” see ENVIRONMENT below.
  • If properly configured, the main programs ctangle and cweave are 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 of Xcwebmac.tex
  • +t β€” treat typename in a template like typedef

🌸 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 \input in the first line of the cweave output 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.tex and the source code listings of common.w, ctangle.w, and cweave.w).
  • Literate Programming: by D. E. Knuth.
  • Weaving a Program: by Wayne Sewell.

cweb(1), tex(1), cc(1)


πŸ’– 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