[Tex/LaTex] Polyglossia and Verbatim problem

fontspolyglossiaverbatim

After having some hyphenation problems with my text (in greek and english) I changed some of my packages. In the beggining I was using:

  \usepackage{mathspec} 
  \usepackage{xgreek}
  \usepackage{xunicode}
  \usepackage{fontspec}
  \setallmainfonts[Mapping=tex-text]{Arial}
  \setallsansfonts[Mapping=tex-text]{Arial}
  \setallmonofonts[Mapping=tex-text]{Arial}

After doing some search I modified those to get correct hyphenation. After doing so in a small sample text, I am trying to change the packages of my original text to the ones used in my sample, in order to get finally the correct hyphenation. However at some point I get:

Package polyglossia error: The current Roman Font does not contain the Greek Script.

Line 242: \begin{verbatim}

The packages I use are the following:

\usepackage{fontspec}
\newfontfamily\greekfont[Script=Greek]{Linux Libertine O}
\newfontfamily\greekfontsf[Script=Greek]{Linux Libertine O}
\usepackage[Greek,Latin]{ucharclasses}
\usepackage{polyglossia}
\usepackage{xltxtra}
\setmainlanguage{greek}
\setotherlanguages{english}
\setTransitionsForGreek{\selectlanguage{greek}}{\selectlanguage{english}}
\setmainfont{Linux Libertine O}

How can this be fixed?

Best Answer

Verbatim text uses the font defined with \setmonofont (or the default Latin Modern Typewriter font).

However, when the Greek language is active, Polyglossia makes XeLaTeX look whether the font has the GRK feature and, if that's not available, it looks whether a font family under the name \greekfonttt has been defined. Thus

\newfontfamily{\greekfonttt}{FreeMono}

(use your preferred monospaced font) should do.

I wouldn't use ucharclasses for switching automatically from English to Greek and conversely: this will fill your auxiliary files with \select@language declarations and won't ensure that a monospaced font is used in verbatim. Rather prefer the standard method of confining language switches with explicit \selectlanguage commands (not recommended), otherlanguage, otherlanguage* or \foreignlanguage.

Related Question