Why \numrange{number}{number} and \SIrange{number}{number}{unit} doesn't work as expected in math mode?

The commands \SIrange and \numrange are implemented such that they can only be used reliably in text mode: this relates to handling spaces if a line break occurs within the output of the commands. As such, they behaviour in math mode is undefined. (I am working on a new implementation of all of siunitx and this is one area to examine. At present I cannot be sure of whether v3 will be able to offer better outcomes here.)


enter image description here

\documentclass{scrartcl}
\usepackage[per-mode = fraction]{siunitx}
\sisetup{mode=text,range-phrase = {\text{~to~}}}
\begin{document}
  Text. \numrange{1}{3} experiments.\\[\baselineskip]
  Text. \SIrange{1}{5}{\kg} text.\\[\baselineskip]
  Text. $k = \numrange{1}{3}$ experiments text.\\[\baselineskip]
  Text. $v = \SIrange{1}{5}{\cubic\m\per\kg}$ text.\\[\baselineskip]
\end{document}

Tags:

Siunitx