# Set hyphenation with polyglossia

If babel doesn't know how to hyphenate a word, I can inform it of good line breaks with \babelhyphenation:

\documentclass{article}
\usepackage[nynorsk]{babel}
\babelhyphenation[nynorsk]{fram-halds-skulen}
\begin{document}
framhaldsskulen
\end{document}


But how do I do this with polyglossia? The documentation doesn't say anything about it. \babelhyphenation obviously doesn't work:

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{nynorsk}
\babelhyphenation[nynorsk]{fram-halds-skulen}
\begin{document}
framhaldsskulen
\end{document}

! Undefined control sequence.
l.4 ^^I\babelhyphenation
[nynorsk]{fram-halds-skulen}
?

• I would assume you can use \hyphenation{fram-halds-skulen} as long as the right language is in scope at that point – David Carlisle Nov 20 '14 at 22:30
• @DavidCarlisle Right, I only tried \hyphenation[nynorsk]{fram-halds-skulen}, which didn't work. Then how will polyglossia understand what language the hyphenation is for if I just set \hyphenation{fram-halds-skulen}? – Sverre Nov 20 '14 at 22:33
• it's a tex primitive it is the same mechanism as tex knows which hyphenation table to use for text at that point. – David Carlisle Nov 20 '14 at 22:35

As usual, in the example the lines are overfull on purpose, so as to force hyphenation.

\documentclass{article}

\usepackage{polyglossia}
\setmainlanguage{nynorsk}

\begin{hyphenrules}{nynorsk}
\hyphenation{fram-halds-skulen}
\end{hyphenrules}

\begin{document}

\parbox{0pt}{\hspace{0pt}framhaldsskulen}

\end{document}


Use the same trick of \begin{hyphenrules} if you have different languages in your document and want to add some hyphenation rules for single words.

A possibly better interface:

\documentclass{article}

\usepackage{polyglossia}

\makeatletter
\newcommand\sethyphenation[3][]{%
\begingroup
{\xpg@nogloss{#2}}
{\setkeys{#2}{#1}\xpg@set@language{#2}%
\hyphenation{#3}}%
\endgroup
}
\@onlypreamble\sethyphenation
\makeatother

\setmainlanguage{nynorsk}
\setotherlanguage[variant=british]{english}

\sethyphenation{nynorsk}{fram-halds-skulen}

\sethyphenation{english}{tes-t-word}

\begin{document}

\parbox{0pt}{\hspace{0pt}framhaldsskulen testword}

\selectlanguage{english}

\parbox{0pt}{\hspace{0pt}framhaldsskulen testword}

\end{document}


The \sethyphenation command accepts also an optional argument such as variant=british, but at the moment it wouldn't do much good, because the same option to \selectlanguage doesn't seem to have any effect.

• Ah! \begin{hyphenrules}! – Sverre Nov 20 '14 at 22:36
• @Sverre Yes, babel 3.9 uses a similar trick, but defines the \babelhyphenation command; there's no corresponding command in polyglossia, currently. – egreg Nov 20 '14 at 22:37
• Just an extra note regarding variants, it is not quite clear what language argument one should pass to hypenrules. In the case of \setdefaultlanguage[variant=british]{english} it turns out one needs \begin{hyphenrules}{ukenglish}..., which I discovered by checking lua's messages in the log file. – Andrew Swann Nov 27 '14 at 19:12
• If the word to be hyphenated contains a hyphen itself (such as “non-degenerate”), how would one write the \hyphenation command for it? – Ruud Apr 28 '15 at 9:02
• @RuudvA You don't. By rule, TeX breaks words with explicit hyphens only at those hyphens. – egreg Apr 28 '15 at 9:17