# How can the dimensions of a box be retrieved with LaTeX

One can specify a box in LaTeX, using various methods for example:

 \newsavebox{\Abox}
\savebox{\Abox}{\parbox{4cm}{\lorem}}
\usebox{\Abox}


How can I retrieve the width, height and depth of the box. TeX has the primitives \wd, \ht and \dp. However in order for these to be used it is necessary to know the number of the box for example box13.

-

You really shouldn't be referring to boxes by number even with the plain format. For example,

\newbox\mybox
\setbox\mybox=\hbox{Hello}
\showthe\wd\mybox
\bye


will work fine. Both \newbox and \newsavebox do a \chardef to assign the name you give as a number. So in LaTeX you can happily do

\newsavebox{\mybox}
\savebox{\mybox}{\parbox{4cm}{\lorem}}
\showthe\wd\mybox


and all will be fine.

-
Thanks Joseph. Out of curiosity, I see if I type \showthe\Abox I get the number 101, does LaTeX allocated from box100 onwards? Thanks for the tip though, I will not be using numbers even with the plain format :) – Yiannis Lazarides Sep 16 '10 at 20:28
No, it's just that the kernel itself allocates a lot of things, both as boxes and as inserts (which need a box leaving free). – Joseph Wright Sep 16 '10 at 20:51

I believe the canonical LaTeX way is this:

\newlength{\myhh}
\newlength{\mydd}
\newlength{\myww}
\settoheight{\myhh}{\usebox{\Abox}}
\settodepth{\mydd}{\usebox{\Abox}}
\settowidth{\myww}{\usebox{\Abox}}

-
Brent thanks. The question though asked how can the dimensions be retrieved i.e one or more of them might not be known. Is there a canonical way for this? – Yiannis Lazarides Sep 16 '10 at 21:12
Yiannis, I don't fully understand the comment. If you have a TeX "thinh", the three lengths are always (I think) known. The lengths \myhh etc can be used as standard TeX lengths, I believe. What more do you want to do with them? – Brent.Longborough Sep 18 '10 at 14:14