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?

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


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} 

Replay

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}

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

Category: spacing Time: 2016-07-31 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.166 (s). 12 q(s)