Every time you use the \w
escape sequence, several registers are populated with information about the argument you gave to it.
Here is what the groff Texinfo manual from its Git repository says, lightly adapted.
-- Escape sequence: \w'anything'
-- Register: \n[st]
-- Register: \n[sb]
-- Register: \n[rst]
-- Register: \n[rsb]
-- Register: \n[ct]
-- Register: \n[ssc]
-- Register: \n[skw]
Interpolate the width of ANYTHING in basic units. This escape
sequence allows several properties of formatted output to be
measured without writing it out.
The length of the string 'abc' is \w'abc'u.
=> The length of the string 'abc' is 72u.
ANYTHING is processed in a dummy environment: this means that font
and type size changes, for example, may occur within it without
affecting subsequent output.
After each use, '\w' sets several registers.
'st'
'sb'
The maximum vertical displacements of the text baseline above
and below, respectively. The sign convention is opposite that
of relative vertical motions; that is, depth below the
(original) baseline is negative. These registers are
incorrectly documented in the AT&T 'troff' manual as "the
highest and lowest extent of [the argument to '\w'] relative
to the baseline".
'rst'
'rsb'
Like 'st' and 'sb', but taking account of the heights and
depths of glyphs. In other words, these registers store the
highest and lowest vertical positions attained by ANYTHING,
doing what AT&T 'troff' documented 'st' and 'sb' as doing.
'ct'
Characterizes the geometry of glyphs occurring in ANYTHING.
0 only short glyphs, no descenders or tall glyphs
1 at least one descender
2 at least one tall glyph
3 at least one each of a descender and a tall glyph
'ssc'
The amount of horizontal space (possibly negative) that should
be added to the last glyph before a subscript.
'skw'
How far to right of the center of the last glyph in the '\w'
argument, the center of an accent from a roman font should be
placed over that glyph.
I would add that on terminal devices, a.k.a. in "nroff mode", the register ct
's value is typically zero no matter what the input was. I think this is because nroff devices are not capable of fine vertical motions anyway. Historically, they could move by half-line motions at best, and video terminals and their emulators can't even do that.
man groff_font
, but I don't know of any built-in commands to find them within a troff document. You can generate text into a diversion and then get the width and height of the diversion in number registers dl, dn, but I don't know whether this will take into account a character's visible height, or just the font height and line spacing.