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.

There is a more or less equivalent question to this: Ensure minimal length of last line, but I absolutely need a TeX solution. I more or less stumbled upon the problem mentioned in the discussion of egreg's answer, and I'd like to see a deeper analysis just to make sure there absolutely is no working TeX solution.

Replicating Patrick's solution (insert unbrekable space between words at the end) in TeX will get really ugly.

So there I was naively saying

\parfillskip 0pt plus 100pt

in the hope this would make sure the horizontal space at the end of the last line of every paragraph was at most 100pt wide.

But witness the result of my MWE:

\documentclass[11pt]{article}

\usepackage{lipsum}

\begin{document}

\parfillskip 0pt plus 100pt

\let\opar\par
\def\par{\opar\hbox to \linewidth{\hfill\vrule width100pt height\fboxrule}}

\lipsum

\end{document}

You'll see that the 100pt are disregarded even by 'unproblematic' paragraphs. \sloppy doesn't really help either, so the problem doesn't really lie in the fact that there is not enough material to stretch out.

Here's an extreme example:

parfillskip example

The rule indicates the point to which the last line should stretch.

Looking at the resulting box yields

.\hbox(7.60416+0.0)x360.0, glue set 2.49602
..\OT1/cmr/m/n/10.95 c
..\OT1/cmr/m/n/10.95 u
..\OT1/cmr/m/n/10.95 r
..\discretionary
...\OT1/cmr/m/n/10.95 -
..\OT1/cmr/m/n/10.95 s
..\OT1/cmr/m/n/10.95 u
..\OT1/cmr/m/n/10.95 s
..\glue 3.65 plus 1.825 minus 1.21666
..\OT1/cmr/m/n/10.95 l
..\OT1/cmr/m/n/10.95 u
..\OT1/cmr/m/n/10.95 c
..\discretionary
...\OT1/cmr/m/n/10.95 -
..\OT1/cmr/m/n/10.95 t
..\OT1/cmr/m/n/10.95 u
..\OT1/cmr/m/n/10.95 s
..\glue 3.65 plus 1.825 minus 1.21666
..\OT1/cmr/m/n/10.95 m
..\OT1/cmr/m/n/10.95 a
..\OT1/cmr/m/n/10.95 u
..\discretionary
...\OT1/cmr/m/n/10.95 -
..\OT1/cmr/m/n/10.95 r
..\OT1/cmr/m/n/10.95 i
..\OT1/cmr/m/n/10.95 s
..\OT1/cmr/m/n/10.95 .
..\penalty 10000
..\glue(\parfillskip) 0.0 plus 100.0
..\glue(\rightskip) 0.0

So I assume the glue set 2.49602 is applied to the \parfillskip glue, yielding 249.6pt, which looks more or less like what's on the screenshot.

My question is now: Is there another solution to get the intended effect in TeX?

Edit: I found that adding \usepackage[latin]{babel} will make the 'problem' go away in this case, but the real "text" I need to typeset is a list of symbols with spaces between them. They need to be spaced out in any manner such that the last line is not too short, so the real application is much nearer to the MWE I'm giving (without proper hyphenation).

Conclusion Thanks to David, my original application now works like a charm:

enter image description here

I think the pictograms slightly stretched out look much better than the alternative with only one pictogram in the last line!

share|improve this question
    
Glue with a stretch component is allowed to stretch beyond the stated dimension, at the expense of \badness. If the badness is more than \tolerance, TeX will do a third pass on the paragraph, adding \emergencystretch to the stretchability in all lines. This will allow to stay in the imposed limit in many more paragraphs than before. Not everyone. With a small line width the success/unsuccess ratio will be higher. You're missing an accent on "Plzeň". :) –  egreg Jul 18 '12 at 17:07
    
@egreg On the accent: That's a drawback of data-basedness. While the database itself and all subsequent steps are unicode-based, there are all kinds of possibilities to get garbage into the database... –  Stephan Lehmke Jul 18 '12 at 17:12
    
@egreg I still feel dense one the \emergencystretch-\tolerance issue. In this case, with low tolerance, the second symbol refused to enter the last line. I had to set \tolerance9999 to make it move down. Based on your explanation, I'd have expected it the other way round. –  Stephan Lehmke Jul 18 '12 at 17:15
1  
See the TeXbook, p. 107. For the pictogram line, I suggest to allow more stretchable space between them (\spaceskip, probably) and ~ between the last two, so you'll avoid the lonely pictogram from the start. –  egreg Jul 18 '12 at 17:20
    
@egreg That's semantically equivalent to what you said (but your version is more concise :) My problem lies more in applying this reasoning to the balance between stretching interword space and the badness induced by breaking \parfillskip 100pt minus 100pt, which seems to lie behind the issue at hand. –  Stephan Lehmke Jul 18 '12 at 17:26
show 1 more comment

2 Answers 2

up vote 6 down vote accepted
\emergencystretch.3\textwidth

works for me to keep all the last lines inside the ruled area.

Alternatively you can do

 \parfillskip  100pt minus 100pt

But that works by s t r e t ch i n g the last line only, so looks rather horrible. Or you could do a combination of the two....

share|improve this answer
    
Can you explain why and how this works? Interestingly when just setting \emergencystretch I'm getting slightly less than satisfactory results with my original MWE (at least here the last two paragraphs are not filled out enough, is this different on your side?), but it works on the original application I had in mind! –  Stephan Lehmke Jul 18 '12 at 15:31
1  
well I sort of use Tex like I use English: sometimes its hard to say why things are as they are, you just have to do what feels right:-) The problem with just setting emergencystretch and leaving plus glue in parfillskip is that the energencystretch will apply to parfillskip as well as to interword spacing so if necessary this will stretch to more than 100pt, with the minus version then the 100pt is an upper limit (or you will get infinite badness) so probably doing that and then having emergencystretch is the thing to do. –  David Carlisle Jul 18 '12 at 16:30
    
Thank you, that probably is it. The sad thing is, lacking this kind of intuition one is often left to banging one's head against the wall without any result. For instance, in the "real" example I gave above, with setting \emergencystretch and \parfillskip as you specified, I was still absolutely unable to get more than one icon in the last line, though all other MWEs I tried to construct just worked :-( It turned out I had to set \tolerance9999 to get it working. I'm sometimes hoping for a more systematic method to get things done. –  Stephan Lehmke Jul 18 '12 at 16:43
add comment

In one of my Glisterings columns in TUGboat (TUGboat, 28, 2, 229--232, 2007) I wrote about several different paragraph formatting methods (see www.tug.org /TUGboat/tb28-2/tb89glister.pdf). The following code is taken from that 2007 article.

\newdimen\parabout
\newdimen\about
\about=2em
\def\nottooshort{%
  \parabout=\hsize
  \advance\parabout -\about
  \leftskip=0pt plus 0pt minus 0pt
  \rightskip=\leftskip
  \parfillskip=\parabout minus \parabout
  \parindent=2em}

Following the declaration \nottooshort then the last line of paragraphs will be at least approximately \about long.

share|improve this answer
    
Thank you very much for the reference. Good to have a complete overview! Concerning my problem at hand, the 'approximately' is really the problem, isn't it? At least I don't see an advantage to the suggestion of David. Is there? \hsize12em \nottooshort foo foo foo foo foo foo foo\par \noindent \hrule width 2em will give an "underfull" last line unless I add \tolerance 9999. –  Stephan Lehmke Jul 19 '12 at 10:42
    
Is there a way to apply such a setting only to paragraphs, but not to titles? I've asked this in a question here: tex.stackexchange.com/questions/151680/… –  Ruben Verborgh Dec 29 '13 at 17:17
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.