Next: Built-in Registers, Previous: Auto-increment, Up: Registers [Contents][Index]
A writable register’s value can be interpolated in several number formats. Conventional Arabic numerals are the default format; others see use in sectioning and outlining schemes and alternative page numbering arrangements.
Apply number format fmt when interpolating register reg. The default format for all writable registers is ‘0’. Specifying an unrecognized format is an error. Valid 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’.
IUppercase Roman numerals: 0, I, II, III, IV, ...
iLowercase Roman numerals: 0, i, ii, iii, iv, ...
AUppercase letters: 0, A, B, C, …, Z, AA, AB, ...
aLowercase letters: 0, a, b, c, …, z, aa, ab, ...
The formatter interpolates zero values as ‘0’ and prefixes negative quantities with ‘-’ irrespective of format. In Arabic formats, the sign supplements the field width. Assigning a format to a nonexistent register creates it 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 ±3,999.117
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.
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.
The formatter interprets
\g
even in copy mode.118
GNU
troff interprets only Arabic numerals.
The Roman numeral or alphabetic formats
cannot be used as operands to arithmetic operators in expressions;
recall 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: Built-in Registers, Previous: Auto-increment, Up: Registers [Contents][Index]