Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
2  
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
3  
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
1  
Then measuring the box Ag should usually be enough, perhaps with some safety margin. –  Philipp Dec 22 '10 at 14:03
1  
@xport if you use { like in maths you should look-up mathstrut. –  Yiannis Lazarides Dec 22 '10 at 16:37

3 Answers 3

up vote 4 down vote accepted

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}
share|improve this answer
    
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
1  
@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}}
share|improve this answer
    
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
3  
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

The Luatex manual, section 4.4.5.1.2, Glyph items, documents the glyph array that exists for each font, which provides information on the bounding element of each rendered character:

On boundingbox: The boundingbox information for TrueType fonts and TrueType-based otf fonts is read directly from the font file. PostScript-based fonts do not have this information, so the boundingbox of traditional PostScript fonts is generated by interpreting the actual bezier curves to find the exact boundingbox. This can be a slow process, so starting from LuaTEX 0.45, the boundingboxes of Post- Script-based otf fonts (and raw cff fonts) are calculated using an approximation of the glyph shape based on the actual glyph points only, instead of taking the whole curve into account. This means that glyphs that have missing points at extrema will have a too-tight boundingbox, but the processing is so much faster that in our opinion the tradeoff is worth it.

This sounds like it is as good an approximation to what you want as you will get. Iterating over the glyphs in a font and computing the maximum altitude and depth of each should be fairly easy if you know Lua.

share|improve this answer
    
I think one of the OpenType headers already contains the correct values for the maximum ascent and descent. –  Philipp Dec 22 '10 at 13:32
    
@Philipp: I think that's what the first sentence I quoted means, but it won't help with other kinds of font. –  Charles Stewart Dec 22 '10 at 15:45
    
I'm not sure, but I interpreted the sentence as referring to the bounding boxes of inidividual characters, not to the global maximum values. –  Philipp Dec 22 '10 at 17:10
    
@Philipp: Yes, that is right, I misunderstood the point you were making. Where that exists, it probably is better than the result from computing the value by iteration. –  Charles Stewart Dec 22 '10 at 19:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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