Next: , Previous: Registers, Up: Registers


5.6.1 Setting Registers

Define or set registers using the nr request or the \R escape.

— Request: .nr ident value

— Escape: \R'ident value'

Set number register ident to value. If ident doesn't exist, gtroff creates it.

The argument to \R usually has to be enclosed in quotes. See Escapes, for details on parameter delimiting characters.

The \R escape doesn't produce an input token in gtroff; in other words, it vanishes completely after gtroff has processed it.

For example, the following two lines are equivalent:

     
     .nr a (((17 + (3 * 4))) % 4)
     \R'a (((17 + (3 * 4))) % 4)'
         ⇒ 1

Both nr and \R have two additional special forms to increment or decrement a register.

— Request: .nr ident +value

— Request: .nr ident -value

— Escape: \R'ident +value'

— Escape: \R'ident -value'

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
— Request: .rr ident

Remove number register ident. If ident doesn't exist, the request is ignored.

— Request: .rnn ident1 ident2

Rename number register ident1 to ident2. If either ident1 or ident2 doesn't exist, the request is ignored.

— Request: .aln ident1 ident2

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.