[Tex/LaTex] How to the dimensions of a box be retrieved with LaTeX

boxeslengthstex-core

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.

Best Answer

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.

Related Question