gtroff it is possible to divert text into a named
storage area. Due to the similarity to defining macros it is sometimes
said to be stored in a macro. This is used for saving text for output
at a later time, which is useful for keeping blocks of text on the same
page, footnotes, tables of contents, and indices.
For orthogonality it is said that
gtroff is in the top-level
diversion if no diversion is active (i.e., the data is diverted to the
Although the following requests can be used to create diversions, simply using an undefined diversion will cause it to be defined as empty. See Identifiers.
Begin a diversion. Like the
de request, it takes an argument of
a macro name to divert subsequent text into. The
appends to an existing diversion.
da without an argument ends the diversion.
The current partially filled line is included into the diversion. See
box request below for an example. Note that switching to
another (empty) environment (with the
ev request) avoids the
inclusion of the current partially filled line.
Begin (or append to) a diversion like the
requests. The difference is that
boxa do not
include a partially filled line in the diversion.
Before the box. .box xxx In the box. .br .box After the box. .br ⇒ Before the box. After the box. .xxx ⇒ In the box.
Before the diversion. .di yyy In the diversion. .br .di After the diversion. .br ⇒ After the diversion. .yyy ⇒ Before the diversion. In the diversion.
boxa without an argument ends the diversion.
Diversions may be nested. The read-only number register
contains the name of the current diversion (this is a string-valued
register). The read-only number register
.d contains the current
vertical place in the diversion. If not in a diversion it is the same
The high-water mark on the current page or in the current diversion. It corresponds to the text baseline of the lowest line on the page. This is a read-only register.
.tm .h==\n[.h], nl==\n[nl] ⇒ .h==0, nl==-1 This is a test. .br .sp 2 .tm .h==\n[.h], nl==\n[nl] ⇒ .h==40, nl==120
As can be seen in the previous example, empty lines are not considered
in the return value of the
After completing a diversion, the read-write number registers
dl contain the vertical and horizontal size of the diversion.
Note that only the just processed lines are counted: For the computation
dl, the requests
handled as if
box had been used – lines that have
been already stored in a macro are not taken into account.
.\" Center text both horizontally & vertically . .\" Enclose macro definitions in .eo and .ec .\" to avoid the doubling of the backslash .eo .\" macro .(c starts centering mode .de (c . br . ev (c . evc 0 . in 0 . nf . di @c ..
.\" macro .)c terminates centering mode .de )c . br . ev . di . nr @s (((\n[.t]u - \n[dn]u) / 2u) - 1v) . sp \n[@s]u . ce 1000 . @c . ce 0 . sp \n[@s]u . br . fi . rr @s . rm @c .. .\" End of macro definitions, restore escape mechanism .ec
Prevent requests, macros, and escapes from being interpreted when read into a diversion. Both escapes take the given text and transparently embed it into the diversion. This is useful for macros that shouldn’t be invoked until the diverted text is actually output.
\! escape transparently embeds text up to and including the
end of the line. The
\? escape transparently embeds text until
the next occurrence of the
\? escape. Example:
anything may not contain newlines; use
\! to embed
newlines in a diversion. The escape sequence
\? is also
recognized in copy mode and turned into a single internal code; it is
this code that terminates anything. Thus the following example
.nr x 1 .nf .di d \?\\?\\\\?\\\\\\\\nx\\\\?\\?\? .di .nr x 2 .di e .d .di .nr x 3 .di f .e .di .nr x 4 .f
Both escapes read the data in copy mode.
\! is used in the top-level diversion, its argument is
directly embedded into the
gtroff intermediate output. This can
be used for example to control a postprocessor that processes the data
before it is sent to the device driver.
\? escape used in the top-level diversion produces no output
at all; its argument is simply ignored.
Emit string directly to the
gtroff intermediate output
(subject to copy mode interpretation); this is similar to
at the top level. An initial double quote in string is stripped
off to allow initial blanks.
This request can’t be used before the first page has started – if you
get an error, simply insert
.br before the
output is ignored.
Use with caution! It is normally only needed for mark-up used by a postprocessor that does something with the output before sending it to the output device, filtering out string again.
Unformat the diversion specified by div in such a way that
ASCII characters, characters translated with the
request, space characters, and some escape sequences that were formatted
and diverted are treated like ordinary input characters when the
diversion is reread. It can be also used for gross hacks; for example,
the following sets register
n to 1.
.tr @. .di x @nr n 1 .br .di .tr @@ .asciify x .x
asciify cannot return all items in a diversion back
to their source equivalent, nodes such as
\N[...] will still
remain as nodes, so the result cannot be guaranteed to be a pure string.
See Copy-in Mode.
asciify, unformat the specified diversion. However,
unformat only unformats spaces and tabs between words.
Unformatted tabs are treated as input tokens, and spaces are stretchable
The vertical size of lines is not preserved; glyph information (font, font size, space width, etc.) is retained.