Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In TeX, I can use

\hbox to 1in{foo bar baz}

to get
enter image description here

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

enter image description here

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:

enter image description here

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

share|improve this question
    
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
add comment

2 Answers

up vote 4 down vote accepted
\documentclass{article}
\begin{document}

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

\end{document}

enter image description here

share|improve this answer
    
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
add comment

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

lorem ipsum

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.