josephwright / siunitx

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

WIth `separate-uncertainty` a line break is allowed after ± #753

Open eg9 opened 2 weeks ago

eg9 commented 2 weeks ago

If \sisetup{separate-uncertainty} is used, a line break becomes possible after ±.

Minimal example from https://tex.stackexchange.com/q/729528/4427

\documentclass[12pt,paper=a4]{scrartcl}
\usepackage{siunitx}
\sisetup{separate-uncertainty}

\begin{document}

\noindent
In general, line breaks within the value are somewhat rare,
with me encountering \qty{1(2)}{breaks} on average when formatting short documents.

\end{document}

As there's no interface for changing the symbol used to separate the uncertainty, the fix should be to change the code

   2611 \cs_new:Npn \__siunitx_number_output_uncert_S_sep:nnnn #1#2#3#4
   2612   {
   2613     \exp_not:n {#2}
   2614     \bool_if:NTF \l__siunitx_number_tight_bool
   2615       { \exp_not:N \mathord }
   2616       { \use:n }
   2617         { \exp_not:n { \pm } }
   2618     \exp_not:n {#2}
   2619     \__siunitx_number_output_uncert_augment:nnnn {#4} {#1} {#4} {#2}
   2620   }

into

   2611 \cs_new:Npn \__siunitx_number_output_uncert_S_sep:nnnn #1#2#3#4
   2612   {
   2613     \exp_not:n {#2}
   2614     \bool_if:NTF \l__siunitx_number_tight_bool
   2615       { \exp_not:N \mathord }
   2616       { \use:n }
   2617         { \exp_not:n { \pm\nobreak } }
   2618     \exp_not:n {#2}
   2619     \__siunitx_number_output_uncert_augment:nnnn {#4} {#1} {#4} {#2}
   2620   }

To confirm this, the hack

\documentclass[12pt,paper=a4]{scrartcl}
\usepackage{siunitx}
\sisetup{separate-uncertainty}

\mathchardef\originalpm=\pm
\def\pm{\originalpm\nobreak}

\begin{document}

\noindent
In general, line breaks within the value are somewhat rare,
with me encountering \qty{1(2)}{breaks} on average when formatting short documents.

\end{document}

shows that the bad line break doesn't happen.

josephwright commented 2 weeks ago

In contrast to the link between a number and the unit, where BIPM explicitly say there should be no break, there is no formal guidance on breaks within 'compound' numbers: either separated uncertainties or exponent form. (My feeling is BIPM favour always writing the unit with the number, and always using prefixes, so either issue really arises.) Thus the standard TeX math mode breaking behaviour has always been left as-is in this area.

I can add an option to adjust the allowed breaking, but I caution that particularly in journals, this is likely to be problematic: as it is, most journals ignore the rule about not breaking between a number and a unit as otherwise it's difficult to set material.

josephwright commented 2 weeks ago

Presumably something similar to allow-quantity-breaks would be OK: \binoppenalty if true, \nobreak if false. As always, option name suggestion welcome - I'll add for v3.4 so in the next month or so.