josephwright / siunitx

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

Inconsistent behavior for unit only in denominator #723

Closed dflvunoooooo closed 6 months ago

dflvunoooooo commented 7 months ago

If I try to set a unit which is one over something, like 1/s, the result is different for math and text mode. In text, I have to set {1\per\second} in a math environment that will disregard a local ´per-mode´ setting and I have to use ´{\per\second}´ without the 1.

Screenshot_20240306_221912

Here is the code

\documentclass{scrartcl}

\usepackage{siunitx}
\usepackage{amsmath}    
\sisetup{
    per-mode = symbol,  
}

\begin{document}

\qty{504.4667}{\per\second}

\qty{1}{1\per\second}

\begin{equation}
    \sisetup{per-mode=fraction}
    \qty{504.4667}{\per\second}
\end{equation}

\begin{equation}
    \sisetup{per-mode=fraction}
    \qty{1}{1\per\second}
\end{equation}

\end{document}
josephwright commented 7 months ago

You've put something that prints literally in the second unit expression: siunitx therefore typesets in literal mode, in which case \per is always /.

josephwright commented 7 months ago

Note that if you simply omit the 1, siunitx will 'read in' the required 1 for the fraction.

dflvunoooooo commented 7 months ago

You've put something that prints literally in the second unit expression: siunitx therefore typesets in literal mode, in which case \per is always /.

I am sorry, I don't understand what you mean.

Edit: Nevermind, got it. Edit 2: But why is the per-mode=fraction not working inside math?

Note that if you simply omit the 1, siunitx will 'read in' the required 1 for the fraction.

Yes, I expected that, but it is not working for the first \qty command in text.

josephwright commented 7 months ago

No, it's not expected to have a 1 there, as 504.4667 1/s doesn't make sense, it's just 504.4667/2 (you are dividing the value by seconds). This is by-design. (BTW, nothing is in text mode here.)

dflvunoooooo commented 7 months ago

Why not, 504.4667 1/s are for example counts from a Geiger-Müller-Counter. But I accept, that per-mode=symbol works that way. But if I set per-mode=fraction only {\per\second} works, {1\per\second} doesn't do what I want. And inside a math environment it is the other way round.

Screenshot_20240306_230419

\documentclass{scrartcl}

\usepackage{siunitx}
\usepackage{amsmath}    

\begin{document}
\sisetup{per-mode=symbol}
\qty{504.4667}{\per\second}

\qty{1}{1\per\second}

\sisetup{per-mode=fraction}
\qty{504.4667}{\per\second}

\qty{1}{1\per\second}

\sisetup{per-mode=symbol}
\begin{equation}
    \qty{504.4667}{\per\second}
\end{equation}

\begin{equation}
    \qty{1}{1\per\second}
\end{equation}

\sisetup{per-mode=fraction}
\begin{equation}
    \qty{504.4667}{\per\second}
\end{equation}

\begin{equation}
    \qty{1}{1\per\second}
\end{equation}

\end{document}
josephwright commented 7 months ago

The moment you add the 1 into the unit, you are taking control of the output. No parsing occurs, and \per always generates / under those circumstances. If you want a fraction, you'll need to write {\frac{1}{\second}} or similar.

dflvunoooooo commented 7 months ago

I see, thank you! So the problem is that "one" is not a unit and therefore there is no \one which could be put before the \per to let siunitx control the output?