1

Using the ms macros and eqn, is there some way to number an equation in Groff automatically similar to LaTeX?

0

2 Answers 2

3

I don't see anything built-in to the ms macros for this, but you can always use the base troff number registers.

Add to the start the file the definition and initialisation of your number register (starts at 0, increment by 1):

.nr myeqn 0 1

Then whereever you use it as

\n+[myeqn]

it will be incremented and replaced by the current value. Eg

.EQ
e sup {i pi} + 1 = 0
.EN
.sp -1
.tl ' ' '... \n+[myeqn]'

If you want to use the same number again it is \n[myeqn] instead.

2
  • What does .tl do? I can't find it in any man page.
    – Al Bundy
    Commented May 8, 2021 at 17:16
  • 1
    It's in man 7 groff, and means three part title. .tl 'a'b'c' will put a on the left, b in the middle, and c on the right edge of the line.
    – meuh
    Commented May 8, 2021 at 17:55
1

meuh's answer is correct but not quite idiomatic.

There is a simpler way to get the equation number set to the right of the equation than messing with sp and tl requests.

ms's EQ macro accepts (optional) arguments, and if you give it a second argument, ms will set it to the right of the equation display for you.

    .EQ [align [label]]
    .EN Demarcate an equation to be processed by the eqn preprocessor.
        The equation is centered by default; align can be C, L, or I to
        (explicitly) center, left‐align, or indent it by \n[DI],
        respectively.  If specified, label is set right‐aligned.

The foregoing is from the groff_ms(7) page in groff Git. The version of the page in groff 1.22.4 is not as comprehensive.

So you can rewrite meuh's solution more briefly.

.nr myeqn 0 1
.\" ...stuff...
.EQ C \n+[myeqn]
e sup {i pi} + 1 = 0
.EN

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .