# To unbundle, run this file echo e.mac sed 's/.//' >e.mac <<'//GO.SYSIN DD e.mac' -.tr _\(em -.tr *\(** -.de UC -\&\\$3\s-1\\$1\\s0\&\\$2 -.. -.de IT -.if n .ul -\&\\$3\f2\\$1\fP\&\\$2 -.. -.de UL -.if n .ul -\&\\$3\f3\\$1\fP\&\\$2 -.. -.de BD -.bd 3 \\$1 -.. -.de BI -.bd I \\$1 -.. -.de P1 -.DS I 3n -.nf -.if n .ta 5 10 15 20 25 30 35 40 45 50 55 60 -.if t .ta .4i .8i 1.2i 1.6i 2i 2.4i 2.8i 3.2i 3.6i 4i 4.4i 4.8i 5.2i 5.6i -.if t .tr -\(mi|\(bv'\(fm^\(no*\(** -.tr `\(ga'\(aa -.if t .tr _\(ul -. \"use first argument as indent if present -.. -.de P2 -.if n .ls 2 -.tr --||''``^^!! -.if t .tr _\(em -.DE -.. -.hw semi-colon -.hw estab-lished -.hy 14 -. \"2=not last lines; 4= no -xx; 8=no xx- -. \"special chars in programs -.ds . \s\\nP.\s0 -.ds , \s\\nP,\s0 -.ds ; \s\\nP\z,\v'-.3m'.\v'.3m'\s0 -.ds : \s\\nP\z.\v'-.3m'.\v'.3m'\s0 -.ds ' \s\\nQ\v'.25m'\(fm\v'-.25m'\s0 -.ds ^ \h'-.1m'\(no\h'.1m' -.de WS -.sp \\$1 -.. //GO.SYSIN DD e.mac echo e0 sed 's/.//' >e0 <<'//GO.SYSIN DD e0' -.nr PS 9 -.nr VS 11 -....ND "Revised April, 1977" -.EQ -delim $$ -gsize 9 -.EN -....TR 17 -.TL -A System for Typesetting Mathematics -.AU -Brian W. Kernighan and Lorinda L. Cherry -.AI -.MH -.AB -.PP -This 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 typists) -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 exceptions. -For typical expressions, -the size and font changes, positioning, line drawing, -and the like necessary to print according to mathematical conventions -are all done automatically. -For example, -the input -.sp 4p -.ce -sum from i=0 to infinity x sub i = pi over 2 -.sp 4p -produces -.EQ -sum from i=0 to infinity x sub i = pi over 2 -.EN -.PP -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. -.LP -.LP -.PP -This paper is a revision of a paper originally published in -CACM, March, 1975. -.AE //GO.SYSIN DD e0 echo e1 sed 's/.//' >e1 <<'//GO.SYSIN DD e1' -.2C $gsize 9$ -.nr PS 9 -.nr VS 11p -.NH -Introduction -.PP -``Mathematics is known in the trade as -.ul -difficult, -or -.ul -penalty, copy -because it is slower, more difficult, -and more expensive to set in type -than any other kind of copy normally -occurring in books and journals.'' -[1] -.PP -One difficulty with mathematical text -is the multiplicity of characters, -sizes, and fonts. -An expression such as -.EQ -lim from {x-> pi /2} ( tan~x) sup{sin~2x}~=~1 -.EN -requires an intimate mixture of roman, italic and greek letters, in three sizes, -and a special character or two. -(``Requires'' is perhaps the wrong word, -but mathematics has its own typographical conventions -which are quite different from those -of ordinary text.) -Typesetting such an expression by traditional methods -is still an essentially manual operation. -.PP -A second difficulty is the two dimensional character -of mathematics, -which the superscript and limits in the preceding example -showed in its simplest form. -This is carried further by -.EQ -a sub 0 + b sub 1 over - {a sub 1 + b sub 2 over - {a sub 2 + b sub 3 over - {a sub 3 + ... }}} -.EN -.sp -and still further by -.EQ -define emx "{e sup mx}" -define mab "{m sqrt ab}" -define sa "{sqrt a}" -define sb "{sqrt b}" -int dx over {a emx - be sup -mx} ~=~ -left { lpile { - 1 over {2 mab} ~log~ {sa emx - sb} over {sa emx + sb} - above - 1 over mab ~ tanh sup -1 ( sa over sb emx ) - above - -1 over mab ~ coth sup -1 ( sa over sb emx ) -} -.EN -These examples also show line-drawing, built-up characters like braces and radicals, -and a spectrum of positioning problems. -(Section 6 shows -what a user has to type to produce these -on our system.) //GO.SYSIN DD e1 echo e2 sed 's/.//' >e2 <<'//GO.SYSIN DD e2' -.NH -Photocomposition -.PP -Photocomposition techniques -can be used to solve some of the problems of typesetting mathematics. -A phototypesetter is a device which exposes -a piece of photographic paper or film, placing characters -wherever they are wanted. -The Graphic Systems phototypesetter[2] on the -.UC UNIX -operating -system[3] works by shining light through a character stencil. -The character is made the right size by lenses, -and the light beam directed by fiber optics -to the desired place on a piece of photographic paper. -The exposed paper is developed and typically used -in some form of photo-offset reproduction. -.PP -On -.UC UNIX , -the phototypesetter is driven by a formatting program called -.UC TROFF -[4]. -.UC TROFF -was designed for setting running text. -It also provides all of the facilities that one needs for -doing mathematics, such as -arbitrary horizontal and vertical motions, -line-drawing, size changing, -but the syntax for describing these special operations is -difficult to learn, -and difficult even for experienced users to type correctly. -.PP -For this reason we decided to use -.UC TROFF -as an ``assembly language,'' -by -designing a language for describing mathematical -expressions, -and compiling it into -.UC TROFF . //GO.SYSIN DD e2 echo e3 sed 's/.//' >e3 <<'//GO.SYSIN DD e3' -.NH -Language Design -.PP -The fundamental principle upon which we based our language design -is that the language should be easy to use -by people (for example, secretaries) who know neither mathematics nor typesetting. -.PP -This principle implies -several things. -First, -``normal'' mathematical conventions about operator precedence, -parentheses, and the like cannot be used, -for to give special meaning to such characters means -that the user has to understand what he or she -is typing. -Thus the language should not assume, for instance, -that parentheses are always balanced, -for they are not in -the half-open interval $(a,b]$. -Nor should it assume that -that $sqrt{a+b}$ can be replaced by -$(a+b) sup roman \(12$, -or that $1/(1-x)$ is better written as $1 over 1-x$ -(or -vice versa). -.PP -Second, there should be relatively few rules, -keywords, -special symbols and operators, and the like. -This keeps the language easy to learn and remember. Furthermore, there should be few exceptions to -the rules that do exist: -if something works in one situation, -it should work everywhere. -If a variable can have a subscript, -then a subscript can have a subscript, and so on without limit. -.PP -Third, ``standard'' things should happen automatically. -Someone who types ``x=y+z+1'' should get ``$x=y+z+1$''. -Subscripts and superscripts should automatically -be printed in an appropriately smaller size, -with no special intervention. -Fraction bars have to be made the right length and positioned at the -right height. -And so on. -Indeed a mechanism for overriding default actions has to exist, -but its application is the exception, not the rule. -.PP -We assume -that the typist has a reasonable picture -(a two-dimensional representation) -of the desired final form, as might be handwritten -by the author of a paper. -We also assume that -the input is typed on a computer terminal much like an ordinary typewriter. -This implies an input alphabet -of perhaps 100 characters, -none of them special. -.PP -A secondary, but still important, goal in our design -was that the system should be easy to implement, -since neither of the authors had any desire to make -a long-term project of it. -Since our design was not firm, -it was also necessary that the program be easy to change -at any time. -.PP -To make the program easy to build and to change, -and to guarantee regularity -(``it should work everywhere''), -the language is defined by a -context-free grammar, described in Section 5. -The compiler for the language was built using a compiler-compiler. -.PP -A priori, -the grammar/compiler-compiler approach seemed the right thing to do. -Our subsequent experience leads us to believe -that any other course would have been folly. -The original language was designed in a few days. -Construction of a working system -sufficient to try significant examples -required perhaps a person-month. -Since then, we have spent a modest amount of additional time -over several years -tuning, adding facilities, -and occasionally changing the language as users -make criticisms and suggestions. -.PP -We also decided quite early that -we would let -.UC TROFF -do our work for us whenever possible. -.UC TROFF -is quite a powerful program, with -a macro facility, text and arithmetic variables, numerical computation and testing, -and conditional branching. -Thus we have been able to avoid writing -a lot of mundane but tricky software. -For example, we store no text strings, -but simply pass them on to -.UC TROFF . -Thus we avoid having to write a storage management package. -Furthermore, we have been able to isolate ourselves -from most details of the particular device and character set -currently in use. -For example, we let -.UC TROFF -compute the widths of all strings of characters; -we need know nothing about them. -.PP -A third design goal is special to our environment. -Since our program is only useful for typesetting mathematics, -it is necessary that it interface cleanly with the underlying typesetting language -for the benefit of users -who want to set intermingled mathematics and text -(the usual case). -The standard mode of operation -is that when a document is typed, -mathematical expressions are input as part of the text, -but marked by user settable delimiters. -The program reads this input and treats as comments -those things which are not mathematics, -simply passing them through untouched. -At the same time it converts the mathematical input -into the necessary -.UC TROFF -commands. -The resulting ioutput is passed directly to -.UC TROFF -where the comments and the mathematical parts both become -text and/or -.UC TROFF -commands. //GO.SYSIN DD e3 echo e4 sed 's/.//' >e4 <<'//GO.SYSIN DD e4' -.NH -The Language -.PP -We will not try to describe the language precisely here; -interested readers may refer to the appendix for more details. -Throughout this section, we will write expressions -exactly -as they are handed to the typesetting program (hereinafter called -.UC ``EQN'' ), -except that we won't show the delimiters -that the user types to mark the beginning and end of the expression. -The interface between -.UC EQN -and -.UC TROFF -is described at the end of this section. -.PP -As we said, typing x=y+z+1 should produce $x=y+z+1$, -and indeed it does. -Variables are made italic, operators and digits become roman, -and normal spacings between letters and operators are altered slightly -to give a more pleasing appearance. -.PP -Input is free-form. -Spaces and new lines in the input are used by -.UC EQN -to separate pieces of the input; -they are not used to create space in the output. -Thus -.P1 -x = y - + z + 1 -.P2 -also gives $x=y+z+1$. -Free-form input is easier to type initially; -subsequent editing is also easier, -for an expression may be typed as many short lines. -.PP -Extra white space can be forced into the output by several -characters of various sizes. -A tilde ``\|~\|'' gives a space equal -to the normal word spacing in text; -a circumflex gives half this much, -and a tab charcter spaces to the next tab stop. -.PP -Spaces (or tildes, etc.) -also serve to delimit pieces of the input. -For example, to get -.EQ -f(t) = 2 pi int sin ( omega t )dt -.EN -we write -.P1 -f(t) = 2 pi int sin ( omega t )dt -.P2 -Here spaces are -.ul -necessary -in the input -to indicate that -.ul -sin, pi, int, -and -.ul -omega -are special, and potentially worth special treatment. -.UC EQN -looks up each such string of characters -in a table, and if appropriate gives it a translation. -In this case, -.ul -pi -and -.ul -omega -become their greek equivalents, -.ul -int -becomes the integral sign -(which must be moved down and enlarged so it looks ``right''), -and -.ul -sin -is made roman, following conventional mathematical practice. -Parentheses, digits and operators are automatically made roman -wherever found. -.PP -Fractions are specified with the keyword -.ul -over: -.P1 -a+b over c+d+e = 1 -.P2 -produces -.EQ -a+b over c+d+e = 1 -.EN -.PP -Similarly, subscripts and superscripts are introduced by the keywords -.ul -sub -and -.ul -sup: -.EQ -x sup 2 + y sup 2 = z sup 2 -.EN -is produced by -.P1 -x sup 2 + y sup 2 = z sup 2 -.P2 -The spaces after the 2's are necessary to mark the end of -the superscripts; -similarly the keyword -.ul -sup -has to be marked off by spaces or -some equivalent delimiter. -The return to the proper baseline is automatic. -Multiple levels of subscripts or superscripts -are of course allowed: -``x\|\|sup\|\|y\|\|sup\|\|z'' is -$x sup y sup z$. -The construct -``something -.ul -sub -something -.ul -sup -something'' -is recognized as a special case, -so -``x sub i sup 2'' -is -$x sub i sup 2$ instead of ${x sub i} sup 2$. -.PP -More complicated expressions can now be formed with these -primitives: -.EQ -{partial sup 2 f} over {partial x sup 2} = -x sup 2 over a sup 2 + y sup 2 over b sup 2 -.EN -is produced by -.P1 -.ce 0 - {partial sup 2 f} over {partial x sup 2} = - x sup 2 over a sup 2 + y sup 2 over b sup 2 -.P2 -Braces {} are used to group objects together; -in this case they indicate unambiguously what goes over what -on the left-hand side of the expression. -The language defines the precedence of -.ul -sup -to be higher than that of -.ul -over, -so -no braces are needed to get the correct association on the right side. -Braces can always be used when in doubt -about precedence. -.PP -The braces convention is an example of the power -of using a recursive grammar -to define the language. -It is part of the language that if a construct can appear -in some context, -then -.ul -any expression -in braces -can also occur in that context. -.PP -There is a -.ul -sqrt -operator for making square roots of the appropriate size: -``sqrt a+b'' produces $sqrt a+b$, -and -.P1 -x = {-b +- sqrt{b sup 2 -4ac}} over 2a -.P2 -is -.EQ -x={-b +- sqrt{b sup 2 -4ac}} over 2a -.EN -Since large radicals look poor on our typesetter, -.ul -sqrt -is not useful for tall expressions. -.PP -Limits on summations, integrals and similar -constructions are specified with -the keywords -.ul -from -and -.ul -to. -To get -.EQ -sum from i=0 to inf x sub i -> 0 -.EN -we need only type -.P1 -sum from i=0 to inf x sub i -> 0 -.P2 -Centering and making the $SIGMA$ big enough and the limits smaller -are all automatic. -The -.ul -from -and -.ul -to -parts are both optional, -and the central part (e.g., the $SIGMA$) -can in fact be anything: -.P1 -lim from {x -> pi /2} ( tan~x) = inf -.P2 -is -.EQ -lim from {x -> pi /2} ( tan~x) = inf -.EN -Again, -the braces indicate just what goes into the -.ul -from -part. -.PP -There is a facility for making braces, brackets, parentheses, and vertical bars -of the right height, using the keywords -.ul -left -and -.ul -right: -.P1 -left [ x+y over 2a right ]~=~1 -.P2 -makes -.EQ -left [ x+y over 2a right ]~=~1 -.EN -A -.ul -left -need not have a corresponding -.ul -right, -as we shall see in the next example. -Any characters may follow -.ul -left -and -.ul -right, -but generally only various parentheses and bars are meaningful. -.PP -Big brackets, etc., -are often used with another facility, -called -.ul -piles, -which make vertical piles of objects. -For example, -to get -.EQ -sign (x) ~==~ left { - rpile {1 above 0 above -1} - ~~lpile {if above if above if} - ~~lpile {x>0 above x=0 above x<0} -.EN -we can type -.P1 -sign (x) ~==~ left { - rpile {1 above 0 above -1} - ~~lpile {if above if above if} - ~~lpile {x>0 above x=0 above x<0} -.P2 -The construction ``left {'' -makes a left brace big enough -to enclose the -``rpile {...}'', -which is a right-justified pile of -``above ... above ...''. -``lpile'' makes a left-justified pile. -There are also centered piles. -Because of the recursive language definition, -a -pile -can contain any number of elements; -any element of a pile can of course -contain piles. -.PP -Although -.UC EQN -makes a valiant attempt -to use the right sizes and fonts, -there are times when the default assumptions -are simply not what is wanted. -For instance the italic -.ul -sign -in the previous example would conventionally -be in roman. -Slides and transparencies often require larger characters than normal text. -Thus we also provide size and font -changing commands: -``size 12 bold {A~x~=~y}'' -will produce -$size 12 bold{ A~x~=~y}$. -.ul -Size -is followed by a number representing a character size in points. -(One point is 1/72 inch; -this paper is set in 9 point type.) -.PP -If necessary, an input string can be quoted in "...", -which turns off grammatical significance, and any font or spacing changes that might otherwise be done on it. -Thus we can say -.P1 -lim~ roman "sup" ~x sub n = 0 -.P2 -to ensure that the supremum doesn't become a superscript: -.EQ -lim~ roman "sup" ~x sub n = 0 -.EN -.PP -Diacritical marks, long a problem in traditional typesetting, -are straightforward: -.EQ -x dot under + x hat + y tilde + X hat + Y dotdot = z+Z bar -.EN -is made by typing -.P1 -x dot under + x hat + y tilde -+ X hat + Y dotdot = z+Z bar -.P2 -.PP -There are also facilities for globally changing default -sizes and fonts, for example for making viewgraphs -or for setting chemical equations. -The language allows for matrices, and for lining up equations -at the same horizontal position. -.PP -Finally, there is a definition facility, -so a user can say -.P1 -define name "..." -.P2 -at any time in the document; -henceforth, any occurrence of the token ``name'' -in an expression -will be expanded into whatever was inside -the double quotes in its definition. -This lets users tailor -the language to their own specifications, -for it is quite possible to redefine -keywords -like -.ul -sup -or -.ul -over. -Section 6 shows an example of definitions. -.PP -The -.UC EQN -preprocessor reads intermixed text and equations, -and passes its output to -.UC TROFF. -Since -.UC TROFF -uses lines beginning with a period as control words -(e.g., ``.ce'' means ``center the next output line''), -.UC EQN -uses the sequence ``.EQ'' to mark the beginning of an equation and -``.EN'' to mark the end. -The ``.EQ'' and ``.EN'' are passed through to -.UC TROFF -untouched, -so they can also be used by a knowledgeable user to -center equations, number them automatically, etc. -By default, however, -``.EQ'' and ``.EN'' are simply ignored by -.UC TROFF , -so by default equations are printed in-line. -.PP -``.EQ'' and ``.EN'' can be supplemented by -.UC TROFF -commands as desired; -for example, a centered display equation -can be produced with the input: -.P1 -.ce 0 -.in 5 - .ce - .EQ - x sub i = y sub i ... - .EN -.in 0 -.P2 -.PP -Since it is tedious to type -``.EQ'' and ``.EN'' around very short expressions -(single letters, for instance), -the user can also define two characters to serve -as the left and right delimiters of expressions. -These characters are recognized anywhere in subsequent text. -For example if the left and right delimiters have both been set to ``#'', -the input: -.P1 -Let #x sub i#, #y# and #alpha# be positive -.P2 -produces: -.P1 -Let $x sub i$, $y$ and $alpha$ be positive -.P2 -.PP -Running a preprocessor is strikingly easy on -.UC UNIX. -To typeset -text stored in file -``f\|'', -one issues the command: -.P1 -eqn f | troff -.P2 -The vertical bar connects the output -of one process -.UC (EQN) -to the input of another -.UC (TROFF) . //GO.SYSIN DD e4 echo e5 sed 's/.//' >e5 <<'//GO.SYSIN DD e5' -.NH -Language Theory -.PP -The basic structure of the language is -not a particularly original one. -Equations are pictured as a set of ``boxes,'' -pieced together in various ways. -For example, something with a subscript is -just a box followed by another box moved downward -and shrunk -by an appropriate amount. -A fraction is just a box centered above another box, -at the right altitude, -with a line of correct length drawn between them. -.PP -The grammar for the language is shown below. -For purposes of exposition, we have collapsed -some productions. In the original grammar, there -are about 70 productions, but many of these -are simple ones used only to guarantee -that some keyword is recognized early enough in the parsing process. -Symbols in -capital letters -are terminal symbols; -lower case -symbols are non-terminals, i.e., syntactic categories. -The vertical bar \(bv indicates an alternative; -the brackets [ ] indicate optional material. -A -.UC TEXT -is a string of non-blank characters or -any string inside double quotes; -the other terminal symbols represent literal occurrences -of the corresponding keyword. -.P1 -.ce 0 -.ta .3i -.ps 9 -.ne 17 -.in 1 -eqn : box | eqn box -.sp 5p -box : text - | { eqn } - | box OVER box - | SQRT box - | box SUB box | box SUP box - | [ L | C | R ]PILE { list } - | LEFT text eqn [ RIGHT text ] - | box [ FROM box ] [ TO box ] - | SIZE text box - | [ROMAN | BOLD | ITALIC] box - | box [HAT | BAR | DOT | DOTDOT | TILDE] - | DEFINE text text -.sp 5p -list : eqn | list ABOVE eqn -.sp 5p -text : TEXT -.ps 10 -.in 0 -.P2 -.PP -The grammar makes it obvious why there are few exceptions. -For example, the observation that something can be replaced by a more complicated something -in braces is implicit in the productions: -.P1 -.ce 0 - eqn : box | eqn box - box : text | { eqn } -.P2 -Anywhere a single character could be used, -.ul -any -legal construction can be used. -.PP -Clearly, our grammar is highly ambiguous. -What, for instance, do we do with the input -.P1 -a over b over c ? -.P2 -Is it -.P1 -{a over b} over c -.P2 -or is it -.P1 -a over {b over c} ? -.P2 -.PP -To answer questions like this, the grammar -is supplemented with a small set of rules that describe the precedence -and associativity -of operators. -In particular, we specify (more or less arbitrarily) -that -.ul -over -associates to the left, -so the first alternative above is the one chosen. -On the other hand, -.ul -sub -and -.ul -sup -bind to the right, -because this is closer to standard mathematical practice. -That is, we assume $x sup a sup b$ is $x sup {(a sup b )}$, -not $(x sup a ) sup b$. -.PP -The precedence rules resolve the ambiguity in a construction like -.P1 -a sup 2 over b -.P2 -We define -.ul -sup -to have a higher precedence than -.ul -over, -so this construction is parsed as -$a sup 2 over b$ instead of $a sup {2 over b}$. -.PP -Naturally, a user can always -force a particular parsing -by placing braces around expressions. -.PP -The ambiguous grammar approach seems to be quite useful. -The grammar we use is small enough to be easily understood, -for it contains none of the productions that would be -normally used for resolving ambiguity. -Instead the supplemental information about -precedence and associativity (also small enough to be understood) -provides the compiler-compiler -with the information it needs -to make a fast, deterministic parser for -the specific language we want. -When the language is supplemented by the disambiguating rules, -it is in fact -.UC LR(1) -and thus easy to parse[5]. -.PP -The output code is generated as the input is scanned. -Any time a production -of the grammar is recognized, -(potentially) some -.UC TROFF -commands are output. -For example, when the lexical analyzer -reports that it has found a -.UC TEXT -(i.e., a string of contiguous characters), -we have recognized the production: -.P1 -text : TEXT -.P2 -The translation of this is simple. -We generate a local name for the string, -then hand the name and the string to -.UC TROFF, -and let -.UC TROFF -perform the storage management. -All we save is the name of the string, -its height, and its baseline. -.PP -As another example, -the translation associated with the production -.P1 -box : box OVER box -.P2 -is: -.P1 -.ce 0 -.in 1 -.ne 14 -Width of output box = - slightly more than largest input width -Height of output box = - slightly more than sum of input heights -Base of output box = - slightly more than height of bottom input box -String describing output box = - move down; - move right enough to center bottom box; - draw bottom box (i.e., copy string for bottom box); - move up; move left enough to center top box; - draw top box (i.e., copy string for top box); - move down and left; draw line full width; - return to proper base line. -.in 0 -.P2 -Most of the other productions have -equally simple semantic actions. -Picturing the output as a set of properly placed boxes -makes the right sequence of positioning commands -quite obvious. -The main difficulty is in finding the right numbers to use -for esthetically pleasing positioning. -.PP -With a grammar, it is usually clear how to extend the language. -For instance, one of our users -suggested a -.UC TENSOR -operator, to make constructions like -.EQ -~ sub size 7 m sup size 7 l -{bold T from n to k} sub size 7 i sup size 7 j -.EN -Grammatically, this is easy: -it is sufficient to add a production like -.P1 -box : TENSOR { list } -.P2 -Semantically, we need only juggle the boxes to the right places. //GO.SYSIN DD e5 echo e6 sed 's/.//' >e6 <<'//GO.SYSIN DD e6' -.NH -Experience -.PP -There are really three aspects of interest_how -well -.UC EQN -sets mathematics, -how well it satisfies its goal -of being ``easy to use,'' -and how easy it was to build. -.PP -The first question is easily addressed. -This entire paper -has been set by the program. -Readers can judge for themselves -whether it is good enough for their purposes. -One of our users commented that although the output -is not as good as the best hand-set material, -it is still -better than average, -and much better than -the worst. -In any case, who cares? -Printed books cannot compete with the birds and flowers -of illuminated manuscripts on esthetic grounds, -either, -but they have some clear economic advantages. -.PP -Some of the deficiencies in the output could -be cleaned up with more work on our part. -For example, we sometimes leave too much space between -a roman letter and an italic one. -If we were willing to keep track of the fonts -involved, -we could do this better more of the time. -.PP -Some other weaknesses are inherent in our output device. -It is hard, for instance, to draw a line -of an arbitrary length without getting -a perceptible overstrike at one end. -.PP -As to ease of use, -at the time of writing, -the system has been used by two distinct groups. -One user population consists of mathematicians, -chemists, physicists, and computer scientists. -Their typical reaction has been something like: -.IP " (1)" -It's easy to write, although I make the following mistakes... -.IP " (2)" -How do I do...? -.IP " (3)" -It botches the following things.... Why don't you fix them? -.IP " (4)" -You really need the following features... -.sp 5p -.PP -The learning time is short. -A few minutes gives the general flavor, -and typing a page or two of a paper generally -uncovers most of the misconceptions about how it works. -.PP -The second user group is much larger, -the secretaries and mathematical typists -who were the original target of the system. -They tend to be enthusiastic converts. -They find the language easy to learn -(most are largely self-taught), -and have little trouble producing the output they want. -They are of course less critical of the esthetics of their output -than users trained in mathematics. -After a transition period, most find -using a computer more interesting than -a regular typewriter. -.PP -The main difficulty that users have seems to be remembering -that a blank is a delimiter; -even experienced users use blanks where they shouldn't and omit them -when they are needed. -A common instance is typing -.P1 -f(x sub i) -.P2 -which produces -.EQ -f(x sub i) -.EN -instead of -.EQ -f(x sub i ) -.EN -Since the -.UC EQN -language knows no mathematics, it cannot deduce that the -right parenthesis is not part of the subscript. -.PP -The language is somewhat prolix, but this doesn't seem -excessive considering how much is being done, -and it is certainly more compact than the corresponding -.UC TROFF -commands. -For example, here is the source for the continued fraction -expression in Section 1 of this paper: -.P1 -.ne 4 -.ce 0 - a sub 0 + b sub 1 over - {a sub 1 + b sub 2 over - {a sub 2 + b sub 3 over - {a sub 3 + ... }}} -.P2 -This is the input for the large integral of Section 1; -notice the use of definitions: -.P1 -.ce 0 -.ne 15 -.in 1 -define emx "{e sup mx}" -define mab "{m sqrt ab}" -define sa "{sqrt a}" -define sb "{sqrt b}" -int dx over {a emx - be sup -mx} ~=~ -left { lpile { - 1 over {2 mab} ~log~ - {sa emx - sb} over {sa emx + sb} - above - 1 over mab ~ tanh sup -1 ( sa over sb emx ) - above - -1 over mab ~ coth sup -1 ( sa over sb emx ) -} -.in 0 -.P2 -.PP -As to ease of construction, -we have already -mentioned that there are really only a few person-months -invested. -Much of this time has gone into two things_fine-tuning -(what is the most esthetically pleasing space to use -between the numerator and denominator of a fraction?), -and changing things found deficient by our users -(shouldn't a tilde be a delimiter?). -.PP -The program consists of a number of small, -essentially unconnected modules for code generation, -a simple lexical analyzer, -a canned parser which we did not have to write, -and some miscellany associated with input files -and the macro facility. -The program is now about 1600 lines of -.UC C -[6], a high-level language reminiscent of -.UC BCPL . -About 20 percent of these lines are ``print'' statements, -generating the output code. -.PP -The semantic routines that generate the actual -.UC TROFF -commands can be changed to accommodate other formatting languages -and devices. -For example, in less than 24 hours, -one of us changed the entire semantic package -to drive -.UC NROFF, -a variant of -.UC TROFF, -for typesetting mathematics on teletypewriter devices -capable of reverse line motions. -Since many potential users do not have access -to a typesetter, but still have to type mathematics, -this provides a way to get a typed version of the final output -which is close enough for debugging purposes, -and sometimes even for ultimate use. //GO.SYSIN DD e6 echo e7 sed 's/.//' >e7 <<'//GO.SYSIN DD e7' -.NH -Conclusions -.PP -We think we have shown that it is possible -to do acceptably good typesetting of mathematics -on a phototypesetter, -with an input language that is easy to learn and use and -that satisfies many users' demands. -Such a package can be implemented in -short order, -given a compiler-compiler and -a decent typesetting program underneath. -.PP -Defining a language, and building a compiler for it -with a compiler-compiler -seems like the only sensible way to do business. -Our experience with the use of -a grammar and a compiler-compiler has been -uniformly favorable. -If we had written everything into code directly, -we would have been locked into -our original design. -Furthermore, we would have never been sure -where the exceptions and special cases were. -But because we have a grammar, we can change our minds readily and still be reasonably -sure that if a construction works in one place -it will work everywhere. -.SH -Acknowledgements -.PP -We are deeply indebted to -J. F. Ossanna, -the author of -.UC TROFF , -for his willingness to modify -.UC TROFF -to make our task easier -and for his continuous assistance -during the development of our program. -We are also grateful to -A. V. Aho for help with language theory, -to S. C. Johnson for aid with the compiler-compiler, -and to our early users -A. V. Aho, S. I. Feldman, S. C. Johnson, -R. W. Hamming, -and M. D. McIlroy -for their constructive criticisms. -.SH -References -.IP [1] -.ul -A Manual of Style, -12th Edition. -University of Chicago Press, 1969. p 295. -.IP [2] -.ul -Model C/A/T Phototypesetter. -Graphic Systems, Inc., -Hudson, N. H. -.IP [3] -Ritchie, D. M., and Thompson, K. L., -``The UNIX time-sharing system.'' -\fIComm. ACM 17,\fR 7 (July 1974), 365-375. -.IP [4] -Ossanna, J. F., -TROFF User's Manual. -Bell Laboratories Computing Science Technical Report 54, 1977. -.IP [5] -Aho, A. V., and Johnson, S. C., -``LR Parsing.'' -\fIComp. Surv. 6,\fR 2 (June 1974), 99-124. -.br -.IP [6] -B. W. Kernighan and D. M. Ritchie, -.ul -The C Programming Language. -Prentice-Hall, Inc., 1978. //GO.SYSIN DD e7 echo g.mac sed 's/.//' >g.mac <<'//GO.SYSIN DD g.mac' -.tr %$ -.de SC -.NH -\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 -.. -.de UC -\&\\$3\s-2\\$1\\s+2\\$2 -.. -.de P1 -.nf -.tr -\(mi -.tr ^. -.tr '\(fm -.ss 18 -.if \\n(.$ .DS I \\$1 -.if !\\n(.$ .DS -.. -.de P2 -.DE -.fi -.ss 12 -.tr -- -.tr ^^ -.tr '' -.. -.tr _\(em //GO.SYSIN DD g.mac echo g0 sed 's/.//' >g0 <<'//GO.SYSIN DD g0' -.EQ -delim $$ -.EN -\".ND "June 2, 1976" -.RP -\".TM "76-1273-4 76-1271-4" 39199 39199-11 -.TL -Typesetting Mathematics _ User's Guide -\&\ \ \ \ \ (Second\ Edition) -.AU 2C-518 6021 -Brian W. Kernighan and Lorinda L. Cherry -.AI -.MH -.AB -.in -.ll -.PP -This is the user's guide for a system for typesetting -mathematics, -using -the phototypesetters on the -.UX -and -.UC GCOS -operating systems. -.PP -Mathematical expressions are described in a language -designed to be easy to use -by people who know neither mathematics nor typesetting. -Enough of the language to set in-line expressions like -$lim from {x-> pi /2} ( tan~x) sup{sin~2x}~=~1$ -or display equations like -.in .5i -.EQ I -G(z)~mark =~ e sup { ln ~ G(z) } -~=~ exp left ( -sum from k>=1 {S sub k z sup k} over k right ) -~=~ prod from k>=1 e sup {S sub k z sup k /k} -.EN -.EQ I -lineup = left ( 1 + S sub 1 z + -{ S sub 1 sup 2 z sup 2 } over 2! + ... right ) -left ( 1+ { S sub 2 z sup 2 } over 2 -+ { S sub 2 sup 2 z sup 4 } over { 2 sup 2 cdot 2! } -+ ... right ) ... -.EN -.EQ I -lineup = sum from m>=0 left ( -sum from -pile { k sub 1 ,k sub 2 ,..., k sub m >=0 -above -k sub 1 +2k sub 2 + ... +mk sub m =m} -{ S sub 1 sup {k sub 1} } over {1 sup k sub 1 k sub 1 ! } ~ -{ S sub 2 sup {k sub 2} } over {2 sup k sub 2 k sub 2 ! } ~ -... -{ S sub m sup {k sub m} } over {m sup k sub m k sub m ! } -right ) z sup m -.EN -.in 0 -can be learned in an hour or so. -.PP -The language interfaces directly with -the phototypesetting language -.UC TROFF , -so mathematical expressions can be embedded in the running -text -of a manuscript, -and the entire document produced in one process. -This user's guide is an example of its output. -.PP -The same language -may be used with the -.UC UNIX -formatter -.UC NROFF -to set mathematical expressions on -.UC DASI -and -.UC GSI -terminals -and Model 37 teletypes. -.AE -.CS 11 0 11 0 0 3 //GO.SYSIN DD g0 echo g1 sed 's/.//' >g1 <<'//GO.SYSIN DD g1' -.if t .2C -.SC Introduction -.PP -.UC EQN -is a -program for typesetting mathematics -on the Graphics Systems phototypesetters on -.UC UNIX -and -.UC GCOS . -The -.UC EQN -language was designed to be easy to use -by people who know neither mathematics -nor typesetting. -Thus -.UC EQN -knows relatively little about mathematics. -In particular, mathematical symbols like -+, \(mi, \(mu, parentheses, and so on have no special meanings. -.UC EQN -is quite happy to set garbage (but it will look good). -.PP -.UC EQN -works as a preprocessor for the typesetter formatter, -.UC TROFF [1], -so the normal mode of operation is to prepare -a document with both mathematics and ordinary text -interspersed, -and let -.UC EQN -set the mathematics while -.UC TROFF -does the body of the text. -.PP -On -.UC UNIX , -.UC EQN -will also produce mathematics on -.UC DASI -and -.UC GSI -terminals and on -Model 37 teletypes. -The input is identical, but you have to use the programs -.UC NEQN -and -.UC NROFF -instead of -.UC EQN -and -.UC TROFF . -Of course, some things won't look as good -because terminals -don't provide the variety of characters, sizes and fonts -that a typesetter does, -but the output is usually adequate for proofreading. -.PP -To use -.UC EQN -on -.UC UNIX , -.P1 -eqn files | troff -.P2 -.UC GCOS -use is discussed in section 26. -.SC Displayed Equations -.PP -To tell -.UC EQN -where a mathematical expression begins and ends, -we mark it with lines beginning -.UC .EQ -and -.UC .EN . -Thus -if you type the lines -.P1 -^EQ -x=y+z -^EN -.P2 -your output will look like -.EQ -x=y+z -.EN -The -.UC .EQ -and -.UC .EN -are copied through untouched; -they -are not otherwise processed -by -.UC EQN . -This means that you have to take care -of things like centering, numbering, and so on -yourself. -The most common way is to use the -.UC TROFF -and -.UC NROFF -macro package package `\(mims' -developed by M. E. Lesk[3], -which allows you to center, indent, left-justify and number equations. -.PP -With the `\(mims' package, -equations are centered by default. -To left-justify an equation, use -.UC \&.EQ\ L -instead of -.UC .EQ . -To indent it, use -.UC .EQ\ I . -Any of these can be followed by an arbitrary `equation number' -which will be placed at the right margin. -For example, the input -.P1 -^EQ I (3.1a) -x = f(y/2) + y/2 -^EN -.P2 -produces the output -.EQ I (3.1a) -x = f(y/2) + y/2 -.EN -.PP -There is also a shorthand notation so -in-line expressions -like -$pi sub i sup 2$ -can be entered without -.UC .EQ -and -.UC .EN . -We will talk about it in section 19. -.SC Input spaces -.PP -Spaces and newlines within an expression are thrown away by -.UC EQN . -(Normal text is left absolutely alone.) -Thus -between -.UC .EQ -and -.UC .EN , -.P1 -x=y+z -.P2 -and -.P1 -x = y + z -.P2 -and -.P1 -x = y - + z -.P2 -and so on -all produce the same -output -.EQ -x=y+z -.EN -You should use spaces and newlines freely to make your input equations -readable and easy to edit. -In particular, very long lines are a bad idea, -since they are often hard to fix if you make a mistake. -.SC Output spaces -.PP -To force extra spaces into the -.ul -output, -use a tilde ``\|~\|'' -for each space you want: -.P1 -x~=~y~+~z -.P2 -gives -.EQ -x~=~y~+~z -.EN -You can also use a circumflex ``^'', -which gives a space half the width of a tilde. -It is mainly useful for fine-tuning. -Tabs may also be used to position pieces -of an expression, -but the tab stops must be set by -.UC TROFF -commands. -.SC "Symbols, Special Names, Greek" -.PP -.UC EQN -knows some mathematical symbols, -some mathematical names, and the Greek alphabet. -For example, -.P1 -x=2 pi int sin ( omega t)dt -.P2 -produces -.EQ -x = 2 pi int sin ( omega t)dt -.EN -Here the spaces in the input are -.B -necessary -.R -to tell -.UC EQN -that -.ul -int, -.ul -pi, -.ul -sin -and -.ul -omega -are separate entities that should get special treatment. -The -.ul -sin, -digit 2, and parentheses are set in roman type instead of italic; -.ul -pi -and -.ul -omega -are made Greek; -and -.ul -int -becomes the integral sign. -.PP -When in doubt, leave spaces around separate parts of the input. -A -.ul -very -common error is to type -.ul -f(pi) -without leaving spaces on both sides of the -.ul -pi. -As a result, -.UC EQN -does not recognize -.ul -pi -as a special word, and it appears as -$f(pi)$ -instead of -$f( pi )$. -.PP -A complete list of -.UC EQN -names appears in section 23. -Knowledgeable users can also use -.UC TROFF -four-character names -for anything -.UC EQN -doesn't know about, -like -.ul -\\(bs -for the Bell System sign \(bs. -.SC "Spaces, Again" -.PP -The only way -.UC EQN -can deduce that some sequence -of letters might be special -is if that sequence is separated from the letters -on either side of it. -This can be done by surrounding a special word by ordinary spaces -(or tabs or newlines), -as we did in the previous section. -.PP -.tr ~~ -You can also make special words stand out by surrounding them -with tildes or circumflexes: -.P1 -x~=~2~pi~int~sin~(~omega~t~)~dt -.P2 -is much the same as the last example, -except that the tildes -not only -separate the magic words -like -.ul -sin, -.ul -omega, -and so on, -but also add extra spaces, -one space per tilde: -.EQ -x~=~2~pi~int~sin~(~omega~t~)~dt -.EN -.PP -Special words can also be separated by braces { } -and double quotes "...", -which have special meanings that we will -see soon. -.tr ~ -.SC "Subscripts and Superscripts" -.PP -Subscripts and superscripts are -obtained with the words -.ul -sub -and -.ul -sup. -.P1 -x sup 2 + y sub k -.P2 -gives -.EQ -x sup 2 + y sub k -.EN -.UC EQN -takes care of all the size changes and vertical motions -needed to make the output look right. -The words -.ul -sub -and -.ul -sup -must be surrounded by spaces; -.ul -x sub2 -will give you -$x sub2$ instead of $x sub 2$. -Furthermore, don't forget to leave a space -(or a tilde, etc.) -to mark the end of a subscript or superscript. -A common error is to say -something like -.P1 -y = (x sup 2)+1 -.P2 -which causes -.EQ -y = (x sup 2)+1 -.EN -instead of -the intended -.EQ -y = (x sup 2 )+1 -.EN -.PP -Subscripted subscripts and superscripted superscripts -also work: -.P1 -x sub i sub 1 -.P2 -is -.EQ -x sub i sub 1 -.EN -A subscript and superscript on the same thing -are printed one above the other -if the subscript comes -.ul -first: -.P1 -x sub i sup 2 -.P2 -is -.EQ -x sub i sup 2 -.EN -.PP -Other than this special case, -.ul -sub -and -.ul -sup -group to the right, so -.ul -x\ sup\ y\ sub\ z -means -$x sup {y sub z}$, not ${x sup y} sub z$. -.SC "Braces for Grouping" -.PP -Normally, the end of a subscript or superscript is marked -simply by a blank (or tab or tilde, etc.) -What if the subscript or superscript is something that has to be typed -with blanks in it? -In that case, you can use the braces -{ and } to mark the -beginning and end of the subscript or superscript: -.P1 -e sup {i omega t} -.P2 -is -.EQ -e sup {i omega t} -.EN -.sp -Rule: Braces can -.ul -always -be used to force -.UC EQN -to treat something as a unit, -or just to make your intent perfectly clear. -Thus: -.P1 -x sub {i sub 1} sup 2 -.P2 -is -.EQ -x sub {i sub 1} sup 2 -.EN -with braces, but -.P1 -x sub i sub 1 sup 2 -.P2 -is -.EQ -x sub i sub 1 sup 2 -.EN -which is rather different. -.PP -Braces can occur within braces if necessary: -.P1 -e sup {i pi sup {rho +1}} -.P2 -is -.EQ -e sup {i pi sup {rho +1}} -.EN -The general rule is that anywhere you could use some single -thing like -.ul -x, -you can use an arbitrarily complicated thing if you enclose -it in braces. -.UC EQN -will look after all the details of positioning it and making -it the right size. -.PP -In all cases, make sure you have the -right number of braces. -Leaving one out or adding an extra will cause -.UC EQN -to complain bitterly. -.PP -Occasionally you will have to -print braces. -To do this, -enclose them in double quotes, -like "{". -Quoting is discussed in more detail in section 14. -.SC Fractions -.PP -To make a fraction, -use the word -.ul -over: -.P1 -a+b over 2c =1 -.P2 -gives -.EQ -a+b over 2c =1 -.EN -The line is made the right length and positioned automatically. -Braces can be used to make clear what goes over what: -.P1 -{alpha + beta} over {sin (x)} -.P2 -is -.EQ -{alpha + beta} over {sin (x)} -.EN -What happens when there is both an -.ul -over -and a -.ul -sup -in the same expression? -In such an apparently ambiguous case, -.UC EQN -does the -.ul -sup -before the -.ul -over, -so -.P1 -\(mib sup 2 over pi -.P2 -is -$-b sup 2 over pi$ -instead of -$-b sup {2 over pi}$ -The rules -which decide which operation is done first in cases like this -are summarized in section 23. -When in doubt, however, -.ul -use braces -to make clear what goes with what. -.SC "Square Roots" -.PP -To draw a square root, use -.ul -sqrt: -.P1 2 -sqrt a+b + 1 over sqrt {ax sup 2 +bx+c} -.P2 -is -.EQ -sqrt a+b + 1 over sqrt {ax sup 2 +bx+c} -.EN -Warning _ square roots of tall quantities look lousy, -because a root-sign -big enough to cover the quantity is -too dark and heavy: -.P1 -sqrt {a sup 2 over b sub 2} -.P2 -is -.EQ -sqrt{a sup 2 over b sub 2} -.EN -Big square roots are generally better written as something -to the power \(12: -.EQ -(a sup 2 /b sub 2 ) sup half -.EN -which is -.P1 -(a sup 2 /b sub 2 ) sup half -.P2 -.SC "Summation, Integral, Etc." -.PP -Summations, integrals, and similar constructions -are easy: -.P1 -sum from i=0 to {i= inf} x sup i -.P2 -produces -.EQ -sum from i=0 to {i= inf} x sup i -.EN -Notice that we used -braces to indicate where the upper -part -$i= inf$ -begins and ends. -No braces were necessary for the lower part $i=0$, -because it contained no blanks. -The braces will never hurt, -and if the -.ul -from -and -.ul -to -parts contain any blanks, you must use braces around them. -.PP -The -.ul -from -and -.ul -to -parts are both optional, -but if both are used, -they have to occur in that order. -.PP -Other useful characters can replace the -.ul -sum -in our example: -.P1 -int prod union inter -.P2 -become, respectively, -.EQ -int ~~~~~~ prod ~~~~~~ union ~~~~~~ inter -.EN -Since the thing before the -.ul -from -can be anything, -even something in braces, -.ul -from-to -can often be used in unexpected ways: -.P1 -lim from {n \(mi> inf} x sub n =0 -.P2 -is -.EQ -lim from {n-> inf} x sub n =0 -.EN //GO.SYSIN DD g1 echo g2 sed 's/.//' >g2 <<'//GO.SYSIN DD g2' -.SC "Size and Font Changes" -.PP -By default, equations are set in 10-point type (the same size as this guide), -with standard mathematical conventions -to determine what characters are in roman and what in italic. -Although -.UC EQN -makes a valiant attempt to use -esthetically pleasing sizes and fonts, -it is not perfect. -To change sizes and fonts, use -.ul -size n -and -.ul -roman, italic, -.ul -bold -and -.ul -fat. -Like -.ul -sub -and -.ul -sup, -size -and font changes affect only the thing that follows -them, and revert to the normal situation -at the end of it. Thus -.P1 -bold x y -.P2 -is -.EQ -bold x y -.EN -and -.P1 -size 14 bold x = y + - size 14 {alpha + beta} -.P2 -gives -.EQ -size 14 bold x = y + - size 14 {alpha + beta} -.EN -As always, you can use braces if you want to affect something -more complicated than a single letter. -For example, you can change the size of an entire equation by -.P1 -size 12 { ... } -.P2 -.PP -Legal sizes which may follow -.ul -size -are -6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 28, 36. -You can also change the size -.ul -by -a given amount; -for example, you can say -.ul -size~+2 -to make the size two points bigger, -or -.ul -size~\(mi3 -to make it three points smaller. -This has the advantage that you don't have -to know what the current size is. -.PP -If you are using fonts other than roman, italic and bold, -you can say -.ul -font X -where -.ul -X -is a one character -.UC TROFF -name or number for the font. -Since -.UC EQN -is tuned for roman, italic and bold, -other fonts may not give quite as good an appearance. -.PP -The -.ul -fat -operation takes the current font and widens it by overstriking: -.ul -fat\ grad -is -$fat grad$ and -.ul -fat {x sub i} -is -$fat {x sub i}$. -.PP -If an entire document is to be in a non-standard size -or font, it is a severe nuisance -to have to write out a size and font change for each -equation. -Accordingly, you can set a ``global'' size or font -which thereafter affects all equations. -At the beginning of any equation, you might say, for instance, -.P1 -^EQ -gsize 16 -gfont R - ... -^EN -.P2 -to set the size to 16 and the font to roman thereafter. -In place of R, you can use any of the -.UC TROFF -font names. -The size after -.ul -gsize -can be a relative change with + or \(mi. -.PP -Generally, -.ul -gsize -and -.ul -gfont -will appear at the beginning of a document -but they can also appear -thoughout a document: the global font and size -can be changed as often as needed. -For example, in a footnote\(dd -.FS -\(ddLike this one, in which we have a -$gsize -2$few random -expressions like $x sub i$ and $pi sup 2$. -The sizes for these were set by the command -.ul -gsize~\(mi2. -.FE $gsize +2$ -you will typically want the size of equations to match -the size of the footnote text, which is two points smaller -than the main text. -Don't forget to reset the global size -at the end of the footnote. -.SC "Diacritical Marks" -.PP -To get funny marks on top of letters, -there are several words: -.P1 -.tr ^^ -.tr ~~ -.ta 1i -x dot $x dot$ -x dotdot $x dotdot$ -x hat $x hat$ -x tilde $x tilde$ -x vec $x vec$ -x dyad $x dyad$ -x bar $x bar$ -x under $x under$ -.P2 -The diacritical mark is placed at the right height. -The -.ul -bar -and -.ul -under -are made the right length for the entire construct, -as in $x+y+z bar$; -other marks are centered. -.SC "Quoted Text" -.PP -Any input entirely within quotes (\|"..."\|) -is not subject to any of the font changes and spacing -adjustments normally done by the equation setter. -This provides a way to do your own spacing and adjusting if needed: -.P1 -italic "sin(x)" + sin (x) -.P2 -is -.EQ -italic "sin(x)" + sin (x) -.EN -.PP -Quotes are also used to get braces and other -.UC EQN -keywords printed: -.P1 -"{ size alpha }" -.P2 -is -.EQ -"{ size alpha }" -.EN -and -.P1 -roman "{ size alpha }" -.P2 -is -.EQ -roman "{ size alpha }" -.EN -.PP -The construction "" is often used as a place-holder -when grammatically -.UC EQN -needs something, but you don't actually want anything in your output. -For example, to make -$"" sup 2 roman He$, -you can't just type -.ul -sup 2 roman He -because a -.ul -sup -has to be a superscript -.ul -on -something. -Thus you must say -.P1 -"" sup 2 roman He -.P2 -.PP -To get a literal quote -use ``\\"''. -.UC TROFF -characters like -.ul -\e(bs -can appear unquoted, but more complicated things like -horizontal and vertical motions with -.ul -\eh -and -.ul -\ev -should -always -be quoted. -(If you've never heard of -.ul -\\h -and -.ul -\\v, -ignore this section.) -.SC "Lining Up Equations" -.PP -Sometimes it's necessary to line up a series of equations -at some horizontal position, often at an equals sign. -This is done with two operations called -.ul -mark -and -.ul -lineup. -.PP -The word -.ul -mark -may appear once at any place in an equation. -It remembers the horizontal position where it appeared. -Successive equations can contain one occurrence of the word -.ul -lineup. -The place where -.ul -lineup -appears is made to line up -with the place marked by the previous -.ul -mark -if at all possible. -Thus, for example, -you can say -.P1 -^EQ I -x+y mark = z -^EN -^EQ I -x lineup = 1 -^EN -.P2 -to produce -.EQ I -x+y mark = z -.EN -.EQ I -x lineup = 1 -.EN -For reasons too complicated to talk about, -when you use -.UC EQN -and -`\(mims', -use either -.UC .EQ\ I -or -.UC .EQ\ L . -mark -and -.ul -lineup -don't work with centered equations. -Also bear in mind that -.ul -mark -doesn't look ahead; -.P1 -x mark =1 - ... -x+y lineup =z -.P2 -isn't going to work, because there isn't room -for the -.ul -x+y -part after the -.ul -mark -remembers where the -.ul -x -is. -.SC "Big Brackets, Etc." -.PP -.tr ~ -To get big brackets [~], -braces {~}, parentheses (~), and bars |~| -around things, use the -.ul -left -and -.ul -right -commands: -.tr ~~ -.P1 -left { a over b + 1 right } - ~=~ left ( c over d right ) - + left [ e right ] -.P2 -is -.EQ -left { a over b + 1 right } ~=~ left ( c over d right ) + left [ e right ] -.EN -The resulting brackets are made big enough to cover whatever they enclose. -Other characters can be used besides these, -but the are not likely to look very good. -One exception is the -.ul -floor -and -.ul -ceiling -characters: -.P1 -left floor x over y right floor -<= left ceiling a over b right ceiling -.P2 -produces -.EQ -left floor x over y right floor -<= left ceiling a over b right ceiling -.EN -.PP -Several warnings about brackets are in order. -First, braces are typically bigger than brackets and parentheses, -because they are made up of three, five, seven, etc., pieces, -while brackets can be made up of two, three, etc. -Second, big left and right parentheses often look poor, -because the character set is poorly designed. -.PP -The -.ul -right -part may be omitted: -a ``left something'' need not have a -corresponding -``right -something''. -If the -.ul -right -part is omitted, -put braces around the thing you want the left bracket -to encompass. -Otherwise, the resulting brackets may be too large. -.PP -If you want to omit the -.ul -left -part, things are more complicated, -because technically you can't have a -.ul -right -without a corresponding -.ul -left. -Instead you have to say -.P1 -left "" ..... right ) -.P2 -for example. -The -.ul -left "" -means a ``left nothing''. -This satisfies the rules without hurting your output. -.SC "Piles" -.PP -There is a general facility for making vertical piles -of things; it comes in several flavors. -For example: -.P1 -.tr ~~ -A ~=~ left [ - pile { a above b above c } - ~~ pile { x above y above z } -right ] -.P2 -will make -.EQ -A ~=~ left [ -pile { a above b above c } ~~ pile { x above y above z } -right ] -.EN -The elements of the pile (there can be as many as you want) -are centered one above another, at the right height for -most purposes. -The keyword -.ul -above -is used to separate the pieces; -braces are used around the entire list. -The elements of a pile can be as complicated as needed, even containing more piles. -.PP -Three other forms of pile exist: -.ul -lpile -makes a pile with the elements left-justified; -.ul -rpile -makes a right-justified pile; -and -.ul -cpile -makes a centered pile, just like -.ul -pile. -The vertical spacing between the pieces -is somewhat larger for -.ul -l-, -.ul -r- -and -.ul -cpiles -than it is for ordinary piles. -.P1 2 -roman sign (x)~=~ -left { - lpile {1 above 0 above -1} - ~~ lpile - {if~x>0 above if~x=0 above if~x<0} -.P2 -makes -.EQ -roman sign (x)~=~ -left { - lpile {1 above 0 above -1} - ~~ lpile - {if~x>0 above if~x=0 above if~x<0} -.EN -Notice the left brace -without a matching right one. -.SC Matrices -.PP -It is also possible to make matrices. -For example, to make -a neat array like -.EQ -matrix { - ccol { x sub i above y sub i } - ccol { x sup 2 above y sup 2 } -} -.EN -you have to type -.P1 -matrix { - ccol { x sub i above y sub i } - ccol { x sup 2 above y sup 2 } -} -.P2 -This produces a matrix with -two centered columns. -The elements of the columns are then listed just as for a pile, -each element separated by the word -.ul -above. -You can also use -.ul -lcol -or -.ul -rcol -to left or right adjust columns. -Each column can be separately adjusted, -and there can be as many columns as you like. -.PP -The reason for using a matrix instead of two adjacent piles, by the way, -is that if the elements of the piles don't all have the same height, -they won't line up properly. -A matrix forces them to line up, -because it looks at the entire structure before deciding what -spacing to use. -.PP -A word of warning about matrices _ -.ul -each column must have the same number of elements in it. -The world will end if you get this wrong. //GO.SYSIN DD g2 echo g3 sed 's/.//' >g3 <<'//GO.SYSIN DD g3' -.SC "Shorthand for In-line Equations" -.PP -In a mathematical document, -it is necessary to follow mathematical conventions -not just in display equations, -but also in the body of the text, -for example by making variable names like $x$ italic. -Although this could be done by surrounding the appropriate parts -with -.UC .EQ -and -.UC .EN , -the continual repetition of -.UC .EQ -and -.UC .EN -is a nuisance. -Furthermore, with `\(mims', -.UC .EQ -and -.UC .EN -imply a displayed equation. -.PP -.UC EQN -provides a shorthand for short in-line expressions. -You can define two characters to mark the left and right ends -of an in-line equation, and then type expressions right in the middle of text -lines. -To set both the left and right characters to dollar signs, for example, -add to the beginning of your document the three lines -.P1 - .EQ - delim %% - .EN -.P2 -Having done this, you can then say things like -.P1 -.fi -Let %alpha sub i% be the primary variable, -and let %beta% be zero. -Then we can show that %x sub 1% is %>=0%. -.P2 -This works as -you might expect _ -spaces, newlines, and so on are significant -in the text, but not in the equation part itself. -Multiple equations can occur in a single input line. -.PP -Enough room is left before and after a line that contains -in-line expressions -that something like -$sum from i=1 to n x sub i$ -does not interfere with the lines surrounding it. -.PP -To turn off the delimiters, -.P1 - .EQ - delim off - .EN -.P2 -Warning: don't use braces, tildes, circumflexes, or double quotes as delimiters _ -chaos will result. -.SC "Definitions" -.PP -.UC EQN -provides a facility so you can give -a frequently-used string of characters a name, -and thereafter just type the name instead of the -whole string. -For example, if the sequence -.P1 -x sub i sub 1 + y sub i sub 1 -.P2 -appears repeatedly throughout a paper, -you can save re-typing it each time by defining it like this: -.P1 2 -define xy 'x sub i sub 1 + y sub i sub 1' -.P2 -This makes -.ul -xy -a shorthand for whatever characters occur between the single quotes -in the definition. -You can use any character instead of quote to mark the ends of the definition, -so long as it doesn't appear inside the definition. -.PP -Now you can use -.ul -xy -like this: -.P1 -^EQ -f(x) = xy ... -^EN -.P2 -and so on. -Each occurrence of -.ul -xy -will expand into what it was defined as. -Be careful to leave spaces or their equivalent -around the name -when you actually use it, so -.UC EQN -will be able to identify it as special. -.PP -There are several things to watch out for. -First, although definitions can use previous definitions, -as in -.P1 - .EQ - define xi ' x sub i ' - define xi1 ' xi sub 1 ' - .EN -.P2 -.ul -don't define something in terms of itself' -A favorite error is to say -.P1 -define X ' roman X ' -.P2 -This is a guaranteed disaster, -since X -.ul -is -now defined in terms of itself. -If you say -.P1 -define X ' roman "X" ' -.P2 -however, the quotes -protect the second X, -and everything works fine. -.PP -.UC EQN -keywords can be redefined. -You can make -/ mean -.ul -over -by saying -.P1 -define / ' over ' -.P2 -or redefine -.ul -over -as / -with -.P1 -define over ' / ' -.P2 -.PP -If you need different things -to print on a terminal and on the typesetter, it is sometimes worth -defining a symbol differently in -.UC NEQN -and -.UC EQN . -This can be done with -.ul -ndefine -and -.ul -tdefine. -A definition made with -.ul -ndefine -only takes effect if you are running -.UC NEQN ; -if you use -.ul -tdefine, -the definition only applies for -.UC EQN . -Names defined with plain -.ul -define -apply to both -.UC EQN -and -.UC NEQN . -.SC "Local Motions" -.PP -Although -.UC EQN -tries to get most things at the right place on the paper, -it isn't perfect, and occasionally you will need to tune -the output to make it just right. -Small extra horizontal spaces can be obtained with -tilde and circumflex. -You can also say -.ul -back n -and -.ul -fwd n -to move small amounts horizontally. -.ul -n -is how far to move in 1/100's of an em (an em is about the width -of the letter -`m'.) -Thus -.ul -back 50 -moves back about half the width of an m. -Similarly you can move things up or down with -.ul -up n -and -.ul -down n. -As with -.ul -sub -or -.ul -sup, -the local motions affect the next thing in the input, -and this can be something arbitrarily complicated if it is enclosed -in braces. //GO.SYSIN DD g3 echo g4 sed 's/.//' >g4 <<'//GO.SYSIN DD g4' -.SC "A Large Example" -.PP -Here is the complete source for the three display equations -in the abstract of this guide. -.sp -.nf -.ps -2 -.vs -2 - .EQ I - G(z)~mark =~ e sup { ln ~ G(z) } - ~=~ exp left ( - sum from k>=1 {S sub k z sup k} over k right ) - ~=~ prod from k>=1 e sup {S sub k z sup k /k} - .EN - .EQ I - lineup = left ( 1 + S sub 1 z + - { S sub 1 sup 2 z sup 2 } over 2! + ... right ) - left ( 1+ { S sub 2 z sup 2 } over 2 - + { S sub 2 sup 2 z sup 4 } over { 2 sup 2 cdot 2! } - + ... right ) ... - .EN - .EQ I - lineup = sum from m>=0 left ( - sum from - pile { k sub 1 ,k sub 2 ,..., k sub m >=0 - above - k sub 1 +2k sub 2 + ... +mk sub m =m} - { S sub 1 sup {k sub 1} } over {1 sup k sub 1 k sub 1 ! } ~ - { S sub 2 sup {k sub 2} } over {2 sup k sub 2 k sub 2 ! } ~ - ... - { S sub m sup {k sub m} } over {m sup k sub m k sub m ! } - right ) z sup m - .EN -.sp -.fi -.ps +2 -.vs +2 -.SC "Keywords, Precedences, Etc." -.PP -If you don't use braces, -.UC EQN -will -do operations in the order shown in this list. -.P1 3 -.ft I -dyad vec under bar tilde hat dot dotdot -fwd back down up -fat roman italic bold size -sub sup sqrt over -from to -.ft R -.P2 -These operations group to the left: -.P1 -.ft I -over sqrt left right -.ft R -.P2 -All others group to the right. -.PP -Digits, parentheses, brackets, punctuation marks, and these mathematical words -are converted -to Roman font when encountered: -.P1 -sin cos tan sinh cosh tanh arc -max min lim log ln exp -Re Im and if for det -.P2 -These character sequences are recognized and translated as shown. -.sp -.nf -.tr -\(mi -.in .5i -.ta 1i ->= $>=$ -<= $<=$ -== $==$ -!= $!=$ -+- $+-$ --> $->$ -<- $<-$ -<< $<<$ ->> $>>$ -inf $inf$ -partial $partial$ -half $half$ -prime $prime$ -approx $approx$ -nothing $nothing$ -cdot $cdot$ -times $times$ -del $del$ -grad $grad$ -\&... $...$ -,..., $,...,$ -sum $sum$ -.sp 3p -int $int$ -.sp 2p -prod $prod$ -union $union$ -inter $inter$ -.sp -.in -.fi -.tr -- -.PP -To obtain Greek letters, -simply spell them out in whatever case you want: -.sp -.nf -.in .2i -.ta .7i 1.4i 2.1i -DELTA $DELTA$ iota $iota$ -GAMMA $GAMMA$ kappa $kappa$ -LAMBDA $LAMBDA$ lambda $lambda$ -OMEGA $OMEGA$ mu $mu$ -PHI $PHI$ nu $nu$ -PI $PI$ omega $omega$ -PSI $PSI$ omicron $omicron$ -SIGMA $SIGMA$ phi $phi$ -THETA $THETA$ pi $pi$ -UPSILON $UPSILON$ psi $psi$ -XI $XI$ rho $rho$ -alpha $alpha$ sigma $sigma$ -beta $beta$ tau $tau$ -chi $chi$ theta $theta$ -delta $delta$ upsilon $upsilon$ -epsilon $epsilon$ xi $xi$ -eta $eta$ zeta $zeta$ -gamma $gamma$ -.sp -.in -.fi -.PP -These are all the words known to -.UC EQN -(except for characters with names), -together with the section where they are discussed. -.sp -.nf -.in .2i -.ta .7i 1.4i 2.1i -above 17, 18 lpile 17 -back 21 mark 15 -bar 13 matrix 18 -bold 12 ndefine 20 -ccol 18 over 9 -col 18 pile 17 -cpile 17 rcol 18 -define 20 right 16 -delim 19 roman 12 -dot 13 rpile 17 -dotdot 13 size 12 -down 21 sqrt 10 -dyad 13 sub 7 -fat 12 sup 7 -font 12 tdefine 20 -from 11 tilde 13 -fwd 21 to 11 -gfont 12 under 13 -gsize 12 up 21 -hat 13 vec 13 -italic 12 ~, ^ 4, 6 -lcol 18 { } 8 -left 16 "..." 8, 14 -lineup 15 -.sp -.in 0 -.fi -.SC Troubleshooting -.PP -If you make a mistake in an equation, -like leaving out a brace (very common) -or having one too many (very common) -or having a -.ul -sup -with nothing before it (common), -.UC EQN -will tell you with the message -.P1 2 -.ft I -syntax error between lines x and y, file z -.ft R -.P2 -where -.ul -x -and -.ul -y -are approximately the lines -between which the trouble occurred, and -.ul -z -is the name -of the file in question. -The line numbers are approximate _ look nearby as well. -There are also self-explanatory messages that arise if you leave out a quote -or try to run -.UC EQN -on a non-existent file. -.PP -If you want to check a document before actually printing it -(on -.UC UNIX -only), -.P1 -eqn files >/dev/null -.P2 -will -throw away the output but print the messages. -.PP -If you use something like dollar signs as delimiters, -it is easy to leave one out. -This causes very strange troubles. -The program -.ul -checkeq -(on -.UC GCOS , -use -.ul -\&./checkeq -instead) -checks for misplaced or missing dollar signs -and similar troubles. -.PP -In-line equations can only be so big -because of an internal buffer in -.UC TROFF . -If you get a message -``word overflow'', -you have exceeded this limit. -If you print the equation as a displayed equation -this message will usually go away. -The message -``line overflow'' -indicates you have exceeded an even bigger buffer. -The only cure for this is to break the equation into two separate ones. -.PP -On a related topic, -.UC EQN -does not break equations by itself _ -you must split long equations up across multiple lines -by yourself, -marking each by a separate -.UC .EQ -\&...\& -.UC .EN -sequence. -.UC EQN -does warn about equations that are too long -to fit on one line. //GO.SYSIN DD g4 echo g5 sed 's/.//' >g5 <<'//GO.SYSIN DD g5' -.SC "Use on UNIX" -.PP -To print a document that contains mathematics on -the -.UC UNIX -typesetter, -.P1 -eqn files | troff -.P2 -If -there are any -.UC TROFF -options, they go after the -.UC TROFF -part of the command. For example, -.P1 -eqn files | troff -ms -.P2 -To run the same document on the -.UC GCOS -typesetter, use -.P1 -eqn files | troff -g (other options) | gcat -.P2 -.PP -A compatible version of -.UC EQN -can be used on devices like teletypes and -.UC DASI -and -.UC GSI -terminals -which have half-line forward and reverse capabilities. -To print -equations on a Model 37 teletype, for example, use -.P1 -neqn files | nroff -.P2 -The language for equations recognized by -.UC NEQN -is identical to that of -.UC EQN, -although of course the output is more restricted. -.PP -To use a -.UC GSI -or -.UC DASI -terminal as the output device, -.P1 -neqn files | nroff -T\fIx\fP -.P2 -where -.ul -x -is the terminal type you are using, -such as -.ul -300 -or -.ul -300S. -.PP -.UC EQN -and -.UC NEQN -can be used with the -.UC TBL -program[2] -for setting tables that contain mathematics. -Use -.UC TBL -before -.UC [N]EQN , -like this: -.P1 -tbl files | eqn | troff -tbl files | neqn | nroff -.P2 -.SC "Acknowledgments" -.PP -We are deeply indebted to J. F. Ossanna, -the author of -.UC TROFF , -for his willingness to extend -.UC TROFF -to make our task easier, -and for his -continuous assistance during the development -and evolution -of -.UC EQN . -We are also grateful to A. V. Aho -for advice on language design, -to S. C. Johnson for assistance with -the -.UC YACC -compiler-compiler, -and to all the -.UC EQN -users -who have made helpful suggestions and criticisms. -.SH -References -.LP -.IP [1] -J. F. Ossanna, -.UC NROFF/TROFF \& `` -User's Manual'', -Bell Laboratories Computing Science Technical Report -#54, 1976. -.IP [2] -M. E. Lesk, -``Typing Documents on -.UC UNIX '', -Bell Laboratories, 1976. -.IP [3] -M. E. Lesk, -.UC TBL \& `` -\(em A Program for Setting Tables'', -Bell Laboratories Computing Science Technical Report #49, -1976. //GO.SYSIN DD g5