EQN(7)

πŸ“¦
version 1.14.6 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

okay bestie sit DOWN because we're doing EQN(7) β€” straight outta the Miscellaneous Information Manual β€” and it's literally the whole eqn language reference for mandoc. it's long, so buckle up, part 1 starts now 🌸

✨ NAME ✨

eqn β€” the eqn language reference for mandoc


πŸ¦‹ DESCRIPTION πŸ¦‹

so the eqn language is an equation-formatting language. you use it inside mdoc(7) and man(7) Unix manual pages. and listen β€” it describes the structure of an equation, not its mathematical meaning. no cap. this manual is describing the eqn language that the mandoc(1) utility actually accepts, which lines up with the Second Edition eqn specification (peep β€œSEE ALSO” for the references, iykyk).

an equation kicks off with an input line containing exactly the characters .EQ, can have a whole bunch of input lines in it, and wraps up with an input line containing exactly the characters .EN. equivalently, you can drop an equation right in the middle of a single text input line by wrapping it in the equation delimiters you defined with the delim statement. πŸ’…

the equation grammar goes like this β€” and heads up, quoted strings in here are case-sensitive literals in the input:

eqn     : box | eqn box
box     : text
        | "{" eqn "}"
        | "define" text text
        | "ndefine" text text
        | "tdefine" text text
        | "gfont" text
        | "gsize" text
        | "set" text text
        | "undef" text
        | "sqrt" box
        | box pos box
        | box mark
        | "matrix" "{" [col "{" list "}"]* "}"
        | pile "{" list "}"
        | font box
        | "size" text box
        | "left" text eqn ["right" text]
col     : "lcol" | "rcol" | "ccol" | "col"
text    : [^space\"]+ | \".*\"
pile    : "lpile" | "cpile" | "rpile" | "pile"
pos     : "over" | "sup" | "sub" | "to" | "from"
mark    : "dot" | "dotdot" | "hat" | "tilde" | "vec"
        | "dyad" | "bar" | "under"
font    : "roman" | "italic" | "bold" | "fat"
list    : eqn
        | list "above" eqn
space   : [\^~ \t]

okay so white-space is made up of the space, tab, circumflex, and tilde characters. it's required to delimit tokens that consist of alphabetic characters, and it gets straight-up ignored everywhere else. braces and quotes also delimit tokens, periodt. if you're inside a quoted string tho, those space characters are retained. quoted strings also don't get scanned for keywords, glyph names, or expansion of definitions. and if you wanna print a literal quote character, you can prepend it with a backslash or express it with the \(dq escape sequence. πŸŽ€

subequations can be wrapped in braces so you can pass them as arguments to operation keywords, which overrides the standard operation precedence. braces nest, btw. and to set a brace verbatim, it has to be enclosed in quotes. 🫢

now here's the glow-up list β€” these text terms get translated into a rendered glyph, if that glyph is available:

  • alpha, beta, chi, delta, epsilon, eta, gamma, iota, kappa, lambda, mu, nu, omega, omicron, phi, pi, psi, rho, sigma, tau, theta, upsilon, xi, zeta β€” the lowercase greek girlies πŸ›οΈ
  • DELTA, GAMMA, LAMBDA, OMEGA, PHI, PI, PSI, SIGMA, THETA, UPSILON, XI β€” the uppercase icons πŸ‘‘
  • inter (intersection), union (union), prod (product), int (integral), sum (summation), grad (gradient), del (vector differential), times (multiply), cdot (center-dot), nothing (zero-width space), approx (approximately equals), prime (prime), half (one-half), partial (partial differential), inf (infinity)
  • and the symbols: >> (much greater), << (much less), <- (left arrow), -> (right arrow), +- (plus-minus), != (not equal), == (equivalence), <= (less-than-equal), and >= (more-than-equal)

and the character escape sequences documented in mandoc_char(7) can be used too, bestie. πŸ’œ


🌈 the control statements 🌈

these are the control statements you've got available:

  • define β€” replace all occurrences of a key with a value. its syntax is literally:
define key cvalc

the first character of the value string, c, is used as the delimiter for the value val. this is what lets you do arbitrary enclosure of terms (not just quotes), like:

define foo 'bar baz'
define foo cbar bazc
it is an error to have an empty key or val. and ngl, a quoted key causes errors in some eqn implementations, so it should not be considered portable. it is not expanded for replacements. definitions may refer to other definitions β€” those get evaluated recursively when text replacement happens, and not when the definition is created. 😭

definitions can create arbitrary strings, for example, the following is a legal construction:

define foo 'define'
foo bar 'baz'

self-referencing definitions will raise an error. the ndefine statement is a synonym for define, while tdefine is discarded. πŸ’€

  • delim β€” this statement takes a string argument consisting of two bytes, to be used as the opening and closing delimiters for equations in the middle of text input lines. conventionally, the dollar sign is used for both delimiters, like:
.EQ
delim $$
.EN
An equation like $sin pi = 0$ can now be entered
in the middle of a text input line.

the special statement delim off temporarily disables previously declared delimiters, and delim on reenables them. πŸ”₯

  • gfont β€” set the default font of subsequent output. its syntax is:
gfont font

in mandoc, this value is discarded. πŸ™ˆ

  • gsize β€” set the default size of subsequent output. its syntax is:
gsize [+|-]size

the size value should be an integer. if it's prepended by a sign, the font size is changed relative to the current size.

  • set β€” set an equation mode. in mandoc, both arguments are thrown away. its syntax is:
set key val

the key and val are not expanded for replacements. this statement is a GNU extension.

  • undef β€” unset a previously-defined key. its syntax is:
define key

once invoked, the definition for key is discarded. the key is not expanded for replacements. this statement is also a GNU extension.


πŸ”₯ operation keywords πŸ”₯

the operation keywords have these semantics, and no I did not skip any:

  • above β€” see pile.
  • bar β€” draw a line over the preceding box.
  • bold β€” set the following box using bold font.
  • ccol β€” like cpile, but for use in matrix.
  • cpile β€” like pile, but with slightly increased vertical spacing.
  • dot β€” set a single dot over the preceding box.
  • dotdot β€” set two dots (dieresis) over the preceding box.
  • dyad β€” set a dyad symbol (left-right arrow) over the preceding box.
  • fat β€” a synonym for bold.
  • font β€” set the second argument using the font specified by the first argument; currently not recognized by the mandoc(1) eqn parser. 😭
  • from β€” set the following box below the preceding box, using a slightly smaller font. used for sums, integrals, limits, and the like.
  • hat β€” set a hat (circumflex) over the preceding box.
  • italic β€” set the following box using italic font.
  • lcol β€” like lpile, but for use in matrix.
  • left β€” set the first argument as a big left delimiter before the second argument. as an optional third argument, right can follow. in that case, the fourth argument is set as a big right delimiter after the second argument.
  • lpile β€” like cpile, but subequations are left-justified.
  • matrix β€” followed by a list of columns enclosed in braces. all columns need to have the same number of subequations. the columns are set as a matrix. the difference compared to multiple subsequent pile operators is that in a matrix, corresponding subequations in all columns line up horizontally, while each pile does vertical spacing independently.
  • over β€” set a fraction. the preceding box is the numerator, the following box is the denominator.
  • pile β€” followed by a list of subequations enclosed in braces, the subequations being separated by above keywords. sets the subequations one above the other, each of them centered. typically used to represent vectors in coordinate representation.
  • rcol β€” like rpile, but for use in matrix.
  • right β€” see left; right cannot be used without left. to set a big right delimiter without a big left delimiter, the following construction can be used:
left "" box right delimiter
  • roman β€” set the following box using the default font.
  • rpile β€” like cpile, but subequations are right-justified.
  • size β€” set the second argument with the font size specified by the first argument; currently ignored by mandoc(1). by prepending a plus or minus sign to the first argument, the font size can be selected relative to the current size.
  • sqrt β€” set the square root of the following box.
  • sub β€” set the following box as a subscript to the preceding box.
  • sup β€” set the following box as a superscript to the preceding box. as a special case, if a sup clause immediately follows a sub clause as in
mainbox sub subbox sup supbox

both are set with respect to the same mainbox, that is, supbox is set above subbox. ✨

  • tilde β€” set a tilde over the preceding box.
  • to β€” set the following box above the preceding box, using a slightly smaller font. used for sums and integrals and the like. as a special case, if a to clause immediately follows a from clause as in
mainbox from frombox to tobox

both are set below and above the same mainbox.

  • under β€” underline the preceding box.
  • vec β€” set a vector symbol (right arrow) over the preceding box.

🧚 grouping & precedence, aka the vibe check 🧚

the binary operations from, to, sub, and sup group to the right, that is,

mainbox sup supbox sub subbox

is the same as

mainbox sup {supbox sub subbox}

and different from

{mainbox sup supbox} sub subbox

by contrast, over groups to the left. 😀

in the following list, earlier operations bind more tightly than later operations:

  1. dyad, vec, under, bar, tilde, hat, dot, dotdot
  2. fat, roman, italic, bold, size
  3. sub, sup
  4. sqrt
  5. over
  6. from, to

and that's where part 1 wraps up β€” part 2 is literally right behind me, keep scrolling bestie πŸ’–

πŸ’– COMPATIBILITY πŸ’–

okay bestie, this section is the ✨ tea ✨ on how mandoc's eqn vibes with the troff eqn implementation (and yes, GNU troff counts too). they're mostly the same girlies but there are some little differences, so listen up πŸ”₯

  • The text string \" is read as a literal quote over in troff. but in mandoc? nope, it's treated as a comment. literally different meanings, so watch out πŸ‘€
  • In troff, the circumflex and tilde white-space symbols map to fixed-width spaces. in mandoc though, those characters are just synonyms for the space character. same energy, different font drama πŸ’…
  • The troff implementation of eqn lets you align your equations using the mark and lineup tokens. mandoc just discards them, no cap 😭. and the back n, fwd n, up n, and down n commands? also ignored. they're giving ghosted fr fr πŸ’€

🌸 SEE ALSO 🌸

go read these next, they're the whole friend group 🫢

and the academic icons themselves πŸ“š:

  • Brian W. Kernighan and Lorinda L. Cherry, β€œSystem for Typesetting Mathematics”, Communications of the ACM, 18, pp. 151–157, March, 1975.
  • Brian W. Kernighan and Lorinda L. Cherry, Typesetting Mathematics, User's Guide, 1976.
  • Brian W. Kernighan and Lorinda L. Cherry, Typesetting Mathematics, User's Guide (Second Edition), 1978.

⭐ HISTORY ⭐

so the eqn utility, which is a preprocessor for troff, was originally written by Brian W. Kernighan and Lorinda L. Cherry way back in 1975. iconic behavior honestly πŸ‘‘

then the GNU reimplementation of eqn, which is part of the GNU troff package, dropped in 1989 courtesy of James Clark. slay.

and the eqn component of mandoc(1)? that got added in 2011, a lil late to the party but she showed up and ate πŸ’…βœ¨


πŸ’œ AUTHORS πŸ’œ

this eqn reference was written by Kristaps Dzonsons <kristaps@bsd.lv>. give her her flowers fr fr πŸŽ€


okay that's the whole page bestie!! this one's from the Debian crew, dated January 10, 2020, and it lives at EQN(7). go forth and typeset some math, you main character πŸ¦‹πŸ’–βœ¨
πŸ“¦ where this page comes from