# Polyglossia and Verbatim problem

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?

-
You have to define also \greekfonttt. I would never use ucharclasses for interspersing English in Greek; you risk many unexpected results. –  egreg Oct 16 '12 at 17:21
So what would you recommend instead? Apart the strategy when you define a command for change language and then you put the language X block in it, like \en{I am Jonathan} \gr{Είμαι ο Γιάννης} –  Paramar Oct 16 '12 at 17:38
The default language is Greek; just define \en for English snippets: \newcommand{\en}[1]{\foreignlanguage{english}{#1}} and use the provided environments to switch languages for longer passages in English (and maybe \gr for inserting Greek snippets in English text). Marking the code is always better. One problem you can run into is exactly that \verb text may not be typeset in the mono font. –  egreg Oct 16 '12 at 17:45
@egreg Make that an answer, please. –  lockstep Nov 4 '12 at 15:01

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}

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.