# XeLaTeX with polyglossia and Greek

I'm struggling a lot with XeLaTeX and polyglossia. Somehow the font selection doesn't seem to work as I would expect it (and as the error messages suggest).

\documentclass{scrreprt}

\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\newfontfamily\greekfont[Script=Greek]{Linux Libertine O}

\usepackage{polyglossia}
\setdefaultlanguage{french}

\begin{document}
\tableofcontents{}

\section{Αυτό είναι ελληνικά.}
{\bfseries Welcome to Greek:} Αυτό είναι ελληνικά

Or Russian: Привет

Or Hebrew: מה הבעיה?
\end{document}


This works perfectly well with an automatically generated "Table des matières" thanks to polyglossia.

When I change the default language to Greek by using:

\setdefaultlanguage{greek}


XeLaTeX issues an error from polyglossia:

! Package polyglossia Error:
The current roman font does not contain the Greek script!
See the polyglossia package documentation for explanation.
Type H <return> for immediate help.
...
l.12 \tableofcontents
{}


I did declare the \greekfont with \newfontfamily as you can see, but somehow \tableofcontents seems to do and expect something else.

In the end I would like to use the same document with different languages in \setdefaultlanguage to get all the nice automatic texts of polyglossia for my chapters, table of contents, etc... in the appropriate language.

-
Your example works fine for me. (TL 2011 on a Mac) Perhaps you have a duplicate of the font somewhere (e.g. an OTF and a TTF version?) This can sometimes mess up XeLaTeX. – Alan Munn Aug 2 '11 at 15:33
@alan yes, the example should work fine with language french - but does it also work for you with language set to greek? – kongo09 Aug 2 '11 at 15:47
Yes, that's what I meant with my comment. (Sorry if I was unclear.) With the default language set to greek I get Greek headings for the TOC and no error. – Alan Munn Aug 2 '11 at 15:50
@alan This is freaking me out. I'm on TL 2011 on Ubuntu Linux. Now, when I use \setsansfont{Liberation Sans} it works for me as well - almost. On close inspection the whole text body is in boldface (compared to french language setting where only the Welcome to Greek is bold). – kongo09 Aug 2 '11 at 16:01
Did you try the suggestion in my posted answer? Does that still give you problems? Changing the sans font to Liberation Sans works fine for me too. – Alan Munn Aug 2 '11 at 16:22

The KOMA scripts set headings in a sans serif font. This means in your example, they will be set in Arial. The version of Arial that you have installed therefore does not have the Greek script, hence the error (although the mention of roman in the error is a bit misleading here.)

However, if you want to use Linux Libertine for all Greek text, then you need to define separately the \greekfontsf:

% !TEX TS-program = XeLaTeX

\documentclass{scrreprt}

\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\newfontfamily\greekfont[Script=Greek]{Linux Libertine O}
\newfontfamily\greekfontsf[Script=Greek]{Linux Libertine O}
\usepackage{polyglossia}
\setdefaultlanguage{greek}

\begin{document}
\tableofcontents{}

\section{Αυτό είναι ελληνικά.}
{\bfseries Welcome to Greek:} Αυτό είναι ελληνικά

Or Russian: Привет

Or Hebrew: מה הבעיה?
\end{document}


Of course, this no longer sets the headings with a sans serif font. If you want that, then you need to get a version of Arial with the Greek script, (in which case you don't need to explicitly set the \greekfontsf ) or use another sans serif font with Greek for the \greekfontsf command.

-
Ok, I just tried. It works. The only remaining problem is that this puts the whole text body into boldface. So it is still not quite right. – kongo09 Aug 2 '11 at 16:53
Ok, one final experiment that also solves the boldface problem - and leaves me puzzled again: If I use the following two lines, everything comes out perfect without problem: \newfontfamily\greekfont{Times New Roman} and \newfontfamily\greekfontsf{Times New Roman} – kongo09 Aug 2 '11 at 17:45
I meant \newfontfamily\greekfontsf{Arial} in my last comment. – kongo09 Aug 2 '11 at 17:53
So just to get this clear: if you use \setsansfont{Arial} it doesn't work, but if you use \newfontfamily\greekfontsf{Arial} it does? That's odd indeed. As for the boldface issue I have no idea. There is a well-known issue with duplicate fonts with XeTeX, so you do need to make sure that you only have one version of whatever fonts you are using. – Alan Munn Aug 2 '11 at 18:41
Yes, it works with \newfontfamily\greekfontsf{Arial} but not with \setsansfont{Arial}. In fact, I now use both and am happy. Thanks so much for your help! My take-away is that the main problem rests with the irritating error message by Polyglossia talking about some roman font and suggesting a not so helpful font family declaration. I never would have guessed to use \greekfontsf and I haven't even seen this documented anywhere. – kongo09 Aug 2 '11 at 19:22