2

Is there an easier way to get numbers in $\num{}$ to be in the same font as normal text than using $\text{\num{}}$?

\documentclass[varwidth]{standalone}

\usepackage[sfdefault]{overlock}
\usepackage[detect-all]{siunitx}

\begin{document}

num in maths mode: $\num{1200}$

num in text in maths mode: $\text{\num{1200}}$

\end{document}

I am using pdflatex and I want all the numbers in maths mode to be in overlock font, so they are consistent with the rest of the document.

James
  • 59

2 Answers2

3

You need the option mode=text if you want \num to use the text font. But if you really want all number to use the same font you should better reset the math font so that it works also outside \num:

\documentclass[varwidth]{standalone}

\usepackage[sfdefault]{overlock}
\usepackage{siunitx}
 \DeclareSymbolFont{numbers}{\encodingdefault}{\sfdefault}{\mddefault}{n}%
 \DeclareMathSymbol{0}\mathalpha{numbers}{"30}%
  \DeclareMathSymbol{1}\mathalpha{numbers}{"31}%
  \DeclareMathSymbol{2}\mathalpha{numbers}{"32}%
  \DeclareMathSymbol{3}\mathalpha{numbers}{"33}%
  \DeclareMathSymbol{4}\mathalpha{numbers}{"34}%
  \DeclareMathSymbol{5}\mathalpha{numbers}{"35}%
  \DeclareMathSymbol{6}\mathalpha{numbers}{"36}%
  \DeclareMathSymbol{7}\mathalpha{numbers}{"37}%
  \DeclareMathSymbol{8}\mathalpha{numbers}{"38}%
  \DeclareMathSymbol{9}\mathalpha{numbers}{"39}%

\begin{document}

num in maths mode: 

$1234567890^{1234567890} \num{1200}$

num in text in maths mode: 1234567890

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • I like mode=text. It's really easy to miss its one mention in the siunitx manual. I can set it globally usepackage[mode=text]{siunitx} or locally \num[mode=text]{1200}. It doesn't work if I set detect-all, though, but I guess I don't really need it. – James Mar 28 '18 at 20:47
  • detect-all also contains detect-mode and so switches mode. The problem with mode=text is that it won't change only the number but also the units which is perhaps not what you want. – Ulrike Fischer Mar 28 '18 at 20:52
1

My comment analytically:

\documentclass{article}

\usepackage[sfdefault]{overlock}
\usepackage[detect-all]{siunitx}
\let\oldnum\num
\makeatletter
\def\num{\@ifnextchar[{\ReadOpt}{\ReadMand}}
\def\ReadOpt[#1]#2{\text{\oldnum[#1]{#2}}}
\def\ReadMand#1{\text{\oldnum{#1}}}
\makeatother
\begin{document}

\Huge
num in maths mode: $\oldnum{1200}$

num in text in maths mode: $\oldnum[scientific-notation=true]{1200}$

New:

num in maths mode: $\num{1200}$

num in text in maths mode: $\num[scientific-notation=true]{1200}$

\end{document}

Output:

enter image description here

koleygr
  • 20,105