Typesetting Mathematics-User's Guide (Second Edition) Brian W. Kernighan Lorinda L. Cherry Bell Laboratories Murray Hill, New Jersey 07974 _A_B_S_T_R_A_C_T This is the user's guide for a system for typesetting mathematics, using the phototypesetters on the UNIX* operat- ing 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 like9 _x->J/28lim (tan _x)sin 2_x = 1 or display 9equations like 9 _G(_z) = _eln _G(_z) = exp7|99|99|8_k>_18R9 _k7_S_k_z_k9____7|99|99|7 =9 _k>_18P _e8_S_k_z8_k9/_k 9 =7|99|99|71+_S1_z+9 2!7_S182_z29____+...7|99|99|77|99|99|71+9 27_S2_z29____+922.2!7_S282_z49_____+...7|99|99|7... 9 =9_m>_08R77 |99|99|99|99|8_k1+2_k2+...+_m_k_m=_m8_k1,_k2,...,_k_m>_08R9 18_k19_k1!7_S18_k199______9 28_k29_k2!7_S28_k299______ ...9_m8_k_m9_k_m!7_S_m8_k_m99______77|99|99|99|99|77_z_m can be learned in an hour or so. The language interfaces directly with the phototypeset- ting 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 terminals and Model 37 _T_E_L_E_T_Y_P_E8r9 terminals. 9-------------------------- * UNIX is a Trademark of Bell Laboratories. June 26, 1991 2 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e _1. _I_n_t_r_o_d_u_c_t_i_o_n EQN is a program for typesetting mathematics on photo- typesetters on UNIX. The EQN language was designed to be easy to use by people who know neither mathematics nor typesetting. Thus EQN knows relatively little about mathematics. In particular, mathematical symbols like +, -, x, parentheses, and so on have no special meanings. EQN is quite happy to set garbage (but it will look good). EQN works as a preprocessor for the typesetter for- matter, TROFF [1], so the normal mode of operation is to prepare 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 ter- minals and on Model 37 _T_E_L_E_T_Y_P_E terminals. 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 char- acters, sizes and fonts that a typesetter does, but the out- put is usually adequate for proofreading. To use EQN on UNIX, eqn files | troff _2. _D_i_s_p_l_a_y_e_d _E_q_u_a_t_i_o_n_s To tell EQN where a mathematical expression begins and ends, we mark it with lines beginning .EQ and .EN. Thus if you type the lines .EQ x=y+z .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 packages `-ms' and `-mm' [3,4], which allow 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 June 26, 1991 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 3 the right margin. For example, the input .EQ I (3.1a) x = f(y/2) + y/2 .EN produces the output _x_=_f(_y_/2)_+_y_/2 (3.1a) There is also a shorthand notation so in-line expres- sions like J_i82 can be entered without .EQ and .EN. We will talk about it in section 19. _3. _I_n_p_u_t _s_p_a_c_e_s Spaces and new-lines within an expression are thrown away by EQN. (Normal text is left absolutely alone.) Thus between .EQ and .EN, x=y+z and x = y + z and x = y + z and so on all produce the same output _x_=_y_+_z You should use spaces and new-lines 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. _O_u_t_p_u_t _s_p_a_c_e_s To force extra spaces into the _o_u_t_p_u_t, use a tilde ``~'' for each space you want: x~=~y~+~z gives _x _= _y _+ _z You can also use a circumflex ``^'', which gives a space half the width of a tilde. It is mainly useful for fine- June 26, 1991 4 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e tuning. Tabs may also be used to position pieces of an expression, but the tab stops must be set by TROFF commands. _5. _S_y_m_b_o_l_s, _S_p_e_c_i_a_l _N_a_m_e_s, _G_r_e_e_k EQN knows some mathematical symbols, some mathematical names, and the Greek alphabet. For example, x=2 pi int sin ( omega t)dt produces _x_=2J^sin(C_t)_d_t Here the spaces in the input are _n_e_c_e_s_s_a_r_y to tell EQN that _i_n_t, _p_i, _s_i_n and _o_m_e_g_a are separate entities that should get special treatment. The _s_i_n, digit 2, and parentheses are set in roman type instead of italic; _p_i and _o_m_e_g_a are made Greek; and _i_n_t becomes the integral sign. When in doubt, leave spaces around separate parts of the input. A _v_e_r_y common error is to type _f(_p_i) without leaving spaces on both sides of the _p_i. As a result, EQN does not recognize _p_i as a special word, and it appears as _f(_p_i) instead of _f(J). 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 \(_b_s for the Bell System sign . _6. _S_p_a_c_e_s, _A_g_a_i_n 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 surround- ing them with tildes or circumflexes: x~=~2~pi~int~sin~(~omega~t~)~dt is much the same as the last example, except that the tildes not only separate the magic words like _s_i_n, _o_m_e_g_a, and so on, but also add extra spaces, one space per tilde: _x _= 2 J ^ sin ( C _t ) _d_t Special words can also be separated by braces { } and double quotes "...", which have special meanings that we will see soon. June 26, 1991 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 5 _7. _S_u_b_s_c_r_i_p_t_s _a_n_d _S_u_p_e_r_s_c_r_i_p_t_s Subscripts and superscripts are obtained with the words _s_u_b and _s_u_p. x sup 2 + y sub k gives _x2_+_y_k EQN takes care of all the size changes and vertical motions needed to make the output look right. The words _s_u_b and _s_u_p must be surrounded by spaces; _x _s_u_b_2 will give you _x_s_u_b2 instead of _x2. Furthermore, don't forget to leave a space (or a tilde, etc.) to mark the end of a subscript or super- script. A common error is to say something like y = (x sup 2)+1 which causes _y_=(_x2)_+1 instead of the intended _y_=(_x2)_+1 Subscripted subscripts and superscripted superscripts also work: x sub i sub 1 is _x_i1 A subscript and superscript on the same thing are printed one above the other if the subscript comes _f_i_r_s_t: x sub i sup 2 is _x_i82 Other than this special case, _s_u_b and _s_u_p group to the right, so _x _s_u_p _y _s_u_b _z means _x8_y_z9, not _x_y_z. June 26, 1991 6 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e _8. _B_r_a_c_e_s _f_o_r _G_r_o_u_p_i_n_g 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: e sup {i omega t} is _e_iC_t Rule: Braces can _a_l_w_a_y_s be used to force EQN to treat some- thing as a unit, or just to make your intent perfectly clear. Thus: x sub {i sub 1} sup 2 is _x_i182 with braces, but x sub i sub 1 sup 2 is _x_i172 9which is rather different. Braces can occur within braces if necessary: e sup {i pi sup {rho +1}} is _e_iJ8K_+1 9The general rule is that anywhere you could use some single thing like _x, you can use an arbitrarily 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 June 26, 1991 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 7 this, enclose them in double quotes, like "{". Quoting is discussed in more detail in section 14. _9. _F_r_a_c_t_i_o_n_s To make a fraction, use the word _o_v_e_r: a+b over 2c =1 gives 9 2_c7_a_+_b____=1 9The line is made the right length and positioned automati- cally. Braces can be used to make clear what goes over what: {alpha + beta} over {sin (x)} is 9 sin(_x)7A_+B______ 9What happens when there is both an _o_v_e_r and a _s_u_p in the same expression? In such an apparently ambiguous case, EQN does the _s_u_p before the _o_v_e_r, so -b sup 2 over pi 9is9 J7-_b2___ instead of -_bJ72_9. The rules which decide which opera- 9tion is done first in cases like this are summarized in sec- tion 23. When in doubt, however, _u_s_e _b_r_a_c_e_s to make clear what goes with what. _1_0. _S_q_u_a_r_e _R_o_o_t_s To draw a square root, use _s_q_r_t: sqrt a+b + 1 over sqrt {ax sup 2 +bx+c} is _a_+_b_+9_a_x2_+_b_x_+_c71________ 9Warning - 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} is 9 June 26, 1991 8 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 99 5 5_b27_a2__ 9Big square roots are generally better written as something to the power 1/2: (_a2_/_b2)1/2 which is (a sup 2 /b sub 2 ) sup half _1_1. _S_u_m_m_a_t_i_o_n, _I_n_t_e_g_r_a_l, _E_t_c. Summations, integrals, and similar constructions are easy: sum from i=0 to {i= inf} x sup i produces 99 _i_=08R8_i_=oo9_x_i 9Notice that we used braces to indicate where the upper part _i=oo 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 _f_r_o_m and _t_o parts contain any blanks, you must use braces around them. The _f_r_o_m and _t_o parts are both optional, but if both are used, they have to occur in that order. Other useful characters can replace the _s_u_m in our example: int prod union inter become, respectively, ^ P U Since the thing before the _f_r_o_m can be anything, even some- thing in braces, _f_r_o_m-_t_o can often be used in unexpected ways: lim from {n -> inf} x sub n =0 is 9 _n__->oo8lim _x_n_=0 99 June 26, 1991 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 9 _1_2. _S_i_z_e _a_n_d _F_o_n_t _C_h_a_n_g_e_s By default, equations are set in 10-point type (the same size as this guide), with standard mathematical conven- tions to determine what characters are in roman and what in italic. Although EQN makes a valiant attempt to use esthet- ically pleasing sizes and fonts, it is not perfect. To change sizes and fonts, use _s_i_z_e _n and _r_o_m_a_n, _i_t_a_l_i_c, _b_o_l_d and _f_a_t. Like _s_u_b and _s_u_p, 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 x_y and size 14 bold x = y + size 14 {alpha + beta} gives x_=_y_+A_+B As always, you can use braces if you want to affect some- thing 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 _s_i_z_e are 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 28, 36. You can also change the size _b_y a given amount; for example, you can say _s_i_z_e +_2 to make the size two points bigger, or _s_i_z_e -_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 _f_o_n_t _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 _f_a_t operation takes the current font and widens it by overstriking: _f_a_t _g_r_a_d is [[ and _f_a_t {_x _s_u_b _i} is _x_i_x_i. 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 June 26, 1991 10 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e equations. 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 _g_s_i_z_e can be a relative change with + or -. Generally, _g_s_i_z_e and _g_f_o_n_t will appear at the beginning of a document but they can also appear throughout a docu- ment: the global font and size can be changed as often as needed. For example, in a footnote|= 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. _1_3. _D_i_a_c_r_i_t_i_c_a_l _M_a_r_k_s To get funny marks on top of letters, there are several words: x dot _x8. 9 x dotdot _x8.. 9 x hat _x^ x tilde _x~ x vec _x-> x dyad _x<--> x bar _x8_ 9 x under _x_ x utilde _x9~ 9The diacritical mark is placed at the right height. The _b_a_r and _u_n_d_e_r are made the right length for the entire con- struct, as in _x+_y+_z8_____9; other marks are centered. _1_4. _Q_u_o_t_e_d _T_e_x_t 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: italic "sin(x)" + sin (x) -------------------------- |=Like this one, in which we have a few random expres- sions like _x_i and J2. The sizes for these were set by the command _g_s_i_z_e -_2. June 26, 1991 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 11 is _s_i_n_(_x_)_+sin(_x) Quotes are also used to get braces and other EQN key- words printed: "{ size alpha }" is _{ _s_i_z_e _a_l_p_h_a _} and roman "{ size alpha }" is { size alpha } The construction "" is often used as a place-holder when grammatically EQN needs something, but you don't actu- ally want anything in your output. For example, to make 2He, you can't just type _s_u_p _2 _r_o_m_a_n _H_e because a _s_u_p has to be a superscript _o_n something. Thus you must say "" sup 2 roman He To get a literal quote use ``\"''. TROFF characters like _\(_b_s can appear unquoted, but more complicated things like horizontal and vertical motions with _\_h and _\_v should always be quoted. (If you've never heard of \_h and \_v, ignore this section.) _1_5. _L_i_n_i_n_g _u_p _E_q_u_a_t_i_o_n_s Sometimes it's necessary to line up a series of equa- tions at some horizontal position, often at an equals sign. This is done with two operations called _m_a_r_k and _l_i_n_e_u_p. The word _m_a_r_k may appear once at any place in an equa- tion. It remembers the horizontal position where it appeared. Successive equations can contain one occurrence of the word _l_i_n_e_u_p. The place where _l_i_n_e_u_p appears is made to line up with the place marked by the previous _m_a_r_k if at all possible. Thus, for example, you can say June 26, 1991 12 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e .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 .EQ I or .EQ L. mark and _l_i_n_e_u_p don't work with centered equations. Also bear in mind that _m_a_r_k 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 _m_a_r_k remembers where the _x is. _1_6. _B_i_g _B_r_a_c_k_e_t_s, _E_t_c. To get big brackets [], braces {}, parentheses (), and bars || around things, use the _l_e_f_t and _r_i_g_h_t commands: left { a over b + 1 right } ~=~ left ( c over d right ) + left [ e right ] is 97 |99|99|8_b7_a__+17|99|99|7 _=7 |99|99|8_d7_c_7|99|99|7_+8|99|8_e8|99| 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 _f_l_o_o_r and _c_e_i_l_i_n_g characters: left floor x over y right floor <= left ceiling a over b right ceiling produces 97 |99|99|8_y7_x_7|99|99|7<_7|99|99|8_b7_a_7|99|99| 9 June 26, 1991 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 13 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. The _r_i_g_h_t part may be omitted: a ``left something'' need not have a corresponding ``right something''. If the _r_i_g_h_t part is omitted, put braces around the thing you want the left bracket to encompass. Otherwise, the resulting brackets may be too large. If you want to omit the _l_e_f_t part, things are more com- plicated, because technically you can't have a _r_i_g_h_t without a corresponding _l_e_f_t. Instead you have to say left "" ..... right ) for example. The _l_e_f_t "" means a ``left nothing''. This satisfies the rules without hurting your output. _1_7. _P_i_l_e_s There is a general facility for making vertical piles of things; it comes in several flavors. For example: A ~=~ left [ pile { a above b above c } ~~ pile { x above y above z } right ] will make 9 _A _=7 |99|99|8_c8_b8_a99 _z8_y8_x8|99|99| 9The 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 _a_b_o_v_e 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. Three other forms of pile exist: _l_p_i_l_e makes a pile with the elements left-justified; _r_p_i_l_e makes a right- justified pile; and _c_p_i_l_e makes a centered pile, just like _p_i_l_e. The vertical spacing between the pieces is somewhat larger for _l-, _r- and _c_p_i_l_e_s than it is for ordinary piles. June 26, 1991 14 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e roman sign (x)~=~ left { lpile {1 above 0 above -1} ~~ lpile {if~x>0 above if~x=0 above if~x<0} makes sign(_x) _=77 |99|99|99|99|7_-17071999 if _x_<07if _x_=07if _x_>0 9Notice the left brace without a matching right one. _1_8. _M_a_t_r_i_c_e_s It is also possible to make matrices. For example, to make a neat array like 99 _y_i7_x_i99 _y27_x2 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 ele- ments of the columns are then listed just as for a pile, each element separated by the word _a_b_o_v_e. You can also use _l_c_o_l or _r_c_o_l 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 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. A word of warning about matrices - _e_a_c_h _c_o_l_u_m_n _m_u_s_t _h_a_v_e _t_h_e _s_a_m_e _n_u_m_b_e_r _o_f _e_l_e_m_e_n_t_s _i_n _i_t. The world will end if you get this wrong. _1_9. _S_h_o_r_t_h_a_n_d _f_o_r _I_n-_l_i_n_e _E_q_u_a_t_i_o_n_s 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 sur- rounding the appropriate parts with .EQ and .EN, the June 26, 1991 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 15 continual repetition of .EQ and .EN is a nuisance. Further- more, 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 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 begin- ning 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 $>=0$. This works as you might expect - spaces, new-lines, and so on are significant in the text, but not in the equation part itself. Multiple equations can occur in a single input line. Enough room is left before and after a line that con- 9tains in-line expressions that something like9 _i=18R8_n9 _x_i does not 9interfere with the lines surrounding 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. Also, in-line font changes must be closed before in-line equations are encountered. _2_0. _D_e_f_i_n_i_t_i_o_n_s 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 sub i sub 1 appears repeatedly throughout a paper, you can save re- typing it each time by defining it like this: define xy 'x sub i sub 1 + y sub i sub 1' June 26, 1991 16 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e This makes _x_y 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 defini- tion. Now you can use _x_y like this: .EQ f(x) = xy ... .EN and so on. Each occurrence of _x_y 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 identify it as special. There are several things to watch out for. First, although definitions can use previous definitions, as in .EQ define xi ' x sub i ' define xi1 ' xi sub 1 ' .EN _d_o_n'_t _d_e_f_i_n_e _s_o_m_e_t_h_i_n_g _i_n _t_e_r_m_s _o_f _i_t_s_e_l_f! A favorite error is to say define X ' roman X ' This is a guaranteed disaster, since X _i_s 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 _o_v_e_r by saying define / ' over ' or redefine _o_v_e_r as / with define over ' / ' If you need different things to print on a terminal and on the typesetter, it may be worth defining a symbol dif- ferently in NEQN and EQN. This can be done with _n_d_e_f_i_n_e and _t_d_e_f_i_n_e. A definition made with _n_d_e_f_i_n_e only takes effect if you are running NEQN; if you use _t_d_e_f_i_n_e, the definition only applies for EQN. Names defined with plain _d_e_f_i_n_e apply June 26, 1991 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 17 to both EQN and NEQN. _2_1. _L_o_c_a_l _M_o_t_i_o_n_s 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 cir- cumflex. You can also say _b_a_c_k _n and _f_w_d _n to move small amounts horizontally. _n is how far to move in 1/100's of an em (an em is about the width of the letter `m'.) Thus _b_a_c_k _5_0 moves back about half the width of an m. Similarly you can move things up or down with _u_p _n and _d_o_w_n _n. As with _s_u_b or _s_u_p, the local motions affect the next thing in the input, and this can be something arbitrarily complicated if it is enclosed in braces. _2_2. _A _L_a_r_g_e _E_x_a_m_p_l_e Here is the complete source for the three display equa- tions in the abstract of this guide. .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 _2_3. _K_e_y_w_o_r_d_s, _P_r_e_c_e_d_e_n_c_e_s, _E_t_c. If you don't use braces, EQN will do operations in the order shown in this list. June 26, 1991 18 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e _d_y_a_d _v_e_c _u_n_d_e_r _u_t_i_l_d_e _b_a_r _t_i_l_d_e _h_a_t _d_o_t _d_o_t_d_o_t _f_w_d _b_a_c_k _d_o_w_n _u_p _f_a_t _r_o_m_a_n _i_t_a_l_i_c _b_o_l_d _s_i_z_e _s_u_b _s_u_p _s_q_r_t _o_v_e_r _f_r_o_m _t_o These operations group to the left: _o_v_e_r _s_q_r_t _l_e_f_t _r_i_g_h_t All others group to the right. Digits, parentheses, brackets, punctuation marks, and these mathematical words are converted to Roman font when encountered: sin cos tan sinh cosh tanh arc max min lim log ln exp Re Im and if for det These character sequences are recognized and translated as shown. >= >_ <= <_ == =_ != =/ +- +_ -> -> <- <- << << >> >> inf oo partial ] half 1/2 prime9 ' 8 approx 9~89~8 nothing cdot . times x del [ grad [ ... ... ,..., ,..., sum R int ^ prod P union U inter dollar $ To obtain Greek letters, simply spell them out in June 26, 1991 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 19 whatever case you want: DELTA W iota i GAMMA G kappa k LAMBDA E lambda L OMEGA Z mu M PHI F nu @ PI P omega C PSI H omicrono SIGMA R phi U THETA T pi J UPSILON Y psiV XI rho K alpha A sigma Y beta B tau I chi x theta O delta D upsilonv epsilon S xiX eta N zeta Q gamma \ These are all the words known to EQN (except for char- acters 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 ndefine20 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 tdefine20 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 utilde 13 June 26, 1991 20 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e _2_4. _T_r_o_u_b_l_e_s_h_o_o_t_i_n_g 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 _s_u_p with nothing before it (common), EQN will tell you with the message _s_y_n_t_a_x _e_r_r_o_r _b_e_t_w_e_e_n _l_i_n_e_s _x _a_n_d _y, _f_i_l_e _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 - 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 print- ing it, eqn files >/dev/null will throw away the output but print the messages. If you use something like dollar signs as delimiters, it is easy to leave one out. This causes very strange trou- bles. The program _c_h_e_c_k_e_q 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 over- flow'', 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. On a related topic, EQN does not break equations by itself - you must split long equations up across multiple lines by yourself, marking each by a separate .EQ ... .EN sequence. EQN does warn about equations that are too long to fit on one line. _2_5. _U_s_e _o_n _U_N_I_X To print a document that contains mathematics on the typesetter, eqn files | troff If there are any TROFF options, they go after the TROFF part of the command. For example, eqn files | troff -ms (or -mm) If you are using a non-standard typesetter, you have to tell June 26, 1991 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 21 eqn with the same -T argument that you use with TROFF: eqn -Taps files | troff -Taps ... A compatible version of EQN can be used on devices like _T_E_L_E_T_Y_P_E terminals and DASI terminals which have half-line forward and reverse capabilities. To print equations on a Model 37 _T_E_L_E_T_Y_P_E terminal, 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 res- tricted. To use a DASI terminal as the output device, neqn files | nroff -T_x where _x is the terminal type you are using, such as _3_0_0 or _3_0_0_s. 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 _2_6. _A_c_k_n_o_w_l_e_d_g_e_m_e_n_t_s 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 development and evolution of EQN. We are also grateful 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 criti- cisms. _R_e_f_e_r_e_n_c_e_s [1] J. F. Ossanna. _N_R_O_F_F/_T_R_O_F_F _U_s_e_r'_s _M_a_n_u_a_l, Bell Labora- tories, 1976. [2] M. E. Lesk. _T_y_p_i_n_g _D_o_c_u_m_e_n_t_s _o_n _U_N_I_X, Bell Labora- tories, 1976. [3] M. E. Lesk. _T_B_L-_A _P_r_o_g_r_a_m _f_o_r _S_e_t_t_i_n_g _T_a_b_l_e_s, Bell Laboratories, 1976. [4] D. W. Smith and J. R. Mashey. _M_M-_M_e_m_o_r_a_n_d_u_m _M_a_c_r_o_s, June 26, 1991 22 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e Bell Laboratories, 1980. June 26, 1991