ECN No Name Newsletter: February, 1990

The ECN No Name Newsletter is no longer being published. This is an archived issue.

[previous article] [next article]

TROFF:Automatic Numbering Of Equations

Steve Weinrich

When placing equations throughout a paper, it is often useful to consecutively number them. A problem can arise when you reach the end of your paper and realize that you must insert an equation, in the middle!

You can avoid having to read through the entire document, renumbering equations and adjusting references by using the Troff commands explained below.

Equation Numbering

Troff is capable of storing a numeric value in a location called a number register. These number registers can be used as a variable to keep track of the current equation number. To use a number register, it must be initialized, as below:

        _______________________________________________________
        |     .nr eQ 0 1                                      |
        |    _________________________________________________|
        | nr | indicates a number register command follows    |
        |    |________________________________________________|
        | eQ | is the NAME of the number register.  Any one   |
        |    | or 2 letter combination may be used; however,  |
        |    | using a lower-case letter follow by an upper-  |
        |    | case letter avoids conflicting with existing   |
        |    | number registers used by the macro packages.   |
        |    |________________________________________________|
        | 0  | option indicating initial value of the register|
        |    |________________________________________________|
        | 1  | option indicating incrementing value           |
        |____|________________________________________________|

To access a number register within your text, start with the escape character, "\" followed by "n", then the name of the register. Note, if a two letter name is used, then an open parenthesis before the name is required. ie: "en(eQ".

To number multiple equations sequentially, employ the auto- increment feature of the number register. When a number register is referenced with a "+" preceding it, the value in the register will be incremented by N. "N" is the incrementing value supplied in the register's initialization line (as noted above). In most instances you will want this to be 1. Here is an example to clear up initial questions:

    Troff Code:      .nr eQ 0 1
                     .EQ (\n+(eQ)
                     a over b
                     .EN
                     .EQ (\n+(eQ)
                     y=( x sup 2 ) + 1
                     .EN

    Processed Text:  equation shown              (1)
                       
                     equation shown              (2)

This can be continued through an entire paper. Then without changing any other equation command, a new equation can be inserted and the numbering of all following equations will be updated.

Equation Referencing

Equation number referencing within a text can be accomplished through the same technique, except that it is necessary to STORE the number of the equation in a variable that can be referenced later.

As noted earlier, a number register can be initialized with a starting value. The following command assigns the register "eA" with the current value of "eQ".

.nr eA \n(eQ

Then, later in the paper, that equation can be referenced, as below:

...in equation \n(eA the variables are...

Used in conjunction with the auto-increment feature, this allows you to make generic numeric assignments to your equations, and any time a new equation is inserted, it will update the number AND subsequent references. Note that each equation reference variable (ie: "eA") must be UNIQUE. Meaning a new register must be created for each equation that will be referenced later. This final example shows how to use the features explained above.

Troff Code:

...and found that a large portion of the data conformed to the following equation:

     .sp
     .nr eQ 0 1
     .EQ {\n+(eQ}
     x=2 pi * sin ( omega t)dt * gamma
     .EN
     .nr eA \n(eQ    \"store equation number in variable
     .sp
     ...while we found that a smaller portion of
     the data conform to the following equation:
     .sp
     .EQ {\n+(eQ}
     x=2 pi * sin ( omega t ) dt 1 over gamma
     .EN
     .sp
     But as I stated earlier,
     we were searching for a curve of the form:
     .sp
     .EQ {\n+(eQ}
     x=2 pi * tan ( omega t)dt * cos ( gamma )
     .EN
     .nr eB \n(eQ    \"store equation number in variable
     .sp
     Noting in Equation \n(eA that gamma has
     a linear nature rather than, as seen in
     Equation \n(eB, having the cosine nature.

Processed Text:

...and found that a large portion of the data conformed to the following equation:

                     equation shown              (1)

...while we found that a smaller portion conformed to the following equation:

                     equation shown              (2)

But as I stated earlier, we were searching for a curve the form:

                     equation shown              (3)

Noting in Equation 1 that gamma has a linear nature rather than, as seen in Equation 3, having the cosine nature.


webmaster@ecn.purdue.edu
Last modified: Friday, 24-Oct-97 13:51:22 EST

[HTML Check] HTML