Home
UNIX Version 7 Volume 2A
Contents
1. don t define something in terms of itself A favorite error is to say define X roman X This is a guaranteed disaster since X is now defined in terms of itself If you say define X roman X however the quotes protect the second X and everything works fine EQN keywords can be redefined You can make mean over by saying define over or redefine over as with define over If you need different things to print on a terminal and on the typesetter it is sometimes worth defining a symbol differently in NEQN and EQN This can be done with ndefine and tdefine A definition made with ndefine only takes effect if you are running NEQN if you use fdefine the definition only applies for EQN Names defined with plain define apply to both EQN and NEQN 21 Local Motions Although 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 back n and fwd n to move small amounts horizontally is how far to move in 1 100 s of an em an em is about the width of the letter m Thus back 50 moves back about half the width of an m Similarly you can move things up or down with up n and down n As with sub or sup the local motions affect the next thing in the input and this can be some thing arbitrarily complic
2. 10 typesetter use eqn files troff g other options gcat A compatible version of EQN can be used on devices like teletypes and DASI and GSI termi nals which have half line forward and reverse capabilities To print equations on a Model 37 teletype for example use neqn files nroff The language for equations recognized by NEQN is identical to that of EQN although of course the output is more restricted To use a GSI or DASI terminal as the out put device neqn files nroff Tx where x is the terminal type you are using such as 300 or 30085 EQN and NEQN can be used with the TBL program 2 for setting tables that contain mathematics Use TBL before N EQN like this tbl files eqn troff tbl files neqn nroff 26 Acknowledgments We are deeply indebted to J F Ossanna the author of TROFF for his willingness to extend TROFF to make our task easier and for his continuous assistance during the develop ment and evolution of EQN We are also grate ful to A V Aho for advice on language design to S C Johnson for assistance with the YACC compiler compiler and to all the EQN users who have made helpful suggestions and criticisms References 1 J F Ossanna NROFF TROFF User s Manual Bell Laboratories Computing Science Technical Report 54 1976 2 M E Lesk Typing Documents on UNIX Bell Laboratories 1976 3 M E Lesk TBL A Program f
3. 2 How do I do 3 It botches the following things Why don t you fix them 4 You really need the following features 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 misconcep tions about how it works The second user group is much larger the secretaries and mathematical typists who were the ori ginal target of the system They tend to be enthusias tic 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 The main difficulty that users have seems to be remembering that a blank is a delimiter even experi enced users use blanks where they shouldn t and omit them when they are needed A common instance is typing f x sub i which produces f xj instead of fi Since the EQN language knows no mathematics it cannot deduce that the right parenthesis is not part of the subscript 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 TROFF commands For example here is the source for the continued fraction expression in Section 1 of this
4. look nearby as well There are also self explanatory messages that arise if you leave out a quote or try to run EQN on a non existent file If you want to check a document before actually printing it on UNIX only eqn files gt dev null will throw away the output but print the mes sages If you use something like dollar signs as delimiters it is easy to leave one out This causes very strange troubles The program checkeq on GCOS use checkeq instead checks for misplaced or missing dollar signs and similar troubles In line equations can only be so big because of an internal buffer in 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 indi cates you have exceeded an even bigger buffer The only cure for this is to break the equation into two separate ones On a related topic EQN does not break equations by itself you must split long equa tions up across multiple lines by yourself mark ing each by a separate EQ EN sequence EQN does warn about equations that are too long to fit on one line 25 Use on UNIX To print a document that mathematics on the UNIX typesetter contains eqn files troff If there are any TROFF options they go after the TROFF part of the command For example eqn files troff ms To run the same document on the GCOS
5. ticular we specify more or less arbitrarily that over associates to the left so the first alternative above is the one chosen On the other hand sub and sup bind to the right because this is closer to standard mathematical practice That is we assume x is x not x The precedence rules resolve the ambiguity in a construction like a sup 2 over b We define sup to have a higher precedence than over 2 2 2 f Part a so this construction is parsed as T instead of a Naturally a user can always force a particular parsing by placing braces around expressions 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 pro ductions 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 LR 1 and thus easy to parse 5 The output code is generated as the input is scanned Any time a production of the grammar is recognized potentially some TROFF commands are output For example when the lexical analyzer reports that it has found a TEXT i e a string of con tiguous characters we have recognized the produc tion tex
6. the left and right commands left a over b 1 right left c over d right left e right a fe 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 floor and ceiling characters d left floor x over y right floor lt left ceiling a over b right ceiling Big 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 brack ets can be made up of two three etc Second big left and right parentheses often look poor because the character set is poorly designed The right part may be omitted a left something need not have a corresponding right something If the right part is omitted put braces around the thing you want the left bracket to encompass Otherwise the resulting brackets may be too large produces If you want to omit the left part things are more complicated because technically you can t have a right without a corresponding left Instead you have to say left right for example The left means a left noth ing This satisfies the rules without hurting your output 17 Piles There is a general facility for making vert ical piles of things it comes in several flavors For example A
7. they are not in the half open interval a b Nor should it assume that that Va b can be replaced by a b or that 1 1 x is better written as Iz or x vice versa 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 excep tions to the rules that do exist if something works in one situation it should work everywhere If a vari able can have a subscript then a subscript can have a subscript and so on without limit Third standard things should happen automatically Someone who types x y z l 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 We assume that the typist has a reasonable pic ture 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 charac ters none of them special A secondary but still important goal in our design was that the system should be
8. 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 footnotet 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 13 Diacritical Marks To get funny marks on top of letters there are several words x dot x dotdot x hat x tilde x vec x dyad x bar x under de SD RL Se Se Be The diacritical mark is placed at the right height The bar and under are made the right length for the entire construct as in x y z other marks are centered 14 Quoted Text Any input entirely within quotes is not subject to any of the font changes and spac ing adjustments normally done by the equation setter This provides a way to do your own spacing and adjusting if needed italic sin x sin x is sin x sin x Quotes are also used to get braces and other EQN keywords printed size alpha is size alpha and roman size alpha is size alpha we The construction is often used as a place holder when grammatically EQN needs Like this one in which we have a few random expressions like x and n The sizes for these were set by the command gsize 2 something but you don t actually want anything in your output For example to make
9. by TROFF commands as desired for example a centered display equation can be produced with the input ce EQ x sub i y subi EN 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 subse quent text For example if the left and right delim iters have both been set to the input Let x sub i y and alpha be positive produces Let x y and amp be positive Running a preprocessor is strikingly easy on UNIX To typeset text stored in file f one issues the command eqn f troff The vertical bar connects the output of one process EQN to the input of another TROFF 5 Language Theory 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 fol lowed 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 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
10. easy to imple ment 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 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 A priori the grammar compiler compiler approach seemed the right thing to do Our subse quent 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 work ing 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 occasion ally changing the language as users make criticisms and suggestions We also decided quite early that we would let TROFF do our work for us whenever possible TROFF is quite a powerful program with a macro facility text and arithmetic variables numerical com putation 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 TROFF Thus we avoid having to write a storage management package Furthermore we have been ab
11. example the input EQ I 3 1a x f y 2 y 2 EN produces the output x f y2 4y2 3 1a There is also a shorthand notation so in line expressions like 1 can be entered without EQ and EN We will talk about it in section 19 3 Input spaces Spaces and newlines within an expression are thrown away by EQN Normal text is left absolutely alone Thus between EQ and EN xX y z and X yt zZ and x y z and so on all produce the same output X y zZ 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 4 Output spaces To force extra spaces into the output use a tilde for each space you want xX ytz gives x ytz AZE 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 TROFF commands 5 Symbols Special Names Greek EQN knows some mathematical symbols some mathematical names and the Greek alpha bet For example x 2 pi int sin omega t dt produces x 2n sin rdt Here the spaces in the input are necessary to tell EQN that int pi sin and omega are separate enti ties that should get special treatment The sin digit 2 and parentheses are set in roman type instead of itali
12. is which is a sup 2 b sub 2 sup half 11 Summation Integral Etc Summations integrals and similar con structions are easy sum from i 0 to i inf x sup i produces 00 La i 0 Notice that we used braces to indicate where the upper part i co 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 from and to parts contain any blanks you must use braces around them The from and to parts are both optional but if both are used they have to occur in that order Other useful characters can replace the sum in our example int prod union inter become respectively I Wun Since the thing before the from can be anything even something in braces from to can often be used in unexpected ways lim from n gt inf x sub n 0 is lim x 0 n 12 Size and Font Changes 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 EQN makes a valiant attempt to use esthetically pleasing sizes and fonts it is not perfect To change sizes and fonts use size n and roman italic bold and fat Like sub and sup size and font changes affect only the thing that follows them and revert to the normal situation at the end of it Thus bold x y is Xy and size 14 bold x y size 14
13. language that if a construct can appear in some context then any expression in braces can also occur in that context There is a sqrt operator for making square roots of the appropriate size sqrt a b produces Va b and x b sqrt b sup 2 4ac over 2a is b Vb 4ac 2a Since large radicals look poor on our typesetter sqrt is not useful for tall expressions Limits on summations integrals and similar constructions are specified with the keywords from and to To get Px gt 0 i 0 we need only type sum from i 0 to inf x sub i gt 0 Centering and making the big enough and the limits smaller are all automatic The from and to parts are both optional and the central part e g the can in fact be anything lim from x gt pi 2 tanx inf is lim tan x x72 Again the braces indicate just what goes into the from part There is a facility for making braces brackets parentheses and vertical bars of the right height using the keywords left and right left x y over 2a right 1 pe 2a A left need not have a corresponding right as we shall see in the next example Any characters may follow left and right but generally only various parentheses and bars are meaningful makes Big brackets etc are often used with another facility called piles which make vertical piles of objects For example to get 1 if x gt 0 0 if x 0 1 if x lt 0 sign x we can
14. left pile a above b above c pile x above y above z right ax A b y cz 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 key word 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 will make Three other forms of pile exist Ipile makes a pile with the elements left justified rpile makes a right justified pile and cpile makes a centered pile just like pile The verti cal spacing between the pieces is somewhat larger for l r and cpiles than it is for ordinary piles roman sign xy left lpile 1 above 0 above 1 Ipile if x gt 0 above ifx 0 above ifx lt 0 makes 1 if x gt 0 signx 0 if x 0 1 if x lt 0 Notice the left brace without a matching right one 18 Matrices It is also possible to make matrices For example to make a neat array like you have to type matrix ccol x sub i above y sub i ccol x sup 2 above y sup 2 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 above You can also use Icol or rcol to left or right adjust columns Each column can be separately adjusted and there can be as many columns as you like The reason for using a matrix instead o
15. of these are simple ones used only to guarantee that some keyword is recog nized 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 indicates an alternative the brack ets indicate optional material A 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 eqn box eqn box text eqn box OVER box SQRT box box SUB box box SUP box L C R JPILE list LEFT text eqn RIGHT text box FROM box TO box SIZE text box ROMAN BOLD ITALIC box box DEFINE text text eqn list ABOVE eqn TEXT list text box HAT BAR DOT DOTDOT TILDE 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 eqn box eqn box box text eqn Anywhere a single character could be used any legal construction can be used Clearly our grammar is highly ambiguous What for instance do we do with the input a over b overc Is it a over b over c or is it a over b over c To answer questions like this the grammar is supplemented with a small set of rules that describe the precedence and associativity of operators In par
16. paper a sub 0 b sub 1 over a sub 1 b sub 2 over a sub 2 b sub 3 over a sub 3 This is the input for the large integral of Section 1 notice the use of definitions 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 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 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 C 6 a high level language reminiscent of BCPL About 20 percent of these lines are print statements generating the out put code The semantic routines that generate the actual TROFF commands can be changed to accommodate other formatting languages and devices For example in less than
17. type sign x left rpile 1 above 0 above 1 Tpile if above if above if Tpile x gt 0 above x 0 above x lt 0 The construction left makes a left brace big enough to enclose the rpile which is a right justified pile of above above Ipile 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 Although 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 sign in the previous example would conventionally be in roman Slides and tran sparencies often require larger characters than normal text Thus we also provide size and font changing commands size 12 bold Ax y Size is followed by a number represent ing a character size in points One point is 1 72 x y will produce inch this paper is set in 9 point type If necessary an input string can be quoted in a which turns off grammatical significance and any font or spacing changes that might otherwise be done on it Thus we can say lim roman sup x sub n 0 to ensure that the supremum doesn t become a super script lim sup x 0 Diacritical marks long a problem in traditional typesetting are straightforward
18. 24 hours one of us changed the entire semantic package to drive NROFF a variant of 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 7 Conclusions 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 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 Acknowledgements We are deeply indebted to J F Ossanna the author of TROFF for his willingness to modify TROFF to ma
19. 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 On UNIX the phototypesetter is driven by a formatting program called TROFF 4 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 For this reason we decided to use TROFF as an assembly language by designing a language for describing mathematical expressions and compiling it into TROFF 3 Language Design 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 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 typ ing Thus the language should not assume for instance that parentheses are always balanced for
20. A System for Typesetting Mathematics Brian W Kernighan and Lorinda L Cherry Bell Laboratories Murray Hill New Jersey 07974 ABSTRACT This paper describes the design and implementation of a system for typesetting mathemat ics 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 excep tions 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 exam ple the input sum from i 0 to infinity x sub i pi over 2 produces S T LiF 5 i 0 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 Introduction Mathematics is known in the trade as difficult or penalty copy because it is slower more difficult and more expensive to set in type than any other kin
21. He you can t just type sup 2 roman He because a sup has to be a superscript on something Thus you must say we sup 2 roman He To get a literal quote use TROFF characters like bs can appear unquoted but more complicated things like horizontal and vertical motions with i and v should always be quoted If you ve never heard of h and W ignore this section 15 Lining Up Equations 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 mark and lineup The word mark may appear once at any place in an equation It remembers the horizon tal position where it appeared Successive equa tions can contain one occurrence of the word lineup The place where lineup appears is made to line up with the place marked by the previous mark if at all possible Thus for example you can say EQ I x y mark z EN EQ I x lineup 1 EN to produce x y z x 1 For reasons too complicated to talk about when you use EQN and ms use either EQI or EQL mark and lineup don t work with centered equa tions Also bear in mind that mark doesn t look ahead x mark 1 x y lineup z isn t going to work because there isn t room for the x y part after the mark remembers where the x is 16 Big Brackets Etc To get big brackets braces parentheses and bars around things use
22. ake the output look right The words sub and sup must be sur rounded by spaces x sub2 will give you xsub 2 instead of x2 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 y x sup 2 1 which causes y x2 instead of the intended y Q 41 Subscripted subscripts and superscripted superscripts also work x sub i sub 1 is Xi A subscript and superscript on the same thing are printed one above the other if the subscript comes first x sub i sup 2 is ae Other than this special case sub and sup y group to the right so x sup y sub z means x not x 8 Braces for Grouping Normally the end of a subscript or super script 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 e sup i omega t is iot Rule Braces can always be used to force EQN to treat something as a unit or just to make your intent perfectly clear Thus x sub i sub 1 sup 2 is with braces but x sub i sub 1 sup 2 is x 2 which is rather different Braces can occur within braces if neces sary e sup i pi sup rho 1 is e mt The general rule is that anywhere you could use some single thing like x you can use an arbi trar
23. alpha beta gives X y 0 B 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 size 12 Legal sizes which may follow size are 6 7 8 9 10 11 12 14 16 18 20 22 24 28 36 You can also change the size by a given amount for example you can say size 2 to make the size two points bigger or size 3 to make it three points smaller This has the advantage that you don t have to know what the current size is If you are using fonts other than roman italic and bold you can say font X where X is a one character TROFF name or number for the font Since EQN is tuned for roman italic and bold other fonts may not give quite as good an appearance The fat operation takes the current font and widens it by overstriking fat grad is V and fat x sub i is x 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 equa tions At the beginning of any equation you might say for instance EQ gsize 16 gfont R EN to set the size to 16 and the font to roman thereafter In place of R you can use any of the TROFF font names The size after gsize can be a relative change with or Generally gsize and gfont will
24. ated if it is enclosed in braces 22 A Large Example Here is the complete source for the three display equations in the abstract of this guide QI G z mark e sup In G z exp left sum from k gt 1 S sub k z sup k over k right prod from k gt 1 e sup S sub k z sup k k EN QI 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 QI lineup sum from m gt 0 left sum from pile k sub 1 k sub 2 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 k sub m gt 0 ya S sub 2 sup k sub 2 over 2 sup k sub 2 k sub 2 7 S sub m sup k sub m over m sup k sub m k sub m right z sup m EN 23 Keywords Precedences Etc If you don t use braces EQN will do operations in the order shown in this list dyad vec under bar tilde hat dot dotdot fwd back down up fat roman italic bold size sub sup sqrt over from to These operations group to the left over sqrt left right All others group to the right Digits parentheses brackets punctuation marks and these mathematical words are con verted to Roman font when encountered sin cos tan sinh cosh tanh arc max min lim log In exp Re Im and if for det These character sequences are recognized and translated as sh
25. c pi and omega are made Greek and int becomes the integral sign When in doubt leave spaces around separate parts of the input A very common error is to type f pi without leaving spaces on both sides of the pi As a result EQN does not recognize pi as a special word and it appears as f pi instead of f 7 A complete list of EQN names appears in section 23 Knowledgeable users can also use TROFF four character names for anything EQN doesn t know about like bs for the Bell Sys tem sign 6 Spaces Again The only way 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 new lines as we did in the previous section You can also make special words stand out by surrounding them with tildes or circumflexes x 2 pint sin omega t dt is much the same as the last example except that the tildes not only separate the magic words like sin omega and so on but also add extra spaces one space per tilde x 2n sin or dt Special words can also be separated by braces and double quotes which have special meanings that we will see soon 7 Subscripts and Superscripts Subscripts and superscripts are obtained with the words sub and sup x sup 2 y sub k gives x y EQN takes care of all the size changes and verti cal motions needed to m
26. cribed at the end of this section 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 Input is free form Spaces and new lines in the input are used by EQN to separate pieces of the input they are not used to create space in the output Thus also gives x y z 1l Free form input is easier to type initially subsequent editing is also easier for an expression may be typed as many short lines 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 Spaces or tildes etc also serve to delimit pieces of the input For example to get f t 2n sin t dt we write f t 2 pi int sin omega t dt Here spaces are necessary in the input to indicate that sin pi int and omega are special and potentially worth special treatment EQN looks up each such string of characters in a table and if appropriate gives it a translation In this case pi and omega become their greek equivalents int becomes the integral sign which must be moved down and enlarged so it looks right and sin is made roman following conven tional mathematical practice Paren
27. d of copy normally occurring in books and journals 1 One difficulty with mathematical text is the multiplicity of characters sizes and fonts An expression such as lim tan x 1 x2 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 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 by ag be a Bs az a3 E and still further by 1 Vae Vb oe 2mVab Vae Vb f nue 1 tanh Va gmx ae be mvab Vb coti V4 em mNvVab Vb 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 2 Photocomposition Photocomposition techniques can be used to solve some of the problems of typesetting mathemat ics A phototypesetter is a device which exposes a piece of photographic paper or film placing charac ters wherever they are wanted The Graphic Systems phototypesetter 2 on the UNIX operating system
28. ence There are really three aspects of interest how well EQN sets mathematics how well it satisfies its goal of being easy to use and how easy it was to build 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 gt flowers of illuminated manuscripts on esthetic grounds either but they have some clear economic advantages Some of the deficiencies in the output could be cleaned up with more work on our part For exam ple 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 Some other weaknesses are inherent in our out put device It is hard for instance to draw a line of an arbitrary length without getting a perceptible over strike at one end 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 1 _ It s easy to write although I make the follow ing mistakes
29. f two adjacent piles by the way is that if the ele ments 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 A word of warning about matrices each column must have the same number of elements in it The world will end if you get this wrong 19 Shorthand for In line Equations In a mathematical document it is neces sary 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 sur rounding the appropriate parts with EQ and EN the continual repetition of EQ and EN is a nui sance Furthermore with ms EQ and EN imply a displayed equation 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 equa tion and then type expressions right in the mid dle 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 EQ delim EN Having done this you can then say things like Let alpha sub i be the primary variable and let beta be zero Then we can show that x sub 1 is gt 0 This works as you might expect spaces new lines and so on are significant in the text but not in the e
30. ily complicated thing if you enclose it in braces EQN will look after all the details of positioning it and making it the right size In all cases make sure you have the right number of braces Leaving one out or adding an extra will cause EQN to complain bitterly Occasionally you will have to print braces To do this enclose them in double quotes like Quoting is discussed in more detail in sec tion 14 9 Fractions To make a fraction use the word over a b over 2c 1 gives a b 2c The line is made the right length and positioned automatically Braces can be used to make clear what goes over what 1 alpha beta over sin x is a p sin x What happens when there is both an over and a sup in the same expression In such an apparently ambiguous case EQN does the sup before the over so b sup 2 over pi pb2 2 is Pa instead of b The rules which decide which operation is done first in cases like this are summarized in section 23 When in doubt however use braces to make clear what goes with what 10 Square Roots To draw a square root use sqrt sqrt a b 1 over sqrt ax sup 2 bx c is Va b Vax bx c Warning square roots of tall quantities look lousy because a root sign big enough to cover the quantity is too dark and heavy sqrt a sup 2 over b sub 2 Faz bo Big square roots are generally better written as something to the power 7 a b
31. isplay equations like x gt 22 G z en G z exp Soa Sz pee r k21 k21 S z Saz S3z4 Be ee ea cd ae ee 2 2 2 9 k k ka S S2 Sm m y z eee E Zz m20 koky kp Z0 1 ky 2 k m Kin k 2k 4 gt mk m can be learned in an hour or so The language interfaces directly with the phototypesetting language 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 The same language may be used with the UNIX formatter NROFF to set mathematical expressions on DASI and GSI terminals and Model 37 teletypes August 15 1978 UNIX is a Trademark of Bell Laboratories Typesetting Mathematics User s Guide Second Edition Brian W Kernighan and Lorinda L Cherry Bell Laboratories Murray Hill New Jersey 07974 1 Introduction EQN is a program for typesetting mathematics on the Graphics Systems photo typesetters on UNIX and GCOS The EQN language was designed to be easy to use by peo ple who know neither mathematics nor typeset ting Thus EQN knows relatively little about mathematics In particular mathematical sym bols like x parentheses and so on have no special meanings EQN is quite happy to set gar bage but it will look good EQN works as a preprocessor for the typesetter formatter TROFF 1 so the normal mode of operation is to p
32. its 494X4 74Z is made by typing x dot under x hat y tilde X hat Y dotdot z Z bar There are also facilities for globally changing default sizes and fonts for example for making view graphs or for setting chemical equations The language allows for matrices and for lining up equa tions at the same horizontal position Finally there is a definition facility so a user can say define name 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 sup or over Sec tion 6 shows an example of definitions The EQN preprocessor reads intermixed text and equations and passes its output to TROFF Since TROFF uses lines beginning with a period as control words e g ce means center the next output line 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 TROFF untouched so they can also be used by a knowledge able user to center equations number them automati cally etc By default however EQ and EN are simply ignored by TROFF so by default equations are printed in line EQ and EN can be supplemented
33. ke 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 Mcllroy for their constructive criticisms References 1 A Manual of Style 12th Edition University of Chicago Press 1969 p 295 Model C A T Phototypesetter tems Inc Hudson N H Ritchie D M and Thompson K L The UNIX time sharing system Comm ACM 17 7 July 1974 365 375 Ossanna J F TROFF User s Manual Bell Laboratories Computing Science Technical Report 54 1977 Aho A V and Johnson S C LR Pars ing Comp Surv 6 2 June 1974 99 124 B W Kernighan and D M Ritchie The C Programming Language Prentice Hall Inc 1978 2 Graphic Sys 3 4 5 6 Typesetting Mathematics User s Guide Second Edition Brian W Kernighan and Lorinda L Cherry Bell Laboratories Murray Hill New Jersey 07974 ABSTRACT This is the user s guide for a system for typesetting mathematics using the phototypesetters on the UNIX and GCOS operating systems 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 tan x 1 or d
34. le to isolate ourselves from most details of the particular device and charac ter set currently in use For example we let TROFF compute the widths of all strings of characters we need know nothing about them A third design goal is special to our environ ment Since our program is only useful for typeset ting 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 TROFF com mands The resulting ioutput is passed directly to TROFF where the comments and the mathematical parts both become text and or TROFF commands 4 The Language We will not try to describe the language pre cisely here interested readers may refer to the appen dix for more details Throughout this section we will write expressions exactly as they are handed to the typesetting program hereinafter called EQN except that we won t show the delimiters that the user types to mark the beginning and end of the expres sion The interface between EQN and TROFF is des
35. or Set ting Tables Bell Laboratories Comput ing Science Technical Report 49 1976
36. own gt gt inf partial 0 half prime approx nothing cdot times del grad lt lt x sum int SM prod union U a inter To obtain Greek letters simply spell them out in whatever case you want DELTA A iota 1 GAMMA T kappa K LAMBDA A lambda OMEGA Q mu u PHI p nu v PI II omega oO PSI y omicron oO SIGMA phi o THETA pi T UPSILON Y psi y XI E rho p alpha a sigma oO beta B tau T chi x theta 0 delta upsilon v epsilon xi E eta n zeta C gamma Y These are all the words known to EQN except for characters with names together with the section where they are discussed 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 So 4 6 Icol 18 8 left 16 Maa 8 14 lineup 15 24 Troubleshooting 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 sup with nothing before it common EQN will tell you with the message syntax error between lines x and y file z where x and y are approximately the lines between which the trouble occurred and z is the name of the file in question The line numbers are approximate
37. quation part itself Multiple equa tions can occur in a single input line Enough room is left before and after a line that contains in line expressions that something n like x does not interfere with the lines sur i l rounding it To turn off the delimiters EQ delim off EN Warning don t use braces tildes circumflexes or double quotes as delimiters chaos will result 20 Definitions 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 x sub i sub 1 y subi sub 1 appears repeatedly throughout a paper you can save re typing it each time by defining it like this define xy x subi sub 1 y subi sub 1 This makes xy a shorthand for whatever charac ters 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 Now you can use xy like this EQ f x xy EN and so on Each occurrence of 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 EQN will be able to iden tify it as special There are several things to watch out for First although definitions can use previous definitions as in EQ define xi x subi define xil xi sub 1 EN
38. repare a document with both mathematics and ordinary text interspersed and let EQN set the mathematics while TROFF does the body of the text On UNIX EQN will also produce mathematics on DASI and GSI terminals and on Model 37 teletypes The input is identical but you have to use the programs NEQN and NROFF instead of EQN and 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 To use EQN on UNIX eqn files troff GCOS use is discussed in section 26 2 Displayed Equations To tell EQN where a mathematical expres sion begins and ends we mark it with lines beginning EQ and EN Thus if you type the lines EQ x y Zz EN your output will look like X y Z The EQ and EN are copied through untouched they are not otherwise processed by 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 TROFF and NROFF macro package package ms developed by M E Lesk 3 which allows you to center indent left justify and number equations With the ms package equations are centered by default To left justify an equation use EQ L instead of EQ To indent it use EQ I Any of these can be followed by an arbitrary equation number which will be placed at the right margin For
39. t TEXT The translation of this is simple We generate a local name for the string then hand the name and the string to TROFF and let TROFF perform the storage management All we save is the name of the string its height and its baseline As another example the translation associated with the production box box OVER box is 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 1 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 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 With a grammar it is usually clear how to extend the language For instance one of our users suggested a TENSOR operator to make constructions like kj l T Mni Grammatically this is easy it is sufficient to add a production like box TENSOR list Semantically we need only juggle the boxes to the right places 6 Experi
40. theses digits and operators are automatically made roman wherever found Fractions are specified with the keyword over a b over c d e 1 produces a b _ c d e Similarly subscripts and superscripts are intro duced by the keywords sub and sup xyz is produced by x sup 2 y sup 2 z sup 2 The spaces after the 2 s are necessary to mark the end of the superscripts similarly the keyword sup has to be marked off by spaces or some equivalent delimiter The return to the proper baseline is automatic Multi ple levels of subscripts or superscripts are of course allowed x sup y sup z is x The construct something sub something sup something is recog nized as a special case so x sub i sup 2 is x instead of x 7 More complicated expressions can now be formed with these primitives Of x eres y dx a b p2 is produced by partial sup 2 f over partial x sup 2 x sup 2 over a sup 2 y sup 2 over b sup 2 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 sup to be higher than that of 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 The braces convention is an example of the power of using a recursive grammar to define the language Itis part of the
Download Pdf Manuals
Related Search
Related Contents
Mölnlycke, September 16th, 2009 BENDIX PNU-004 User's Manual Contents T'nB NEBR01 cleaning media 取扱説明書 Adcom GFA GFA-7700 User's Manual Junior Association en association Loi 1901 Copyright © All rights reserved.
Failed to retrieve file