[Tex/LaTex] Hyphenation in two languages in XeLaTeX + polyglossia

hyphenationxetex

I am fairly new to LaTeX so please excuse any obvious parts of the question.

I am looking for a way to setup hyphenation in 2 languages (Greek and English) at the same time. My setup is MacTeX +Texmaker+ XeLaTeX + polyglossia. The main language is Greek and I periodically use some terms in English that escape the fully justified text body.
Concerning the language, my preamble looks like:

\usepackage{xltxtra}
\defaultfontfeatures{Mapping=tex-text}

\setmainfont[]{Cambria} 
\setsansfont[]{Candara} 
\setmonofont[]{Consolas} 

\usepackage{polyglossia} 
\setotherlanguage{english}
\setmainlanguage{greek}

I would also appreciate any comments for my preamble on commands I could omit or change.

Thank you in advance.

Best Answer

The simplest way to get correct English hyphenation in your setup is to use \foreignlanguage:

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}

\setmainfont{Cambria}
\setsansfont{Candara}
\setmonofont{Consolas}

\setmainlanguage{greek}
\setotherlanguage{english}

\begin{document}

Αυτό το κείμενο είναι στα ελληνικά
\foreignlanguage{english}{and not in English}

\end{document}

You may want to define a shorthand in the preamble, such as

\newcommand{\EN}[1]{\foreignlanguage{english}{#1}}

so the input can be

Αυτό το κείμενο είναι στα ελληνικά
\EN{and not in English}

Note that loading xltxtra is not recommended any more. The most recent versions of fontspec take care of what used to be delegated to xltxtra, including the default font features.