bugGNU roff - Bugs: bug #59823, [ms] re-implement PN register

 
 

bug #59823: [ms] re-implement PN register

Submitter:  G. Branden Robinson <gbranden>
Submitted:  Tue 05 Jan 2021 02:37:00 AM UTC
   
 
Category:  Macro ms Severity:  4 - Important
Item Group:  Incorrect behaviour Status:  Fixed
Privacy:  Public Assigned to:  gbranden
Open/Closed:  Closed Planned Release:  1.23.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 02 May 2021 07:31:26 AM UTC, comment #2: 


commit 3d7a207e853468c78391ae66f9350a5328deac4b
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Sun May 2 06:12:42 2021 +1000

    [ms]: Restore support for AT&T ms PN register.

    * tmac/s.tmac (pg): Make register PN an alias of %.

    * doc/groff.texi (Differences from AT&T ms):
    * doc/ms.ms (Differences from AT&T ms):
    * tmac/groff_ms.7.man (Differences from troff ms): We don't need PN, and
      it was removed in commit 08291b40 (25 October 2020), but since it is
      documented in Lesk 1978 we're stuck with it.  Advise users to stick
      with %.  Also warn them of the hoop they must jump through if they
      redefine the page trap macro PT, which Lesk 1978 also encourages.

    Fixes <https://savannah.gnu.org/bugs/?59823>.

commit ca761ed69ad67190ae9dab499aca2bbdabd9c660
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Sun May 2 17:13:14 2021 +1000

    Add regression test for Savannah #59923.

    * tmac/tests/s_PN-works.sh: Do it.
    * tmac/tmac.am (tmac_TESTS): Run test.

    Test fails at this commit.


G. Branden Robinson <gbranden>
Group administrator
Tue 05 Jan 2021 03:16:07 AM UTC, comment #1: 

On further thought this might be really easy.  I may have already done the "hard" part in the quoted commit.  The only time the page number is parsed is in the PT macro, which is now defined as follows.


.de PT
.\" To compare the page number to 1, we need it in decimal.
.ds pg*saved-page-number-format \\g%\"
.af % 0
.nr pg*page-number-in-decimal \\n%
.af % \\*[pg*saved-page-number-format]
.ie \\n[pg*page-number-in-decimal]=1 .if \\n[pg*P1] .tl \\*[pg*OH]
.el \{\
.       ie o .tl \\*[pg*OH]
.       el .tl \\*[pg*EH]
.\}
..


Access to % is serialized because the formatter is single-threaded (in general, but more importantly with respect to input processing), so our meddling with its format is invisible to any other operation that might access %...including access through an alias.

So I am now thinking that this bug can indeed be resolved by throwing


.aln PN %


over the wall at an appropriate point in initialization and have done with it.  Even if the user assigns a format to % or PN, they will never be able to observe it while we have it temporarily set to decimal inside PT.

Lesk encourages the user to redefine PT if desired, so this point may be worth noting in the documentation update portion of this bug's resolution.

G. Branden Robinson <gbranden>
Group administrator
Tue 05 Jan 2021 02:37:00 AM UTC, original submission:  

In commit 08291b401786f57ffb8c8c3551455167bcfb4d31 last year, I eliminated the PN register.


commit 08291b401786f57ffb8c8c3551455167bcfb4d31
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Sun Oct 25 20:57:39 2020 +1100

    tmac/s.tmac: Fix page number in table of contents.

    Fix ms .TC macro by allowing it to actually use lowercase Roman numerals
    for the page(s) of the table of contents when a custom title (header or
    footer) is defined containing '%'.

    As a side effect, eliminate the PN register, which was apparently
    misused because it was undocumented and had a name just long enough to
    be both suggestive and ambiguous.  Another pin goes into my Ken Thompson
    voodoo doll.

    * tmac/s.tmac (IX): Write out page number of index term(s) in using the
      % register (instead of PN), obtaining whatever format is assigned to
      % the register at that time.
      (CH): Similarly, output %, not PN, in the center of the default
      heading.
      (PT): Save the format of %, set it to decimal, copy its value to a new
      register, pg*page-number-in-decimal, then restore %'s previous format.
      Compare the new register, not %, to 1 to determine whether special
      page one behavior should be used.
      (pg*end-page): Assign pg*next-format to %, not PN.
      (XA): Define toc*num with the interpolation of %, not PN.

    * tmac/tests/s-TC-works-with-percent-in-custom-titles.sh: Test.
    * tmac/tmac.an (tmac_TEST): Run test.

    Problem appears to be very old; as I read it, Larry Kollar was
    complaining of it in his ms.ms document over 20 years ago.

    Fixes <https://savannah.gnu.org/bugs/?59345>.


At the time I was not aware that PN was part of ms's documented interface, per Lesk's 1978-11-13 revision of the ms manual.  Lesk says only this.

"The page number on output is taken from register PN, to permit changing its output style."

What I think this means is that the assigned format of % cannot be changed to something other than a decimal format or it will break ms's internal logic in much the way we saw here in groff ms.  PN exists, apparently, so that people can .af on it and have their front matter use lowercase roman numerals, for example.

In groff, we have a register aliasing facility but unfortunately it works too well; the format as well as the value are aliased, so a clever trick of creating an alias and then changing the format of the alias does not leave the original register undisturbed.


.aln PN %
.af % i
.bp
.tm \n%
ii
.tm \n(PN
ii
.af PN 0
.tm \n(PN
2
.tm \n%
2


This leaves us with the yuckier problem of maintaining a PN register in s.tmac, updating it every time % changes.

Further, the existence and purpose of PN should actually be documented for a change, both in ms.ms and groff_ms(7).

I haven't marked this as a blocker since conceivably we could ship groff 1.23.0 without fixing it, and even without our dropping of it in NEWS--after all, PN wasn't working right in the first place, as bug #59345 revealed.  Few people besides Larry Kollar me seem to have publicly griped about it (and it took 20 years for me to provide a second instance), and it wasn't documented in the first place.

I seek opinions about how to proceed.

G. Branden Robinson <gbranden>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by gbranden (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-05-02 gbranden StatusIn Progress Fixed
        Open/ClosedOpen Closed
        Planned ReleaseNone 1.23.0
    2021-05-01 gbranden StatusNeed Info In Progress

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code