I'd like to write the following:
Some long paragraph of text \measureremainder{\whatsleft}\begin{mimipage}{\whatsleft}
stuff
\end{minipage}
so that the minipage takes up exactly the remaining \hsize minus \widthof{Some long paragraph of text}. I tried the following, based on code in TeX by Topic:
\newbox\linebox
\newbox\snapbox
\def\restofline#1{%
\hfill\par\setbox\linebox\lastbox% Fill the line, then pop it off
\ifvoid\linebox%
\else%
\unskip\unpenalty%
\setbox\snapbox\hbox{\unhcopy\linebox}% and reset the line without expanding flexible spaces
\setlength{#1}{\wd\linebox}% Then retrieve the difference between the two settings
\addtolength{#1}{-\wd\snapbox}%
\usebox\snapbox% and replace the line with the tightly-set one
\fi%
}
And that kinda works, in raw paragraphs: it will duplicate the initial \parindent, though, if the paragraph is only one line long. But it totally breaks if I try it inside, e.g., an itemize environment:
\begin{itemize}
\item Some text \measurerest{\whatsleft}\showthe\whatsleft
\end{itemize}
Because \lastbox doesn't work in vertical mode.
Two approaches that didn't work: I tried \begin{minipage}{\textwidth plus -1fill}, but minipages take a length, not a dimen, so the stretch factors are ignored. I also tried \hfill\setlength\whatsleft\lastskip, but that returns 0.0pt plus 1.0fill instead of SomeNumberOfpt
Is there a way around the \lastbox-in-vertical mode restrictions? Or a more robust way to force TeX to set glue so it can be measured?

\leadersbased solution will be simpler. – Aditya May 09 '11 at 17:47\leaders, but the OP would have surly mentioned a need for rules, wouldn't he? – Martin Scharrer May 09 '11 at 18:32and I want to let the tags wrap in as wide a space as possible (between the |...| bars) @MartinScharrer's answer seems to work for me :)
– Ben Lerner May 10 '11 at 06:49