Next: , Previous: , Up: Registers   [Contents][Index]


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’. See 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 (see Copy Mode).

GNU troff interprets only Arabic numerals. The Roman numeral or alphabetic formats cannot be used as operands to arithmetic operators in expressions (see 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

Next: , Previous: , Up: Registers   [Contents][Index]