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


5.6.3 Auto-increment

Number registers can also be auto-incremented and auto-decremented. The increment or decrement value can be specified with a third argument to the nr request or \R escape.

Request: .nr ident value incr

Set number register ident to value; the increment for auto-incrementing is set to incr. Note that the \R escape doesn’t support this notation.

To activate auto-incrementing, the escape \n has a special syntax form.

Escape: \n+i
Escape: \n-i
Escape: \n+(id
Escape: \n-(id
Escape: \n+[ident]
Escape: \n-[ident]

Before interpolating, increment or decrement ident (one-character name i, two-character name id) by the auto-increment value as specified with the nr request (or the \R escape). If no auto-increment value has been specified, these syntax forms are identical to \n.

For example,

.nr a 0 1
.nr xx 0 5
.nr foo 0 -2
\n+a, \n+a, \n+a, \n+a, \n+a
.br
\n-(xx, \n-(xx, \n-(xx, \n-(xx, \n-(xx
.br
\n+[foo], \n+[foo], \n+[foo], \n+[foo], \n+[foo]

produces

1, 2, 3, 4, 5
-5, -10, -15, -20, -25
-2, -4, -6, -8, -10

To change the increment value without changing the value of a register (a in the example), the following can be used:

.nr a \na 10