geqn(1) | User Commands | geqn(1) |
geqn - format mathematics (equations) for groff or MathML
geqn |
[-CNrR] [-d xy] [-f F] [-m n] [-M dir] [-p n] [-s n] [-T dev] [file ...] |
geqn |
--help |
geqn |
-v |
geqn |
--version |
The GNU implementation of eqn is part of the groff(7) document formatting system. geqn is a gtroff(1) preprocessor that translates expressions in its own language, embedded in roff(7) input files, into mathematical notation typeset by gtroff(1). It copies each file's contents to the standard output stream, translating each equation between lines starting with .EQ and .EN, or within a pair of user-specified delimiters. Normally, geqn is not executed directly by the user, but invoked by specifying the -e option to groff(1). While GNU eqn's input syntax is highly compatible with AT&T eqn, the output geqn produces cannot be processed by AT&T troff; GNU troff (or a troff implementing relevant GNU extensions) must be used. If no file operands are given on the command line, or if file is “-”, geqn reads the standard input stream.
Unless the -R option is used, geqn searches for the file eqnrc in the directories given with the -M option first, then in /usr/lib/amd64/groff/site-tmac, /usr/share/groff/site-tmac, and finally in the standard macro directory /usr/share/groff/1.23.0/tmac. If it exists and is readable, geqn processes it before any input files.
This man page primarily discusses the differences between GNU eqn and AT&T eqn. Most of the new features of the GNU eqn input language are based on TeX. There are some references to the differences between TeX and GNU eqn below; these may safely be ignored if you do not know TeX.
Three points are worth special note.
eqn input consists of tokens. Consider a form of Newton's second law of motion. The input
.EQ F = m a .EN
becomes Each of F, =, m, and a is a token. Spaces and newlines are interchangeable; they separate tokens but do not break lines or produce space in the output.
The following input characters not only separate tokens, but manage their grouping and spacing as well.
Tab and leader characters separate tokens as well as advancing the drawing position to the next tab stop, but are seldom used in eqn input. When they occur, they must appear at the outermost lexical scope. This roughly means that they can't appear within braces that are necessary to disambiguate the input; geqn will diagnose an error in this event. (See subsection “Macros” below for additional token separation rules.)
Other tokens are primitives, macros, an argument to either of the
foregoing, or components of an equation.
Primitives are fundamental keywords of the eqn language. They can configure an aspect of the preprocessor's state, as when setting a “global” font selection or type size (gfont and gsize), or declaring or deleting macros (“define” and undef); these are termed commands. Other primitives perform formatting operations on the tokens after them (as with fat, over, sqrt, or up).
Equation components include mathematical variables, constants, numeric literals, and operators. geqn remaps some input character sequences to groff special character escape sequences for economy in equation entry and to ensure that glyphs from an unstyled font are used; see groff_char(7).
+ | \[pl] | ' | \[fm] | |
- | \[mi] | <= | \[<=] | |
= | \[eq] | >= | \[>=] |
Macros permit primitives, components, and other macros to be collected and referred to by a single token. Predefined macros make convenient the preparation of eqn input in a form resembling its spoken expression; for example, consider cos, hat, inf, and lim.
GNU eqn imputes types to the components of an equation, adjusting the spacing between them accordingly. Recognized types are as follows; most affect spacing only, whereas the “letter” subtype of “ordinary” also assigns a style.
ordinary | character such as “1”, “a”, or “!” |
letter | character to be italicized by default |
digit | n/a |
operator | large operator such as “Σ” |
binary | binary operator such as “+” |
relation | relational operator such as “=” |
opening | opening bracket such as “(” |
closing | closing bracket such as “)” |
punctuation | punctuation character such as “,” |
inner | sub-formula contained within brackets |
suppress | component to which automatic spacing is not applied |
Two primitives apply types to equation components.
geqn sets up spacings and styles as if by the following commands.
chartype "letter" | abcdefghiklmnopqrstuvwxyz |
chartype "letter" | ABCDEFGHIKLMNOPQRSTUVWXYZ |
chartype "letter" | \[*a]\[*b]\[*g]\[*d]\[*e]\[*z] |
chartype "letter" | \[*y]\[*h]\[*i]\[*k]\[*l]\[*m] |
chartype "letter" | \[*n]\[*c]\[*o]\[*p]\[*r]\[*s] |
chartype "letter" | \[*t]\[*u]\[*f]\[*x]\[*q]\[*w] |
chartype "binary" | *\[pl]\[mi] |
chartype "relation" | <>\[eq]\[<=]\[>=] |
chartype "opening" | {([ |
chartype "closing" | })] |
chartype "punctuation" | ,;:. |
chartype "suppress" | ^~ |
geqn assigns all other ordinary and special roff characters, including numerals 0–9, the “ordinary” type. (The “digit” type is not used, but is available for customization.) In keeping with common practice in mathematical typesetting, lowercase, but not uppercase, Greek letters are assigned the “letter” type to style them in italics. The macros for producing ellipses, “...”, cdots, and ldots, use the “inner” type.
geqn supports without alteration the AT&T eqn primitives above, back, bar, bold, define, down, fat, font, from, fwd, gfont, gsize, italic, left, lineup, mark, matrix, ndefine, over, right, roman, size, sqrt, sub, sup, tdefine, to, under, and up.
The GNU extension primitives “type” and chartype are discussed in subsection “Spacing and typeface” above; “set” in subsection “Customization” below; and grfont and gbfont in subsection “Fonts” below. In the following synopses, X can be any character not appearing in the parameter thus bracketed.
accent { "^" }
<mstyle mathsize='big'>
.de Ca . ds 0s \ \Z'\\*(0s'\ \v'\\n(0du'\ \D'l \\n(0wu -\\n(0hu-\\n(0du'\ \v'\\n(0hu' .. .EQ special Ca "x \[mi] 3 \[pl] x" ~ 3 .EN
.de Bx .ds 0s \ \Z'\\h'1n'\\*[0s]'\ \v'\\n(0du+1n'\ \D'l \\n(0wu+2n 0'\ \D'l 0 -\\n(0hu-\\n(0du-2n'\ \D'l -\\n(0wu-2n 0'\ \D'l 0 \\n(0hu+\\n(0du+2n'\ \h'\\n(0wu+2n' .nr 0w +2n .nr 0d +1n .nr 0h +1n .. .EQ define box ' special Bx $1 ' box(foo) ~ "bar" .EN
define sum ! { type "operator" vcenter size +5 \(*S } !
GNU eqn extends the syntax of some AT&T eqn primitives, introducing one deliberate incompatibility.
When geqn generates gtroff input, the appearance of equations is controlled by a large number of parameters. They have no effect when generating MathML, which delegates typesetting to a MathML rendering engine. Configure these parameters with the set primitive.
set x_height 45
Available parameters are as follows; defaults are shown in parentheses. We intend these descriptions to be expository rather than rigorous.
<mstyle mathvariant='double-struck'>
In GNU eqn, macros can take arguments. A word defined by any of the define, ndefine, or tdefine primitives followed immediately by a left parenthesis is treated as a parameterized macro call: subsequent tokens up to a matching right parenthesis are treated as comma-separated arguments. In this context only, commas and parentheses also serve as token separators. A macro argument is not terminated by a comma inside parentheses nested within it. In a macro definition, $n, where n is between 1 and 9 inclusive, is replaced by the nth argument; if there are fewer than n arguments, it is replaced by nothing.
GNU eqn supports the predefined macros offered by AT&T eqn: and, approx, arc, cos, cosh, del, det, dot, dotdot, dyad, exp, for, grad, half, hat, if, inter, Im, inf, int, lim, ln, log, max, min, nothing, partial, prime, prod, Re, sin, sinh, sum, tan, tanh, tilde, times, union, vec, ==, !=, +=, ->, <-, <<, >>, and “...”. The lowercase classical Greek letters are available as alpha, beta, chi, delta, epsilon, eta, gamma, iota, kappa, lambda, mu, nu, omega, omicron, phi, pi, psi, rho, sigma, tau, theta, upsilon, xi, and zeta. Spell them with an initial capital letter (Alpha) or in full capitals (ALPHA) to obtain uppercase forms.
GNU eqn further defines the macros cdot, cdots, and utilde (all discussed above), dollar, which sets a dollar sign, and ldots, which sets an ellipsis on the text baseline.
geqn uses up to three typefaces to set an equation: italic (oblique), roman (upright), and bold. Assign each a groff typeface with the primitives gfont, grfont, and gbfont. The defaults are the styles I, R, and B (applied to the current font family). The chartype primitive (see above) sets a character's type, which determines the face used to set it. The “letter” type is set in italics; others are set in roman. Use the bold primitive to select an (upright) bold style.
--help displays a usage message, while -v and --version show version information; all exit afterward.
MathML is designed on the assumption that it cannot know the exact physical characteristics of the media and devices on which it will be rendered. It does not support control of motions and sizes to the same degree gtroff does.
As in its troff mode, geqn in MathML mode leaves the .EQ and .EN tokens in place, but emits nothing corresponding to delim delimiters. They can, however, be recognized as character sequences that begin with “<math>”, end with “</math>”, and do not cross line boundaries.
Tokens must be double-quoted in eqn input if they are not to be recognized as names of macros or primitives, or if they are to be interpreted by troff. In particular, short ones, like “pi” and “PI”, can collide with troff identifiers. For instance, the eqn command “gfont PI” does not select groff's Palatino italic font for the global italic face; you must use “gfont "PI"” instead.
Delimited equations are set at the type size current at the beginning of the input line, not necessarily that immediately preceding the opening delimiter.
Unlike TeX, eqn does not inherently distinguish displayed and inline equation styles; see the smallover primitive above. However, macro packages frequently define EQ and EN macros such that the equation within is displayed. These macros may accept arguments permitting the equation to be labeled or captioned; see the package's documentation.
eqn abuses terminology—its “equations” can be inequalities, bare expressions, or unintelligible gibberish. But there's no changing it now.
In nroff mode, lowercase Greek letters are rendered in roman instead of italic style.
In MathML mode, the mark and lineup features don't work. These could, in theory, be implemented with “<maligngroup>” elements.
In MathML mode, each digit of a numeric literal gets a separate “<mn></mn>” pair, and decimal points are tagged with “<mo></mo>”. This is allowed by the specification, but inefficient.
We first illustrate geqn usage with a trigonometric identity.
.EQ sin ( alpha + beta ) = sin alpha cos beta + cos alpha sin beta .EN
It can be convenient to set up delimiters if mathematical content will appear frequently in running text.
.EQ delim $$ .EN Having cached a table of logarithms, the property $ln ( x y ) = ln x + ln y$ sped calculations.
The quadratic formula illustrates use of fractions and radicals, and affords an opportunity to use the full space token ~.
.EQ x = { - b ~ \[+-] ~ sqrt { b sup 2 - 4 a c } } over { 2 a } .EN
Alternatively, we could define the plus-minus sign as a binary operator. Automatic spacing puts 0.06 em less space on either side of the plus-minus than ~ does, this being the difference between the widths of the medium_space parameter used by binary operators and that of the full space. Independently, we can define a macro “frac” for setting fractions.
.EQ chartype "binary" \[+-] define frac ! { $1 } over { $2 } ! x = frac(- b \[+-] sqrt { b sup 2 - 4 a c }, 2 a) .EN
“Typesetting Mathematics—User's Guide” (2nd edition), by Brian W. Kernighan and Lorinda L. Cherry, 1978, AT&T Bell Laboratories Computing Science Technical Report No. 17.
The TeXbook, by Donald E. Knuth, 1984, Addison-Wesley Professional. Appendix G discusses many of the parameters from section “Customization” above in greater detail.
groff_char(7), particularly subsections “Logical symbols”, “Mathematical symbols”, and “Greek glyphs”, documents a variety of special character escape sequences useful in mathematical typesetting.
groff(1), gtroff(1), gpic(1), groff_font(5)
2 July 2023 | groff 1.23.0 |