groff_out
Section: File Formats (5)
Updated: 202-0-28
Index
Return to Main Contents
Name
groff_out - GNU
roff
devic-independent page description language
.nr d-fallback 1
.nr d-fallback 1
Description
The fundamental operation of the GNU
troff formatter,
is the translation of the
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 devic-independent output language,
never to the language intended for use by document authors.
Devic-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 catc-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
As
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 devic-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 devic-independent output can be thought of
as a [lq]page description language[rq].
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 devic-independent output can be found in the
groff
sources at
src/:libs/:libdriver/:input.cpp.)
When Brian Kernighan designed AT&T
troff's
devic-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:
singl-letter commands or their arguments.
Some commands accept a subcommand as a first argument,
followed by one or more further arguments.
AT&T devic-independent
troff used whitespace minimally when producing output.
GNU
troff,
in contrast,
attempts to make its output more huma-readable.
The whitespace characters[em]tab,
space,
and newline[em]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/[lq]ASCII[rq] 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
[lq]
x~X[rq]
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~[lq]
u[rq]
(basic units),
and others
use~[lq]
s[rq]
(scaled points).
These are defined by the parameters specified in the device's
DESC
file;
see
and,
for more on scaling units,
and
Groff: The GNU Implementation of troff,
the
groff
Texinfo manual.
Colo-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 no-digit
character, which then is regarded as the first character of the next
argument or command.
Output structure
Devic-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 [lq]Device Control Commands[rq] below.
The parser for the devic-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
[lq]
x init[rq],
it prepares to handle commands in general.
Processing terminates when a
[lq]
x stop[rq]
command is encountered;
the last line of any
GNU
troff page description output always contains such a command.
Semantically,
the body is pag-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 [lq]job[rq])
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
-
[la]lin-break[ra]
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.
-
mmand ,C/id
-
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.
-
mmand ,c/c
-
Typeset the glyph of the ordinary
character~c.
The drawing position is not advanced.
-
mmand ,f/n
-
Select the font mounted at
position~n.
n~cannot
be negative.
-
mmand ,H/n
-
Horizontally move the drawing position to
n~basic
units from the left edge of the page.
n~cannot
be negative.
-
mmand ,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.
-
mmand ,m/scheme R][]componentR] ...]
-
Select the stroke color using the
components
in the color space
scheme.
Each
component
is an integer between 0 and @maxcolor].
The quantity of components and their meanings vary with each
scheme.
This command is a
groff
extension.
-
-
mmand ,mc/cyan magenta yellow
-
Use the CMY color scheme with components
cyan,
magenta,
and yellow.
-
mmand ,md/
-
Use the default color
(no components;
black in most cases).
-
mmand ,mg/gray
-
Use a grayscale color scheme with a component ranging
between 0 (black) and @maxcolor] (white).
-
mmand ,mk/cyan magenta yellow black
-
Use the CMYK color scheme with components
cyan,
magenta,
yellow,
and black.
-
mmand ,mr/red green blue
-
Use the RGB color scheme with components
red,
green,
and blue.
-
mmand ,N/n
-
Typeset the glyph with
index~n
in the current font.
n~is
normally a no-negative integer.
The drawing position is not advanced.
The
html
and
xhtml
devices use this command with
negative~n
to produce unbreakable space;
the absolute value of
n
is taken and interpreted in basic units.
-
mmand ,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.
See
v
and
V.
-
mmand ,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 a
p~command
must precede them.
-
mmand ,s/n
-
Set type size to
n
scaled points
(unit~z
in GNU
troff).
AT&T
troff used unscaled points
(p)
instead;
see section [lq]Compatibility[rq] below.
-
mmand ,t/xyzR]...
-
mmand ,t/xyzR]...] dumm-arg
Typeset word
xyz;
that is,
set a sequence of ordinary glyphs named
x,
y,
z,
...,
terminated by a space or newline;
an optional second integer argument is ignored
(this allows the formatter to generate an even number of arguments).
Each glyph is set at the current drawing position,
and the position is then advanced 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 the
C
command to emplace glyphs of special characters.
The
t~command
is a
groff
extension and is output only for devices whose
DESC
file contains the
tcommand
directive;
see
-
mmand ,u/n xyzR]...
-
mmand ,u/xyzR]...] dumm-arg
Typeset word
xyz
with track kerning.
As
t,
but after placing each glyph,
the drawing position is further advanced horizontally
by~n
basic units.
The
u~command
is a
groff
extension and is output only for devices whose
DESC
file contains the
tcommand
directive;
see
-
mmand ,V/n
-
Vertically move the drawing position to
n~basic
units from the top edge of the page.
n~cannot
be negative.
-
mmand ,v/n
-
Move the drawing position down
n
basic units.
AT&T
troff allowed negative
n;
GNU
troff does not produce such values,
but
groff's
output driver library handles them.
-
mmand ,w/
-
Indicate an inte-word space.
No action is performed;
the command is present to make the output more easily parsed.
Only inte-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.
See
h
and
H.
Graphics commands
Each graphics or drawing command in the page description language
starts with the letter
[lq]
D[rq],
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
[lq]
D[rq],
command may not be followed by another command on the same line
(apart from a comment),
so each
[lq]
D[rq]
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 [rs]D
escape sequence.
See subsection [lq]Drawing commands[rq] of
Unless indicated otherwise, each graphics command directly corresponds
to a similar
groff
@backslash]D
escape sequence; see
Unknown
D~commands
are assumed to be devic-specific.
Its arguments are parsed as strings; the whole information is then
sent to the postprocessor.
In the following command reference, the syntax element
[la]lin-break[ra]
means a
syntactical line break
as defined in subsection [lq]Separation[rq] above.
-
Dmultiarg hv1] hv2] ... hvn]@linebreak]
-
Draw -spline from current position to offset
then to offset
if given, etc., up to
This command takes a variable number of argument pairs; the current
position is moved to the terminal point of the drawn curve.
-
Da hv1] hv2]@linebreak]
-
Draw arc from current position to
with center at
then move the current position to the final point of the arc.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Dcommand hv1] hv2] ... hvn]@linebreak]
Draw a solid circle using the current fill color with diameter~d
(integer in basic units~u)
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.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Draw circle line with diameter~d
(integer in basic units~u)
with leftmost point at the current position; then move the current
position to the rightmost point of the circle.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Draw a solid ellipse in the current fill color with a horizontal
diameter of~h
and a vertical diameter of~v
(both integers in basic units~u)
with the leftmost point at the current position; then move to the
rightmost point of the ellipse.
This command is a GNU extension.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Draw an outlined ellipse with a horizontal diameter of~h
and a vertical diameter of~v
(both integers in basic units~u)
with the leftmost point at current position; then move to the
rightmost point of the ellipse.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
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 is
m.
The color components are specified as integer arguments between 0 and
@maxcolor].
The number of color components and their meaning vary for the
different color schemes.
These commands are generated by
GNU
troff's
escape sequences
[lq][rs]D[aq]F~...[aq][rq]
[rs]M
(with no other corresponding graphics commands).
No position changing.
This command is a GNU extension.
-
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Set fill color for solid drawing objects using the CMY color scheme,
having the 3~color components cyan, magenta, and yellow.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Set fill color for solid drawing objects to the default fill color value
(black in most cases).
No component arguments.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Set fill color for solid drawing objects to the shade of gray given by
the argument, an integer between 0 (black) and @maxcolor] (white).
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Set fill color for solid drawing objects using the CMYK color scheme,
having the 4~color components cyan, magenta, yellow, and black.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Set fill color for solid drawing objects using the RGB color scheme,
having the 3~color components red, green, and blue.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
The argument
n
must be an integer in the range -32767 to 32767.
-
- 0[<=]n[<=]1000
-
Set the color for filling solid drawing objects to a shade of gray,
where 0 corresponds to solid white, 1000 (the default) to solid black,
and values in between to intermediate shades of gray;
this command is
superseded by
[lq]DFg[rq].
- n<0 or n>1000
-
Set the filling color to the color that is currently being used for
the text and the outline, see command
m.
For example, the command sequence
-
-
mg 0 0 @maxcolor]
Df -1
-
sets all colors to blue.
This command is a GNU extension.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Draw line from current position to offset
(,fset/, ,h/)v
(integers in basic units~u);
then set current position to the end of the drawn line.
-
Dmultiarg hv1] hv2] ... hvn]@linebreak]
-
Draw a polygon line from current position to offset
from there to offset
etc., up to offset
and from there back to the starting position.
As the polygon is closed, the end of drawing is the starting point, so
the position doesn't change.
This command is a
groff
extension.
-
Dmultiarg hv1] hv2] ... hvn]@linebreak]
-
The same macro as the corresponding
Dp
command with the same arguments, but draws a solid polygon in the
current fill color rather than an outlined polygon.
This command is a GNU extension.
-
Dcommand hv1] hv2] ... hvn]@linebreak]
-
Set the current line thickness
to~n
(an integer in basic
units~u)
if
n>0;
if
n=0
select the smallest available line thickness;
otherwise,
the line thickness is made proportional to the type size,
which is the default.
This command is a GNU extension.
Device control commands
Each device control command starts with the letter
[lq]
x[rq],
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
[lq]
x[rq],
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
[lq]
x i[rq]
as
[lq]
x init[rq]
and the resolution command
[lq]
x r[rq]
as
[lq]
x res[rq].
In the following, the syntax element
[la]lin-break[ra]
means a
syntactical line break
as defined in subsection [lq]Separation[rq] above.
-
xcommand F@linebreak]
-
(ub control command)
Use
name
as the intended name for the current file in error reports.
This is useful for remembering the original file name when
groff
uses its internal piping mechanism.
The input file is not changed by this command.
This command is a GNU extension.
-
xcommand f@linebreak]
-
(ub control command)
Mount font position~n
(a no-negative integer) with font named~s
(a text word);
see
-
xcommand H@linebreak]
-
(ub control command)
Set character height to~n
(a positive integer in scaled points~z).
Classical troff
used the unit points (p)
instead;
see section [lq]Compatibility[rq] below.
-
xcommand i@linebreak]
-
(ub control command)
Initialize device.
This is the third command of the header.
-
xcommand p@linebreak]
-
(ub control command)
Parsed but ignored.
The classical documentation reads
pause device, can be
restarted.
-
xcommand r@linebreak]
-
(ub control command)
Resolution is~n,
while
h
is the minimal horizontal motion, and
v
the minimal vertical motion possible with this device; all arguments
are positive integers in basic units~u
per inch.
This is the second command of the header.
-
xcommand S@linebreak]
-
(ub control command)
Set slant to~n
degrees (an integer in basic units~u).
-
xcommand s@linebreak]
-
(ub control command)
Terminates the processing of the current file; issued as the last
command of devic-independent
troff output.
-
xcommand t@linebreak]
-
(ub control command)
Generate trailer information, if any.
In
groff,
this is currently ignored.
-
xcommand T@linebreak]
-
(ub control command)
Set the name of the output driver to
xxx,
a sequence of no-whitespace characters terminated by whitespace.
The possible names correspond to those of
groff's
-T
option.
This is the first command of the header.
-
xcommand u@linebreak]
-
(ub control command)
Configure underlining of spaces.
If
n
is~1, start underlining of spaces;
if
n
is~0, stop underlining of spaces.
This is needed for the
cu
request in
nroff
mode and is ignored otherwise.
This command is a GNU extension.
-
xcommand X@linebreak]
-
(ub control command)
Send 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, 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
@backslash]X.
Line continuation is a GNU extension.
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.
- ddc
-
Move right
dd
(exactly two decimal digits) basic units~u,
then print glyph with singl-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 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 hig-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.
Compatibility
The page description language of AT&T
troff was first documented in
[lq]A Typesette-independent TROFF[rq],
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.
- [bu]
-
AT&T devic-independent
troff's
quas-device independence is not yet implemented.
- [bu]
-
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 command
dpost),
has a resolution of only 720 units per inch,
suitable for printers of decades past.
groff's
ps
device has a resolution of 72000 units per inch.
In principle,
by implementing a rescaling mechanism,
groff
could come to emulate AT&T's
post
device.
- [bu]
-
While the -spline command
D[ti]
is reliably interpreted by
groff's
page description language parser,
some output drivers don't implement drawing routines for it.
- [bu]
-
In
GNU
troff, the argument to the commands
s
and
x~H
uses an implicit unit of scaled points
z
whereas AT&T
troff uses spacing points
p.
This isn't an incompatibility,
but a compatible extension,
for both units coincide for any device without a
sizescale
directive in its
DESC
file,
including all postprocessors from AT&T and
groff's
text
(nroff-mode)
devices.
groff
devices that use
sizescale
either do not exist for AT&T
troff have a different name,
or seem to have a different resolution.
So conflicts are very unlikely.
- [bu]
-
Temporarily, there existed some confusion on the positioning after the
D
commands that are
groff
extensions.
This has been clarified by establishing the classical rule for all
groff drawing commands:
-
The position after a graphic object has been drawn is at its end;
for circles and ellipses, the "end" is at the right side.
From this, the positionings specified for the drawing commands above
follow quite naturally.
The differences between
groff
and
classical troff
are documented in
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
devic-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
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 [lq]info groff[rq].
[lq]Troff User's Manual[rq]
by Joseph F. Ossanna,
1976
(revised by Brian W. Kernighan,
1992),
AT&T Bell Laboratories Computing Science Technical Report No. 54,
widely called simply [lq]CSTR~#54[rq],
documents the language,
device and font description file formats,
and devic-independent page description language
referred to collectively in
groff
documentation as
[lq]AT&T~
troff[rq].
[lq]A Typesette-independent TROFF[rq]
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 devic-independent page description language.
-
-
documents the
-Z
option and contains pointers to further
groff
documentation.
-
-
describes the
groff
language,
including its escape sequences and system of units.
-
-
details the scaling parameters of
DESC
(device description)
files.
-
-
generates the language documented here.
-
-
presents historical aspects and the general structure of
roff
systems.
-
-
enumerates differences between the output of AT&T
troff and that of GNU
troff.
-
-
is a viewer for devic-independent
troff output.
-
-
Roff.js
is a viewer for devic-independent
troff output written in JavaScript.
and
are
groff
postprocessors.
Index
- Name
-
- Description
-
- Background
-
- Syntax
-
- Argument units
-
- Output structure
-
- Command reference
-
- Comment command
-
- Simple commands
-
- Graphics commands
-
- Device control commands
-
- Legacy compressed encoding
-
- Compatibility
-
- Files
-
- Authors
-
- See also
-