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

Add parentheses to units in \per mode in console output #40

Open
Splines opened this issue Apr 11, 2024 · 13 comments · May be fixed by #42
Open

Add parentheses to units in \per mode in console output #40

Splines opened this issue Apr 11, 2024 · 13 comments · May be fixed by #42
Assignees

Comments

@Splines
Copy link
Collaborator

Splines commented Apr 11, 2024

Consider this:

wiz.res("a911", 1.05, unit=r"\mm\s\per\N\kg").print()

will print:

aNineHundredEleven = 1.1 mm s/N kg

The unit representation might be misleading. Instead, I'd expect something like (mm s)/(N kg). This is also what siunitx is doing when users specify per-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.

@Splines Splines changed the title Add parentheses to units in \per mode in console output Add parentheses to units in \per mode in console output Apr 11, 2024
@paul019
Copy link
Collaborator

paul019 commented Apr 11, 2024

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.

@Splines
Copy link
Collaborator Author

Splines commented Apr 11, 2024

I refer to the console output, not the output to results.tex

@paul019
Copy link
Collaborator

paul019 commented Apr 11, 2024

I know. But both should be built upon the same logic.

@Splines
Copy link
Collaborator Author

Splines commented Apr 11, 2024

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.

@paul019
Copy link
Collaborator

paul019 commented Apr 11, 2024

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:

  1. A/(BC)
  2. (A/B)C

@Splines
Copy link
Collaborator Author

Splines commented Apr 11, 2024

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).

image

Also see the documentation

@paul019
Copy link
Collaborator

paul019 commented Apr 11, 2024

...but only if you use multiple \per's.

@Splines
Copy link
Collaborator Author

Splines commented Apr 11, 2024

Ah, you're right. But I still don't get your full point I guess.

image

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 \pers, 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.

@Splines
Copy link
Collaborator Author

Splines commented Apr 11, 2024

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.

@Splines
Copy link
Collaborator Author

Splines commented Apr 11, 2024

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.

@paul019
Copy link
Collaborator

paul019 commented Apr 11, 2024

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.

@Splines
Copy link
Collaborator Author

Splines commented Apr 11, 2024

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

@paul019
Copy link
Collaborator

paul019 commented Apr 11, 2024

I added a small lexer.

@paul019 paul019 linked a pull request Apr 12, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants