[comp.text.tex] multi-line vbox

marcel@cs.caltech.edu (Marcel van der Goot) (05/29/91)

Jeff Tang (jefft@athena.mit.edu) wrote
> I've been looking for a way to get a vbox with multiple lines of text in
> it, which is only as wide as it needs to be. (this is in TeX or LaTeX)
>
> The best I can manage is:
>
> \vbox{
> \hbox{text text}
> \hbox{text text}
> \hbox{text text}
> \hbox{text text}
> }
>
> Is there any better solution? Everything else I've tried leavese the  vbox
> as wide as the page.

Almost certainly any solution will amount to the above; however, I assume
you want an easier way to input the text.

Midnight/dolines.tex will help you solve this; it may be a bit overkill
for this particular problem, but it can easily be adapted to other situations.
(To fully understand why this works, you'll need to read dolines.doc.)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	\input Midnight/dolines

	\def\beforelines{\def\enddolines{}} % empty line means end
	\def\everyline#1{\hbox{#1\strut}} % put every line in an hbox
	\let\afterlines=\relax % no need to do anything here
	\def\finishdolines{\egroup} % close the vbox

	\def\boxlines
	   {\vbox\bgroup % start the vbox
	    \let\enddolines=\relax % don't worry, relax
	    \begindolines
	   }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The macro \boxlines now takes the following lines, and puts them in a
vbox the way you want. The macro stops reading lines at the first empty line.
E.g.,
	\boxlines
	Here is the first line
	and here the second
	whereas this is the last

(followed by an empty line) creates a vbox with three hboxes inside.
You can also say
	\setbox0=\boxlines The first line
	and the last

(empty line) which puts the vbox in a register so that you can manipulate
it further. However, you cannot do
	\somemacro{\boxlines
		    ...

		  }
because that way the lines will be read before \boxlines gets it chance.


dolines.tex and dolines.doc can be obtained from ymir.claremont.edu
[134.173.4.23], directory [tex.inputs.midnight]. To make it work, you
also need loop.tex from the same directory.


                                          Marcel van der Goot
 .----------------------------------------------------------------
 | Blauw de viooltjes,                    marcel@vlsi.cs.caltech.edu
 |    Rood zijn de rozen;
 | Een rijm kan gezet
 |    Met plaksel en dozen.
 |

krab@iesd.auc.dk (Kresten Krab Thorup) (05/29/91)

Try:

\hbox to SIZE{\vbox{ test tes test test test }}

where size can be any TeX length.

BTW this problem is also implemented in LaTeX's \parbox command.

/Kresten