[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] automatic equation numbering
From: |
Ted Harding |
Subject: |
Re: [Groff] automatic equation numbering |
Date: |
Sat, 15 Mar 2014 23:50:36 -0000 (GMT) |
[See at end]
On 15-Mar-2014 20:54:10 Anton Shterenlikht wrote:
> Hi
>
> My groff experience is very limited. I've been using latex for
> years, so probably I just need to get used to groff ways of
> cross-referencing.
>
> I'd like to give a label to every equation, and then use those
> labels for cross-referencing, as in latex.
>
> I've done someting like this with mm EC + mmroff, but it's very clunky.
>
> So I wanted to ask - what is the easiest way of achieving equation
> (or table, figure, etc. ) cross-referencing with groff?
> I've only tried mm and ms, but will try other macro packages if advised.
>
> Thanks
> Anton
Here is a suggestion (it's a technique I use systematically for
the purpose you describe). The following is in the context of ms
macros, though the same (or possibly a slight variant) should work
for other macro sets.
**I first define an equation numbering and description system:
.nr EQno 0 1
.ds EQnxt \Z'\h'0.5m'[\\n+[EQno]\\$1]'
.ds EQnow \Z'\h'0.5m'[\\n[EQno]\\$1]'
.ds EQthing \Z'\h'0.5m'[\\$1]'
These define an auto-incrementing equation number \n[EQno],
so that, for instance (wsaqy we have already got up to equation [4],
.EQ \*[EQnxt]
phi ( x ) ~=~ exp( - half x sup 2 ) / sqrt{2 pi}
.EN
.ds EQnormdist \*[EQnow]
Then the above equation will have its equation number (5) displayed
to the right as " [5]", since the "\n+[EQno]" when "\n[EQnxt]" is
read will first increment \n[EQno] from 4 to 5.
The equation as written defines the probability density function
of the Normal distribution, and the line ".ds EQnormdist \*[EQnow]"
assigns this value to a string register \*[EQnormdist]. At any later
point in the document I can then refer to it as in the following:
Using the Normal density function defined by \*[EQnormdist] ...
which will then be rendered as;
Using the Normal density function defined by [5] ...
The presence of "\\$1" in
.ds EQnxt \Z'\h'0.5m'[\\n+[EQno]\\$1]'
.ds EQnow \Z'\h'0.5m'[\\n[EQno]\\$1]'
allows additional tags to be appended to the equation number string,
so that one could define equation numbers like [5a], [5b], ...
The definition
.ds EQthing \Z'\h'0.5m'[\\$1]'
allows an arbitrary string to be used as an equation reference, so that
one could write, say,
.ds EQnormal Normal
.EQ \*[EQnormal]
<expression for Normal distribution>
.EN
.ds EQpoisson Poisson
.EQ \*[EQpoisson]
<expression for Poisson distribution>
.EN
which would render as
<expression for Normal distribution> [Normal]
and
<expression for Poisson distribution> [Poisson]
and can again be referred to at arbitrary later points in the text
using the same string names "\*[EQnormal]" and "\*[EQpoisson]".
This works straightforwardly for back-references to equations
already defined. For forward-reference to equations yet to be defined
(in the auto-incrementing numbered case) it would be necessary to
implement a two-pass technique (such as is typical for page-numbers
etc.) in order to be able to refer to equations qhich have yet to be
defined. This problem does not arise for equations labelled with
text (such as "[Normal]") since they are fixed strings which can
be defined at the start of the document.
Hoping this helps! It is only one possible suggestion, and only
an outline. It would probably need some revision to match your
own needs.
Ted.
-------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Date: 15-Mar-2014 Time: 23:50:32
This message was sent by XFMail
-------------------------------------------------