[Tex/LaTex] siunitx fonts in math and text mode always identical

fontspecsiunitxunicode-math

I am stuck with configuring siunitx to my liking.

Using LuaLaTex and fontspec I want siunitx to print numbers and units in normal text font when in text. When in math mode I want it to print numbers in serif math font and units in sans serif text font.
No matter what I change, it always affects both typesettings, inside and outside of math mode.

Her is my MWE:

\documentclass[a4paper, 10pt, german]{scrartcl}

\usepackage{polyglossia}
    \setdefaultlanguage[spelling=new]{german}           
    \setotherlanguage{english}

\usepackage{fontspec}
    \setmainfont{Tex Gyre Heros}[Scale=0.91]            
    \setsansfont{Tex Gyre Heros}[Scale=0.93, LetterSpace=0, WordSpace=0.96]
    \setmonofont{TeX Gyre Cursor}[Scale=0.95]
\usepackage{microtype}  



\usepackage{mathtools}
\usepackage{unicode-math}

\usepackage{siunitx}
            \sisetup{%detect-all,
                    math-rm=\mathsf,
                    text-rm=\sffamily,
                    binary-units=true, %use binary units
                    per-mode=fraction, %\per inserts fraction
                    output-decimal-marker={,} %comma as decimal sperator
                    }

\begin{document}

In text I want siunitx to print sans serif text font: 1000kV, \SI{1000}{\kilo\volt}

In math mode I want it to print numbers in serif math font: $1000kV, \SI{1000}{\kilo\volt}$

\end{document}

Which gives this output:

enter image description here

What am I doing wrong here?

Best Answer

Here's a solution that uses (a) sans-serif glyphs for both numbers and units if \SI is encountered in text mode and (b) serif glyphs for both numbers and units if \SI is encountered in math mode. This may be achieved by setting the siunitx options math-rm=\symup and detect-all.

enter image description here

\documentclass[a4paper, 10pt, german]{scrartcl}

\usepackage{fontspec}
    \setmainfont{Tex Gyre Heros}[Scale=0.91]
\usepackage{unicode-math}
    \setmathfont{Latin Modern Math}

\usepackage{polyglossia}
    \setdefaultlanguage[spelling=new]{german}
    \setotherlanguage{english}

\usepackage{microtype}
\usepackage{mathtools}

\usepackage{siunitx}
\sisetup{math-rm=\symup,detect-all}

\begin{document}

Text mode: 1000\,kV, \SI{1000}{\kilo\volt} --- sans serif text font

Math mode: $1000\,\symup{kV}$, $\SI{1000}{\kilo\volt}$ --- serif math font

\end{document} 
Related Question