[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] labelling and referring

From: Ted Harding
Subject: Re: [Groff] labelling and referring
Date: Mon, 29 Nov 2010 20:14:28 -0000 (GMT)

On 29-Nov-10 17:18:21, Patrik Schindler wrote:
> Am 29.11.2010 um 15:23 schrieb Tim23:
>> Is it possible to label equations or tables to refer to them from  
>> anywhere in a text?
> Yes, for equations this is possible. See the documentation for
> the .EQ-request to use equation numbering.
> For tables you have to build something yourself. Example:
> .\" Define Register TN with an autoincrement-Value of 1.
> .nr TN 0 1
> And for numbering tables:
> .(b
> .TS
> .TE
> .sz -2
> .ce 1
> Table \n+(TN: Foo Bar
> .sz
> .)b
> (I'm using me macros, so adjust to your needs)
>:wq! PoC

As well as using the auto-increment mechanism to create successive
table/equation numbers automatically, it is also useful to be able
to cross-reference them later in the text. I illustrate a possible
mechanism for equations (quoted from my standard setup):

.nr EQno 0 1
.ds EQnxt \Z'\h'0.5m'[\\n+[EQno]\\$1]'
.ds EQnow \Z'\h'0.5m'[\\n[EQno]\\$1]'

Then you invoke it as follows (say it is the formula for the
solution of a quadratic equation):

.EQ \*[EQnxt]
<eqn code for your equation>
.ds QuadEqn \*[EQnow]

You now have the number of the equation where you stated the
formula for the Quadratic Equation saved as \*[QuadEqn], and
you can refer to it at any later stage (and it will auto-adjust
appropriately if, in subsequent editing, you insert further
equations preceding that one). Example:

  For the formula for the solution of a quadratic equation,
  see Equation \*[QuadEqn] ...

If you want to plant a forward reference to an equation which
will only occur later, then you are into the more complicated
business of a "double run" of groff, in which the first run
saves identified items out to a file as definitions, and the
second run reads them back in.

By the way, the above code contains "cosmetic" things.
In particular, I like my equation numbers to be out in the
right margin, leaving more room for long equations (and also
making the equation numbers themselves more conspicuous and
easier to find by the reader), and I like them in [...].

A "plainer Jane" version is:

.nr EQno 0 1
.ds EQnxt \\n+[EQno]\\$1
.ds EQnow \\n[EQno]\\$1

The "\\$1" allows the possibility of appending extra bits
to the equation number, e.g.

.EQ \*[EQnxt A]

would give something like

   y = a X^2 + b X + c    2A

('A' could be anything, but you may need to quote it is it is

You can of course leave that off and have the real "plain Jane":

.nr EQno 0 1
.ds EQnxt \\n+[EQno]\\$1
.ds EQnow \\n[EQno]\\$1

An example of what the output from my standard mechanism looks
like can be seen at


E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 094 0861
Date: 29-Nov-10                                       Time: 20:08:56
------------------------------ XFMail ------------------------------

reply via email to

[Prev in Thread] Current Thread [Next in Thread]