eqn
Format mathematical equations for troff
TLDR
Process input with equations, saving the output for future typesetting with groff to PostScript
Typeset an input file with equations to PDF using the [me] macro package
SYNOPSIS
eqn [options] [file...]
or
command | eqn [options]
PARAMETERS
-dXY
Set delimiters for inline equations. X is the left delimiter and Y is the right. Equations within these delimiters will be processed. The default delimiters are '.EQ' and '.EN' on separate lines.
-ffont
Set the default font for mathematical expressions. This overrides the default font used by eqn.
-psize
Set the default point size for text within equations. This applies to normal text elements, not subscripts or superscripts.
-ssize
Set the default point size for subscripts and superscripts. This size is typically smaller than the main text size.
-Tdevice
Specify the output device for which the troff commands should be generated (e.g., ps for PostScript, dvi for DVI, latin1). This ensures correct formatting for the target display or printer.
--help
Display a help message with usage information and exit.
--version
Display version information about eqn and exit.
DESCRIPTION
eqn is a preprocessor for the troff (or groff) typesetting system, specifically designed for formatting mathematical equations.
It translates a specialized, human-readable equation language into troff commands. Users define equations using intuitive keywords (e.g., "a over b", "sum from i=1 to n", "x sub i sup 2"). eqn then handles the intricate details of positioning, sizing, and styling mathematical components like fractions, integrals, subscripts, superscripts, and special symbols.
Typically, eqn processes an input file containing a mix of text and equation definitions, sending its output (which is then valid troff input) to the troff or groff formatter for final rendering. It's a fundamental component of the classic Unix document preparation toolchain.
CAVEATS
eqn is a preprocessor; its output must be fed to a troff or groff formatter to produce viewable documents. While powerful for its time, modern document preparation often favors systems like LaTeX for complex mathematical typesetting, which offer more advanced features and easier workflow for many users. The equation syntax can be strict and requires attention to detail.
EQUATION SYNTAX OVERVIEW
eqn uses a highly intuitive, almost natural-language-like syntax for describing equations. Key elements include:
Fractions: a over b
Sums/Integrals: sum from i=1 to n X sub i, integral from 0 to infinity x dx
Subscripts/Superscripts: x sub i sup 2
Square Roots: sqrt{x}
Auto-sizing Parentheses: left( x over y right)
Support for Greek letters (alpha, beta), special symbols (approx, !=), and matrices (matrix { col { a } { c } } { col { b } { d } }).
Equations are typically enclosed within .EQ and .EN macros, or custom delimiters defined with the -d option.
INTEGRATION WITH GROFF
While eqn can be run as a standalone filter, it's most commonly used as a preprocessor within the groff suite. This is typically achieved by passing the -e option to groff (e.g., groff -e -t -mp filename). This tells groff to automatically pipe the document through eqn (and potentially other preprocessors like tbl for tables) before processing it with troff, simplifying the workflow for complex documents.
HISTORY
eqn was originally developed by Brian Kernighan and Lorinda Cherry at Bell Labs in 1974, as an integral part of the troff typesetting system. It was groundbreaking for its ability to easily typeset complex mathematical equations within documents at a time when such capabilities were rare. The GNU implementation, part of the groff suite, aims for compatibility with the original while also incorporating modern enhancements and bug fixes. It remains a classic example of declarative programming for document formatting.