# possible side effect of siunitx, tgheroes, familydefault combination

I use the following code to change the font to sans serif. I would like to use TeX Gyre Heroes and copied the code snipped from tug.dk.

\documentclass{article}

\usepackage{tgheros}
\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif
\usepackage[T1]{fontenc}

\usepackage{siunitx}

\begin{document}

2 K, 2 Kelvin, \SI{2}{K}, \SI{2}{Kelvin}

\end{document}


However, the result is not as expected:

The fonts are slightly different. Leaving the \usepackage{tgheroes} out leads to

which seems okay. Leaving the \renewcommand... out also seems to work, now with a serif font.

Is this a side effect of a combination of all 3 (siunitx, tgheroes, renew...)?

Declaring \renewcommand{\familydefault}{\sfdefault} doesn't change the \mathsf font; siunitx realizes that it's in a sans serif context and so uses \mathsf.

\DeclareMathAlphabet{\mathsf}{OT1}{\sfdefault}{m}{n}
\SetMathAlphabet{\mathsf}{bold}{OT1}{\sfdefault}{b}{n}

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tgheros}
\usepackage{siunitx}

\DeclareMathAlphabet{\mathsf}{OT1}{\sfdefault}{m}{n}
\SetMathAlphabet{\mathsf}{bold}{OT1}{\sfdefault}{b}{n}

\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif

\begin{document}

2 K, 2 Kelvin, \SI{2}{K}, \SI{2}{Kelvin}

\bfseries
2 K, 2 Kelvin, \SI[detect-weight]{2}{K}, \SI[detect-weight]{2}{Kelvin}

\end{document}


The second line is just to see that the right font is chosen in the (unlikely) case you need detect-weight.

Alternatively, add the option mode=text (I wouldn't recommend it, though):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tgheros}
\usepackage{siunitx}

\sisetup{mode=text}

\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif

\begin{document}

2 K, 2 Kelvin, \SI{2}{K}, \SI{2}{Kelvin}

\bfseries
2 K, 2 Kelvin, \SI[detect-weight]{2}{K}, \SI[detect-weight]{2}{Kelvin}

\end{document}