The \settowidth command, which sets a width equal to the width of some text, is described at Get width of a given text as length and How to set the width of the label of a description to the width of a string of text in ConTeXt?. What is the plain TeX equivalent of this command?

2 Answers 2


There is none other than doing the same thing by copying the LaTeX definition:

\def\settodepth {\@settodim\dp}
\def\settowidth {\@settodim\wd}

Now \settowidth\mylen{xyz} would become


so transformed into


and the trick is done, assuming you already allocated

  • 1
    In the middle line of the three-line code snippet, should that be \wd rather than \ht? By the way, is \@tempboxa defined in Plain-TeX? (If not, one can just create a new "scratch" box with that name, right?) Separately, it may be useful to remind readers that they'll need to "wrap" these instructions in the usual \catcode`@=11 ... \catcode`@=12 pair.
    – Mico
    Commented Apr 22, 2012 at 11:30
  • You're right about \ht that should be \wd; the second part is just to show the working of the macros, not actual input.
    – egreg
    Commented Apr 22, 2012 at 12:19

You can set your wanted content into a box with \setbox

\setbox0\hbox{some horizontal material}

where 0 is a “scratch” box register, or you can assign a new box register number with \newbox


after which you can use that, as in

\setbox\mybox\vbox{some vertical material}

Now you can ask for its dimensions with

\the\ht\mybox for its height,
\the\wd\mybox for its width, and
\the\dp\mybox for its depth

(where the prefix \the typesets the quantity)

So to answer the question,

  \global\mydim=\wd\mybox% global so the dim can be used outside
  \leavevmode% in case it's the first thing in a paragraph
  \box\mybox% typeset the contents of the box

Some text \setMyDimToMyBoxWidth{some horizontal material} more text
now, the width is \hbox to\mydim{\hfil\the\mydim}.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .