On Sat, Jan 18, 2025 at 03:10:28PM +0100, onf wrote:
[...]
> TL;DR: When centering, horizontal motions become part of the line and
>        centered with it.

This is what I didn't understand.  Thank you for your detailed
explanation!  (Don't get me wrong, I cut off the rest of your
explanation so the post doesn't get too long, as I plan to add another
example below.)

> When using \Z in centered lines, the text
>        actually becomes right justified.
[...]
> 
> I doubt the behavior of \Z shown above is intended.

This is what I still don't understand, "right justified" against what?
Run the next adaptation of your example, please, first with ".ad c" and
then with ".ad n", and you'll see the last line is placed both times in
the right margin, what I understand as right justifing.

.pl 40
.ll 40
.ad c
v
.br
123\h'3n'789
.br
\h'3n'456789
.br
\Z'\h'3n'456789'
.br
\Z'123456789'
.rj
123456789 

For my part, I can only wait to come across a case where this behavior
of groff is desirable :-).  For now, at least in what led me to try to
understand this, it was very confusing.  Even though I may be going a
bit off topic, I'm going to explain it because it'll surely be useful to
someone who encounters the problem.  I was trying to center vertical
text on the spine of the cover of my novels.  First I tried the well
known pic hack to rotate text:

  https://troff.org/faq.html

But, depending on the font you use, it doesn't always center the text
perfectly.  Searching a bit more I found this hack from Tadziu Hoffmann:

  https://lists.gnu.org/archive/html/groff/2017-09/msg00051.html

More late, this useful explanaition from Werner Lemberg (thank you
both!)

  https://lists.nongnu.org/archive/html/bug-groff/2010-01/msg00004.html

So, adapting Werner Lemberg's reasoning to my case:

    +------+
    |      |
    |      | \n[rst]
    |      |
  --+------+--------- base line
    |      | \n[rsb]
    +------+

To center the glyph in the base line (before rotating it,) I had to move
it this amount (rsb is negative):

   rsb + (rst - rsb) / 2
   = rsb + rst / 2 + rsb / 2
   = rst / 2 + rsb / 2
   = (rst + rsb) / 2

Then I applied that reasoning to my adaptation of Tadziu's hack:

  .ds 90 \R'w \w'\\$*''\
  \v'\\nwu-\\n[.v]u'\
  \h'(\\n[rst]u+\\n[rsb]u)/2u'\
  \X'ps: exec gsave currentpoint 2 copy translate \
  -90 rotate neg exch neg exch translate'\
  \Z'\\$*'\
  \X'ps: exec grestore'

But that works as expected only if you use \Z:

  \Z'\*[90 "Your text here"]'

Or, if instead of using '.ad c' or '.ce' you center your text manually
in the page:

  \h'\n[.ll]u/2u'\*[90"Your text here"]

You can also center perfectly your text with .ce and without \Z by
removing the division by two from the \h move (third line).

  [...]
  \h'\\n[rst]u+\\n[rsb]u'\
  [...]

All that solutions work but I'm still not able to decide which is the
consistent one. :-)

> 
> ~ onf
> 

Thank you again onf!

-- 
Walter

Reply via email to