# How to spread words in several lines uniformly?

In TeX, I can use

\hbox to 1in{foo bar baz}


to get

Is it possible generalize the use, to get this result:

by typing a paragraph foo bar baz test text only?

I tried \break to break lines at the end of the paragraph, or to set \parfillskip=0pt, but the results are wrong:

What parameters should be set to tell TeX's line-breaking algorithm to get this 'ugly' result?

-
Could e-TeX's \lastlinefit be relevant here? –  morbusg Mar 3 '11 at 13:28
@morbusg: I don't think so. As is said in eTeX's manual, the new algorithm is used only if '\parfillskip has infinite stretchability'. But I need it to be 0pt here. –  Leo Liu Mar 3 '11 at 14:48

\documentclass{article}
\begin{document}

\parbox{1in}{\sloppy\parfillskip=0pt
foo bar baz test text only}

\end{document}


-
Wow, works up to 1.4in (for 1.5in, everything fits into one line). –  Hendrik Vogt Mar 3 '11 at 10:00
Great! \tolerance10000 and \parfillskip0pt does the work. –  Leo Liu Mar 3 '11 at 10:08

Nothing very general springs to mind. You're going to need to convince TeX that the two lines you want are better than what it gives you. This does it for your particular example.

\hsize1in
\parfillskip0pt
\parindent0pt
\fontdimen3\font.25in
foo bar baz test text only
\bye


It is setting the font dimension parameter 3—the amount of stretch for a normal space—in the current font to one quarter of an inch.

I guess this sort of works for larger text. Using \frenchspacing to have intersentence spacing be the same as interword spacing and removing the size, it produces something more or less reasonable (I think; I'm not sure what your exact requirements are).

\parfillskip0pt
\parindent0pt
\fontdimen3\font.25in
\frenchspacing
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
\bye


-
Thank you. \frenchspacing is useful. But setting larger \fontdimen3 may not produce uniform spacing. It seems that TeX will still try to get pretty line-breaking with fewer streching and shrinking. –  Leo Liu Mar 3 '11 at 10:18