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

Issue with negative exponents when using output-exponent-marker #600

Closed
adamliter opened this issue Apr 3, 2022 · 1 comment
Closed
Assignees
Labels
bug Something isn't working hotfix A change that will be addressed in a hotfix

Comments

@adamliter
Copy link

adamliter commented Apr 3, 2022

When compiling the following document with TeX Live 2020 and version 2020/02/25 v2.8b of siunitx, I get the following result:

\documentclass{article}
\usepackage{siunitx}
\sisetup{output-exponent-marker=\ensuremath{e}}
\begin{document}
\num{2.74e-7}
\end{document}

image

When compiling with TeX Live 2021 and version 2022-02-15 v3.0.49 of siunitx, I get the following result:

image

In this second case, it seems like the negative is being treated as a minus sign for the purposes of spacing. I'm guessing this is a bug, right? Thanks!

If you happen to have a fix you could suggest for the time being while TeX Live is frozen, I'd really appreciate it! 😄

@josephwright josephwright self-assigned this Apr 3, 2022
@josephwright josephwright added bug Something isn't working hotfix A change that will be addressed in a hotfix labels Apr 3, 2022
@josephwright
Copy link
Owner

In place fix

\documentclass{article}
\usepackage{siunitx}
\ExplSyntaxOn
\cs_gset:Npn \__siunitx_number_output_exponent_auxi:nnnnn #1#2#3#4#5
  {
    \bool_lazy_or:nnT
      {
        \bool_lazy_and_p:nn
          { \l__siunitx_number_unity_mantissa_bool }
          { \str_if_eq_p:nn { #3 . #4 } { 1. } }
      }
      {
        ! \bool_lazy_or_p:nn
          { \str_if_eq_p:nn { #3 . #4 } { 1. } }
          { \tl_if_blank_p:n {#3} }
      }
      {
        \bool_if:NTF \l__siunitx_number_tight_bool
          { \exp_not:N \mathord }
          { \use:n }
            { \exp_not:V \l__siunitx_number_exponent_product_tl }
      }
    \exp_not:n {#5}
    \exp_not:V \l__siunitx_number_exponent_base_tl
    ^
      { \__siunitx_number_output_exponent_auxiii:nnn { } {#1} {#2} }
  }
\cs_gset:Npn \__siunitx_number_output_exponent_auxii:nnnnn #1#2#3#4#5
  {
    \exp_not:n {#5}
    \exp_not:V \l__siunitx_number_output_exp_marker_tl
    \__siunitx_number_output_exponent_auxiii:nnn { \mathord } {#1} {#2}
  }
\cs_gset:Npn \__siunitx_number_output_exponent_auxiii:nnn #1#2#3
  {
    \tl_if_blank:nTF {#2}
      {
        \bool_lazy_and:nnT
          { \l__siunitx_number_implicit_plus_bool }
          { ! \str_if_eq_p:nn {#3} { 0 } }
          { #1 + }
      }
      { \exp_not:n {#1#2} }
    \__siunitx_number_output_digits:nn { integer } {#3}
  }
\ExplSyntaxOff
\sisetup{output-exponent-marker=\mathrm{e}}
\begin{document}
\num{2.74e-7}
\end{document}

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