File: groff.info, Node: Setting Registers.php">Registers, Next: Registers.php">Registers.php">Interpolating Registers.php">Registers, Prev: Registers.php">Registers, Up: Registers.php">Registers 5.8.1 Setting Registers ----------------------- Define registers and update their values with the 'nr' request or the '\R' escape sequence. -- Request: .nr ident value -- Escape sequence: \R'ident value' Set register IDENT to VALUE. If IDENT doesn't exist, GNU 'troff' creates it. In the '\R' escape sequence, the delimiter need not be a neutral apostrophe; see *note Delimiters::. It also does not produce an input token in GNU 'troff'. *Note Gtroff Internals::. .nr a (((17 + (3 * 4))) % 4) \n[a] .\R'a (((17 + (3 * 4))) % 4)' \n[a] => 1 1 (Later, we will discuss additional forms of 'nr' and '\R' that can change a register's value after it is dereferenced but before it is interpolated. *Note Auto-increment::.) The complete transparency of '\R' can cause surprising effects if you use 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 ('-Tps'), there will be a line break eventually after 'ggg' in both input lines. However, after processing the space after 'ggg', the partially collected line is not overfull yet, so GNU 'troff' 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 sequence 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 '.k' register that is even greater than the current line length. In the second input line, the insertion of '\h'0'' to cause a zero-width motion forces GNU 'troff' to check the line length, which in turn causes the start of a new output line. Now '.k' returns the expected value. 'nr' and '\R' each have two additional special forms to increment or decrement a register. -- Request: .nr ident +value -- Request: .nr ident -value -- Escape sequence: \R'ident +value' -- Escape sequence: \R'ident -value' Increment (decrement) register IDENT by VALUE. In the '\R' escape sequence, the delimiter need not be a neutral apostrophe; see *note Delimiters::. .nr a 1 .nr a +1 \na => 2 A leading minus sign in VALUE is always interpreted as a decrementation operator, not an algebraic sign. To assign a register a negative value or the negated value of another register, you can force GNU 'troff' to interpret '-' as a negation or minus, rather than decrementation, operator: enclose it with its operand in parentheses or subtract it from zero. .nr a 7 .nr b 3 .nr a -\nb \na => 4 .nr a (-\nb) \na => -3 .nr a 0-\nb \na => -3 If a register's prior value does not exist (the register was undefined), an increment or decrement is applied as if to 0. -- Request: .rr ident Remove register IDENT. If IDENT doesn't exist, the request is ignored. Technically, only the name is removed; the register's contents are still accessible under aliases created with 'aln', if any. -- Request: .rnn ident1 ident2 Rename register IDENT1 to IDENT2. If IDENT1 doesn't exist, the request is ignored. Renaming a built-in register does not otherwise alter its properties. -- Request: .aln new old Create an alias NEW for an existing register OLD, causing the names to refer to the same stored object. If OLD is undefined, a warning in category 'reg' is produced and the request is ignored. *Note Warnings::, for information about the enablement and suppression of warnings. To remove a register alias, invoke 'rr' on its name. A register's contents do not become inaccessible until it has no more names.
