TypeWriter font have no effect with polyglossia package

Using XeLaTeX engine, MWE1 works fine with fontspec and ucharclasses package. But when I change fontspec to polyglossia (MWE2), there is no TypeWriter font effect. Moreover, the first sentence of English text is not in Times New Roman font. Is there any fix?

MWE1

\documentclass[11pt,a4paper]{article}
\usepackage{fontspec}
\newfontfamily\khmerfont[Script=Khmer,Scale=0.9]{Khmer OS}
\newfontfamily\khmerfonttt[Script=Khmer,Scale=0.9]{Khmer OS}
\newfontfamily\englishfont{Computer Modern Roman}
\usepackage{ucharclasses}
\setTransitionTo{Khmer}{\khmerfont}
\setTransitionFrom{Khmer}{\englishfont}
\usepackage{fancyvrb}
\begin{document}
\noindent What is wrong? តើមានអ្វីប្លែក? What is wrong? តើមានអ្វីប្លែក?
\begin{Verbatim}
What is wrong? តើមានអ្វីប្លែក? What is wrong? តើមានអ្វីប្លែក?
\end{Verbatim}
\end{document}


MWE2

\documentclass[11pt,a4paper]{article}
\usepackage{polyglossia}
\newfontfamily\khmerfont[Script=Khmer,Scale=0.9]{Khmer OS}
\newfontfamily\khmerfonttt[Script=Khmer,Scale=0.9]{Khmer OS}
\newfontfamily\englishfont{Computer Modern Roman}
\setdefaultlanguage[numerals=khmer]{khmer}
\setotherlanguage{english}
\usepackage{ucharclasses}
\setTransitionTo{Khmer}{\khmerfont}
\setTransitionFrom{Khmer}{\englishfont}
\usepackage{fancyvrb}
\begin{document}
\noindent What is wrong? តើមានអ្វីប្លែក? What is wrong? តើមានអ្វីប្លែក?
\begin{Verbatim}
What is wrong? តើមានអ្វីប្លែក? What is wrong? តើមានអ្វីប្លែក?
\end{Verbatim}
\end{document}


Khmer OS font http://www.khmeros.info/en/fonts

I get wrong output in both cases. At least in the english text they are more font family involved so you need a bit more sophisticated font changing. Try this instead:

\documentclass[11pt,a4paper]{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\newfontfamily\khmerfont[Script=Khmer,Scale=0.9]{Khmer OS}
\setdefaultlanguage[numerals=khmer]{khmer}
\setotherlanguage{english}
\usepackage{ucharclasses}
\makeatletter
\setTransitionTo{Khmer}{%
\global\let\orif@family\f@family
\khmerfont}
\setTransitionFrom{Khmer}{%
\fontfamily{\orif@family}\selectfont}
\makeatother
\usepackage{fancyvrb}
\begin{document}
\noindent What is wrong? តើមានអ្វីប្លែក ? What is wrong? តើមានអ្វីប្លែក?
\begin{Verbatim}
What is wrong? តើមានអ្វីប្លែក? What is wrong? តើមានអ្វីប្លែក?
\end{Verbatim}
\end{document}


If you have a dedicated tt-font for khmer you could add some test for the current family.

• Yes, you are right. Both MWE produce wrong output! However, your suggestion work only for MWE1. So I think the the polyglossia command \setdefaultlanguage cause this issue. – Say OL Jul 30 '15 at 1:51
• @SayOL: I don't know what you mean. My example uses polyglossia and produces the output in the picture. What is wrong with it? – Ulrike Fischer Jul 30 '15 at 6:10
• I still encountered error Package polyglossia Error: Please define \khmerfont with \newfontfamily.^^I\begin{Verbatim} – Say OL Jul 30 '15 at 9:42
• And the normal English text is not in Computer Modern Roman – Say OL Jul 30 '15 at 9:52
• I don't get errors in a current texlive. And for the font you can probably use \setmainfont{CMU Serif} but the default Latin Modern looks quite similar. – Ulrike Fischer Jul 30 '15 at 10:16