josephwright / siunitx

A comprehensive (SI) units package for LaTeX
LaTeX Project Public License v1.3c
350 stars 25 forks source link

separate-uncertainty with a list and units: cannot remove brackets #717

Closed japhir closed 5 months ago

japhir commented 5 months ago

I've found this potentially related issue https://github.com/josephwright/siunitx/issues/441 and have read and re-read the manual, but I cannot figure out the following:

How can I print a qtylist without brackets and with a single unit? (i.e., in the mathematically wrong way.)

I want to get: qty: 50 ± 3 m (works as expected) qtyrange: 50 ± 3 m to 300 ± 5 m qtylist: 50 ± 3 m, 300 ± 5 m, and 250 ± 10 m

or even the same without repeating the unit qty: 50 ± 3 m (works as expected) qtyrange: 50 ± 3 to 300 ± 5 m qtylist: 50 ± 3, 300 ± 5, and 250 ± 10 m

(reviewers are asking about this)

I've tried the below, which currently results in:

\documentclass{article}
\usepackage{siunitx}
\sisetup{
  uncertainty-mode=separate,
  separate-uncertainty-units=single,
  multi-part-units=single,
  bracket-unit-denominator=false,
  bracket-negative-numbers=false,
  bracket-ambiguous-numbers=false,
  range-units=single,
  % list-units=single,
  % maybe I do want to repeat the unit for a list?
  list-units=repeat,
}

\begin{document}

\qty{50\pm3}{\metre}.
\qtyrange{50\pm3}{300\pm5}{\metre}.
\qtylist{50\pm3;300\pm5;250\pm10}{\metre}.

\end{document}

50 ± 3 m. (50 ± 3) to (300 ± 5) m. (50 ± 3) m, (300 ± 5) m and (250 ± 10) m.

josephwright commented 5 months ago

To get you sorted right now, try

\sisetup{range-open-bracket = , range-close-bracket = ,
  list-open-bracket = , list-close-bracket = }

I'll look at a fix shortly

japhir commented 5 months ago

Hmm it turns out I may not be running the latest version:

latexmk -pdflua -f qtylist_uncertainty                  
Rc files read:
  NONE
Latexmk: This is Latexmk, John Collins, 7 Jan. 2023. Version 4.79.
Latexmk: applying rule 'lualatex'...
Rule 'lualatex':  Reasons for rerun
Changed files or newly in use/created:
  /var/lib/texmf/web2c/luahbtex/lualatex.fmt
Category 'changed_user':
  /var/lib/texmf/web2c/luahbtex/lualatex.fmt

------------
Run number 1 of rule 'lualatex'
------------
------------
Running 'lualatex  -recorder  "qtylist_uncertainty.tex"'
------------
This is LuaHBTeX, Version 1.17.0 (TeX Live 2023/Arch Linux) 
 restricted system commands enabled.
(./qtylist_uncertainty.tex
LaTeX2e <2022-11-01> patch level 1
 L3 programming layer <2023-02-22>
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2022/07/02 v1.4n Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texmf-dist/tex/latex/siunitx/siunitx.sty
(/usr/share/texmf-dist/tex/latex/translations/translations.sty
(/usr/share/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/share/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty
(/usr/share/texmf-dist/tex/generic/infwarerr/infwarerr.sty)
(/usr/share/texmf-dist/tex/generic/iftex/iftex.sty)
(/usr/share/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty)))
(/usr/share/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/share/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/share/texmf-dist/tex/latex/tools/array.sty))

! LaTeX Error: The key 'siunitx/range-open-bracket' is unknown and is being
(LaTeX)        ignored.

For immediate help type H <return>.
 ...                                              

l.27 }
    %
? 

I'm on arch linux, running version 2023.66594-20 of the texlive-mathscience meta-package. The file siunitx itself says

\providecommand\DeclareRelease[3]{}
\providecommand\DeclareCurrentRelease[2]{}
\DeclareRelease{2}{2010-05-23}{siunitx-v2.sty}
\DeclareRelease{v2}{2010-05-23}{siunitx-v2.sty}
\DeclareCurrentRelease{}{2021-05-17}
josephwright commented 5 months ago

You could try

\ExplSyntaxOn
\cs_gset:Npn \__siunitx_compound_uncert_bracket:nnw #1#2 #3 \q_nil #4 \q_nil #5 \q_stop
  {
    \bool_lazy_any:nTF
      {
        { ! \l__siunitx_compound_unit_repeat_bool }
        { \tl_if_blank_p:n {#2#3} }
        { ! \tl_if_blank_p:n {#5} }
      }
      { \exp_not:n {#1#2#3#4#5} }
      {
        \exp_not:V \l__siunitx_compound_bracket_open_tl
        \exp_not:n {#1#2#3}
        \exp_not:V \l__siunitx_compound_bracket_close_tl
        \exp_not:n {#4#5}
      }
  }
\ExplSyntaxOff

as an in-place fix

japhir commented 5 months ago

Thanks, this seems like it might fix the range but not the list. EDIT: NEVER MIND, I had to put list-units=single, here too!

Where should I put it? I've tried:

\usepackage{siunitx}
% HERE <- this works
\sisetup{range-open-bracket = , range-close-bracket = ,
  list-open-bracket = , list-close-bracket = ,
  uncertainty-mode=separate,
  separate-uncertainty-units=single,
  multi-part-units=single,
  bracket-ambiguous-numbers=false,
  range-units=single,
  list-units=single,
  forbit-literal-units=true,
  per-mode=symbol,
}

but it always results in warnings such as ! LaTeX Error: The key 'siunitx/list-close-bracket' is unknown and is being ignored. and for my example file:

qty 50 ± 3 m qtyrange 50 ± 3 to 300 ± 5 m qtylist 50 ± 3, 300 ± 5 and 250 ± 10 m

full example ``` \documentclass{article} \usepackage{siunitx} \ExplSyntaxOn \cs_gset:Npn \__siunitx_compound_uncert_bracket:nnw #1#2 #3 \q_nil #4 \q_nil #5 \q_stop { \bool_lazy_any:nTF { { ! \l__siunitx_compound_unit_repeat_bool } { \tl_if_blank_p:n {#2#3} } { ! \tl_if_blank_p:n {#5} } } { \exp_not:n {#1#2#3#4#5} } { \exp_not:V \l__siunitx_compound_bracket_open_tl \exp_not:n {#1#2#3} \exp_not:V \l__siunitx_compound_bracket_close_tl \exp_not:n {#4#5} } } \ExplSyntaxOff \sisetup{% range-open-bracket = , range-close-bracket = , list-open-bracket = , list-close-bracket = , % mode=match, % propagate-math-font=true, % reset-math-version=false, % reset-text-family=false, % reset-text-series=false, % reset-text-shape=false, % text-family-to-math=true, % text-series-to-math=true, % text-font-command=\unitnumberfont % don't have v3 yet uncertainty-mode=separate, separate-uncertainty-units=single, multi-part-units=single, bracket-ambiguous-numbers=false, range-units=single, % maybe I do want to repeat the unit for a list? list-units=single, % list-units=repeat, forbit-literal-units=true, per-mode=symbol, }% \begin{document} \begin{table} \begin{tabular}{ll} \texttt{qty} & \qty{50\pm3}{\metre} \\ \texttt{qtyrange} & \qtyrange{50\pm3}{300\pm5}{\metre} \\ \texttt{qtylist} & \qtylist{50\pm3;300\pm5;250\pm10}{\metre} \\ \end{tabular} \end{table} \end{document} ```
josephwright commented 5 months ago

Definitely working when used with the latest siunitx release: all I can suggest is installing the latest code.