eqn: eqn: equations in knitroff documents

eqnR Documentation

eqn: equations in knitroff documents

Description

eqn, by Brian Kernighan and Lorinda Cherry, is the troff preprocessor for mathematics; its input reads much as the formula is spoken: ⁠x sup 2 over 2⁠. render_roff runs it for PDF and PostScript output. This page follows eqn(1) for groff 1.24.1.

Displays and inline equations

⁠.EQ⁠ ... ⁠.EN⁠

a displayed equation, centred by ms; ⁠.EQ L⁠ left-aligns it, ⁠.EQ I⁠ indents it, and a second argument is a label at the right margin, as in ⁠.EQ C (1)⁠.

⁠delim $$⁠

inside an ⁠.EQ⁠ ... ⁠.EN⁠, makes ⁠$⁠ delimit equations within the text: ⁠the mean $x bar$ is⁠. ⁠delim off⁠ stops it.

knitroff

in the ⁠"utf8"⁠ draft, displayed equations appear as their eqn source, because groff cannot set them on a terminal; inline equations appear between their delimiters.

Writing equations

eqn reads words separated by spaces; spaces themselves do not show. Braces group: ⁠e sup {i pi}⁠. Quoted text is set as it is, in roman: ⁠"for all"⁠. ⁠~⁠ is a space and ⁠^⁠ half a space. eqn sets letters in italic and digits, operators and function names such as ⁠sin⁠ in roman, and turns ⁠+ - = <= >=⁠ into their mathematical characters.

⁠x sub i⁠, ⁠x sup 2⁠ subscript, superscript; ⁠x sub i sup 2⁠ both
⁠a over b⁠ a fraction
⁠sqrt x⁠ square root
⁠sum from i=1 to n x sub i⁠ limits under and over ⁠sum⁠, ⁠prod⁠, ⁠int⁠, ⁠lim⁠, ⁠union⁠, ⁠inter⁠
⁠left ( a over b right )⁠ brackets that grow to fit: ( [ { | and their mates, and ⁠left floor⁠, ⁠ceiling⁠
⁠x bar⁠, ⁠x under⁠, ⁠x hat⁠, ⁠x dot⁠, ⁠x vec⁠ marks over or under x; also ⁠dotdot⁠, ⁠tilde⁠, ⁠dyad⁠
⁠pile { a above b above c }⁠ a vertical stack; ⁠lpile⁠, ⁠cpile⁠, ⁠rpile⁠ align it
⁠matrix { ccol { a above b } ccol { c above d } }⁠ a matrix of columns; ⁠lcol⁠, ⁠rcol⁠ align them
⁠mark⁠, ⁠lineup⁠ align successive equations at a point, such as their = signs
⁠roman⁠, ⁠italic⁠, ⁠bold⁠, ⁠fat⁠ the face of the next item; ⁠fat⁠ overstrikes to embolden
⁠size 12 x⁠, ⁠size +2 x⁠ type size of the next item
⁠up n⁠, ⁠down n⁠, ⁠fwd n⁠, ⁠back n⁠ move by n hundredths of an em
⁠define name "text"⁠ a macro: ⁠define var "x sub i"⁠; ⁠ndefine⁠ and ⁠tdefine⁠ only for nroff or troff
⁠gsize n⁠, ⁠gfont f⁠ the global type size and italic font of equations

Names eqn knows

Greek letters: ⁠alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu nu xi omicron pi rho sigma tau upsilon phi chi psi omega⁠; spelled with a capital (⁠Gamma⁠) or in capitals (⁠GAMMA⁠) for uppercase.

Symbols and functions: ⁠inf partial grad del prime approx times nothing ... half⁠, ⁠== != += -> <- << >>⁠, and ⁠sin cos tan sinh cosh tanh arc exp log ln lim max min det Re Im and for if⁠.

Added by GNU eqn: ⁠cdot cdots ldots utilde dollar⁠, and the primitives ⁠accent uaccent big smallover vcenter split nosplit opprime type chartype set reset grfont gifont gbfont⁠.

See Also

ms, troff, tbl. In a terminal: man eqn; and B. W. Kernighan and L. L. Cherry, A System for Typesetting Mathematics, Communications of the ACM 18 (1975), and their Typesetting Mathematics, User's Guide.

Examples

eq <- c(".EQ", "s sup 2 ~=~ 1 over {n - 1} sum from i=1 to n ( x sub i - x bar ) sup 2", ".EN")
cat(eq, sep = "\n")

knitroff documentation built on Oct. 16, 2026, 5:09 p.m.