TransWikia.com

unicode-math and siunitx: how to make num recognize text or math mode

TeX - LaTeX Asked on March 25, 2021

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 ?

One Answer

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}

Correct answer by Mico on March 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP