It doesn't work because \wd
is basically an operator; you give it the box you want the width of. Also keep in mind that \multiply
doesn't work with floating-point numbers, only integers; so if you want to multiply by something like 0.7, you'll have to multiply by 7 and then divide by 10.
Assuming that the full length is \hsize
, and you want a box 0.7 times \hsize
:
\hbox to\hsize{This box will be the full width}
\newbox\mybox
\setbox\mybox\hbox to\hsize{\hfil}
\newdimen\mywidth\mywidth=\wd\mybox
\multiply\mywidth by7
\divide\mywidth by10
\hbox to\mywidth{This box will be the right width}
\bye
The first line is purely for demonstrative purposes, to show the full length of the line. Then we declare a new box, \mybox
, and make sure that its width is also equal to \hsize
by assigning to it an empty \hbox
of that width. Then we declare a new dimen
, \mywidth
, and set it equal to the width of \mybox
. Then we multiply \mywidth
by 7 and divide it by 10, which is the equivalent of multiplying by 0.7. Finally, we put some text in a box of \mywidth
, which, as you can see, if 70% the width of the original box.
You can, of course, wrap this in a macro:
\hbox to\hsize{This box will be the full width}
\newbox\mybox
\newdimen\mywidth
\def\width#1#2#3#4{%
\setbox\mybox\hbox to#1{\hfil}
\mywidth=\wd\mybox
\multiply\mywidth by#2
\divide\mywidth by#3
\hbox to\mywidth{#4}
}%
\width{\hsize}{7}{10}{This box will be the short width}
\width{\hsize}{8}{10}{This box will be the short width}
\width{\hsize}{4}{10}{This box will be the short width}
\bye
That will produce the following:

If you need the text to wrap, wrap the #4
in a \hbox
and \vbox
and change the \hsize
inside it:
\newbox\mybox
\newdimen\mywidth
\def\width#1#2#3#4{%
\setbox\mybox\hbox to#1{\hfil}
\mywidth=\wd\mybox
\multiply\mywidth by#2
\divide\mywidth by#3
\hbox to\mywidth{%
\hfil%
\vbox{%
\hsize=\mywidth
#4
}%
\hfil%
}
}%
Hope that answers your need.
\wd0=0.7\wd0
instead. However this will only change the width of the box, but the characters therein will not change, so some will protrude outside the box. You need driver-specific code to do that. You can loadgraphicx
in Plain with\input graphicx.tex
.