# Why wasn't \fbox defined to enclose its contents based on the most left, right, bottom, top parts of its contents?

## 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}

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.

## 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?

-
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
\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

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}

-
@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
@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