2

For definiteness, let's suppose we use pdfLaTeX to compile this:

\documentclass[10pt]{article}
\usepackage{lmodern}
\begin{document}
\thispagestyle{empty}
\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.0001pt}
\fbox{a}
\end{document}

The output is

enter image description here

I do understand that there are good reasons why the displayed box is not the true bounding box (in particular, the top and bottom of the glyph stick out, while there are gaps between the glyph and the left and right sides of the box).

On the other hand, this is a glyph from lmr10.pfb (I know this because pdffonts tells me the font is LMRoman10-Regular, while lm.map contains the line

cs-lmr10 LMRoman10-Regular "enclmcs ReEncodeFont" <lm-cs.enc <lmr10.pfb

When I inspect lmr10.afm, I see the line

C 97 ; WX 500 ; N a ; B 32 -11 483 448 ;

and when I inspect cs-lmr10.vpl (generated from cs-lmr10.tfm by tftopl), there is this:

(CHARACTER C a
   (CHARWD R 0.5)
   (CHARHT R 0.445274)
   (CHARIC R 0.010777)

Finally, I can inspect lmr10.pfb in FontForge, and it turns out that the values listed in lmr10.afm are the dimensions of the true bounding box of the glyph 'a': in FontForge, the leftmost point of the glyph has the x-coordinate 32, the lowest point has the y-coordinate -11, the rightmost point has the x-coordinate 483, and the highest point has the y-coordinate 448.

As best as I can tell, the values listed in cs-lmr10.vpl give the width of the box produced by \fbox{a}, but not the height. This can be inspected visually; but also, using \heightof from calc package, we get that the height is 4.3056 pt.

Just in case there is some question whether all of this is some artifact of \fbox, we can also perform these measurements: \heightof{\mbox{a}}, \heightof{\hbox{a}}, \heightof{a}, and \widthof{\mbox{a}}, \widthof{\hbox{a}}, \widthof{a}. All the heights come out as 4.3055 pt, and all the widths as 5.0 pt.

My questions:

  1. How does LaTeX determine the geometry of the box produced by \fbox? For example, where does this 4.3056 pt for the height come from? If—as it appears to be the case—it does not come from either the .afm file or the .tfm file, then where does it come from?

  2. Is it possible, in LaTeX, to put 'a' in a box (not necessarily a framed one) that coincides with the true bounding box of the glyph? Can we use it to do the following: when we use the \put(10,10) command to place that box (which contains the visible glyph 'a') on a page, what ends up at the coordinate (10,10) is the lower-left corner of the true bounding box of the glyph? Another thing that should happen is that when we apply \heghtof and \widthof to that box, we get the height and width of the true bounding box of the glyph.

(Of course, what I mean is, can we do the above using only the internal resources of LaTeX, no matter what font we are using? We shouldn't have to figure out, every time and for every glyph that interests us, which font it came from and then go look at the appropriate .afm file ourselves and set the coordinates in the LaTeX document by hand.)

1 Answer 1

2

You want to look at rm-lmr10 not cs-lmr10,

A modified version of your test file

\documentclass[10pt]{article}
\usepackage{lmodern}
\begin{document}
\thispagestyle{empty}
\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.0001pt}
\fbox{a}

\sbox0{a}
\typeout{box:
\the\ht0,
\the\dp0,
\the\wd0}
\typeout{tfm:
\the\fontcharht\font`a,
\the\fontchardp\font`a,
\the\fontcharwd\font`a}
\typeout{font:\the\font}
\typeout{meaning:\expandafter\meaning\the\font}

Produces terminal output of

box: 4.3055pt, 0.0pt, 5.0pt
tfm: 4.3055pt, 0.0pt, 5.0pt
font:\OT1/lmr/m/n/10 
meaning:select font rm-lmr10

note the final rm-lmr10.

Then tfopl rm-lmr10.tfm produces

(CHARACTER C a
   (CHARWD R 0.5)
   (CHARHT R 0.43055)
   (CHARIC R 0.010777)

with the width and height exactly matching the dimensions that you see from TeX.

4
  • Thank you! (I should have deduced this also from the log file, which mentions lm-rm.enc; then grep lmr10.pfb $(kpsewhich pdftex.map) | grep lm-rm.enc gives a line that begins with rm-lmr10.) Feb 19, 2022 at 14:32
  • As far as the second question I posed: am I to understand that there seems to be no practical, automatic way, within pdfLaTeX (or even LuaLaTeX), to get access to the true visual bounding box of a character, such as that given in the file lmr10.afm? Feb 19, 2022 at 14:32
  • 2
    @linguisticturn certainly tex has no access to the visual character, a could be a solid black rectangle as far as it can tell, what I can't exactly see is where the tfm metrics came from compared to afm, but they may have been adjusted by hand in comparison to the cmr10 tfm metrics, anyway they are by now what they are. Feb 19, 2022 at 14:53
  • BTW, I just looked at what happens if we use LuaLaTeX and \usepackage{fontspec} with \setmainfont{Latin Modern Roman}. In this case, \ht and \dp of a box containing a single glyph do correspond to the numbers given in the afm file. But \wd still gives the distance between the left and the right side-bearing boundaries of the glyph, same as in pdfLaTeX. Feb 19, 2022 at 16:56

You must log in to answer this question.

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