[Tex/LaTex] Where do the values of 1em and 1ex come from

fontsunit-of-measure

In my answer to “Which measurement units should one use in LaTeX?” I explore the values of 1em and 1ex for different fonts using both TFM fonts and the font mechanisms of XeLaTeX that uses non-TFM fonts.

My, highly empirical, conclusions in that post are:

  • For TFM fonts:
    • The value of 1em is not equal to the ‘selected size’ of the font,
      nor is it the width of an actual “M”.
    • The value of 1ex is not tied to the size of an actual “x”.
      However, for all the ‘Computer Modern’ text fonts and most styles of the ‘Latin Modern’ text fonts, 1ex = \ht of \hbox{x}
  • For non-TFM fonts (in XeLaTeX):
    • The value of 1em is exactly the ‘selected font size’.
    • The value of 1ex is exactly the height of an “x”. (\ht of \hbox{x})

Now to my question. Am I correct to assume that:

  • For TFM fonts:
    • The values of 1em and 1ex are separate, “independent”, values in the font definition file, and those are read into LaTeX when the font is loaded.
  • For non-TFM fonts (in XeLaTeX):
    • The value of 1em is always set to the ‘selected font size’, and the value of 1ex is always set to the height of an “x”. (\ht of \hbox{x})
    • or; is it possible to have 1em ≠ ‘selected font size’ and/or 1ex\ht of \hbox{x}?

Edit to better specify what answer I am looking for:

The answer provided by tohecz deals with the design reasons for having 1em and 1ex not exactly tied to the extents of letters “M“ and “x”. What I am looking for is an answer more on the lines of where TeX loads these values from.

The answer provided by David Carlisle corroborates my first assertion (that for TFM fonts values are loaded from the font definition file, and are independent on the extents of the letters “M” and “x”).

What’s left is whether, for Xe(La)TeX, fonts loaded from non-TFM files, the values are always taken from the selected size and extents of letter “x”.

I find this interesting since the values of 1em and 1ex differ between whether you load Latin Modern fonts from TFM files (via e.g. \usepackage{lmodern}) or via new font methods (via e.g. \fontspec{LMSans10})

[I realize that \usepackage{lmodern} is probably most consistent, but still…]

Best Answer

As listed in

What do different \fontdimen<num> mean

the ex and em lengths are specified separately in the tfm format as parameters 5 and 6 respectively. the font designer can set these to anything, although usually ex is as you say the height of an x (em is a bit more variable but is usually close to the nominal design size). Also you can set them to anything in TeX just after loading the font, before any text is typeset with it.

Not sure about xetex, but I suspect it takes the default values that you suggest.

Related Question