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.

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

share|improve this question
    
for the english word it should be reported to Barbara Beeton and for the german one to Werner Lemberg. Then they can move into the default hyphenation exception list or the experimental one for ngerman. –  Herbert Dec 11 '11 at 20:40
    
@Herbert: True. My question implied that there are (hopefully only temporarily) some words which are missing in the default exception list. –  lockstep Dec 11 '11 at 20:48
add comment

3 Answers

up vote 17 down vote accepted

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}
share|improve this answer
    
+1 for the babel addition. –  lockstep Dec 11 '11 at 20:35
2  
Nice idea. I don't like redefining primitives, but I'll consider it for babel 3.9. –  Javier Bezos Aug 22 '12 at 16:07
    
@JavierBezos Maybe \definehyphenation or something like this. –  egreg Aug 22 '12 at 17:47
add comment

babel v3.9, released in March 2013, introduces the \babelhyphenation macro. Quoting the manual, p. 14:

\babelhyphenation[<language>,<language>,...]{<exceptions>}

Sets hyphenation exceptions for the languages given or, without the optional argument, for all languages (eg, proper nouns or common loan words, and of course monolingual documents). Language exceptions take precedence over global ones.

See section 1.6 of the manual for more details.

\documentclass[draft]{article}

\usepackage[ngerman,english]{babel}

% The following requires babel v3.9 (released March 2013)
\babelhyphenation[english]{pot-able}
\babelhyphenation[ngerman]{Mord-op-fer}

\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}
share|improve this answer
add comment

egreg's solution is great and especially to be preferred if you want to use as few packages as possible. In case you're using the biblatex package to manage your bibliographies and citations: This package also provides a mechanism for multiple hyphenation exception lists, namely, the macro \DefineHyphenationExceptions{<language>}{<exceptions>}.

\documentclass[draft]{article}

\usepackage[ngerman,english]{babel}

\usepackage{biblatex}

\DefineHyphenationExceptions{english}{pot-able}
\DefineHyphenationExceptions{ngerman}{Mord-op-fer}

% Everything from here to \begin{document} only serves to avoid biber errors
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\nocite{*}

\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}
share|improve this answer
add comment

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.