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

Padding not correct / decimal point at wrong place #725

Closed
Splines opened this issue Apr 11, 2024 · 12 comments
Closed

Padding not correct / decimal point at wrong place #725

Splines opened this issue Apr 11, 2024 · 12 comments
Assignees
Labels
bug Something isn't working hotfix A change that will be addressed in a hotfix

Comments

@Splines
Copy link

Splines commented Apr 11, 2024

Presumptions

I use the following sisetup:

\sisetup{
	locale=US,
	group-separator={,},
	group-digits=integer,
	per-mode=symbol,
	separate-uncertainty=true
}

Description of problem

I'm wondering why this input:

$$\qty[minimum-decimal-digits=6]{5.407 \pm 0.04}{\m}$$

is printed as

(5.407000 \pm 0.004000) m in the LaTeX document. Note that siunitx altered the uncertainty from 0.04 to 0.004.


The root cause for this is probably the same for the following confusing output:

\NewDocumentCommand{\UncertStat}{}{_{\text{stat}}}
\NewDocumentCommand{\UncertSys}{}{_{\text{sys}}}
\sisetup{input-digits=0123456789\UncertStat\UncertSys\UncertSystematic}

$$\qty{5.407 \pm 0.010\UncertSys \pm 0.04\UncertStat e-7}{\m}$$

will result in:

image

note that the 0 is printed after the \text{stat}. Is there a way to get rid of this trailing 0 altogether?

Efforts taken

Additional context

If you're wondering why we need this \NewDocumentCommand stuff. A friend of mine and me currently build a Python library called ResultWizard as an interface between Python code and the siunitx LaTeX package. We're in the second alpha version right now and stumbled upon the described issue here.

System Information

I'm using TeX Live in WSL (Ubuntu 22.04 jammy). siunitx version: 3.1.11 (2022-12-05).

@josephwright
Copy link
Owner

josephwright commented Apr 12, 2024

Minimised example

\documentclass{article}
\usepackage{siunitx}
\sisetup{minimum-decimal-digits = 4}
\begin{document}
\qty{5.407 \pm 0.04}{\metre}
\end{document}

@josephwright josephwright self-assigned this Apr 12, 2024
@josephwright josephwright added the bug Something isn't working label Apr 12, 2024
@josephwright
Copy link
Owner

The root cause for this is probably the same for the following confusing output:

Off-topic here, but you seem to have missed that siunitx has native support for multiple uncertainties from v3.1.0, released 2022-04-25.

@josephwright josephwright added the hotfix A change that will be addressed in a hotfix label Apr 12, 2024
@Splines
Copy link
Author

Splines commented Apr 12, 2024

Thanks a lot for your hot fix 🎉

Unfortunately, users of our library might not be easily able to use an updated version of siunitx. E.g. even for the current LTS Ubuntu (Ubuntu 22.04 jammy), the siunitx version that comes shipped with sudo apt install texlive-science is 3.0.4. We do provide an update guide here (at the very bottom), but only up to version 3.1.11 (2022-12-05), as this is the last one before we'd have to update other dependencies as well as you make use of the new LaTeX3 layer and expl3 is breaking for us.

That's why I'm asking if there is a workaround when using version 3.1.11 (2022-12-05) to still get correct output for the following:

\NewDocumentCommand{\UncertStat}{}{_{\text{stat}}}
\NewDocumentCommand{\UncertSys}{}{_{\text{sys}}}
\sisetup{input-digits=0123456789\UncertStat\UncertSys\UncertSystematic}

$$\qty{5.407 \pm 0.010\UncertSys \pm 0.04\UncertStat e-7}{\m}$$

@josephwright
Copy link
Owner

@Splines The auxiliary hasn't changed name, so

\ExplSyntaxOn
\cs_gset:Npn \__siunitx_number_digits_uncert_aux:nn #1#2
  {
    \exp_not:n {#2}
    \int_compare:nNnT
      { \l__siunitx_number_min_decimal_int - \tl_count:n {#1} } > 0
      {
        \prg_replicate:nn
          { \l__siunitx_number_min_decimal_int - \tl_count:n {#1} } { 0 }
      }
  }
\ExplSyntaxOff

will locally adjust the code.

I'm still not clear why you are not using the built-in multi-uncertainty support in v3.1.

@Splines
Copy link
Author

Splines commented Apr 12, 2024

Thanks a lot!

I'm still not clear why you are not using the built-in multi-uncertainty support in v3.1.

I thought that multi-uncertainty support only referred to being able to add multiple \pms to a number. Having looked through the docs again now, I found the uncertainty-descriptors key and that's exactly what I needed in the first place 🙌. The \NewDocumentCommand was just a workaround since we didn't know about the other option ;)
We will go ahead and recommend our users to add this to their preamble (or give them a hint they might find this option useful):

\sisetup{uncertainty-descriptor-mode=subscript}

and then generate programatically the following output for quantities:

\qty[uncertainty-descriptors={customlabel1,customlabel2}]{1.2 \pm 0.1 \pm 0.05}{\m}

@Splines
Copy link
Author

Splines commented Apr 12, 2024

\qty{5.407 \pm 0.010 \pm 0.04}{\m}

Is there a way to print the 0.04 "as is", i.e. not 0.040? With round-pad=false and round-mode=none and minimum-decimal-digits=0, we still get 0.040 in version 3.1.11 (2022-12-05). Even with you're hotfix (manually applied via your workaround) it's not working as expected. Maybe I have missed a crucial option in the docs?

@josephwright
Copy link
Owner

\qty{5.407 \pm 0.010 \pm 0.04}{\m}

Is there a way to print the 0.04 "as is", i.e. not 0.040? With round-pad=false and round-mode=none and minimum-decimal-digits=0, we still get 0.040 in version 3.1.11 (2022-12-05). Even with you're hotfix (manually applied via your workaround) it's not working as expected. Maybe I have missed a crucial option in the docs?

No, becaue the main value here has 3 decimal places, so the uncertainty must also be specified to the same precision.

@josephwright
Copy link
Owner

(Or rather that's the internal model siunitx uses.)

@Splines
Copy link
Author

Splines commented Apr 12, 2024

Ah ok and I guess there's also no (easy) way to overwrite that, right?

@josephwright
Copy link
Owner

@Splines I can imagine an approach but that's definitely a non-trivial feature request for the current release not something that can be shoehorned into a past release.

@Splines
Copy link
Author

Splines commented Apr 13, 2024

In the case you're willing to put your time and effort into such a feature (which would be much appreciated), we'd like to then also be able to make our users profit from it. That's why I've opened #726 to get to know how users can upgrade to the most recent version of siunitx without having to rethink their entire LaTeX setup.

@josephwright
Copy link
Owner

@Splines Please open a separate issue - including supporting links/PDFs/whatever that show that this approach is used by professionally-typeset material (that's my usual requirement for feature requests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hotfix A change that will be addressed in a hotfix
Projects
None yet
Development

No branches or pull requests

2 participants