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.

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.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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{\Abox}{\parbox{4cm}{\lorem}}
\showthe\wd\mybox 

and all will be fine.

share|improve this answer
    
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
add comment

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}}
share|improve this answer
    
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
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.