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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 14 down vote accepted

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

share|improve this answer
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 Apr 22 '12 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 Apr 22 '12 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}.
share|improve this answer

Your Answer


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.