[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Page numbers in ms keeps
From: |
John A. |
Subject: |
Re: Page numbers in ms keeps |
Date: |
Fri, 8 Jan 2021 02:50:56 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 |
John A. <john@ankarstrom.se> wrote:
Does anyone have a good solution for this problem?
.KF
[...]
The current page number is \n(PN.
.KE
If the floating keep above is moved to another page, because it doesn't
fit on the current one, then the PN (and %, for that matter) register
holds the incorrect page.
I just came up with a solution, which works for the majority of cases.
To illustrate, I have a TAG macro, which stores the current page number
in a named register, to which I can refer using a REF macro later in the
document:
.de TAG
.nr TAG_\\$1 \\n(PN
..
.de REF
\\$3\\n[TAG_\\$1]\\$2
..
To use the TAG macro within an ms keep (or indeed any other diversion),
I now use the following:
\!.TAG tagname
This postpones the processing of the line until the diversion is
actually inserted (see 5.25 "Diversions" in the groff manual).
Subsequently, TAG is called when the keep is inserted on the next page,
which means that the PN register is set correctly. Neat!
Best regards
John
P.S.
The caveat is that \! doesn't work very well if you want to insert the
page number into the keep/diversion itself (like in the example in my
original message). It comes out in the wrong size, left-aligned etc. It
can be fixed manually, though:
\!.fi
\!.sp \\n(PDu
\!.ps \\n(PSu
\!.vs \\n(VSu
\!.ll \\n(LLu
\!.ad b
\!The current page number is \\n(PN.
\!.nf
Using \!.PP directly kind of works, but leaves some small garbage above
the paragraph -- surely, something is going wrong. Maybe there's someone
here who knows what?