# Use \num macro with \SI[parse-numbers=false]

It seems that when I apply the [parse-numbers=false] option to \SI, this also applies this option to the \num macro if it is in the number parameter of \SI. I realize that there is usually no need for this, but it is needed when the "number" portion of the \SI macro has other content in it, for instance a \frac (last example in MWE).

This is probably on purpose, but I feel that it should not be this way. I think of the \num macro separately from the \SI macro. In my opinion, an option should only apply to a macro that is given to.

## Question:

Is there a way I can setup the \siunitx macros so that \num does not inherit the options applied to \SI?

## Notes:

Possible workaround include

• It seems that if I use \num[parse-numbers=true], then things work, but I would prefer not to have to do that.
• Another option is to use $\frac{1}{\num{100000}}\,\si{\meter}$, but again I would prefer to use \SI[parse-numbers=false] macro for consistency instead of manual spacing.

## Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{xcolor}

\begin{document}
\textbf{OK}

Outside of \verb|\SI|: \num{100000}

In a \verb|\frac|: $\frac{1}{\num{100000}}$

Inside of \verb|\SI| without \verb|\num|: \SI{100000}{\meter}

\medskip
\textbf{Problem}

Inside of \verb|\SI[parse-numbers=false]| with \verb|\num|:
\SI[parse-numbers=false]{\color{red}\num{100000}}{\meter}
$\SI[parse-numbers=false]{\color{red}\frac{1}{\num{100000}}}{\meter}$
\end{document}

• Short of 'no', what would be an answer here? – Joseph Wright Jul 31 '16 at 9:15
• @JosephWright: That would be fine, but I just don't see why \num should inherit the options, nor a case where \num[parse-numbers=true] would be useful. – Peter Grill Jul 31 '16 at 11:45

This quick-and-dirty solution redefines \num in terms of the original definition from siunitx.sty to always include parse-numbers=true. To override this, you can still pass parse-numbers=false to the new \num.

\documentclass{article}
\usepackage{siunitx}
\usepackage{xcolor}

\ExplSyntaxOn

\RenewDocumentCommand \num { o m } {
\leavevmode
\group_begin:
\bool_set_false:N \l__siunitx_font_set_bool
\IfNoValueTF {#1} % <- changed
{ \keys_set:nn { siunitx } {parse-numbers=true} } % <- changed
{ \keys_set:nn { siunitx } {parse-numbers=true,#1} } % <- changed
\__siunitx_number_output:n {#2}
\group_end:
}

\ExplSyntaxOff

\begin{document}

\textbf{OK}

Outside of \verb|\SI|: \num{100000}

In a \verb|\frac|: $\frac{1}{\num{100000}}$

Inside of \verb|\SI| without \verb|\num|: \SI{100000}{\meter}

\medskip
\textbf{Problem}

Inside of \verb|\SI[parse-numbers=false]| with \verb|\num|:
\SI[parse-numbers=false]{\color{red}\num{100000}}{\meter}
$\SI[parse-numbers=false]{\color{red}\frac{1}{\num{100000}}}{\meter}$

\end{document}


• This works great. Any advantage of this solution compared to using \LetLtxMacro\OldNum\num and \RenewDocumentCommand{\num}{O{} m}{\OldNum[parse-numbers=true,#1]{#2}}? – Peter Grill Jul 31 '16 at 11:46
• @PeterGrill This is a very bad idea. See this question of mine. – Henri Menke Jul 31 '16 at 12:05
• Ok thanks. I don't quite understand Joseph's answer, but will follow the advice given and use your code. – Peter Grill Jul 31 '16 at 12:09
• Why not just \SI[quotient-mode = fraction, number-color = red]{1/10000}{\metre}? – Joseph Wright Jul 31 '16 at 13:55