EQN(7)
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 emptykeyorval. and ngl, a quotedkeycauses 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. inmandoc, 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β seepile.barβ draw a line over the preceding box.boldβ set the following box using bold font.ccolβ likecpile, but for use inmatrix.cpileβ likepile, 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 forbold.fontβ set the second argument using the font specified by the first argument; currently not recognized by themandoc(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β likelpile, but for use inmatrix.leftβ set the first argument as a big left delimiter before the second argument. as an optional third argument,rightcan follow. in that case, the fourth argument is set as a big right delimiter after the second argument.lpileβ likecpile, 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 subsequentpileoperators is that in a matrix, corresponding subequations in all columns line up horizontally, while eachpiledoes 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 byabovekeywords. sets the subequations one above the other, each of them centered. typically used to represent vectors in coordinate representation.rcolβ likerpile, but for use inmatrix.rightβ seeleft;rightcannot be used withoutleft. 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β likecpile, but subequations are right-justified.sizeβ set the second argument with the font size specified by the first argument; currently ignored bymandoc(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 asupclause immediately follows asubclause 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 atoclause immediately follows afromclause 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:
dyad,vec,under,bar,tilde,hat,dot,dotdotfat,roman,italic,bold,sizesub,supsqrtoverfrom,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
markandlineuptokens. mandoc just discards them, no cap π. and theback n,fwd n,up n, anddown ncommands? 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
- epel 10: mandoc 1.14.6-11.el10_1 Β· ISC AND BSD-2-Clause AND BSD-3-Clause
- epel 9: mandoc 1.14.6-2.el9 Β· ISC
- fedora 43: mandoc 1.14.6-12.fc43 Β· ISC AND BSD-2-Clause AND BSD-3-Clause
- fedora 44: mandoc 1.14.6-13.fc44 Β· ISC AND BSD-2-Clause AND BSD-3-Clause
- Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms