manpagez: man pages & more
info groff
Home | html | info | man

File: groff.info,  Node: Assigning Register Formats,  Next: Registers.php">Built-in Registers,  Prev: Auto-increment,  Up: Registers

5.8.4 Assigning Register Formats
--------------------------------

A writable register's value can be interpolated in several number
formats.  By default, conventional Arabic numerals are used.  Other
formats see use in sectioning and outlining schemes and alternative page
numbering arrangements.

 -- Request: .af reg fmt
     Use number format FMT when interpolating register REG.  Valid
     number formats are as follows.

     '0...'
          Arabic numerals 0, 1, 2, and so on.  Any decimal digit is
          equivalent to '0'; the formatter merely counts the digits
          specified.  Multiple Arabic numerals in FMT cause
          interpolations to be zero-padded on the left if necessary to
          at least as many digits as specified (interpolations never
          truncate a register value).  A register with format '00'
          interpolates values 1, 2, 3 as '01', '02', '03'.  The default
          format for all writable registers is '0'.

     'I'
          Uppercase Roman numerals: 0, I, II, III, IV, ...

     'i'
          Lowercase Roman numerals: 0, i, ii, iii, iv, ...

     'A'
          Uppercase letters: 0, A, B, C, ..., Z, AA, AB, ...

     'a'
          Lowercase letters: 0, a, b, c, ..., z, aa, ab, ...

     Omitting FMT causes a warning in category 'missing'.  *Note
     Warnings::, for information about the enablement and suppression of
     warnings.  Specifying an unrecognized format is an error.

     Zero values are interpolated as '0' in non-Arabic formats.
     Negative quantities are prefixed with '-' irrespective of format.
     In Arabic formats, the sign supplements the field width.  If REG
     doesn't exist, it is created with a zero value.

          .nr a 10
          .af a 0           \" the default format
          \na,
          .af a I
          \na,
          .af a 321
          .nr a (-\na)
          \na,
          .af a a
          \na
              => 10, X, -010, -j

     The representable extrema in the 'i' and 'I' formats correspond to
     Arabic ±39,999.  GNU 'troff' uses 'w' and 'z' to represent 5,000
     and 10,000 in Roman numerals, respectively, following the
     convention of AT&T 'troff'--currently, the correct glyphs for Roman
     numerals five thousand ('U+2181') and ten thousand ('U+2182') are
     not used.

     Assigning the format of a read-only register is an error.  Instead,
     copy the read-only register's value to, and assign the format of, a
     writable register.

 -- Escape sequence: \gr
 -- Escape sequence: \g(rg
 -- Escape sequence: \g[reg]
     Interpolate the format of the register REG (one-character name R,
     two-character name RG).  Zeroes represent Arabic formats.  If REG
     is not defined, REG is not created and nothing is interpolated.
     '\g' is interpreted even in copy mode (*note Copy Mode::).

   GNU 'troff' interprets only Arabic numerals.  The Roman numeral or
alphabetic formats cannot be used as operands to arithmetic operators in
expressions (*note Numeric Expressions::).  For instance, it may be
desirable to test the page number independently of its format.

     .af % i \" front matter
     .de header-trap
     .  \" To test the page number, we need it in Arabic.
     .  ds saved-page-number-format \\g%\"
     .  af % 0
     .  nr page-number-in-decimal \\n%
     .  af % \\*[saved-page-number-format]
     .  ie \\n[page-number-in-decimal]=1 .do-first-page-stuff
     .  el \{\
     .    ie o .do-odd-numbered-page-stuff
     .    el   .do-even-numbered-page-stuff
     .  \}
     .  rm saved-page-number-format
     ..
     .wh 0 header-trap

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.