[Tex/LaTex] Font settings in siunitx package

fontssiunitx

I have changed the whole font settings by using fontspec package.

\documentclass{article}

\usepackage{fontspec}
\setmainfont{Source Sans Pro}[
UprightFont     =Source Sans Pro-Light,
BoldFont        =Source Sans Pro-Semibold,
ItalicFont      =Source Sans Pro-Light Italic,
BoldItalicFont  =Source Sans Pro-Semibold Italic]

\usepackage{siunitx}

\begin{document}

 5 km \SI{5}{\km} $\SI{5}{\km}$ $5\text{km}$
\end{document}

enter image description here

But when I type inside \SI environment, I want the font to be the same as in math mode. How can I achieve this?

Best Answer

The \SI macro in siunitx has optional parameters (list of key-value pairs). One of the keywords is 'mode', with possible values 'text', 'math'. You may have to set 'detect-mode' to false in \sisetup.
If you want to always use the math fonts for your measures/units, then you can use

\sisetup{mode=math}

This is explained in the documentation of the siunitx package. You can also select the math fonts with other package macros. Full exemple (note that I use LuaLatex):

\documentclass[a4paper,article,openany,12pt]{memoir}
\usepackage{lipsum}
\usepackage{mathpazo} %shows the differences between math and text mode better
\usepackage{fontspec}
\usepackage{siunitx}


\begin{document}
\sisetup{mode=math}    

\SI[mode=text]{9.8}{\kilogram\metre\per\second\squared}\\
\SI{9.8}{\kilogram\metre\per\second\squared}\\
$\SI{9.8}{\kilogram\metre\per\second\squared}$

\end{document}