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.

To suppress overflows, on one extreme, we have ragged layouts which suppress justification :

\usepackage{ragged2e} % http://tex.stackexchange.com/questions/168480/why-does-tex-prefer-an-overfull-box-to-hyphenating-here
\RaggedRight

On the other extreme, we have standard justified text and one can use \sloppy which does not solve every problem anyway.

Both leads to ugly things for me.

At this point, I have come to:

\usepackage{hyphenat}
\hyphenpenalty=750
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[babel=true,kerning=french,protrusion=true,expansion=auto,spacing,tracking]{microtype}
\pretolerance=1500
\tolerance=2000
\setlength{\emergencystretch}{2em}

Which is the best solution I could come to, for my usage (French has compound words and apostrophes which deal badly with hyphenation - for compound words, I use \BreakableHyphen{}). Good discussion here and here.

But ideally, I would like standard tolerance and in some exceptional cases, relax the justification and replace it with a left alignment. But I want that parameterized in the preamble because I want the users to parameterize the format of the eBooks they will get, and want them to fit right without control. So local solutions are prohibited here.

What I imagine would be something like:

% previous lines identical
\pretolerance=300
\tolerance=500
\setlength{\emergencystretch}{2em}
pseudo-code: if (overflow) then underflow the current line by moving the last word to the next line

Any idea please?

share|improve this question
1  
This is a very interesting question, but it could be improved immeasurably with the addition of compilable code beginning with \documentclass and ending with \end{document} to demonstrate some of the current issues you routinely face. –  Steven B. Segletes May 16 at 15:04
    
I forgot to precise I use LyX. I have to find how to make an example with LaTeX only... –  lalebarde May 16 at 16:40
    
I can make a LaTeX-only MWE, but I still don't manage to reproduce my line break problems. –  lalebarde May 16 at 17:39

1 Answer 1

An example would (always) help, but I suspect that the answer is that you can not do this without adding markup at the problematic linebreak. or at least you can not do it in a single pass of TeX's linebreaking algorithm. TeX doesn't really consider each line in this way it is trying to minimise badness over the paragraph.

If you are prepared to save each paragraph and re-process (or use luatex's callbacks) Then I think what you want to do is set the paragraph with a large emergency stretch so that there will be no overfull lines unless there is an unbreakable box (or word) that is wider than \textwidth.

Then disassemble the box line by line (using lua or a \lastbox loop) and find each line box that is very stretched: eg if the line is in \box0 use \setbox2\hbox{\unhbox0} then if box 2 is a lot shorter than \hsize use \box2 (so putting all the white space at the right) otherwise use \box0 keeping the original justified line, then move on to check another line of the saved paragraph until you have adjusted the whole paragraph.

This is certainly possible, but it is a very invasive change and will almost certainly be incompatible with lots of things.

share|improve this answer
    
Thanks David, but I am afraid this is to much far from my skills. –  lalebarde May 16 at 16:35

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.