Open Splines opened 6 months ago
I find this difficult as per-mode=symbol
is not the default in siunitx
. If we want to generate the output (mm s)/(N kg)
as you proposed, we should set per-mode=symbol
in results.tex
.
I refer to the console output, not the output to results.tex
I know. But both should be built upon the same logic.
But for siunitx
the user should be able to decide on their own what per-mode
they want to use, right? E.g. they prefer a fraction over the /
delimiter.
However, in the console, we don't have a fraction available. Instead, a meaningful representation of \per
with ASCII symbols is only possible with /
(or provide me with a different approach if you find something better).
If the user specifies per-mode=symbol
, siunitx will automatically add the parentheses if the output would be ambiguous otherwise. In the console, we should reflect this behavior, I guess. E.g. for a product in the denominator, use parentheses.
And last but not least: I don't think we should go as far as allowing customization of the printouts to the console. These printouts just serve as a first glance for the variable and are mainly intended for Jupyter notebooks. The core of ResultWizard is still the output in a siunitx-compatible format.
I see the following problem: Depending on the mode used in siunitx
, a user could mean one of the two things with A \per B C
:
A/(BC)
(A/B)C
As far as I know, per-mode
only affects how the output is printed. After the first \per
, siunitx will always consider the rest to be in a grouping (your case 1).
Also see the documentation
...but only if you use multiple \per
's.
Ah, you're right. But I still don't get your full point I guess.
Here, the grouping is still consistent within all three options in this case.
siunitx apparently parses it like this: \per + <unit>
is one group, e.g. A \per B C
is treated like A (\per B) C
. And with multiple \per
s, it's the same way: A \per B \per C
is treated like A (\per B) (\per C)
. Reflect that in the console to conform with siunitx.
Now I see the confusion: my original comment in this post is then wrong, that's true.
\mm\s\per\N\kg\per\T
should be printed as mm s kg / (N T)
. Maybe put everything that is in the denominator after the /
. There should be only one /
in the console output to make things clear. If the denominator contains more than one unit specifier, put parentheses around them.
You probably have to build a small Lexer to achieve this.
maybe use the same "parentheses logic" for the numerator as well to print (mm s kg) / (N T)
instead of mm s kg / (N T)
. That makes it better to read in my view.
This, I don't get again. We can only do such grouping, if we analyze the user's unit string more deeply, i.e. detect whether there are multiple \per
's etc.
Yes, exactly, that's what I mean with
You probably have to build a small Lexer to achieve this.
If you like, I can support you with this task as I have a tiny bit of knowledge in compiler construction
I added a small lexer.
Consider this:
will print:
The unit representation might be misleading. Instead, I'd expect something like
(mm s)/(N kg)
. This is also whatsiunitx
is doing when users specifyper-mode=symbol
in the\sisetup{}
.Edit: My assumptions how siunitx parses the input were wrong in this issue. See the discussion below for how it looks like in reality, i.e. in this example, we'd expect
(mm s kg) / N
.