Skip to content

Commit

Permalink
Correct printing of (only) "inline-per-mode = symbol" (fixes #765)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwright committed Jan 20, 2025
1 parent 0f4697f commit fb2c0b7
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to

## [Unreleased]

### Fixed
- Correct behavior of `inline-per-mode = symbol` with an alternative setting
for `display-per-mode` when units are entirely in the denominator (see issue
[\#765](/~https://github.com/josephwright/siunitx/issues/765))

## [v3.4.2] - 2025-01-17

### Changed
Expand Down
33 changes: 32 additions & 1 deletion siunitx-quantity.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@
% \siunitx_quantity_print:VV, \siunitx_quantity_print:eV
% }
% \begin{macro}{\@@_print_unit:n}
% \begin{macro}{\@@_print_mathchoice:Nnnnn}
% \begin{macro}{\@@_print_mathchoice:nnN}
% For printing a single part of a quantity. This is needed for compound
% quantities and so is public: that's also the reason for passing both
% argument explicitly. The semantics here require that the penalty and
Expand All @@ -401,7 +403,11 @@
{
\tl_if_head_eq_charcode:nNTF {#2} 1
{ \siunitx_print_unit:o { \use_none:n #2 } }
{ \@@_print_unit:n {#2} }
{
\tl_if_head_eq_meaning:nNTF {#2} \mathchoice
{ \@@_print_mathchoice:Nnnnn #2 }
{ \@@_print_unit:n {#2} }
}
}
}
}
Expand All @@ -415,6 +421,31 @@
\siunitx_print_unit:n {#1}
}
% \end{macrocode}
% If the first token of the unit is |\mathchoice|, we are looking at
% formatting differently in display and inline math modes. If we then have a
% leading |1|, then it needs to be lopped off. We also need to remember here
% that the spacing also needs to be inside the |\mathchoice|, as it only
% applies in display mode. To get all of this to work, there is then some
% nesting of print functions: unavoidable. As |#3|, |#4| and |#5| are
% identical, expansion can take place just once to pass the trimmed tokens.
% \begin{macrocode}
\cs_new_protected:Npn \@@_print_mathchoice:Nnnnn #1#2#3#4#5
{
\tl_if_head_eq_charcode:nNTF {#3} 1
{
\exp_args:No \@@_print_mathchoice:nnN
{ \use_none:n #3 } {#2} #1
}
{ \@@_print_unit:n { #1 {#2} {#3} {#4} {#5} } }
}
\cs_new_protected:Npn \@@_print_mathchoice:nnN #1#2#3
{
\siunitx_print_unit:n
{ #3 { \@@_print_unit:n {#2} } {#1} {#1} {#1} }
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
Expand Down
41 changes: 41 additions & 0 deletions testfiles/siunitx-quantity.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -1029,3 +1029,44 @@ l. ... }
<argument> \l_tmpa_box
l. ... }
============================================================
============================================================
TEST 12: Option settings "display per-mode = fraction" and "inline-per-mode = symbol"
============================================================
> \box...=
\hbox(7.5+2.5)x13.94447, direction TLT
.\mathon
.\OT1/cmr/m/n/10 1
.\OML/cmm/m/it/10 =
.\OT1/cmr/m/n/10 s
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(7.5+2.5)x13.94447, direction TLT
.\mathon
.\OT1/cmr/m/n/10 2
.\mathoff
.\mathon
.\OML/cmm/m/it/10 =
.\OT1/cmr/m/n/10 s
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(7.5+2.5)x23.94455, direction TLT
.\mathon
.\OT1/cmr/m/n/10 3
.\mathoff
.\penalty 10000
.\kern1.66672
.\mathon
.\OT1/cmr/m/n/10 m
.\OML/cmm/m/it/10 =
.\OT1/cmr/m/n/10 s
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
============================================================
8 changes: 8 additions & 0 deletions testfiles/siunitx-quantity.lvt
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,12 @@
\test:nn { 3 } { \metre \per \second }
}

\TEST { Option~settings~"display~per-mode~=~fraction"~and~"inline-per-mode~=~symbol" }
{
\keys_set:nn { siunitx } { display-per-mode = fraction , inline-per-mode = symbol }
\test:nn { } { \per \second }
\test:nn { 2 } { \per \second }
\test:nn { 3 } { \metre \per \second }
}

\END
41 changes: 41 additions & 0 deletions testfiles/siunitx-quantity.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -1029,3 +1029,44 @@ l. ... }
<argument> \l_tmpa_box
l. ... }
============================================================
============================================================
TEST 12: Option settings "display per-mode = fraction" and "inline-per-mode = symbol"
============================================================
> \box...=
\hbox(7.5+2.5)x13.94447
.\mathon
.\OT1/cmr/m/n/10 1
.\OML/cmm/m/it/10 =
.\OT1/cmr/m/n/10 s
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(7.5+2.5)x13.94447
.\mathon
.\OT1/cmr/m/n/10 2
.\mathoff
.\mathon
.\OML/cmm/m/it/10 =
.\OT1/cmr/m/n/10 s
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(7.5+2.5)x23.94455
.\mathon
.\OT1/cmr/m/n/10 3
.\mathoff
.\penalty 10000
.\kern 1.66672
.\mathon
.\OT1/cmr/m/n/10 m
.\OML/cmm/m/it/10 =
.\OT1/cmr/m/n/10 s
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
============================================================
41 changes: 41 additions & 0 deletions testfiles/siunitx-quantity.xetex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -1029,3 +1029,44 @@ l. ... }
<argument> \l_tmpa_box
l. ... }
============================================================
============================================================
TEST 12: Option settings "display per-mode = fraction" and "inline-per-mode = symbol"
============================================================
> \box...=
\hbox(7.5+2.5)x13.94447
.\mathon
.\OT1/cmr/m/n/10 1
.\OML/cmm/m/it/10 =
.\OT1/cmr/m/n/10 s
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(7.5+2.5)x13.94447
.\mathon
.\OT1/cmr/m/n/10 2
.\mathoff
.\mathon
.\OML/cmm/m/it/10 =
.\OT1/cmr/m/n/10 s
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(7.5+2.5)x23.94455
.\mathon
.\OT1/cmr/m/n/10 3
.\mathoff
.\penalty 10000
.\kern 1.66672
.\mathon
.\OT1/cmr/m/n/10 m
.\OML/cmm/m/it/10 =
.\OT1/cmr/m/n/10 s
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
============================================================

0 comments on commit fb2c0b7

Please sign in to comment.