Skip to content
sjnamPublic

About

Literate programming system for Go

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Repository files navigation

GWEB — Literate programming for Go

CI License: Unlicense

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

Install

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 own

This installs both commands and the TeX macros; ./install.sh --help lists the options.

Usage

gtangle foo.gw    # -> foo.go
gweave  foo.gw    # -> foo.tex
pdftex  foo.tex   # -> foo.pdf

Both 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.

Documentation

Examples and related projects

Small examples are in examples/. Larger work, mostly Knuth's programs translated into Go with Korean commentary:

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.

Development

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 itself

On a fresh checkout, build with make rather than go build ./...: the Go for gweave is generated, not committed.

License

Public domain, under the Unlicense.

About

Literate programming system for Go

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages