Skip to content

Commit

Permalink
New option "complex-phase-command" (closes #732)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwright committed Dec 3, 2024
1 parent 867bdda commit f71d749
Show file tree
Hide file tree
Showing 7 changed files with 413 additions and 181 deletions.
1 change: 1 addition & 0 deletions .github/tl_packages
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ realscripts
revtex
sansmath
soulpos
steinmetz
tabularray
textcase
threeparttable
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
### Added
- Option `simplify-uncertainty` (see issue
[\#688](https://github.com/josephwright/siunitx/issues/688))
- Option `complex-phase-command` (see issue
[\#732](https://github.com/josephwright/siunitx/issues/732))
- Option `allow-uncertainty-breaks` (see issue
[\#753](https://github.com/josephwright/siunitx/issues/753))
- `\siunitx_unit_options_declare:Nn` to support fine-tuning of unit commands
Expand All @@ -30,6 +32,7 @@ Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to

- Option `number-angle-product`in favor of using settings applying to relevant
units
- Option `complex-symbol-angle` in favor of `complex-phase-command`

## [v3.3.24] - 2024-11-19

Expand Down
75 changes: 48 additions & 27 deletions siunitx-complex.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,20 @@
% |input|.
% \end{function}
%
% \begin{function}{complex-root-position}
% \begin{function}{complex-phase-command}
% \begin{syntax}
% |complex-root-position| = |after-number|\verb"|"|before-number|
% |complex-phase-command| = \meta{cmd}
% \end{syntax}
% Choice which determines where the complex root symbol is printed relative
% to the numbers. The standard setting is |after-number|.
% Sets the command used during output of the phase of a complex number in
% polar form. The standard setting is |\angle|.
% \end{function}
%
% \begin{function}{complex-symbol-angle}
% \begin{function}{complex-root-position}
% \begin{syntax}
% |complex-symbol-angle| = \meta{symbol}
% |complex-root-position| = |after-number|\verb"|"|before-number|
% \end{syntax}
% Sets the symbol used before the polar angle.
% Choice which determines where the complex root symbol is printed relative
% to the numbers. The standard setting is |after-number|.
% \end{function}
%
% \begin{function}{complex-symbol-degree}
Expand Down Expand Up @@ -253,8 +254,8 @@
% \l_@@_root_after_bool ,
% \l_@@_force_cartesian_bool ,
% \l_@@_force_polar_bool ,
% \l_@@_phase_tl ,
% \l_@@_polar_degree_bool ,
% \l_@@_symbol_angle_tl ,
% \l_@@_symbol_degree_tl ,
% \l_@@_input_root_tl ,
% \l_@@_output_root_tl
Expand Down Expand Up @@ -287,13 +288,13 @@
{ \bool_set_true:N \l_@@_polar_degree_bool } ,
complex-angle-unit / radians .code:n =
{ \bool_set_false:N \l_@@_polar_degree_bool } ,
complex-phase-command .tl_set:N =
\l_@@_phase_tl ,
complex-root-position .choice: ,
complex-root-position / after-number .code:n =
{ \bool_set_true:N \l_@@_root_after_bool } ,
complex-root-position / before-number .code:n =
{ \bool_set_false:N \l_@@_root_after_bool } ,
complex-symbol-angle .tl_set:N =
\l_@@_symbol_angle_tl ,
complex-symbol-degree .tl_set:N =
\l_@@_symbol_degree_tl ,
input-complex-root .tl_set:N =
Expand Down Expand Up @@ -1028,6 +1029,7 @@
% \@@_format_extract-exponent:n ,
% \@@_format_polar_input:n
% }
% \begin{macro}{\@@_format_phase:}
% We see similar ideas here to the Cartesian versions, but with only
% the magnitude to adjust, things are rather simpler in the exponent
% manipulations.
Expand All @@ -1054,16 +1056,7 @@
{ \exp_not:V \l_@@_mag_tl }
}
\siunitx_print_number:V \l_@@_tmp_tl
\siunitx_print_unit:V \l_@@_symbol_angle_tl
\group_begin:
\bool_if:NTF \l_@@_polar_degree_bool
{
\exp_args:NV \siunitx_unit_options_apply:n \l_@@_symbol_degree_tl
\siunitx_unit_format:VN \l_@@_symbol_degree_tl \l_@@_tmp_tl
}
{ \tl_clear:N \l_@@_tmp_tl }
\siunitx_quantity_print:VV \l_@@_angle_tl \l_@@_tmp_tl
\group_end:
\l_@@_phase_tl { \@@_format_phase: }
\siunitx_quantity_print:nV { } \l_@@_unit_tl
}
\cs_new_protected:cpn { @@_format_polar_combine-exponent:n } #1
Expand All @@ -1088,8 +1081,21 @@
{ \siunitx_number_process:NN \l_@@_mag_tl \l_@@_mag_tl }
\siunitx_unit_format:nN {#1} \l_@@_unit_tl
}
\cs_new_protected:Npn \@@_format_phase:
{
\group_begin:
\bool_if:NTF \l_@@_polar_degree_bool
{
\exp_args:NV \siunitx_unit_options_apply:n \l_@@_symbol_degree_tl
\siunitx_unit_format:VN \l_@@_symbol_degree_tl \l_@@_tmp_tl
}
{ \tl_clear:N \l_@@_tmp_tl }
\siunitx_quantity_print:VV \l_@@_angle_tl \l_@@_tmp_tl
\group_end:
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Conversion}
%
Expand Down Expand Up @@ -1249,6 +1255,21 @@
}
% \end{macrocode}
%
% \subsection{Deprecated options}
%
% \begin{macrocode}
\keys_define:nn { siunitx }
{
complex-symbol-angle .code:n =
{
\msg_info:nnnn { siunitx } { option-deprecated }
{ number-angle-product }
{ complex-phase-command }
complex-phase-command = {#1}
}
}
% \end{macrocode}
%
% \subsection{Standard settings for module options}
%
% Some of these follow naturally from the point of definition
Expand All @@ -1257,13 +1278,13 @@
% \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-phase-command = \ensuremath { \angle } ,
complex-symbol-degree = \degree ,
input-complex-root = ij ,
output-complex-root = \mathrm { i } ,
print-complex-unity = false
}
% \end{macrocode}
Expand Down
17 changes: 10 additions & 7 deletions siunitx.tex
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
\usepackage{cancel}
\usepackage{collcell}
\usepackage{sansmath}
\usepackage{steinmetz}
\newlength{\mylength}

% For creating code demonstrations
Expand Down Expand Up @@ -2227,8 +2228,8 @@ \subsection{Complex numbers}
\midrule
complex-angle-unit & Choice & degrees \\
complex-mode & Choice & input \\
complex-phase-command & Literal & \cs{angle} \\
complex-root-position & Choice & after-number \\
complex-symbol-angle & Literal & \cs{angle} \\
complex-symbol-degree & Literal & \cs{degree} \\
input-complex-root & Literal & ij \\
output-complex-root & Literal & \verb=\mathrm{i}= \\
Expand Down Expand Up @@ -2285,18 +2286,19 @@ \subsection{Complex numbers}
\end{LaTeXdemo}

\DescribeOption{complex-angle-unit}
\DescribeOption{complex-symbol-angle}
\DescribeOption{complex-symbol-degree}
\DescribeOption{complex-phase-command}
When printing or converting to polar form, the angle may be interpreted in
units set by \opt{complex-angle-unit}: one of \opt{degrees} or \opt{radians}.
The symbol used to denote the angle, and that used for units of degrees,
are controlled by the options \opt{complex-symbol-angle} and
\opt{complex-symbol-degree}, respectively.
The unit symbol used for degrees is controlled by \opt{complex-symbol-degree}.
To allow control of the surrounding of the entire phase part, the option
\opt{complex-phase-command} is available. This can be used for example to
print using Steinmetz notation (which requires the \pkg{steinmetz} package).
\begin{LaTeXdemo}
\complexqty{1:1}{\ohm} \\
\complexqty[complex-angle-unit = radians]{1:1}{\ohm} \\
\complexqty[complex-symbol-angle = \mathrm{A}]{1:1}{\ohm} \\
\complexqty[complex-symbol-degree = d]{1:1}{\ohm}
\complexqty[complex-symbol-degree = d]{1:1}{\ohm} \\
\complexqty[complex-phase-command = \phase]{1:1}{\ohm}
\end{LaTeXdemo}

\DescribeOption{print-complex-unity}
Expand Down Expand Up @@ -3337,6 +3339,7 @@ \subsection{Version~\version{3.4}}
\item Combination of all control for angle unit formatting into
\cs{degree}, \cs{arcminute} and \cs{arcsecond} unit macros,
with \opt{number-angle-product} deprecated
\item Support for more varied printing of complex numbers phases
\end{itemize}

\section{Upgrading from version~\version{2}%
Expand Down
Loading

0 comments on commit f71d749

Please sign in to comment.