| groff_out(5) | File Formats and Configurations | groff_out(5) |
groff_out - GNU roff device-independent page description language
The fundamental operation of the GNU troff formatter, gtroff(1), is the translation of the groff(7) input language into a series of instructions concerned primarily with placing glyphs or geometric objects at specific positions on a rectangular page. In the following discussion, the term command refers to this device-independent output language, never to the language intended for use by document authors. Device-independent output commands comprise several categories: glyph output; font, color, and text size selection; motion of the drawing position; page advancement; drawing of geometric primitives; and device extension commands, a catch-all for other operations. The last includes directives to start and stop output, identify the intended output device, and embed URL hyperlinks in supported output formats.
As groff(1) is a wrapper program around GNU troff and automatically calls an output driver, users seldom encounter this format under normal circumstances. groff offers the option -Z to inhibit postprocessing such that GNU troff's output is sent to the standard output stream just as it is when running GNU troff directly.
The purpose of device-independent output is to facilitate the development of postprocessors by providing a common programming interface for all devices. It is a distinct, and much simpler, language from that of the formatter, troff. The device-independent output can be thought of as a “page description language”.
In the following discussion, the term troff output describes what is output by GNU troff, while page description denotes the language accepted by the parser that interprets this output for the output drivers. This parser handles whitespace more flexibly than AT&T troff's implementation, recognizes a GNU extension to the language, and supports a legacy compressed encoding of a subset of commands for compatibility; otherwise, the formats are the same. (The parser for device-independent output can be found in the groff sources at src/libs/libdriver/input.cpp.)
When Brian Kernighan designed AT&T troff's device-independent page description language circa 1980, he had to balance readability and maintainability against severe constraints on file size and transmission speed to the output device. A decade later, when James Clark wrote groff, these constraints were no longer as tight.
roff's page description language is a sequence of tokens: single-letter commands or their arguments. Some commands accept a subcommand as a first argument, followed by one or more further arguments.
AT&T device-independent troff used whitespace minimally when producing output. GNU troff, in contrast, attempts to make its output more human-readable. The whitespace characters—tab, space, and newline—are always meaningful. They are never used to represent spacing in the document; that is done with horizontal (h, H) and vertical (v, V) positioning commands. Any sequence of space and/or tab characters is equivalent to a single space, separating commands from arguments and arguments from each other. Space is required only where omitting it would cause ambiguity. A line break separates commands. The comment character is a pound/hash sign (#), and marks the remainder of the line as a comment. A line comprising only whitespace after comment removal does nothing but separate input tokens.
For example, the relative horizontal motion command (h) and the command to write one glyph (c), each take a single argument; the former a signed integer, and the latter a printable ISO 646/“ASCII” character. A series of such commands could validly occur without spaces on an input line, but GNU troff follows each with a newline.
Some commands have a more complex syntax; the GNU troff extension command for writing glyph sequences (t) accepts a variable number of arguments. Those that draw geometric objects (D) or control the device (x) furthermore recognize subcommand arguments. Such commands thus must end with a newline. In GNU troff, the device extension (sub)command “x X” uniquely supports a line continuation syntax; a single input line contains any other.
Some commands accept integer arguments that represent measurements, but the scaling units of the formatter's language are never used. Most commands assume a scaling unit of “u” (basic units), and others use “s” (scaled points). These are defined by the parameters specified in the device's DESC file; see groff_font(5) and, for more on scaling units, groff(7) and Groff: The GNU Implementation of troff, the groff Texinfo manual. Color-related commands use dimensionless integers.
Note that single characters can have the eighth bit set, as can the names of fonts and special characters (this is, glyphs). The names of glyphs and fonts can be of arbitrary length. A glyph that is to be printed will always be in the current font.
A string argument is always terminated by the next whitespace character (space, tab, or newline); an embedded # character is regarded as part of the argument, not as the beginning of a comment command. An integer argument is already terminated by the next non-digit character, which then is regarded as the first character of the next argument or command.
Device-independent troff output is organized into three parts: a header, a body, and a trailer.
The task of the header is to set general device parameters. GNU troff guarantees that its header consists of the following three lines:
x T device
x res n h v
x init
with the parameters n, h, and v set as outlined in subsection “Device Control Commands” below. The parser for the device-independent page description language format is able to interpret additional whitespace and comments as well even in the header.
The body contains the document's visible content. Once an output driver interprets “x init”, it prepares to handle commands in general. Processing terminates when a “x stop” command is encountered; the last line of any GNU troff page description output always contains such a command.
Semantically, the body is page-oriented. The p command starts a new page. Positioning, writing, and drawing commands are performed within a page, so they cannot occur before the first p command. The output driver reckons absolute positioning (by the H and V commands) with respect to the current page's origin at the top left corner, and all other positioning relative to the drawing position on the page.
The trailer advances the drawing position to the bottom of the page and informs the device that the document (or “job”) has ended.
This section describes all page description output commands, both from AT&T troff as well as extension commands issued by GNU troff.
The commands in this subsection have a command code consisting of a single character, taking a fixed number of arguments. Most of them are commands for positioning and text writing. These commands are smart about whitespace. Optionally, syntactical space can be inserted before, after, and between the command letter and its arguments. All of these commands are stackable, i.e., they can be preceded by other simple commands or followed by arbitrary other commands on the same line. A separating syntactical space is necessary only when two integer arguments would clash or if the preceding argument ends with a string argument.
Each graphics or drawing command in the page description language starts with the letter “D”, followed by one or two characters that specify a subcommand; this is followed by a fixed or variable number of integer arguments that are separated by a single space character. A “D”, command may not be followed by another command on the same line (apart from a comment), so each “D” command is terminated by a syntactical line break.
GNU troff output follows AT&T troff's output conventions (no space between command and subcommand, all arguments are preceded by a single space character), but groff's parser allows optional space between the command letters and makes the space before the first argument optional. As usual, each space can be any sequence of tab and space characters.
Some graphics commands can take a variable number of arguments. In this case, they are integers representing a size measured in basic units u. The h arguments stand for horizontal distances where positive means right, negative left. The v arguments stand for vertical distances where positive means down, negative up. All these distances are offsets relative to the current location.
Each graphics command directly corresponds to a troff \D escape sequence. See subsection “Drawing commands” of groff(7).
Unless indicated otherwise, each graphics command directly corresponds to a similar groff \D escape sequence; see groff(7).
Unknown D commands are assumed to be device-specific. Its arguments are parsed as strings; the whole information is then sent to the postprocessor.
In the following command reference, the syntax element ⟨line-break⟩ means a syntactical line break as defined in subsection “Separation” above.
mg 0 0 65536
Df -1
This command is a GNU extension.
Each device control command starts with the letter “x”, followed by a space character (optional or arbitrary space or tab in GNU troff) and a subcommand letter or word; each argument (if any) must be preceded by a syntactical space. All “x”, commands are terminated by a syntactical line break; no device control command can be followed by another command on the same line (except a comment).
The subcommand is basically a single letter, but to increase readability, it can be written as a word, i.e., an arbitrary sequence of characters terminated by the next tab, space, or newline character. All characters of the subcommand word but the first are simply ignored. For example, GNU troff outputs the initialization command “x i” as “x init” and the resolution command “x r” as “x res”.
In the following, the syntax element ⟨line-break⟩ means a syntactical line break as defined in subsection “Separation” above.
AT&T troff primarily emitted glyphs by writing two digits (a motion) followed by a single character corresponding to a glyph. This syntax is less a command itself than a compressed encoding of the c and h commands.
In groff, arbitrary syntactical space around and within this command is allowed to be added. Only when a preceding command on the same line ends with an argument of variable length a separating space is obligatory. In classical troff, large clusters of these and other commands were used, mostly without spaces; this made such output almost unreadable.
For modern high-resolution devices, this command is impractical because the widths of the glyphs have a greater magnitude in basic units than two decimal digits can represent. In groff, it is used only for output to the X75, X75-12, X100, and X100-12 devices. For others, the commands t and u provide greater functionality and superior troubleshooting capacity.
The page description language of AT&T troff was first documented in “A Typesetter-independent TROFF”, by Brian Kernighan, and by 1992 the AT&T troff manual was updated to incorporate a description of it.
groff's page description language is compatible with this specification except in the following aspects.
The differences between groff and classical troff are documented in groff_diff(7).
James Clark wrote an early version of this document, which described only the differences between AT&T device-independent troff's page description language and that of GNU troff. It has since been expanded and revised by Bernd Warken and G. Branden Robinson.
Groff: The GNU Implementation of troff, by Trent A. Fisher
and Werner Lemberg, is the primary groff manual. You can browse it
interactively with “info groff”.
“Troff User's Manual” by Joseph F. Ossanna, 1976 (revised by Brian W. Kernighan, 1992), AT&T Bell Laboratories Computing Science Technical Report No. 54, widely called simply “CSTR #54”, documents the language, device and font description file formats, and device-independent page description language referred to collectively in groff documentation as “AT&T troff”.
“A Typesetter-independent TROFF” by Brian W. Kernighan, 1982, AT&T Bell Laboratories Computing Science Technical Report No. 97, (CSTR #97), provides additional insights into the device and font description file formats and device-independent page description language.
grodvi(1), grohtml(1), grolbp(1), grolj4(1), gropdf(1), grops(1), and grotty(1) are groff postprocessors.
| 2026-03-14 | groff 1.24.1 |