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 like99999 _x->_J/2778lim (tan _x)78sin 2_x999 = 1 or display 9equations like 9 _G(_z) = _e78ln _G(_z)999 = exp7|99|99|99999_k>_17778_R99999 _k77777_S9_k8_z78_k999999____|99|99|7 =9999999 _k>_17778_P _e77_S99_k7_z7_k99/_k =7|99|99|71+_S918_z+99999 2!77777_S91772999_z782999999____99+...7|99|99|77|99|99|71+99999 277777_S928_z782999999____99+999992782999.2!777778_S92772999_z784999999_____99+...7|99|99|7... 9 =9999999_m>_07778_R77 |99|99|99|99|999999999_k9917+2_k9927+...+_m_k99_m7=_m7778_k9917,_k9927,...,_k99_m7>_07778_R9999999 177_k99199_k918!777777_S91777_k991999999______999999999 277_k99299_k928!777777_S92777_k992999999______99 ...9999999_m77_k99_m99_k9_m8!777777_S9_m777_k99_m999999______7|99|99|99|99|77_z78_m -------------------------- * UNIX is a Trademark of Bell Laboratories. September 28, 1987 2 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 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. _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 September 28, 1987 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 3 _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 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 _J9_i772999 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. September 28, 1987 4 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e _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- 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 9 _x_=2_J_^sin(_C_t)_d_t 9Here 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 September 28, 1987 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 5 surrounding 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: 9 _x _= 2 _J _^ sin ( _C _t ) _d_t 9 Special words can also be separated by braces { } and double quotes "...", which have special meanings that we will see soon. _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 _x782999_+_y9_k 9EQN 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 _x928. 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_=(_x782)_+1 9instead of the intended _y_=(_x782999)_+1 Subscripted subscripts and superscripted superscripts also work: x sub i sub 1 is _x9_i991 9 September 28, 1987 6 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 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 _x9_i772 9 Other than this special case, _s_u_b and _s_u_p group to the 9right, so _x _s_u_p _y _s_u_b _z means _x77_y99_z99, not _x78_y9999_z8. _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 _e78_i_C_t 9 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 _x9_i9917772 9with braces, but x sub i sub 1 sup 2 is _x999_i991782 which is rather different. Braces can occur within braces if necessary: September 28, 1987 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e 7 e sup {i pi sup {rho +1}} is 9 _e78_i_J7_K_+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 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 999999 2_c77778_a_+_b99______99_=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 999999 sin(_x)77778_A_+_B99____________ 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 9is99999 _J77778-_b78299999___99 instead of -_b78_J77729_9999999. The rules which decide which opera- 8 _E_Q_N _U_s_e_r_'_s _G_u_i_d_e tion 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 9 _a_+_b_+99999_a_x782999_+_b_x_+_c77778199________________ 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} is