Realcodeart.com

TeX

The program Knuth wrote so his books would look right.

Donald Knuth

Get it on a mug or tee →

Donald Knuth began TeX in the late 1970s because a new edition of The Art of Computer Programming looked worse than the one it replaced. The first editions had been set in metal type, with the uneven care of a craft that knew how mathematics should sit on a page. Phototypesetting, the new process, had given him pages he did not want his name on. He did what a computer scientist with that particular grievance would do. He wrote a program to set type, and then he spent years making the program good enough that other people's books could depend on it.

TeX thinks of a page as boxes and glue. A character is a box. A line is a box made of smaller boxes. Glue stretches or shrinks between them, within limits. A paragraph is broken by measuring the badness of each possible line break, a score of how far the glue had to stretch, and by adding penalties for things a reader should rarely see, such as a hyphen in a bad place or a lonely word. The line-breaking algorithm Knuth developed with Michael Plass is still the reason a TeX paragraph looks considered rather than merely wrapped. Pages are built from those lines, then shipped to a device-independent file, the DVI, which a later driver turns into marks on paper or pixels on a screen. The program does not know your printer. It knows boxes.

The inner decision procedure is main_control. TeX reads a token, a character or a command that survived the input processor, and it switches on the current mode and on what the token means. Horizontal mode is building a paragraph. Vertical mode is stacking lines into a page. Math mode is a different grammar entirely, with its own spacing. Letters go to the main loop that accumulates a word. Spaces become glue. A command that should not appear in the current mode is an error, or a reason to change mode. The switch is large because the language is large. The bars are that procedure, from the label list through the exit. They are long because the procedure is long. A typesetter's brain, written as a case statement, does not have a short portrait.

Knuth rewrote the program in the early 1980s in WEB, his literate-programming system. The source of TeX is a book that is also a program. You can read the explanation and the code as one document, tex.web, and tangle out the Pascal, later the C, that a machine runs. The version number tracks pi. Each release adds a digit. Knuth has said that when he dies the version should become pi and the program should stop changing. Bugs, when a person finds a real one, are paid for. The bounty and the version are the same idea: this is finished work, and change is a confession.

The name TeX is his, and the program is his, in a way he has been specific about. This catalog does not treat the name as a decoration that can be moved onto a product line. A lawyer cleared the listing of the bars from main_control. The notice on the product page says the program and the name remain his. The piece is marked notice. Clear would mean a public-domain gift. Knuth did not make that gift. He made a tool, documented it as literature, and kept the right to say what the tool is called.

The bars omit the literature. WEB is full of prose, and the prose is his book about his program. The picture keeps the control structure: labels, cases, the exit. A reader who has never set a page can still see that one procedure is deciding, over and over, what kind of thing was just read. That decision is the whole of TeX at the scale of a single token. The page builder, the math list, the hyphenator, and the font tables are other countries. main_control is the border post. Everything comes through it, and the mode it is in determines what the token is allowed to mean. The mug is the border post. The notice is the reason the country's name stays on the page.

A reader who sets type for a living will recognize the switch. A reader who does not can still see the mass of it, which is the point of a bar portrait. The decisions are numerous because written language is numerous. TeX's answer was to face that mass in one procedure and to write the procedure down as literature. The literature stays his. The mass is what the mug is for.

Mug and tee of TeX