Consider this MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A, T1]{fontenc}
\usepackage{amsmath}
\usepackage{lmodern}
\usepackage{siunitx}
\usepackage{mathpazo}
\usepackage{trace}
% https://tex.stackexchange.com/questions/19255/using-declaremathversion
% note: mathpazo.sty, lmodern.sty overrides normal, bold!
%%% New math versions
\DeclareMathVersion{lmnormal}
\DeclareMathVersion{lmbold}
\DeclareMathVersion{mpazonormal}
\DeclareMathVersion{mpazobold}
\newcommand\lmmath{\mathversion{lmnormal}}
\newcommand\lmboldmath{\mathversion{lmbold}}
\newcommand\mpmath{\mathversion{mpazonormal}}
\newcommand\mpboldmath{\mathversion{mpazobold}}
%%% Math symbol fonts
% lmodern.sty
\SetSymbolFont{operators} {lmnormal}{OT1}{lmr} {m}{n}
\SetSymbolFont{letters} {lmnormal}{OML}{lmm} {m}{it}
\SetSymbolFont{symbols} {lmnormal}{OMS}{lmsy}{m}{n}
\SetSymbolFont{largesymbols}{lmnormal}{OMX}{lmex}{m}{n}
\SetSymbolFont{operators} {lmbold} {OT1}{lmr} {bx}{n}
\SetSymbolFont{letters} {lmbold} {OML}{lmm} {b}{it}
\SetSymbolFont{symbols} {lmbold} {OMS}{lmsy}{b}{n}
\SetSymbolFont{largesymbols}{lmbold} {OMX}{lmex}{m}{n}
% add for \SI?
\SetSymbolFont{upright} {lmnormal}{OT1}{lmr} {m}{n}
% mathpazo.sty
\SetSymbolFont{operators} {mpazonormal} {OT1}{ppl}{m}{n}
\SetSymbolFont{upright} {mpazonormal} {OT1}{zplm}{m}{n}
\SetSymbolFont{letters} {mpazonormal} {OML}{zplm}{m}{it}
\SetSymbolFont{symbols} {mpazonormal} {OMS}{zplm}{m}{n}
\SetSymbolFont{largesymbols}{mpazonormal} {OMX}{zplm}{m}{n}
\SetSymbolFont{operators} {mpazobold} {OT1}{ppl}{b}{n}
\SetSymbolFont{upright} {mpazobold} {OT1}{zplm}{b}{n}
\SetSymbolFont{letters} {mpazobold} {OML}{zplm}{b}{it}
\SetSymbolFont{symbols} {mpazobold} {OMS}{zplm}{b}{n}
\SetSymbolFont{largesymbols}{mpazobold}{OMX}{zplm}{m}{n}
%%% Math alphabets, at most 16 families
% lmodern.sty
\SetMathAlphabet{\mathbf}{lmnormal}{OT1}{lmr}{bx}{n}
\SetMathAlphabet{\mathsf}{lmnormal}{OT1}{lmss}{m}{n}
\SetMathAlphabet{\mathit}{lmnormal}{OT1}{lmr}{m}{it}
\SetMathAlphabet{\mathtt}{lmnormal}{OT1}{lmtt}{m}{n}
\SetMathAlphabet{\mathbf}{lmbold} {OT1}{lmr}{bx}{n}
\SetMathAlphabet{\mathsf}{lmbold} {OT1}{lmss}{bx}{n}
\SetMathAlphabet{\mathit}{lmbold} {OT1}{lmr}{bx}{it}
\SetMathAlphabet{\mathtt}{lmbold} {OT1}{lmtt}{m}{n}
% mathpazo.sty
\SetMathAlphabet{\mathit}{mpazonormal} {OT1}{ppl}{m}{it}
\SetMathAlphabet{\mathit}{mpazobold} {OT1}{ppl}{b}{it}
\SetMathAlphabet{\mathbf}{mpazonormal} {OT1}{zplm}{b}{n}
\SetMathAlphabet{\mathbold}{mpazonormal} {OML}{zplm}{b}{it}
% https://tex.stackexchange.com/questions/35287/sans-serif-font-with-siunitx
% \SI % "By default, all text is typeset in the current upright, serif math font."
% \sisetup{detect-all} %
\begin{document}
\fontfamily{lmr}\selectfont% change text font to lmodern
\renewcommand{\rmdefault}{lmr}%
% \sisetup{detect-all}
\makeatletter
This is Mathpazo font \math@version. $a^2 + b^2 = c^2; \mathrm{ms}$. $20$ ms, \fbox{\SI{20}{\meter\per\second}}
\mpmath
\def\defaultscriptratio{.76}
\def\defaultscriptscriptratio{.6}
% \sisetup{detect-all}
This is Mathpazo font \math@version. $a^2 + b^2 = c^2; \mathrm{ms}$. $20$ ms, \fbox{\SI{20}{\meter\per\second}}
\lmmath
\def\defaultscriptratio{.7}
\def\defaultscriptscriptratio{.5}
% \sisetup{detect-all}
This is LModern font \math@version. $a^2 + b^2 = c^2; \mathrm{ms}$. $20$ ms, %
% \traceon%
\fbox{\SI{20}{\meter\per\second}}%
% \traceoff
\makeatother
\end{document}
As is, the output with pdflatex
is:
The first two \SI
are typeset with Mathpazo as expected (the first time because the math setup "leaks" since mathpazo
is loaded last; the second time because \mpmath
->\mathversion{mpazonormal}
is explicitly requested). But once \mathversion{lmnormal}
is requested, it has no effect on \SI
- even if the \mathrm
in the equation (the equivalent of \mathup for upright text in math mode) is acknowledged (since it is typeset with the lmodern
font).
If I enable all of the \sisetup{detect-all}
, then the output is this:
Now all of the \SI
are typeset in lmodern
- even if I expect the first two to be typeset with mathpazo
?!
So what do I need to do, so when I switch the math font, also the \SI
command is typeset with the same font?