[Tex/LaTex] XeLaTeX with polyglossia and Greek

fontspecgreekpolyglossiaxetex

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).

Please consider the following example:

\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!
Please define \greekfont with \newfontfamily.
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.

Can anyone please help?

Best Answer

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.

Related Question