CTWILL(1)

πŸ“¦ version 2026.0, in alpine 3.24

πŸ’… CTWILL(1) β€” the ctwill family, explained by your favorite Unix bestie πŸŽ€

ok so bestie, buckle up. this is the manual page for ctwill, ctwill-proofsort, ctwill-refsort, and ctwill-twinx β€” the whole little crew. we're in the General Commands Manual section, which is giving "the classics" energy. let's go ✨


🌸 NAME 🌸

ctwill, ctwill-proofsort, ctwill-refsort, ctwill-twinx β€” translate CWEB to TeX, but with mini-indexes. that's the whole vibe. πŸ¦‹


🩷 SYNOPSIS 🩷

like, the shapes you can call it in, verbatim, no cap:

ctwill [options] webfile[.w] [{changefile[.ch]|-} [outfile[.tex]]]
( ctwill-proofsort < texfile.tex ) 1<> texfile.tex
ctwill-refsort < indexfile.ref > indexfile.sref
ctwill-twinx outfile.tex [outfile.tex ...]  > index.tex

πŸ’– DESCRIPTION πŸ’–

so ctwill takes your CWEB source document and turns it into a TeX file. then you format and print that TeX file the usual way. it handles all the typographic details for you β€” page layout, indentation, italics, boldface, the whole aesthetic ✨ β€” and on top of that it supplies extensive cross-index information that it gathers all by itself. main character behavior honestly. πŸ‘‘

CWEB lets you prepare one single document containing literally everything you need: both to produce a compilable C/C++ program and to produce a well-formatted document describing the program in as much detail as the writer could possibly want. obsessed. 🫢

⚠️ heads up bestie: the user of CWEB ought to be familiar with TeX as well as C/C++. that's the assignment, fr fr.

🌈 USAGE 🌈

okay so the command line should have one, two, or three names on it. here's the breakdown, iykyk:

  1. first name β†’ taken as the CWEB input file (and .w gets added if there's no extension)
  2. second name β†’ it's a change file (and .ch gets added if there's no extension). the change file overrides parts of the CWEB file, as described in the documentation.
  3. third name β†’ overrides the default name of the output file, which is ordinarily the same as the name of the input file (but on the current directory) with the extension .tex.

and if you just want to change the output file name but don't have a change file to apply? slay, just use - as the second argument. πŸ’…


ctwill is exactly like cweave except that it produces much better documentation β€” for which you must work much harder. 😭 trade-offs, bestie. you should run ctwill twice, once to prime the pump and once to get decent answers. and moreover, you must run the output twice through TeX.

after tex foo you'll have output that looks like final pages, except the entries of mini-indexes won't be alphabetized. πŸ™ˆ the first run produces a weird file called foo.ref. then you say:

ctwill-refsort < foo.ref > foo.sref

and then another tex foo will produce alphabetized output. iconic. ✨


the ctwill-twinx program compiles a master index for a set of related programs that have been processed by ctwill β€” not by cweave, mind you! 🫡

the individual programs should define their names with a line of the form \def\title{NAME}. for your convenience, ctwill-twinx grabs the first "word" in \title and turns it into uppercase form. you should adapt file twinx-startup.tex for the first page of the master index. πŸŽ€


the mini-indexes list identifiers that are used but not defined on each two-page spread. at the end of each section, ctwill gives TeX a list of identifiers used in that section and information about where they are defined. lowkey genius. 🧚


the current meaning of every identifier is initially \uninitialized. then ctwill reads the .aux file for your job, if any.

before reading the .aux file, ctwill actually looks for a file called system.bux, which will be read if present. and after foo.aux, a third possibility is foo.bux. the general convention is: put definitions of system procedures such as printf into system.bux, and put definitions found in specifically foo-ish header files into foo.bux. like the .aux files, .bux files should contain only @$ specifications.

the meaning specified by @$...@> generally has four components: an identifier (followed by space), a program name (enclosed in braces), a section number (followed by space), and a TeX part. four-for-four, no notes. πŸ“


a special proofmode is provided so you can check ctwill's conclusions about cross-references. run ctwill with the flag +P, and TeX will produce a specially formatted document with mini-indexes for each section, so you can check that your specifications are correct. vibe check: passed. βœ…

this proofmode format is used in conjunction with pdfctproofmac.tex, which creates active hyperlinks in PDF and HINT output. you can use ctwill-proofsort to get the index entries in alphabetical order β€” just invoke:

( ctwill-proofsort < texfile.tex ) 1<> texfile.tex

after invoking ctwill (twice), but before invoking TeX (once). order matters bestie, don't skip steps πŸ’…


more details on how to use ctwill can be found in the first sections of its source code, respectively the change file cweav-twill.ch applicable to the cweave.w source. a complete example with all bells and whistles is described in Mini-Indexes for Literate Programs, pages 225–245 of Knuth's Digital Typography (CSLI, 1999). πŸ“š


πŸ¦‹ DIFFERENCES TO ORIGINAL CTWILL πŸ¦‹

the present incarnation of ctwill and its utilities tries hard to be a drop-in replacement for the original package. ✨ but there are, however, a few differences worth noting:

  • this version is based on the most recent version of CWEB (4.12.2).
  • in TeX Live the utility programs are prefixed with ctwill- and the macro files with ct, for technical reasons.
  • options --help, --quiet, --verbose, --version, and flags +c, -i, -o, and +lX are new in CWEBbin and TeX Live.
  • option +lX is accompanied by example wrapper files for ctwimac.tex and ctproofmac.tex with translated captions for German (+ld).
  • option +lX is also accompanied by an extended pdfctwimac.tex for production of PDF and HINT output with active hyperlinks (+lpdf).
  • file lookup with the environment variable CWEBINPUTS is extended to permit several, colon-separated, paths; see ENVIRONMENT below.
  • if properly configured, the main program ctwill is localized with the "GNU gettext utilities".

✨ OPTIONS ✨

okay so the rules of the game: options on the command line may be either turned off with - (if they're on by default) or turned on with + (if they're off by default).

πŸ“Œ and bestie, listen β€” the options are processed from 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. 🫢
  • +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, fyi)
  • +c β€” check temporary output for changes
  • -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
  • +P β€” \input ctproofmac.tex instead of ctwimac.tex
  • +lX/-lX β€” use macros for language X as of X{ctwimac|ctproofmac}.tex
  • +s β€” print usage statistics
  • +t β€” treat typename in a template like typedef
  • --help β€” display help message and exit
  • --version β€” output version information and exit

🧚 ENVIRONMENT 🧚

the environment variable CWEBINPUTS is used to search for the input files, or the system default if CWEBINPUTS is not set. see tex(1) for the details of the searching. πŸ‘€

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, ctwill β€” like ctangle and cweave β€” uses 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. πŸ”

  • ctwimac.tex β€” the default TeX macros \input in the first line of the output file.
  • ctproofmac.tex β€” if ctwill is invoked with the +P option, it will change the first line of the output file to \input ctproofmac.tex.

in both cases you can request some prefix X with the +lX option, e.g., +ld will \input dctwimac.tex and +Pld will \input dctproofmac.tex. a special application is the use of option +lpdf that will \input pdfctwimac.tex or \input pdfctproofmac.tex for production of PDF and HINT output with active hyperlinks. πŸ”₯

  • webfile.bux β€” reference definitions to resolve from other modules.
  • system.bux β€” reference definitions to resolve from C/C++ standard library header files like <stdio.h>.

other auxiliary files with references are created automatically by ctwill and the actual index files are created by TeX. πŸͺ„

  • 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).
  • CTWILL program source, section 287:

https://mirror.ctan.org/info/knuth-pdf/cweb/ctwill.pdf

  • Digital Typography: by D. E. Knuth (CSLI, 1999).
  • Literate Programming: by D. E. Knuth (CSLI, 1992).
  • Weaving a Program: by Wayne Sewell.

cweb(1), tex(1), cc(1) β€” go read those too bestie, they're the supporting cast 🫢


πŸ‘‘ AUTHORS πŸ‘‘

Don Knuth wrote ctwill based on cweave by Silvio Levy and Knuth. contemporary development on https://github.com/ascherer/cwebbin. absolute legends, no cap. πŸ’œ


and that's the whole page bestie!! mwah πŸ’‹ this was Web2c 2026, dated February 3, 2026 β€” so go forth, run ctwill twice, run TeX twice, and alphabetize those mini-indexes. slay. πŸŽ€βœ¨πŸ’…

πŸ“¦ where this page comes from