Assume I have a word like Baden-Württemberg. TeX can't hyphenate any of these two word parts. Why?

no hyphenation in the compound word

why isn't it something like this:

enter image description here

where the small ticks indicate possible hyphenation points. A technical (TeXnical) explanation is welcome.

BTW: I am not asking how to circumvent this (by using the babel shorthand "= for example).

  • 8
    Because so decided Knuth. – egreg Jul 13 '12 at 19:35
  • 1
    @egreg but why? I mean, what parts of TeX makes decide to disable hyphenation? Is there an explicit "if word contains hyphen char, then exit" somewhere in the hyphenation routine? – topskip Jul 13 '12 at 19:37
  • See the posting Switch meaning of hyphenation commands for a LuaLaTeX-based solution, which changes all instances of - on the fly to "= if they (the instances of -) are sandwiched between two letters. Thus, Baden-Württemberg, branchen-üblich, and Gesäß-Muskulatur (and many others!) can automatically be hyphenated at many additional places. :-) – Mico Aug 7 '16 at 19:53
up vote 23 down vote accepted

The TeXbook, page 454, last but one double dangerous bend paragraph

If a trial word l1 … ln has been found by this process, hyphenation will still be abandoned unless n ≥ λ + ρ, where λ = max(1,|\lefthyphenmin|) and ρ = max(1,|\righthyphenmin|). (Plain TeX takes λ = 2 and ρ = 3.) Furthermore, the items immediately following the trial word must consist of zero or more characters, ligatures, and implicit kerns, followed immediately by either glue or an explicit kern or a penalty item or a whatsit or an item of vertical mode material from \mark, \insert, or \vadjust. Thus, a box or rule or math formula or discretionary following too closely upon the trial word will inhibit hyphenation. (Since TeX inserts empty discretionaries after explicit hyphens, these rules imply that already-hyphenated compound words will not be further hyphenated by the algorithm.)

An explicit hyphen is a character whose character code matches the font's \hyphenchar value or a ligature that ends with such a character (that's why also -- or --- inhibit hyphenation).

Indeed, if you try the following example, you'll see that TeX hyphenates the compound word:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\begin{document}
\hyphenchar\font=\string"7F

\parbox{1pt}{In Baden-W\"urttemberg}

\end{document}

The result is

In
Ba-
den-Würt-
tem-
berg

The T1 encoded fonts have in position 0x7F a character which is identical to the normal hyphen. Changing the \hyphenchar to denote this slot, the normal hyphen does not inhibit hyphenation any more.

  • 3
    8 consecutive lines with hyphenated words in the TeXbook (the mentioned paragraph). That should be worth a Knuth-error-award-cheque. – topskip Jul 13 '12 at 19:55
  • 1
    @PatrickGundlach Read at the bottom of page 451. :) – egreg Jul 13 '12 at 19:59
  • This solution works fine for me if I just load fontenc with the T1 encoding so that it uses cm-super. However, if I load lmodern as well, for example, it doesn't seem to work. Looking at the encoding files, both seem to put hyphen.alt in that spot. Does anybody know why it doesn't work with lmodern? – cfr Nov 26 '13 at 23:07
  • 2
    @egreg Am I right that changing \hyphenchar ist not really a practical »solution«? One would need to change it for all fonts and fonts series in use to get uniform behaviour for a document... (and still a "= may be needed in Baden-Württemberg so there isn't much gained when typing, anyway) – clemens Feb 27 '14 at 11:49
  • 1
    @cgnieder Yes, you're right. IIRC, there should a package that can hook the choice of \hyphenchar at every font loading; but also hyphenation patterns should be modified to have possible breaks at - (the usual hyphen). – egreg Feb 27 '14 at 11:55

The \hyphenchar\font=\string"7F seems not the correct work around for this problem, since it is not font independent.

A better way would be to set the \defaulthyphenchar=127 which seems font independent. Also hyphenation which are defined in acronyms will be correct too. BUT there are still issues when having hyphens in the text like:

Baden-W\"urttemberg
\gls{BP}-Test

enter image description here

If you look at "den-Würt-", it is still not split correctly into two lines. Also the last example "BP-Test" isn't split. The only work around I have found is to use "= instead of - in the text which works for now. But I would appreciate a better solution...

Here is the MWE:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

%\usepackage{lmodern}
\usepackage{mathptmx}

\usepackage[
nonumberlist,
acronym,
nopostdot,
section]
{glossaries} 

\newacronym{BP}{BP}{Borderline-Pers\"onlichkeitsst\"orung}

\defaulthyphenchar=127

\begin{document}
\parbox{1pt}{In Baden"=W\"urttemberg}

\parbox{1pt}{In \gls{BP}}

\parbox{1pt}{\gls{BP}"=Test}

\end{document}

enter image description here

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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