. 1
( : 45)

. . >>

page mcmlxxxv)

The book

The ¬ne print in the upper right-hand
corner of each page is a draft of intended
index entries; it won™t appear in the real book.
Some index entries will be in typewriter type
and/or enclosed in . . . , etc;
such typographic distinctions aren™t shown here.
An index entry often extends for several pages;
the actual scope will be determined later.
Please note things that should be indexed but aren™t.
Apology: The xeroxed illustrations are often hard to see;
they will be done professionally in the real book.
(page i)

The book Knuth, Donald Ervin
Bibby, Duane Robert

DONALD E. KNUTH Stanford University

Illustrations by

Reading, Massachusetts
Menlo Park, California
New York
Don Mills, Ontario
Wokingham, England
Amsterdam · Bonn
Sydney · Singapore · Tokyo
Madrid · San Juan
(page ii)

Knuth, Donald Ervin

This manual describes Version 2.0. Some of the advanced features mentioned here
are absent from earlier versions.
The joke on page 8 is due to Richard S. Palais.
The Wilkins quotation on page 283 was suggested by Georgia K. M. Tobin.
is a trademark of Addison “Wesley Publishing Company.
TEX is a trademark of the American Mathematical Society.

Library of Congress cataloging in publication data
Knuth, Donald Ervin, 1938-
(Computers & Typesetting ; C)
Includes index.
1. METAFONT (Computer system). 2. Type and type-
founding--Data processing. I. Title. II. Series:
Knuth, Donald Ervin, 1938- . Computers &
typesetting ; C.
Z250.8.M46K58 1986 686.2'24 85-28675
ISBN 0-201-13445-4
ISBN 0-201-13444-6 (soft)

Incorporates the ¬nal corrections made in 1995.
Internet page http://www-cs-faculty.stanford.edu/˜knuth/abcde.html contains current in-
formation about this book and related books.
Copyright c 1986 by the American Mathematical Society
This book is published jointly by the American Mathematical Society and Addison “Wesley
Publishing Company. All rights reserved. No part of this publication may be reproduced,
stored in a retrieval system, or transmitted, in any form or by any means, electronic, me-
chanical, photocopying, recording, or otherwise, without the prior written permission of the
publishers. Printed in the United States of America.
ISBN 0-201-13445-4
6 7 8 9 10 11 12“CRS“9998979695
(page iii)

Zapf, Hermann

To Hermann Zapf:
Whose strokes are the best
(page iv)
(page v)

Preface beauty

by mathematical means was ¬rst tried in
the ¬fteenth century; it became popular in the sixteenth and seventeenth
centuries; and it was abandoned (for good reasons) during the eighteenth century.
Perhaps the twentieth century will turn out to be the right time for this idea to
make a comeback, now that mathematics has advanced and computers are able
to do the calculations.
Modern printing equipment based on raster lines”in which metal “type”
has been replaced by purely combinatorial patterns of zeroes and ones that spec-
ify the desired position of ink in a discrete way”makes mathematics and com-
puter science increasingly relevant to printing. We now have the ability to give a
completely precise de¬nition of letter shapes that will produce essentially equiv-
alent results on all raster-based machines. Moreover, the shapes can be de¬ned
in terms of variable parameters; computers can “draw” new fonts of characters
in seconds, making it possible for designers to perform valuable experiments that
were previously unthinkable.
is a system for the design of alphabets suited to raster-based
devices that print or display text. The characters that you are reading were all
designed with , in a completely precise way; and they were developed
rather hastily by the author of the system, who is a rank amateur at such things.
It seems clear that further work with has the potential of producing
typefaces of real beauty. This manual has been written for people who would
like to help advance the art of mathematical type design.
A top-notch designer of typefaces needs to have an unusually good eye
and a highly developed sensitivity to the nuances of shapes. A top-notch user of
computer languages needs to have an unusual talent for abstract reasoning and
a highly developed ability to express intuitive ideas in formal terms. Very few
people have both of these unusual combinations of skills; hence the best products
of will probably be collaborative e¬orts between two people who
complement each other™s abilities. Indeed, this situation isn™t very di¬erent from
the way types have been created for many generations, except that the rˆle of o
“punch-cutter” is now being played by skilled computer specialists instead of by
skilled metalworkers.
A user writes a “program” for each letter or symbol of
a typeface. These programs are di¬erent from ordinary computer programs,
because they are essentially declarative rather than imperative. In the -
language you explain where the major components of a desired shape are
vi Preface

to be located, and how they relate to each other, but you don™t have to work
out the details of exactly where the lines cross, etc.; the computer takes over the
work of solving equations as it deduces the consequences of your speci¬cations.
One of the advantages of is that it provides a discipline according to
which the principles of a particular alphabet design can be stated precisely. The
underlying intelligence does not remain hidden in the mind of the designer; it
is spelled out in the programs. Thus consistency can readily be obtained where
consistency is desirable, and a font can readily be extended to new symbols that
are compatible with the existing ones.
It would be nice if a system like were to simplify the task
of type design to the point where beautiful new alphabets could be created in a
few hours. This, alas, is impossible; an enormous amount of subtlety lies behind
the seemingly simple letter shapes that we see every day, and the designers of
high-quality typefaces have done their work so well that we don™t notice the
underlying complexity. One of the disadvantages of is that a person
can easily use it to produce poor alphabets, cheaply and in great quantity. Let
us hope that such experiments will have educational value as they reveal why
the subtle tricks of the trade are important, but let us also hope that they will
not cause bad workmanship to proliferate. Anybody can now produce a book
in which all of the type is home-made, but a person or team of persons should
expect to spend a year or more on the project if the type is actually supposed
to look right. won™t put today™s type designers out of work; on
the contrary, it will tend to make them heroes and heroines, as more and more
people come to appreciate their skills.
Although there is no royal road to type design, there are some things
that can, in fact, be done well with in an afternoon. Geometric
designs are rather easy; and it doesn™t take long to make modi¬cations to letters
or symbols that have previously been expressed in form. Thus,
although comparatively few users of will have the courage to do
an entire alphabet from scratch, there will be many who will enjoy customizing
someone else™s design.
This book is not a text about mathematics or about computers. But
if you know the rudiments of those subjects (namely, contemporary high school
mathematics, together with the knowledge of how to use the text editing or
word processing facilities on your computing machine), you should be able to
use with little di¬culty after reading what follows. Some parts
Preface vii

dangerous bend

of the exposition in the text are more obscure than others, however, since the
author has tried to satisfy experienced ers as well as beginners and
casual users with a single manual. Therefore a special symbol has been used to
warn about esoterica: When you see the sign

at the beginning of a paragraph, watch out for a “dangerous bend” in the train of
thought”don™t read such a paragraph unless you need to. You will be able to use
reasonably well, even to design characters like the dangerous-bend
symbol itself, without reading the ¬ne print in such advanced sections.
Some of the paragraphs in this manual are so far out that they are rated
everything that was said about single dangerous-bend signs goes double for these.
You should probably have at least a month™s experience with before
you attempt to fathom such doubly dangerous depths of the system; in fact,
most people will never need to know in this much detail, even if
they use it every day. After all, it™s possible to fry an egg without knowing
anything about biochemistry. Yet the whole story is here in case you™re curious.
(About , not eggs.)
The reason for such di¬erent levels of complexity is that people change
as they grow accustomed to any powerful tool. When you ¬rst try to use -
, you™ll ¬nd that some parts of it are very easy, while other things will take
some getting used to. At ¬rst you™ll probably try to control the shapes too rigidly,
by overspecifying data that has been copied from some other medium. But later,
after you have begun to get a feeling for what the machine can do well, you™ll
be a di¬erent person, and you™ll be willing to let help contribute to
your designs as they are being developed. As you gain more and more experience
working with this unusual apprentice, your perspective will continue to change
and you will run into di¬erent sorts of challenges. That™s the way it is with any
powerful tool: There™s always more to learn, and there are always better ways
to do what you™ve done before. At every stage in the development you™ll want a
slightly di¬erent sort of manual. You may even want to write one yourself. By
paying attention to the dangerous bend signs in this book you™ll be better able
to focus on the level that interests you at a particular time.
viii Preface


Computer system manuals usually make dull reading, but take heart:
This one contains JOKES every once in a while. You might actually enjoy read-
ing it. (However, most of the jokes can only be appreciated properly if you
understand a technical point that is being made”so read carefully.)
Another noteworthy characteristic of this book is that it doesn™t always
tell the truth. When certain concepts of are introduced informally,
general rules will be stated; afterwards you will ¬nd that the rules aren™t strictly
true. In general, the later chapters contain more reliable information than the
earlier ones do. The author feels that this technique of deliberate lying will
actually make it easier for you to learn the ideas. Once you understand a simple
but false rule, it will not be hard to supplement that rule with its exceptions.
In order to help you internalize what you™re reading, EXERCISES are
sprinkled through this manual. It is generally intended that every reader should
try every exercise, except for questions that appear in the “dangerous bend”
areas. If you can™t solve a problem, you can always look up the answer. But
please, try ¬rst to solve it by yourself; then you™ll learn more and you™ll learn
faster. Furthermore, if you think you do know the solution, you should turn to
Appendix A and check it out, just to make sure.

WARNING: Type design can be hazardous to your other interests.
Once you get hooked, you will develop intense feelings about letter-
forms; the medium will intrude on the messages that you read. And
you will perpetually be thinking of improvements to the fonts that
you see everywhere, especially those of your own design.

The language described here has very little in common with
the author™s previous attempt at a language for alphabet design, because ¬ve
years of experience with the old system has made it clear that a completely
di¬erent approach is preferable. Both languages have been called ;
but henceforth the old language should be called 79, and its use
should rapidly fade away. Let™s keep the name for the language
described here, since it is so much better, and since it will never change again.
I wish to thank the hundreds of people who have helped me to formulate
this “de¬nitive edition” of , based on their experiences with prelim-
inary versions of the system. In particular, John Hobby discovered many of
Preface ix

National Science Foundation
O¬ce of Naval Research
IBM Corporation
System Development Foundation
American Mathematical Society
Knuth, Jill
Knuth, Don

the algorithms that have made the new language possible. My work at Stan-
ford has been generously supported by the National Science Foundation, the
O¬ce of Naval Research, the IBM Corporation, and the System Development
Foundation. I also wish to thank the American Mathematical Society for its
encouragement and for publishing the TUGboat newsletter (see Appendix J).
Above all, I deeply thank my wife, Jill, for the inspiration, understanding, com-
fort, and support she has given me for more than 25 years, especially during the
eight years that I have been working intensively on mathematical typography.
Stanford, California ” D. E. K.
September 1985

It is hoped that Divine Justice may ¬nd
some suitable a¬„iction for the malefactors
who invent variations upon the alphabet of our fathers. . . .
The type-founder, worthy mechanic, has asserted himself
with an overshadowing individuality,
defacing with his monstrous creations and revivals
every publication in the land.
” AMBROSE BIERCE, The Opinionator. Alphabˆtes (1911)

Can the new process yield a result that, say,
a Club of Bibliophiles would recognise as a work of art
comparable to the choice books they have in their cabinets?
” STANLEY MORISON, Typographic Design in Relation to
Photographic Composition (1958)
(page x)

Contents Contents of this manual, table

1 The Name of the Game . . . . . . . . . 1
2 Coordinates . . . . . . . . . . . 5
3 Curves . . . . . . . . . . . . . 13
4 Pens . . . . . . . . . . . . . 21
5 Running . . . . . . . . . . 31
6 How Reads What You Type . . . . . 49
7 Variables . . . . . . . . . . . . 53
8 Algebraic Expressions . . . . . . . . . 59
9 Equations . . . . . . . . . . . . 75
10 Assignments . . . . . . . . . . . 87
11 Magni¬cation and Resolution . . . . . . . . 91
12 Boxes . . . . . . . . . . . . 101
13 Drawing, Filling, and Erasing . . . . . . . . 109
14 Paths . . . . . . . . . . . . 123
15 Transformations . . . . . . . . . . . 141
16 Calligraphic E¬ects . . . . . . . . . 147
17 Grouping . . . . . . . . . . . . 155
18 De¬nitions (also called Macros) . . . . . . . 159
19 Conditions and Loops . . . . . . . . . 169
20 More about Macros . . . . . . . . . 175
21 Random Numbers . . . . . . . . . . 183
22 Strings . . . . . . . . . . . . 187
23 Online Displays . . . . . . . . . . . 191
Contents xi

24 Discreteness and Discretion . . . . . . . . 195
25 Summary of Expressions . . . . . . . . . 209
26 Summary of the Language . . . . . . . . 217
27 Recovering from Errors . . . . . . . . . 223

A Answers to All the Exercises . . . . . . . 233
B Basic Operations . . . . . . . . . . 257
C Character Codes . . . . . . . . . . 281
D Dirty Tricks . . . . . . . . . . . . 285
E Examples . . . . . . . . . . . . 301
F Font Metric Information . . . . . . . . . 315
G Generic Font Files . . . . . . . . . . 323
H Hardcopy Proofs . . . . . . . . . . . 327
I Index . . . . . . . . . . . . 345
J Joining the TEX Community . . . . . . . . 361
(page xii)

The Name of
the Game
Chapter 1: The Name of the Game 1

This is a book about a computer system called , just as The TEXbook TeX
METAFONT, the name
is about TEX. and TEX are good friends who intend to live together meta-font
for a long time. Between them they take care of the two most fundamental tasks
of typesetting: TEX puts characters into the proper positions on a page, while
determines the shapes of the characters themselves.

. 1
( : 45)

. . >>