# Why does \setdefaultlanguage modify my fontfamily?

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=new]{german}

\renewcommand*\familydefault{\sfdefault}
\begin{document}
test
\end{document}


test is written in \rmfamily not \sffamily. But when you kill the third line with \setdefaultlanguage the correct font is used.

Why? What is behind that?

• I don't have a good "why", but I have a good workaround. Replace your \renewcommand* with \newfontfamily\germanfont{Arial} or whatever other font you want. See section 4 of the polyglossia documentation. – Mike Renfro Jan 26 '16 at 3:21
• The language file sets fontsetup=true which triggers Polyglossia's automatic font configuration. – cfr Jan 26 '16 at 3:46
• @MikeRenfro That's not a good workaround. All kinds of things rely on \normalfont and this will break all of them. – cfr Jan 26 '16 at 3:50
• If you want to set the default font for the document you really need \setmainfont or similar. – cfr Jan 26 '16 at 3:51
• @cfr Can I loosely define "good" as "fixes the symptom for this MWE", and plead ignorance beyond that? – Mike Renfro Jan 26 '16 at 3:53

This is arguably a bug in polyglossia. Examining the polyglossia.sty one sees it has a concept of \familytype. When the user has selected a language, the font selection is influenced by it this tests the value of \familytype.

There is some code to set during package loading \familytype:

\expandafter\ifx\familydefault\sfdefault
\def\familytype{sf}
\else\expandafter\ifx\familydefault\ttdefault
\def\familytype{tt}
\else
\def\familytype{rm}
\fi\fi


This has two issues:

1. arguably it should be done at begin document, not during package loading, to allow user's redefinitions of \familydefault anywhere in the preamble (and personally I would wish to also be able to define it in the document body, it is not immediately clear to me why polyglossia needs its own \familytype rather than \familydefault, restricting the efficiency of the latter).

2. the \expandafter\ifx\familydefault constrains user's definition of \familydefault to be done in a certain way, actually it constrains it to be in the style of the OP: \renewcommand*\familydefault{\sfdefault}. In particular \let\familydefault\sfdefault would lead to unexpected outcome. But ideally the full expansion should be used.

Thus there are two work-arounds: first one is to do \renewcommand*\familydefault{\sfdefault} before loading polyglossia, alternative is to do \def\familytype{sf} at the end of the preamble.

First method:

\documentclass{article}

\renewcommand*\familydefault{\sfdefault}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=new]{german}
\def\test{test}
%\def\familytype{sf}
% \tracingmacros1
\begin{document}
\test
\end{document}
% Local Variables:
% TeX-engine: xetex
% End:


Second method:

\documentclass{article}

%\renewcommand*\familydefault{\sfdefault}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=new]{german}
\def\test{test}
\def\familytype{sf}
% \tracingmacros1
\begin{document}
\test
\end{document}
% Local Variables:
% TeX-engine: xetex
% End:


Adding \AtBeginDocument{\normalfont} in the preamble anywhere after \setdefaultlanguage will also suffice as a workaround

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=new]{german}
\AtBeginDocument{\normalfont}

\renewcommand*\familydefault{\sfdefault}
\begin{document}
test
\end{document}