I'm not very familiar with the world of TeX and its flavors, and I'm having trouble evaluating whether it fits my needs before I dive into it. TeX and its ilk can draw horizontal line strokes, but can any of them align the lines at the various typographic baselines of running text (hanging, alphabetic, ideographic)—producing something like the image below from the WHATWG HTML5 canvas baseline spec?

A bunch of glyphs with lines drawn under them indicating various typographic baselines

  • 1
    I would expect this to be difficult as TeX internally does not know much about each character -- it just sees a bounding box. However, each font contains meta information but I don't know how accessible it is. LuaTeX is probably the best bet here. – Christian Lindig Oct 23 '15 at 16:52
  • 2
  • 6
    Bounding box, em square, middle and alphabetic baseline are known to all tex flavours. Values for ideographic and hanging baseline exist only in open type fonts and you would need xetex or luatex. The last is imho certainly able to extract the values and to use them, but I don't know if someone has already implemented code for it. I also don't know if xetex can use the values. – Ulrike Fischer Oct 23 '15 at 17:20
  • 1
    Actually, every character (box) has a height (distance from top to basline) and depth (distance from bottom to baseline). In particular, the height and depth of \strut mark the top and bottom for all characters. One can also express them as fractions of \baselineskip. – John Kormylo Oct 23 '15 at 19:03

Some values are accessible in TeX, e.g.:


\subsection{Bounding box}
    \test{\`A} \test{\sffamily C} \test{\itshape f}
    \test{$\cdot$} \test{\_}%

    \rlap{\color{red}\vrule width\wd0 height.15pt depth.15pt}%

\subsection{Math axis}
    \textbullet & \verb|\sbox0{$\vcenter{}$}\the\ht0| & 6.22pt\\
    \textbullet & \verb|\the\fontdimen22\textfont2\relax| & 6.22pt\\
    % Math axis via an empty `\vcenter`, which vertically
    % centers around the math axis.
    \sbox0{\Huge$\vcenter{}$}% \vcenter centers around the math axis
      \vrule width\wd2 height\dimexpr\ht0+.15pt\relax

\subsection{Corpus size, x-height}
  Font dependent unit: \verb|1ex|
      \vrule width\wd0 height\dimexpr1ex+.15pt\relax

  Font dependent unit: \verb|1em|
    1\,em $\times$ 1\,em


Bounding box

TeX is not a rasterizer, thus it does not know the exact bounding box. Instead it relies on the glyph bounding box reported by the font:

  • Side bearings are included (left and right white margin).

  • Baseline is included (see underscore or middle dot in the example above).

  • There are cases, where the glyph bounding box from the font can be larger or smaller than the actual bounding box. Often this is part of the font design, sometimes font bugs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.