I'm trying to set up a document with Polyglossia/XeLaTeX, which should be mostly in Hebrew, with some English excerpts. However, I can't get fontspec to use the correct English font for anything other than the main (roman) font – it instead uses the Hebrew-specified fonts.
Here is my minimal example file:
\documentclass{article}
\usepackage{fontspec}
\usepackage[a4paper]{geometry}
\makeatletter
\setmainfont[Language=English,Script=Latin]{Nimbus Roman No9 L}
\setsansfont[Language=English,Script=Latin]{Nimbus Sans L}
\setmonofont[Language=English,Script=Latin]{Nimbus Mono L}
\newfontfamily\hebrewfont[Language=Hebrew,Script=Hebrew,Scale=3.0]{Frank Ruehl CLM}
\newfontfamily\hebrewfontsf[Language=Hebrew,Script=Hebrew,Scale=3.0]{Nachlieli CLM}
\newfontfamily\hebrewfonttt[Language=Hebrew,Script=Hebrew,Scale=3.0]{Miriam Mono CLM}
\makeatother
\usepackage{xunicode}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\begin{document}
בדיקה, באיזה פונט זה יוצג \textenglish{\ttfamily{Hello, World!}}.
\begin{english}
Hello, \sffamily{Sans}, \ttfamily{Mono}
\end{english}
\end{document}
Hebrew fonts scale to better see outcome. The result looks like this:
As you can see, only the default (roman) English font is used, while all other English text uses the scaled (Hebrew) fonts. I have tried with or without Language/Script specifications, but results are always the same.
Edit: Changing it so English is default and Hebrew is other seems to fix it, but this is far from ideal – the document would be 95% Hebrew at least. But maybe it hints towards the root cause?
Edit2: Changing default language to English also has the undesired outcome of making it so Hebrew Sans-Serif and Typewriter/Mono text disappears completely.
Edit3: The proposed fix in Ulrike Fischer's answer has the side effect of making it so after the first use of \textenglish
, all section titles are wrongly rendered using the English fonts:
\documentclass{article}
\usepackage{fontspec}
\usepackage[a4paper]{geometry}
\usepackage{xunicode}
\usepackage{polyglossia}
\setmainfont{DejaVu Sans}
\setsansfont{DejaVu Sans}
\setmonofont{DejaVu Sans}
\newfontfamily\englishfont{TeX Gyre Termes}
\newfontfamily\englishfontsf{TeX Gyre Heros}
\newfontfamily\englishfonttt{TeX Gyre Cursor}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\makeatletter
\addto\inlineextras@english{\xpg@set@normalfont{english}}
\addto\blockextras@english{\xpg@set@normalfont{english}}
\makeatother
\begin{document}
\section{חלק ראשון}
נכתוב באנגלית \textenglish{Hello, World!}
ומעכשיו כל הכותרות לא יופיעו
\section{חלק שני}
הכותרת לא מופיעה, אבל הטקסט כן.
\end{document}
Different fonts will have different behaviors – the previously used Nimbus fonts only show spaces, while the Liberation ones show empty squares – I guess it has to do with what those fonts have in the Hebrew glyph locations.
Best Answer
hebrew is your main language and so it would feel like a hack to set english to the default language only to get the fonts right.
Imho there is a bug in polyglossia, it doesn't seem to reset the fonts correctly.
The following seems to work to correct the problem. As I don't have your fonts I had to change them.
Edit
As noted in the comment my first solution broke the fonts in \section (and other places). The reason is that
\xpg@set@normalfont
redefines\normalfont
globally. The following correct this, but it could have other side effects. Also it is more a work-around than a solution.On the whole I think that the font changing commands in polyglossia are not symmetric. There is code for the case "latin=main, hebrew=other" but not the other way round.