In cases when input text to be typeset is separate from the structured template, can the input determine the height and width of its containing box?
An example input. Question marks (?) to be substituted (Lua or TeX).
The width of the parent box is ?
The height of the parent box is ?
Several possible templates:
\ruledhbox to 10cm{\vbox to 4cm{ \input input }} % 10cm by 4cm
\ruledvbox to 4cm{\hsize=10cm \input input } % 10cm by 4cm
\framed
[width=10cm,
height=4cm,
align={middle,lohi},
offset=0.5cm]
{ \input input } % 9cm by 3cm
Dimensions are meaningless until the box has been stored, so that's probably the place to start.
My expansion of the \aftergroup
+\lastbox
answer:
\typeset{\hbox to50pt{\vbox to40pt{\hbox to30pt{width: \parwd }}}}
{ \let\parht\askparent\let\parwd\askparent\let\pardp\askparent
\setbox0=\hbox to50pt{\vbox to40pt{\hbox to30pt{width: \parwd }}}
\hbox to50pt{\vbox to40pt{\hbox to30pt{width: \parwd }}}
}
{ \let\parht\askparent\let\parwd\askparent\let\pardp\askparent
\setbox0=\hbox to50pt{\vbox to40pt{\hbox to30pt{width: \parwd }}}
\hbox to50pt{\vbox to40pt{\hbox to30pt{width: \askparent }}}
}
{ \let\parht\askparent\let\parwd\askparent\let\pardp\askparent
\setbox0=\hbox to50pt{\vbox to40pt{\hbox to30pt{width: \parwd }}}
\hbox to50pt{\vbox to40pt{\hbox to30pt{width: } \afterafter }}
}
{ \let\parht\askparent\let\parwd\askparent\let\pardp\askparent
\setbox0=\hbox to50pt{\vbox to40pt{\hbox to30pt{width: \parwd }}}
\hbox to50pt{\vbox to40pt{\hbox to30pt{width: }} \after }
}
{ \let\parht\askparent\let\parwd\askparent\let\pardp\askparent
\setbox0=\hbox to50pt{\vbox to40pt{\hbox to30pt{width: \parwd }}}
\hbox to50pt{
\setbox\storelast=\vbox to40pt{\hbox to30pt{width: }}
\xdef\parht{\the\ht\storelast}
\xdef\parwd{\the\wd\storelast}
\xdef\pardp{\the\dp\storelast}
\ifvmode\nointerlineskip\fi\box\storelast}
}
{ \let\parht\askparent\let\parwd\askparent\let\pardp\askparent
\setbox0=\hbox to50pt{\vbox to40pt{\hbox to30pt{width: \parwd }}}
\hbox to50pt{
\setbox\storelast=\vbox to40pt{\hbox to30pt{width: }}
\xdef\parht{\the\ht\storelast}
\xdef\parwd{\the\wd\storelast}
\xdef\pardp{\the\dp\storelast}
\vbox to40pt{\hbox to30pt{width: }}}
}
\framed
you can just query\framedparameter{width}
to get the width.\setbox0
assignment is carried out before anything in the following line is evaluated, including the call to\parwd
in the assignment. therefore, everything you did afterwards is actually done in the\setbox0
line first, and after that the rest is expanded, but this time\parwd
is the width of the parent box.