Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior for unit only in denominator #723

Closed
dflvunoooooo opened this issue Mar 6, 2024 · 7 comments
Closed

Inconsistent behavior for unit only in denominator #723

dflvunoooooo opened this issue Mar 6, 2024 · 7 comments

Comments

@dflvunoooooo
Copy link

dflvunoooooo commented Mar 6, 2024

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
Copy link
Owner

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
Copy link
Owner

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

@dflvunoooooo
Copy link
Author

dflvunoooooo commented Mar 6, 2024

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
Copy link
Owner

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
Copy link
Author

dflvunoooooo commented Mar 6, 2024

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
Copy link
Owner

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
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants