A System for Typesetting Mathematics Brian W. Kernighan and Lorinda L. Cherry _A_B_S_T_R_A_C_T This paper describes the design and implemen- tation of a system for typesetting mathematics. The language has been designed to be easy to learn and to use by people (for example, secretaries and mathematical typists) who know neither mathematics nor typesetting. Experience indicates that the language can be learned in an hour or so, for it has few rules and fewer exceptions. For typical expressions, the size and font changes, position- ing, line drawing, and the like necessary to print according to mathematical conventions are all done automatically. For example, the input 9 sum from i=0 to infinity x sub i = pi over 2 9 produces 9999 _i=078_R78oo999_x_i=99277_J9_ 9 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 ter- minal with forward and reverse half-line motions. The system interfaces directly with text format- ting programs, so mixtures of text and mathematics may be handled simply. This paper is a revision of a paper origi- nally published in CACM, March, 1975. 978 9 August 3, 1987 - 2 - _1. _I_n_t_r_o_d_u_c_t_i_o_n ``Mathematics is known in the trade as _d_i_f_f_i_c_u_l_t, or _p_e_n_a_l_t_y, _c_o_p_y because it is slower, more difficult, and more expensive to set in type than any other kind of copy normally occurring in books and journals.'' [1] One difficulty with mathematical text is the multiplicity of characters, sizes, and fonts. An expression such as 99 _x__->_J_/27lim (tan _x)8sin 2_x9 _= 1 9requires an intimate mixture of roman, italic and greek 7777777777777777777777777777777777777777777777777777778 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 tradi- tional methods is still an essentially manual opera- tion. A second difficulty is the two dimensional charac- ter of mathematics, which the superscript and limits in the preceding example showed in its simplest form. August 3, 1987 - 3 - This is carried further by _a0_+9999_a1_+9999_a2_+99_a3_+ _. _. _.77_b39____________________777_b29__________________________777_b19________________________________ and still further by