7

When I define custom hyphenation with \hyphenation in XeTeX, it seems to only work for the main body of the text, but not for the bits inside \text<language> (as in \textgerman) environments.

I know I can use \- but I would rather have a global solution.

A minimal example:

\documentclass[draft]{article}
\usepackage{xltxtra}
\usepackage{polyglossia}
\setmainlanguage[variant=british]{english}
\setotherlanguage{german}

\begin{document}

\hyphenation{bb-bbb}

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbb

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \textgerman{bbbbb}

\end{document}

yields this:

\hyphenation failing with \textgerman

3
  • Maybe some of the solutions listed here also work with XeTeX: tex.stackexchange.com/questions/37934/…
    – lockstep
    Commented Mar 6, 2012 at 22:55
  • They surely work.
    – egreg
    Commented Mar 6, 2012 at 23:33
  • I might have done something wrong but I can't get either to work. They seem to depend on babel, while I want to use polyglossia.
    – Kamil S.
    Commented Mar 7, 2012 at 9:21

1 Answer 1

7

The method with hyphenrules indeed doesn't work with Polyglossia (and it should be investigated why). You can do in another way:

\newcommand{\sethyphenation}[3][]{%
  \sbox0{\begin{otherlanguage}[#1]{#2}
    \hyphenation{#3}\end{otherlanguage}}}

\sethyphenation{german}{bb-bbbb}
\sethyphenation[variant=british]{english}{bbb-bbb}

The following document will show different hyphenations of bbbbbb

\documentclass[draft]{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage[variant=british]{english}
\setotherlanguage{german}

\newcommand{\sethyphenation}[3][]{%
  \sbox0{\begin{otherlanguage}[#1]{#2}
    \hyphenation{#3}\end{otherlanguage}}}

\sethyphenation{german}{bb-bbbb}
\sethyphenation[variant=british]{english}{bbb-bbb}

\begin{document}

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbb

\textgerman{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  bbbbbb}

\end{document}

The syntax of \sethyphenation is

\sethyphenation[<options>]{<language>}{<list of words separated by spaces>}
3
  • Fantastic, thanks a lot! Would you mind explaining the purpose of \sbox0, please? I can't see a different behaviour without it.
    – Kamil S.
    Commented Mar 7, 2012 at 21:30
  • @KamilS. It's just to ensure that nothing is typeset. I'll ask Arthur Reutenauer to include this facility in Polyglossia.
    – egreg
    Commented Mar 7, 2012 at 21:35
  • That would be great. I'm a linguist and often mix many languages inside one text, so hyphenating them all manually was somewhat tedious. Thanks for the explanation.
    – Kamil S.
    Commented Mar 7, 2012 at 21:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .