2

I'm working on a preprocessor to draw the square root for the equation (attempt to improve aesthetic of the EQN equation) which involves finding the size (width and height) of the string. I've found request/command and register that return the width of the string or character like \w'H', but I can't find the request/command to return the height. Is there some to way to find the height?

Thank you so much.

1
  • The groff font metrics per character are held in files as described in 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.
    – meuh
    Commented Jan 8, 2021 at 14:44

2 Answers 2

1

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.

0

The point-size of the font is the sum of:

  • The leading (the room required above the letter)
  • The ascent or capital height (the room between the baseline and the top of the largest letter)
  • The descent (the room between the baseline and the bottom of the lowest letter)

The ascent or capital height is the sum of the x-height (the height of the letter 'x' and the ascender.

These figures are font-dependent. You could print-out two lines of xhY and just measure them (print them large and keep the result as a % of the point-size)

See https://www.onlineprinters.co.uk/magazine/font-sizes/ and/or http://web.mit.edu/6.813/www/sp18/classes/16-typography/ or google these terms for a picture.

Unless you want to glue the square-root sign to the top of your letters, you should respect the leader. If you are sure, that there are never ever any ascenders, you may choose to disrespect the ascenders. The descenders are below the baseline, so you may choose to ignore them.

In groff, this is still the case, but the leading may be varied a lot with .vs (Register: \n[.v])

For times roman, you can use approximately:

  • descent=20%
  • x-height=42%
  • ascender=75%

but these are rough approximations.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .