# Change height of a box, recalculate rubber lengths

I'm using \setbox and \usebox to define a box, measure its default dimensions and render it later. During rendering, sometimes there is more vertical space available than measured initially, and I'd like to distribute this space between paragraphs. Is this possible using only the \mybox box in the example below?

\documentclass{scrartcl}
\pagestyle{empty}

\newbox\mybox

\begin{document}
\setbox\mybox=\hbox{
\begin{minipage}[t]{10em}
\setlength{\parskip}{0ex plus5ex}
First paragraph

Second paragraph

Third paragraph
\end{minipage}
}%
%
\usebox{\mybox}
% How can I render the box with a specified height and distribute the paragraphs
% according to the parskip?
\end{document}


Updating glue after changing width of a box seems related, but I don't see how to apply the technique shown there to change the height of a box.

• You can't do it with minipage, you can if you say \setbox\mybox=\vbox{...} and then do tricks with \unvbox. – egreg Jun 23 '15 at 12:26
• @egreg: Thanks. Can I use a \vbox like a minipage (type in paragraphs separated by an empty line, specify the width of the box)? Then I could use \vbox instead of minipage -- but isn't a minipage just a box (internally) that can be unboxed just the same? – krlmlr Jun 23 '15 at 12:34
• You should add \@minipagerestore at the start, so the behavior should be the same as in a minipage – egreg Jun 23 '15 at 12:43
• @egreg: At the start of what? – krlmlr Jun 23 '15 at 12:46
• \setbox\mybox=\vbox{\@minipagerestore...} (requires \makeatletter). – egreg Jun 23 '15 at 12:51

After the removal of white spaces by line ends at the begin and end of the \hbox, the box \mybox is an \hbox, which contains a \vtop. Then the outer \hbox can be unpacked with \unhcopy or \unhbox (the latter clears the contents of the box). \lastbox catches the unpacked \vtop, which can be unpacked with \unvcopy and put into a new \vtop with the specified height:

\documentclass{scrartcl}
\pagestyle{empty}

\newbox\mybox
\newbox\tmpbox

\begin{document}
\setbox\mybox=\hbox{%
\begin{minipage}[t]{10em}
\setlength{\parskip}{0ex plus5ex}
First paragraph

Second paragraph

Third paragraph
\end{minipage}%
}%
%
\unhcopy\mybox
\setbox\tmpbox=\lastbox
\vtop to 100pt{\unvcopy\tmpbox}
\end{document}


• This works like a charm for my application, from the first try. Many thanks! – krlmlr Jun 23 '15 at 12:45