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.

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

share|improve this question
    
Maybe some of the solutions listed here also work with XeTeX: tex.stackexchange.com/questions/37934/… –  lockstep Mar 6 '12 at 22:55
    
They surely work. –  egreg Mar 6 '12 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. Mar 7 '12 at 9:21
add comment

1 Answer

up vote 5 down vote accepted

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>}
share|improve this answer
    
Fantastic, thanks a lot! Would you mind explaining the purpose of \sbox0, please? I can't see a different behaviour without it. –  Kamil S. Mar 7 '12 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 Mar 7 '12 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. Mar 7 '12 at 21:47
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.