# How to detect the length of the tallest letter and that of the deepest letter of the current font size?

My idea is to redefine the \strut to be as short as possible.

It means the length of strut is the sum of the tallest letter length and the deepest letter length.

-
Hm. Do you mean "the tallest letter in the font file", "the tallest letter of an encoding (e.g. T1)" or "the tallest letter used in your document"? This sets can differ quite a lot - even more if you include luatex/xetex in your question which can use large fonts with thousands of characters. –  Ulrike Fischer Dec 22 '10 at 9:57
@Ulrike, the tallest letter for fonts used in my document only. –  xport Dec 22 '10 at 10:00
All fonts? Include the "large symbol math font"? At what about the unused letters in the fonts? Should a chinese letter be measured too? –  Ulrike Fischer Dec 22 '10 at 10:15
Then measuring the box Ag should usually be enough, perhaps with some safety margin. –  Philipp Dec 22 '10 at 14:03
@xport if you use { like in maths you should look-up mathstrut. –  Yiannis Lazarides Dec 22 '10 at 16:37

One problem is that the font metrics do not include appropriate dimensions for this. The code below provides a short macro for displaying the font dimensions.

\documentclass[10pt]{article}

\usepackage{graphicx, booktabs, tabularx, scalefnt, xcolor}

\begin{document}
\def\displayfontmetrics#1{\medskip
\noindent
\begin{table}[htbp]
\begin{tabular}{lcl}
\toprule
Parameter  & Description & Value\\
\midrule
fontdimen1 & slant &  \the\fontdimen1\font\\
fontdimen2 &interword space  &  \the\fontdimen2\font\\
fontdimen3 &interword stretch &  \the\fontdimen3\font\\
fontdimen4 & interword shrink &  \the\fontdimen4\font\\
fontdimen5 & x-height &  \the\fontdimen5\font\\
fontdimen6 & quad width &  \the\fontdimen6\font\\
fontdimen7 & extra space &  \the\fontdimen7\font\\
\bottomrule
\end{tabular}
\caption{Font metrics for font #1}
\end{table}
\medskip}

\scalebox{2}{ H\'AMB\"URG\'E\c F\'ON\c ST\'IV}

\scalebox{2}{ \lowercase{H\'AMB\"URG\'E\'ty\c F\'ON\c ST\'IV}}

\end{document}


One solution is to use a vphantom which you can use as a strut.

\def\Z{\vphantom{y\vphantom{\'l}}}

\colorbox{yellow}{\Z abcdy}

-
thanks for introducing vphantom that I haven't known before. It will be sophisticated if on the fly we can make a query against the letters to find the heighest letter and the deepest letter. And finally construct a strut using \vphantom and the 2 letters obtained by the query. –  xport Dec 22 '10 at 6:33
why did you use nested \vphantom when defining \Z ? does it make a difference if I just use one? –  xport Dec 22 '10 at 7:29
@xport It makes little difference. I used two to show that you get a different height based on y rather than l. –  Yiannis Lazarides Dec 22 '10 at 10:49

the strutbox is defined to exactly the height of \baselineskip which is the smallest value including the interlinespace of a row. However, you have to redefine every time the strutbux when changing the fontsize. This is the reason why it makes no sense to have an own strut value. Use instead the \vphantom macro:

\def\mystrut{\vphantom{Äg}}

-
first of all, thank for answering. The combination Äg produces the longest length? Or are there other combinations that produce the longest one? –  xport Dec 22 '10 at 6:36
There is no longest length in general. It depends to the used language. For example, when writing vietnamese you have double accents (accent over another one). The conbination of Äg is the longest one for german, no more no less. –  Herbert Dec 22 '10 at 6:57
OK. Thank you very much. –  xport Dec 22 '10 at 7:02
Rather than making a new macro, why not change \strutbox appropriately? It should be an \hbox containing a \vrule with the appropriate height and depth and zero width. –  TH. Dec 22 '10 at 19:39