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.

Case 1: \fbox cannot enclose characters tightly

Why don't \fbox and PSTricks \psframebox enclose its contents accurately? In my opinion, every edge should exactly touch the outer part of its contents. Does changing font solve this issue?

\documentclass{article}
\usepackage[english]{babel}
\usepackage{pstricks}

\fboxsep=0pt
\fboxrule=0.001pt

\begin{document}
\color{red}\fbox{\color{black}3}
\end{document}

enter image description here

This funny feature might be the source of problem where pdfcrop accidently trims grid labels.

Case 2: \fbox cannot enclose PSTricks grid labels

It is another example where \fbox and \psframebox cannot accurately enclose their contents.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{pstricks}

\fboxsep=0pt
\fboxrule=0.001pt

\begin{document}

\color{red}
\fbox{\color{black}%
\pspicture[showgrid](3,3)
\endpspicture
}

\vspace{1cm}

\psframebox[framesep=0pt,linewidth=0.001pt,linecolor=red]{%
\pspicture[showgrid](3,3)
\endpspicture
}
\end{document}

Should the frames enclose the grid labels? In my mental model, they should.

enter image description here

Questions

In my mental model, \fbox should enclose its contents tightly when \fboxsep=0pt without allowing any part of its contents to reside outside its frame. If \fbox allows any part of its contents to live outside its frame, what is \fbox actually for?

Why wasn't \fbox defined to enclose its contents based on the most left, right, bottom, top parts? I think it is more useful, right?

share|improve this question
    
In computer modern, all lining figures are exactly half an em wide. I'm not sure why the height and depth are off (and I think the depth should be zero). –  TH. Jun 13 '11 at 19:11
    
And by off I meant different from the actual characters' heights and depths, not incorrect. Herbert gives a good example. –  TH. Jun 13 '11 at 19:24
1  
\fbox is a frame around boxes, not a frame around characters –  Herbert Jun 13 '11 at 20:28
    
@Herbert: Why wasn't \fbox defined to enclose its contents based on the most left, right, bottom, top parts? –  xport Jun 13 '11 at 21:39
    
I think \fbox is considered to be more of a decorative box than you hope. After all, it has the tuning parameter \fboxsep indicating how far from the "real" box the frame should be drawn, and by default, it is not zero. –  Ryan Reich Jun 13 '11 at 21:56
show 3 more comments

2 Answers

up vote 10 down vote accepted

the bounding box of the character has nothing to do with its contents:

\documentclass{article}
\usepackage[T1]{fontenc} 
\usepackage{mathpazo}
\begin{document}
\fontsize{3cm}{3.1cm}\selectfont\frame{\itshape ff}
\end{document}

enter image description here

share|improve this answer
1  
@Herbert: If \fbox cannot enclose its contents accurately, what is \fbox actually for? –  xport Jun 13 '11 at 19:31
    
@xport I have used fbox (and the "boxit" macro from the TeXbook) many times to see how much space a box really occupies. I use a similar (LuaTeX node based) approach daily now. But I do agree that a \contentsbox macro could be helpful, too. –  topskip Jun 13 '11 at 19:56
    
@Patrick: Where is \contentsbox defined? –  xport Jun 13 '11 at 20:05
1  
@xport: Remember that TeX works with boxes and not with characters. For TeX it is aboslutely unimportant what's inside the box, the reason why you can write english and arabic in the same file. The characters are inserted by the driver, not by TeX. For a good typographical reason, the characters e, o, 3, 6, and so on are at the bottom a little bit outside the box. –  Herbert Jun 13 '11 at 20:24
    
@xport, @Herbert: I think it is more instructive to note that TeX typesets words by putting the character boxes together so that they just touch. The character boxes are defined so that the resulting words look “right”. (Exception: Sometimes, this algorithm does not produce acceptable interletter spacing. The font will have kerning tables to deal with those special cases.) –  Harald Hanche-Olsen Jun 13 '11 at 21:27
show 2 more comments

TeX has no notion of how the ink will be used to draw a character. All it knows are the bounding boxes of characters, but typically a glyph is not entirely contained in the bounding box reserved for it. Letters with rounded shape at the top or at the bottom (the digit 3 is a prominent example) usually are drawn slighly over or under the bounding box, to align optically with one another. Often the "f", especially the italic shape, protrudes from its bounding box. It's impossible for TeX to know whether this happens or not.

However it's possible to access at the "real" bounding box of a character with XeTeX, as shown in XeTeX-reference, page 8. With TeX Live one can access to the document by texdoc xetex.

share|improve this answer
add comment

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.