Skip to content

Commit

Permalink
Add option "print-complex-unity" (fixes #625)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwright committed Oct 23, 2022
1 parent 6085ee0 commit fe5a86d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to

## [Unreleased]

### Added
- Option `print-complex-unity`

## Fixed
- Printing of complex values of exactly one (see issue
[\#625](https://github.com/josephwright/siunitx/issues/625))

## [v3.1.8] - 2022-10-04

### Fixed
Expand Down
36 changes: 25 additions & 11 deletions siunitx-complex.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@
% is |\mathrm{i}|.
% \end{function}
%
% \begin{function}{print-complex-unity}
% \begin{syntax}
% |print-complex-unity| = |true|\verb"|"|false|
% \end{syntax}
% Switch to determine if the number \num{1} is printed for a complex
% part which is exactly unity.
% \end{function}
%
% \end{documentation}
%
% \begin{implementation}
Expand Down Expand Up @@ -286,7 +294,9 @@
input-complex-root .tl_set:N =
\l_@@_input_root_tl ,
output-complex-root .tl_set:N =
\l_@@_output_root_tl
\l_@@_output_root_tl ,
print-complex-unity .bool_set:N =
\l_@@_print_unity_bool
}
% \end{macrocode}
% \end{variable}
Expand Down Expand Up @@ -885,9 +895,12 @@
\q_nil #9 \q_stop
{
\tl_set:Nn \l_@@_sign_tl {#1#2}
\bool_lazy_and:nnTF
{ \str_if_eq_p:nn {#3} { 1 } }
{ \tl_if_blank_p:n {#5} }
\bool_lazy_all:nTF
{
{ ! \l_@@_print_unity_bool }
{ \str_if_eq_p:nn {#3} { 1 } }
{ \tl_if_blank_p:n {#5} }
}
{ \@@_extract_exponent_aux:nw {#6#7#8} }
{ \@@_extract_exponent_aux:nw {#3#4#5#6#7#8} }
#9 \q_stop
Expand Down Expand Up @@ -1192,13 +1205,14 @@
% \begin{macrocode}
\keys_set:nn { siunitx }
{
complex-angle-unit = degrees ,
complex-mode = input ,
complex-root-position = after-number ,
complex-symbol-angle = \angle ,
complex-symbol-degree = \degree ,
input-complex-root = ij ,
output-complex-root = \mathrm { i }
complex-angle-unit = degrees ,
complex-mode = input ,
complex-root-position = after-number ,
complex-symbol-angle = \angle ,
complex-symbol-degree = \degree ,
input-complex-root = ij ,
output-complex-root = \mathrm { i } ,
print-complex-unity = false
}
% \end{macrocode}
%
Expand Down
10 changes: 10 additions & 0 deletions siunitx.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,7 @@ \subsection{Complex numbers}
complex-symbol-degree & Literal & \cs{degree} \\
input-complex-root & Literal & ij \\
output-complex-root & Literal & \verb=\mathrm{i}= \\
print-complex-unity & Switch & false \\
\bottomrule
\end{tabular}
\end{table}
Expand Down Expand Up @@ -2121,6 +2122,15 @@ \subsection{Complex numbers}
\complexqty[complex-symbol-degree = d]{1:1}{\ohm}
\end{LaTeXdemo}

\DescribeOption{print-complex-unity}
When the complex part of a number is exactly \num{1}, it is possible to either
print or suppress the value. This is controlled by the switch
\opt{print-complex-unity}.
\begin{LaTeXdemo}
\complexqty{1i}{\ohm} \\
\complexqty[print-complex-unity]{1i}{\ohm}
\end{LaTeXdemo}

\subsection{Angles}

Angle processing provided by the \cs{ang} function has a set of options which
Expand Down
31 changes: 30 additions & 1 deletion testfiles/siunitx-complex.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,36 @@ l. ... }
l. ... }
============================================================
============================================================
TEST 10: Option settings "exponent-mode" and "prefix-mode"
TEST 10: Option setting "print-complex-unity"
============================================================
> \box...=
\hbox(6.67859+0.83333)x19.99994, direction TLT
.\mathon
.\OT1/cmr/m/n/10 1
.\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
.\OT1/cmr/m/n/10 +
.\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
.\OT1/cmr/m/n/10 i
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(6.67859+0.83333)x24.99995, direction TLT
.\mathon
.\OT1/cmr/m/n/10 1
.\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
.\OT1/cmr/m/n/10 +
.\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
.\OT1/cmr/m/n/10 1
.\OT1/cmr/m/n/10 i
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
============================================================
============================================================
TEST 11: Option settings "exponent-mode" and "prefix-mode"
============================================================
> \box...=
\hbox(7.5+2.5)x101.66681, direction TLT
Expand Down
7 changes: 7 additions & 0 deletions testfiles/siunitx-complex.lvt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@
\test:n { 12.34 + 2i }
}

\TEST { Option~setting~"print-complex-unity" }
{
\test:n { 1 + 1i }
\keys_set:nn { siunitx } { print-complex-unity = true }
\test:n { 1 + 1i }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\OMIT
Expand Down
31 changes: 30 additions & 1 deletion testfiles/siunitx-complex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,36 @@ l. ... }
l. ... }
============================================================
============================================================
TEST 10: Option settings "exponent-mode" and "prefix-mode"
TEST 10: Option setting "print-complex-unity"
============================================================
> \box...=
\hbox(6.67859+0.83333)x19.99994
.\mathon
.\OT1/cmr/m/n/10 1
.\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
.\OT1/cmr/m/n/10 +
.\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
.\OT1/cmr/m/n/10 i
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(6.67859+0.83333)x24.99995
.\mathon
.\OT1/cmr/m/n/10 1
.\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
.\OT1/cmr/m/n/10 +
.\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
.\OT1/cmr/m/n/10 1
.\OT1/cmr/m/n/10 i
.\mathoff
! OK.
<argument> \l_tmpa_box
l. ... }
============================================================
============================================================
TEST 11: Option settings "exponent-mode" and "prefix-mode"
============================================================
> \box...=
\hbox(7.5+2.5)x101.66681
Expand Down

0 comments on commit fe5a86d

Please sign in to comment.