Hi Walter,
On Sat Jan 18, 2025 at 12:40 PM CET, Walter Alejandro Iglesias wrote:
> I have a question. Surely it's something silly that I'm missing. I
> don't understand the logic in how centering (with .ad c or .ce) affects
> horizontal movements (\h). Let's take this example:
>
> .ad c
> v
> .br
> \Z'\h'1i'v'
> .br
> \Z'\h'1i'Hello, World!'
> .br
> \h'1i'v
> .br
> \h'1i'Hello, World!
> [...]
Let's go through this one point at a time. Let me provide an example
which shows the behavior of horizontal motions when centering:
$ groff -Tutf8 << EOF | sed -E "s/ /'/g"
.pl 1
.ll 20
.nf
.ce
One\h'4n'Two
EOF
'''''One''''Two
What this shows is that:
1) the size of the horizontal motion isn't affected by centering
2) the horizontal motion is considered a part of the line and affects
its width
You can see proof of #2 in that One + 4 blanks + Two is 10 characters
wide, and groff set the text 5 blanks from the left margin with a line
length of 20. (1n is 1 character wide on the terminal device.)
Note that the sum of left indentation and the horizontal motion is
9 characters; it will become important shortly.
Now, let's turn to your usage of \h and modify the above one a bit:
$ groff -Tutf8 << EOF | sed -E "s/ /'/g"
.pl 1
.ll 20
.nf
.ce
\h'4n'OneTwo
EOF
'''''''''OneTwo
When you count the spaces before OneTwo, you will notice there is
still 9 of them. In other words, the horizontal motion became a part
of the line, which was then centered in the usual manner.
Now, let's modify this to include \Z:
$ groff -Tutf8 << EOF | sed -E "s/ /'/g"
.pl 1
.ll 20
.nf
.ce
\Z"\h'4n'OneTwo"
EOF
''''''''''''''OneTwo
What the heck? Let's try something else:
$ groff -Tutf8 << EOF | sed -E "s/ /'/g"
.ll 20
.pl 1
.nf
.ce
1\Z"\h'4n'OneTwo"2
EOF
'''''''''12'''OneTwo
Hm... it looks like the text isn't actually being centered, eh?
$ groff -Tutf8 << EOF | sed -E "s/ /'/g"
.ll 20
.pl 1
.nf
.rj
\h'4n'OneTwo
EOF
''''''''''''''OneTwo
Right, it's being right-justified, presumably as a side effect of the
way groff handles centering.
TL;DR: When centering, horizontal motions become part of the line and
centered with it. When using \Z in centered lines, the text
actually becomes right justified.
> [...]
> Also, given what the documentation explains about \Z, I don't understand
> the effect it has in this example either. (If any part of the manual can
> help me understand this behavior, there's no need to waste your time
> explaining it, just point it out to me.)
I doubt the behavior of \Z shown above is intended.
~ onf