Define or set registers using the
nr request or the
Although the following requests and escapes can be used to create registers, simply using an undefined register will cause it to be set to zero.
Set number register ident to value. If ident doesn’t
gtroff creates it.
The argument to
\R usually has to be enclosed in quotes.
See Escapes, for details on parameter delimiting characters.
\R escape doesn’t produce an input token in
in other words, it vanishes completely after
For example, the following two lines are equivalent:
.nr a (((17 + (3 * 4))) % 4) \R'a (((17 + (3 * 4))) % 4)' ⇒ 1
Note that the complete transparency of
\R can cause surprising
effects if you use number registers like
.k, which get evaluated
at the time they are accessed.
.ll 1.6i . aaa bbb ccc ddd eee fff ggg hhh\R':k \n[.k]' .tm :k == \n[:k] ⇒ :k == 126950 . .br . aaa bbb ccc ddd eee fff ggg hhh\h'0'\R':k \n[.k]' .tm :k == \n[:k] ⇒ :k == 15000
If you process this with the POSTSCRIPT device (
there will be a line break eventually after
ggg in both input
lines. However, after processing the space after
partially collected line is not overfull yet, so
continues to collect input until it sees the space (or in this case,
the newline) after
hhh. At this point, the line is longer
than the line length, and the line gets broken.
In the first input line, since the
\R escape leaves no traces,
the check for the overfull line hasn’t been done yet at the point where
\R gets handled, and you get a value for the
register that is even greater than the current line length.
In the second input line, the insertion of
\h'0' to emit an
invisible zero-width space forces
troff to check the line length,
which in turn causes the start of a new output line. Now
returns the expected value.
\R have two additional special forms to
increment or decrement a register.
Increment (decrement) register ident by value.
.nr a 1 .nr a +1 \na ⇒ 2
To assign the negated value of a register to another register, some care must be taken to get the desired result:
.nr a 7 .nr b 3 .nr a -\nb \na ⇒ 4 .nr a (-\nb) \na ⇒ -3
The surrounding parentheses prevent the interpretation of the minus sign as a decrementing operator. An alternative is to start the assignment with a ‘0’:
.nr a 7 .nr b -3 .nr a \nb \na ⇒ 4 .nr a 0\nb \na ⇒ -3
Remove number register ident. If ident doesn’t exist, the request is ignored.
Rename number register ident1 to ident2. If either ident1 or ident2 doesn’t exist, the request is ignored.
Create an alias ident1 for a number register ident2. The new name and the old name are exactly equivalent. If ident1 is undefined, a warning of type ‘reg’ is generated, and the request is ignored. See Debugging, for information about warnings.