A System for Typesetting Mathematics USD:23-1A System for Typesetting MathematicsBrian W. Kernighan and Lorinda L. Cherry AT&T Bell Laboratories Murray Hill, New Jersey 07974ABSTRACTThis paper describes the design and implementation of a system for typesetting mathematics. The language has been designed to be easy to learn and to use by people (for example, secretaries and mathematical typ- ists) who know neither mathematics nor typesetting. Experience indicates that the language can be learned in an hour or so, for it has few rules and fewer excep- tions. For typical expressions, the size and font changes, positioning, line drawing, and the like neces- sary to print according to mathematical conventions are all done automatically. For example, the input sum from i=0 to infinity x sub i = pi over 2 produces oo_̅i_̅ ≥̅ xi=2 The syntax of the=language is specified by a small context-free grammar; a compiler-compiler is used to make a compiler that translates this language into typesetting commands. Output may be produced on either a phototypesetter or on a terminal with forward and reverse half-line motions. The system interfaces directly with text formatting programs, so mixtures of text and mathematics may be handled simply. This paper is a revision of a paper originally published in CACM, March, 1975.1. IntroductionDecember 24, 2022 USD:23-2 A System for Typesetting Mathematics ``Mathematics is known in (``Requires'' is perhaps the the trade asdifficult, or wrong word, but mathematicspenalty,copybecause it is has its own typographical con- slower, more difficult, and ventions which are quite dif- more expensive to set in type ferent from those of ordinary than any other kind of copy text.) Typesetting such an normally occurring in books expression by traditional and journals.'' [1] methods is still an essen- tially manual operation. One difficulty with mathematical text is the mul- A second difficulty is tiplicity of characters, the two dimensional character sizes, and fonts. An expres- of mathematics, which the sion such as superscript and limits in the preceding example showed in lim (tan x)sin 2x = 1 x->i̅i̅/2 its simplest form. This is requires an intimate mixture carried further by of roman, italic and greek______1___________2____ letters, in three sizes, and a a0+ a1+___3___ a2+a3+... special character or two. December 24, 2022 A System for Typesetting Mathematics USD:23-3 and still further by phototypesetter is a device | | _ _ which exposes a piece of pho- |_______log_|_a__m__-__|_b_ |2m\|ab \|aemx+\|b | _ tographic paper or film, plac-_____x_____ |______tanh-1(_|_a_emx) aemx-be-mx |m\|ab \|b | _ ing characters wherever they |______coth-1(_|_a_emx) |m\|ab \|b | are wanted. The Graphic Sys- These examples also show line- tems phototypesetter[2] on the drawing, built-up characters UNIX operating system[3] works like braces and radicals, and by shining light through a a spectrum of positioning character stencil. The charac- problems. (Section 6 shows ter is made the right size by what a user has to type to lenses, and the light beam produce these on our system.) directed by fiber optics to the desired place on a piece2. Photocompositionof photographic paper. The exposed paper is developed and Photocomposition tech- typically used in some form of niques can be used to solve photo-offset reproduction. some of the problems of typesetting mathematics. A December 24, 2022 USD:23-4 A System for Typesetting Mathematics On UNIX, the photo- ``assembly language,'' by typesetter is driven by a for- designing a language for matting program called TROFF describing mathematical [4]. TROFF was designed for expressions, and compiling it setting running text. It also into TROFF. provides all of the facilities that one needs for doing3. Language Designmathematics, such as arbitrary The fundamental principle horizontal and vertical upon which we based our motions, line-drawing, size language design is that the changing, but the syntax for language should be easy to use describing these special by people (for example, secre- operations is difficult to taries) who know neither learn, and difficult even for mathematics nor typesetting. experienced users to type This principle implies correctly. several things. First, ``nor- For this reason we mal'' mathematical conventions decided to use TROFF as an about operator precedence, December 24, 2022 A System for Typesetting Mathematics USD:23-5 operators, and the like. This parentheses, and the like can- keeps the language easy to not be used, for to give spe- learn and remember. Further- cial meaning to such charac- more, there should be few ters means that the user has exceptions to the rules that to understand what he or she do exist: if something works is typing. Thus the language in one situation, it should should not assume, for work everywhere. If a variable instance, that parentheses are can have a subscript, then a always balanced, for they are subscript can have a sub- not in the half-open interval script, and so on without (a,b]. Nor should it assume ___ limit. that that \|a+b can be replaced by (a+b)1/2, or that Third, ``standard'' 1/(1-x) is better written as things should happen automati- ___(or vice versa). 1-x cally. Someone who types Second, there should be ``x=y+z+1'' should get relatively few rules, key- ``x=y+z+1''. Subscripts and words, special symbols and superscripts should automati- December 24, 2022 USD:23-6 A System for Typesetting Mathematics cally be printed in an typed on a computer terminal appropriately smaller size, much like an ordinary type- with no special intervention. writer. This implies an input Fraction bars have to be made alphabet of perhaps 100 char- the right length and posi- acters, none of them special. tioned at the right height. A secondary, but still And so on. Indeed a mechanism important, goal in our design for overriding default actions was that the system should be has to exist, but its applica- easy to implement, since nei- tion is the exception, not the ther of the authors had any rule. desire to make a long-term We assume that the typist project of it. Since our has a reasonable picture (a design was not firm, it was two-dimensional representa- also necessary that the pro- tion) of the desired final gram be easy to change at any form, as might be handwritten time. by the author of a paper. We To make the program easy also assume that the input is to build and to change, and to December 24, 2022 A System for Typesetting Mathematics USD:23-7 guarantee regularity (``it significant examples required should work everywhere''), the perhaps a person-month. Since language is defined by a then, we have spent a modest context-free grammar, amount of additional time over described in Section 5. The several years tuning, adding compiler for the language was facilities, and occasionally built using a compiler- changing the language as users compiler. make criticisms and sugges- tions. A priori, the grammar/compiler-compiler We also decided quite approach seemed the right early that we would let TROFF thing to do. Our subsequent do our work for us whenever experience leads us to believe possible. TROFF is quite a that any other course would powerful program, with a macro have been folly. The original facility, text and arithmetic language was designed in a few variables, numerical computa- days. Construction of a work- tion and testing, and condi- ing system sufficient to try tional branching. Thus we have December 24, 2022 USD:23-8 A System for Typesetting Mathematics been able to avoid writing a Since our program is only use- lot of mundane but tricky ful for typesetting mathemat- software. For example, we ics, it is necessary that it store no text strings, but interface cleanly with the simply pass them on to TROFF. underlying typesetting Thus we avoid having to write language for the benefit of a storage management package. users who want to set inter- Furthermore, we have been able mingled mathematics and text to isolate ourselves from most (the usual case). The standard details of the particular dev- mode of operation is that when ice and character set a document is typed, mathemat- currently in use. For example, ical expressions are input as we let TROFF compute the part of the text, but marked widths of all strings of char- by user settable delimiters. acters; we need know nothing The program reads this input about them. and treats as comments those things which are not mathemat- A third design goal is ics, simply passing them special to our environment. December 24, 2022 A System for Typesetting Mathematics USD:23-9 through untouched. At the same as they are handed to the time it converts the mathemat- typesetting program ical input into the necessary (hereinafter called ``EQN''), TROFF commands. The resulting except that we won't show the ioutput is passed directly to delimiters that the user types TROFF where the comments and to mark the beginning and end the mathematical parts both of the expression. The inter- become text and/or TROFF com- face between EQN and TROFF is mands. described at the end of this section.4. The LanguageAs we said, typing We will not try to x=y+z+1 should produce describe the language pre- x=y+z+1, and indeed it does. cisely here; interested Variables are made italic, readers may refer to the operators and digits become appendix for more details. roman, and normal spacings Throughout this section, we between letters and operators will write expressions exactly are altered slightly to give a December 24, 2022 USD:23-10 A System for Typesetting Mathematics more pleasing appearance. may be typed as many short Input is free-form. lines. Spaces and new lines in the input are used by EQN to separate pieces of the input; Extra white space can be they are not used to create space in the output. Thus forced into the output by x = y several characters of various + z + 1 also gives x=y+z+1. Free-form sizes. A tilde ``~'' gives a input is easier to type ini- space equal to the normal word tially; subsequent editing is spacing in text; a circumflex also easier, for an expression gives half this much, and a December 24, 2022 A System for Typesetting Mathematics USD:23-11 tab charcter spaces to the Here spaces arenecessaryin next tab stop. the input to indicate thatsin,pi,int, andomegaare Spaces (or tildes, etc.) special, and potentially worth also serve to delimit pieces special treatment. EQN looks of the input. For example, to up each such string of charac- get ters in a table, and if f(t)=2i̅i̅sin(wt)dt we write appropriate gives it a trans- f(t) = 2 pi int sin ( omega t )dlation. In this case,piand December 24, 2022 USD:23-12 A System for Typesetting Mathematicsomegabecome their greek roman wherever found. equivalents,intbecomes the Fractions are specified integral sign (which must be with the keywordover: moved down and enlarged so it a+b over c+d+e = 1 looks ``right''), andsinis produces made roman, following conven-__±__=1 c+d+e tional mathematical practice. Similarly, subscripts and Parentheses, digits and opera- superscripts are introduced by tors are automatically made the keywordssubandsup: December 24, 2022 A System for Typesetting Mathematics USD:23-13 x2+y2=z2 is automatic. Multiple levels is produced by of subscripts or superscripts x sup 2 + y sup 2 = z sup 2 are of course allowed: The spaces after the 2's are ``xsupysupz'' is xyz. The con- necessary to mark the end of struct ``somethingsubsome- the superscripts; similarly thingsupsomething'' is the keywordsuphas to be recognized as a special case, marked off by spaces or some 2 so ``x sub i sup 2'' is xi equivalent delimiter. The instead of xi2. return to the proper baseline December 24, 2022 USD:23-14 A System for Typesetting Mathematics More complicated expres- they indicate unambiguously sions can now be formed with what goes over what on the these primitives: left-hand side of the expres- sion. The language defines the`__f_=_2_+_2_`x2 a2 b2 is produced by precedence ofsupto be higher {partial sup 2 f} over {partial x sup 2} = than that ofover, so no x sup 2 over a sup 2 + y sup 2 over b sup 2 braces are needed to get the Braces {} are used to group correct association on the objects together; in this case right side. Braces can always December 24, 2022 A System for Typesetting Mathematics USD:23-15 be used when in doubt about in braces can also occur in precedence. that context. The braces convention is There is asqrtoperator an example of the power of for making square roots of the using a recursive grammar to appropriate size: ``sqrt a+b'' ___ define the language. It is produces \|a+b, and part of the language that if a x = {-b +- sqrt{b sup 2 -4ac}} over 2a construct can appear in some is context, thenany expression_______b__\__b__-__a__c x= 2a December 24, 2022 USD:23-16 A System for Typesetting Mathematics Since large radicals look poor sum from i=0 to inf x sub i -> 0 on our typesetter,sqrtis not Centering and making the ≥̅ big useful for tall expressions. enough and the limits smaller Limits on summations, are all automatic. Thefromintegrals and similar con- andtoparts are both structions are specified with optional, and the central part the keywordsfromandto. To (e.g., the ≥̅) can in fact be get anything: oo ≥̅ xi->0 i=0 we need only type December 24, 2022 A System for Typesetting Mathematics USD:23-17 of the right height, using the lim from {x -> pi /2} ( tan~x) = inf keywordsleftandright: is left [ x+y over 2a right ]~=~1 lim (tan x)=oo x->i̅i̅/2 Again, the braces indicate makes just what goes into thefrom|_±_||2a | = 1 part. Aleftneed not have a There is a facility for correspondingright, as we making braces, brackets, shall see in the next example. parentheses, and vertical bars Any characters may followleftDecember 24, 2022 USD:23-18 A System for Typesetting Mathematics andright, but generally only we can type various parentheses and bars sign (x) ~==~ left { are meaningful. rpile {1 above 0 above -1} Big brackets, etc., are ~~lpile {if above if above if} often used with another facil- ~~lpile {x>0 above x=0 above x<0} ity, calledpiles, which make The construction ``left {'' vertical piles of objects. For makes a left brace big enough example, to get to enclose the ``rpile | | 1 sign(x)_| 0 if |-1 if x>0 | if x=0 {...}'', which is a right- x<0 December 24, 2022 A System for Typesetting Mathematics USD:23-19 justified pile of ``above ... Although EQN makes a above ...''. ``lpile'' makes a valiant attempt to use the left-justified pile. There are right sizes and fonts, there also centered piles. Because are times when the default of the recursive language assumptions are simply not definition, a pile can contain what is wanted. For instance any number of elements; any the italicsignin the previ- element of a pile can of ous example would convention- course contain piles. ally be in roman. Slides and December 24, 2022 USD:23-20 A System for Typesetting Mathematics transparencies often require is 1/72 inch; this paper is larger characters than normal set in 9 point type.) text. Thus we also provide If necessary, an input size and font changing com- string can be quoted in "...", mands: ``size 12 bold which turns off grammatical {A~x~=~y}'' will produce significance, and any font or A x = y.Sizeis followed by a spacing changes that might number representing a charac- otherwise be done on it. Thus ter size in points. (One point we can say December 24, 2022 A System for Typesetting Mathematics USD:23-21 lim~ roman "sup" ~x sub n = 0 x dot under + x hat + y tilde + X hat + Y dotdot = z+Z bar to ensure that the supremum doesn't become a superscript: There are also facilities lim sup xn=0 for globally changing default Diacritical marks, long a sizes and fonts, for example problem in traditional for making viewgraphs or for typesetting, are straightfor- setting chemical equations. ward: The language allows for . .. ____+^+y̅+^+Y =z+Z matrices, and for lining up is made by typing December 24, 2022 USD:23-22 A System for Typesetting Mathematics equations at the same horizon- expression will be expanded tal position. into whatever was inside the double quotes in its defini- Finally, there is a tion. This lets users tailor definition facility, so a user the language to their own can say specifications, for it is define name "..." quite possible to redefine at any time in the document; keywords likesuporover. henceforth, any occurrence of Section 6 shows an example of the token ``name'' in an December 24, 2022 A System for Typesetting Mathematics USD:23-23 definitions. the sequence ``.EQ'' to mark the beginning of an equation The EQN preprocessor and ``.EN'' to mark the end. reads intermixed text and The ``.EQ'' and ``.EN'' are equations, and passes its out- passed through to TROFF put to TROFF. Since TROFF uses untouched, so they can also be lines beginning with a period used by a knowledgeable user as control words (e.g., to center equations, number ``.ce'' means ``center the them automatically, etc. By next output line''), EQN uses December 24, 2022 USD:23-24 A System for Typesetting Mathematics default, however, ``.EQ'' and input: ``.EN'' are simply ignored by .ce TROFF, so by default equations .EQ are printed in-line. x sub i = y sub i ... ``.EQ'' and ``.EN'' can .EN be supplemented by TROFF com- Since it is tedious to mands as desired; for example, type ``.EQ'' and ``.EN'' a centered display equation around very short expressions can be produced with the (single letters, for December 24, 2022 A System for Typesetting Mathematics USD:23-25 instance), the user can also Let #x sub i#, #y# and #alpha# be positive define two characters to serve produces: as the left and right delim- Let xi, y and(be positive iters of expressions. These Running a preprocessor is characters are recognized any- strikingly easy on UNIX. To where in subsequent text. For typeset text stored in file example if the left and right ``f'', one issues the command: delimiters have both been set to ``#'', the input: eqn f | troff December 24, 2022 USD:23-26 A System for Typesetting Mathematics The vertical bar connects the various ways. For example, output of one process (EQN) to something with a subscript is the input of another (TROFF). just a box followed by another box moved downward and shrunk5. Language Theoryby an appropriate amount. A The basic structure of fraction is just a box cen- the language is not a particu- tered above another box, at larly original one. Equations the right altitude, with a are pictured as a set of line of correct length drawn ``boxes,'' pieced together in December 24, 2022 A System for Typesetting Mathematics USD:23-27 between them. guarantee that some keyword is recognized early enough in the The grammar for the parsing process. Symbols in language is shown below. For capital letters are terminal purposes of exposition, we symbols; lower case symbols have collapsed some produc- are non-terminals, i.e., syn- tions. In the original gram- tactic categories. The verti- mar, there are about 70 pro- cal bar | indicates an alter- ductions, but many of these native; the brackets [ ] indi- are simple ones used only to December 24, 2022 USD:23-28 A System for Typesetting Mathematics cate optional material. A TEXT eqn: box | eqn box is a string of non-blank char- box: text acters or any string inside | { eqn } double quotes; the other ter- | box OVER box minal symbols represent | SQRT box literal occurrences of the | box SUB box | box SUP box corresponding keyword. | [ L | C | R ]PILE { list } | LEFT text eqn [ RIGHT text ] | box [ FROM box ] [ TO box ] December 24, 2022 A System for Typesetting Mathematics USD:23-29 | SIZE text box observation that something can | [ROMAN | BOLD | ITALIC] box be replaced by a more compli- | box [HAT | BAR | DOT | DOTDOTcatedLDsomething in braces is | DEFINE text text implicit in the productions: list: eqn | list ABOVE eqn eqn : box | eqn box text: TEXT box : text | { eqn } The grammar makes it Anywhere a single character obvious why there are few could be used,anylegal con- exceptions. For example, the struction can be used. December 24, 2022 USD:23-30 A System for Typesetting Mathematics Clearly, our grammar is a over {b over c} ? highly ambiguous. What, for To answer questions like instance, do we do with the this, the grammar is supple- input mented with a small set of a over b over c ? rules that describe the pre- Is it cedence and associativity of {a over b} over c operators. In particular, we specify (more or less arbi- or is it trarily) thatoverassociates December 24, 2022 A System for Typesetting Mathematics USD:23-31 to the left, so the first resolve the ambiguity in a alternative above is the one construction like chosen. On the other hand,suba sup 2 over b andsupbind to the right, We definesupto have a higher because this is closer to precedence thanover, so this standard mathematical prac-_2_ construction is parsed as b tice. That is, we assume xab _2 b. instead of a is x(ab), not (xa)b. Naturally, a user can The precedence rules always force a particular December 24, 2022 USD:23-32 A System for Typesetting Mathematics parsing by placing braces resolving ambiguity. Instead around expressions. the supplemental information about precedence and associa- The ambiguous grammar tivity (also small enough to approach seems to be quite be understood) provides the useful. The grammar we use is compiler-compiler with the small enough to be easily information it needs to make a understood, for it contains fast, deterministic parser for none of the productions that the specific language we want. would be normally used for December 24, 2022 A System for Typesetting Mathematics USD:23-33 When the language is supple- mands are output. For example, mented by the disambiguating when the lexical analyzer rules, it is in fact LR(1) and reports that it has found a thus easy to parse[5]. TEXT (i.e., a string of con- tiguous characters), we have The output code is gen- recognized the production: erated as the input is scanned. Any time a production text : TEXT of the grammar is recognized, The translation of this is (potentially) some TROFF com- simple. We generate a local December 24, 2022 USD:23-34 A System for Typesetting Mathematics name for the string, then hand the production the name and the string to box : box OVER box TROFF, and let TROFF perform is: the storage management. All we save is the name of the string, its height, and its baseline. As another example, the translation associated with December 24, 2022 A System for Typesetting Mathematics USD:23-35 draw bottom box (i.e., copy string for bottom box); Width of output box = move up; move left enough to center top box; slightly more than largest input width draw top box (i.e., copy string for top box); Height of output box = move down and left; draw line full width; slightly more than sum of input heights return to proper base line. Base of output box = slightly more than height of botMostiofutheoother productions String describing output box = have equally simple semantic move down; actions. Picturing the output move right enough to center bottasbax;set of properly placed December 24, 2022 USD:23-36 A System for Typesetting Mathematics boxes makes the right sequence one of our users suggested a of positioning commands quite TENSOR operator, to make con- obvious. The main difficulty structions like is in finding the right kj lT mni Grammatically, this is easy: numbers to use for estheti- it is sufficient to add a pro- cally pleasing positioning. duction like With a grammar, it is box : TENSOR { list } usually clear how to extend Semantically, we need only the language. For instance, December 24, 2022 A System for Typesetting Mathematics USD:23-37 juggle the boxes to the right The first question is places. easily addressed. This entire paper has been set by the pro-6. Experiencegram. Readers can judge for There are really three themselves whether it is good aspects of interest-how well enough for their purposes. One EQN sets mathematics, how well of our users commented that it satisfies its goal of being although the output is not as ``easy to use,'' and how easy good as the best hand-set it was to build. December 24, 2022 USD:23-38 A System for Typesetting Mathematics material, it is still better tages. than average, and much better Some of the deficiencies than the worst. In any case, in the output could be cleaned who cares? Printed books can- up with more work on our part. not compete with the birds and For example, we sometimes flowers of illuminated leave too much space between a manuscripts on esthetic roman letter and an italic grounds, either, but they have one. If we were willing to some clear economic advan- keep track of the fonts December 24, 2022 A System for Typesetting Mathematics USD:23-39 involved, we could do this As to ease of use, at the better more of the time. time of writing, the system has been used by two distinct Some other weaknesses are groups. One user population inherent in our output device. consists of mathematicians, It is hard, for instance, to chemists, physicists, and com- draw a line of an arbitrary puter scientists. Their typi- length without getting a per- cal reaction has been some- ceptible overstrike at one thing like: end. December 24, 2022 USD:23-40 A System for Typesetting Mathematics (1) It's easy to write, The learning time is although I make the fol- short. A few minutes gives the lowing mistakes... general flavor, and typing a page or two of a paper gen- (2) How do I do...? erally uncovers most of the (3) It botches the following misconceptions about how it things.... Why don't you works. fix them? The second user group is (4) You really need the fol- much larger, the secretaries lowing features... December 24, 2022 A System for Typesetting Mathematics USD:23-41 and mathematical typists who critical of the esthetics of were the original target of their output than users the system. They tend to be trained in mathematics. After enthusiastic converts. They a transition period, most find find the language easy to using a computer more learn (most are largely self- interesting than a regular taught), and have little trou- typewriter. ble producing the output they The main difficulty that want. They are of course less users have seems to be December 24, 2022 USD:23-42 A System for Typesetting Mathematics remembering that a blank is a instead of delimiter; even experienced f(xi) Since the EQN language knows users use blanks where they no mathematics, it cannot shouldn't and omit them when deduce that the right they are needed. A common parenthesis is not part of the instance is typing subscript. f(x sub i) The language is somewhat which produces prolix, but this doesn't seem f(xi) excessive considering how much December 24, 2022 A System for Typesetting Mathematics USD:23-43 is being done, and it is cer- a sub 0 + b sub 1 over tainly more compact than the {a sub 1 + b sub 2 over corresponding TROFF commands. {a sub 2 + b sub 3 over For example, here is the {a sub 3 + ... }}} source for the continued frac- This is the input for the tion expression in Section 1 large integral of Section 1; of this paper: notice the use of definitions: December 24, 2022 USD:23-44 A System for Typesetting Mathematics 1 over mab ~ tanh sup -1 ( sa over sb emx ) define emx "{e sup mx}" above define mab "{m sqrt ab}" -1 over mab ~ coth sup -1 ( sa over sb emx ) define sa "{sqrt a}" } define sb "{sqrt b}" int dx over {a emx - be sup -mx} ~=~ As to ease of construc- left { lpile { tion, we have already men- 1 over {2 mab} ~log~ tioned that there are really {sa emx - sb} over {sa emx + sb} only a few person-months above invested. Much of this time December 24, 2022 A System for Typesetting Mathematics USD:23-45 has gone into two things-fine- The program consists of a tuning (what is the most number of small, essentially esthetically pleasing space to unconnected modules for code use between the numerator and generation, a simple lexical denominator of a fraction?), analyzer, a canned parser and changing things found which we did not have to deficient by our users write, and some miscellany (shouldn't a tilde be a delim- associated with input files iter?). and the macro facility. The December 24, 2022 USD:23-46 A System for Typesetting Mathematics program is now about 1600 commands can be changed to lines of C [6], a high-level accommodate other formatting language reminiscent of BCPL. languages and devices. For About 20 percent of these example, in less than 24 lines are ``print'' state- hours, one of us changed the ments, generating the output entire semantic package to code. drive NROFF, a variant of TROFF, for typesetting The semantic routines mathematics on teletypewriter that generate the actual TROFF December 24, 2022 A System for Typesetting Mathematics USD:23-47 devices capable of reverse and sometimes even for ulti- line motions. Since many mate use. potential users do not have7. Conclusionsaccess to a typesetter, but We think we have shown still have to type mathemat- that it is possible to do ics, this provides a way to acceptably good typesetting of get a typed version of the mathematics on a photo- final output which is close typesetter, with an input enough for debugging purposes, language that is easy to learn December 24, 2022 USD:23-48 A System for Typesetting Mathematics and use and that satisfies like the only sensible way to many users' demands. Such a do business. Our experience package can be implemented in with the use of a grammar and short order, given a compiler- a compiler-compiler has been compiler and a decent typeset- uniformly favorable. If we had ting program underneath. written everything into code directly, we would have been Defining a language, and locked into our original building a compiler for it design. Furthermore, we would with a compiler-compiler seems December 24, 2022 A System for Typesetting Mathematics USD:23-49 have never been sure where theAcknowledgementsexceptions and special cases We are deeply indebted to were. But because we have a J. F. Ossanna, the author of grammar, we can change our TROFF, for his willingness to minds readily and still be modify TROFF to make our task reasonably sure that if a con- easier and for his continuous struction works in one place assistance during the develop- it will work everywhere. ment of our program. We are also grateful to A. V. Aho for December 24, 2022 USD:23-50 A System for Typesetting Mathematics help with language theory, to [1]A Manual of Style, 12th S. C. Johnson for aid with the Edition. University of compiler-compiler, and to our Chicago Press, 1969. p early users A. V. Aho, S. I. 295. Feldman, S. C. Johnson, R. W. [2]Model C/A/T Photo-Hamming, and M. D. McIlroy fortypesetter. Graphic Sys- their constructive criticisms. tems, Inc., Hudson, N. H. [3] Ritchie, D. M., andReferencesThompson, K. L., ``The December 24, 2022 A System for Typesetting Mathematics USD:23-51 UNIX time-sharing sys- S. C., ``LR Parsing.'' tem.''Comm. ACM 17, 7Comp. Surv. 6, 2 (June (July 1974), 365-375. 1974), 99-124. [4] Ossanna, J. F., TROFF [6] B. W. Kernighan and D. M. User's Manual. Bell Ritchie,The C Program-Laboratories Computingming Language. Prentice- Science Technical Report Hall, Inc., 1978. 54, 1977. [5] Aho, A. V., and Johnson, December 24, 2022