I'm testing this with the following code:
\documentclass{article}
% set up a box for dimension testing purposes
\newbox\testbox
\newcommand{\filltestbox}[1]{\setbox\testbox=\hbox{#1}}
\newcommand{\testboxwidth}{\the\wd\testbox}
\begin{document}
\filltestbox{This is \\ text of which \\ I don't know the \\ exact width}
\begin{minipage}{\testboxwidth}
\box\testbox
\end{minipage}
\end{document}
but I have no idea how to make TeX process the linebreaks so that the box has
the bounds that the text would have as paragraph. The inability to use
\parbox without an explicit width is quite frustrating. Has anyone tried this
before? what really obvious thing (if you've memorised the TeX Book) am I
missing?
(This problem affects the settobox package too, so it's just as not-working
as this more basic example)
- Mike "Pomax" Kamermans
nihongoresources.com
have you tried varwidth? a version of minipage that will reduce its with
to the max line width used.
/daleif
> PmI wrote:
>> I'm trying to put some text in an box, so that I can calculate the box
>> dimensions, but hbox nor mbox seem to want to preform linebreaks, and parbox
>> needs a width argument, which is actually what I want to compute so it's
>> useless...
> have you tried varwidth? a version of minipage that will reduce its with
> to the max line width used.
Or use a tabular:
\documentclass{article}
% set up a box for dimension testing purposes
\newsavebox\testbox
\newcommand{\filltestbox}[1]{\savebox\testbox{\begin{tabular}{@{}l@{}}#1\end{tabular}}}
\newcommand{\testboxwidth}{\the\wd\testbox}
\begin{document}
\filltestbox{This is \\ text of which \\ I don't know the \\ exact
width}
x\begin{minipage}{\testboxwidth}
\usebox\testbox
\end{minipage}y
\end{document}
--
Ulrike Fischer
tabular wasn't quite satisfactory, but the varwidth solution works quite
nicely. yet another package that should be mentioned in the list of "stuff
you will reasonably want to have in your preamble".
thanks for the help.
- Mike
> \filltestbox{This is \\ text of which \\ I don't know the \\ exact width}
> \begin{minipage}{\testboxwidth}
varwidth is fine and handles lots of complications in the text,
and performs the measurement and the minipage together,
but for interest, it isn't too hard to extend the effect of \hbox
for measurement, as long as you are only using simple
text.
\newcommand\filltestbox[1]{\setbox\testbox\vbox{%
\def\\{\unskip\egroup\hbox\bgroup\ignorespaces}%
\hbox\bgroup\ignorespaces #1\unskip\egroup
}
Donald Arseneau
> for interest, it isn't too hard to extend the effect of \hbox for measurement, as long as you are only using simple text.
>
> \newcommand\filltestbox[1]{\setbox\testbox\vbox{%
> \def\\{\unskip\egroup\hbox\bgroup\ignorespaces}%
> \hbox\bgroup\ignorespaces #1\unskip\egroup
> }
Hmm, can you elaborate on what this code does?
- Mike
It makes a vbox (called \testbox) containing a list of hboxes,
whose contents are the pieces of text between \\. Thus
\testbox has width equal to the widest of the hboxes.
The last line should be }}
Donald Arseneau
I agree varwidth is extremely useful, but I think it is out of scope for
the average user. *I* might reasonably want to have it in my own
Preamble, but in 20 years of teaching TeX I have never encountered an
author who would have needed it, although many developers certainly
might -- but it depends on whom the "list of stuff you will reasonably
want to have in your preamble" is aimed at...
///Peter