This is groff.info, produced by makeinfo version 6.7 from groff.texi.

This manual documents GNU 'troff' version 1.24.1.

     Copyright © 1994-2018 Free Software Foundation, Inc.
     Copyright © 2018-2026 G. Branden Robinson

     Permission is granted to copy, distribute and/or modify this
     document under the terms of the GNU Free Documentation License,
     Version 1.3 or any later version published by the Free Software
     Foundation; with no Invariant Sections, no Front-Cover Texts, and
     no Back-Cover Texts.  A copy of the license is included in the
     section entitled "GNU Free Documentation License".
INFO-DIR-SECTION Typesetting
START-INFO-DIR-ENTRY
* Groff: (groff).               The GNU roff document formatting system.
END-INFO-DIR-ENTRY


File: groff.info,  Node: Line Continuation,  Next: Page Layout,  Prev: Line Layout,  Up: GNU troff Reference

5.16 Line Continuation
======================

When filling is enabled, input and output line breaks generally do not
correspond.  The 'roff' language therefore distinguishes input and
output line continuation.

 -- Escape sequence: \<RET>
     '\<RET>' (a backslash immediately followed by a newline) suppresses
     the effects of that newline in the input.  The next input line thus
     retains the classification of its predecessor as a control or text
     line.  '\<RET>' is useful for managing line lengths in the input
     during document maintenance; you can even break an input line in
     the middle of a word, request invocation, macro call, or escape
     sequence.  Input line continuation is invisible to the formatter,
     with two exceptions: the '|' operator recognizes the new input line
     (*note Numeric Expressions::), and the input line counter register
     '.c' increments.  '\RET' is interpreted even in copy mode.(1)
     (*note Line Continuation-Footnote-1::)

          .ll 50n
          .de I
          .  ft I
          .  nop \\$*
          .  ft
          ..
          Our film class watched
          .I The Effect of Gamma Rays on Man-in-the-Moon
          Marigolds. \" whoops, the input line wrapped
          .br
          .I My own opus begins on line \n[.c] \
          and ends on line \n[.c].
              => Our film class watched The Effect of Gamma Rays on
              => Man-in-the-Moon Marigolds.
              => My own opus begins on line 11 and ends on line 12.

 -- Escape sequence: \c
 -- Register: \n[.int]
     '\c' continues an output line.  Nothing after it on the input line
     is formatted.  In contrast to '\<RET>', a line after '\c' remains a
     new input line, so a control character is recognized at its
     beginning.  The visual results depend on whether filling is
     enabled; see *note Manipulating Filling and Adjustment::.

        * If filling is enabled, a word interrupted with '\c' is
          continued with the text on the next input text line, without
          an intervening space.

               This is a te\c
               st.
                   => This is a test.

        * If filling is disabled, the next input text line after '\c' is
          handled as a continuation of the same input text line.

               .nf
               This is a \c
               test.
                   => This is a test.

     An intervening control line that causes a break overrides '\c',
     flushing out the pending output line in the usual way.

     The '.int' register interpolates a positive value only if the
     pending output line has been continued with '\c'; this datum is
     associated with the environment (*note Environments::).(2)  (*note
     Line Continuation-Footnote-2::)


File: groff.info,  Node: Line Continuation-Footnotes,  Up: Line Continuation

   (1) *Note Copy Mode::.

   (2) Historically, the '\c' escape sequence has proven challenging to
characterize.  Some sources say it "connects the next input text" (to
the input line on which it appears); others describe it as
"interrupting" text, on the grounds that a text line is interrupted
without breaking, perhaps to inject a request invocation or macro call.


File: groff.info,  Node: Page Layout,  Next: Page Control,  Prev: Line Continuation,  Up: GNU troff Reference

5.17 Page Layout
================

The formatter permits configuration of the page length and page number.

 -- Request: .pl [length]
 -- Request: .pl +length
 -- Request: .pl -length
 -- Register: \n[.p]
     Change (increase or decrease) the page length per the numeric
     expression LENGTH.  The default scaling unit is 'v'.  If LENGTH is
     invalid, GNU 'troff' emits a warning in category 'number'.  If
     LENGTH is absent or invalid, '11i' is assumed.  If LENGTH is
     nonpositive, GNU 'troff' emits a warning in category 'range' and
     sets the page length to the device's vertical motion quantum;
     recall *note Motion Quanta::.

     The read-only register '.p' interpolates the current page length.

 -- Request: .pn num
 -- Request: .pn +num
 -- Request: .pn -num
 -- Register: \n[.pn]
     Change (increase or decrease) the page number of the _next_ page
     per the numeric expression NUM.  If NUM is invalid, GNU 'troff'
     emits a warning in category 'number' and ignores the request.
     Without an argument, 'pn' is ignored.

     The read-only register '.pn' interpolates NUM if set by 'pn' on the
     current page, or the current page number plus 1.

   The formatter offers special support for typesetting headers and
footers, collectively termed "titles".  Titles have an independent line
length, and their placement on the page is not restricted.

 -- Request: .tl '''left'''center'''right'''
     Format an output line as a title consisting of LEFT, CENTER, and
     RIGHT, each aligned accordingly.  The delimiter need not be a
     neutral apostrophe: 'tl' accepts the same delimiters as most escape
     sequences; see *note Delimiters::.  If not used as the delimiter,
     any "page number character" character is replaced with the current
     page number; the default is '%'; see the the 'pc' request below.
     Without an argument, 'tl' is ignored.  'tl' writes the title line
     immediately, ignoring any partially collected line.

     It is not an error to omit delimiters after the first.  For
     example, '.tl /Thesis' is interpreted as '.tl /Thesis///': it sets
     a title line comprising only the left-aligned word 'Thesis'.

 -- Request: .lt [length]
 -- Request: .lt +length
 -- Request: .lt -length
 -- Register: \n[.lt]
     Change (increase or decrease) the line length used by titles per
     the numeric expression LENGTH.  The default scaling unit is 'm'.
     The formatter's default title length is '6.5i'.  If LENGTH is
     invalid, GNU 'troff' emits a warning in category 'number' and
     ignores the request.  If LENGTH is nonpositive, GNU 'troff' emits a
     warning in category 'range' and sets the title line length to the
     device's horizontal motion quantum; recall *note Motion Quanta::.
     The title length is is associated with the environment (*note
     Environments::).  If LENGTH is omitted, GNU 'troff' restores the
     environment's previous title length.

     The read-only register '.lt' interpolates the title line length.

 -- Request: .pc [char]
     Set the page number character to CHAR.  With no argument, the page
     number character is disabled.  'pc' does not affect the
     register '%'.

   The following example exercises title features.

     .lt 50n
     This is my partially collected
     .tl 'Isomers 2023'%'Dextrose Edition'
     line.
         => Isomers 2023             1        Dextrose Edition
         => This is my partially collected line.

   We most often see titles used in page header and footer traps.  *Note
Traps::.


File: groff.info,  Node: Page Control,  Next: Using Fonts,  Prev: Page Layout,  Up: GNU troff Reference

5.18 Page Control
=================

Discretionary page breaks can prevent the unwanted separation of
content.  A new page number takes effect during page ejection; see *note
The Implicit Page Trap::.

 -- Request: .bp [page-number]
 -- Request: .bp +page-number
 -- Request: .bp -page-number
 -- Register: \n[%]
     Break the page and change (increase or decrease) the next page
     number per the numeric expression PAGE-NUMBER.  If PAGE-NUMBER is
     invalid, GNU 'troff' emits a warning in category 'number' and
     ignores the argument.  This request causes a break.  A page break
     advances the vertical drawing position to the bottom of the page,
     springing traps.  *Note Page Location Traps::.  'bp' has effect
     only if invoked within the top-level diversion.(1)  (*note Page
     Control-Footnote-1::) This request is incorrectly documented in the
     AT&T 'troff' manual as having a default scaling unit of 'v'.

     The register '%' interpolates the page number.

          .de BP
          '  bp \" schedule page break once current line is output
          ..

     *Caution:* Interpolations occur before formatting operations.  The
     process of filling, breaking, and adjusting a line can change the
     page number.  '%' is a register like any other, not a placeholder
     that is rewritten after the line it appears on is formatted.
     Consider, for example, an extremely long page number at the end of
     the last line on the page; numbers aren't hyphenated, so the word
     containing the page number might break the line and the page,
     causing the reported page number to lag by one.  This sequencing
     also means that interpolating the '%' register inside a diversion
     (such as a footnote) records the page number at the time the
     diversion is populated, not when it is output.

 -- Request: .ne [space]
     Force a page break if insufficient vertical space is available (it
     asserts "needed" space).  'ne' tests the distance to the next page
     location trap; see *note Page Location Traps::, and breaks the page
     if that amount is less than SPACE.  The default scaling unit is
     'v'.  If SPACE is invalid, GNU 'troff' emits a warning in category
     'number' and ignores the argument.  If SPACE is not specified, '1v'
     is assumed.

     We can require space for at least the first two output lines of a
     paragraph, preventing its first line from being isolated at the
     page bottom.

          .ne 2v
          Considering how common illness is,
          how tremendous the spiritual change that it brings,
          how astonishing,
          when the lights of health go down,
          the undiscovered countries that are then disclosed,
          what wastes and deserts of the soul a slight attack
          of influenza brings to view,
          what precipices and lawns sprinkled with bright flowers
          a little rise of temperature reveals,
          what ancient and obdurate oaks are uprooted in us
          in the act of sickness,
          how we go down into the pit of death
          and feel the waters of annihilation
          close above our heads.\|.\|.
          .sp
          Virgina Woolf, \[lq]On Being Ill\[rq], 1926

     This method is reliable only if no output line is pending when 'ne'
     is invoked.  When macro packages are used, this is often not the
     case: their paragraphing macros perform the break.  You may need to
     experiment with placing the 'ne' after the paragraphing macro, or
     'br' and 'ne' before it.

     'ne' is also useful to force grouping of section headings with
     their subsequent paragraphs, or tables with their captions and/or
     explanations.  Macro packages often use 'ne' with diversions to
     implement keeps and displays; see *note Diversions::.  They may
     also offer parameters for widow and orphan management.

 -- Request: .sv [space]
 -- Request: .os
     'sv' requires vertical space as 'ne' does, but also saves it for
     later output by the 'os' request.  If SPACE is available before the
     next page location trap, it is output immediately.  Both requests
     ignore a partially collected line, taking effect at the next break.
     'sv' and 'os' ignore no-space mode (recall *note Manipulating
     Spacing::).  While the 'sv' request allows negative values for
     SPACE, 'os' ignores them.  The default scaling unit is 'v'.  If
     SPACE is not specified, '1v' is assumed.

 -- Register: \n[nl]
     'nl' interpolates the vertical drawing position as of the most
     recently typeset output line.  It does not necessarily (and often
     does not) represent that of the pending output line, because the
     formatter does not determine the position of its baseline until it
     is output; recall *note Manipulating Spacing::.  Assigning a value
     to 'nl' sets the vertical drawing position in advance of further
     modifications to baseline positioning arising from alterations to
     type size, changes to vertical spacing, or application of extra
     pre- or post-vertical spacing.

     When the formatter starts, the transition to the first page has not
     yet happened--'nl' is negative.  If you plant a page location trap
     at vertical position '0' (idiomatically to format a header), you
     can assign a negative value to 'nl' to spring that trap even if the
     page has already started (*note Page Location Traps::).

          .de HD
          .  sp
          .  tl ''Goldbach Solution''
          .  sp
          ..
          .
          First page.
          .bp
          .wh 0 HD \" plant header trap at top of page
          .nr nl (-1)
          Second page.
              => First page.
              =>
              => (blank lines elided)
              =>
              =>                         Goldbach Solution
              =>
              => (blank lines elided)
              =>
              => Second page.

     Without resetting 'nl' to a negative value, the trap just planted
     would be active beginning with the _next_ page, not the current
     one.

     *Note Diversions::, for a comparison of 'nl' with the '.h' and '.d'
     registers.


File: groff.info,  Node: Page Control-Footnotes,  Up: Page Control

   (1) *Note Diversions::.


File: groff.info,  Node: Using Fonts,  Next: Manipulating Type Size and Vertical Spacing,  Prev: Page Control,  Up: GNU troff Reference

5.19 Using Fonts
================

In digital typography, a "font" is a collection of characters in a
specific typeface that a device can render as glyphs at a desired
size.(1)  (*note Using Fonts-Footnote-1::) A 'roff' formatter can change
typefaces at any point in the text.  The basic faces are a set of
"styles" combining upright and slanted (italic or oblique) shapes with
normal and heavy stroke weights: 'R', 'I', 'B', and 'BI'--these stand
for roman, italic, bold, and bold-italic.  For linguistic text, GNU
'troff' groups typefaces into "families" containing each of these
styles.(2)  (*note Using Fonts-Footnote-2::) A "text font" is thus often
a family combined with a style, but it need not be: consider the 'ps'
and 'pdf' devices' 'ZCMI' (Zapf Chancery Medium italic)--often, no other
style of Zapf Chancery Medium is provided.  On typesetters, at least one
"special font" is available, comprising "unstyled" glyphs for
mathematical operators and other purposes.

   Like the AT&T 'troff' formatter, GNU 'troff' does not itself load or
manipulate a digital font file;(3) (*note Using Fonts-Footnote-3::)
instead it works with a "font description file" that characterizes it,
including its glyph repertoire and the "metrics" (dimensions) of each
glyph.(4)  (*note Using Fonts-Footnote-4::) This information permits the
formatter to accurately place glyphs with respect to each other.  Before
using a font description, the formatter associates it with a "mounting
position", a place in an ordered list of available typefaces.  So that a
document need not be strongly coupled to a specific font family, in GNU
'troff' an output device can associate a style in the abstract sense
with a mounting position.  Thus the default family can be combined with
a style dynamically, producing a "resolved font name".  A user-specified
font name that combines family and style, or refers to a font that is
not a member of a family, is already "resolved".

   Fonts often have trademarked names, and even Free Software fonts can
require renaming upon modification.  'groff' maintains a convention that
a device's serif font family is given the name 'T' ("Times"), its
sans-serif family 'H' ("Helvetica"), and its monospaced family 'C'
("Courier").  Historical inertia has driven 'groff''s font identifiers
to short uppercase abbreviations of font names, as with 'TR', 'TI',
'TB', 'TBI', and a special font 'S'.

   The default family used with abstract styles is initially 'T'.
Typically, abstract styles are arranged in the first four mounting
positions in the order shown above.  The default mounting position, and
therefore style, is always '1' ('R').  By issuing appropriate formatter
instructions, you can override these defaults before your document
writes its first glyph.

   Terminals cannot change font families and lack special fonts.  They
support style changes by overstriking, or by altering ISO 6429/ECMA-48
"graphic renditions" (character cell attributes).

* Menu:

* Selecting Fonts::
* Font Families::
* Font Positions::
* Characters and Glyphs::
* Character Classes::
* Special Fonts::
* Artificial Fonts::
* Ligatures and Kerning::
* Italic Corrections::
* Dummy Characters::


File: groff.info,  Node: Using Fonts-Footnotes,  Up: Using Fonts

   (1) Terminals and some typesetters have fonts that render at only one
or two sizes.  As examples, take the 'groff' 'lj4' device's Lineprinter,
and 'lbp''s Courier and Elite faces.

   (2) Font designers prepare families such that the styles share
esthetic properties.

   (3) Historically, the fonts 'troff's dealt with were not Free
Software or, as with the Graphic Systems C/A/T, did not even exist in
the digital domain.

   (4) *Note Font Description File Format::.


File: groff.info,  Node: Selecting Fonts,  Next: Font Families,  Up: Using Fonts

5.19.1 Selecting Fonts
----------------------

We use "font" to refer to any of several means of identifying a
typeface: by its mounting position ('3'), by its identifier ('TB'), or
by an abstract style ('B') to be combined with the default family.

 -- Request: .ft [font]
 -- Escape sequence: \ff
 -- Escape sequence: \f(fn
 -- Escape sequence: \f[font]
 -- Register: \n[.fn]
     The 'ft' request selects the typeface FONT.  If the argument is
     absent or 'P', it selects the previously used typeface; if there is
     none, the formatter ignores the request.  If FONT is an integer,
     the formatter interprets it as a mounting position; the font
     mounted there is selected.  If that position refers to an abstract
     style, GNU 'troff' combines it with the default family (see 'fam'
     and '\F' below) to make a resolved font name.  If FONT is 'DESC',
     if the mounting position is not an abstract style and no font is
     mounted there, or the mounting position is negative, GNU 'troff'
     ignores the request.(1)  (*note Selecting Fonts-Footnote-1::)

     If FONT matches a style name, it is combined with the default
     family to make a resolved font name.  If not, FONT is assumed to be
     resolved already.

     The resolved font name is subject to translation (see request 'ftr'
     below).  Next, the (possibly translated) font name's mounting
     position is looked up; if not mounted, FONT is sought on the file
     system as a font description file and, if located, automatically
     mounted at the next available position (see register '.fp' below).
     If the font was mounted using an identifier different from its font
     description file name (see request 'fp' below), that file name is
     then sought.  If a font description file for the resolved font name
     is not found, GNU 'troff' emits a warning in category 'font' and
     ignores the request.

     The '\f' escape sequence is similar, accepting names or mounting
     positions of one character F, two characters FN, or arbitrary
     length FONT.  '\f[]' selects the previous font.  The syntax form
     '\fP' is supported for backward compatibility, and '\f[P]' for
     consistency.

          eggs, bacon,
          .ft I
          spam,
          .ft
          and sausage.
          .br
          eggs, bacon, \fIspam,\fP and sausage.
              => eggs, bacon, spam, and sausage.
              => eggs, bacon, spam, and sausage.

     The currently and previously selected fonts are properties of the
     environment (*note Environments::).

     The read-only string-valued register '.fn' contains the resolved
     font name of the selected font.  Copy its value to a string to save
     it for later use.

          .ds saved-font \n[.fn]
          ... text involving many font changes ...
          .ft \*[saved-font]

     GNU 'troff' does not tokenize '\f' when reading it; the escape
     sequence updates the environment.  It thus can be used in requests
     that expect a single-character argument.  We can assign a font to a
     margin character as follows (*note Miscellaneous::).

          .mc \f[I]x\f[]

 -- Request: .ftr f [g]
     Translate font name F to G.  Where the '\f' escape sequence, the
     'F' and 'S' conditional expression operators, and the 'ft', 'ul',
     'bd', 'cs', 'tkf', 'special', 'fspecial', 'fp', or 'sty' requests
     refer to F, GNU 'troff' uses G instead.  Omit G or repeat F as G to
     untranslate F.  F and G need not be mounted fonts.

     You can obtain a report of font translations defined by 'ftr' on
     the standard error stream with the 'pftr' request.  *Note
     Debugging::.

 -- Request: .fzoom font [zoom]
 -- Register: \n[.zoom]
     Set magnification of mounted FONT to factor ZOOM, a multiplier
     applied to the type size in thousandths.  ZOOM must be
     non-negative.  'fzoom' applies to glyphs when they are formatted,
     altering a font's apparent size in relation to others.  A missing
     or zero ZOOM is treated as '1000'--no magnification.  FONT must be
     a resolved font name, not an abstract style.

     Font magnification is transparent to some aspects of GNU 'troff'.
     A change of the zoom factor affects scaling of glyph sizes,
     inter-word and inter-sentence spaces, and kerning adjustments on
     the output device, but _not_ vertical spacing.  It is not reflected
     in registers that report the requested or current type size, or the
     minimum inter-word and supplemental inter-sentence space sizes.  It
     _is_ reflected in measurements of formatted output: the horizontal
     drawing position register 'hp', interpolation of the '\w' escape
     sequence, and the registers updated by that escape sequence or the
     formatting of a glyph in the environment.  *Note Environments::.

     'fzoom' can harmonize the apparent cap-heights of fonts from
     different families when formatted on the same baseline at the same
     type size.

          .fzoom HR 900
          .fzoom CR 1150
          .fzoom PR 950
          Times, \F[H]Helvetica\F[], \F[C]Courier\F[],
          and \F[P]Palatino\F[].
          .sp
          M\F[H]M\F[C]M\F[P]M

     The zoom factor of the currently selected font is available in the
     read-only register '.zoom'.  It interpolates zero if there is no
     magnification.


File: groff.info,  Node: Selecting Fonts-Footnotes,  Up: Selecting Fonts

   (1) It also emits a warning in category 'font' or 'range', as
appropriate.  *Note Warnings::.


File: groff.info,  Node: Font Families,  Next: Font Positions,  Prev: Selecting Fonts,  Up: Using Fonts

5.19.2 Font Families
--------------------

To accommodate the wide variety of fonts available, GNU 'troff'
distinguishes "font families" and "font styles".  A resolved font name
is the catenation of a font family and a style.  Selecting an abstract
style causes GNU 'troff' to combine it with the default font family.

   You can thus compose a document using abstract styles exclusively for
its body or running text--selecting a specific family only for titles or
examples, for instance--and change the default family on the command
line.

 -- Request: .fam [family]
 -- Register: \n[.fam]
 -- Escape sequence: \Ff
 -- Escape sequence: \F(fm
 -- Escape sequence: \F[family]
     Set the default font family, used in combination with abstract
     styles to construct a resolved font name, to FAMILY (one-character
     name F, two-character name FM).  If no argument is given, GNU
     'troff' selects the previous font family; if there are none, it
     falls back to the device's default(1) (*note Font
     Families-Footnote-1::) or its own ('T').

     The '\F' escape sequence works similarly.  In disanalogy to '\f',
     '\FP' makes 'P' the default family.  Use '\F[]' to select the
     previous default family.  The default font family is available in
     the read-only string-valued register '.fam'; it is associated with
     the environment (*note Environments::).

          spam,     \" startup defaults are T (Times) R (roman)
          .fam H    \" make Helvetica the default family
          spam,     \" family H + style R = HR
          .ft B     \" family H + style B = HB
          spam,
          .ft CR    \" Courier roman (default family not changed)
          spam,
          .ft       \" back to Helvetica bold
          spam,
          .fam T    \" make Times the default family
          spam,     \" family T + style B = TB
          .ft AR    \" font AR (not a style)
          baked beans,
          .ft R     \" family T + style R = TR
          and spam.

     GNU 'troff' does not tokenize '\F' when reading it; the escape
     sequence updates the environment.  It thus can be used in requests
     that expect a single-character argument.  We can assign a font
     family to a margin character as follows (*note Miscellaneous::).

          .mc \F[P]x\F[]

 -- Request: .sty pos style
 -- Register: \n[.sty]
     Associate an abstract style STYLE with mounting position POS, which
     must be a non-negative integer.  Applying the requests 'cs', 'bd',
     'tkf', 'uf', or 'fspecial' to an abstract style affects the member
     of the default family corresponding to that style.

     The default family can be set with the '-f' option (*note Groff
     Options::).  The 'styles' command in the 'DESC' file controls which
     font positions (if any) are initially associated with abstract
     styles rather than fonts.

     *Caution:* The STYLE argument is not validated.  Errors may occur
     later, when the formatter attempts to construct a resolved font
     name, or format a character for output.

          .nr BarPos \n[.fp]
          .sty \n[.fp] Bar
          .fam Foo
          .ft \n[BarPos]
          .tm .f=\n[.f]
          A
              error-> error: no font family named 'Foo' exists
              error-> .f=41
              error-> error: cannot format glyph: no current font

     When an abstract style has been selected, the read-only
     string-valued register '.sty' interpolates its name; this datum is
     associated with the environment (*note Environments::).  Otherwise,
     '.sty' interpolates nothing.


File: groff.info,  Node: Font Families-Footnotes,  Up: Font Families

   (1) *Note DESC File Format::.


File: groff.info,  Node: Font Positions,  Next: Characters and Glyphs,  Prev: Font Families,  Up: Using Fonts

5.19.3 Font Positions
---------------------

To support typeface indirection through abstract styles, and for
compatibility with AT&T 'troff', the formatter maintains a list of font
"positions" at which fonts required by a document are "mounted".  An
output device's description file 'DESC' typically configures a set of
pre-mounted fonts; see *note Device and Font Description Files::.  A
font need not be explicitly mounted before it is selected; GNU 'troff'
will search 'GROFF_FONT_PATH' for a file name matching the identifier
and mount it on demand.

 -- Request: .fp pos id [font-description-file-name]
 -- Register: \n[.f]
 -- Register: \n[.fp]
     Mount a font under the name ID at mounting position POS, a
     non-negative integer.  When the formatter starts up, it reads the
     output device's description to mount an initial set of faces, and
     selects font position 1.  Position 0 is unused by default.  Unless
     the FONT-DESCRIPTION-FILE-NAME argument is given, ID should be the
     name of a font description file stored in a directory corresponding
     to the selected output device.  GNU 'troff' does not traverse
     directories to locate the font description file.

     The optional third argument enables font names to be aliased, which
     can be necessary in compatibility mode since AT&T 'troff' syntax
     affords no means of identifying fonts with names longer than two
     characters, like 'TBI' or 'ZCMI', in a font selection escape
     sequence.  *Note Compatibility Mode::.  You can also alias fonts on
     mounting for convenience or abstraction.  (See below regarding the
     '.fp' register.)

          .fp \n[.fp] SC ZCMI
          Send a \f(SChand-written\fP thank-you note.
          .fp \n[.fp] Emph TI
          .fp \n[.fp] Strong TB
          Are \f[Emph]these names\f[] \f[Strong]comfortable\f[]?

     'DESC', 'P', and non-negative integers are not usable as font
     identifiers.

     You can obtain a report of occupied font mounting positions
     (whether configured by the 'DESC' file, the 'fp' request, or
     automatic mounting) on the standard error stream with the 'pfp'
     request.  *Note Debugging::.

     The position of the currently selected font (or abstract style) is
     available in the read-only register '.f'.  It is associated with
     the environment (*note Environments::).

     Copy the value of '.f' to another register to save it for later
     use.

          .nr sF \n(.f
          ... text involving many font changes ...
          .ft \n(sF

     The index of the next (non-zero) free font position is available in
     the read-only register '.fp'.  Fonts not listed in the 'DESC' file
     are automatically mounted at position '\n[.fp]' when selected with
     the 'ft' request or '\f' escape sequence.  When mounting a font at
     a position explicitly with the 'fp' request, this same practice
     should be followed, although GNU 'troff' does not enforce this
     strictly.


File: groff.info,  Node: Characters and Glyphs,  Next: Character Classes,  Prev: Font Positions,  Up: Using Fonts

5.19.4 Characters and Glyphs
----------------------------

A glyph is a graphical representation of a character.  Whereas a
"character" is an abstraction of semantic information, a "glyph" is an
intelligible mark visible on screen or paper.  A character has many
possible representation forms; for example, the character 'A' can be
written in an upright or slanted typeface, producing distinct glyphs.
Sometimes, a sequence of characters map to a single glyph: this is a
"ligature"--the most common is 'fi'.

   Space characters never become glyphs in GNU 'troff'.  If not
discarded (as when trailing text lines), horizontal motions represent
them in the output.

   In a 'troff' system, a font description file (recall *note Font
Directories::) lists all of the glyphs a particular font provides.  If
the user requests a glyph not available in the currently selected font,
the formatter looks it up an ordered list of "special fonts".  By
default, the 'ps' (PostScript) and 'pdf' output devices support the two
special fonts 'SS' (slanted symbol) and 'S' (symbol); and these devices'
'DESC' files arrange them such that the formatter searches the former
before the latter.  Other output devices use different names for special
fonts.  Fonts mounted with the 'fonts' keyword in the 'DESC' file are
globally available.  GNU 'troff''s 'special' and 'fspecial' requests
alter the list of fonts treated as special on a general basis, or only
when a certain font is currently selected, respectively.

   The formatter supports three kinds of character.  An "ordinary
character" is the most commonly used, has no special syntax, and
typically represents itself.(1)  (*note Characters and
Glyphs-Footnote-1::) Interpolate a "special character" with the '\[XXX]'
or '\C'XXX'' escape sequence syntax, where XXX is an identifier.  An
"indexed character" bypasses most character-to-glyph resolution logic,
uses the '\N'I'' syntax, and selects a glyph from the currently selected
font by its integer-valued position I in the output device's
representation of that font.(2)  (*note Characters and
Glyphs-Footnote-2::)

   "User-defined characters" are similar to string definitions,(3)
(*note Characters and Glyphs-Footnote-3::) and permit extension of or
substitution within the character repertoire.  Any ordinary, special, or
indexed character can be user-defined.  The 'char', 'fchar', 'schar',
and 'fschar' requests create user-defined characters employed at various
stages of the character-to-glyph resolution process.

   GNU 'troff' employs the following procedure to resolve an input
character into a glyph.  User-defined characters make this resolution
process recursive.  The first step that succeeds ends the resolution
procedure for the character being formatted, which may not be the last
in the sequence interpolated by a user-defined character.

   * Interpolate the definition of any character defined by the 'char'
     request and apply this procedure to each character in its
     definition.

   * Check the current font for a glyph corresponding to the character.

   * Interpolate the definition of any user-defined character matching
     defined by the 'fchar' request and apply this procedure to each
     character in its definition.

   * Check whether the current font has a font-specific list of special
     fonts; if so, check the each font therein, in the order determined
     by the last applicable 'fspecial' request, for a glyph
     corresponding to the character.

   * Interpolate the definition of any character defined by the 'fschar'
     request for the currently selected font, and apply this procedure
     to each character in its definition.

   * Check each font in the list configured by the most recently issued
     'special' request for a glyph corresponding to the character.

   * Interpolate the definition of any character defined by the 'sschar'
     request and apply this procedure to each character in its
     definition.

   * Finally, iterate through the list of mounted fonts by position;
     recall *Note Font Positions::.  For each mounted font, if that font
     bears the 'special' directive,(4) (*note Characters and
     Glyphs-Footnote-4::) check it for a glyph corresponding to the
     character.  This stage of the resolution process can sometimes lead
     to surprising results since the 'fonts' directive in the 'DESC'
     file often contains empty positions that are filled by a macro file
     or document employing the 'fp' request after the formatter
     initializes.

     For example, consider the following:

          fonts 3 0 0 FOO

     This mounts font 'foo' at font position 3.  We assume that 'FOO' is
     a special font, containing glyph 'foo', and that no font has been
     loaded yet.  The line

          .fspecial BAR BAZ

     makes font 'BAZ' special only if font 'BAR' is active.  We further
     assume that 'BAZ' is really a special font, i.e., the font
     description file contains the 'special' keyword, and that it also
     contains glyph 'foo' with a special shape fitting to font 'BAR'.
     After executing 'fspecial', font 'BAR' is loaded at font
     position 1, and 'BAZ' at position 2.

     We now switch to a new font 'XXX', trying to access glyph 'foo'
     that is assumed to be missing.  There are neither font-specific
     special fonts for 'XXX' nor any other fonts made special with the
     'special' request, so the formatter starts the search for special
     fonts in the list of already mounted fonts, with increasing font
     positions.  Consequently, it finds 'BAZ' before 'FOO' even before
     'XXX', which is not the intended behaviour.

   *Note Device and Font Description Files::, and *note Special Fonts::,
for more details.

   The 'groff_char(7)' man page houses a complete list of predefined
special character names, but the availability of any as a glyph is
device- and font-dependent.  For example, say

     man -T dvi groff_char > groff_char.dvi

to obtain those available with the DVI device and default font
configuration.(5)  (*note Characters and Glyphs-Footnote-5::) If you
want to use an additional macro package to change the fonts used, you
must run 'groff' (or 'troff') directly.

     groff -T dvi -m ec -m an groff_char.7 > groff_char.dvi

   Special character names not listed in 'groff_char(7)' are derived
algorithmically, using a simplified version of the Adobe Glyph List
(AGL) algorithm, which is described in
<https://github.com/adobe-type-tools/agl-aglfn>.  The (frozen) set of
names that can't be derived algorithmically is called the "'groff' glyph
list (GGL)".

   * A glyph for Unicode character U+XXXX[X[X]], which is not a
     composite character is named 'uXXXX[X[X]]'.  X must be an uppercase
     hexadecimal digit.  Examples: 'u1234', 'u008E', 'u12DB8'.  The
     largest Unicode value is 0x10FFFF. There must be at least four 'X'
     digits; if necessary, add leading zeroes (after the 'u').  No zero
     padding is allowed for character codes greater than 0xFFFF.
     Surrogates (i.e., Unicode values greater than 0xFFFF represented
     with character codes from the surrogate area U+D800-U+DFFF) are not
     allowed either.

   * A glyph representing more than a single input character is named

          'u' COMPONENT1 '_' COMPONENT2 '_' COMPONENT3 ...

     Example: 'u0045_0302_0301'.

     For simplicity, all Unicode characters that are composites must be
     maximally decomposed to NFD;(6) (*note Characters and
     Glyphs-Footnote-6::) for example, 'u00CA_0301' is not a valid glyph
     name since U+00CA (LATIN CAPITAL LETTER E WITH CIRCUMFLEX) can be
     further decomposed into U+0045 (LATIN CAPITAL LETTER E) and U+0302
     (COMBINING CIRCUMFLEX ACCENT).  'u0045_0302_0301' is thus the glyph
     name for U+1EBE, LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND ACUTE.

   * groff maintains a table to decompose all algorithmically derived
     glyph names that are composites itself.  For example, 'u0100'
     (LATIN LETTER A WITH MACRON) is automatically decomposed into
     'u0041_0304'.  Additionally, a glyph name of the GGL is preferred
     to an algorithmically derived glyph name; 'groff' also
     automatically does the mapping.  Example: The glyph 'u0045_0302' is
     mapped to '^E'.

   * glyph names of the GGL can't be used in composite glyph names; for
     example, '^E_u0301' is invalid.

 -- Escape sequence: \(nm
 -- Escape sequence: \[name]
 -- Escape sequence: \[base-glyph combining-component ...]
     Typeset a special character NAME (two-character name NM) or a
     composite glyph consisting of BASE-GLYPH overlaid with one or more
     COMBINING-COMPONENTs.  For example, '\[A ho]' is a capital letter
     "A" with a "hook accent" (ogonek).

     There is no special syntax for one-character names--the analogous
     form '\N' would collide with other escape sequences.  However, the
     four escape sequences '\'', '\-', '\_', and '\`', are translated on
     input to the special character escape sequences '\[aa]', '\[-]',
     '\[ul]', and '\[ga]', respectively.

     A special character name of length one is not the same thing as an
     ordinary character: that is, the character 'a' is not the same as
     '\[a]'.

     If NAME is undefined, a warning in category 'char' is produced and
     the escape is ignored.  *Note Warnings::, for information about the
     enablement and suppression of warnings.

     GNU 'troff' resolves '\[...]' with more than a single component as
     follows:

        * Any component that is found in the GGL is converted to the
          'uXXXX' form.

        * Any component 'uXXXX' that is found in the list of
          decomposable glyphs is decomposed.

        * The resulting elements are then catenated with '_' in between,
          dropping the leading 'u' in all elements but the first.

     No check for the existence of any component (similar to 'tr'
     request) is done.

     Examples:

     '\[A ho]'
          'A' maps to 'u0041', 'ho' maps to 'u02DB', thus the final
          glyph name would be 'u0041_02DB'.  This is not the expected
          result: the ogonek glyph 'ho' is a spacing ogonek, but for a
          proper composite a non-spacing ogonek (U+0328) is necessary.
          Looking into the file 'composite.tmac', one can find
          '.composite ho u0328', which changes the mapping of 'ho' while
          a composite glyph name is constructed, causing the final glyph
          name to be 'u0041_0328'.

     '\[^E u0301]'
     '\[^E aa]'
     '\[E a^ aa]'
     '\[E ^ ']'
          '^E' maps to 'u0045_0302', thus the final glyph name is
          'u0045_0302_0301' in all forms (assuming proper calls of the
          'composite' request).

     It is not possible to define glyphs with names like 'A ho' within a
     'groff' font file.  This is not really a limitation; instead, you
     have to define 'u0041_0328'.

 -- Escape sequence: \C'''xxx'''
     Typeset the special character XXX.  Normally, it is more convenient
     to use '\[XXX]', but '\C' has some advantages: it is compatible
     with AT&T device-independent 'troff' (and therefore available in
     compatibility mode(7) (*note Characters and Glyphs-Footnote-7::))
     and can interpolate special characters with ']' in their names.
     The delimiter need not be a neutral apostrophe; recall *note
     Delimiters::.

 -- Request: .composite c1 c2
     Map ordinary or special character name C1 to C2 when C1 is a
     combining component in a composite character.  See above for
     examples.  This is a strict rewriting of the special character
     name; no check is performed for the existence of a glyph for
     either.  Typically, 'composite' is used to map a spacing character
     to a combining one.  A set of default mappings for many accents can
     be found in the file 'composite.tmac', loaded by the default
     'troffrc' at startup.

     You can obtain a report of mappings defined by 'composite' on the
     standard error stream with the 'pcomposite' request.  *Note
     Debugging::.

 -- Escape sequence: \N'''n'''
     Format indexed character numbered N in the current font ('n' is
     _not_ the input character code).  N can be any non-negative decimal
     integer.  Most devices number glyphs with codes between 0 and 255
     only; the 'utf8' output device uses codes in the range 0-65535.  If
     the current font does not contain a glyph with that code, special
     fonts are _not_ searched.  The '\N' escape sequence can be
     conveniently used in conjunction with the 'char' request.

          .char \[phone] \f[ZD]\N'37'

     The code of each glyph is given in the fourth column in the font
     description file after the 'charset' command.  It is possible to
     include unnamed glyphs in the font description file by using a name
     of '---'; the '\N' escape sequence is the only way to use these.

     No kerning is applied to glyphs accessed with '\N'.  The delimiter
     need not be a neutral apostrophe; see *note Delimiters::.

   A few escape sequences are also special characters.

 -- Escape sequence: \'''
     An escaped neutral apostrophe is a synonym for '\[aa]' (acute
     accent).

 -- Escape sequence: \'`'
     An escaped grave accent is a synonym for '\[ga]' (grave accent).

 -- Escape sequence: \-
     An escaped hyphen-minus is a synonym for '\[-]' (minus sign).

 -- Escape sequence: \_
     An escaped underscore ("low line") is a synonym for '\[ul]'
     (underrule).  On typesetting devices, the underrule is
     font-invariant and drawn lower than the underscore '_'.

 -- Request: .cflags n c...
     Assign properties encoded by non-negative integer N to each
     character or class(8) (*note Characters and Glyphs-Footnote-8::).
     C.  Spaces need not separate C arguments.

     Characters, whether ordinary, special, or indexed, have certain
     associated properties.  The first argument is the sum of the
     desired flags and the remaining arguments are the characters to be
     assigned those properties.  arguments.

     The non-negative integer N is the sum of any of the following.
     Some combinations are nonsensical, such as '33' (1 + 32).

     '1'
          Recognize the character as ending a sentence if followed by a
          newline or two spaces.  Initially, characters '.?!' have this
          property.

     '2'
          Enable breaks before the character.  A line is not broken at a
          character with this property unless the characters on each
          side both have non-zero hyphenation codes.  This exception can
          be overridden by adding 64.  Initially, no characters have
          this property.

     '4'
          Enable breaks after the character.  A line is not broken at a
          character with this property unless the characters on each
          side both have non-zero hyphenation codes.  This exception can
          be overridden by adding 64.  Initially, characters
          '\-\[hy]\[em]' have this property.

     '8'
          Mark the glyph associated with this character as overlapping
          other instances of itself horizontally.  Initially, characters
          '\[ul]\[rn]\[ru]\[radicalex]\[sqrtex]' have this property.

     '16'
          Mark the glyph associated with this character as overlapping
          other instances of itself vertically.  Initially, the
          character '\[br]' has this property.

     '32'
          Mark the character as transparent for the purpose of
          end-of-sentence recognition.  In other words, an
          end-of-sentence character followed by any number of characters
          with this property is treated as the end of a sentence if
          followed by a newline or two spaces.  This is the same as
          having a zero space factor in TeX.  Initially, characters
          '"')]*\[dg]\[dd]\[rq]\[cq]' have this property.

     '64'
          Ignore hyphenation codes of the surrounding characters.  Use
          this in combination with values 2 and 4 (initially, no
          characters have this property).

          For example, if you need an automatic break point after the
          en-dash in numeric ranges like "3000-5000", insert

               .cflags 68 \[en]

          into your document.  However, this practice can lead to bad
          layout if done thoughtlessly; in most situations, a better
          solution instead of changing the 'cflags' value is to insert
          '\:' right after the hyphen at the places that really need a
          break point.

     The remaining values were implemented for East Asian language
     support; those who use alphabetic scripts exclusively can disregard
     them.

     '128'
          Prohibit a line break before the character, but allow a line
          break after the character.  This works only in combination
          with flags 256 and 512 and has no effect otherwise.
          Initially, no characters have this property.

     '256'
          Prohibit a line break after the character, but allow a line
          break before the character.  This works only in combination
          with flags 128 and 512 and has no effect otherwise.
          Initially, no characters have this property.

     '512'
          Allow line break before or after the character.  This works
          only in combination with flags 128 and 256 and has no effect
          otherwise.  Initially, no characters have this property.

     In contrast to values 2 and 4, the values 128, 256, and 512 work
     pairwise.  If, for example, the left character has value 512, and
     the right character 128, no break will be automatically inserted
     between them.  If we use value 6 instead for the left character, a
     break after the character can't be suppressed since the neighboring
     character on the right doesn't get examined.

 -- Request: .char c ['"'][contents]
 -- Request: .fchar c ['"'][contents]
 -- Request: .fschar f c ['"'][contents]
 -- Request: .schar c ['"'][contents]
     Define an ordinary, special, or indexed character C as CONTENTS.

     Omitting CONTENTS gives C an empty definition.

     GNU 'troff' removes a leading neutral double quote '"' from
     CONTENTS, permitting initial embedded spaces in it, and reads it to
     the end of the input line in copy mode.  *Note Copy Mode::.

     Defining (or redefining) a character C creates a formatter object
     that GNU 'troff' recognizes like any other ordinary, special, or
     indexed character on input, and produces CONTENTS on output.  When
     formatting C, GNU 'troff' processes CONTENTS in a temporary
     environment and enscapsulates the result in a node;(9) (*note
     Characters and Glyphs-Footnote-9::) disabling compatibility mode
     and setting the escape character to '\' while interpreting
     CONTENTS.  Any emboldening, constant spacing, or track kerning
     applies to this object rather than to individual glyphs resulting
     from the formatting of CONTENTS.

     A character defined by these requests can be used just like a glyph
     provided by the output device.  In particular, other characters can
     be translated to it with the 'tr' and 'trin' requests; it can be
     made the tab or leader fill character with the 'tc' and 'lc'
     requests, respectively; sequences of it can be drawn with the '\l'
     and '\L' escape sequences; and, if the 'hcode' request is used on
     C, it is subject to automatic hyphenation.

     However, a user-defined character C does not participate at its
     boundaries in kerning adjustments or italic corrections.

     The formatter prevents infinite recursion by treating an occurrence
     of a character in its own definition as if it were undefined; when
     interpolating such a character, GNU 'troff' emits a warning in
     category 'char'.(10)  (*note Characters and Glyphs-Footnote-10::)

     The 'tr' and 'trin' requests take precedence if 'char' accesses the
     same symbol.

          .tr XY
          X
              => Y
          .char X Z
          X
              => Y
          .tr XX
          X
              => Z

     The 'fchar' request defines a fallback glyph: 'troff' checks for
     glyphs defined with 'fchar' only if it cannot find the glyph in the
     current font.  'troff' performs this test before checking special
     fonts.

     'fschar' defines a fallback glyph for font F: 'troff' checks for
     glyphs defined with 'fschar' after the list of fonts declared as
     font-specific special fonts with the 'fspecial' request, but before
     the list of fonts declared as global special fonts with the
     'special' request.

     Finally, the 'schar' request defines a global fallback glyph:
     'troff' checks for glyphs defined with 'schar' after the list of
     fonts declared as global special fonts with the 'special' request,
     but before the already mounted special fonts.

     *Note Character Classes::.

     *Caution:* These requests remove a leading neutral double quote '"'
     and treat the remainder of the input line as their second argument,
     including any spaces, up to a newline or comment escape sequence.
     See the discussion of the 'ds' request in *note Strings::.

 -- Request: .rchar c ...
 -- Request: .rfschar f c ...
     Remove definition of each ordinary, special, or indexed character
     C, undoing the effect of a 'char', 'fchar', or 'schar' request.
     Spaces need not separate C arguments.  The character definition
     removed (if any) is the first encountered in the resolution process
     documented above.  Glyphs, which are defined by font description
     files, cannot be removed.

     'rfschar' removes character definitions created by 'fschar' for
     font F.


File: groff.info,  Node: Characters and Glyphs-Footnotes,  Up: Characters and Glyphs

   (1) Depending on the breadth of the output device's glyph repertoire,
the characters ''', '-', '^', '`', and '~' can be exceptions to this
rule.  '"' and '\' are not exceptions, but because they are
syntactically meaningful to the formatter, access to their glyphs may
require use of special characters (or changing or disabling the escape
character).  See 'groff_char(7)'.

   (2) Fonts do not necessarily arrange their glyphs per a standard
character encoding.

   (3) *Note Strings::.

   (4) *Note Device and Font Description Files::.

   (5) Not all versions of the 'man' program support the '-T' option;
use the subsequent example for an alternative.

   (6) This is "Normalization Form D" as documented in Unicode Standard
Annex #15 (<https://unicode.org/reports/tr15/>).

   (7) *Note Compatibility Mode::.

   (8) *Note Character Classes::.

   (9) *Note GNU troff Internals::.

   (10) Mutually recursive character definitions are handled similarly.


File: groff.info,  Node: Character Classes,  Next: Special Fonts,  Prev: Characters and Glyphs,  Up: Using Fonts

5.19.5 Character Classes
------------------------

GNU 'troff' can group characters into "classes", making manipulation of
their breaking and/or sentential properties convenient; recall the
'cflags' request in *note Characters and Glyphs::.  Classes are
particularly useful for East Asian languages such as Chinese, Japanese,
and Korean, which have much larger character repertoires than the Latin,
Greek, Cyrillic, or Thai scripts.  In such large character sets, many
characters share the same properties.  Only 'class' and 'cflags'
requests can operate on character classes.

 -- Request: .class ident c ...
     Define a character class (or simply "class") IDENT comprising the
     members C ..., where each C is an ordinary, special, or indexed
     character; or a range expression.  A class thus defined can then be
     referred to in a 'cflags' request in lieu of listing all the
     characters within it.

          .class [quotes] ' \[aq] \[dq] \[oq] \[cq] \[lq] \[rq]

     Since class and special character names share the same name space,
     we recommend starting and ending the class name with '[' and ']',
     respectively, to avoid collisions with existing special character
     names defined by GNU 'troff' or the user (with 'char' and related
     requests).  This practice applies the presence of ']' in the class
     name to prevent the use of the special character escape form
     '\[...]', you must therefore access a class thus named via the '\C'
     escape sequence.

     An argument C can alternatively be a "range expression" consisting
     of a start character followed by '-' and then an end character.
     Internally, GNU 'troff' converts these two symbol names to Unicode
     code points (according to the 'groff' glyph list [GGL]), which
     determine the start and end values of the range.  If that
     conversion fails, GNU 'troff' skips the range expression and any
     remaining arguments.

     If you want to include '-' in a class, it must be the first
     character in a C argument; otherwise GNU 'troff' interprets the
     argument as a range expression.


File: groff.info,  Node: Special Fonts,  Next: Artificial Fonts,  Prev: Character Classes,  Up: Using Fonts

5.19.6 Special Fonts
--------------------

Special fonts are those that the formatter searches, in mounting
position order, when it cannot find a requested glyph in the selected
font.  Typically, they are declared as such in their description
files,(1) (*note Special Fonts-Footnote-1::) and contain unstyled
glyphs.  The "Symbol" and "Zapf Dingbats" fonts of the PostScript and
PDF standards are examples.  Ordinarily, only typesetters have special
fonts.

   GNU 'troff''s 'special' and 'fspecial' requests permit a document to
supplement the set of fonts the device configures for glyph search
without having to use the 'fp' request to manipulate the list of
mounting positions, which can be tedious--by default, GNU 'troff' mounts
40 fonts at startup when using the 'ps' device.

 -- Request: .special [s ...]
 -- Request: .fspecial f [s ...]
     'special' declares each font S as special, irrespective of its
     description file, populating a list that GNU 'troff' searches, in
     order, to find the glyph demanded.  GNU 'troff' mounts each font S.
     Invoking 'special' without arguments empties the list.  A font is
     not automatically unmounted if a subsequent 'special' request
     removes it from the list.  Initially, the list is empty.

     'fspecial' is similar; it designates each font S as special only
     when font F is selected.  Initially, a font F's list of associated
     special fonts is empty for all F.

     Invoking 'special' (or 'fspecial', for a given font F) again
     overwrites the previous list; if you invoke them without arguments,
     GNU 'troff' empties the corresponding list.


File: groff.info,  Node: Special Fonts-Footnotes,  Up: Special Fonts

   (1) *Note Font Description File Format::.


File: groff.info,  Node: Artificial Fonts,  Next: Ligatures and Kerning,  Prev: Special Fonts,  Up: Using Fonts

5.19.7 Artificial Fonts
-----------------------

There are a number of requests and escape sequences for artificially
creating fonts.  These are largely vestiges of the days when output
devices did not have a wide variety of fonts, and when 'nroff' and
'troff' were separate programs.  Most of them are no longer necessary in
GNU 'troff'.  Nevertheless, they are supported.

 -- Escape sequence: \H'''height'''
 -- Escape sequence: \H'''+height'''
 -- Escape sequence: \H'''-height'''
 -- Register: \n[.height]
     Set (increment, decrement) the height of the current font, but not
     its width.  If HEIGHT is zero, the formatter uses the font's
     inherent height for its type size.  The default scaling unit is
     'z'.

     Changing the font height does not affect vertical spacing; dramatic
     changes may be better accompanied by an '\x' escape sequence to add
     extra pre-vertical space to the output line.  Recall *note
     Manipulating Spacing::.

     The read-only register '.height' interpolates the font height.

     As of this writing, only the 'ps' and 'pdf' output devices support
     this feature.

     The formatter does not tokenize '\H' when reading it; the escape
     sequence updates the environment.(1)  (*note Artificial
     Fonts-Footnote-1::) It thus can be used in requests that expect a
     single-character argument.  We can alter the font height of a
     margin character(2) (*note Artificial Fonts-Footnote-2::) as
     follows.

          .mc \H'+5z'x\H'0'

     In compatibility mode, GNU 'troff' behaves differently: it applies
     an increment or decrement to the current type size and not to the
     previously selected font height.

          .cp 1
          \H'+5'test \H'+5'test

     prints the word 'test' twice with the same font height--five points
     larger than the current font size.

 -- Escape sequence: \S'''slant'''
 -- Register: \n[.slant]
     Slant the glyphs of the currently selected font by SLANT degrees.
     Positive values slant in the direction of text flow.  Only integer
     values are possible.

     The read-only register '.slant' interpolates the font slant.

     As of this writing, only the 'ps' and 'pdf' output devices support
     this feature.

     The formatter does not tokenize '\S' when reading it; the escape
     sequence updates the environment.(3)  (*note Artificial
     Fonts-Footnote-3::) It thus can be used in requests that expect a
     single-character argument.  We can apply a slant to a margin
     character(4) (*note Artificial Fonts-Footnote-4::) as follows.

          .mc \S'20'x\S'0'

     This escape sequence is incorrectly documented in the AT&T 'troff'
     manual: the slant is only assigned, never incremented or
     decremented.

 -- Request: .ul [lines]
     The 'ul' request normally underlines subsequent lines if a TTY
     output device is used.  Otherwise, the lines are printed in italics
     (only the term 'underlined' is used in the following).  The single
     argument is the quantity of input lines to be underlined; with no
     argument, the next line is underlined.  If LINES is zero or
     negative, stop the effects of 'ul' (if it was active).  Requests
     and empty lines do not count for computing the number of underlined
     input lines, even if they produce some output like 'tl'.  Lines
     inserted by macros (e.g., invoked by a trap) do count.

     At the beginning of 'ul', the current font is stored and the
     underline font is activated.  Within the span of a 'ul' request, it
     is possible to change fonts, but after the last line affected by
     'ul' the saved font is restored.

     This number of lines still to be underlined is associated with the
     environment (*note Environments::).  The underline font can be
     changed with the 'uf' request.

     The 'ul' request does not underline spaces.

 -- Request: .cu [lines]
     The 'cu' request is similar to 'ul' but underlines spaces as well
     (if a TTY output device is used).

 -- Request: .uf font
     Set the underline font (globally) used by 'ul' and 'cu'.  By
     default, this is the font at position 2.  FONT can be either a
     non-negative font position or the name of a font.

 -- Request: .bd font [offset]
 -- Request: .bd font1 font2 [offset]
 -- Register: \n[.b]
     Embolden FONT by overstriking its glyphs offset by OFFSET units
     minus one.

     Two syntax forms are available.

        * Imitate a bold font unconditionally.  The first argument
          specifies the font to embolden, and the second is the number
          of basic units, minus one, by which the two glyphs are offset.
          If the second argument is missing, emboldening is turned off.

          FONT can be either a non-negative font position or the name of
          a font.

          OFFSET is available in the '.b' read-only register if a
          special font is active; in the 'bd' request, its default unit
          is 'u'.

        * Imitate a bold form conditionally.  Embolden FONT1 by OFFSET
          only if font FONT2 is the current font.  This request can be
          issued repeatedly to set up different emboldening values for
          different current fonts.  If the second argument is missing,
          emboldening is turned off for this particular current font.

          Because the emboldening is conditional, it applies only if the
          glyph to be formatted is not available in the current font.
          FONT1 must therefore be a special font, configured either with
          the 'special' directive in its font description file or with
          the 'fspecial' request).

 -- Request: .cs font [width [em-size]]
     Switch to and from "constant glyph spacing mode".  If activated,
     the width of every glyph is WIDTH/36 ems.  The em size is given
     absolutely by EM-SIZE; if this argument is missing, the em value is
     taken from the current font size (as set with the 'ps' request)
     when the font is effectively in use.  Without second and third
     argument, constant glyph spacing mode is deactivated.

     Default scaling unit for EM-SIZE is 'z'; WIDTH is an integer.


File: groff.info,  Node: Artificial Fonts-Footnotes,  Up: Artificial Fonts

   (1) *Note Environments::.

   (2) *Note Miscellaneous::.

   (3) *Note Environments::.

   (4) *Note Miscellaneous::.


File: groff.info,  Node: Ligatures and Kerning,  Next: Italic Corrections,  Prev: Artificial Fonts,  Up: Using Fonts

5.19.8 Ligatures and Kerning
----------------------------

Proportional fonts commonly employ two techniques to improve the
esthetics of typeset text.  "Ligatures" are sequences of glyphs that are
visually connected or "tied", overlapping them and slightly altering
their shapes.  "Kerning" is the adjustment of horizontal spacing between
glyphs.  Neither is employed on terminals.(1)  (*note Ligatures and
Kerning-Footnote-1::)

   Most typesetters support ligatures for the sequences 'fi', 'fl',
'ff', 'ffi', and 'ffl', and 'troff' does likewise.  Some fonts may
include others, but GNU 'troff' does not (yet) support them.

   The formatter checks only the current font for ligatures and kerning
adjustments; neither glyphs from special fonts nor special characters
defined with the 'char' request (and its siblings) are considered for
these processes.

 -- Request: .lg [flag]
 -- Register: \n[.lg]
     Switch the ligature mechanism on or off; if the parameter is
     non-zero or missing, ligatures are enabled, otherwise disabled.
     Default is on.  The current ligature mode can be found in the
     read-only register '.lg' (set to 1 or 2 if ligatures are enabled,
     0 otherwise).

     Setting the ligature mode to 2 enables the two-character ligatures
     (fi, fl, and ff) and disables the three-character ligatures (ffi
     and ffl).

   "Pairwise kerning" is another subtle typesetting mechanism that
modifies the distance between adjacent glyphs in a pair to improve
readability.  In most cases (but not always) the distance is decreased.
Monospaced (typewriter-like) fonts and terminals don't use kerning.

 -- Request: .kern [flag]
 -- Register: \n[.kern]
     Enable or disable pairwise kerning of glyphs in the environment per
     B.  It is enabled by default, and if B is omitted.

     The read-only register '.kern' interpolates 1 if pairwise kerning
     is enabled, 0 otherwise.

     If the font description file contains pairwise kerning information,
     glyphs from that font are kerned.  Kerning between two glyphs can
     be inhibited by placing '\&' between them: 'V\&A'.

     *Note Font Description File Format::.

   "Track kerning" expands or reduces the space between glyphs.  This
can be handy, for example, if you need to squeeze a long word onto a
single line or spread some text to fill a narrow column.  It must be
used with great care since it is usually considered bad typography if
the reader notices the effect.

 -- Request: .tkf f s1 n1 s2 n2
     Enable track kerning for font F.  If the current font is F the
     width of every glyph is increased by an amount between N1 and N2
     (N1, N2 can be negative); if the current type size is less than or
     equal to S1 the width is increased by N1; if it is greater than or
     equal to S2 the width is increased by N2; if the type size is
     greater than or equal to S1 and less than or equal to S2 the
     increase in width is a linear function of the type size.

     The default scaling unit is 'z' for S1 and S2, 'p' for N1 and N2.

     The track kerning amount is added even to the rightmost glyph in a
     line; for large values it is thus recommended to increase the line
     length by the same amount to compensate.


File: groff.info,  Node: Ligatures and Kerning-Footnotes,  Up: Ligatures and Kerning

   (1) A monospaced font may possess glyphs for ligatures, but they
nevertheless seldom see use to set text.


File: groff.info,  Node: Italic Corrections,  Next: Dummy Characters,  Prev: Ligatures and Kerning,  Up: Using Fonts

5.19.9 Italic Corrections
-------------------------

When typesetting adjacent glyphs from typefaces of different slants, the
space between them may require adjustment.

 -- Escape sequence: \/
     Apply an "italic correction": modify the spacing of the preceding
     glyph so that the distance between it and the following glyph is
     correct if the latter is of upright shape.  For example, if an
     italic 'f' is followed immediately by a roman right parenthesis,
     then in many fonts the top right portion of the 'f' overlaps the
     top of the right parenthesis, which is ugly.  Use '\/' whenever a
     slanted glyph is followed immediately by an upright glyph without
     any intervening space.

 -- Escape sequence: \,
     Apply a "left italic correction": modify the spacing of the
     following glyph so that the distance between it and the preceding
     glyph is correct if the latter is of upright shape.  For example,
     if a roman left parenthesis is immediately followed by an
     italic 'f', then in many fonts the bottom left portion of the 'f'
     overlaps the bottom of the left parenthesis, which is ugly.  Use
     '\,' whenever an upright glyph is followed immediately by a slanted
     glyph without any intervening space.


File: groff.info,  Node: Dummy Characters,  Prev: Italic Corrections,  Up: Using Fonts

5.19.10 Dummy Characters
------------------------

As discussed in *note Requests and Macros::, the first character on an
input line is treated specially.  Further, formatting a glyph has many
consequences on formatter state (*note Environments::).  Occasionally,
we want to escape this context or embrace some of those consequences
without actually rendering a glyph to the output.

 -- Escape sequence: \&
     Interpolate a dummy character, which is constitutive of output but
     invisible.(1)  (*note Dummy Characters-Footnote-1::) Its presence
     alters the interpretation context of a subsequent input character,
     and enjoys several applications.

        * Prevent insertion of extra space after an end-of-sentence
          character.

               Test.
               Test.
                   => Test.  Test.
               Test.\&
               Test.
                   => Test. Test.

        * Prevent recognition of a control character.

               .Test
                   error-> warning: name 'Test' not defined
               \&.Test
                   => .Test

        * Prevent kerning between two glyphs.

        * Translate a character to "nothing".

               .tr JIjiK\&k\&UVuv
               Post universitum, alea jacta est, OK?
                   => Post vniversitvm, alea iacta est, O?

        * Stop the interpretation of a numerical expression.

               \l'4i-'
                   error-> warning: expected numeric expression,
                   error-> got character "'"
               \l'4i\&-'
                   => ----------------------------------------

     The dummy character escape sequence sees use in macro definitions
     as a means of ensuring that arguments are treated as text even if
     they begin with spaces or control characters.

          .de HD \" typeset a simple bold heading
          .  sp
          .  ft B
          \&\\$1 \" exercise: remove the \&
          .  ft
          .  sp
          ..
          .HD .\|.\|.\|surprised?

   One way to think about the dummy character is to imagine placing the
symbol '&' in the input at a certain location; if doing so has all the
side effects on formatting that you desire except for sticking an ugly
ampersand in the midst of your text, the dummy character is what you
want in its place.

 -- Escape sequence: \)
     Interpolate a transparent dummy character--one that is transparent
     to end-of-sentence detection.  It behaves as '\&', except that '\&'
     is treated as letters and numerals normally are after '.', '?' and
     '!'; '\&' cancels end-of-sentence detection, and '\)' does not.

          .de Suffix-&
          .  nop \&\\$1
          ..
          .
          .de Suffix-)
          .  nop \)\\$1
          ..
          .
          Here's a sentence.\c
          .Suffix-& '
          Another one.\c
          .Suffix-) '
          And a third.
              => Here's a sentence.' Another one.'  And a third.


File: groff.info,  Node: Dummy Characters-Footnotes,  Up: Dummy Characters

   (1) Opinions of this escape sequence's best name abound.  "Zero-width
space" is a popular misnomer: 'roff' formatters do not treat it like a
space; when filling, they do not break a line where '\&' appears.
Ossanna called it a "non-printing, zero-width character", but the
character causes _output_ even though it does not "print".  If no output
line is pending, the dummy character starts one.  Contrast an empty
input document with one containing only '\&'.  The former produces no
output; the latter, a blank page.


File: groff.info,  Node: Manipulating Type Size and Vertical Spacing,  Next: Colors,  Prev: Using Fonts,  Up: GNU troff Reference

5.20 Manipulating Type Size and Vertical Spacing
================================================

These concepts were introduced in *note Page Geometry::.  The height of
a font's tallest glyph is one em, which is equal to the type size in
points.(1)  (*note Manipulating Type Size and Vertical
Spacing-Footnote-1::) A vertical spacing of less than 120% of the type
size can make a document hard to read.  Larger proportions can be useful
to spread the text for annotations or proofreader's marks.  By default,
GNU 'troff' uses 10 point type on 12 point spacing.  Typographers call
the difference between type size and vertical spacing "leading".(2)
(*note Manipulating Type Size and Vertical Spacing-Footnote-2::) Both
properties are associated with the environment; see *note
Environments::)

* Menu:

* Changing the Type Size::
* Changing the Vertical Spacing::
* Using Fractional Type Sizes::


File: groff.info,  Node: Manipulating Type Size and Vertical Spacing-Footnotes,  Up: Manipulating Type Size and Vertical Spacing

   (1) In text fonts, parentheses are often the tallest glyphs, but a
font's glyphs may not match the nominal type size!  In the standard
PostScript font families, 10-point Times sets better with 9-point
Helvetica and 11-point Courier than if all were used at 10 points.
Recall the 'fzoom' request in *note Selecting Fonts:: for a remedy.

   (2) Rhyme with "sledding"; mechanical typography used lead metal
(Latin _plumbum_).


File: groff.info,  Node: Changing the Type Size,  Next: Changing the Vertical Spacing,  Up: Manipulating Type Size and Vertical Spacing

5.20.1 Changing the Type Size
-----------------------------

 -- Request: .ps [size]
 -- Request: .ps +size
 -- Request: .ps -size
 -- Register: \n[.s]
     Set (increase, decrease) the type size to (by) SIZE points.  'ps'
     with no argument restores the previous size.  The 'ps' request's
     default scaling unit is 'z'; recall *note Measurements:: and see
     *note Using Fractional Type Sizes::).  The formatter rounds the
     requested size to the nearest valid size (with ties rounding down)
     within the limits supported by the device, and if the requested
     size is non-positive, treats it as 1u.

     Type size alteration is incorrectly documented in the AT&T 'troff'
     manual, which claims "if [the requested size] is invalid, the next
     larger valid size will result, with a maximum of 36".(1)  (*note
     Changing the Type Size-Footnote-1::)

     The read-only string-valued register '.s' interpolates the type
     size in points as a decimal fraction.  To obtain the type size in
     scaled points, interpolate the '.ps' register instead (*note Using
     Fractional Type Sizes::).

 -- Escape sequence: \ssize
     The '\s' escape sequence also determines the type size, but handles
     a zero argument differently.  It supports a variety of syntax
     forms.

     '\sN'
          Set the type size to N typographical points.  N must be a
          single digit.(2)  (*note Changing the Type Size-Footnote-2::)
          If N is '0', restore the previous size.

     '\s+N'
     '\s-N'
          Increase or decrease the type size by N typographical points.
          N must be exactly one digit.

     '\s(NN'
          Set the type size to NN typographical points.  NN must be
          exactly two digits.  If N is '00', restore the previous size.

     '\s+(NN'
     '\s-(NN'
     '\s(+NN'
     '\s(-NN'
          Alter the type size in scaled points by the NN typographical
          points.  NN must be exactly two digits.

     *Note Using Fractional Type Sizes::, for further syntactical forms
     of the '\s' escape sequence that additionally accept decimal
     fractions.

          snap, snap,
          .ps +2
          grin, grin,
          .ps +2
          wink, wink, \s+2nudge, nudge,\s+8 say no more!
          .ps 10

   The formatter does not tokenize '\s' when reading its input; it
instead updates the environment.  It thus can be used in requests that
expect a single-character argument.  We might alter the type size when
writing a margin character as follows (*note Miscellaneous::).

     .mc \s[20]x\s[0]

 -- Request: .sizes s1 s2 ... sn [0]
     The 'DESC' file specifies which type sizes are allowed by the
     output device; see *note DESC File Format::.  Use the 'sizes'
     request to change this set of permissible sizes.  Arguments are in
     scaled points; see *note Using Fractional Type Sizes::.  Each can
     be a single type size (such as '12000'), or a range of sizes (such
     as '4000-72000').  You can optionally end the list with a '0'.


File: groff.info,  Node: Changing the Type Size-Footnotes,  Up: Changing the Type Size

   (1) The claim appears to have been true of Ossanna 'troff' for the
C/A/T device; Kernighan made device-independent 'troff' more flexible.

   (2) In compatibility mode only, a non-zero N must be in the range
4-39.  *Note Compatibility Mode::.


File: groff.info,  Node: Changing the Vertical Spacing,  Next: Using Fractional Type Sizes,  Prev: Changing the Type Size,  Up: Manipulating Type Size and Vertical Spacing

5.20.2 Changing the Vertical Spacing
------------------------------------

 -- Request: .vs [space]
 -- Request: .vs +space
 -- Request: .vs -space
 -- Register: \n[.v]
     Set the vertical spacing to, or alter it by, SPACE.  The default
     scaling unit is 'p'.  If 'vs' is invoked without an argument, the
     vertical spacing is reset to the previous value before the last
     call to 'vs'.  GNU 'troff' emits a warning in category 'range' if
     SPACE is negative; the vertical spacing is then set to the smallest
     possible positive value, the vertical motion quantum (as found in
     the '.V' register).

     '.vs 0' isn't saved in a diversion since it doesn't result in a
     vertical motion.  You must explicitly issue this request before
     interpolating the diversion.

     The read-only register '.v' contains the vertical spacing.

When a break occurs, GNU 'troff' performs the following procedure.

   * Move the drawing position vertically by the "extra pre-vertical
     line space", the minimum of all negative '\x' escape sequence
     arguments in the pending output line.

   * Move the drawing position vertically by the vertical line spacing.

   * Write out the pending output line.

   * Move the drawing position vertically by the "extra post-vertical
     line space", the maximum of all positive '\x' escape sequence
     arguments in the line that has just been output.

   * Move the drawing position vertically by the "post-vertical line
     spacing" (see below).

   Prefer 'vs' or 'pvs' over 'ls' to produce double-spaced documents.
'vs' and 'pvs' have finer granularity than 'ls'; moreover, some
preprocessors assume single spacing.  *Note Manipulating Spacing::,
regarding the '\x' escape sequence and the 'ls' request.

 -- Request: .pvs [space]
 -- Request: .pvs +space
 -- Request: .pvs -space
 -- Register: \n[.pvs]
     Set the post-vertical spacing to, or alter it by, SPACE.  The
     default scaling unit is 'p'.  If 'pvs' is invoked without an
     argument, the post-vertical spacing is reset to the previous value
     before the last call to 'pvs'.  GNU 'troff' emits a warning in
     category 'range' if SPACE is negative; the post-vertical spacing is
     then set to zero.

     The read-only register '.pvs' interpolates the post-vertical
     spacing.


File: groff.info,  Node: Using Fractional Type Sizes,  Prev: Changing the Vertical Spacing,  Up: Manipulating Type Size and Vertical Spacing

5.20.3 Using Fractional Type Sizes
----------------------------------

When configuring the type size, AT&T 'troff' ignored scaling units and
interpreted all measurements in points.  Combined with integer
arithmetic, this design choice made it impossible to support, for
instance, ten-and-a-half-point type.  In GNU 'troff', an output device
can select a scaling factor that subdivides a point into "scaled
points".  A type size expressed in scaled points can thus represent a
non-integral size in points.

   A "scaled point", scaling unit 's', is equal to 1/SIZESCALE points,
where the device description file, 'DESC', specifies SIZESCALE and
otherwise defaults to 1.(1)  (*note Using Fractional Type
Sizes-Footnote-1::) GNU 'troff' also defines the "typographical point",
scaling unit 'z', which explicitly specifies a type size of potentially
non-integral measure.  The program multiplies typographical points by
SIZESCALE and converts the value to an integer.  Arguments GNU 'troff'
interprets in 'z' units by default comprise those to the escape
sequences '\H' and '\s', to the request 'ps', the third argument to the
'cs' request, and the second and fourth arguments to the 'tkf' request.

   For example, if SIZESCALE is 1000, then a scaled point is one
thousandth of a point.  The request '.ps 10.5' is synonymous with '.ps
10.5z'; both set the type size to 10,500 scaled points, or
10.5 typographical points.

 -- Register: \n[.ps]
     This read-only register interpolates the type size in scaled
     points.  '\n[.ps]s', '\n[.s]z', and '1m' are co-equal by
     definition.

     .tm device=\*[.T]
     .tm A: .s=\n[.s]z, .ps=\n[.ps]s
     .ps 10.5
     .tm B: .s=\n[.s]z, .ps=\n[.ps]s
     .ps 12.3p
     .tm C: .s=\n[.s]z, .ps=\n[.ps]s
     .ps 8.1z
     .tm D: .s=\n[.s]z, .ps=\n[.ps]s
     .ps 10500s
     .tm E: .s=\n[.s]z, .ps=\n[.ps]s
         => device=ps
         => A: .s=10z, .ps=10000s
         => B: .s=10.5z, .ps=10500s
         => C: .s=12.3z, .ps=12300s
         => D: .s=8.1z, .ps=8100s
         => E: .s=10.5z, .ps=10500s

   It makes no sense to use the 'z' scaling unit in a numeric expression
whose default scaling unit is neither 'u' nor 'z', so GNU 'troff'
disallows this.  Similarly, it is nonsensical to use scaling units other
than 'p', 's', 'z', or 'u' in a numeric expression whose default scaling
unit is 'z', and so GNU 'troff' disallows those as well.

 -- Register: \n[.psr]
 -- Register: \n[.sr]
     Output devices may be limited in the type sizes they can employ.
     The '.s' and '.ps' registers represent the type size selected by
     the formatter as it understands a device's capability.  The last
     _requested_ type size is interpolated in scaled points by the
     read-only register '.psr' and in points as a decimal fraction by
     the read-only string-valued register '.sr'.

     For example, if a document requests a type size of 10.95 points,
     and the nearest size permitted by a 'sizes' request (or by the
     'sizes' or 'sizescale' directives in the device's 'DESC' file) is
     11 points, 'groff' uses the latter value.

   The '\s' escape sequence offers the following syntax forms that work
with fractional type sizes and accept scaling units.  The delimited
forms need not use the neutral apostrophe; see *note Delimiters::.

'\s[N]'
'\s'N''
     Set the type size to N typographical points; N is a numeric
     expression with a default scaling unit of 'z'.

'\s[+N]'
'\s[-N]'
'\s+[N]'
'\s-[N]'
'\s'+N''
'\s'-N''
'\s+'N''
'\s-'N''
     Increase or decrease the type size by N typographical points; N is
     a numeric expression with a default scaling unit of 'z'.  If N is
     '0', restore the previous size.


File: groff.info,  Node: Using Fractional Type Sizes-Footnotes,  Up: Using Fractional Type Sizes

   (1) *Note Device and Font Description Files::.


File: groff.info,  Node: Colors,  Next: Strings,  Prev: Manipulating Type Size and Vertical Spacing,  Up: GNU troff Reference

5.21 Colors
===========

GNU 'troff' supports color output with a variety of color spaces and up
to 16 bits per channel.  Some devices, particularly terminals, may be
more limited.  When color support is enabled, two colors are current at
any given time: the "stroke color", with which glyphs, rules (lines),
and geometric objects like circles and polygons are drawn, and the "fill
color", which can be used to paint the interior of a closed geometric
figure.

 -- Request: .color [b]
 -- Register: \n[.color]
     Enable or disable output of color-related device-independent output
     commands per Boolean expression B.  It is enabled by default, and
     if B is omitted.

     The read-only register '.color' interpolates 1 if color support is
     enabled, 0 otherwise.

     Color can also be disabled with the '-c' command-line option.

 -- Request: .defcolor ident scheme color-component ...
     Define a color named IDENT.  SCHEME selects a color space and
     determines the quantity of required COLOR-COMPONENTs; it must be
     one of 'rgb' (three components), 'cmy' (three), 'cmyk' (four), or
     'gray' (one).  'grey' is accepted as a synonym of 'gray'.  The
     color components can be encoded as a single hexadecimal value
     starting with '#' or '##'.  The former indicates that each
     component is in the range 0-255 (0-FF), the latter the range
     0-65,535 (0-FFFF).

          .defcolor half gray #7f
          .defcolor pink rgb #FFC0CB
          .defcolor magenta rgb  ##ffff0000ffff

     Alternatively, each color component can be specified as a decimal
     fraction in the range 0-1, interpreted using a default scaling unit
     of 'f', which multiplies its value by 65,536 (but clamps it at
     65,535).

          .defcolor gray50 rgb 0.5 0.5 0.5
          .defcolor darkgreen rgb 0.1f 0.5f 0.2f

     You can obtain a report of colors defined by 'defcolor' on the
     standard error stream with the 'pcolor' request.  *Note
     Debugging::.

   Each output device has a color named 'default', which cannot be
redefined.  A device's default stroke and fill colors are not
necessarily the same.  For the 'dvi', 'html', 'pdf', 'ps', and 'xhtml'
output devices, GNU 'troff' automatically loads a macro file defining
many color names at startup.  By the same mechanism, the devices
supported by 'grotty' recognize the eight standard ISO 6429/ECMA-48
color names.(1)  (*note Colors-Footnote-1::)

 -- Request: .gcolor [col]
 -- Escape sequence: \mc
 -- Escape sequence: \m(co
 -- Escape sequence: \m[col]
 -- Register: \n[.m]
     Select COL as the stroke color for glyphs, rules, and objects drawn
     with '\D'...'' escape sequences.  The escape sequence '\M[]'
     restores the previous stroke color, or the default if there is
     none, as does a 'gcolor' request without an argument.

          .gcolor red
          The next words
          .gcolor
          \m[red]are in red\m[]
          and these words are in the previous color.

     The current environment's stroke color selection is available in
     the read-only string-valued register '.m' (*note Environments::).
     The default strike color is named 'default'.

     GNU 'troff' does not tokenize '\m' when reading it; the escape
     sequence updates the environment.  It thus can be used in requests
     that expect a single-character argument.  We can assign a stroke
     color to a margin character as follows (*note Miscellaneous::).

          .mc \m[red]x\m[]

 -- Request: .fcolor [col]
 -- Escape sequence: \Mc
 -- Escape sequence: \M(co
 -- Escape sequence: \M[col]
 -- Register: \n[.M]
     Select COL as the fill color for objects drawn with '\D'...''
     escape sequences.  The escape sequence '\M[]' restores the previous
     fill color, or the default if there is none, as does an 'fcolor'
     request without an argument.

     GNU 'troff' does not tokenize '\F' when reading it; the escape
     sequence updates the environment.  It thus can be used in requests
     that expect a single-character argument.  We can assign a fill
     color to a margin character as follows (*note Miscellaneous::);
     'grotty' interprets the fill color as a character cell background
     color.

          .mc \m[black]\M[green]x\M[]\m[]

     The current environment's fill color selection is available in the
     read-only string-valued register '.M' (*note Environments::).  The
     default fill color is named 'default'.

     Create an ellipse with a red interior as follows.

          \M[red]\h'0.5i'\D'E 2i 1i'\M[]


File: groff.info,  Node: Colors-Footnotes,  Up: Colors

   (1) These are known vulgarly as "ANSI" colors, after its X3.64
standard, now withdrawn.


File: groff.info,  Node: Strings,  Next: Conditionals and Loops,  Prev: Colors,  Up: GNU troff Reference

5.22 Strings
============

GNU 'troff' supports strings primarily for user convenience.
Conventionally, if one would define a macro only to interpolate a small
amount of text, without invoking requests or calling any other macros,
one defines a string instead.  Only one string is predefined by the
language.

 -- String: \*[.T]
     Contains the name of the output device (for example, 'utf8' or
     'pdf').

   The 'ds' request creates a string with a specified name and contents
and the '\*' escape sequence dereferences its name, interpolating its
contents.  If the string named by the '\*' escape sequence does not
exist, it is defined as empty, nothing is interpolated, and a warning in
category 'mac' is emitted.  *Note Warnings::, regarding the enablement
and suppression of warnings.

 -- Request: .ds name [['"']contents]
 -- Request: .ds1 name [['"']contents]
 -- Escape sequence: \*n
 -- Escape sequence: \*(nm
 -- Escape sequence: \*[name [arg1 arg2 ...]]
     Define a string called NAME with contents CONTENTS.  If NAME
     already exists as an alias, the target of the alias is redefined;
     see 'als' and 'rm' below.  If 'ds' is invoked with only one
     argument, NAME is defined as an empty string.  Otherwise, GNU
     'troff' stores CONTENTS in copy mode.  '\*' is itself interpreted
     even in copy mode.(1)  (*note Strings-Footnote-1::)

     The '\*' escape sequence interpolates a previously defined string
     NAME (one-character name N, two-character name NM).  The bracketed
     interpolation form accepts arguments that are handled as macro
     arguments are; recall *note Calling Macros::.  In contrast to macro
     calls, however, if a closing bracket ']' occurs in a string
     argument, that argument must be enclosed in double quotes.  When
     defining strings, argument interpolations must be escaped if they
     are to reference parameters from the calling context; see *note
     Parameters::.

          .ds cite (\\$1, \\$2)
          Gray codes are explored in \*[cite Morgan 1998].
              => Gray codes are explored in (Morgan, 1998).

     *Caution:* After the formatter has read the space character that
     ends the first argument, it treats the remainder of the input line
     as the second argument, including any spaces, up to a newline or
     comment escape sequence.  Ending string definitions (and
     appendments) with a comment, even an empty one, prevents unwanted
     space from creeping into them during source document maintenance.

          .ds Si silicon \" use chemical symbol
          We observed a \*[Si]-based life form.
              => We observed a silicon -based life form.

     Instead, place the comment on another line or put the comment
     escape sequence immediately adjacent to the last character of the
     string.

          .ds Si silicon\" use chemical symbol
          We observed a \*[Si]-based life form.
              => We observed a silicon-based life form.

     Because the first space after the string name separates the
     arguments, you can retain it while using a comment to document an
     empty string.

          .ds author Alice Pleasance Liddell\"
          .ds friends \" empty; append to with .as

     The formatter removes a leading neutral double quote '"' from
     CONTENTS, permitting initial embedded spaces in it.  It interprets
     any other '"' literally, but the wise author uses the special
     character escape sequence '\[dq]' instead if the string might be
     interpolated as part of a macro argument; recall *note Calling
     Macros::.

          .ds salutation "         Yours in a white wine sauce,\"
          .ds c-var-defn "  char mydate[]=\[dq]2020-07-29\[dq];\"

     Strings are not limited to a single input line of text.  '\<RET>'
     works just as it does elsewhere.  The resulting string is stored
     _without_ the newlines.  When filling is disabled, care is required
     to avoid overrunning the line length when interpolating strings.

          .ds foo This string contains \
          text on multiple lines \
          of input.

     Conversely, when filling is enabled, it is not necessary to append
     '\c' to a string interpolation to prevent a break afterward, as
     might be required in a macro argument.  Nor does a string require
     use of the GNU 'troff' 'chop' request to excise a trailing newline
     as is often done with diversions.

     It is not possible to embed a newline in a string that will be
     interpreted as such when the string is interpolated.  To achieve
     that effect, use '\*' to interpolate a macro instead; see *note
     Punning Names::.

     Because strings are similar to macros, they too can be defined so
     as to suppress AT&T 'troff' compatibility mode when used; see *note
     Writing Macros:: and *note Compatibility Mode::.  The 'ds1' request
     defines a string such that compatibility mode is off when the
     string is later interpolated.  To be more precise, GNU 'troff'
     inserts a a "compatibility save" token at the beginning of
     CONTENTS, and a "compatibility restore" token at the end.

          .nr xxx 12345
          .ds aa The value of xxx is \\n[xxx].
          .ds1 bb The value of xxx is \\n[xxx].
          .
          .cp 1
          .
          \*(aa
              error-> warning: register '[' not defined
              => The value of xxx is 0xxx].
          \*(bb
              => The value of xxx is 12345.

 -- Request: .as name [['"']contents]
 -- Request: .as1 name [['"']contents]
     The 'as' request is similar to 'ds' but appends CONTENTS to the
     string stored as NAME instead of redefining it.  If NAME doesn't
     exist yet, it is created.  If 'as' is invoked with only one
     argument, no operation is performed (beyond dereferencing the
     string).

          .as salutation " with shallots, onions and garlic,\"

     *Caution:* The formatter reads the second argument to the end of
     the line in copy mode, omitting any leading neutral double quote
     '"' character.  See the discussion of the 'ds' request above.

     The 'as1' request works as does 'as', but like 'ds1', it brackets
     CONTENTS with compatibility save and restore tokens.

   Several requests exist to perform rudimentary string operations.
Strings can be queried ('length') and modified ('chop', 'substring',
'stringup', 'stringdown'), and their names can be manipulated through
renaming, removal, and aliasing ('rn', 'rm', 'als').

 -- Request: .length reg [['"']contents]
     Compute the number of characters in CONTENTS and store the count in
     the register REG.  If REG doesn't exist, GNU 'troff' creates it.

     GNU 'troff' removes a leading neutral double quote '"' from
     CONTENTS, permitting initial embedded spaces in it, and reads it to
     the end of the input line in copy mode.  *Note Copy Mode::.

          .ds xxx abcd\h'3i'efgh
          .length yyy \*[xxx]
          \n[yyy]
              => 14

     *Caution:* The formatter reads the second argument to the end of
     the line in copy mode, omitting any leading neutral double quote
     '"' character.  See the discussion of the 'ds' request above.

     *Caution:* If you interpolate a macro or diversion in CONTENTS
     (*note Punning Names::), the 'length' request counts characters (or
     nodes) only up to the first newline, and leaves the rest on the
     input stream.  In conventional circumstances, that means the
     remainder is interpreted, and may be formatted.  To discover the
     length of any string, macro, or diversion, use the 'pm' request.
     *Note Debugging::.

 -- Request: .chop object
     Remove the last character from the macro, string, or diversion
     named OBJECT.  This is useful for removing the newline from the end
     of a diversion that is to be interpolated as a string.  This
     request can be used repeatedly on the same OBJECT; see *note GNU
     troff Internals::, for details on nodes inserted additionally by
     GNU 'troff'.

 -- Request: .substring str start [end]
     Replace the string named STR with its substring bounded by the
     indices START and END, inclusively.  The first character in the
     string has index 0.  If END is omitted, it is implicitly set to the
     largest valid value (the string length minus one).  Negative
     indices count backward from the end of the string: the last
     character has index -1, the character before the last has index -2,
     and so on.

          .ds xxx abcdefgh
          .substring xxx 1 -4
          \*[xxx]
              => bcde
          .substring xxx 2
          \*[xxx]
              => de

 -- Request: .stringdown str
 -- Request: .stringup str
     Alter the string named STR by replacing each of its bytes with its
     lowercase ('stringdown') or uppercase ('stringup') version (if one
     exists).  Special characters in the string will often transform in
     the expected way due to the regular naming convention for accented
     characters.  When they do not, use substrings and/or catenation.

          .ds resume R\['e]sum\['e]\"
          \*[resume]
          .stringdown resume
          \*[resume]
          .stringup resume
          \*[resume]
              => Résumé résumé RÉSUMÉ

 -- Request: .rn old new
     Rename the request, macro, diversion, or string OLD to NEW.

 -- Request: .rm name ...
     Remove each request, macro, diversion, or string NAME.  GNU 'troff'
     treats subsequent invocations as if the name had never been
     defined.

     This request is incorrectly documented in the AT&T 'troff' manual
     as accepting only one argument.

 -- Request: .als new-name existing-name
     Create alias (additional name) NEW-NAME of request, string, macro,
     or diversion EXISTING-NAME, causing the names to refer to the same
     stored object.  If EXISTING-NAME is undefined, the formatter
     ignores the request.(2)  (*note Strings-Footnote-2::) If NEW-NAME
     already exists, its contents are lost unless already aliased.

     To understand how the 'als' request works, consider two different
     storage pools: one for objects (macros, strings, etc.), and another
     for names.  As soon as an object is defined, GNU 'troff' adds it to
     the object pool, adds its name to the name pool, and creates a link
     between them.  When 'als' creates an alias, it adds a new name to
     the name pool that gets linked to the same object as the old name.

     Now consider this example.

          .de foo
          ..
          .
          .als bar foo
          .
          .de bar
          .  foo
          ..
          .
          .bar
              error-> input stack limit exceeded (probable infinite
              error-> loop)

     In the above, 'bar' remains an _alias_--another name for--the
     object referred to by 'foo', which the second 'de' request
     replaces.  Alternatively, imagine that the 'de' request
     _dereferences_ its argument before replacing it.  Either way, the
     result of calling 'bar' is a recursive loop that finally leads to
     an error.  *Note Writing Macros::.

     To remove an alias, call 'rm' on its name.  The object itself is
     not destroyed until it has no more names.

     When a request, macro, string, or diversion is aliased
     redefinitions and appendments "write through" alias names.  To
     replace an alias with a separately defined object, remove its name
     first.


File: groff.info,  Node: Strings-Footnotes,  Up: Strings

   (1) *Note Copy Mode::.

   (2) GNU 'troff' emits a warning in category 'mac'.  *Note Warnings::.


File: groff.info,  Node: Conditionals and Loops,  Next: Writing Macros,  Prev: Strings,  Up: GNU troff Reference

5.23 Conditionals and Loops
===========================

'groff' has 'if' and 'while' control structures like other languages.
However, the syntax for grouping multiple input lines in the branches or
bodies of these structures is unusual.

* Menu:

* Operators in Conditionals::
* if-then::
* if-else::
* Conditional Blocks::
* while::


File: groff.info,  Node: Operators in Conditionals,  Next: if-then,  Up: Conditionals and Loops

5.23.1 Operators in Conditionals
--------------------------------

The 'if', 'ie', and 'while' requests test the truth values of numeric
expressions.  They also support several additional Boolean operators;
the members of this expanded class are termed "conditional expressions";
their truth values are as shown below.

'c CHR'
     True if a character CHR is available; CHR is an ordinary, special
     or indexed character, whether defined by a font description file or
     a request.

'd NAME'
     True if a string, macro, diversion, or request called NAME exists.

'e'
     True if the current page is even-numbered.

'F FONT'
     True if FONT exists.  FONT is handled as if it were an argument to
     the 'ft' request (that is, the default family is combined with an
     abstract style and font translation is applied), but FONT cannot be
     a mounting position, and no font is mounted.

'm COLOR'
     True if COLOR is defined.

'n'
     True if the document is being processed in 'nroff' mode.

'o'
     True if the current page is odd-numbered.

'r REGISTER'
     True if REGISTER exists.

'S STYLE'
     True if STYLE is available for the current font family.  Font
     translation is applied.

't'
     True if the document is being processed in 'troff' mode.

'v'
     Always false.  This condition exists for compatibility with certain
     other 'troff' implementations.(1)  (*note Operators in
     Conditionals-Footnote-1::)

   If the first argument to an 'if', 'ie', or 'while' request begins
with a non-alphanumeric character apart from '!' (see below) and is not
a numeric expression, the formatter performs an output comparison test.
(2) (*note Operators in Conditionals-Footnote-2::)

''XXX'YYY''
     This "output comparison operator" interpolates a true value if
     formatting the comparands XXX and YYY produces the same output
     commands.  The delimiter need not be a neutral apostrophe: the
     output comparison operator accepts the same delimiters as most
     escape sequences; see *note Delimiters::.  'troff' formats XXX and
     YYY in separate scratch buffers; after comparison, it discards the
     resulting data.

          .ie "|"\fR|\fP" true
          .el false
              => true

     The resulting glyph properties, including font family, style, size,
     and slant, must match, but not necessarily the requests and/or
     escape sequences used to obtain them.  In the previous example, '|'
     and '\fR|\fP' result in '|' glyphs in the same typefaces at the
     same positions, so the comparands are equal.  If '.ft I' had been
     added before the '.ie', they would differ: the first '|' would
     produce an italic '|', not a roman one.  Motions must match in
     orientation and magnitude to within the applicable horizontal and
     vertical motion quanta of the device, after rounding.  '.if
     "\u\d"\v'0'"' is false even though both comparands result in zero
     net motion, because motions are not interpreted or optimized but
     sent as-is to the output.(3)  (*note Operators in
     Conditionals-Footnote-3::) On the other hand, '.if "\d"\v'0.5m'"'
     is true, because '\d' is defined as a downward motion of one-half
     em.(4)  (*note Operators in Conditionals-Footnote-4::)

     Surround the comparands with '\?' to avoid formatting them; this
     causes them to be compared character by character, as with string
     comparisons in other programming languages.

          .ie "\?|\?"\?\fR|\fP\?" true
          .el false
              => false

     Since GNU 'troff' reads comparands protected with '\?' in copy
     mode,(5) (*note Operators in Conditionals-Footnote-5::) they need
     not even be syntactically valid.  The escape character is still
     lexically recognized, however, and consumes the next character.

          .ds a \[
          .ds b \[
          .if '\?\*a\?'\?\*b\?' a and b equivalent
          .if '\?\\?'\?\\?' backslashes equivalent
          .if '\?\P\?'\?P\?' backslash-P and P equivalent
              => a and b equivalent

   The above operators can't be combined with most others, but a leading
'!', not followed immediately by spaces or tabs, complements an
expression.

     .nr x 1
     .ie !r x register x is not defined
     .el      register x is defined
         => register x is defined

   Spaces and tabs are optional immediately after the 'c', 'd', 'F',
'm', 'r', and 'S' operators, but right after '!', they end the predicate
and the conditional evaluates true.(6)  (*note Operators in
Conditionals-Footnote-6::)

     .nr x 1
     .ie ! r x register x is not defined
     .el       register x is defined
         => r x register x is not defined

The unexpected 'r x' in the output is a clue that our conditional was
not interpreted as we planned, but matters may not always be so obvious.

   Conditional operators do not create 'roff' language objects as
interpolations with '\n' and '\*' escape sequences do.


File: groff.info,  Node: Operators in Conditionals-Footnotes,  Up: Operators in Conditionals

   (1) We refer to 'vtroff', which converted the C/A/T command stream
produced by early-vintage AT&T 'troff' to input suitable for Versatec
and Benson-Varian plotters.

   (2) Strictly, letters not otherwise recognized _are_ treated as
output comparison delimiters.  A portable document avoids using letters
not in the list above; for example, Plan 9 'troff' uses 'h' to test a
mode it calls 'htmlroff', and GNU 'troff' may provide additional
operators in the future.

   (3) Because formatting of the comparands takes place in a dummy
environment, vertical motions within them cannot spring traps.  *Note
Traps::.

   (4) All of this is to say that the lists of nodes created by
formatting XXX and YYY must be identical.  *Note GNU troff Internals::.

   (5) *Note Copy Mode::.

   (6) This bizarre behavior maintains compatibility with AT&T 'troff'.


File: groff.info,  Node: if-then,  Next: if-else,  Prev: Operators in Conditionals,  Up: Conditionals and Loops

5.23.2 if-then
--------------

 -- Request: .if cond-expr input
     Evaluate the conditional expression COND-EXPR, and if it evaluates
     true (or to a positive value), interpret the remainder of the line
     INPUT as if it were an input line.  Recall from *note Invoking
     Requests:: that any quantity of spaces between arguments to
     requests serves only to separate them; leading spaces in INPUT are
     thus not seen.  INPUT effectively _cannot_ be omitted; if COND-EXPR
     is true and INPUT is empty, the formatter interprets the newline at
     the end of the control line as a blank input line (and therefore a
     blank text line).

          super\c
          tanker
          .nr force-word-break 1
          super\c
          .if ((\n[force-word-break] = 1) & \n[.int])
          tanker
              => supertanker super tanker

 -- Request: .nop [input]
     Interpret INPUT as if it were an input line.  'nop' resembles '.if
     1'; it puts a break on the output if INPUT is empty.  Unlike 'if',
     it cannot govern conditional blocks.  Its application is to
     maintain consistent indentation within macro definitions even when
     formatting output.

          .als real-MAC MAC
          .de wrapped-MAC
          .  tm MAC: called with arguments \\$@
          .  nop \\*[real-MAC]\\
          ..
          .als MAC wrapped-MAC
          \# Later...
          .als MAC real-MAC

     In the above, we've used aliasing, 'nop', and the interpolation of
     a macro as a string to interpose a wrapper around the macro 'MAC'
     (perhaps to debug it).


File: groff.info,  Node: if-else,  Next: Conditional Blocks,  Prev: if-then,  Up: Conditionals and Loops

5.23.3 if-else
--------------

 -- Request: .ie cond-expr input
 -- Request: .el input
     Use the 'ie' and 'el' requests to write an if-then-else.  The first
     request is the "if" part and the latter is the "else" part.
     Unusually among programming languages, any number of
     non-conditional requests may be interposed between the 'ie' branch
     and the 'el' branch.

          .nr a 0
          .ie \na a is non-zero.
          .nr a +1
          .el a was not positive but is now \na.
              => a was not positive but is now 1.

     Another way in which 'el' is an ordinary request is that it does
     not lexically "bind" more tightly to its 'ie' counterpart than it
     does to any other request.  This fact can surprise C programmers.

          .nr a 1
          .nr z 0
          .ie \nz \
          .  ie \na a is true
          .  el     a is false
          .el z is false
              => a is false

     To conveniently nest conditionals, keep reading.


File: groff.info,  Node: Conditional Blocks,  Next: while,  Prev: if-else,  Up: Conditionals and Loops

5.23.4 Conditional Blocks
-------------------------

It is frequently desirable for a control structure to govern more than
one request, macro call, text line, or combination of the foregoing.
The opening and closing brace escape sequences '\{' and '\}' define such
groups.  These "conditional blocks" can furthermore be nested.

 -- Escape sequence: \{
 -- Escape sequence: \}
     '\{' begins a conditional block; it must appear (after optional
     spaces and tabs) immediately subsequent to the conditional
     expression of an 'if', 'ie', or 'while' request,(1) (*note
     Conditional Blocks-Footnote-1::) or as the argument to an 'el'
     request.

     '\}' ends a conditional block and should appear on a line with
     other occurrences of itself as necessary to match '\{' sequences.
     It can be preceded by a control character, spaces, and tabs.  Input
     after any quantity of '\}' sequences on the same line is processed
     only if all of the preceding conditions to which they correspond
     are true.  Furthermore, a '\}' closing the body of a 'while'
     request must be the last such escape sequence on an input line.

     Brace escape sequences outside of control structures have no
     meaning and produce no output.

     *Caution:* Input lines using '\{' often end with '\RET', especially
     in macros that consist primarily of control lines.  Forgetting to
     use '\RET' on an input line after '\{' is a common source of error.

   We might write the following in a page header macro.  If we delete
'\RET', the header will carry an unwanted extra empty line (except on
page 1).

     .if (\\n[%] != 1) \{\
     .  ie ((\\n[%] % 2) = 0) .tl \\*[even-numbered-page-title]
     .  el                    .tl \\*[odd-numbered-page-title]
     .\}

   Let us take a closer look at how conditional blocks nest.

     A
     .if 0 \{ B
     C
     D
     \}E
     F
         => A F

     N
     .if 1 \{ O
     .  if 0 \{ P
     Q
     R\} S\} T
     U
         => N O U

   The above behavior may challenge the intuition; it was implemented to
retain compatibility with AT&T 'troff'.  For clarity, it is idiomatic to
end input lines with '\{' (followed by '\<RET>' if appropriate), and to
precede '\}' on an input line with nothing more than a control
character, spaces, tabs, and other instances of itself.

   We can use 'ie', 'el', and conditional blocks to simulate the
multi-way "switch" or "case" control structures of other languages.  The
following example is adapted from the 'groff' 'man' package.
Indentation is used to clarify the logic.

     .\" Simulate switch/case in roff.
     .      ie '\\$2'1' .ds title General Commands\"
     .el \{.ie '\\$2'2' .ds title System Calls\"
     .el \{.ie '\\$2'3' .ds title Library Functions\"
     .el \{.ie '\\$2'4' .ds title Kernel Interfaces\"
     .el \{.ie '\\$2'5' .ds title File Formats\"
     .el \{.ie '\\$2'6' .ds title Games\"
     .el \{.ie '\\$2'7' .ds title Miscellaneous Information\"
     .el \{.ie '\\$2'8' .ds title System Management\"
     .el \{.ie '\\$2'9' .ds title Kernel Development\"
     .el                .ds title \" empty
     .\}\}\}\}\}\}\}\}


File: groff.info,  Node: Conditional Blocks-Footnotes,  Up: Conditional Blocks

   (1) *Note while::.


File: groff.info,  Node: while,  Prev: Conditional Blocks,  Up: Conditionals and Loops

5.23.5 while
------------

GNU 'troff' provides a looping construct: the 'while' request.  Its
syntax matches the 'if' request.

 -- Request: .while cond-expr input
     Evaluate the conditional expression COND-EXPR, and repeatedly
     execute INPUT unless and until COND-EXPR evaluates false.  INPUT,
     which is often a conditional block, is referred to as the 'while'
     request's "body".

          .nr a 0 1
          .while (\na < 9) \{\
          \n+a,
          .\}
          \n+a
              => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

     GNU 'troff' treats the body of a 'while' request similarly to that
     of a 'de' request (albeit one not read in copy mode(1) (*note
     while-Footnote-1::)), but stores it under an internal name and
     deletes it when the loop finishes.  The operation of a macro
     containing a 'while' request can slow significantly if its body is
     large.  Each time GNU 'troff' interpolates the macro, it parses and
     stores the 'while' body again.

          .de xxx
          .  nr num 10
          .  while (\\n[num] > 0) \{\
          .    \" many lines of code
          .    nr num -1
          .  \}
          ..

     An often better solution--and one that is more portable, since AT&T
     'troff' lacked the 'while' request--is to instead write a recursive
     macro, which is parsed only once.(2)  (*note while-Footnote-2::)

          .de yy
          .  if (\\n(nm > 0) \{\
          .    \" many lines of code
          .    nr nm -1
          .    yy
          .  \}
          ..
          .
          .de xx
          .  nr nm 10
          .  yy
          ..

     To prevent infinite loops, GNU 'troff' limits the default number of
     available recursion levels to 1,000 or somewhat less.(3)  (*note
     while-Footnote-3::) You can disable this protective measure, or
     alter the limit, by setting the 'slimit' register.  *Note
     Debugging::.

     As noted above, if a 'while' body begins with a conditional block,
     its closing brace must end an input line.

          .if 1 \{\
          .  nr a 0 1
          .  while (\n[a] < 10) \{\
          .    nop \n+[a]
          .\}\}
              error-> unbalanced brace escape sequences

 -- Request: .break
     Exit a 'while' loop.  Do not confuse this request with a
     typographical break or the 'br' request.

 -- Request: .continue
     Skip the remainder of a 'while' loop's body, immediately retesting
     its conditional expression.


File: groff.info,  Node: while-Footnotes,  Up: while

   (1) *Note Copy Mode::.

   (2) unless you redefine it

   (3) "somewhat less" because things other than macro calls can be on
the input stack


File: groff.info,  Node: Writing Macros,  Next: Page Motions,  Prev: Conditionals and Loops,  Up: GNU troff Reference

5.24 Writing Macros
===================

A "macro" is a stored collection of text and control lines that can be
interpolated multiple times.  Use macros to define common operations.
Macros are called in the same way that requests are invoked.  While
requests exist for the purpose of creating macros, simply calling an
undefined macro, or interpolating it as a string, will cause it to be
defined as empty.  *Note Identifiers::.

 -- Request: .de name [end]
     Define a macro NAME, replacing the definition of any existing
     request, macro, string, or diversion called NAME.  If NAME already
     exists as an alias, the target of the alias is redefined; recall
     *note Strings::.  GNU 'troff' enters copy mode,(1) (*note Writing
     Macros-Footnote-1::) storing subsequent input lines as the macro
     definition.  If the optional second argument is not specified, the
     definition ends with the control line '..' (two dots).
     Alternatively, END identifies a macro whose call syntax at the
     start of a control line ends the definition of NAME; END is then
     called normally.  A macro definition must end in the same
     conditional block (if any) in which it began (recall *note
     Conditional Blocks::).  Spaces or tabs are permitted after the
     control character in the line containing this ending token (either
     '.' or 'END'), but a tab immediately after the token prevents its
     recognition as the end of a macro definition.  The macro END can be
     called with arguments.(2)  (*note Writing Macros-Footnote-2::)

     Here is a small example macro called 'P' that causes a break and
     inserts some vertical space.  It could be used to separate
     paragraphs.

          .de P
          .  br
          .  sp .8v
          ..

     We can define one macro within another.  Attempting to nest '..'
     naïvely will end the outer definition because the inner definition
     isn't interpreted as such until the outer macro is later
     interpolated.  We can use an end macro instead.  Each level of
     nesting should use a unique end macro.

     An end macro need not be defined until it is called.  This fact
     enables a nested macro definition to begin inside one macro and end
     inside another.  Consider the following example.(3)  (*note Writing
     Macros-Footnote-3::)

          .de m1
          .  de m2 m3
          you
          ..
          .de m3
          Hello,
          Joe.
          ..
          .de m4
          do
          ..
          .m1
          know?
          .  m3
          What
          .m4
          .m2
              => Hello, Joe.  What do you know?

     A nested macro definition _can_ be terminated with '..' and nested
     macros _can_ reuse end macros, but these control lines must be
     escaped multiple times for each level of nesting.  The necessity of
     this escaping and the utility of nested macro definitions will
     become clearer when we employ macro parameters and consider the
     behavior of copy mode in detail.

   'de' defines a macro that inherits the compatibility mode enablement
status of its context (*note Implementation Differences::).  Often it is
desirable to make a macro that uses 'groff' features callable from
contexts where compatibility mode is on; for instance, when writing
extensions to a historical macro package.  To achieve this,
compatibility mode needs to be switched off while such a macro is
interpreted--without disturbing that state when it is finished.

 -- Request: .de1 name [end]
     The 'de1' request defines a macro to be interpreted with
     compatibility mode disabled.  When NAME is called, compatibility
     mode enablement status is saved; it is restored when the call
     completes.  Observe the extra backlash before the interpolation of
     register 'xxx'; we'll explore this subject in *note Copy Mode::.

          .nr xxx 12345
          .de aa
          The value of xxx is \\n[xxx].
          .  br
          ..
          .de1 bb
          The value of xxx is \\n[xxx].
          ..
          .cp 1
          .aa
              error-> warning: register '[' not defined
              => The value of xxx is 0xxx].
          .bb
              => The value of xxx is 12345.

 -- Request: .dei name [end]
 -- Request: .dei1 name [end]
     The 'dei' request defines a macro with its name and end macro
     indirected through strings.  That is, it interpolates strings named
     NAME and END before performing the definition.

     The following examples are equivalent.

          .ds xx aa
          .ds yy bb
          .dei xx yy

          .de aa bb

     The 'dei1' request bears the same relationship to 'dei' as 'de1'
     does to 'de'; it temporarily turns compatibility mode off when NAME
     is called.

 -- Request: .am name [end]
 -- Request: .am1 name [end]
 -- Request: .ami name [end]
 -- Request: .ami1 name [end]
     'am' appends subsequent input lines to macro NAME, extending its
     definition, and otherwise working as 'de' does.

     To make the previously defined 'P' macro set indented instead of
     block paragraphs, add the necessary code to the existing macro.

          .am P
          .ti +5n
          ..

     The other requests are analogous to their 'de' counterparts.  The
     'am1' request turns off compatibility mode during interpretation of
     the appendment.  The 'ami' request appends indirectly, meaning that
     strings NAME and END are interpolated with the resulting names used
     before appending.  The 'ami1' request is similar to 'ami',
     disabling compatibility mode during interpretation of the appended
     lines.

   Using 'trace.tmac', you can trace calls to 'de', 'de1', 'am', and
'am1'.  You can also use the 'backtrace' request at any point desired to
troubleshoot tricky spots (*note Debugging::).

   *Note Strings::, for the 'als', 'rm', and 'rn' requests to create an
alias of, remove, and rename a macro, respectively.

   Macro identifiers share their name space with requests, strings, and
diversions; see *note Identifiers::.  The 'am', 'as', 'da', 'de', 'di',
and 'ds' requests (together with their variants) create a new object
only if the name of the macro, diversion, or string is currently
undefined or if it is defined as a request; normally, they modify the
value of an existing object.  *Note the description of the 'als'
request: als, for pitfalls when redefining a macro that is aliased.

 -- Request: .return [input]
     Stop interpreting an interpolated macro, skipping to the end of its
     definition.  Do not confuse 'return' with 'rt'.  If called with an
     argument INPUT, GNU 'troff' performs the skip twice--once within
     the macro being interpreted and once in an enclosing macro,
     permitting a macro to wrap the request.(4)  (*note Writing
     Macros-Footnote-4::)

* Menu:

* Parameters::
* Copy Mode::


File: groff.info,  Node: Writing Macros-Footnotes,  Up: Writing Macros

   (1) *Note Copy Mode::.

   (2) While it is possible to define and call a macro '.', you can't
use it as an end macro: during a macro definition, '..' is never handled
as calling '.', even if '.de NAME .' explicitly precedes it.

   (3) Its structure is adapted from, and isomorphic to, part of a
solution by Tadziu Hoffman to the problem of reflowing text multiple
times to find an optimal configuration for it.
<https://lists.gnu.org/archive/html/groff/2008-12/msg00006.html>

   (4) as 'trace.tmac' does


File: groff.info,  Node: Parameters,  Next: Copy Mode,  Up: Writing Macros

5.24.1 Parameters
-----------------

Macro calls and string interpolations optionally accept a list of
arguments; recall *note Calling Macros::.  At the time such an
interpolation takes place, these "parameters" can be examined using a
register and a variety of escape sequences starting with '\$'.  All such
escape sequences are interpreted even in copy mode, a fact we shall
motivate and explain below (*note Copy Mode::).

 -- Register: \n[.$]
     The count of parameters available to a macro or string is kept in
     this read-only register.  The 'shift' request can change its value.

   Any individual parameter can be accessed by its position in the list
of arguments to the macro call, numbered from left to right starting at
1, with one of the following escape sequences.

 -- Escape sequence: \$n
 -- Escape sequence: \$(nn
 -- Escape sequence: \$[nnn]
     Interpolate the Nth, NNth, or NNNth parameter.  The first form
     expects only a single digit (1<=N<=9)), the second two digits
     (01<=NN<=99)), and the third any positive integer NNN.  Macros and
     strings accept an unlimited number of parameters.  '\$' is
     interpreted even in copy mode.(1)  (*note Parameters-Footnote-1::)

 -- Request: .shift [n]
     Shift macro or string parameters N places (by 1 if N omitted):
     argument I becomes argument I-N; arguments 1 to N become
     unavailable.  Shifting by a non-positive amount, or outside of a
     macro or string definition, performs no operation.  The register
     '.$' adjusts its value accordingly.

   In practice, parameter interpolations are usually seen prefixed with
an extra escape character.  This is because the '\$' family of escape
sequences is interpreted even in copy mode.(2)  (*note
Parameters-Footnote-2::)

 -- Escape sequence: \$*
 -- Escape sequence: \$@
 -- Escape sequence: \$^
     In some cases it is convenient to interpolate all of the parameters
     at once (to pass them to a request, for instance).  The '\$*'
     escape catenates the parameters, separating them with spaces.
     '\$@' is similar, surrounding each parameter with double quotes and
     separating them with spaces.  If not in compatibility mode, the
     interpolation depth of double quotes is preserved (*note Calling
     Macros::).  '\$^' interpolates all parameters as if they were
     arguments to the 'ds' request.

          .de foo
          . tm $1='\\$1'
          . tm $2='\\$2'
          . tm $*='\\$*'
          . tm $@='\\$@'
          . tm $^='\\$^'
          ..
          .foo " This is a "test"
              error-> $1=' This is a '
              error-> $2='test"'
              error-> $*=' This is a  test"'
              error-> $@='" This is a " "test""'
              error-> $^='" This is a "test"'

     '\$*' is useful when writing a macro that doesn't need to
     distinguish its arguments, or even to not interpret them; examples
     include macros that produce diagnostic messages by wrapping the
     'tm' or 'ab' requests.  Use '\$@' when writing a macro that may
     need to shift its parameters and/or wrap a macro or request that
     finds the count significant.  If in doubt, prefer '\$@' to '\$*'.
     An application of '\$^' is seen in 'trace.tmac', which redefines
     some requests and macros for debugging purposes.

 -- Escape sequence: \$0
     Interpolate the name by which the macro being interpreted was
     called.  The 'als' request can cause a macro to have more than one
     name.  Applying string interpolation to a macro does not change
     this name.

          .de foo
          .  tm \\$0
          ..
          .als bar foo
          .
          .de aaa
          .  foo
          ..
          .de bbb
          .  bar
          ..
          .de ccc
          \\*[foo]\\
          ..
          .de ddd
          \\*[bar]\\
          ..
          .
          .aaa
              error-> foo
          .bbb
              error-> bar
          .ccc
              error-> ccc
          .ddd
              error-> ddd


File: groff.info,  Node: Parameters-Footnotes,  Up: Parameters

   (1) *Note Copy Mode::.

   (2) If they were not, parameter interpolations would be similar to
command-line parameters--fixed for the entire duration of a 'roff'
program's run.  The advantage of interpolating '\$' escape sequences
even in copy mode is that they can interpolate different contents from
one call to the next, like function parameters in a procedural language.
The additional escape character is the price of this power.


File: groff.info,  Node: Copy Mode,  Prev: Parameters,  Up: Writing Macros

5.24.2 Copy Mode
----------------

GNU 'troff' processes certain requests in "copy mode": it copies
ordinary, special, and indexed characters as-is; interpolates the escape
sequences '\n', '\g', '\$', '\*', '\V', and '\?' normally; discards
comments '\"' and '\#'; interpolates '\a', '\e', and '\t', as the
current leader, escape, or tab character, respectively; represents
'\RET', '\&', '\_', '\|', '\^', '\{', '\}', '\`', '\'', '\-', '\!',
'\c', '\%', '\SPC', '\E', '\)', '\~', and '\:' in an encoded form, and
copies other escape sequences as-is.  The term "copy mode" reflects its
most visible application in requests that populate macros and strings,
but other requests also use it when interpreting arguments that can't
meaningfully represent typesetting operations.  For example, a font
selection escape sequence has no meaning in a hyphenation pattern file
name ('hpf') or a diagnostic message written to the terminal ('tm').

   The complement of copy mode--a 'roff' formatter's behavior when not
defining or appending to a macro, string, or diversion--where all macros
are interpolated, requests invoked, and valid escape sequences processed
immediately upon recognition, can be termed "interpretation mode".

 -- Escape sequence: \\
     The escape character ('\' by default) when used before itself
     "quotes" an escape character for later interpretation in an
     enclosing context.  Escape character quotation enables you to
     control whether the formatter interprets a given '\n', '\g', '\$',
     '\*', '\V', or '\?' escape sequence at the time the macro
     containing it is defined, or later when the macro is called.(1)
     (*note Copy Mode-Footnote-1::)

          .nr x 20
          .de y
          .nr x 10
          \&\nx
          \&\\nx
          ..
          .y
              => 20 10

     You can think of '\\' as a "delayed" backslash; it is the escape
     character followed by a backslash from which the escape character
     has removed its special meaning.  Consequently, '\\' is not best
     considered an escape sequence, but a quoted escape character.  In
     any escape sequence '\X' that GNU 'troff' does not recognize, the
     formatter discards the escape character and outputs X.  An
     unrecognized escape sequence causes a warning in category 'escape',
     with two exceptions--'\\' is the first.

 -- Escape sequence: \.
     '\.' quotes the control character.  It is similar to '\\' in that
     it isn't a true escape sequence.  It is used to permit nested macro
     definitions to end without a named macro call to conclude them.
     Without a syntax for quoting the control character, this would not
     be possible.

          .de m1
          foo
          .
          .  de m2
          bar
          \\..
          .
          ..
          .m1
          .m2
              => foo bar

     The first backslash is consumed while the macro is read, and the
     second is interpreted when macro 'm1' is called.

   Outside of copy mode, 'roff' documents should not use the '\\' or
'\.' character sequences; they serve only to obfuscate the input.  Use
'\e' to represent the escape character, '\[rs]' to obtain a backslash
glyph, and '\&' before '.' and ''' where GNU 'troff' expects them as
control characters if you mean to use them literally (recall *note
Requests and Macros::).

   Macro definitions can be nested to arbitrary depth.  The mechanics of
parsing the escape character have significant consequences for this
practice.

     .de M1
     \\$1
     .  de M2
     \\\\$1
     .    de M3
     \\\\\\\\$1
     \\\\..
     .    M3 hand.
     \\..
     .  M2 of
     ..
     This understeer is getting
     .M1 out
         => This understeer is getting out of hand.

   As seen above, the formatter interprets each escape character in
multiple contexts; once, when populating the macro or string, where the
first '\' serves its quotation function\[em]thus only one '\' is stored
in the definition.  (Verify this fact with the 'pm' request.)  The
formatter interprets the second '\' as an escape character (assuming the
escape character hasn't been changed in the meantime) each time it
interpolates the macro or string definition.  This fact leads to
exponential growth in the quantity of escape characters required to
quote and thereby delay interpolation of '\n', '\g', '\$', '\*', '\V',
and '\?' at each nesting level, which can be daunting.  GNU 'troff'
offers a solution.

 -- Escape sequence: \E
     '\E' represents an escape character that is not interpreted in copy
     mode.  You can use it to ease the writing of nested macro
     definitions.

          .de M1
          .  nop \E$1
          .  de M2
          .    nop \E$1
          .    de M3
          .      nop \E$1
          \\\\..
          .    M3 better.
          \\..
          .  M2 bit
          ..
          This vehicle handles
          .M1 a
              => This vehicle handles a bit better.

     Observe that because '\.' is not a true escape sequence, we can't
     use '\E' to keep '..' from ending a macro definition prematurely.
     If the multiplicity of backslashes complicates maintenance, use end
     macros.

     '\E' is also convenient to define strings containing escape
     sequences that need to work when used in copy mode (for example, as
     macro arguments), or which will be interpolated at varying macro
     nesting depths.  We might define strings to begin and end
     superscripting as follows.(2)  (*note Copy Mode-Footnote-2::)

          .ds { \v'-.9m\s'\En[.s]*7u/10u'+.7m'
          .ds } \v'-.7m\s0+.9m'

     When the 'ec' request is used to redefine the escape character,
     '\E' also makes it easier to distinguish the semantics of an escape
     character from the other meaning(s) its character might have.
     Consider the use of an unusual escape character, '-'.

          .nr a 1
          .ec -
          .de xx
          --na
          ..
          .xx
              => -na

     This result may surprise you; some people expect '1' to be output
     since register 'a' has clearly been defined with that value.  What
     has happened?  The robotic replacement of '\' with '-' has led us
     astray.  You might recognize the sequence '--' more readily with
     the default escape character as '\-', the special character escape
     sequence for the minus sign glyph.

          .nr a 1
          .ec -
          .de xx
          -Ena
          ..
          .xx
              => 1


File: groff.info,  Node: Copy Mode-Footnotes,  Up: Copy Mode

   (1) Compare this to the '\def' and '\edef' commands in TeX.

   (2) These are lightly adapted from the 'groff' implementation of the
'ms' macros.


File: groff.info,  Node: Page Motions,  Next: Output Line Annotation,  Prev: Writing Macros,  Up: GNU troff Reference

5.25 Page Motions
=================

*Note Manipulating Spacing::, for a discussion of the most commonly used
request for vertical motion, 'sp'.

 -- Request: .mk [reg]
 -- Request: .rt [dist]
     You can "mark" a location on a page for subsequent "return".  'mk'
     takes an argument, a register name in which to store the current
     page location.  If given no argument, it stores the location in an
     internal register.  This location can be used later by the 'rt' or
     the 'sp' requests (or the '\v' escape sequence).

     The 'rt' request returns _upward_ to the location marked with the
     last 'mk' request.  If used with an argument, it returns to a
     vertical position DIST from the top of the page (no previous call
     to 'mk' is necessary in this case).  The default scaling unit is
     'v'.

     If a page break occurs between a 'mk' request and its matching 'rt'
     request, the 'rt' request is silently ignored.

     A simple implementation of a macro to set text in two columns
     follows.  This example also defines a macro to be called when a
     trap is sprung;(1) (*note Page Motions-Footnote-1::) this trap
     macro performs the motion to the next column.

          .nr column-length 1.5i
          .nr column-gap 4m
          .nr bottom-margin 1m
          .
          .de 2c
          .  br
          .  mk
          .  ll \\n[column-length]u
          .  wh -\\n[bottom-margin]u 2c-trap
          .  nr right-side 0
          ..
          .
          .de 2c-trap
          .  ie \\n[right-side] \{\
          .    nr right-side 0
          .    po -(\\n[column-length]u + \\n[column-gap]u)
          .    \" remove trap
          .    wh -\\n[bottom-margin]u
          .  \}
          .  el \{\
          .    \" switch to right side
          .    nr right-side 1
          .    po +(\\n[column-length]u + \\n[column-gap]u)
          .    rt
          .  \}
          ..

     Now let us apply our two-column macro.

          .pl 1.5i
          .ll 4i
          This is a small test that shows how the
          rt request works in combination with mk.

          .2c
          Starting here, text is typeset in two columns.
          Note that this implementation isn't robust
          and thus not suited for a real two-column
          macro.
              => This is a small test that shows how the
              => rt request works in combination with mk.
              =>
              => Starting  here,    isn't    robust
              => text is typeset    and   thus  not
              => in two columns.    suited  for   a
              => Note that  this    real two-column
              => implementation     macro.

   Several escape sequences enable fine control of movement about the
page.

 -- Escape sequence: \v'''expr'''
     Vertically move the drawing position.  EXPR indicates the magnitude
     of motion: positive is downward and and negative upward.  The
     default scaling unit is 'v'.  The motion is relative to the current
     drawing position unless EXPR begins with the boundary-relative
     measurement operator '|'.  *Note Numeric Expressions::.

     Text processing continues at the new drawing position; usually,
     vertical motions should be in balanced pairs to avoid a confusing
     page layout.

     '\v' does not spring a vertical position trap.  This can be useful;
     for example, consider a page bottom trap macro that prints a mark
     in the margin to indicate continuation of a footnote.  *Note
     Traps::.

   A few escape sequences that produce vertical motion are unusual.
They are thought to originate early in AT&T 'nroff' history to achieve
super- and subscripting by half-line motions on line printers and
teletypewriters before the phototypesetter made more precise positioning
available.  They are reckoned in ems--not vees--to maintain continuity
with their original purpose of moving relative to the size of the type
rather than the distance between text baselines (vees).(2)  (*note Page
Motions-Footnote-2::)

 -- Escape sequence: \r
 -- Escape sequence: \u
 -- Escape sequence: \d
     Move upward 1m, upward .5m, and downward .5m, respectively.

Let us see these escape sequences in use.

     Obtain 100 cm\u3\d of \ka\d\092\h'|\nau'\r233\dU.

   In the foregoing we have paired '\u' and '\d' to typeset a
superscript, and later a full em negative ("reverse") motion to place a
superscript above a subscript.  A numeral-width horizontal motion escape
sequence aligns the proton and nucleon numbers, while '\k' marks a
horizontal position to which '\h' returns so that we could stack them.
(We shall discuss these horizontal motion escape sequences presently.)
In serious applications, we often want to alter the type size of the
-scripts and to fine-tune the vertical motions, as the 'groff' 'ms'
package does with its super- and subscripting string definitions.

 -- Escape sequence: \h'''expr'''
     Horizontally move the drawing position.  EXPR indicates the
     magnitude of motion: positive is rightward and negative leftward.
     The default scaling unit is 'm'.  The motion is relative to the
     current drawing position unless EXPR begins with the
     boundary-relative measurement operator '|'.  *Note Numeric
     Expressions::.

   The following string definition sets the TeX logo.  Recall *note
Strings:: regarding the trailing '\"'.

     .ds TeX T\h'-.1667m'\v'.224m'E\v'-.224m'\h'-.125m'X\"

   An input backspace becomes a negative horizontal motion of one word
space; recall *note Manipulating Filling and Adjustment::.  This feature
persists for backward compatibility with early formatters that predate
'nroff' and even Unix itself, and which used it to facilitate
user-directed overstriking for character composition, boldfacing, and
underlining.  GNU 'troff' has explicit features to support each of
these; use them instead.

   Several escape sequences support special cases of horizontal motion.

 -- Escape sequence: \<SPC>
     Move right one word space.  (The input is a backslash followed by a
     space.)  This escape sequence can be thought of as a
     non-adjustable, unbreakable space.  Usually you want '\~' instead;
     see *note Manipulating Filling and Adjustment::.

 -- Escape sequence: \|
     Move one-sixth em to the right on typesetting output devices.  If a
     glyph named '\|' is defined in the current font, its width is used
     instead, even on terminal output devices.

 -- Escape sequence: \^
     Move one-twelfth em to the right on typesetting output devices.  If
     a glyph named '\^' is defined in the current font, its width is
     used instead, even on terminal output devices.

 -- Escape sequence: \0
     Move right by the width of a numeral in the current font.

   Horizontal motions are not discarded at the end of an output line as
word spaces are; recall *note Breaking::.

 -- Escape sequence: \w'''input'''
 -- Register: \n[st]
 -- Register: \n[sb]
 -- Register: \n[rst]
 -- Register: \n[rsb]
 -- Register: \n[ct]
 -- Register: \n[ssc]
 -- Register: \n[skw]
     Interpolate the width of INPUT, as interpreted, in basic units.
     This escape sequence allows several properties of formatted output
     to be measured without writing it out.

          The length of the string 'abc' is \w'abc'u.
              => The length of the string 'abc' is 72u.

     The formatter processes INPUT in a dummy environment: this means
     that font and type size changes, for example, may occur within it
     without affecting subsequent output.

     After each use, '\w' sets several registers.

     'st'
     'sb'
          The maximum vertical displacements of the text baseline above
          and below, respectively.  The sign convention is opposite that
          of relative vertical motions; that is, depth below the
          (original) baseline is negative.  These registers are
          incorrectly documented in the AT&T 'troff' manual as "the
          highest and lowest extent of [the argument to '\w'] relative
          to the baseline".

     'rst'
     'rsb'
          Like 'st' and 'sb', but taking account of the heights and
          depths of glyphs.  In other words, these registers store the
          highest and lowest vertical positions attained by INPUT, doing
          what AT&T 'troff' documented 'st' and 'sb' as doing.

     'ct'
          Characterizes the geometry of glyphs occurring in INPUT.

          0
               only short glyphs, no descenders or tall glyphs

          1
               at least one descender

          2
               at least one tall glyph

          3
               at least one each of a descender and a tall glyph

     'ssc'
          The amount of horizontal space (possibly negative) that should
          be added to the last glyph before a subscript.

     'skw'
          How far to right of the center of the last glyph in the '\w'
          argument, the center of an accent from a roman font should be
          placed over that glyph.

 -- Escape sequence: \kp
 -- Escape sequence: \k(ps
 -- Escape sequence: \k[position]
     Store the horizontal drawing position, relative to that
     corresponding to the start of the input line (ignoring page offset
     and indentation), in a register with the name POSITION
     (one-character name P, two-character name PS).  Use this, for
     example, to later move to the beginning of a word for highlighting
     or other decoration.

 -- Register: \n[hp]
     The horizontal position relative to that at the start of the input
     line.

 -- Register: \n[.k]
     A read-only register containing the current horizontal output
     position (relative to the current indentation).

 -- Escape sequence: \o'''abc...'''
     Overstrike the glyphs of characters A, B, C, ...; the glyphs are
     centered, written, and the drawing position advanced by the widest
     of the glyphs.

 -- Escape sequence: \zc
     Format the character C with zero width; that is, without advancing
     the drawing position.  Use '\z' to overstrike glyphs aligned to
     their left edges, in contrast to '\o''s centering.

 -- Escape sequence: \Z'''input
     Save the drawing position, format INPUT, then restore it.  GNU
     'troff' ignores tabs and leaders in INPUT with an error diagnostic.

     We might implement a strike-through macro thus.

          .de strikeout
          .nr width \w'\\$1'
          \Z@\v'-.25m'\l'\\n[width]u'@\\$1
          ..
          .
          This is
          .strikeout "a test"
          an actual emergency!


File: groff.info,  Node: Page Motions-Footnotes,  Up: Page Motions

   (1) *Note Page Location Traps::.

   (2) At the 'grops' defaults of 10-point type on 12-point vertical
spacing, the difference between half a vee and half an em can be subtle:
large spacings like '.vs .5i' make it obvious.


File: groff.info,  Node: Output Line Annotation,  Next: Drawing Geometric Objects,  Prev: Page Motions,  Up: GNU troff Reference

5.26 Output Line Annotation
===========================

After an output line is broken (and adjusted, if applicable), it can be
annotated in the margins.  You can indicate line numbers on the left,
and apply a margin character on the right.

 -- Request: .nm [start [increment [space [indentation]]]]
 -- Register: \n[ln]
 -- Register: \n[.nm]
     Begin (or, with no arguments, cease) numbering output lines.  START
     assigns the number of the _next_ output line.  Only line numbers
     divisible by INCREMENT (default: '1') bear marks.  The formatter
     reckons the third and fourth arguments in numeral widths ('\0'):
     SPACE configures the horizontal spacing between the number and the
     text (default: '1').  Any given INDENTATION applies to the numbers
     (default: '0').  START must be non-negative and INCREMENT positive.

     The formatter aligns the number to the right in a space of three
     numeral widths plus INDENTATION, then catenates SPACE and the
     output line.  The line length is _not_ reduced.  Depending on the
     value of the page offset (recall *note Line Layout::) numbers wider
     than the allocated space protrude into the left margin, or shift
     the output line to the right.

     Line numbering parameters corresponding to missing arguments are
     not altered.  After numbering is disabled, '.nm +0' resumes it
     using the previously active parameters.

     The parameters of 'nm' are associated with the environment (*note
     Environments::).

     While numbering is enabled, the output line number register 'ln' is
     updated as each line is output, even if no line number is formatted
     with it because it is being skipped (it is not a multiple of
     INCREMENT) or because numbering is suppressed (see the 'nn' request
     below).

     The '.nm' register tracks the enablement status of numbering.
     Temporary suspension of numbering with the 'nn' request does _not_
     alter its value.

          .po 5n
          .ll 44n
          Programming,
          when stripped of all its circumstantial irrelevancies,
          .nm 999 1 1 -4
          boils down to no more and no less than
          .nm +0 3
          very effective thinking so as to avoid unmastered
          .nn 2
          complexity,
          to very vigorous separation of your many
          different concerns.
          .br
          \(em Edsger Dijkstra
          .sp
          .nm 1 1 1
          This guy's arrogance takes your breath away.
          .br
          \(em John Backus
              =>      Programming,  when  stripped of all its cir-
              =>  999 cumstantial irrelevancies, boils down to  no
              =>      more  and no less than very effective think-
              =>      ing so as to avoid unmastered complexity, to
              =>      very vigorous separation of your  many  dif-
              =>      ferent concerns.
              => 1002 -- Edsger Dijkstra
              =>
              =>    1 This guy's arrogance takes your breath away.
              =>    2 -- John Backus

 -- Request: .nn [skip]
 -- Register: \n[.nn]
     Suppress numbering of the next SKIP output lines counted by the
     'nm' request.  If SKIP is '0', cancel suppression.  The default
     is 1.  'nn' can be invoked when line numbering is not active;
     suppression of numbering takes effect for SKIP lines once 'nm'
     enables it.

     The '.nn' register stores the count of lines remaining in the
     environment for which numbering is suppressed while output line
     numbering is enabled.

     This count is associated with the environment (*note
     Environments::).

   To test whether the current output line will be numbered, you must
check both the '.nm' and '.nn' registers.

       .de is-numbered
       .  nop This line
       .  ie (\\n[.nm] & (1-\\n[.nn])) IS
       .  el                           ISN'T
       .  nop numbered.
       .  br
       ..
       Test line numbering.
       .is-numbered
       .nm 1
       .nn 1
       .is-numbered
       .is-numbered
       .nm
       .is-numbered
         => Test line numbering.  This line ISN'T numbered.
         => This line ISN'T numbered.
         =>   1 This line IS numbered.
         => This line ISN'T numbered.

 -- Request: .mc [margin-character [distance]]
     Begin (or, with no arguments, cease) writing a "margin-character"
     to the right of each output line.  The DISTANCE argument separates
     MARGIN-CHARACTER from the right margin.  If absent, the most recent
     value is used; the default is 10 points.  If an output line exceeds
     the line length, the margin character is appended to it.  No margin
     character is written on lines produced by the 'tl' request.

     The margin character is a property of the output line.  Only one
     margin character is in effect at one time; the most recent 'mc'
     call determines its value.  If the margin character is disabled
     before an output line breaks, none is output (but see below).

     The margin character is associated with the environment (*note
     Environments::).

          .ll 5i
          .nf
          .mc \[br]
          This paragraph is marked with a margin character.
          .sp
          As seen above, vertical space isn't thus marked.
          \&
          An output line that is present, but empty, is.
              => This paragraph is marked with a margin character.  |
              =>
              => As seen above, vertical space isn't thus marked.   |
              =>                                                    |
              => An output line that is present, but empty, is.     |

   For compatibility with AT&T 'troff', a call to 'mc' to set the margin
character can't be undone immediately; at least one line gets a margin
character.

     .ll 10n
     .nf
     .mc |
     .mc *
     .mc
     foo
     bar
         => foo        *
         => bar

   The margin character mechanism is commonly used to annotate changes
in documents.  The 'groff' distribution ships a program, 'gdiffmk', to
assist with this task.(1)  (*note Output Line Annotation-Footnote-1::)


File: groff.info,  Node: Output Line Annotation-Footnotes,  Up: Output Line Annotation

   (1) Historically, tools named 'nrchbar' and 'changebar' were
developed for marking changes with margin characters and could be found
in archives of the 'comp.sources.unix' Usenet group.  Some proprietary
Unices also offer(ed) a 'diffmk' program.


File: groff.info,  Node: Drawing Geometric Objects,  Next: Deferring Output,  Prev: Output Line Annotation,  Up: GNU troff Reference

5.27 Drawing Geometric Objects
==============================

A few of the formatter's escape sequences draw lines and other geometric
objects.  Combined with each other and with page motion commands (*note
Page Motions::), a wide variety of figures is possible.  For complex
drawings, these operations can be cumbersome: the preprocessors 'pic' or
'grn' are typically used instead.

   The '\l' and '\L' escape sequences draw horizontal and vertical
sequences of glyphs, respectively.  Even the simplest of output devices
supports them.  They require an argument specifying the length of the
rule (line) to be drawn, optionally followed by a single ordinary or
special character with which to draw the rule if the default is not
desired.  If the character is valid in a numerical expression, put '\&'
after L to disambiguate the input.

 -- Escape sequence: \l'''l'''
 -- Escape sequence: \l'''lc'''
     Draw a horizontal line of length L from the drawing position.
     Rightward motion is positive.  Afterward, the drawing position is
     at the right end of the line.  The default scaling unit is 'm'.
     The default glyph is the baseline rule special character, '\[ru]'.

          \l'4i\&-'
              => ----------------------------------------

     Let us see how to draw a box around a word using a macro.

          .de textbox
          \[br]\\$*\[br]\l'|0\[rn]'\l'|0\[ul]'
          ..

     The foregoing outputs a box rule (a vertical line), the text
     argument(s), and another box rule.  We employ the boundary-relative
     measurement operator '|'.  Finally, the line-drawing escape
     sequences draw a radical extender (a form of overline) and an
     underline from the drawing position to the position corresponding
     to beginning of the _input_ line.  The formatter leaves the drawing
     position at the right-hand box rule even though the line lengths
     are negative, as noted above.

 -- Escape sequence: \L'''l'''
 -- Escape sequence: \L'''lc'''
     Draw a vertical line of length L from the drawing position.
     Downward motion is positive.  The default scaling unit is 'v'.  The
     default glyph is the box rule, '\[br]'.  As with vertical motion
     escape sequences, text processing continues where the line ends.

          $ nroff <<EOF
          This is a \L'3v'test.
          EOF
              => This is a
              =>           |
              =>           |
              =>           |test.

     When writing text, the drawing position is at the text baseline;
     recall *note Page Geometry::.

   The '\D' escape sequence provides "drawing commands" that direct the
output device to render geometrical objects rather than glyphs.
Specific devices may support only a subset, or may feature additional
ones; consult the man page for the output driver in use.  Terminals in
particular implement almost none.  *Note Graphics Commands::.

   Rendering starts at the drawing position; when finished, the drawing
position is left at the rightmost point of the object, even for closed
figures, except where noted.  GNU 'troff' draws stroked (outlined)
objects with the stroke color, and shades filled ones with the fill
color.  *Note Colors::.  Coordinates H and V are horizontal and vertical
motions relative to the drawing position or previous point in the
command.  The default scaling unit for horizontal measurements (and
diameters of circles) is 'm'; for vertical ones, 'v'.

   Circles, ellipses, and polygons can be drawn filled or stroked.
These are independent properties; if you want a filled, stroked figure,
you must draw the same figure twice using each drawing command.  A
filled figure is always smaller than an outlined one because the former
is drawn only within its defined area, whereas strokes have a line
thickness (set with '\D't'').

     \h'1i'\v'1i'\
     \# increase line thickness
     \Z'\D't 5p''\
     \# draw stroked (unfilled) polygon
     \Z'\D'p 3 3 -6 0''\
     \# draw filled (solid) polygon
     \Z'\D'P 3 3 -6 0''

 -- Escape sequence: \D'''command argument ...'''
     Drawing command escape sequence parameters begin with an ordinary
     character, COMMAND, selecting the type of object to be drawn,
     followed by ARGUMENTs whose meaning is determined by COMMAND.

     '\D'~ H1 V1 ... HN VN''
          Draw a B-spline to each point in sequence, leaving the drawing
          position at (HN, VN).

     '\D'a HC VC H V''
          Draw a circular arc centered at (HC, VC) counterclockwise from
          the drawing position to a point (H, V) relative to the center.
          (1) (*note Drawing Geometric Objects-Footnote-1::)

     '\D'c D''
          Draw a circle of diameter D with its leftmost point at the
          drawing position.

     '\D'C D''
          As '\D'C ...'', but the circle is filled.

     '\D'e H V''
          Draw an ellipse of width H and height V with its leftmost
          point at the drawing position.

     '\D'E X Y''
          As '\D'e ...'', but the ellipse is filled.

     '\D'l DX DY''
          Draw line from the drawing position to (H, V).

          The following is a macro for drawing a box around a text
          argument; for simplicity, the box margin is a fixed at 0.2m.

               .de TEXTBOX
               .  nr @wd \w'\\$1'
               \h'.2m'\
               \h'-.2m'\v'(.2m - \\n[rsb]u)'\
               \D'l 0 -(\\n[rst]u - \\n[rsb]u + .4m)'\
               \D'l (\\n[@wd]u + .4m) 0'\
               \D'l 0 (\\n[rst]u - \\n[rsb]u + .4m)'\
               \D'l -(\\n[@wd]u + .4m) 0'\
               \h'.2m'\v'-(.2m - \\n[rsb]u)'\
               \\$1\
               \h'.2m'
               ..

          The argument is measured with the '\w' escape sequence.  Its
          width is stored in register '@wd'.  '\w' also sets the
          registers 'rst' and 'rsb'; these contain its maximum vertical
          extents of the argument.  Then, four lines are drawn to form a
          box, offset by the box margin.

     '\D'p H1 V1 ... HN VN''
          Draw polygon with vertices at the drawing position and each
          point in sequence.  GNU 'troff' closes the polygon by drawing
          a line from (HN, VN) back to the initial drawing position.
          Afterward, the drawing position is left at (HN, VN).

     '\D'P DX1 DY1 DX2 DY2 ...''
          As '\D'P ...'', but the polygon is filled.  'groff' does not
          specify how the output device must fill concave or
          self-intersecting polygons.

          The following macro is like the '\D'l'' example, but shades
          the box.  We draw the box before writing the text because
          colors in GNU 'troff' have no transparency; in the opposite
          order, the filled polygon would occlude the text.

               .de TEXTBOX
               .  nr @wd \w'\\$1'
               \h'.2m'\
               \h'-.2m'\v'(.2m - \\n[rsb]u)'\
               \M[lightcyan]\
               \D'P 0 -(\\n[rst]u - \\n[rsb]u + .4m) \
                    (\\n[@wd]u + .4m) 0 \
                    0 (\\n[rst]u - \\n[rsb]u + .4m) \
                    -(\\n[@wd]u + .4m) 0'\
               \h'.2m'\v'-(.2m - \\n[rsb]u)'\
               \M[]\
               \\$1\
               \h'.2m'
               ..

     '\D't N''
          Set the stroke thickness of geometric objects to N basic
          units.  A zero N selects the minimum supported thickness.  A
          negative N selects a thickness proportional to the type size;
          this is the default.

   In a hazy penumbra between text rendering and drawing commands we
locate the bracket-building escape sequence, '\b'.  It can assemble
glyphs that appear large by vertically stacking ordinary ones.

 -- Escape sequence: \b'''contents'''
     Pile and center a sequence of glyphs vertically on the output line.
     "Piling" stacks glyphs corresponding to each character in CONTENTS,
     read from left to right, and placed from top to bottom.  GNU
     'troff' separates the glyphs vertically by 1m, and the pile itself
     is centered 0.5m above the text baseline.  The horizontal drawing
     position is then advanced by the width of the widest glyph in the
     pile.

     This rather inflexible positioning algorithm doesn't work with the
     'dvi' output device since its bracket pieces vary in height.
     Instead, use the 'eqn' preprocessor.

     *note Manipulating Spacing:: describes how to adjust the vertical
     spacing of the output line with the '\x' escape sequence.

     The application of '\b' that lends its name is construction of
     brackets, braces, and parentheses when typesetting mathematics.  We
     might construct a large opening (left) brace as follows.

          \b'\[lt]\[bv]\[lk]\[bv]\[lb]'

     See 'groff_char(7)' for a list of special character identifiers.


File: groff.info,  Node: Drawing Geometric Objects-Footnotes,  Up: Drawing Geometric Objects

   (1) (HC, VC) is adjusted to the point nearest the perpendicular
bisector of the arc's chord.


File: groff.info,  Node: Deferring Output,  Next: Traps,  Prev: Drawing Geometric Objects,  Up: GNU troff Reference

5.28 Deferring Output
=====================

A few 'roff' language elements are generally not used in simple
documents, but arise as page layouts become more sophisticated and
demanding.  "Environments" collect formatting parameters like line
length and typeface.  A "diversion" stores formatted output for later
use.  A "trap" is a condition on the input or output, tested
automatically by the formatter, that is associated with a macro:
fulfilling the condition "springs" the trap--calls the macro.

   Footnote support often exercises all three of the foregoing features.
A simple implementation might work as follows.  The author writes a pair
of macros: one starts a footnote and the other ends it.  They further
set a trap a small distance above the page bottom, reserving a footnote
area.  The author calls the first macro where a footnote mark is
desired.  The macro establishes a diversion so that the footnote text is
collected at the place in the body text where its corresponding mark
appears.  It further creates an environment for the footnote so that it
sets using a smaller typeface.  The footnote text is formatted in the
diversion using that environment but it does not yet appear in the
output.  The document author calls the footnote end macro, which returns
to the previous environment and ends the diversion.  Later, after body
text nearly fills the page, the trap springs.  The macro called by the
trap draws a line across the page and emits the stored diversion by
calling it like a macro.  Thus, the footnote renders.

   Diversions and traps make the text formatting process non-linear.
Let us imagine a set of text lines or paragraphs labelled 'A', 'B', and
so on.  If we set up a trap that produces text 'T' (as a page footer,
say), and we also use a diversion to store the formatted text 'D', then
a document with input text in the order 'A B C D E F' might render as 'A
B C E T F'.  The diversion 'D' is never output if we do not call it.

   Environments of themselves are not a source of non-linearity in
document formatting: environment switches have immediate effect.  One
could always write a macro to change as many formatting parameters as
desired with a single convenient call.  But because diversions can be
nested and macros called by traps that are sprung by other trap-called
macros, they may be interpolated in varying contexts.  For example,
consider a page header that is always to be set in Helvetica.  A
document that uses Times for most of its body text, but Courier for
displayed code examples, poses a challenge if a page break occurs in the
middle of a code display; if the header trap assumes that the "previous
font" is always Times, the rest of the example will be formatted in the
wrong typeface.  One could carefully save all formatting parameters upon
entering the trap and restore them upon leaving it, but this is verbose,
error-prone, and not future-proof as the 'groff' language develops.
Environments save us considerable effort.


File: groff.info,  Node: Traps,  Next: Diversions,  Prev: Deferring Output,  Up: GNU troff Reference

5.29 Traps
==========

"Traps" are locations in the output, or conditions on the input that,
when reached or fulfilled, call a specified macro.  These traps can
occur at a given location either on the page or in the current diversion
(together, these are known as vertical position traps), at a blank line,
at a line with leading space characters, after a quantity of input
lines, or at the end of input.  Setting a trap is also called "planting"
one.  It is said that a trap is "sprung" if its condition is fulfilled.
The formatter passes no arguments to macros called by traps.

* Menu:

* Vertical Position Traps::
* Input Line Traps::
* Blank Line Traps::
* Leading Space Traps::
* End-of-input Traps::


File: groff.info,  Node: Vertical Position Traps,  Next: Input Line Traps,  Up: Traps

5.29.1 Vertical Position Traps
------------------------------

A "vertical position trap" calls a macro when the formatter's vertical
drawing position reaches or passes, in the downward direction, a certain
location on the output page or in a diversion.  Its applications include
setting page headers and footers, body text in multiple columns, and
footnotes.

 -- Request: .vpt [b]
 -- Register: \n[.vpt]
     Enable or disable vertical position traps per Boolean expression B.
     They are enabled by default, and if B is omitted.  Vertical
     position traps are those set by the 'wh' request or by 'dt' within
     a diversion.  Vertical position trap enablement is global.  Its
     status is stored in the '.vpt' read-only register.

     A page can't be ejected if vertical position traps are disabled.(1)
     (*note Vertical Position Traps-Footnote-1::)

* Menu:

* Page Location Traps::
* The Implicit Page Trap::
* Diversion Traps::


File: groff.info,  Node: Vertical Position Traps-Footnotes,  Up: Vertical Position Traps

   (1) *Note The Implicit Page Trap::.


File: groff.info,  Node: Page Location Traps,  Next: The Implicit Page Trap,  Up: Vertical Position Traps

5.29.1.1 Page Location Traps
............................

A "page location trap" is a vertical position trap that applies to the
page; that is, to the top-level diversion.  Many can be present; manage
them with the 'wh' and 'ch' requests.

 -- Request: .wh dist [name]
     Plant macro NAME as page location trap at DIST.  The default
     scaling unit is 'v'.  Non-negative values for DIST set the trap
     relative to the top of the page; negative values set the trap
     relative to the bottom of the page.  It is not possible to plant a
     trap less than one basic unit from the page bottom: the formatter
     interprets a DIST of '-0' as '0', the top of the page.  'wh'
     removes any existing _visible_ trap (see below) at DIST is removed;
     this is its sole function if NAME is missing.

     A trap springs only if it is "visible", meaning that its location
     is reachable on the page(1) (*note Page Location
     Traps-Footnote-1::) and it is not hidden by another trap at the
     same location already planted there.

     A macro package might set headers and footers as follows; this
     example configures vertical margins of one inch to the body text,
     and one half-inch to the titles.  Observe the use of the no-break
     control character with the 'sp' and 'bp' requests to position our
     text baselines and prevent a partially collected line from being
     written outside the body text, and the page number character '%'
     used with the 'tl' request.

          .\" hdfo.roff
          .de hd                  \" page header
          '  sp .5i
          .  tl '\\*(Ti''\\*(Da'  \" title and date strings
          '  sp |1i
          ..
          .de fo                  \" page footer
          '  sp .5i-1v
          .  tl ''%''
          '  bp
          ..
          .wh 0   hd              \" trap at top of the page
          .wh -1i fo              \" trap 1 inch from bottom

     *Caution:* A word about measurements is in order.  Recall that the
     'sp' request vertically spaces such that the next text baseline (of
     one vee in height by definition) sets with the amount of space
     given to 'sp''s argument _above_ it.  Thus in the example above,
     when the 'hd' trap springs at vertical position '0', invoking 'sp
     .5i', we get the desired half-inch of top margin.  With the 'ft'
     trap, we space after the body text by one half-inch _minus one vee_
     to leave a half-inch bottom margin.  The footer title, if taller
     than a baseline rule, thus "encroaches" into the half-inch margin
     between the body text and the bottom margin, just as the header
     title symmetrically intrudes into the half-inch of space between
     its own cap-height and that of the top of the body text.

     To use these traps, copy the above (or load it from a file with the
     'so' or 'mso' requests), then set up the strings it uses.

          .so hdfo.roff
          .ds Ti Final Report\"
          .ds Da 21 May 2023\"
          .ti
          On 5 August of last year,
          this committee tasked me with the investigation of the
          CFIT (controlled flight into terrain) incident of
          .\" ...and so on...

     A trap above the top or at or below the bottom of the page can be
     made visible by either moving it into the page area or increasing
     the page length so that the trap is on the page.  A negative trap
     value always uses the _current_ page length; the formatter does not
     convert it to an absolute vertical position.  We can use the 'pwh'
     request to dump page location traps to the standard error stream
     (*note Debugging::).  GNU 'troff' reports their positions in basic
     units, and includes empty slots in the list, where a trap had been
     planted but subsequently (re)moved, because they can affect the
     visibility of subsequently planted traps.  An 'nroff' device
     example follows.

          .pl 5i
          .wh -1i xx
          .pwh
              error-> xx      -240
          .pl 100i
          .pwh
              error-> xx      -240

     It is possible to have more than one trap at the same location
     (although only one at a time can be visible); to achieve this, the
     traps must be defined at different locations, then moved to the
     same place with the 'ch' request.  In the following example, the
     many empty lines caused by the 'bp' request are not shown in the
     output.

          .de a
          .  nop a
          ..
          .de b
          .  nop b
          ..
          .de c
          .  nop c
          ..
          .
          .wh 1i a
          .wh 2i b
          .wh 3i c
          .bp
              => a b c
          .ch b 1i
          .ch c 1i
          .bp
              => a
          .ch a 0.5i
          .bp
              => a b

 -- Register: \n[.t]
     The read-only register '.t' holds the distance to the next vertical
     position trap.  If no such traps exist between the drawing position
     and the bottom of the page, it contains the distance to the page
     bottom.  Within a diversion, in the absence of a diversion trap,
     this distance is the maximum possible vertical position supported
     by the output device.

 -- Request: .ch name [dist]
     Change the location of a trap by moving macro NAME to new location
     DIST, or by unplanting it altogether if DIST is absent.  The
     default scaling unit is 'v'.  Parameters to 'ch' are specified in
     the opposite order from 'wh'.  If NAME is the earliest planted
     macro of multiple traps at the same location, (re)moving it from
     that location exposes the macro next least recently planted at the
     same place.(2)  (*note Page Location Traps-Footnote-2::)

     Changing a trap's location is useful for building up footnotes in a
     diversion to allow more space at the bottom of the page for them.

   The same macro can be installed simultaneously at multiple locations;
however, only the earliest-planted instance--that has not yet been
deleted with 'wh'--will be moved by 'ch'.  The following example (using
an 'nroff' device) illustrates this behavior.  Blank lines have been
elided from the output.

     .de T
     Trap sprung at \\n(nlu.
     .br
     ..
     .wh 1i T
     .wh 2i T
     foo
     .sp 11i
     .bp
     .ch T 4i
     bar
     .sp 11i
     .bp
     .ch T 5i
     baz
     .sp 11i
     .bp
     .wh 5i
     .ch T 6i
     qux
     .sp 11i
         => foo
         => Trap sprung at 240u.
         => Trap sprung at 480u.
         => bar
         => Trap sprung at 480u.
         => Trap sprung at 960u.
         => baz
         => Trap sprung at 480u.
         => Trap sprung at 1200u.
         => qux
         => Trap sprung at 1440u.

 -- Register: \n[.ne]
     The read-only register '.ne' contains the amount of space that was
     needed in the last 'ne' request that caused a trap to be sprung; it
     is useful in conjunction with the '.trunc' register.  *Note Page
     Control::.  Since the '.ne' register is set only by traps, it
     doesn't make sense to interpolate it outside of macros called by
     traps.

 -- Register: \n[.trunc]
     A read-only register containing the amount of vertical space
     truncated from an 'sp' request by the most recently sprung vertical
     position trap, or, if the trap was sprung by an 'ne' request, minus
     the amount of vertical motion produced by the 'ne' request.  In
     other words, at the point a trap is sprung, it represents the
     difference of what the vertical position would have been but for
     the trap, and what the vertical position actually is.  Since the
     '.trunc' register is set only by traps, it doesn't make sense to
     interpolate it outside of macros called by traps.

 -- Register: \n[.trap]
     This read-only, string-valued register interpolates the name of the
     next vertical position trap that will be sprung.

 -- Register: \n[.pe]
     This Boolean-valued, read-only register interpolates 1 while a page
     is being ejected, and 0 otherwise.

     In the following example, we plant the same trap at the top and the
     bottom of the page.  We also make the trap report its name and the
     vertical drawing position.

          .de T
          .tm \\$0: page \\n%, nl=\\n[nl] .pe=\\n[.pe]
          ..
          .ll 46n
          .wh 0 T
          .wh -1v T
          Those who can make you believe absurdities can make you
          commit atrocities. \[em] Voltaire
              error-> T: page 1, nl=0 .pe=0
              error-> T: page 1, nl=2600 .pe=1
              => Those who can make you believe absurdities can
              => make you commit atrocities. -- Voltaire

   When designing macros, keep in mind that diversions and traps do not
normally interact.  For example, if a trap calls a header macro (while
outputting a diversion) that tries to change the font on the current
page, the effect is not visible before the diversion has completely been
printed (except for input protected with '\!' or '\?') since the data in
the diversion is already formatted.  In most cases, this is not the
expected behaviour.


File: groff.info,  Node: Page Location Traps-Footnotes,  Up: Page Location Traps

   (1) A trap planted at '20i' or '-30i' cannot spring on a page of
length '11i'.

   (2) It may help to think of each trap location as maintaining a
queue; 'wh' operates on the head of the queue, and 'ch' operates on its
tail.  Only the trap at the head of the queue is visible.


File: groff.info,  Node: The Implicit Page Trap,  Next: Diversion Traps,  Prev: Page Location Traps,  Up: Vertical Position Traps

5.29.1.2 The Implicit Page Trap
...............................

If, after starting GNU 'troff' without loading a macro package, you use
the 'pwh' request to dump a list of the active traps to the standard
error stream,(1) (*note The Implicit Page Trap-Footnote-1::) nothing is
reported.  Yet the '.t' register will report a steadily decreasing value
with every output line your document produces, and once the value of
'.t' gets to within '.V' of zero, you will notice that something
trap-like happens--the page is ejected, a new one begins, and the value
of '.t' becomes large once more.

   This "implicit page trap" always exists in the top-level
diversion;(2) (*note The Implicit Page Trap-Footnote-2::) its purpose is
to eject the current page and start the next one.  It works like a trap
in some ways but not others.  It has no name, so it cannot be moved or
deleted with 'wh' or 'ch' requests.  You cannot hide it by placing
another trap at its location, and can move it only by redefining the
page length with 'pl'.  Its operation is suppressed when vertical page
traps are disabled with GNU 'troff''s 'vpt' request.


File: groff.info,  Node: The Implicit Page Trap-Footnotes,  Up: The Implicit Page Trap

   (1) *Note Debugging::.

   (2) *Note Diversions::.


File: groff.info,  Node: Diversion Traps,  Prev: The Implicit Page Trap,  Up: Vertical Position Traps

5.29.1.3 Diversion Traps
........................

A diversion is not formatted in the context of a page, so it lacks page
location traps; instead it can have a "diversion trap".  There can exist
at most one such vertical position trap per diversion.

 -- Request: .dt [dist name]
     Set a trap _within_ a diversion at location DIST, which is
     interpreted relative to diversion rather than page boundaries.  If
     invoked with fewer than two arguments, any diversion trap in the
     current diversion is removed.  The register '.t' works within
     diversions.  It is an error to invoke 'dt' in the top-level
     diversion.  *Note Diversions::.


File: groff.info,  Node: Input Line Traps,  Next: Blank Line Traps,  Prev: Vertical Position Traps,  Up: Traps

5.29.2 Input Line Traps
-----------------------

 -- Request: .it [n name]
 -- Request: .itc [n name]
 -- Register: \n[.it]
 -- Register: \n[.itc]
 -- Register: \n[.itm]
     Set an input line trap, calling macro NAME after processing the
     next N productive input lines (recall *note Manipulating Filling
     and Adjustment::).  Any existing input line trap in the environment
     is replaced.  Without arguments, 'it' and 'itc' clear any input
     line trap that has not yet sprung.

     Consider a macro '.ST S N' which sets the next N input lines in the
     font style S.

          .de ST \" Use style $1 for next $2 text lines.
          .  it \\$2 ES
          .  ft \\$1
          ..
          .de ES \" end ST
          .  ft R
          ..
          .ST I 1
          oblique
          face
          .ST I 1
          oblique\c
          face
              => oblique face obliqueface (second "face" upright)

     Unlike the 'ce' and 'rj' requests, 'it' counts lines interrupted
     with the '\c' escape sequence separately (*note Line
     Continuation::); 'itc' does not.  To see the difference, let's
     change the previous example to use 'itc' instead.

          ...
          .  itc \\$2 ES
          ...
              => oblique face obliqueface (second "face" oblique)

     You can think of the 'ce' and 'rj' requests as implicitly creating
     an input line trap with 'itc' that schedules a break when the trap
     is sprung.

          .de BR
          .  br
          .  internal: disable centering-without-filling
          ..
          .
          .de ce
          .  if \\n[.br] .br
          .  itc \\$1 BR
          .  internal: enable centering-without-filling
          ..

     The '.it', '.itc', and '.itm' registers report the number of input
     lines remaining in a pending input trap, a Boolean indication of
     whether that pending input trap honors output line continuation,
     and the name of the macro associated with the pending input trap,
     respectively.  All are read-only; '.itm' is string-valued as well.

     Let us consider in more detail the sorts of input lines that are or
     are not "productive".

          .de Trap
          TRAP SPRUNG
          ..
          .de Mac
          .if r a \l'5n'
          ..
          .it 2 Trap
          .
          foo
          .Mac
          bar
          baz
          .it 1 Trap
          .sp \" moves, but does not write or draw
          qux
          .itc 1 Trap
          \h'5n'\c \" moves, but does not write or draw
          jat

     When 'Trap' gets called depends on whether the 'a' register is
     defined; the control line with the 'if' request may or may not
     produce written output.  We also see that the spacing request 'sp',
     while certainly affecting the output, does not spring the input
     line trap.  Similarly, the horizontal motion escape sequence '\h'
     also affected the output, but was not "written".  Observe that we
     had to follow it with '\c' and use 'itc' to prevent the newline at
     the end of the text line from causing a word break, which, like an
     ordinary space character, counts as written output.

          $ groff -T ascii input-trap-example.groff
              => foo bar TRAP SPRUNG baz
              =>
              => qux TRAP SPRUNG      jat TRAP SPRUNG
          $ groff -T ascii -r a1 input-trap-example.groff
              => foo _____ TRAP SPRUNG bar baz
              =>
              => qux TRAP SPRUNG      jat TRAP SPRUNG

   Input line traps are associated with the environment (*note
Environments::); switching to another environment suspends the current
input line trap, and going back resumes it, restoring the count of
qualifying lines enumerated in that environment.


File: groff.info,  Node: Blank Line Traps,  Next: Leading Space Traps,  Prev: Input Line Traps,  Up: Traps

5.29.3 Blank Line Traps
-----------------------

 -- Request: .blm [name]
     Set a blank line trap, calling the macro NAME when GNU 'troff'
     encounters a blank line in input, instead of the usual behavior
     (*note Breaking::).  A line consisting only of spaces is also
     treated as blank and subject to this trap.  If no argument is
     supplied, the default blank line behavior is (re-)established.


File: groff.info,  Node: Leading Space Traps,  Next: End-of-input Traps,  Prev: Blank Line Traps,  Up: Traps

5.29.4 Leading Space Traps
--------------------------

 -- Request: .lsm [name]
 -- Register: \n[lsn]
 -- Register: \n[lss]
     Set a leading space trap, calling the macro NAME when GNU 'troff'
     encounters leading spaces on a text line; the implicit line break
     that normally happens in this case is suppressed.  The formatter
     stores the count of leading spaces on the text line in register
     'lsn', and the amount of corresponding horizontal motion in
     register 'lss', irrespective of whether a leading space trap is
     set.  When it is, GNU 'troff' removes the leading spaces from the
     input line and produces no motion before calling NAME.

     If no argument is supplied, GNU 'troff' reëstablishes the default
     handling of leading spaces on text lines (breaking the line when
     filling, and formatting a horizontal motion of '\n[lsn]' word
     spaces).


File: groff.info,  Node: End-of-input Traps,  Prev: Leading Space Traps,  Up: Traps

5.29.5 End-of-input Traps
-------------------------

 -- Request: .em [name]
     Set a trap at the end of input, calling macro NAME after the last
     line of the last input file has been processed.  If no argument is
     given, any existing end-of-input trap is removed.

     For example, if the document had to have a section at the bottom of
     the last page for someone to approve it, the 'em' request could be
     used.

          .de approval
          \c
          .  ne 3v
          .  sp (\\n[.t]u - 3v)
          .  in +4i
          .  lc _
          .  br
          Approved:\t\a
          .  sp
          Date:\t\t\a
          ..
          .
          .em approval

     The '\c' in the above example needs explanation.  For historical
     reasons (compatibility with AT&T 'troff'), the end-of-input macro
     exits as soon as it causes a page break if no partially collected
     line remains.(1)  (*note End-of-input Traps-Footnote-1::)

     Let us assume that there is no '\c' in the above 'approval' macro,
     that the page is full, and last output line has been broken with,
     say, a 'br' request.  Because there is no more room, a 'ne' request
     at this point causes a page ejection, which in turn makes 'troff'
     exit immediately as just described.  In most situations, this is
     not desired; people generally want to format the input after 'ne'.

     To force processing of the whole end-of-input macro independently
     of this behavior, it is thus advisable to (invisibly) ensure the
     existence of a partially collected line ('\c') whenever there is a
     chance that a page break can happen.  In the above example,
     invoking the 'ne' request ensures that there is room for the
     subsequent formatted output on the same page, so we need insert
     '\c' only once.

     The next example shows how to append three lines, then start a new
     page unconditionally.  Since '.ne 1' doesn't give the desired
     effect--there is always one line available or we are already at the
     beginning of the next page--we temporarily increase the page length
     by one line so that we can use '.ne 2'.

          .de EM
          .pl +1v
          \c
          .ne 2
          line one
          .br
          \c
          .ne 2
          line two
          .br
          \c
          .ne 2
          line three
          .br
          .pl -1v
          \c
          'bp
          ..
          .em EM

     This specific feature affects only the first potential page break
     caused by the end-of-input macro; further page breaks emitted by
     the macro are handled normally.

     Another possible use of the 'em' request is to make GNU 'troff'
     emit a single large page instead of multiple pages.  For example,
     one may want to produce a long plain text file for reading in a
     terminal or emulator without page footers and headers interrupting
     the body of the document.  One approach is to set the page length
     at the beginning of the document to a very large value to hold all
     the text and automatically adjust it to the exact height of the
     document after the text has been output.

          .de adjust-page-length
          .  br
          .  pl \\n[nl]u \" \n[nl]: current vertical position
          ..
          .
          .de single-page-mode
          .  pl \n[.R]u
          .  em adjust-page-length
          ..
          .
          .\" Activate the above code if configured.
          .if \n[do-continuous-rendering] \
          .  single-page-mode

     Since only one end-of-input trap exists and another macro package
     may already use it, care must be taken not to break the mechanism.
     A simple solution would be to append the above macro to the macro
     package's end-of-input macro using the 'am' request.


File: groff.info,  Node: End-of-input Traps-Footnotes,  Up: End-of-input Traps

   (1) While processing an end-of-input macro, the formatter assumes
that the next page break must be the last; it goes into "sudden death
overtime".


File: groff.info,  Node: Diversions,  Next: Punning Names,  Prev: Traps,  Up: GNU troff Reference

5.30 Diversions
===============

In 'roff' systems it is possible to format text as if for output, but
instead of writing it immediately, one can "divert" the formatted text
into a named storage area.  It is retrieved later by specifying its name
after a control character.  The formatter uses the same name space for
such diversions as for strings and macros; recall *note Identifiers::.
Such text is sometimes said to be "stored in a macro", but this coinage
obscures the important distinction between macros and strings on one
hand and diversions on the other; the former store _unformatted_ input
text, and the latter capture _formatted_ output.(1)  (*note
Diversions-Footnote-1::) Diversions also do not interpret arguments.
Applications of diversions include footnotes, tables of contents,
indices, and "keeps" (preventing a page break from occurring at an
inconvenient place by forcing a set of output lines to be set as a
group).  For orthogonality it is said that GNU 'troff' populates the
"top-level diversion" if no diversion is active (that is, formatted
output is being "diverted" directly to the output device).  The
top-level diversion has no name.

   Dereferencing an undefined diversion creates an empty one of that
name.(2)  (*note Diversions-Footnote-2::) A diversion does not exist for
the purpose of testing with the 'd' conditional expression operator
until its initial definition ends; recall *note Operators in
Conditionals::.  The following requests create and alter diversions.

 -- Request: .di [name]
 -- Request: .da [name]
     Start collecting formatted output in a diversion called NAME.  The
     'da' request appends to a diversion called NAME, creating it if
     necessary.  If NAME already exists as an alias, the target of the
     alias is replaced or appended to; recall *note Strings::.  The
     pending output line is diverted as well.  Switching to another
     environment (with the 'ev' request) before invoking 'di' or 'da'
     avoids including any pending output line in the diversion.(3)
     (*note Diversions-Footnote-3::)

     Invoking 'di' or 'da' without an argument stops diverting output to
     the diversion named by the most recent corresponding request.
     Invoking 'di' or 'da' without an argument when no diversion is
     being populated does nothing.(4)  (*note Diversions-Footnote-4::)

          .ll 56n
          Ahoy, me hearties,
          I traveled unto a distant isle,
          .br
          .di HT
          and thereupon I lay a vast treasure,
          .br
          .di
          .HT
          .br
          which none o' ye shall ever see.
              => Ahoy, mateys, I traveled unto a distant isle,
              => and thereupon I lay a vast treasure,
              => which none o' ye shall ever see.

   GNU 'troff' supports "box" requests to exclude a partially collected
line from a diversion, as this is often desirable.

 -- Request: .box [name]
 -- Request: .boxa [name]
     Divert (or append) output to NAME, similarly to the 'di' and 'da'
     requests, respectively.  Any pending output line is _not_ included
     in the diversion.  Without an argument, stop diverting output; any
     pending output line inside the diversion is discarded.

          .ll 56n
          Ahoy, mateys,
          I traveled unto a distant isle,
          .br
          .box SECRET
          and thereupon I lay a vast treasure,
          .br
          accurst wi' neutron activation,
          .box
          .SECRET
          .br
          which none o' ye shall ever see.
              => Ahoy, mateys, I traveled unto a distant isle,
              => and thereupon I lay a vast treasure,
              => which none o' ye shall ever see.

   Apart from pending output line inclusion and the request names that
populate them, boxes are handled exactly as diversions are.  All of the
following 'groff' language elements can be used with them
interchangeably.

 -- Register: \n[.z]
 -- Register: \n[.d]
     Diversion requests may be nested.  The read-only string-valued
     register '.z' contains the name of the current diversion.  The
     read-only register '.d' contains the vertical drawing position in
     the diversion.  If the input text is not being diverted, '.d'
     reports the same location as the register 'nl'.

          .nf
          .di A
          alpha
          .di B
          beta
          .di
          gamma
          \*B
          .di
          delta
          \*A
          epsilon
              => delta
              => alpha
              => gamma
              => beta
              =>
              =>
              => epsilon

 -- Register: \n[.h]
     The read-only register '.h' stores 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.(5)  (*note
     Diversions-Footnote-5::)

          .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 implied by the example, vertical motion does not produce text
     baselines and thus does not increase the value interpolated by
     '\n[.h]'.

 -- Register: \n[dn]
 -- Register: \n[dl]
     After output to a (named) diversion stops, the formatter stores its
     vertical and horizontal sizes, to the writable registers 'dn' and
     'dl', respectively.  Only the lines just processed are counted: for
     the computation of 'dn' and 'dl', the requests 'da' and 'boxa' are
     handled as if 'di' and 'box' had been used, respectively--lines
     that have been already stored in the diversion (box) are not taken
     into account.

          .\" Center text both horizontally and vertically.
          .\" Macro .(c starts centering mode; .)c terminates it.
          .
          .\" Disable the escape character with .eo so that we
          .\" don't have to double backslashes on the "\n"s.
          .eo
          .de (c
          .  br
          .  ev (c
          .  evc 0
          .  in 0
          .  nf
          .  di @c
          ..
          .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
          ..
          .ec

 -- Escape sequence: \!character-sequence
 -- Escape sequence: \?character-sequence\?
     "Transparently" embed CHARACTER-SEQUENCE into the current
     diversion, preventing the formatter from interpreting requests,
     macro calls, and escape sequences when reading them into a
     diversion.  Doing so prevents them from taking effect until the
     diverted text is actually output.  The '\!' escape sequence
     transparently embeds input up to and including the end of the line.
     The '\?' escape sequence transparently embeds input, read in copy
     mode, up to its own next occurrence on the input line.  Use '\!' by
     itself to embed newlines in a diversion.  The two escape sequences
     differ in that GNU 'troff' interprets '\?' even in copy mode;
     recall *note Copy Mode::.  Consequently, comparands protected with
     '\?' need not be valid GNU 'troff' syntax.

          .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
              => 4

     Both escape sequences read the data in copy mode.

     If '\!' is used in the top-level diversion, its argument is
     embedded into GNU 'troff''s device-independent output.  One of its
     applications is control of a postprocessor that transforms the data
     that are subsequently read by an output driver.

     Using the '\?' escape sequence in the top-level diversion produces
     no output at all; its argument is simply ignored.

 -- Request: .output ['"']character-sequence
     Emit CHARACTER-SEQUENCE directly to GNU 'troff''s output; this
     usage is similar to that of '\!' when it occurs in the top-level
     diversion.

     GNU 'troff' removes a leading neutral double quote '"' from
     CHARACTER-SEQUENCE, permitting initial embedded spaces in it, and
     reads it to the end of the input line in copy mode.  Recall *note
     Copy Mode::.

     *Caution:* Use of these features can put syntactically invalid
     content into the formatter's output, which 'groff''s output drivers
     then fail to process.  One application of 'output' and of '\!' from
     the top-level diversion is to pass instructions to a postprocessor
     that interprets CHARACTER-SEQUENCE and filters it out before
     sending it to the output driver.

 -- Request: .asciify div
     "Unformat" the diversion DIV in a way such that Unicode basic Latin
     (US-ASCII) characters, characters translated with the 'trin'
     request, space characters, and some escape sequences that were
     formatted and diverted into DIV are treated like ordinary input
     characters when DIV is interpolated.  Doing so can be useful in
     conjunction with the 'writem' request.

     When transforming a glyph node back into an input sequence that
     demands expression as a special character escape sequence, GNU
     'troff' uses the default escape character.

     'asciify' 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 nodes in a diversion to their source
     equivalents: those produced by indexed characters ('\N'), for
     example, remain nodes, so the result cannot be guaranteed to be a
     character sequence as a macro or string is.  Give the diversion
     name as an argument to the 'pm' request to inspect its contents and
     node list.  Glyph parameters such as the type face and size are not
     preserved; use 'unformat' to achieve that.

 -- Request: .unformat div
     Like 'asciify', unformat the diversion DIV.  However, 'unformat'
     handles only tabs and spaces between words, the latter usually
     arising from spaces or newlines in the input.  Tabs are treated as
     tokens, and spaces become adjustable again.  The vertical sizes of
     lines are not preserved, but glyph information (font, type size,
     space width, and so on) is retained.


File: groff.info,  Node: Diversions-Footnotes,  Up: Diversions

   (1) *Note GNU troff Internals::.

   (2) GNU 'troff' emits a warning in category 'mac'.  *Note Warnings::.

   (3) *Note Environments::.

   (4) GNU 'troff' emits a warning in category 'di'.  *Note Warnings::.

   (5) Thus, the "water" gets "higher" proceeding _down_ the page.


File: groff.info,  Node: Punning Names,  Next: Environments,  Prev: Diversions,  Up: GNU troff Reference

5.31 Punning Names
==================

Macros, strings, and diversions share a name space; recall *note
Identifiers::.  Internally, the same mechanism is used to store them.
You can thus call a macro with string interpolation syntax and vice
versa.

     .de subject
     Typesetting
     ..
     .de predicate
     rewards attention to detail
     ..
     \*[subject] \*[predicate].
     Truly.
         => Typesetting
         =>  rewards attention to detail Truly.

What went wrong?  Strings don't contain newlines, but macros do.  String
interpolation placed a newline at the end of '\*[subject]', and the next
thing on the input was a space.  Then when '\*[predicate]' was
interpolated, it was followed by the empty request '.' on a line by
itself.  If we want to use macros as strings, we must take interpolation
behavior into account.

     .de subject
     Typesetting\\
     ..
     .de predicate
     rewards attention to detail\\
     ..
     \*[subject] \*[predicate].
     Truly.
         => Typesetting rewards attention to detail.  Truly.

By ending each text line of the macros with an escaped <RET>, we get the
desired effect; recall *note Line Continuation::.(1)  (*note Punning
Names-Footnote-1::) What would have happened if we had used only one
backslash in each case?

   Interpolating a string does not hide existing macro arguments.  We
can also place the escaped newline outside the string interpolation
instead of within the string definition.  Thus, in a macro, a more
efficient way of doing

     .xx \\$@

is

     \\*[xx]\\

The latter calling syntax doesn't change the value of '\$0', which is
then inherited from the calling macro; recall *note Parameters::.

   It is sometimes convenient to copy a single-line diversion to a
string, which can then be interpolated with '\*'.

     .di xx
     the
     .ft I
     interpolation system
     .ft
     .br
     .di
     .ds yy This is a test of \*(xx\c
     \*(yy.
         => This is a test of the interpolation system.

In the foregoing, we see that formatted output can thus be stored in a
string.  The '\c' escape sequence prevents the subsequent newline from
being interpreted as a break; again, recall *note Line Continuation::.

   Copying multi-output-line diversions produces unexpected results.

     .di xxx
     a funny
     .br
     test
     .br
     .di
     .ds yyy This is \*[xxx]\c
     \*[yyy].
         => test This is a funny.

   Usually, it is not predictable whether a diversion contains one or
more output lines, so this mechanism should be avoided.  With AT&T
'troff', this was the only solution to strip off a final newline from a
diversion.  Another disadvantage is that the spaces in the copied string
are already formatted, preventing their adjustment.  This can cause ugly
results.

   A clean solution to this problem is available in GNU 'troff', using
the requests 'chop' to remove the final newline of a diversion, and
'unformat' to make the horizontal spaces adjustable again.

     .box xxx
     a funny
     .br
     test
     .br
     .box
     .chop xxx
     .unformat xxx
     This is \*[xxx].
         => This is a funny test.

   *Note GNU troff Internals::.


File: groff.info,  Node: Punning Names-Footnotes,  Up: Punning Names

   (1) We must double the backslash.  Recall *note Copy Mode::.


File: groff.info,  Node: Environments,  Next: Suppressing Output,  Prev: Punning Names,  Up: GNU troff Reference

5.32 Environments
=================

As discussed in *note Deferring Output::, environments store most of the
parameters that determine the appearance of text.  A default environment
named '0' (zero) exists when the formatter starts up; formatting-related
requests and escape sequences modify its properties.

   You can create new environments and switch among them.  Only one is
current at any given time.  Active environments are managed using a
"stack", a data structure supporting "push" and "pop" operations.  The
current environment is at the top of the stack.  The same environment
name can be pushed onto the stack multiple times, possibly interleaved
with others.  Popping the environment stack does not destroy the current
environment; it remains accessible by name and can be made current again
by pushing it at any time.  Environments cannot be renamed or deleted,
and can only be modified when current.  To inspect the environment
stack, use the 'pev' request.(1)  (*note Environments-Footnote-1::)

   Environments store the following information.

   * a partially collected line, if any

   * data about the most recently output glyph and line (registers
     '.cdp', '.cht', '.csk', '.n', '.w')

   * typeface parameters (size, family, style, height and slant,
     inter-word and inter-sentence space sizes)

   * page parameters (line length, title length, vertical spacing, line
     spacing, indentation, line numbering, centering, right-alignment,
     underlining, hyphenation parameters)

   * filling enablement; adjustment enablement and mode

   * tab stops; tab, leader, escape, control, no-break control,
     hyphenation, and margin characters

   * input line traps

   * stroke and fill colors

 -- Request: .ev [ident]
 -- Register: \n[.ev]
     Enter the environment IDENT, which is created if it does not
     already exist, using the same parameters as for the default
     environment used at startup.  With no argument, GNU 'troff'
     switches to the previous environment.

     Invoking 'ev' with an argument puts environment IDENT onto the top
     of the environment stack.  (If it isn't already present in the
     stack, this is a proper push.)  Without an argument, 'ev' pops the
     environment stack, making the previous environment current.  It is
     an error to pop the environment stack with no previous environment
     available.  The read-only string-valued register '.ev' contains the
     name of the current environment--the one at the top of the stack.

          .ev footnote-env
          .fam N
          .ps 6
          .vs 8
          .ll -.5i
          .ev

          ...

          .ev footnote-env
          \[dg] Observe the smaller text and vertical spacing.
          .ev

     We can familiarize ourselves with stack behavior by wrapping the
     'ev' request with a macro that reports the contents of the '.ev'
     register to the standard error stream.

          .de EV
          .  ev \\$1
          .  tm environment is now \\n[.ev]
          ..
          .
          .EV foo
          .EV bar
          .EV
          .EV baz
          .EV
          .EV
          .EV

              error-> environment is now foo
              error-> environment is now bar
              error-> environment is now foo
              error-> environment is now baz
              error-> environment is now foo
              error-> environment is now 0
              error-> error: environment stack underflow
              error-> environment is now 0

 -- Request: .evc environment
     Copy the properties of ENVIRONMENT to the current environment,
     except for:

        * a partially collected line, if present;

        * the interruption status of the previous input line (due to use
          of the '\c' escape sequence);

        * the count of remaining lines to center, to right-justify, or
          to underline (with or without underlined spaces)--these are
          set to zero;

        * the activation status of temporary indentation;

        * input line traps and their associated data;

        * the activation status of line numbering (which can be
          reactivated with '.nm +0'); and

        * the count of consecutive hyphenated lines (set to zero).

     Copying an environment to itself discards the foregoing data.

 -- Register: \n[.w]
 -- Register: \n[.cht]
 -- Register: \n[.cdp]
 -- Register: \n[.csk]
     The '\n[.w]' register contains the width of the last glyph
     formatted in the environment.

     The '\n[.cht]' register contains the height of the last glyph
     formatted in the environment.

     The '\n[.cdp]' register contains the depth of the last glyph
     formatted in the environment.  It is positive for glyphs extending
     below the baseline.

     The '\n[.csk]' register contains the "skew" (how far to the right
     of the glyph's center that GNU 'troff' should place an accent) of
     the last glyph formatted in the environment.

 -- Register: \n[.n]
     The '\n[.n]' register contains the length of the previous output
     line emitted in the environment.


File: groff.info,  Node: Environments-Footnotes,  Up: Environments

   (1) *Note Debugging::.


File: groff.info,  Node: Suppressing Output,  Next: Host System Service Access,  Prev: Environments,  Up: GNU troff Reference

5.33 Suppressing Output
=======================

 -- Escape sequence: \O[num]
     Suppress GNU 'troff' output of glyphs and geometric objects.  The
     sequences '\O2', '\O3', '\O4', and '\O5' are intended for internal
     use by 'grohtml'.

     '\O0'
          Disable the emission of glyphs and geometric objects to the
          output driver, provided that this sequence occurs at the
          outermost suppression level (see '\O3' and '\04' below).
          Horizontal motions corresponding to non-overstruck glyph
          widths still occur.

     '\O1'
          Enable the emission of glyphs and geometric objects to the
          output driver, provided that this sequence occurs at the
          outermost suppression level.

     '\O0' and '\O1' also reset the four registers 'opminx', 'opminy',
     'opmaxx', and 'opmaxy' to -1.  These four registers mark the top
     left and bottom right hand corners of a box encompassing all
     written or drawn output.

     '\O2'
          At the outermost suppression level, enable emission of glyphs
          and geometric objects, and write to the standard error stream
          the page number and values of the four aforementioned
          registers encompassing glyphs written since the last
          interpolation of a '\O' sequence, as well as the page offset,
          line length, image file name (if any), horizontal and vertical
          device motion quanta, and input file name.  Numeric values are
          in basic units.

     '\O3'
          Begin a nested suppression level.  'grohtml' uses this
          mechanism to create images of output preprocessed with 'pic',
          'eqn', and 'tbl'.  At startup, GNU 'troff' is at the outermost
          suppression level.  'pre-grohtml' generates these sequences
          when processing the document, using GNU 'troff' with the 'ps'
          output device, Ghostscript, and the PNM tools to produce
          images in PNG format.  They start a new page if the device is
          not 'html' or 'xhtml', to reduce the number of images crossing
          a page boundary.

     '\O4'
          End a nested suppression level.

     '\O[5PFILE]'
          At the outermost suppression level, write the name 'file' to
          the standard error stream at position P, which must be one of
          'l', 'r', 'c', or 'i', corresponding to left, right, centered,
          and inline alignments within the document, respectively.  FILE
          is a name associated with the production of the next image.

 -- Register: \n[.O]
     Output suppression nesting level applied by '\O3' and '\O4' escape
     sequences.


File: groff.info,  Node: Host System Service Access,  Next: Postprocessor Access,  Prev: Suppressing Output,  Up: GNU troff Reference

5.34 Host System Service Access
===============================

Occasionally a document wants to access the system clock, file storage,
or other services provided by the operating environment.

 -- Register: \n[$$]
     Process identifier (PID) of the GNU 'troff' program in its
     operating environment.

   Date- and time-related registers are set per the local time as
determined by 'localtime(3)' when the formatter launches.  This
initialization can be influenced by the environment variable 'TZ' or
overridden by 'SOURCE_DATE_EPOCH'; see *note Environment::.

'\n[seconds]'
     Count of seconds elapsed in the minute (0-60).

'\n[minutes]'
     Count of minutes elapsed in the hour (0-59).

'\n[hours]'
     Count of hours elapsed since midnight (0-23).

'\n[dw]'
     Day of the week (1-7; 1 is Sunday).

'\n[dy]'
     Day of the month (1-31).

'\n[mo]'
     Month of the year (1-12).

'\n[year]'
     Gregorian year.

'\n[yr]'
     Gregorian year minus 1900.  This register is incorrectly documented
     in the AT&T 'troff' manual as storing the last two digits of the
     current year.  That claim stopped being true in 2000.  Old 'troff'
     input that looks like:

          '\" The year number is a surprise after 1999.
          This document was formatted in 19\n(yr.

     can be corrected to:

          This document was formatted in \n[year].

     or, for portability across many 'roff' programs, to the following.

          .nr y4 1900+\n(yr
          This document was formatted in \n(y4.

   If you wish to embed the date and/or time of a document's formatting
into its output, interpolate these registers into its text.  Use the
'af' request to format their values for output.

     .af year 0000
     .af mo 00
     .af dy 00
     .af hours 00
     .af minutes 00
     .af seconds 00
     ISO 8601 date stamp:
     \n[year]-\n[mo]-\n[dy]T\n[hours]:\n[minutes]:\n[seconds]
         => ISO 8601 date stamp: 2025-12-07T02:17:54

   'roff' formatters allow files to be read into the input stream.
Enabling GNU 'troff''s unsafe mode at the command line permits the
writing of files and execution of external commands, with or without
inclusion of their output in the document.

   *Caution:* The requests discussed below that accept a file name or
system command as an argument treat the remainder of the input line as
that argument, including any spaces, up to a newline or comment escape
sequence.  Suffixing the file name or command with a comment, even an
empty one, prevents unwanted space from creeping into it during source
document maintenance.  GNU 'troff' removes a leading neutral double
quote '"' from such an argument, permitting initial embedded spaces in
it, and reads it to the end of the input line in copy mode.  Recall
*note Copy Mode::.

 -- Request: .so ['"']file
 -- Request: .soquiet ['"']file
     Replace the request's control line with the contents of FILE,
     "sourcing" it.  GNU 'troff' searches for FILE in any directories
     specified by '-I' command-line options, followed by the current
     working directory.  If FILE does not exist, the formatter ignores
     the request.(1)  (*note Host System Service Access-Footnote-1::)

     'so' can be useful for large documents, allowing each chapter of a
     book, for example, to be maintained in a separate file.  However,
     files interpolated with 'so' are not preprocessed; to overcome this
     limitation, see 'soelim(1)'.

     *Caution:* Since the formatter replaces the entire control line
     with the contents of a file, FILE must end with a newline, or the
     formatter will continue reading the next input line of the 'roff'
     file as if it were part of the last line of the sourced file.
     Consider a file 'xxx' containing only the word 'foo' without a
     trailing newline.

          $ printf 'foo' > xxx
          $ groff -T ascii <<EOF
          The situation is
          .so xxx
          bar.
          EOF
              => The situation is foobar.

     'soquiet' works the same way, except that GNU 'troff' issues no
     warning diagnostic if FILE does not exist.

 -- Request: .pso ['"']command
     Read the standard output from the specified COMMAND when passed to
     'popen(3)' and include it in place of the 'pso' request.

     It is an error to use this request in safer mode, which is the
     default.  Invoke GNU 'troff' or a front end with the '-U' option to
     enable unsafe mode.

     The cautionary note regarding a final newline in the stream read by
     the 'so' request applies to 'pso' as well.

 -- Request: .mso ['"']file
 -- Request: .msoquiet ['"']file
     As the 'so' and 'soquiet' requests, respectively, except that GNU
     'troff' searches for the specified FILE in the same directories as
     macro files; recall 'GROFF_TMAC_PATH' in *note Environment:: and
     '-m' in *note Groff Options::.

 -- Request: .trf ['"']file
 -- Request: .cf ['"']file
     Break and copy the contents of FILE as "throughput" to GNU
     'troff''s output.  Each line of FILE is output as if preceded by
     '\!', but is not interpreted by the formatter.  If FILE does not
     end with a newline, 'trf' appends one.  Both requests break the
     line before reading FILE, unless invoked with the no-break control
     character.  If a diversion is in use, GNU 'troff' performs the copy
     only when the diversion is emitted.

     'cf' copies the contents of FILE completely unprocessed; it is
     therefore an error to use this request in safer mode, which is the
     default.  Invoke GNU 'troff' or a front end with the '-U' option to
     enable unsafe mode.

     'trf' discards invalid input characters; recall *note Input
     Format::.

     For 'cf', within a diversion, "completely unprocessed" means that
     each line of a file to be inserted is handled as if it were
     preceded by '\!\\!'.

     *Caution:* Use of these requests can put syntactically invalid
     content into the formatter's output, which 'groff''s output drivers
     then fail to process.  One application is to pass instructions to a
     postprocessor that interprets FILE's contents and filters it out
     before sending it to the output driver.

     To define a macro 'x' containing the contents of file 'f', use

          .ev 1
          .di x
          .trf f
          .di
          .ev

     The calls to 'ev' prevent the partially collected output line from
     becoming part of the diversion; recall *note Diversions::.

     In AT&T 'troff', 'cf' copies the contents of FILE to the output
     immediately even if a diversion is active; this behavior is so
     anomalous that it must be considered a bug.

 -- Request: .nx [['"']file]
     Stop processing the input file.  If FILE is specified, read it;
     otherwise, read the next pending input file, if any.

 -- Request: .rd [prompt [arg1 arg2 ...]]
     Read from standard input, and include what is read as though it
     were part of the input file.  Text is read until a blank line is
     encountered.

     If standard input is a TTY input device (keyboard), write PROMPT to
     standard error, followed by a colon (or send BEL for a beep if no
     argument is given).

     Arguments after PROMPT are available for the input.  For example,
     the line

          .rd data foo bar

     with the input 'This is \$2.' prints

          This is bar.

   Using the 'nx' and 'rd' requests, it is easy to set up form letters.
The form letter template is constructed like this, putting the following
lines into a file called 'repeat.let':

     .ce
     \*(td
     .sp 2
     .nf
     .rd
     .sp
     .rd
     .fi
     Body of letter.
     .bp
     .nx repeat.let

When this is run, a file containing the following lines should be
redirected in.  Requests included in this file are executed as though
they were part of the form letter.  The last block of input is the 'ex'
request, which tells GNU 'troff' to stop processing.  If this were not
there, 'troff' would not know when to stop.

     Trent A. Fisher
     708 NW 19th Av., #202
     Portland, OR  97209

     Dear Trent,

     Len Adollar
     4315 Sierra Vista
     San Diego, CA  92103

     Dear Mr. Adollar,

     .ex

 -- Request: .pi ['"']command
     Use the formatter's device-independent output as the input to the
     commands specified in PIPE and emit their output to the standard
     output stream instead of the formatter's usual output.  The
     formatter reads the remainder of the input line into COMMAND and
     passes it to 'popen(3)'.  The formatter does not capture output
     produced by the command(s).

     Multiple 'pi' requests construct a multi-stage pipeline in the same
     order as the formatter encounters the requests.

          .pi foo
          .pi bar

     is the same as '.pi foo | bar'.

     'pi' must be invoked before GNU 'troff' writes any nodes to its
     output.(2)  (*note Host System Service Access-Footnote-2::) The
     formatter reports an error and ignores the request if 'pi' is
     invoked "too late".  Roughly, this means you should set up your
     'pi' pipeline early in a document, before anything but register,
     string, and macro definitions (and/or sourcing of files that
     comprise these exclusively).

     Use of this request in safer mode (GNU 'troff''s default) is
     erroneous.  Invoke GNU 'troff' or a front end with the '-U' option
     to enable unsafe mode.

     *Caution:* Use of the 'pi' request can put syntactically invalid
     content into the formatter's output, which 'groff''s output drivers
     then fail to process.  The pipeline you construct is responsible
     for maintaining the validity of the input to the output driver.

 -- Request: .sy ['"']command
 -- Register: \n[systat]
     Execute the specified shell command(s).  The formatter reads the
     remainder of the input line into a buffer and passes it to
     'system(3)'.  The formatter does not capture the output produced by
     the command(s).

     It is an error to use this request in safer mode; this is the
     default.  Give GNU 'troff' or a front end program the '-U'
     command-line option to enable unsafe mode.

     The writable register 'systat' contains the return value of the
     'system(3)' function executed by the most recent 'sy' request.

     Real-world (and non-malicious) applications of 'sy' are esoteric;
     the request interpolates neither the standard output nor the
     standard error streams of COMMAND into the document--worse, AT&T
     'troff' afforded no means of verifying that COMMAND operated as
     expected.  We therefore offer a silly example of its use, making a
     document refuse to format if the system user name running the
     formatter is 'branden'.(3)  (*note Host System Service
     Access-Footnote-3::)

          .ds user branden\"
          .sy test "$(id -un)" = \*[user]
          .if \n[systat]=0 .ab formatting refused for \*[user]
          Hello, world!

 -- Request: .open stream ['"']file
 -- Request: .opena stream ['"']file
     Open FILE for writing and associate a stream named IDENT with it,
     making it available for 'write' requests.

     The 'opena' request is like 'open', but appends to FILE if it
     already exists instead of overwriting it.

     It is an error to use these requests in safer mode; this is the
     default.  Give GNU 'troff' or a front end program the '-U'
     command-line option to enable unsafe mode.

     The 'pstream' request dumps the list of open streams to the
     standard error stream.(4)  (*note Host System Service
     Access-Footnote-4::)

 -- Request: .write stream ['"']contents
 -- Request: .writec stream ['"']contents
     Write CONTENTS to STREAM, which must previously have been the
     subject of an 'open' (or 'opena') request.  GNU 'troff' flushes the
     stream after writing to it.

     The 'writec' request is like 'write', but only 'write' appends a
     newline to CONTENTS.

 -- Request: .writem stream name
     Write the contents of the macro or string NAME to STREAM, which
     must previously have been the subject of an 'open' (or 'opena')
     request.  GNU 'troff' reads the contents of NAME in copy mode.
     That is, it ignores already formatted elements (nodes).
     Consequently, diversions must be unformatted with the 'asciify'
     request before calling 'writem'.  Usually, this means a loss of
     information.

 -- Request: .close stream
     Close the specified STREAM; the stream is no longer an acceptable
     argument to the 'write' request.

     Here a simple macro to write an index entry.

          .open idx test.idx
          .
          .de IX
          .  write idx \\n[%] \\$*
          ..
          .
          .IX test entry
          .
          .close idx

 -- Escape sequence: \Ve
 -- Escape sequence: \V(ev
 -- Escape sequence: \V[env]
     Interpolate the contents of the system environment variable ENV
     (one-character name E, two-character name EV) as returned by
     'getenv(3)'.  '\V' is interpreted even in copy mode; recall *note
     Copy Mode::.


File: groff.info,  Node: Host System Service Access-Footnotes,  Up: Host System Service Access

   (1) GNU 'troff' emits a warning in category 'file'.  *Note
Warnings::.

   (2) *Note GNU troff Internals::.

   (3) POSIX command environments and 'roff' formatters employ different
integer-to-Boolean interpretation conventions; a POSIX command exits
with a zero status if it succeeds and a positive one if it fails,
whereas a 'roff' register tests "true" if it has a positive value.

   (4) *Note Debugging::.


File: groff.info,  Node: Postprocessor Access,  Next: Miscellaneous,  Prev: Host System Service Access,  Up: GNU troff Reference

5.35 Postprocessor Access
=========================

Beyond the 'cf' and 'trf' requests (recall *note Host System Service
Access::), two escape sequences and two requests enable documents to
pass information directly to a postprocessor.  These are useful for
exercising device-specific capabilities that the 'groff' language does
not abstract or generalize; examples include the embedding of hyperlinks
and image files.  Device-specific functions are documented in each
output driver's man page, such as 'gropdf(1)', 'grops(1)', or
'grotty(1)'.

 -- Request: .device ['"']character-sequence
 -- Escape sequence: \X'''contents ...'''
     Embed CHARACTER-SEQUENCE into GNU 'troff' output as parameters to
     an 'x X' device extension command.(1)  (*note Postprocessor
     Access-Footnote-1::) The output driver or other postprocessor
     interprets CHARACTER-SEQUENCE as it sees fit.

     GNU 'troff' removes a leading neutral double quote '"' from
     CONTENTS, permitting initial embedded spaces in it, and reads it to
     the end of the input line in copy mode.  Recall *note Copy Mode::.

     The 'groff' special character repertoire is unknown to output
     drivers outside of glyphs named in a device's fonts, and even then
     they may not possess complete coverage of the names documented in
     the 'groff_char(7)' man page.  Further, escape sequences that
     produce horizontal or vertical motions, hyphenation breaks, or that
     are dummy characters may appear in strings or be converted to
     nodes, particularly in diversions.(2)  (*note Postprocessor
     Access-Footnote-2::) These are not representable when interpolated
     directly into device-independent output, as might be done when
     writing out tag names for PDF bookmarks, which can appear in a
     viewer's navigation pane.

     So that documents or macro packages do not have to laboriously
     "sanitize" strings destined for interpolation in device extension
     commands, the '\X' escape sequence performs certain transformations
     on its argument.  For these transformations, character translations
     and definitions are ignored.

     GNU 'troff' converts several ordinary characters that typeset as
     non-basic Latin code points to code points outside that range so
     that they are used consistently whether they are formatted as
     glyphs or used in a device extension command argument.  These
     ordinary characters are ''', '-', '^', '`', and '~'; others are
     written as-is.

     Special characters that typeset as Unicode basic Latin characters
     are translated to basic Latin characters accordingly.  So that any
     Unicode code point can be represented in device extension commands,
     for example in an author's name in document metadata or as a
     usefully named bookmark or hyperlink anchor, GNU 'troff' maps other
     special characters to Unicode special character notation.  Recall
     *note Characters and Glyphs::.

     GNU 'troff' does not write special characters without a Unicode
     representation and escape sequences that do not interpolate a
     sequence of ordinary and/or special characters as arguments to
     device extension commands.(3)  (*note Postprocessor
     Access-Footnote-3::)

   GNU 'troff' also permits the interpolation of macro or string
contents as a device extension command.

 -- Request: .devicem name
 -- Escape sequence: \Yn
 -- Escape sequence: \Y(nm
 -- Escape sequence: \Y[name]
     The 'devicem' request and '\Y' escape sequence correspond to
     '.device \*[NAME]' and '\X'\*[NAME]'' (one-character name N,
     two-character name NM), respectively.  They differ from their
     counterparts in that GNU 'troff' does not interpret the contents of
     the string or macro NAME; further, NAME may be a macro and thus
     contain newlines.  (There is no way to embed a newline in the
     arguments to 'device' or '\X'.)  The inclusion of newlines requires
     an extension to the AT&T 'troff' device-independent page
     description language, and their presence confuses drivers that do
     not know about it.(4)  (*note Postprocessor Access-Footnote-4::)

   Use of device extension commands early in a document (before the
first text is formatted) can interfere with processing of page location
traps.  If you experience problems when placing them early, precede the
first with a dummy character escape sequence '\&'; recall *note Dummy
Characters::.

 -- Request: .tag name
 -- Request: .taga name
     Reserved for internal use.


File: groff.info,  Node: Postprocessor Access-Footnotes,  Up: Postprocessor Access

   (1) *Note GNU troff Output::.

   (2) *Note GNU troff Internals::.

   (3) When encountered, these produce warnings in category 'char'.
*Note Warnings::.

   (4) *Note Device Control Commands::.


File: groff.info,  Node: Miscellaneous,  Next: GNU troff Internals,  Prev: Postprocessor Access,  Up: GNU troff Reference

5.36 Miscellaneous
==================

We document here GNU 'troff' features that fit poorly elsewhere.

 -- Request: .psbb file
 -- Register: \n[llx]
 -- Register: \n[lly]
 -- Register: \n[urx]
 -- Register: \n[ury]
     Retrieve the bounding box of the PostScript image found in FILE,
     which must conform to Adobe's "Document Structuring Conventions"
     (DSC), locate a '%%BoundingBox' comment, and store the (upper-,
     lower-, -left, -right) values into the registers 'llx', 'lly',
     'urx', and 'ury'.  If an error occurs (for example, if no
     '%%BoundingBox' comment is present), the formatter sets these
     registers to 0.

     Control the search path for FILE with the '-I' command-line option.


File: groff.info,  Node: GNU troff Internals,  Next: Debugging,  Prev: Miscellaneous,  Up: GNU troff Reference

5.37 GNU 'troff' Internals
==========================

GNU 'troff' processes input in three steps.  It gathers one or more
input characters into a "token",(1) (*note GNU troff
Internals-Footnote-1::) the smallest meaningful unit of 'troff' input.
The process of formatting translates tokens into nodes that populate a
pending output line (recall *note Manipulating Filling and
Adjustment::).  A "node" is a data structure representing any object
that may ultimately appear in the output, like a glyph or motion on the
page.  When the pending output line breaks, the formatter applies any
relevant adjustment, line number, and margin character, and finally
appends it to the current diversion.  Periodically, the formatter
"flushes" accumulated output line(s) to the output device, a process
that translates each node into a device-independent output language
representation understood by all output drivers.  Copy mode tokenizes
but does not format; diversions (apart from that at the top level)
format but do not write output.

   For example, GNU 'troff' converts the input 'Gi\[:u]\%seppe' into a
character token for 'g', a character token for 'i', a special character
token for ':u' (representing 'u' with an umlaut), a token encoding a
hyphenation break point,(2) (*note GNU troff Internals-Footnote-2::) and
further character tokens.  You can observe this process by storing the
foregoing input into a string--which, because its contents are read in
copy mode, is only tokenized, not formatted--and dumping it with the
'pm' request.(3)  (*note GNU troff Internals-Footnote-3::) (Using
'printf(1)' requires us to double the '\' and '%' characters.)

     $ printf '.ds str Gi\\[:u]\\%%seppe\n.pm str\n' \
         | groff 2>&1 | jq

   Similarly, we can observe the details of the formatting process by
interpolating the string, or supplying its contents directly as input,
and invoking the 'pline' request.

     $ printf 'Gi\\[:u]\\%%seppe\n.pline\n' | groff -z 2>&1 | jq

   We now see a list of nodes, including an output line start node,
several glyph nodes, a discretionary break node containing a glyph node
for the special character ':u' _and_ a glyph node for the special
character 'hy' (hyphen), and a word space node at the end corresponding
to the newline at the end of input.(4)  (*note GNU troff
Internals-Footnote-4::)

   If we change 'G' to 'f', we see that the first two glyph nodes, for
'f' and 'i', become contained by a ligature node (provided the current
font has a glyph for this ligature).  All output glyph nodes are
"processed", which means that they are associated with a given font,
type size, advance width, and so forth.

   Macros, diversions, and strings collect elements in two chained
lists: a list of tokens that have been passed unprocessed, and a list of
nodes.  Consider the following diversion.

     .di xxx
     a
     \!b
     c
     .br
     .di

It contains these elements.

node list            token list   element number
                                  
line start node      --           1
glyph node 'a'       --           2
word space node      --           3
--                   'b'          4
--                   '\n'         5
glyph node 'c'       --           6
vertical size node   --           7
vertical size node   --           8
--                   '\n'         9

'troff' inserts elements 1, 7, and 8; the latter two (which are always
present) specify the vertical extent of the last line, possibly modified
by '\x'.  The 'br' request finishes the pending output line, inserting a
newline token, which is subsequently converted to a space when the
diversion is interpolated.  Note that the word space node has a fixed
width that isn't adjustable anymore.  To convert horizontal space nodes
back into tokens, use the 'unformat' request.

   Macros only contain elements in the token list (and the node list is
empty); diversions and strings can contain elements in both lists.

   The 'chop' request simply reduces the number of elements in a macro,
string, or diversion by one.  Exceptions are "compatibility save" and
"compatibility ignore" tokens, which are ignored.  The 'substring'
request also ignores those tokens.

   Some requests like 'tr' or 'cflags' work on glyph identifiers only;
this means that the associated glyph can be changed without destroying
this association.  This can be very helpful for substituting glyphs.  In
the following example, we assume that glyph 'foo' isn't available by
default, so we provide a substitution using the 'fchar' request and map
it to input character 'x'.

     .fchar \[foo] foo
     .tr x \[foo]

Now let us assume that we install an additional special font 'bar' that
has glyph 'foo'.

     .special bar
     .rchar \[foo]

Since glyphs defined with 'fchar' are searched before glyphs in special
fonts, we must call 'rchar' to remove the definition of the fallback
glyph.  Anyway, the translation is still active; 'x' now maps to the
real glyph 'foo'.

   Macro and request arguments preserve compatibility mode enablement.

     .cp 1     \" switch to compatibility mode
     .de xx
     \\$1
     ..
     .cp 0     \" switch compatibility mode off
     .xx caf\['e]
         => café

Since compatibility mode is enabled while 'de' is invoked, the macro
'xx' enables compatibility mode when it is called.  Argument '$1' can
still be handled properly because it inherits the compatibility mode
enablement status that was active at the point where 'xx' was called.

   After interpolation of the parameters, the compatibility save and
restore tokens are removed.


File: groff.info,  Node: GNU troff Internals-Footnotes,  Up: GNU troff Internals

   (1) When not in copy mode, the formatter does not tokenize the escape
sequences '\f', '\F', '\H', '\m', '\M', '\R', '\s', and '\S', but
instead updates the environment.

   (2) GNU 'troff' encodes tokens that aren't Unicode Basic Latin
characters as code points in the C0 and C1 control ranges; we plan to
move them to the Unicode Private Use Area (PUA) or to code points
outside the Unicode encoding space in a future release.

   (3) Because GNU 'troff''s internals are subject to revision, we do
not show the output of these examples.  The names and structures of node
types may change over time.  The JSON interpreter 'jq(1)' is not
essential, but can be helpful in understanding the topology of the node
trees populating output lines and diversions in particular.

   (4) You may wonder why a glyph node for 'hy' exists when this example
doesn't produce one on the output.  That's because the break is
_discretionary_; at the time a word is formatted into nodes, GNU 'troff'
doesn't know where the output line will break.  Later, when processesing
a pending output line, GNU 'troff' has that knowledge, and iterates
through the output line's node list, using its discretion to discard
these hyphen glyph nodes everywhere except when hyphenating a word at
the end of the line.


File: groff.info,  Node: Debugging,  Next: Implementation Differences,  Prev: GNU troff Internals,  Up: GNU troff Reference

5.38 Debugging
==============

          Standard troff voodoo, just put a power of two backslashes in
    front of it until it works and if you still have problems add a \c.
                                                         -- Ron Natalie

   The 'roff' language family is not the easiest to debug, in part
thanks to its design features of recursive interpolation and the use of
multi-stage pipeline processing in the surrounding system.  Nevertheless
there exist several features useful for troubleshooting.

   Preprocessors use the 'lf' request to preserve the identity of the
line numbers and names of input files.  GNU 'troff' emits a variety of
error diagnostics and supports several categories of warning; the output
of each category can be selectively enabled or suppressed.  A trace of
the formatter's input processing stack can be emitted when errors or
warnings occur by means of GNU 'troff''s '-b' option, or produced on
demand with the 'backtrace' request.  The 'tm' and related requests can
be used to emit customized diagnostic messages or for instrumentation
while troubleshooting.  The 'ex' and 'ab' requests cause early
termination with successful and error exit codes respectively, to halt
further processing when continuing would be fruitless.  Examine the
state of the formatter with requests that write lists of defined
names--macros, strings, and diversions--colors, composite character
mappings, environments, occupied font mounting positions, font
translations, automatic hyphenation codes and exceptions, registers,
open streams, and page location traps.  Requests can also disclose to
the standard error stream the internal properties and representations of
characters and classes, macros (and strings and diversions), and the
list of output nodes corresponding to the pending output line.  Recall
*note GNU troff Internals::.

 -- Request: .lf input-line-number [['"']file-identifier]
     Set the input line number (and, optionally, the file name) the
     formatter uses when reporting diagnostics.  The argument becomes
     the input line number of the _next_ line the formatter reads.
     FILE-IDENTIFIER is a sequence of ordinary characters and/or spaces.
     GNU 'troff' removes a leading neutral double quote '"' from
     FILE-IDENTIFIER, permitting initial embedded spaces in it, and
     reads it to the end of the input line in copy mode.  Recall *note
     Copy Mode::.

     'lf''s primary purpose is to aid the debugging of documents that
     undergo preprocessing.  Programs like 'tbl' that transform input in
     their own languages into 'roff' requests use it so that any
     diagnostic messages emitted by a subsequent preprocessor or by
     'troff' correspond to the source document.

 -- Request: .tm terminal-message
 -- Request: .tm1 ['"']message
 -- Request: .tmc ['"']message
     Send TERMINAL-MESSAGE to the standard error stream.  The formatter
     reads the argument to the end of the input line in copy mode
     (recall *note Copy Mode::), but does _not_ remove a leading double
     quote; contrast 'tm1'.

     'tm1' removes a leading neutral double quote '"' from MESSAGE,
     permitting initial embedded spaces in it.

     'tmc' works as 'tm1', but does not append a newline.

 -- Request: .ab [terminal-message]
     Write any TERMINAL-MESSAGE to the standard error stream (like 'tm')
     and then abort the formatter; that is, stop processing and
     terminate with a failure status.  Aborting does not flush a
     partially collected line, a potentially significant fact if you're
     using 'ab' to "bisect" a troublesome document or macro definition;
     see the 'fl' request below.

 -- Request: .ex
     Exit the formatter; that is, stop processing and terminate
     successfully.  To stop processing only the current file, use the
     'nx' request; recall *note Host System Service Access::.

   When doing something complicated, it is useful to leave the debugging
statements in the code and have them turned on by a command-line flag.

     .if \n[DB] .tm debugging output

To activate such statements, use the '-r' option to set the register.

     groff -rDB=1 file

   If you know in advance that there are many errors and no useful
output, or are interested _only_ in diagnostic output, you can suppress
GNU 'troff''s formatted output with its '-z' option.

 -- Request: .pchar c ...
     Report, to the standard error stream, information about each
     character (be it ordinary, special, or indexed) or character class
      C.  A character defined by a request ('char', 'fchar', 'fschar',
     or 'schar') reports its contents as a JSON-encoded string, but the
     output is not otherwise in JSON format.

 -- Request: .pcolor [col ...]
     Report, to the standard error stream, each defined color named COL,
     its color space identifier, and channel value assignments, or,
     without arguments, those of all defined colors.  A device's default
     stroke and/or fill colors, "default", are not listed since they are
     immutable and their details unknown to the formatter.

 -- Request: .pcomposite
     Report, to the standard error stream, the list of configured
     composite character mappings.  Recall the 'composite' request
     description in *note Characters and Glyphs::.  The "from" code
     point is listed first, followed by its "to" mapping.

 -- Request: .pev
     Report the state of the current environment followed by that of all
     other environments to the standard error stream.

 -- Request: .pfp
     Report, to the standard error stream, the list of occupied font
     mounting positions.  Recall the 'fp' request description in *note
     Selecting Fonts::.  Occupied mounting positions are listed, one per
     line, in increasing order, followed by the typeface name; if the
     name corresponds to an abstract style, the entry ends there.
     Otherwise, the name of the font description file and the font's
     "internal name" datum, the meaning of which varies by output
     device, follow.

 -- Request: .pftr
     Report, to the standard error stream, the list of font
     translations.  Recall the 'ftr' request description in *note
     Selecting Fonts::.  The "from" font identifier is listed first,
     followed by its "to" translation.

 -- Request: .phw
     Report, to the standard error stream, the list of hyphenation
     exception words associated with the hyphenation language selected
     by the 'hla' request; recall *note Manipulating Hyphenation::.  A
     '-' marks each hyphenation point.  A word prefixed with '-' is not
     hyphenated at all.  The report suffixes words to which automatic
     hyphenation applies (meaning those defined in a hyphenation pattern
     file rather than with the 'hw' request) with a tab and asterisk
     ('*').

 -- Request: .pline
     Report, in JSON syntax to the standard error stream, the list of
     output nodes corresponding to the pending output line.  In JSON, a
     pair of empty brackets '[ ]' represents an empty list.  A _pending_
     output line has not yet undergone adjustment, and lacks a line
     number and margin character (all as applicable).

 -- Request: .pm [name ...]
     Report, to the standard error stream, the JSON-encoded name and
     contents of each macro, string, or diversion NAME, or, without
     arguments, the names of all defined macros, strings, and diversions
     and their lengths in characters or nodes.

 -- Request: .pnr [reg ...]
     Report the name and value and, if its type is numeric, the
     autoincrement amount and assigned format of each register REG, or,
     without arguments, those of all defined registers, to the standard
     error stream.

 -- Request: .pstream
     Report, in JSON syntax to the standard error stream, the list of
     open streams, including the name of each open stream, the name of
     the file backing it, and its mode (writing or appending).  In JSON,
     a pair of empty brackets '[ ]' represents an empty list.

 -- Request: .pwh
     Report the names and positions of all page location traps to the
     standard error stream.  GNU 'troff' reports empty slots in the
     list, where a trap had been planted but subsequently (re)moved,
     because they can affect the visibility of subsequently planted
     traps.

 -- Request: .fl
     Break the line and flush any pending output line immediately.  The
     effect is the same as the 'br' request unless the no-break control
     character is used; ''br' does nothing, whereas ''fl' writes the
     pending output line without further updating the drawing position.
     However, the _reported_ horizontal drawing position is still
     reckoned from the start of the input line.

          foo \n(hp
          bar \c
          'fl
          \n(hp baz \n(hp
              => foo 96 bar 0 baz 144

     Flush timing is most easily perceived in device-independent output.

     Use of ''fl' may be desirable immediately prior to an 'ab' request
     when troubleshooting a document or macro definition line by line,
     because a significant number of formatting operations can
     accumulate on a partially collected output line, misleading you
     about "where" the abort "really" took place.

     Historically, 'fl' was used with 'rd' to produce interactive
     'nroff' documents.  GNU 'troff' does not easily support that mode
     of operation, because its output for terminals is first prepared in
     device-independent format, which 'grotty' renders a page at a time.

 -- Request: .backtrace
     Write the state of the input stack to the standard error stream.

     Consider the following in a file 'test'.

          .de xxx
          .  backtrace
          ..
          .de yyy
          .  xxx
          ..
          .
          .yyy
              error-> troff: backtrace: 'test':2: macro 'xxx'
              error-> troff: backtrace: 'test':5: macro 'yyy'
              error-> troff: backtrace: file 'test':8

     The '-b' option of GNU 'troff' causes a backtrace to be generated
     on each error or warning.  Some warnings have to be enabled; see
     *note Warnings::.

 -- Register: \n[slimit]
     If greater than 0, sets the maximum quantity of objects on GNU
     'troff''s internal input stack.  If less than or equal to 0, there
     is no limit: recursion can continue until program memory is
     exhausted.  The default is 1,000.

 -- Request: .warnscale scaling-unit
     Set the scaling unit used in certain warnings (one of 'u', 'i',
     'c', 'p', and 'P'; default: 'i').  Ignored on 'nroff'-mode output
     devices, for which these diagnostics report the vertical page
     location in lines, and the horizontal page location in ens.

 -- Request: .spreadwarn [limit]
     Emit a 'break' warning if the additional space inserted for each
     space between words in an output line adjusted to both margins with
     '.ad b' is larger than or equal to LIMIT.  A negative value is
     treated as zero; an absent argument toggles the warning on and off
     without changing LIMIT.  The default scaling unit is 'm'.  At
     startup, 'spreadwarn' is inactive and LIMIT is 3m.

     For example,

          .spreadwarn 0.2m

     causes a warning if 'break' warnings are not suppressed and GNU
     'troff' must add 0.2m or more for each inter-word space in a line.
     *Note Warnings::.

 -- Request: .warn [n]
 -- Register: \n[.warn]
     Select categories of warnings to be reported.  N is the sum of the
     numeric codes associated with each warning category that is to be
     enabled; all other categories are disabled.  The categories and
     their associated codes are listed in *note Warnings::.  For
     example, '.warn 0' disables all warnings, and '.warn 1' disables
     all warnings except those about missing glyphs.  If no argument is
     given, all warning categories are enabled.

     The read-only register '.warn' contains the sum of the numeric
     codes of enabled warning categories.

   GNU 'troff' has command-line options for reporting warnings ('-w'),
suppressing them ('-W'), and issuing backtraces ('-b') when a warning or
an error occurs.

* Menu:

* Warnings::


File: groff.info,  Node: Warnings,  Up: Debugging

5.38.1 Warnings
---------------

GNU 'troff' divides its warning diagnostics into named, numbered
categories.  The '-w' and '-W' options use the associated names.  A
power of two characterizes each category; the 'warn' request and the
'.warn' register respectively set and report the sum of enabled category
codes.  Warnings of each category are produced under the following
circumstances.

'char'
'1'
     No user-defined character of the requested name or index exists and
     no mounted font defines a glyph for it, or input could not be
     encoded for device-independent output.  This category is enabled by
     default.

'break'
'4'
     A filled output line could not be broken such that its length was
     less than or equal to, or adjusted such that its length was exactly
     equal to, the output line length '\n[.l]'.  GNU 'troff' reports the
     amount of overset or underset in the scaling unit configured by the
     'warnscale' request in 'troff' mode, and in ens ('n'; character
     cells) in 'nroff' mode.  *Note troff and nroff Modes::.  This
     category is enabled by default.

'delim'
'8'
     The selected delimiter character was ambiguous because it is also
     meaningful when beginning a numeric expression, or the closing
     delimiter in an escape sequence was missing or mismatched.

     A future 'groff' release may reject ambiguous delimiters.  In
     compatibility mode, ambiguous delimiters are accepted without
     warning.

'scale'
'32'
     A scaling unit inappropriate to its context was used in a numeric
     expression.

'range'
'64'
     A numeric expression was out of range for its context.

'syntax'
'128'
     A self-contradictory hyphenation mode or character flags were
     requested; an empty or incomplete numeric expression was
     encountered; an operand to a numeric operator was missing; an
     attempt was made to format characters or spaces on an input line
     after an output line continuation escape sequence; a recognized but
     inapposite escape sequence or unprintable character code was used
     in a device extension command; an attempt was made to define a
     recursive, empty, or nonsensical character class; or a 'groff'
     extension escape sequence or conditional expression operator was
     used while in compatibility mode.

'di'
'256'
     A 'di', 'da', 'box', or 'boxa' request was invoked without an
     argument when there was no current diversion.

'mac'
'512'
     An undefined string, macro, or diversion was used.  When such an
     object is dereferenced, an empty one of that name is automatically
     created.  So, unless it is later deleted, GNU 'troff' issues at
     most one warning for each.

     GNU 'troff' also uses this category to warn of an attempt to move
     an unplanted trap macro; recall *note Page Location Traps::.  In
     such cases, the unplanted macro is _not_ dereferenced, so it is not
     created if it does not exist.

'reg'
'1024'
     An undefined register was used.  When an undefined register is
     dereferenced, the formatter automatically defines it with a value
     of 0.  So, unless it is later deleted, GNU 'troff' issues at most
     one warning for each.

'tab'
'2048'
     A tab character appeared in a parameterized escape sequence, in an
     unquoted macro argument, or where a request expected a numeric
     expression argument.

'missing'
'8192'
     A request was invoked with a mandatory argument absent.

'input'
'16384'
     An invalid character occurred on the input stream.

'escape'
'32768'
     An unsupported escape sequence was encountered.

'space'
'65536'
     A space was missing between a request or macro and its argument.
     This warning is produced when an undefined name longer than two
     characters is encountered and the first two characters of the name
     constitute a defined name.  No request is invoked, no macro called,
     and an empty macro is not defined.  This category is enabled by
     default.  It never occurs in compatibility mode.

'font'
'131072'
     A non-existent font was selected.  This category is enabled by
     default.

'ig'
'262144'
     An invalid escape sequence occurred in input ignored using the 'ig'
     request.  This warning category diagnoses a condition that is an
     error when it occurs in non-ignored input.

'color'
'524288'
     An undefined color was selected, an attempt was made to define a
     color using an unrecognized color space, an invalid channel value
     in a color definition was encountered, or an attempt was made to
     redefine a default color.

'file'
'1048576'
     An attempt was made to read a file that does not exist, or a stream
     remained open at formatter exit.  This category is enabled by
     default.

   Two warning names group other warning categories for convenience.

'all'
     All warning categories except 'di', 'mac' and 'reg'.  This
     shorthand is intended to produce all warnings that are useful with
     macro packages written for AT&T 'troff' and its descendants, which
     have less fastidious diagnostics than GNU 'troff'.

'w'
     All warning categories.  Authors of documents and macro packages
     targeting 'groff' are encouraged to use this setting.


File: groff.info,  Node: Implementation Differences,  Prev: Debugging,  Up: GNU troff Reference

5.39 Implementation Differences
===============================

GNU 'troff' has a number of features that cause incompatibilities with
documents written for other versions of 'troff'.  Some GNU extensions to
'troff' have become supported by other implementations.

* Menu:

* Safer Mode::
* Compatibility Mode::
* Other Differences::


File: groff.info,  Node: Safer Mode,  Next: Compatibility Mode,  Up: Implementation Differences

5.39.1 Safer Mode
-----------------

GNU 'troff' operates in "safer mode" by default; to mitigate risks from
untrusted input documents, it disables the 'cf', 'pi', and 'sy'
requests.  GNU 'troff''s '-U' option enables "unsafe mode", restoring
their function and enabling additional extension requests, 'open',
'opena', and 'pso'.  Recall *note Host System Service Access::.


File: groff.info,  Node: Compatibility Mode,  Next: Other Differences,  Prev: Safer Mode,  Up: Implementation Differences

5.39.2 Compatibility Mode
-------------------------

Some syntactical and behavioral differences between GNU and AT&T
'troff's are thought too important to neglect; GNU 'troff' therefore
makes available a "compatibility mode" in an effort to keep documents
prepared for AT&T 'troff' rendering well.

   Identifiers of arbitrary length may be GNU 'troff''s most obvious
innovation.  AT&T 'troff' interprets '.dsabcd' as defining a string 'ab'
with contents 'cd'.  Normally, GNU 'troff' interprets this input as
calling a macro named 'dsabcd'.  AT&T 'troff' also interprets '\*[' and
'\n[' as interpolating a string or register, respectively, named '['.
GNU 'troff', however, normally interprets '[' as bracketing a long name
(with ']' at the distal end).  In compatibility mode, GNU 'troff'
interprets names in the traditional way; they thus can be two characters
long at most.

 -- Request: .cp [b]
 -- Register: \n[.C]
     Enable or disable AT&T 'troff' compatibility mode per Boolean
     expression B.  It is disabled by default, and enabled if B is
     omitted.  In compatibility mode, long names are not recognized, and
     the incompatibilities they cause do not arise.

     The read-only register '.C' interpolates 1 if compatibility mode is
     enabled, 0 otherwise.

     GNU 'troff''s '-C' command-line option causes it to start up in
     compatibility mode.

 -- Request: .do name [argument ...]
 -- Register: \n[.cp]
     Interpret the string, request, diversion, or macro NAME (along with
     any further arguments) with compatibility mode disabled.
     Compatibility mode is restored (only if it was active) when the
     interpolation of NAME is interpreted; that is, the restored
     compatibility state applies to the request or contents of the
     macro, string, or diversion NAME, its arguments, and data read from
     files or pipes if NAME is the 'so', 'soquiet', 'mso', 'msoquiet',
     or 'pso' request.

     The following example illustrates several aspects of 'do' behavior.

          .de mac1
          FOO
          ..
          .de1 mac2
          groff
          .mac1
          ..
          .de mac3
          compatibility
          .mac1
          ..
          .de ma
          \\$1
          ..
          .cp 1
          .do mac1
          .do mac2 \" mac2, defined with .de1, calls "mac1"
          .do mac3 \" mac3 calls "ma" with argument "c1"
          .do mac3 \[ti] \" groff syntax accepted in .do arguments
              => FOO groff FOO compatibility c1 ~

     The read-only register '.cp', meaningful only when dereferenced
     from a 'do' request, is 1 if compatibility mode was on when the
     'do' request was encountered, and 0 if it was not.  This register
     is specialized and may require a statement of rationale.

     When writing macro packages or documents that use GNU 'troff'
     features and which may be mixed with other packages or documents
     that do not--common scenarios include serial processing of man
     pages or use of the 'so' or 'mso' requests--you may desire correct
     operation regardless of compatibility mode enablement in the
     surrounding context.  It may occur to you to save the existing
     value of '\n(.C' into a register, say, '_C', at the beginning of
     your file, turn compatibility mode off with '.cp 0', then restore
     it from that register at the end with '.cp \n(_C'.  At the same
     time, a modular design of a document or macro package may lead you
     to multiple layers of inclusion.  You cannot use the same register
     name everywhere lest you "clobber" the value from a preceding or
     enclosing context.  The two-character register name space of AT&T
     'troff' is confining, but employing GNU 'troff''s more capacious
     one, as with '.nr _my_saved_C \n(.C', does not work in
     compatibility mode; the register name is too long.  Employing the
     'do' request is no help: '.do nr _my_saved_C \n(.C' always saves
     zero to the register, because 'do' turns compatibility mode _off_
     while it interprets its argument list.

     To robustly save compatibility mode before switching it off, use

          .do nr _my_saved_C \n[.cp]
          .cp 0

     at the beginning of your file, followed by

          .cp \n[_my_saved_C]
          .do rr _my_saved_C

     at the end.  As the C language exposes application programs'
     symbols to those defined by libraries, 'roff' documents share a
     name space with macro packages; choose a register name that is
     unlikely to collide with other uses.

   Normally, GNU 'troff' tracks the nesting depth of interpolations.  In
compatibility mode, it does not.

     .ds xx '
     \w'abc\*(xxdef'
         => 168 (not in compatibility mode on a terminal device)
         => 72def' (compatibility mode on a terminal device)

   The escape sequences '\f', '\H', '\m', '\M', '\R', '\s', and '\S' are
transparent to control character recognition at the beginning of a line,
or after the conditional expression of an 'if' or 'ie' request, only in
compatibility mode.  That is, upon interpreting them, GNU 'troff'
normally no longer recognizes a control character on the input line; but
in compatibility mode, it does, just like AT&T 'troff'.  Thus the next
example produces bold output in both modes, but the text differs.

     .de xx
     Hello!
     ..
     \fB.xx\fP
         => .xx (not in compatibility mode)
         => Hello! (in compatibility mode)

   Normally, the syntax form '\s'N accepts only a single character (a
digit) for N, consistently with other forms that originated in AT&T
'troff', like '\*', '\f', '\g', '\k', '\n', and '\z'.  In compatibility
mode only, a non-zero N must be in the range 4-39.  Legacy documents
relying upon this quirk of parsing(1) (*note Compatibility
Mode-Footnote-1::) should migrate to another '\s' form.

   In compatibility mode, the 'de', 'am', 'ds', and 'as' requests behave
as 'de1', 'am1', 'ds1', and 'as1', respectively: GNU 'troff' inserts a
compatibility save token at the beginning of the macro, string, or
appendment thereto as applicable and a compatibility restore token at
its end, enabling compatibility mode during its interpolation.(2)
(*note Compatibility Mode-Footnote-2::) Thus they work as expected even
if the interpolation context disables compatibility mode.

   AT&T 'troff' recognized slightly varying sets of delimiters when
expecting numerical expressions (as with the '\h' escape sequence),
string expressions (as with the '\w' escape sequence and 'tl' request),
and output comparisons (as in '.if #foo#bar# .tm match').  GNU 'troff',
when not in compatibility mode, recognizes a single consistent set of
delimiters.  Compatibility mode emulates AT&T 'troff' only up to a
point.  GNU 'troff' accepts leaders and tabs as delimiters, as well as
<Control+D> (EOT or EOF), <Control+H> (BS or backspace), and <Control+L>
(FF or form feed), all of which, when used as delimiters, cause AT&T
'troff' to behave in ways difficult to predict.


File: groff.info,  Node: Compatibility Mode-Footnotes,  Up: Compatibility Mode

   (1) The Graphic Systems C/A/T phototypesetter (the original device
target for AT&T 'troff') supported only a few discrete type sizes in the
range 6-36 points, so Ossanna contrived a special case in the parser to
do what the user must have meant.  Kernighan warned of this in the 1992
revision of CSTR #54 (§2.3), and more recently, McIlroy referred to it
as a "living fossil".

   (2) Recall *note Strings::.


File: groff.info,  Node: Other Differences,  Prev: Compatibility Mode,  Up: Implementation Differences

5.39.3 Other Differences
------------------------

GNU 'troff' does not emit output if it has nothing to format.  For
example, it treats an input document consisting solely of 'nr' and 'tm'
requests as empty, and produces nothing on its standard output stream.
AT&T 'troff' does, creating a blank page.

   Use of C0 control characters in identifiers is not portable; Solaris,
Plan 9, and Heirloom Doctools 'troff's accept <Control+B>, <Control+C>,
<Control+E>, <Control+F>, and <Control+G> (only); DWB 3.3 'troff' does
not.  GNU 'troff' rejects C0 controls in identifiers with an error
diagnostic.

   Formatters that don't implement GNU 'troff' extension request names
tend to ignore them, and if they don't support a GNU 'troff' extension
escape sequence, they are liable to format its function selector
character as text.  For example, the adjustable, non-breaking space
escape sequence '\~' is also supported by Heirloom Doctools 'troff'
050915 (September 2005), 'mandoc' 1.9.5 (2009-09-21), 'neatroff' (commit
1c6ab0f6e, 2016-09-13), and Plan 9 from User Space 'troff' (commit
93f8143600, 2022-08-12), but not by Solaris or Documenter's Workbench
'troff's, which both render it as '~'.  Recall *note Manipulating
Filling and Adjustment::.  GNU 'troff''s features sometimes cause
incompatibilities with documents written assuming old implementations of
'troff'.

   AT&T 'troff' discards trailing spaces from input lines, like GNU
'troff', but when it does so, AT&T 'troff' also cancels end-of-sentence
detection.  Use of the dummy character escape sequence '\&' is more
portable.

   When adjusting output lines to both margins, AT&T 'troff' at first
adjusts spaces starting from the right; GNU 'troff' begins from the
left.  Both implementations adjust spaces from opposite ends on
alternating output lines in this adjustment mode to prevent "rivers" in
the text.

   GNU 'troff' does not always hyphenate words as AT&T 'troff' does.
The AT&T implementation uses a set of hard-coded rules specific to U.S.
English, while GNU 'troff' uses language-specific hyphenation pattern
files derived from TeX.  Some versions of 'troff' reserved meager
storage for hyphenation exception words (arguments to the 'hw' request);
GNU 'troff' has no such restriction.  When the 'hy' request is invoked
without an argument, GNU 'troff' sets the automatic hyphenation mode to
the value of the '.hydefault' register; the AT&T implementation sets it
to '1', which is not suitable in GNU 'troff' for some languages,
including English.

   Unlike GNU 'troff', AT&T 'troff' does not recognize an occurrence of
'\%' at the beginning of a word as suppressing its hyphenation; instead,
it (uselessly) marks the start of the word as a potential hyphenation
point, permitting output lines to end with hyphens that are not interior
to a word.

   GNU 'troff' handles the dummy character '\&' differently from AT&T
'troff' when it is followed by the hyphenation control escape sequence
'\%' at the beginning of a word.  GNU 'troff' does not regard the dummy
character as "starting" the word; AT&T 'troff' does.  Further, Heirloom
Doctools 'troff' does not honor an explicit hyphenation point marked
with '\%' after a word-initial one.(1)  (*note Other
Differences-Footnote-1::)

   GNU 'troff' interprets request arguments representing file names and
system commands in the same way it does the CONTENTS argument to the
'ds' and 'as' requests: it removes a leading neutral double quote '"'
from the argument to the 'cf', 'nx', 'pi', 'so', and 'sy' requests, and
the second argument (if present) to the 'lf' request, permitting initial
embedded spaces in it, and reads it to the end of the input line in copy
mode.  Recall *note Copy Mode::.  This difference permits the formatter
to handle files with spaces in their names, but requires more care with
trailing comments, and doubling of an initial neutral double quote '"'
if the file name has one.

   The existence of the '.T' string is a common feature of
device-independent 'troff's--DWB 3.3, Solaris, Heirloom Doctools, and
Plan 9 'troff's all support it--but valid values are specific to each
implementation.

   The (read-only) register '.T' interpolates 1 if GNU 'troff' is run
with the '-T' option, and 0 otherwise.  In contrast, AT&T 'troff'
interpolated 1 only if 'nroff' was the formatter and was run with '-T'.

   AT&T 'troff' ignored attempts to remove read-only registers; GNU
'troff' honors such requests.  Recall *note Built-in Registers::.

   The 'lf' request sets the number of the _current_ input line in AT&T
'troff' and the _next_ in GNU 'troff'.

   AT&T 'troff' had only environments named '0', '1', and '2'.  In GNU
'troff', any number of environments may exist, using any valid
identifiers for their names.  Recall *note Identifiers::.

   As noted in *note Using Fractional Type Sizes::, AT&T 'troff''s 'ps'
request ignores scaling units and thus '.ps 10u' sets the type size to
10 points, whereas in GNU 'troff' it sets the type size to 10 _scaled_
points, possibly a much smaller measurement.  AT&T's behavior also means
that '.ps 10p' and '.ps 10z' are portable.

   The 'ab' request differs from AT&T 'troff': GNU 'troff' writes no
message to the standard error stream if no arguments are given, and it
exits with a failure status instead of a successful one.

   The 'bp' request differs from AT&T 'troff': GNU 'troff' does not
accept a scaling unit on the argument, a page number; the former does
(uselessly).

   In AT&T 'troff', the 'pm' request reports macro, string, and
diversion sizes in units of 128-byte blocks, and an argument reduces the
report to a sum of the above in the same units.  GNU 'troff' reports
their lengths in characters or nodes if given no arguments, and
otherwise dumps the JSON-encoded name, contents, and other properties of
each named argument.

   AT&T 'troff' ignores the 'ss' request if the output is a terminal
device; GNU 'troff' rounds down the values of minimum inter-word and
additional inter-sentence space each to the nearest multiple of 12.

   GNU 'troff' distinguishes characters from glyphs.  Characters can be
ordinary, special, or indexed, and populate strings and macros.
Characters _per se_ have not (yet) been formatted.  Glyphs represent
graphemes (supplied by the output device) and populate diversions
(recall *note Diversions::).  Formatting converts characters into
(sequences of) glyphs.  GNU 'troff' stores properties of the environment
that affect how a glyph is rendered with the glyph node's data.  Thus,
subsequent formatting operations do not affect it, including 'bd', 'cs',
'tkf', 'tr', and 'fp' requests.  Normally, a macro or string contains
only a list of characters and a diversion contains only a list of nodes.
However, applying the 'asciify' or 'unformat' requests to a diversion
converts some of its nodes back into characters.  Where the formatter
cannot recover the character representation of a node, it stores a null
character in the character list corresponding to a single node in the
node list.

   Consequently, a glyph node does not behave as a character does in
macro interpolation: it does not inherit special properties that the
character from which it was constructed might have had.  For example,
the input

     .di x
     \\\\
     .br
     .di
     .x

produces '\\' in GNU 'troff'.  Each pair of backslashes becomes one
backslash _glyph_; the resulting backslashes are thus not interpreted as
escape _characters_ when they are interpolated as the diversion is
output.  AT&T 'troff' _would_ interpret them as escape characters when
interpolating them and end up printing one '\'.

   One correct way to obtain a printable backslash in most documents is
to use the '\e' escape sequence; this always prints a single instance of
the current escape character,(2) (*note Other Differences-Footnote-2::)
regardless of whether it is used in a diversion; it also works in both
GNU 'troff' and AT&T 'troff'.

   The other correct way, appropriate in contexts independent of the
backslash's common use as a 'roff' escape character--perhaps in
discussion of character sets or other programming languages--is the
special character escape sequence '\(rs' or '\[rs]', for "reverse
solidus", from its name in the ECMA-6 and ISO 10646 standards.(3)
(*note Other Differences-Footnote-3::)

   To store in a diversion an escape sequence that is interpreted when
the diversion is interpolated, either use the traditional '\!'
transparent output facility, or, if this is unsuitable, the new '\?'
escape sequence.  Recall *note Diversions:: and *note GNU troff
Internals::.

   Like AT&T 'troff', GNU 'troff' maintains a buffer of
device-independent output commands,(4) (*note Other
Differences-Footnote-4::) populating the buffer as formatted output
accumulates.  GNU 'troff' always flushes this buffer when processing a
break; AT&T 'troff' does so according to no obvious schedule.  (Perhaps,
if the buffer is of fixed size, the formatter performs the flush when
the buffer runs out of room.)

   In the somewhat pathological case where a diversion exists containing
a partially collected line and a partially collected line at the
top-level diversion has never existed, AT&T 'troff' outputs a partially
collected but otherwise empty line (as if '\c' were in the top-level
diversion) at the end of input; GNU 'troff' does not.


File: groff.info,  Node: Other Differences-Footnotes,  Up: Other Differences

   (1) Thus,
     .ll 10n
     \%antidisestablishmen\%tarianism
     .br
     \&\%antidisestablishmen\%tarianism
     .pl \n(nlu
   produces different results with each of the three formatters.

   (2) Naturally, if you've changed the escape character, you need to
prefix the 'e' with whatever it is--and you'll likely get something
other than a backslash in the output.

   (3) AT&T 'troff''s font description files did not define the 'rs'
special character, but those of its descendant Heirloom Doctools 'troff'
do, as of its 060716 release (July 2006).

   (4) In GNU 'troff', node objects produce these commands; recall *note
GNU troff Internals::.


File: groff.info,  Node: File Formats,  Next: Copying This Manual,  Prev: GNU troff Reference,  Up: Top

6 File Formats
**************

All files that GNU 'troff' reads and writes are text files.(1)  (*note
File Formats-Footnote-1::) The next two sections describe their format.

* Menu:

* Device and Font Description Files::
* GNU troff Output::


File: groff.info,  Node: File Formats-Footnotes,  Up: File Formats

   (1) GNU 'troff' also reads files that don't satisfy the strict POSIX
definition of a text file--for example, those lacking a final newline
character--and the 'cf' and 'trf' requests read arbitrary files.  Recall
*note Host System Service Access::.


File: groff.info,  Node: Device and Font Description Files,  Next: GNU troff Output,  Up: File Formats

6.1 Device and Font Description Files
=====================================

The 'groff' font and output device description formats are slight
extensions of those used by AT&T device-independent 'troff'.  In
distinction to the AT&T implementation, 'groff' lacks a binary format;
all files are text files.(1)  (*note Device and Font Description
Files-Footnote-1::) The device and font description files for a device
NAME are stored in a 'devNAME' directory.  The device description file
is called 'DESC', and, for each font supported by the device, a font
description file is called 'F', where F is usually an abbreviation of a
font's name and/or style.  For example, the 'ps' (PostScript) device has
'groff' font description files for Times roman ('TR') and Zapf Chancery
Medium italic ('ZCMI'), among many others, while the 'utf8' device (for
terminals) has font descriptions for the roman, italic, bold, and
bold-italic styles ('R', 'I', 'B', and 'BI', respectively).

   Device and font description files are read both by the formatter, GNU
'troff', and by output drivers.  The programs delegate these files'
processing to an internal library, 'libgroff', ensuring their consistent
interpretation.

* Menu:

* DESC File Format::
* Font Description File Format::


File: groff.info,  Node: Device and Font Description Files-Footnotes,  Up: Device and Font Description Files

   (1) Plan 9 'troff' has also abandoned the binary format.


File: groff.info,  Node: DESC File Format,  Next: Font Description File Format,  Up: Device and Font Description Files

6.1.1 'DESC' File Format
------------------------

The 'DESC' file contains a series of directives; each begins a line.
Their order is not important, with two exceptions: (1) the 'res'
directive must precede any 'papersize' directive; and (2) the 'charset'
directive must come last (if at all).  If a directive name is repeated,
later entries in the file override previous ones (except that the paper
dimensions are computed based on the 'res' directive last seen when
'papersize' is encountered).  Spaces and/or tabs separate words and are
ignored at line boundaries.  Comments start with the '#' character and
extend to the end of a line.  Empty lines are ignored.

'family FAM'
     The default font family is FAM.

'fonts N F1 ... FN'
     Fonts F1, ..., FN are mounted at font positions M+1, ..., M+N where
     M is the number of 'styles' (see below).  This directive may extend
     over more than one line.  A font name of '0' causes no font to be
     mounted at the corresponding position.

'hor N'
     The horizontal motion quantum is N basic units.  Horizontal
     measurements round to multiples of N.

'image_generator PROGRAM'
     Use PROGRAM to generate PNG images from PostScript input.  Under
     GNU/Linux, this is usually 'gs', but under other systems (notably
     Cygwin) it might be set to another name.  The 'grohtml' driver uses
     this directive.

'paperlength N'
     The vertical dimension of the output medium is N basic units
     (deprecated: use 'papersize' instead).

'papersize FORMAT-OR-DIMENSION-PAIR-OR-FILE-NAME ...'
     The dimensions of the output medium are as according to the
     argument, which is either a standard paper format, a pair of
     dimensions, or the name of a plain text file containing either of
     the foregoing.

     Recognized paper formats are the ISO and DIN formats 'A0'-'A7',
     'B0'-'B7', 'C0'-'C7', 'D0'-'D7'; the U.S. paper types 'letter',
     'legal', 'tabloid', 'ledger', 'statement', and 'executive'; and the
     envelope formats 'com10', 'monarch', and 'DL'.  Matching is
     performed without regard for lettercase.

     Alternatively, the argument can be a custom paper format in the
     format 'LENGTH,WIDTH' (with no spaces before or after the comma).
     Both LENGTH and WIDTH must have a unit appended; valid units are
     'i' for inches, 'c' for centimeters, 'p' for points, and 'P' for
     picas.  Example: '12c,235p'.  An argument that starts with a digit
     is always treated as a custom paper format.

     Finally, the argument can be a file name (e.g., '/etc/papersize');
     if the file can be opened, the first line is read and a match
     attempted against each of the other forms.  No comment syntax is
     supported.

     More than one argument can be specified; each is scanned in turn
     and the first valid paper specification used.

'paperwidth N'
     The horizontal dimension of the output medium is N basic units
     (deprecated: use 'papersize' instead).

'pass_filenames'
     Direct GNU 'troff' to emit the name of the source file being
     processed.  This is achieved with the intermediate output command
     'x F', which 'grohtml' interprets.

'postpro PROGRAM'
     Use PROGRAM as the postprocessor.

'prepro PROGRAM'
     Use PROGRAM as a preprocessor.  The 'html' and 'xhtml' output
     devices use this directive.

'print PROGRAM'
     Use PROGRAM as a spooler program for printing.  If omitted, the
     '-l' and '-L' options of 'groff' are ignored.

'res N'
     The device resolution is N basic units per inch.

'sizes S1 ... SN 0'
     The device has fonts at S1, ..., SN scaled points (see below).  The
     list of sizes must be terminated by '0'.  Each SI can also be a
     range of sizes M-N.  The list can extend over more than one line.

'sizescale N'
     A typographical point is subdivided into N scaled points.  The
     default is '1'.  *Note Using Fractional Type Sizes::.

'styles S1 ... SM'
     The first M mounting positions are associated with styles S1, ...,
     SM.

'tcommand'
     The postprocessor can handle the 't' and 'u' intermediate output
     commands.

'unicode'
     The output device supports the complete Unicode repertoire.  This
     directive is useful only for devices that produce character
     entities instead of glyphs.

     If 'unicode' is present, no 'charset' section is required in the
     font description files since the Unicode handling built into
     'groff' is used.  However, if there are entries in a font
     description file's 'charset' section, they either override the
     default mappings for those particular characters or add new
     mappings (normally for composite characters).

     The 'utf8', 'html', and 'xhtml' output devices use this directive.

'unitwidth N'
     Arbitrary basis with respect to which font metrics are
     proportionally scaled when rendering glyphs at a type size of one
     point.

'unscaled_charwidths'
     Make the font handling module always return unscaled character
     widths.  The 'grohtml' driver uses this directive.

'use_charnames_in_special'
     GNU 'troff' should encode special characters in arguments to device
     extension commands; see *note Postprocessor Access::.  The
     'grohtml' driver uses this directive.

'vert N'
     The vertical motion quantum is N basic units.  Vertical
     measurements round to multiples of N.

'charset'
     This line and everything following it in the file are ignored.  It
     is recognized for compatibility with other 'troff' implementations.
     In GNU 'troff', character set repertoire is described on a per-font
     basis.

   GNU 'troff' recognizes but ignores the directives 'spare1', 'spare2',
and 'biggestfont'.

   The 'res', 'unitwidth', 'fonts', and 'sizes' lines are mandatory.
Directives not listed above are ignored by GNU 'troff' but may be used
by postprocessors to obtain further information about the device.


File: groff.info,  Node: Font Description File Format,  Prev: DESC File Format,  Up: Device and Font Description Files

6.1.2 Font Description File Format
----------------------------------

On typesetting output devices, each font is typically available at
multiple sizes.  While paper measurements in the device description file
are in absolute units, measurements applicable to fonts must be
proportional to the type size.  The font's unit width establishes a
numerical basis that permits all of its metrics to be expressed as
integers if rendered at one point.  When the formatter configures a type
size, it scales the metrics linearly relative to that basis.  The unit
width has no inherent relationship to the device resolution, and the
same division procedure applies to all font metrics.  Observe that
whatever unit might one select for the unit width, the division
operation implied by scaling cancels it out, leaving a dimensionless
quantity.

   For instance, 'groff''s 'lbp' device uses a 'unitwidth' directive
with an argument of 800.  Its Times roman font 'TR' has a 'spacewidth'
of 833; this is also the width of its comma, period, centered period,
and mathematical asterisk, while its 'M' has a width of 2,963.  Thus, an
'M' on the 'lbp' device is 2,963 ÷ 800 times the unit width, or
approximately 3.7.  At a type size of 10 points, a Times roman 'M' is
therefore 37 units wide.

     $ groff -T lbp
     .ps 10
     .nr Mw \w'M'
     .tm width of 'M' at 10 points=\n(Mw
         error-> width of 'M' at 10 points=37

   A font description file has two sections.  The first is a sequence of
directives, and is parsed similarly to the 'DESC' file described above.
Except for the directive names that begin the second section, their
ordering is immaterial.  Later directives of the same name override
earlier ones, spaces and tabs are handled in the same way, and the same
comment syntax is supported.  Empty lines are ignored throughout.

'name F'
     The name of the font is F.  'DESC' is an invalid font name.  Simple
     integers are valid, but their use is discouraged.(1)  (*note Font
     Description File Format-Footnote-1::)

'spacewidth N'
     The width of an unadjusted inter-word space is N, relative to the
     device's unit width.

   The directives above must appear in the first section; those below
are optional.

'slant N'
     The font's glyphs have a slant of N degrees; a positive N slants in
     the direction of text flow.

'ligatures LIG1 ... LIGN [0]'
     Glyphs LIG1, ..., LIGN are ligatures; possible ligatures are 'ff',
     'fi', 'fl', 'ffi' and 'ffl'.  For compatibility with other 'troff'
     implementations, the list of ligatures may be terminated with
     a '0'.  The list of ligatures must not extend over more than one
     line.

'special'
     The font is "special": when the document attempts to format a glyph
     that is not present in the formatter's currently selected font, the
     glyph is sought in any mounted fonts that bear this property.
     Often, such fonts are "unstyled", having no heavy (bold) or slanted
     (italic or oblique) variants.

   Other directives in this section are ignored by GNU 'troff', but may
be used by postprocessors to obtain further information about the font.

   The second section contains one to three subsections, which can
appear in any order, and any of which starts the second section.  Each
starts with a directive on a line by itself.  A 'charset' subsection is
mandatory unless the associated 'DESC' file contains the 'unicode'
directive.  Another subsection, 'kernpairs', is optional.

   The directive 'charset' starts the character set subsection.(2)
(*note Font Description File Format-Footnote-2::) It precedes a series
of glyph descriptions, one per line.  Each such glyph description
comprises a set of fields separated by spaces or tabs and organized as
follows.

     NAME METRICS TYPE INDEX [ENTITY-NAME] ['--' COMMENT]

NAME identifies the glyph: if NAME is a printable character C, it
corresponds to the 'troff' ordinary character C.  If NAME is a
multi-character sequence not beginning with '\', it corresponds to the
GNU 'troff' special character escape sequence '\[NAME]'.  A name
consisting of three minus signs, '---', is special and indicates that
the glyph is unnamed: such glyphs can be accessed only by the '\N'
escape sequence in 'troff'.  A special character named '---' can still
be defined using 'char' and similar requests.  The NAME '\-' defines the
minus sign glyph.  Finally, NAME can be the unbreakable one-sixth and
one-twelfth space escape sequences, '\|' and '\^' ("thin" and "hair"
spaces, respectively), in which case only the width metric described
below is interpreted; a font can thus customize the widths of these
spaces.

   The form of the METRICS field is as follows.

     WIDTH[','[HEIGHT[','[DEPTH[','[ITALIC-CORRECTION
       [','[LEFT-ITALIC-CORRECTION[','[SUBSCRIPT-CORRECTION]]]]]]]]]]

Spaces, tabs, and newlines are prohibited between these "subfields",
which are expressed as decimal integers (and have been split here into
two lines only for better legibility).  The unit of measure is that
established by the 'unitwidth' directive and scaled to the type size.
Unspecified subfields default to '0'.  Since there is no associated
binary format, these values are not required to fit into the C language
data type 'char' as they are in AT&T device-independent 'troff'.

   The WIDTH subfield gives the width of the glyph.  The HEIGHT subfield
gives the height of the glyph (upward is positive); if a glyph does not
extend above the baseline, give it a zero height, not a negative height.
The DEPTH subfield gives the depth of the glyph--that is, the distance
below the baseline to which the glyph extends (downward is positive); if
a glyph does not extend below the baseline, give it a zero depth, not a
negative depth.  Italic corrections apply when upright and slanted
(italic or oblique) styles are typeset adjacently.  The
ITALIC-CORRECTION is the amount of space to add after a slanted glyph to
be followed immediately by an upright glyph.  The LEFT-ITALIC-CORRECTION
is the amount of space to add before a slanted glyph to be preceded
immediately by an upright glyph.  The SUBSCRIPT-CORRECTION is the amount
of space to add after a slanted glyph to be followed by a subscript; it
should be less than the italic correction.

   For fonts used with typesetters, the TYPE field gives a featural
description of the glyph: it is a bit mask recording whether the glyph
is an ascender, descender, both, or neither.  When a '\w' escape
sequence is interpolated, these values are bitwise or-ed together for
each glyph and stored in the 'nr' register.  In font descriptions for
terminals, all glyphs might have a type of zero, regardless of their
appearance.

'0'
     means the glyph lies entirely between the baseline and a horizontal
     line at the "x-height" of the font; typical examples are 'a', 'c',
     and 'x';

'1'
     means the glyph descends below the baseline, like 'p';

'2'
     means the glyph ascends above the font's x-height, like 'A' or 'b';
     and

'3'
     means the glyph is both an ascender and a descender--this is true
     of parentheses in some fonts.

   The INDEX field is an integer that uniquely identifies a glyph within
the font; any integer is accepted as input,(3) (*note Font Description
File Format-Footnote-3::) but no practical font employs all possible
values.  An INDEX is limited to the range of the system's C language
data type 'int'.  In a 'troff' document, use the indexed character
escape sequence '\N' to specify a glyph by index.

   The ENTITY-NAME field defines an identifier for the glyph that the
postprocessor uses to print the GNU 'troff' glyph NAME.  This field is
optional; it was introduced so that the 'grohtml' output driver could
encode its character set.  For example, the glyph '\[Po]' is represented
by '&pound;' in HTML 4.0.  For efficiency, these data are now compiled
directly into 'grohtml'.  'grops' uses the field to build sub-encoding
arrays for PostScript fonts containing more than 256 glyphs.  Anything
on the line after the ENTITY-NAME field or '--' is ignored.

   A line in the 'charset' section can also have the form

     NAME "

identifying NAME as another name for the glyph mentioned in the
preceding line.  Such aliases can be chained.

   A 'charset-range' subsection works like the 'charset' directive
except that the glyph descriptions use a NAME of the form
'u'AAAA'..u'FFFF, where AAAA and FFFF are hexadecimal digit sequences;
the specified metrics then apply identically to all glyphs in the
designated range.

   The directive 'kernpairs' starts a list of kerning adjustments to be
made to adjacent glyph pairs from this font.  It contains a sequence of
lines formatted as follows.

     G1 G2 N

The foregoing means that when glyph G1 is typeset immediately before G2,
the space between them should be increased by N.  The unit of measure is
that established by the 'unitwidth' directive and scaled to the type
size.  Most kerning pairs should have a negative value for N.


File: groff.info,  Node: Font Description File Format-Footnotes,  Up: Font Description File Format

   (1) 'groff' requests and escape sequences interpret non-negative
integers as mounting positions instead.  Further, a font named '0'
cannot be automatically mounted by the 'fonts' directive of a 'DESC'
file.

   (2) On typesetters, this directive is misnamed since it starts a list
of glyphs, not characters.

   (3) that is, any integer parsable by the C standard library's
'strtol(3)' function


File: groff.info,  Node: GNU troff Output,  Prev: Device and Font Description Files,  Up: File Formats

6.2 GNU 'troff' Output
======================

We now describe the 'groff' device-independent page description language
produced by GNU 'troff'.

   As 'groff' is a wrapper program around GNU 'troff' and automatically
runs 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 to 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.(1)  (*note GNU troff
Output-Footnote-1::)

   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.(2)  (*note GNU troff Output-Footnote-2::) A
decade later, when James Clark wrote 'groff', these constraints were no
longer as tight.

* Menu:

* Language Concepts::
* Command Reference::
* GNU troff Output Examples::
* Output Language Compatibility::


File: groff.info,  Node: GNU troff Output-Footnotes,  Up: GNU troff Output

   (1) The parser for device-independent output can be found in the file
'GROFF-SOURCE-DIR/src/libs/libdriver/input.cpp'.

   (2) See "A Typesetter-independent TROFF", Bell Labs CSTR #97, 1982.


File: groff.info,  Node: Language Concepts,  Next: Command Reference,  Up: GNU troff Output

6.2.1 Language Concepts
-----------------------

The fundamental operation of the GNU 'troff' formatter is the
translation of the 'groff' 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" always refers to this device-independent output language, and
never to the language intended for direct 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 objects; and device
control 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.

* Menu:

* Syntax::
* Argument Units::
* Output Structure::


File: groff.info,  Node: Syntax,  Next: Argument Units,  Up: Language Concepts

6.2.1.1 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.

   The positioning commands noted above, 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.


File: groff.info,  Node: Argument Units,  Next: Output Structure,  Prev: Syntax,  Up: Language Concepts

6.2.1.2 Argument Units
......................

Some commands take integer arguments that are assumed to represent
values in a measurement unit, but the letter for the corresponding
scaling unit is not written with the output command arguments.  Most
commands assume the scaling unit 'u', the basic unit of the device, some
use 'z', the scaled point unit of the device, while others, such as the
color commands, expect plain integers.

   Single characters can have the eighth bit set, as can the names of
fonts and special characters.  The names of characters and fonts can be
of arbitrary length.  A character that is to be printed is always 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.

