2

I need to prevent overfull boxes, so that there is never a line larger than \hsize. Is there a way to do this with parameters alone without setting \emergencystretch to a large value?

The problem is: if I set \emergencystretch to say \hsize, the lines will never stick out of the right margin. But this leads to very ugly paragraphs if a small value of \emergencystretch would suffice.

So: is there a way to tell TeX to a) always prevent long lines and b) the resultung paragraph should not be totally ugly.

See the example. All given values of \emergencystretch would suffice to prevent overfull boxes. But only the first example (page 1, lower paragraph) is half way OK. The last page is totally unacceptable in that case. But in order to prevent all cases of overfull boxes, I'd have to set \emergencystretch to such a large value and thus the result #1 wouldn't show up in my document.

I guess the answer is "no", but I hope for a "yes" with a set of parameters.

\documentclass[draft]{article}

\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\begin{document}

\def\txt{Tous mes sens sont émus d'une volupté douce et pure, comme l'haleine du matin dans cette saison délicieuse. Seul, au milieu d'une contrée qui semble fait exprès pour un coeur tel que mien, j'y goûte à longs traits l'ivresse de la vie. Je suis si heureux, mon ami, si absorbé dans le sentiment de ma paisible existence, que mon art en souffre. Incapable de dessiner le mointre trait, la plus faible ébauche, jamais pourtant je ne fus si grand peintre. Quand mon vallon chéri se couvre autour de moi d'une légère vapeur; qu'au-dessus de ma tête le soleil de midi darde ses rayons embrasés sur la sombre voûte de mon bois, au fond duquel, comme d'un sanctuaire, il introduit à peine une tremblante lumière.}

\hsize 2in

\txt

{\emergencystretch 10pt \txt\par}

\vfill\eject

\hsize 2in

\txt

{\emergencystretch 100pt \txt\par}


\vfill\eject

\hsize 2in

\txt

{\emergencystretch 1000pt \txt\par}

\end{document}
  • Not sure its soluble in general. If there is an umbreakable word longer than hsize, you are overfull whatever you do, if there is a line (eg first where there is not much flexibility) with two unbreakable words that fill the line then you need \emergencystretch big enough that stretching a single word space to fill the shortfall brings you below tolerance. this must be less than the length of the next word (or it would have fitted on the line) so it depends how small your unbreakable units are after hyphenation, and how many inter word spaces you have per line. (you know all this but...) – David Carlisle Dec 5 '14 at 16:08
  • microtype can help a bit (in final mode, anyway) but nothing can eliminate the problem in all possible cases... – cfr Dec 6 '14 at 2:00
  • In your example, 3pt eliminates both over and under full boxes with microtype. – cfr Dec 6 '14 at 2:06
  • @cfr I need to prevent all overfull boxes, no matter what (except those who are impossible to solve, where the word for example is larger than \hsize). So microtype does not help me. – topskip Dec 6 '14 at 8:27
  • 1
    @topskip I see no way other than trial typesetting the paragraph with different settings of \emergencystretch until no overfull box results. I suppose this is not too hard with LuaTeX. – egreg Dec 6 '14 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.