gbranden pushed a commit to branch master
in repository groff.

commit 4d8f38aec0a9f5545320c7bd8f61dacc42020aba
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Sep 4 04:06:34 2024 -0500

    [troff]: Fix Savannah #66150 (`p` and `s` units).
    
    * src/roff/troff/number.cpp (is_valid_term): Accept `p` and `s` scaling
      units in expressions where `z` is accepted.  Also fix code style nit:
      parenthesize complex expressions.
    
    * doc/groff.texi.in (Using Fractional Type Sizes):
    * man/groff_diff.7.man (Fractional type sizes and new scaling units):
    * NEWS: Document this.
    
    * doc/groff.texi.in (Using Fractional Type Sizes): Add example.
    
    Fixes <https://savannah.gnu.org/bugs/?66150>.
---
 ChangeLog                 | 15 +++++++++++++++
 NEWS                      |  4 ++++
 doc/groff.texi.in         | 33 ++++++++++++++++++++++++++-------
 man/groff_diff.7.man      | 15 +++++++++------
 src/roff/troff/number.cpp |  9 +++++----
 5 files changed, 59 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 263bef4db..4a6329af6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2024-09-04  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/number.cpp (is_valid_term): Accept `p` and `s`
+       scaling units in expressions where `z` is accepted.  Also fix
+       code style nit: parenthesize complex expressions.
+
+       * doc/groff.texi.in (Using Fractional Type Sizes):
+       * man/groff_diff.7.man (Fractional type sizes and new scaling
+       units):
+       * NEWS: Document this.
+
+       * doc/groff.texi.in (Using Fractional Type Sizes): Add example.
+
+       Fixes <https://savannah.gnu.org/bugs/?66150>.
+
 2024-09-04  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/env.cpp (point_size, override_sizes): Ignore
diff --git a/NEWS b/NEWS
index 9e5d4171d..68c873f56 100644
--- a/NEWS
+++ b/NEWS
@@ -130,6 +130,10 @@ o The read-only registers `.m` and `.M` now interpolate 
"default" when
   the default color is selected as the stroke or fill color,
   respectively, rather than interpolating nothing.
 
+o Numerical expression contexts that accept the `z` and `u` scaling
+  units, such as the `ps` request and `\s` escape sequence, now also
+  accept `p` and `s`.
+
 eqn
 ---
 
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index c92888efc..b2377151e 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -12287,17 +12287,36 @@ This read-only register interpolates the type size in 
scaled points; it
 is associated with the environment (@pxref{Environments}).
 @endDefreg
 
-It makes no sense to use the @samp{z} scaling unit in a numeric
-expression whose default scaling unit is neither @samp{u} nor @samp{z},
-so GNU @code{troff} disallows this.  Similarly, it is nonsensical to use
-a scaling unit other than @samp{z} or @samp{u} in a numeric expression
-whose default scaling unit is @samp{z}, and so GNU @code{troff}
-disallows this as well.
-
 Another GNU @code{troff} scaling unit, @samp{s}, multiplies by the
 number of basic units in a scaled point.  Thus, @samp{\n[.ps]s} is equal
 to @samp{1m} by definition.  Do not confuse the @samp{s} and @samp{z}
 scaling units.
+
+@Example
+.tm device=\*[.T]
+.tm A: .s=\n[.s]z, .ps=\n[.ps]s
+.ps 10.5
+.tm B: .s=\n[.s]z, .ps=\n[.ps]s
+.ps 12.3p
+.tm C: .s=\n[.s]z, .ps=\n[.ps]s
+.ps 8.1z
+.tm D: .s=\n[.s]z, .ps=\n[.ps]s
+.ps 10500s
+.tm E: .s=\n[.s]z, .ps=\n[.ps]s
+    @result{} device=ps
+    @result{} A: .s=10z, .ps=10000s
+    @result{} B: .s=10.5z, .ps=10500s
+    @result{} C: .s=12.3z, .ps=12300s
+    @result{} D: .s=8.1z, .ps=8100s
+    @result{} E: .s=10.5z, .ps=10500s
+@endExample
+
+It makes no sense to use the @samp{z} scaling unit in a numeric
+expression whose default scaling unit is neither @samp{u} nor @samp{z},
+so GNU @code{troff} disallows this.  Similarly, it is nonsensical to use
+scaling units other than @samp{p}, @samp{s}, @samp{z}, or @samp{u} in a
+numeric expression whose default scaling unit is@tie{}@samp{z}, and so
+GNU @code{troff} disallows those as well.
 @c END Keep (roughly) parallel with subsection "Fractional type sizes
 @c and new scaling units" of groff_diff(7).
 
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index 3d7becd37..0a5254d5f 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -430,14 +430,17 @@ so GNU
 disallows this.
 .
 Similarly,
-it is nonsensical to use a scaling unit other
-.RB than\~\[lq] z \[rq]
-.RB or\~\[lq] u \[rq]
+it is nonsensical to use scaling units other than
+.RB \[lq] p \[rq],
+.RB \[lq] s \[rq],
+.RB \[lq] z \[rq],
+or
+.RB \[lq] u \[rq],
 in a numeric expression whose default scaling unit
 .RB is\~\[lq] z \[rq],
-so GNU
-.I troff
-disallows this as well.
+and so GNU
+.I troff \" GNU
+disallows those as well.
 .
 .
 .br
diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp
index ac33c3f5d..d3b4fcadd 100644
--- a/src/roff/troff/number.cpp
+++ b/src/roff/troff/number.cpp
@@ -534,15 +534,16 @@ static bool is_valid_term(units *u, int scaling_unit,
   }
   int si = scaling_unit;
   bool do_next = false;
-  if ((c = tok.ch()) != 0 && strchr(SCALING_UNITS, c) != 0) {
+  if (((c = tok.ch()) != 0)
+      && (strchr(SCALING_UNITS, c) != 0 /* nullptr */)) {
     switch (scaling_unit) {
     case 0:
       warning(WARN_SCALE, "scaling unit invalid in context");
       break;
     case 'z':
-      if (c != 'u' && c != 'z') {
+      if (c != 'u' && c != 'z' && c != 'p' && c != 's') {
        warning(WARN_SCALE, "'%1' scaling unit invalid in context;"
-               " convert to 'z' or 'u'", c);
+               " use 'z', 'p', 's', or 'u'", c);
        break;
       }
       si = c;
@@ -559,7 +560,7 @@ static bool is_valid_term(units *u, int scaling_unit,
       break;
     }
     // Don't do tok.next() here because the next token might be \s,
-    // which would affect the interpretation of m.
+    // which would affect the interpretation of 'm'.
     do_next = true;
   }
   switch (si) {

_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to