# Can a \hbox be made to attain all of its surrounding space?

If I have two boxes like so:

\hbox to 2cm{\vrule\hfil\hbox{\vrule keke\vrule}\hfil\vrule}
\bye


, then is it possible somehow for the inner \hbox to take all of that 2cm? (the \hfils and \vrules are there only to illustrate the sizes)

-
Box specifications take dimensions. So you can write \hbox to2cm{...} or \hbox spread2cm{...}, but \hbox spread1fil{...} doesn't work. If you don't give a specification, then the box has its natural width. Maybe you can explain what you're really trying to accomplish. – TH. Apr 14 '11 at 5:08
To clarify, if somehow \wd\hfill gave you the width that the \hfill would take up, you would want the inner hbox to be \hbox to \wd\hfill? I know a way to get this result, but it's quite ugly. – Charles Stewart Apr 14 '11 at 5:50
@TH.: well, ultimately, I'd like to have a superscript on a \downbracefill which is inside a \halign. Once I change the mode (either mathmode or restricted horizontal I guess), the produced box doesn't get the width of the \hbox assigned by \halign internally. – morbusg Apr 14 '11 at 8:18
@Charles: ugly or not, if it works, I'd love to see your solution. – morbusg Apr 14 '11 at 8:49
This question is a bit of a dilemma when it comes to accepting an answer, due to my mistake. Apologies. – morbusg Apr 19 '11 at 7:01

This doesn't answer your question, but perhaps you want something like this?

\documentclass{article}
\makeatletter
\newcommand\labeleddownbracefill[1]{%
$\m@th \setbox\z@\hbox{$\braceld$}% \braceld \leaders\vrule\@height\ht\z@\@depth\z@\hfill \braceru \raise1ex\hbox to\z@{\hss$\scriptstyle#1$\hss}% \bracelu \leaders\vrule\@height\ht\z@\@depth\z@\hfill \bracerd$%
}
\makeatother
\begin{document}
\begin{tabular}{cc}
foo&\labeleddownbracefill{\lambda}\\
bar&Here is some text to be braced\\
\end{tabular}
\end{document}


-
 Ah, of course! This is definitely the right way for what I was after. Too bad I asked the question on the basis of false assumption. I'll see if I can edit the question (and hopefully the title) to better reflect the actual problem (unless Charles chimes in for the question title). – morbusg Apr 14 '11 at 15:11

My idea was hairier than I thought, and falls a bit too far from a solution to count as an answer, but since I spent some time on it ... the basic idea, given code as follows (all code in Plain Tex):

\setbox0=\hbox to 3in
{\hfill a\hfill} % Box 0 is an hbox containing a skip, an hbox-like item, and a skip
\showbox0


is that (i) \showbox will tell you the information you need to reengineer the hbox by telling you how it "sets" glue:

\hbox(4.30554+0.0)x216.81, glue set 105.905fill
.\glue 0.0 plus 1.0fill
.\tenrm a
.\glue 0.0 plus 1.0fill


namely that 1.0fill is 105.905 of Tex's internal measure; and (ii), you can use this glue setting factor to go back and substitute the vrule for the last skip:

\skip0=105.95 % the glue setting factor
\setbox1=\hbox to 3in
{\unhcopy0 % Make contents so far of this box be contents of box 0
\unskip %remove last skip
\hbox to \skip0{\vrule}} %put in hbox of same width as removed skip


The the two box registers will contain three items of the same width, but the last skip from box 0 will be replaced by a rule in box 1. You can make this step easier by defining a macro with a "hole" where the skip/hbox are to go.

We don't want to have to calculate the width based on looking up the results by hand: we want to get the "setting" width for the glue dimension automatically. This is where it gets hard. I think there is no way in Tex or Etex to internally extract the stretch/shrink factor of skips, although there is the possibility to spit out the information using \showbox and perform the calculation externally. Luatex does allow you to look inside the stretch/shrink factor, but it doesn't seem to directly allow you to inspect the setting factor.

So I can think of two problematic ways to get the value wanted here:

1. By parsing the output of \showbox externally;
2. In Luatex, by recursing over the structure of a box and computing the glue setting based on the information gathered (i.e., reconstructing what the Tex algorithm does already).
-