The attached example (not really an MWE) explains the problem better than I probably can here:
% !TeX program = xelatex
\documentclass{scrreprt}
\usepackage{siunitx}
\sisetup{%
% detect-mode,
% detect-all,
% detect-display-math,
% math-rm=\mathnormal,
}%
\usepackage{unicode-math}
\setmainfont[Numbers=OldStyle,Color=2244FF]{TeX Gyre Pagella}
\setmathfont[Numbers=Lining,Color=FF4422]{TeX Gyre Pagella Math}%lining as 'opposite' of OldStyle
\linespread{1.3}
\begin{document}
Wanted behaviour:
Text-Style numbers: 123456789. Math-Style numbers: \(123456789\).
In Display-Math, only the math font should be used. This works:
\begin{equation}
f(x) = 23.1(2) \times 10^{-2} x^2
\end{equation}
However, \textit{siunitx} does not detect the (surrounding) math font and sets its digits using the text font. Triggering \textit{detect-all} does not change this either:
% \sisetup{detect-all}
\begin{equation}
f(x) = \num{23.1(2)e-2} x^2
\end{equation}
Even explicitly requesting math-font does not seem to work:
\begin{equation}
\num{10} \quad \SI{20}{\newton} \quad \SI[mode=text]{30}{\newton} \quad \SI[mode=math]{40}{\newton} \quad \SI[number-mode=math]{50}{\newton}.
\end{equation}
Does not work outside of math mode either. These are expected to use math mode:
\SI[mode=math]{40}{\newton} \quad \SI[number-mode=math]{50}{\newton}.
This approach seems to work, since it will always use the math-font for its numbers and picks the text-font for its units, \textbf{as long as we are in math-mode}:
\sisetup{number-math-rm=\mathnormal,unit-math-rm=\mathrm,detect-mode}
\(\SI{40}{\newton}\) \quad \SI{40}{\newton} \quad \(\num{45.2(1)e-2}\) \quad \num{45.32(12)e-27}
However, if we try to replicate the same for text-mode, an error is thrown:
% \sisetup{number-text-rm=\mathnormal,unit-text-rm=\textrm}
% \(\SI{40}{\newton}\) \quad \SI{40}{\newton} \quad \(\num{45.2(1)e-2}\) \quad \num{45.32(12)e-27}
\vspace{2\baselineskip}
Also, if we use \textit{mathrm} instead of \textit{mathnormal}, it no longer works, and \textit{siunitx} picks the text-font for its numbers again. I do not know the difference here and why it does this:
\sisetup{number-math-rm=\mathrm}
\(\SI{40}{\newton}\) \quad \SI{40}{\newton} \quad \(\num{45.2(1)e-2}\) \quad \num{45.32(12)e-27}
\end{document}
These two (Number 1 and Number 2) questions are similiar, but mode=text
does not do the trick, since then the numbers are set in OldStyle
. Inversely, mode=math
sets the units in (italic) math font.
This solution is looking for the same thing, but it seems different, since they don't use fontspec
/ unicode-math
.
I can stick with
\sisetup{number-math-rm=\mathnormal}
and it works for now, but it seems to be a very narrow solution that will fall apart quickly, once more sophisticated typesetting occurs. Is there a better solution?