eqn
format mathematics (equations) for groff or MathML
- Provided by: groff-base (Version: 1.24.1-1)
- Source: groff
- Report a bug
format mathematics (equations) for groff or MathML
eqn |
[-CNrR] [-d xy] [-f global-italic-font] [-m minimum-type-size] [-M eqnrc-directory] [-p super/subscript-size-reduction] [-s global-type-size] [-T device] [file ...] |
eqn |
--help |
eqn |
-v |
eqn |
--version |
The GNU implementation of eqn is part of the groff(7) document formatting system. eqn is a troff(1) preprocessor that translates expressions in its own language, embedded in roff(7) input, into mathematical notation typeset by troff(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, eqn 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 eqn 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 present, or if file is “-”, eqn reads the standard input stream.
Unless the -R option is used, eqn searches for the file eqnrc in the directories given with the -M option first, then in /usr/share/groff/site-tmac, and finally in the standard macro directory /usr/share/groff/1.24.1/tmac. If it exists and is readable, eqn processes it before any input.
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. Four points are worth note.
eqn input consists of tokens. Consider a form of Newton's second law of motion for constant mass. 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.
Beyond their primary functions, the following input characters separate tokens 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; eqn 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 (gifont and gsize), or declaring or deleting macros (“define” and undef); these are termed commands. Other primitives perform formatting operations on the tokens around them (as with fat, over, sqrt, or up).
Equation components include mathematical variables, constants, numeric literals, and operators. eqn 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 used together as 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 a type to each equation component, adjusting the space around it accordingly. Recognized types follow; 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.
eqn 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" | ^~ |
eqn 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.
eqn 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.
We describe the GNU extension primitives “type” and chartype in subsection “Spacing and typeface” above; “set” and “reset” in subsection “Customization” below; and gbfont, gifont, and grfont in subsection “Fonts” below. In the following synopses, X can be any character not appearing in the parameter thus bracketed.
accent { roman "^" }
<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 eqn generates troff 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” and “reset” primitives.
set x_height 45
Available parameters p 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.
eqn uses up to three typefaces to set an equation: italic (oblique), roman (upright), and bold (heavy). Assign each a groff typeface with the GNU extension primitives grfont, gifont, and gbfont. The defaults are the styles R, I, 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.
The string 10 stores the most recently formatted equation. The register MK stores the horizontal drawing position of the most recently assigned mark. Avoid using these names for any other purpose.
GNU eqn internally employs register, string, macro, and
diversion names beginning with the numeral 0. (AT&T
eqn used identifiers starting with the numeral 1.) A
document to be preprocessed with GNU eqn should not use any such
identifiers.
--help displays a usage message, while -v and --version show version information; all exit afterward.
eqn exits with status 0 on successful operation, status 2 if the program cannot interpret its command-line arguments, and status 1 if it encounters an error during operation.
MathML's design assumes 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 troff does.
As when producing troff output, eqn generates MathML that 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 “gifont PI” does not select the gropdf(1) or grops(1) device's Palatino italic font as the global italic face; you must use “gifont "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.
When producing terminal output, GNU eqn renders lowercase Greek letters in roman instead of italic style.
When producing MathML output, the mark and lineup features don't work. These could, in theory, be implemented with “<maligngroup>” elements.
When producing MathML output, 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 eqn 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 affords an opportunity to use fractions, radicals, and 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) documents a variety of special character escape sequences useful in mathematical typesetting. See subsections “Logical symbols”, “Mathematical symbols”, and “Greek glyphs” in particular.