josephwright / siunitx

A comprehensive (SI) units package for LaTeX
LaTeX Project Public License v1.3c
348 stars 25 forks source link

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

Closed bamford closed 4 months ago

bamford commented 4 months ago

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.

josephwright commented 4 months ago

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

bamford commented 4 months ago

That was fast! Many thanks @josephwright.