[Tex/LaTex] Specifying multiple hyphenation exception lists for multi-lingual documents

hyphenationlanguages

This question led to a new feature in a package:
babel

By default, (La)TeX fails at hyphenating some words, e.g., the English word potable (should be pot-able) or the German word Mor-dop-fer (murder victim, should be Mord-op-fer). There are two strategies to achieve correct hyphenation:

  • adding a "hyphenation exception" list for the document's main language in the preamble with \hyphenation{pot-able};

  • using pot\-able at every instance in the document body. (This is also the only resort for words that already contain hyphens.)

But what to do in case of multi-lingual documents? As \hyphenation only works for the main document language, must one fall back to manual hyphenation correction in the document body for other languages? Or is it possible to specify separate hyphenation exception lists for the respective languages?

\documentclass[draft]{article}

\usepackage[ngerman,english]{babel}

\begin{document}

The language is \languagename\ (correct hyphenation is \verb|pot-able|):

XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX X potable

\selectlanguage{ngerman}

The language is \languagename\ (correct hyphenation is \verb|Mord-op-fer|):

XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX Mordopfer

\end{document}

enter image description here

Best Answer

The hyphenrules environment just changes the language; moreover \hyphenation commands are always global and refer to the current language, so this is the best strategy

\documentclass[draft]{article}

\usepackage[ngerman,english]{babel}

\hyphenation{pot-able}

\begin{hyphenrules}{ngerman}
\hyphenation{mord-op-fer}
\end{hyphenrules}

\begin{document}
...
\end{document}

You can also, for greater clarity, insert the first \hyphenation command in a proper hyphenrules environment.

enter image description here

A useful addition to babel might be the following

\makeatletter
\let\@@hyphenation\hyphenation
\renewcommand{\hyphenation}[2][\languagename]{%
  \begingroup
  \@ifundefined{l@#1}
    {\@nolanerr{#1}}
    {\bbl@patterns{#1}%
     \languageshorthands{none}%
     \@@hyphenation{#2}}%
  \endgroup
}
\makeatother

so that the previous input could become

\hyphenation{pot-able} % or \hyphenation[english]{pot-able}
\hyphenation[ngerman]{mord-op-fer}