1

In the following MWE \num displays numbers regardless of the mode. Before the \sisetup it always uses the main font and after it always uses the math font

\documentclass{minimal}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Adventor}
\setmathfont{Asana Math}
\usepackage{siunitx}
\begin{document}
\obeylines
text: 1.23 = \num{1.23}
math: \(1.23 = \num{1.23}\)
\sisetup{number-math-rm=\ensuremath}
text: 1.23 = \num{1.23}
math: \(1.23 = \num{1.23}\)
\end{document}

Here is the output

enter image description here

I would like to have the same font for the numbers on each line. How can I make \num use the font according to the mode ?

2
  • You wrote, "I would like to have the same font for the numbers on each line". Which font do you want -- the text font or the math font?
    – Mico
    Dec 19, 2020 at 7:13
  • 1
    the text font in text mode and the math font in math mode Dec 19, 2020 at 7:25

1 Answer 1

3

You may achieve your formatting goal by adding the option detect-mode to the arguments of \sisetup. Observe that this affects not only the apperance of the argument of \num but also that of the first argument of \SI; I trust that this is what you would want.

The following example uses oldstyle numerals for the text font in order to make the difference between the text-mode and math-mode numerals more obvious.

enter image description here

\documentclass{article}  % Please don't use the 'minimal' document class.
\usepackage{unicode-math}
\setmainfont{TeX Gyre Adventor}[Numbers=OldStyle]
\setmathfont{Asana Math}

\usepackage{siunitx}
\sisetup{detect-mode,number-math-rm=\ensuremath}

\begin{document}
\begin{tabular}{lll}
text mode &   1.23 = \num{1.23}   &   \SI{123}{\meter} \\
math mode & \(1.23 = \num{1.23}\) & \(\SI{123}{\meter} \)
\end{tabular}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .