Wrong font in header/footer using greek and verbatim
[I am rewriting here a bug from the old polyglossia project, hoping that it gets some attention.]
If I use greek as the main language, and have a verbatim environment that is more than one page long, then the header and footer of the page containing the verbatim environment (more exactly: of the page(s) that end inside the verbatim environment) use the monospaced font instead of the normal font.
The problem goes away if I don't use greek as the main language (I tried french or no language at all), or if I use xgreek instead of polyglossia.
Here is a test case:
\documentclass[a4paper, 11pt]{article}
\usepackage{fontspec}
\setmainfont{Constantia}
\setmonofont{Consolas}
%\usepackage{xgreek}
\usepackage{polyglossia}
\setmainlanguage{greek}
\setotherlanguage{english}
\begin{document}
Hello
\begin{verbatim}
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
\end{verbatim}
\end{document}
The issue here is that the verbatim text is in Greek, but you haven't defined a greek mono font (via \greekfonttt).
% !TeX TS-program = xelatex
\documentclass[a4paper, 11pt]{article}
\usepackage{polyglossia}
\setmainlanguage{greek}
\setotherlanguage{english}
\setmainfont{Constantia}
\setmonofont{Consolas}
\newfontfamily\greekfonttt{Consolas}%% <-- LOOK HERE!
\pagestyle{headings}
\begin{document}
\section{Title}
Hello
\begin{verbatim}
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
Hello.
\end{verbatim}
\end{document}
I am not sure whether polyglossia should set \greekfonttt here itself if not defined or if this just needs documentation.
This also happens without verbatim. Simpler testcase:
% !TeX TS-program = xelatex
\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{greek}
\setmainfont{Constantia}
\setmonofont{Consolas}
% Commenting this out cures it:
%\newfontfamily\greekfonttt{Consolas}
\pagestyle{headings}
\begin{document}
\section{Title}
\ttfamily
Hello.
\end{document}
And it does not only happen with Greek. With latin script, there is not even a workaround:
% !TeX TS-program = xelatex
\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{english}
\setmainfont{Constantia}
\setmonofont{Consolas}
%\newfontfamily\englishfonttt{Consolas}
\pagestyle{headings}
\begin{document}
\section{Title}
\ttfamily
Hello.
\end{document}
Seems the \*familylatin commands are to blame.
I have a patch in the pipe for 1.46. The solution here is to define default font families and use that rather than \<xx>familylatin.
92cdeb3 reintroduced this problem, but only for non-Latin scripts, and as of 8ef31ad the problem occurs with Latin scripts again. The problem is that the font family in \normalfont is determined by \xpg_select_fontfamily:n, which chooses the family according to \familytype, which might not be the default family, as in the example here.
I think this is fixed with bd7e090, but we should probably test that.
Seems fixed.