0

I checked the warnings and ran into an overfull hbox. The word planned is sticking out of the line. According to this website, it hasn't got any hyphenation, which explains why TeX isn't breaking it. It does not explain though, why it is not breaking before the word instead.
So how do I tell TeX to break the line before a too long word which cannot be hyphenated? the word planned sticks into the margin

Update

To clarify the situation, this issue always occurs when an unbreakable word is the last one in a line. This also applies to words like with and Names without hyphenation pattern. TeX rather prefers to produce an overful hbox instead of breaking the line before the word and I don't understand why or how to change this.
I'm currently using XeLaTeX. microtype does not solve the problem.

Update MWE

Here is an example with which I could reproduce the issue:

\documentclass{scrbook}
\usepackage{lipsum}

%\hyphenation{plan-ned}

\begin{document} \lipsum[1]

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA planned BBB CCC.

\lipsum[2] \end{document}

the word planned sticks into the margin
(Adjust the count of A as needed in case you use another paper format.)
When defining a hyphenation pattern, the word breaks as desired. But TeX is not willing to just break the line before the word.

Erik
  • 33
  • 1
    Please provide code for a minimal example we can compile to reproduce this. – cfr Jan 27 '24 at 02:59
  • @cfr Sorry, I've updated the question with a MWE. – Erik Jan 27 '24 at 04:53
  • 1
    An approach limited to the affected paragraph is to wrap it in \begin{sloppypar} ... \end{sloppypar}. This isn't optimum; rewriting is better, if possible. This question might also be helpful: What is the meaning of \fussy, \sloppy, \emergencystretch, \tolerance, \hbadness? – barbara beeton Jan 27 '24 at 16:08
  • the MWE isn't a real example as there is clearly no way to get sensible linebreaks you are using English patterns and AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA is not an english word. there is no stretchable space on the line so no way to break before planned without being infinitely underful. You should provide a real example. This example is more or less like showing \rule{\dimexpr\textwidth+10pt}{2pt} and asking why it is 10pt over full, there is nothing else TeX can do. – David Carlisle Jan 27 '24 at 23:49
  • @barbarabeeton \begin{sloppypar} is working, thank you. It needs to be applied to every case separately, but at least it is leading to the desired result. If this was an answer, I'd mark it as accepted. – Erik Jan 28 '24 at 00:57
  • you don't have to do every case separately you can just use \sloppy once at the start if you prefer – David Carlisle Jan 28 '24 at 01:23
  • @DavidCarlisle If I understood it right, using \sloppy globally is strongly discouraged since it leads to poor typesetting where better results could be achieved? Correct me if I am wrong. And \sloppy-\fussy didn't change anyching for me, only the sloppypar environment did. – Erik Jan 28 '24 at 02:41

3 Answers3

1

An approach limited to the affected paragraph is to wrap it in \begin{sloppypar} ... \end{sloppypar}. This isn't optimal; rewriting is better, if possible. This question might also be helpful: What is the meaning of \fussy, \sloppy, \emergencystretch, \tolerance, \hbadness?

If any of the "overfull" words can legitimately be hyphenated, adding a "discretionary hyphen" (\-) would probably be better than sloppypar.

0

It is not breaking before the word because is also a very bad solution. It is simply impossible justify a line with a single and shorter word. There are not any space to stretch.

Even breaking the "AAA" line is not enough for a decent line break. Only setting a very ugly interword stretch (\fontdimen3\font=1.9em or more) you can obtain a automatic line break in this case. Otherwise, with the default settings, you will need at least six more interword spaces to push "planned" to the next line.

Therefore, instead of solving the problem in a botched way, LaTeX prefer warn you about the issue (easier to see with the draft option enabled) and expect your solution. A good way to deal with this type of issues in real documents is start thinking how rewrite the text. Use microtype package also could help in some cases.

Fran
  • 80,769
  • Instead of \fontdimen you can (should) use \spaceskip. – egreg Jan 27 '24 at 08:08
  • @egreg I wanted to refer specifically to the interworld stretch ratter that to the interword glue to explain the issue, but it was not my intention to suggest stretch the space in any way, quite the opposite. – Fran Jan 27 '24 at 10:12
  • The problem with setting a \fontdimen is that the setting is global. You get the same effect by \spaceskip=\fontdimen2\font plus 1.9em minus \fontdimen4\font, which can be done locally. – egreg Jan 27 '24 at 11:19
  • @Fran, 'AAA' was just an example. The word is written in a normal text, hence it should be possible to break the line before the word by stretching the whitespaces. Adding some spaces to the 'AAA' string doesn't solve the problem, though. – Erik Jan 27 '24 at 14:03
  • @Erik If you mean "adding some spaces to the AAA string" type AA A for LaTeX this leave just ONE space that obviously does not solve anything. When I said "at least six more interword spaces" I mean that you need al least cut the string at least in eight words (i.e, with 7 spaces between) to push "planned" enough without stretch that spaces. And I said that only to illustrate the issue, not at all as a way to solve it. – Fran Jan 27 '24 at 17:41
  • @Fran The original issue occured in a line where planned is the 10th word. So this still doen't explain it. (And of course I didn't mean consecutive spaces but spilt the string up to multiple words.) – Erik Jan 27 '24 at 23:32
  • @Erik Because the length of your original words + spaces have no the exact same total length (in points, not in number of characters). The question is simply if your original words fill enough the line. And when this does not happen, if the length of spaces (\fontdimen2) can be shrinked (\fontdimen4) or stretched (\fontdimen3) enough to respectively fit "planned" in the line or push it out of the margin, causing the line break. Well, Also matter if the line have a end of sentence, as this could add also an extra space (\fontdimen7). – Fran Jan 28 '24 at 08:34
0

You might insert a soft hyphen for the particular problem (I don't think that globally defining plan-ned as possible hyphenation is good).

However, you might do better by using microtype.

With the standard setting, the overfull already reduces to less than 3pt, but you can locally allow more liberal parameters.

\documentclass{scrbook}
\usepackage{microtype}
\usepackage{lipsum}

\SetExpansion[ context = sloppy, stretch = 100, shrink = 40, step = 5, ]{ encoding = {OT1,T1,TS1} }{}

\newenvironment{microtypesloppy}{% \par\microtypecontext{expansion=sloppy}% }{\par}

\begin{document}

\lipsum[1][1-3]

\bigskip % with a soft hyphen

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA plan-ned BBB CCC.

\bigskip

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA planned BBB CCC.

\bigskip % better

\begin{microtypesloppy} AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA planned BBB CCC. \end{microtypesloppy}

\end{document}

enter image description here

The third paragraph is typeset with no overfull.

egreg
  • 1,121,712
  • Unfortunately, the microtype settings don't work for me, it's still stickig into the margin. – Erik Jan 27 '24 at 14:14
  • @Erik I can't answer what you aren't asking. Tough paragraphs may require different methods. – egreg Jan 27 '24 at 14:19
  • What do you mean with different methods for paragraphs?
    To add a specific question: Can I tell TeX to break a line before a word instead of producing an overfull hbox?
    – Erik Jan 27 '24 at 14:40
  • @Erik Not automatically. What I meant to say is that if we see the *real* offending paragraph, we might suggest different methods. Without that, only generic answers are possible. – egreg Jan 27 '24 at 14:46
  • Sorry, I removed it when adding the MWE. I added it again to the question ;) – Erik Jan 27 '24 at 23:35
  • Actually, microtype does help when using with pdflatex or lualatex. Just some features are not available for XeLaTeX, unfortunately. Hence, it didn't work for me. See the mictrotype manual, Table 1 on page 6 for reference about supported features by TeX engine. – Erik Jan 28 '24 at 02:44