[Tex/LaTex] SIrange typeset different in text and math mode

siunitx

I observe a difference in the dashes typesetting when using SIrange in text or math modes. Any idea of why this happens?
Here's the MWE:

\documentclass{article}
\usepackage{siunitx}
\sisetup{
    range-phrase= -}

\begin{document}
    \SIrange{e-12}{e-10}{\second}
    $\SIrange{e-12}{e-10}{\second}$
\end{document}

This is how it looks:

enter image description here

Best Answer

As written in my comment, you can tell LaTeX to behave differently if you are inside or outside the math mode using the TeX command \if<>\else<>\fi; specifically using the conditional form:

\ifmmode<expression inside math>
\else
 <expression outside math>
\fi

So if this code is applied to your MWE:

\documentclass{article}
%
\usepackage{siunitx}
\sisetup{range-phrase=%
 \ifmmode\mathbin{-}
 \else
  \thinspace\textendash\thinspace
 \fi%
}
%
\begin{document}
%
\centering
\SIrange{e-12}{e-10}{\second}
\[
\SIrange{e-12}{e-10}{\second}
\]
%
\end{document}

The result is:

Result of the MWE with two identical outputs


Update

There is another way of having the correct dash, as egreg suggested, by considering the inclusion of text inside the math mode, replacing \mathbin{-} with:

\sisetup{range-phrase=%
 \ifmmode\text{\,\textendash\,}
 \else
  \thinspace\textendash\thinspace
 \fi%
}
%

Obtaining:

Result of the MWE with two identical outputs, visually identical to the earlier one