josephwright/siunitx

Bug when combining \sqrt with scientific notation and number-mode=match, with workaround

bamford opened this issue · 2 comments

I have been trying to typeset $\sqrt{3}\times10^{10}~m^{-1}$ using \qty, similar to \qty{3e10}{m^{-1}}, in a document that uses \sisetup{number-mode=match}.

Using parse-numbers=false almost works:

\sisetup{number-mode=match}
The number is not \qty{3e10}{m^{-1}}, but rather \qty[parse-numbers=false]{\sqrt{3}\times10^{10}}{m^{-1}}.

produces:
Screenshot 2024-02-14 at 20 16 05
which somehow typesets the $\sqrt{3}$ in the text font, but the $\times 10^{10}$ in the math font!

Presumably this is unintended behaviour, that someone with knowledge of the internals of siunitx may be able to fix.

After some experimentation I found that adding the number-mode=math option and wrapping the number in \text{} produes the desired output, although I’m not sure why! So, this is a workaround:

\sisetup{number-mode=match}
The number is not \qty{3e10}{m^{-1}}, but rather \qty[number-mode=math, parse-numbers=false]{\text{\sqrt{3}\times10^{10}}}{m^{-1}}.

which produces:
Screenshot 2024-02-14 at 20 16 27

I'm using LuaLaTeX with TeX Live 2023 on Overleaf.

I've corrected the behaviour here: you get everything in math mode - that is the documented approach when not parsing numbers.

That was fast! Many thanks @josephwright.