2

Here is the MWE:

\documentclass{article}
\usepackage{siunitx}
\usepackage[default]{lato} %Any other font can be used.
\newcommand\mynum[1]{\num[group-separator={,},group-minimum-digits=4]{\the\numexpr(#1)\relax}}
\begin{document}
\Huge  %Just to get the large sized letters

1200 %This produces text in lato font

\mynum{1200} %This is not lato font. I don't know what font is it

\end{document}

Now, the \mynum command groups the digits correctly but does not respect the font --- lato. This is true whether I compile using latex or xetex.

How do I make \mynum command respect the choice of font?

4
  • 1
    Wouldn't you want \sisetup{detect-all, group-separator = {,}, group-minimum-digits = 4} and then use \num{1200}?
    – Manuel
    Sep 17, 2016 at 12:21
  • 1
    The outcome is exactly as it should be: try $\mathsf{1{,}200}$ in the same document (which is what siunitx is doing, in the end).
    – Joseph Wright
    Sep 17, 2016 at 12:53
  • @JosephWright With the small problem that the comma is not \mathsf
    – egreg
    Sep 17, 2016 at 13:03
  • Using commas or dots as group separators is explicitly agaist the SI rules. IMHO, it makes no sense to use an SI package to go against fundamental SI principles. Four-digit numbers need not be separated, since it arguably makes reading harder. As for the main problem, it is as Runar has written. May 25, 2022 at 21:14

1 Answer 1

5

You might be looking for the option detect-all, see section 5.1 in the documentation for siunitx.

Note that you can always locate the documentation using the command-line/terminal by writing texdoc siunitx, and that works for any package. The documentation is also available at http://ctan.org/pkg/siunitx

Note that you probably want some consistent settings for your typesetting, including numbers. Therefore, assigning your options for siunitx globally would be better than using the settings for only that numbers. Of course, you can use your macro for this, but I really don't see much point in it, as the macro \num{1200} would be plenty.

Therefore, using the command \sisetup{options} is advisable, as both Mico and egreg has pointed out.

Output

enter image description here

Code

\documentclass{article}
\usepackage{siunitx}
\usepackage[default]{lato} %Any other font can be used.
\sisetup{
  detect-all,
  group-separator={,},
  group-minimum-digits=4,
  }
\newcommand\mynum[1]{\num{\the\numexpr(#1)\relax}}
\begin{document}
\Huge  %Just to get the large sized letters

1,200 %This produces text in lato font

\mynum{1200} %Also produces the text in current font

\num{1200}% The same as above, but now extra macro-definition is needed.

\end{document}
1
  • 1
    \sisetup{detect-all} would be better, in my opinion.
    – egreg
    Sep 17, 2016 at 12:50

You must log in to answer this question.

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