GWEB is a literate programming
system for Go, modeled closely on Donald Knuth and Silvio Levy's CWEB. You write
one .gw file that interleaves TeX documentation with Go code, and two tools turn it
into a program or a typeset document:
| CWEB | GWEB | purpose |
|---|---|---|
ctangle |
gtangle |
extract compilable source (.go) for the machine |
cweave |
gweave |
produce a typeset document (.tex → PDF) for people |
You need Go and a TeX distribution such as TeX Live or MacTeX. From a checkout:
./install.sh # into /usr/local (may need sudo)
./install.sh --prefix="$HOME/.local" # or a prefix of your ownThis installs both commands and the TeX macros; ./install.sh --help lists the options.
gtangle foo.gw # -> foo.go
gweave foo.gw # -> foo.tex
pdftex foo.tex # -> foo.pdfBoth commands take an optional change file, as in gtangle foo.gw foo.ch, which
patches the web without editing it. Compiler errors and panic traces point at lines of
the .gw file, not the generated Go.
For webs written in Korean, put \input kotexgweb at the top, typeset with luatex,
and install these fonts: Noto Serif CJK KR, Noto Sans CJK KR,
and Noto Sans Mono CJK KR.
- Manual — gwebman.tex (
make manual), or in Korean gwebman-ko.tex (make manual-ko) - File format — format.md, every control code
- Editor support — editors/vscode, a VS Code extension
Small examples are in examples/. Larger work, mostly Knuth's programs translated into Go with Korean commentary:
- gweb-examples — some forty literate programs
- tex-the-program — TeX: The Program
- metafont-the-program — METAFONT: The Program
- go-mmix — MMIXware
- go-sgb — the Stanford GraphBase
- go-advent — Colossal Cave Adventure, playable in Korean
GWEB's sister program gtwill, the counterpart of Knuth's CTWILL, typesets a web as a book with a mini-index on every right-hand page.
GWEB is written in itself, so edit the .gw files, not the generated Go.
make build # build bin/gtangle and bin/gweave
make test # run the tests
make tangle # regenerate the Go from the .gw sources
make bootstrap # check that GWEB reproduces itselfOn a fresh checkout, build with make rather than go build ./...: the Go for gweave
is generated, not committed.
Public domain, under the Unlicense.