1

Is there a way in groff -ms to automatically number environments? As an example, here are two theorems I'd like to number 1.1 and 2.1.

.TL
Lorem ipsum
.NH
Introduction
\# First thm
.PP
.B Theorem .
Consectetur sed sunt nulla aute dolor elit ut quis.
.EQ
e sup {i pi} + 1 = 0
.EN
\# End of the first thm
.NH
Main result
.PP
.B Theorem .
Magna dolore.
.EQ
e sup {i tau} = 1
.EN
7
  • Could you say what part of the document you consider a theorem that should be numbered? It's unclear whether you are referring to the already numbered section (.NH), the bold text (.B) or the equations themselves (.EQ). Commented Jul 17, 2019 at 7:15
  • I added comments, a theorem is a whole paragraph with a bold title, a text and possibly equations. Commented Jul 17, 2019 at 7:26
  • sure - you could write macros to encapsulate the behavior you want, but for that, you need a tutorial (off-topic here). Commented Jul 17, 2019 at 7:52
  • @ThomasDickey It's not that different from "I have this code that almost works, and now I want to do this with it". It's not off-topic. Commented Jul 17, 2019 at 8:04
  • It may be complicated to do, but the request is simple: number paragraphs starting with a particular text. I don't see where the off-topic is. Commented Jul 17, 2019 at 8:14

1 Answer 1

3

Assuming you have looked at .NH 2 to give you 2nd level numbered headings, and that is not what is wanted, you can use your own number register, as shown in the man page .IP indented paragraph example.

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

.nr mytheorem 0 1

then whereever you use it as

\n+[mytheorem]

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

.PP 
\*[SN]\n+[mytheorem]
.B Theorem .

where SN is the section number (from .NH). You can reset the register by giving the .nr definition again. You can put the above into a macro at the start:

.de myTHEOREM
.PP
\\*[SN]\\n+[mytheorem]
.B Theorem .
..

and call it each time:

.myTHEOREM
Magna dolore.
.EQ
e sup {i tau} = 1
.EN
1
  • Absolutely perfect Commented Jul 17, 2019 at 8:46

You must log in to answer this question.