# \text<language> (polyglossia) changes font

I'm using polyglossia to switch between languages in my documents and fontspec to define various fonts. The combination gives me the following problem.

An MWE:

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{dutch}
\usepackage{fontspec}
\newfontfamily\mono{Latin Modern Mono}[Scale=2] % scaled for visibility
\begin{document}
foo\mono bar foo\textdutch{bar}
\end{document}


Result:

Why isn't the second "bar" typeset in the current font family (\mono)? Is this due to a feature in polyglossia that supports different fonts for different languages? If so, how do I redefine \text<language> so that it uses the current font, or: How do I detect the current font and then activate it within \text<language>{<here>}? Or am I plainly doing something wrong?

Update: Answered by Ulrike Fischer, see below, but I have a persistent problem and a solution:

Another not-so-MWE to illustrate what I'm doing wrong.

\documentclass[]{memoir}

\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{dutch}
\newcommand*\dutchfont{} % the solution to the first problem, thanks to Ulrike Fischer

\usepackage{fontspec}
\newfontfamily\titlefont{Latin Modern Mono}[Scale=2] % scaled for visibility

\renewcommand*{\maketitlehooka}{\titlefont} % this hook executes just before \thetitle is printed

\title{fo\textdutch{ob}ar}

\begin{document}

\sffamily % <=== disable this and the thanks have the desired font
% \fontfamily\sfdefault\selectfont % this works correctly
\maketitle

\end{document}


It causes the same incorrect font selection when the language is changed. In this MWE, the text foobar is in english and in a font selected with \titlefont, but the -ob- in the middle is in dutch. This language change results in a font change as well if \sffamily (and probably any other \..family command) has been called before the text. I used \sffamily before \maketitle to typeset the various title page elements in sans serif. Any text containing another font than default and language changes reverts to the default sans serif font, based on my experience. Using \fontfamily\sfdefault\selectfont instead of \sffamily does work without problems. Why is the use of \sffamily incorrect here?

• In order to support different fonts for different languages (as a font might not have support for an alphabet), polyglossia applies \<language>font if defined or else \normalfont. There's obviously space for improvement here. – egreg Mar 24 '15 at 21:09
• @egreg - What I suspected... Is it possible to easily define \<language>font to always be the current font as soon at it is used? I know the fonts I use are compatible with the languages I use. IMHO there should be a package or language option in polyglossia that disables the font resetting. E.g.: \newfontfamily\<language>font{\font} – Erik Mar 24 '15 at 21:15
• Er, no! If the current font is \cyrillicfont you don't want that switching to Dutch keeps it. – egreg Mar 24 '15 at 21:16
• @egreg - I know that should not happen! But I know the fonts I use in my document are compatible with the languages I use, so polyglossia should act dumb in my case and use the current font. – Erik Mar 24 '15 at 21:20
• The macros don't just change the font family, but also set the necessary attributes; for example, Romanian and Turkish need activation of the corresponding language tags. – egreg Mar 24 '15 at 21:28

You can add a definition for \dutchfont:

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{dutch}
\newcommand\dutchfont{}
\usepackage{fontspec}
\newfontfamily\mono{Latin Modern Mono}[Scale=2] % scaled for visibility
\begin{document}
foo\mono bar foo\textdutch{bar}
\end{document}


But I would prefer babel over polyglossia.

# Edit

Regarding the second example: polyglossia redefines \sffamily to store the "familytype":

 \csgappto{sffamily }{\def\familytype{sf}}


and it uses this familytype to decide if and to which fontfamily it should switch at language boundaries. It is imho difficult to disable this system and polyglossia only knows three standard font families. Also there is no concept of "scriptfamilies", so one can't disable font switches between english and dutch but preserve them between dutch and cyrillic.

The general rules for fonts that should survive language boundaries are: Use the standard families and the standard commands like \bfseries or \large and not settings in fontspec options like [Scale=2]:

\documentclass[]{memoir}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{dutch}

\usepackage{fontspec}
\newcommand\titlefont{\sffamily\Huge} % scaled for visibility

\renewcommand*{\maketitlehooka}{\titlefont} %

\title{fo\textdutch{ob}ar}

\begin{document}

\sffamily
\maketitle

\end{document}


If you want to use a special font somewhere one could probably hide it as a special variant in one of the standard families to fool polyglossia.

• Ah, so this does select the empty \dutchfont everytime, so it doesn't change the font at all? I hadn't thought of not-defining \<lang>font... – Erik Mar 24 '15 at 21:34
• I still have the problem from my original question, despite your solution. I'm still trying to find out how I can reproduce it with an MWE, but my document is already quite complex, unfortunately. – Erik Mar 24 '15 at 22:56
• I've updated the question with a more advanced MWE that illustrates my persiting problem. – Erik Mar 25 '15 at 0:01
• @Erik: I have edited the answer. – Ulrike Fischer Mar 25 '15 at 9:51