groff_out(5)
groff_out(5) — GNU roff device-independent page description language 💅
okay bestie, welcome to groff_out(5) from the File Formats Manual ✨ this is the whole vibe of the GNU roff device-independent page description language, and we're gonna get into it fr fr.
🎀 Name 🎀
groff_out — GNU roff device-independent page description language 🫶
✨ Description ✨
The fundamental operation of the GNU troff formatter, troff(1), is translating 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.
🧚 Background 🧚
Since 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.
🌸 Syntax 🌸
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.
🎀 Argument units 🎀
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.
🦋 Output structure 🦋
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.
🔥 Command reference 🔥
This section describes all page description output commands, both from AT&T troff as well as extension commands issued by GNU troff.
💬 Comment command 💬
#anything⟨line-break⟩— Apply comment annotation. Ignore any characters from the#character up to the next newline. Each comment can be preceded by arbitrary syntactical space, and every command can be terminated by a comment.
✨ Simple commands ✨
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.
C id⟨white-space⟩— Typeset the glyph of the special character id. Trailing syntactical space is necessary to allow special character names of arbitrary length. The drawing position is not advanced.c c— Typeset the glyph of the ordinary character c. The drawing position is not advanced.f n— Select the font mounted at position n. n cannot be negative.H n— Horizontally move the drawing position to n basic units from the left edge of the page. n cannot be negative.h n— Move the drawing position right n basic units. AT&T troff allowed negative n; GNU troff does not produce such values, but groff's output driver library handles them.m scheme [component ...]— Select the stroke color using the components in the color space scheme. Each component is an integer between 0 and 65536. The quantity of components and their meanings vary with each scheme. This command is a groff extension.mc cyan magenta yellow— Use the CMY color scheme with components cyan, magenta, and yellow.md— Use the default color (no components; black in most cases).mg gray— Use a grayscale color scheme with a component ranging between 0 (black) and 65536 (white).mk cyan magenta yellow black— Use the CMYK color scheme with components cyan, magenta, yellow, and black.mr red green blue— Use the RGB color scheme with components red, green, and blue.
N n— Typeset the glyph with index n in the current font. n is normally a non-negative integer. The drawing position is not advanced. Thehtmlandxhtmldevices use this command with negative n to produce unbreakable space; the absolute value of n is taken and interpreted in basic units.n b a— Indicate a break. No action is performed; the command is present to make the output more easily parsed. The integers b and a describe the vertical space amounts before and after the break, respectively. GNU troff issues this command but groff's output driver library ignores it. SeevandV.p n— Begin a new page, setting its number to n. Each page is independent, even from those using the same number. The vertical drawing position is set to 0. All positioning, writing, and drawing commands are interpreted in the context of a page, so apcommand must precede them.s n— Set type size to n scaled points (unitzin GNU troff). AT&T troff used unscaled points (p) instead; see section “Compatibility” below.t xyz...⟨white-space⟩/t xyz... dummy-arg⟨white-space⟩— okay so this typesets the wordxyz, bestie: it sets a sequence of ordinary glyphs namedx,y,z,..., and it stops at a space or newline. That optional second integer arg? It gets ignored — it's just there so the formatter can generate an even number of arguments. Each glyph lands at the current drawing position, and then the position advances horizontally by the glyph's width. A glyph's width is read from its metrics in the font description file, scaled to the current type size, and rounded to a multiple of the horizontal motion quantum. Use theCcommand to emplace glyphs of special characters. Thetcommand is a groff extension and is output only for devices whoseDESCfile contains thetcommanddirective; seegroff_font(5). 💅u n xyz.../u xyz... dummy-arg⟨white-space⟩— this one typesets wordxyzwith track kerning. It's liket, but after placing each glyph, the drawing position gets further advanced horizontally bynbasic units. Theucommand is a groff extension and is output only for devices whoseDESCfile contains thetcommanddirective; seegroff_font(5). ✨V n— vertically move the drawing position tonbasic units from the top edge of the page. And nope,ncannot be negative. Not even a little. 🙈v n— move the drawing position downnbasic units. AT&T troff allowed negativen; GNU troff does not produce such values, but groff's output driver library handles them. So it's giving legacy tolerance, iykyk. 🦋w— indicate an inter-word space. No action is performed; the command is present to make the output more easily parsed. Only inter-word spaces on an output line (be they breakable or not) are thus described; those resulting from horizontal motion escape sequences are not. GNU troff issues this command but groff's output driver library ignores it. SeehandH. 🫶
🎨 Graphics commands 🎨
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. Periodt. 💅
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. Flexible parser behavior, slay. ✨
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. Mystery device energy, but make it parsed. 🌈
In the following command reference, the syntax element ⟨line-break⟩ means a syntactical line break as defined in subsection “Separation” above. 📌
D~ h1 v1 h2 v2 ... hn vn⟨line-break⟩— draw a B-spline from the current position to offset(h1, v1), then to offset(h2, v2)if given, etc., up to(hn, vn). This command takes a variable number of argument pairs; the current position is moved to the terminal point of the drawn curve. Curvy and iconic. 🌀Da h1 v1 h2 v2⟨line-break⟩— draw an arc from the current position to(h1, v1)+(h2, v2)with center at(h1, v1); then move the current position to the final point of the arc. Geometry bestie behavior. 🎀DC d⟨line-break⟩/DC d dummy-arg⟨line-break⟩— draw a solid circle using the current fill color with diameterd(integer in basic unitsu) with leftmost point at the current position; then move the current position to the rightmost point of the circle. An optional second integer argument is ignored (this allows the formatter to generate an even number of arguments). This command is a GNU extension. Solid circle, solid slay. ⭐Dc d⟨line-break⟩— draw a circle line with diameterd(integer in basic unitsu) with leftmost point at the current position; then move the current position to the rightmost point of the circle. Outline only, minimalist queen. 🦋DE h v⟨line-break⟩— draw a solid ellipse in the current fill color with a horizontal diameter ofhand a vertical diameter ofv(both integers in basic unitsu) with the leftmost point at the current position; then move to the rightmost point of the ellipse. This command is a GNU extension. Ellipse emoji energy 🫶De h v⟨line-break⟩— draw an outlined ellipse with a horizontal diameter ofhand a vertical diameter ofv(both integers in basic unitsu) with the leftmost point at current position; then move to the rightmost point of the ellipse. Outline mode activated. ✨DF color-scheme [component ...]⟨line-break⟩— set fill color for solid drawing objects using different color schemes; the analogous command for setting the color of text, line graphics, and the outline of graphic objects ism. The color components are specified as integer arguments between0and65536. The number of color components and their meaning vary for the different color schemes. These commands are generated by GNU troff's escape sequences\D'F ...'and\M(with no other corresponding graphics commands). No position changing. This command is a GNU extension. COLOR SCHEME MOMENT 🌈DFc cyan magenta yellow⟨line-break⟩— set fill color for solid drawing objects using the CMY color scheme, having the 3 color componentscyan,magenta, andyellow. 💛DFd ⟨line-break⟩— set fill color for solid drawing objects to the default fill color value (black in most cases). No component arguments. Default era. 🎀DFg gray⟨line-break⟩— set fill color for solid drawing objects to the shade of gray given by the argument, an integer between0(black) and65536(white). Gray-scale glam. 🩶DFk cyan magenta yellow black⟨line-break⟩— set fill color for solid drawing objects using the CMYK color scheme, having the 4 color componentscyan,magenta,yellow, andblack. 🖤DFr red green blue⟨line-break⟩— set fill color for solid drawing objects using the RGB color scheme, having the 3 color componentsred,green, andblue. RGB bestie!! 💅
Df n⟨line-break⟩— the argumentnmust be an integer in the range-32767to32767. Respect the range, okay? 🙈0≤n≤1000— set the color for filling solid drawing objects to a shade of gray, where0corresponds to solid white,1000(the default) to solid black, and values in between to intermediate shades of gray; this command is superseded byDFg. Old-school gray behavior. 🎚️n<0orn>1000— set the filling color to the color that is currently being used for the text and the outline, see commandm. For example, the command sequence
mg 0 0 65536
Df -1
sets all colors to blue. Blue era activated, no cap. 🦋
This command is a GNU extension. ✨
Dl h v⟨line-break⟩— draw a line from the current position to offset(h, v)(integers in basic unitsu); then set the current position to the end of the drawn line. Line go brrr. 📏Dp h1 v1 h2 v2 ... hn vn⟨line-break⟩— draw a polygon line from the current position to offset(h1, v1), from there to offset(h2, v2), etc., up to offset(hn, vn), and from there back to the starting position. For historical reasons, the position is changed by adding the sum of all arguments with odd index to the current horizontal position and the even ones to the vertical position. Although this doesn't make sense it is kept for compatibility. This command is a groff extension. Historical nonsense, but make it iconic. 🫠DP h1 v1 h2 v2 ... hn vn⟨line-break⟩— the same macro as the correspondingDpcommand with the same arguments, but draws a solid polygon in the current fill color rather than an outlined polygon. The position is changed in the same way as withDp. This command is a GNU extension. Solid polygon upgrade, periodt. 🔥Dt n⟨line-break⟩— set the current line thickness ton(an integer in basic unitsu) ifn>0; ifn=0select the smallest available line thickness; otherwise, the line thickness is made proportional to the type size, which is the default. For historical reasons, the horizontal position is changed by adding the argument to the current horizontal position, while the vertical position is not changed. Although this doesn't make sense, it is kept for compatibility. This command is a GNU extension. Thickness with lore. 💜
🛠️ Device control commands 🛠️
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). One command per line, bestie. 💅
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. Readable but still chaotic. Obsessed. 🎀
In the following, the syntax element ⟨line-break⟩ means a syntactical line break as defined in subsection “Separation” above. ✨
xFname⟨line-break⟩ — (Filename control command) bestie, this one just tells the machinery "hey, call the current file name" so error reports actually say something useful 💖 Super handy for remembering the original file name when groff does its internal piping thing. The input file itself is not changed by this command. This command is a GNU extension, iykyk.xfn s⟨line-break⟩ — (font control command) mounts font position n (a non-negative integer) with the font named s (a text word); go peek atgroff_font(5)for the deets.xHn⟨line-break⟩ — (Height control command) sets the character height to n (a positive integer in scaled pointsz). Classical troff used the unit points (p) instead — see the Compatibility section below, it's giving lore ✨xi⟨line-break⟩ — (init control command) initializes the device. It's literally the third command of the header, main character energy of the header tbh 👑xp⟨line-break⟩ — (pause control command) parsed but ignored, no cap. The classical documentation reads "pause device, can be restarted" — so it's basically a vibe that got cancelled 💀xrn h v⟨line-break⟩ — (resolution control command) resolution is n, h is the minimal horizontal motion, and v the minimal vertical motion possible with this device; all arguments are positive integers in basic unitsuper inch. This is the second command of the header, okurrr 🎀xSn⟨line-break⟩ — (Slant control command) sets the slant to n degrees (an integer in basic unitsu). Slanty. Iconic. ✨xs⟨line-break⟩ — (stop control command) terminates the processing of the current file; it's issued as the last command of device-independent troff output. The final goodbye, periodt 🦋xt⟨line-break⟩ — (trailer control command) generates trailer information, if any. In groff, this is currently ignored — it's the "we'll circle back" of commands 🙈xTxxx⟨line-break⟩ — (Typesetter control command) sets the name of the output driver to xxx, a sequence of non-whitespace characters terminated by whitespace. The possible names correspond to those of groff's-Toption. This is the first command of the header, so like, the opening act 🌟xun⟨line-break⟩ — (underline control command) configures underlining of spaces. If n is1, start underlining of spaces; if n is0, stop underlining of spaces. This is needed for thecurequest in nroff mode and is ignored otherwise. This command is a GNU extension 💅xXanything⟨line-break⟩ — (X-escape control command) sends the string anything uninterpreted to the device. If the line following this command starts with a+character, this line is interpreted as a continuation line in the following sense: the+is ignored, but a newline character is sent instead to the device, and the rest of the line is sent uninterpreted. The same applies to all following lines until the first character of a line is not a+character. This command is generated by the groff escape sequence\X. Line continuation is a GNU extension. Lowkey the wildest one here fr fr 🔥
🧚 Legacy compressed encoding
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 — it's giving "we ran out of storage in 1980" 😭
ddc— Move right dd (exactly two decimal digits) basic unitsu, then print the glyph with single-letter name c.
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 is a separating space 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. Slay, honestly 🫶
🦋 Compatibility
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. History lesson complete, bestie 📚
groff's page description language is compatible with this specification except in the following aspects. Buckle up:
- AT&T device-independent troff's quasi-device independence is not yet implemented. 🙈
- The printing hardware of the early 1980s differed from today's. groff's output device names also differ from those of AT&T troff. For example, the PostScript device in AT&T troff,
post(implemented by the driver commanddpost), has a resolution of only720units per inch, suitable for printers of decades past. groff'spsdevice has a resolution of72000units per inch. In principle, by implementing a rescaling mechanism, groff could come to emulate AT&T'spostdevice. Glow-up of the century ngl 💅 - While the B-spline command
D~is reliably interpreted by groff's page description language parser, some output drivers don't implement drawing routines for it. So like, it parses but maybe nobody draws it 😭 - In GNU troff, the argument to the commands
sandx Huses an implicit unit of scaled pointszwhereas AT&T troff uses spacing pointsp. This isn't an incompatibility, but a compatible extension, for both units coincide for any device without asizescaledirective in itsDESCfile, including all postprocessors from AT&T and groff's text (nroff-mode) devices. groff devices that usesizescaleeither do not exist for AT&T troff have a different name, or seem to have a different resolution. So conflicts are very unlikely. We love a low-stakes edge case 🎀 - The drawing position after the commands
Dp,DP, andDt, are processed is illogical. Since old versions of GNU troff had this wart, we've retained it for compatibility, but may change it in the future. Wrap these drawing commands with the\Zescape sequence to both overcome the illogical positioning and keep your input working consistently regardless of the wart's presence in the implementation. A wart! In the wild! 🐸
The differences between groff and classical troff are documented in groff_diff(7). Go read it, bestie, it's the receipts.
🍓 Files
/usr/share/groff/1.24.2/font/devname/DESC— describes the output device name.
👑 Authors
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. Shoutout to the legends 🫶✨
🌈 See also
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. It's giving required reading 💜
"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". Cute nickname, honestly 🎀
"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. The sequel we didn't know we needed 📖
groff(1)— documents the-Zoption and contains pointers to further groff documentation.groff(7)— describes the groff language, including its escape sequences and system of units.groff_font(5)— details the scaling parameters ofDESC(device description) files.troff(1)— generates the language documented here.roff(7)— presents historical aspects and the general structure of roff systems.groff_diff(7)— enumerates differences between the output of AT&T troff and that of GNU troff.gxditview(1)— is a viewer for device-independent troff output.Roff.js— ⟨https://github.com/Alhadis/Roff.js/⟩ is a viewer for device-independent troff output written in JavaScript. JS representation!! 🦋grodvi(1),grohtml(1),grolbp(1),grolj4(1),gropdf(1),grops(1), andgrotty(1)are groff postprocessors.
Okay that's the whole page, bestie, you made it to the end 🎉 This was groff_out(5) from groff 1.24.2, dated 2026-10-01 — go forth and format, ily 💖✨👑
📦 where this page comes from
- alpine 3.24: groff-doc 1.24.2-r0 · GPL-3.0-or-later
- Copyright 1989-2024 Free Software Foundation, Inc
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms