| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% File: siunitx.dtx Copyright (C) 2008-2019,2021-2026 Joseph Wright |
| 4 |
% |
| 5 |
% It may be distributed and/or modified under the conditions of the |
| 6 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 7 |
% license or (at your option) any later version. The latest version |
| 8 |
% of this license is in the file |
| 9 |
% |
| 10 |
% https://www.latex-project.org/lppl.txt |
| 11 |
% |
| 12 |
% This file is part of the "siunitx bundle" (The Work in LPPL) |
| 13 |
% and all files in that bundle must be distributed together. |
| 14 |
% |
| 15 |
% The released version of this bundle is available from CTAN. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/josephwright/siunitx |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
% |
| 25 |
% ----------------------------------------------------------------------- |
| 26 |
% |
| 27 |
%<*driver> |
| 28 |
\documentclass{l3doc} |
| 29 |
% Additional commands needed in this source |
| 30 |
\ProvideDocumentCommand\email{m}{\href{mailto:#1}{\nolinkurl{#1}}} |
| 31 |
\ProvideDocumentCommand\version{m}{\ensuremath{#1}} |
| 32 |
% Tidy up the above in bookmarks |
| 33 |
\makeatletter |
| 34 |
\pdfstringdefDisableCommands{% |
| 35 |
\let\version\@firstofone |
| 36 |
} |
| 37 |
\makeatother |
| 38 |
% The next line is needed so that \GetFileInfo will be able to pick up |
| 39 |
% version data |
| 40 |
\usepackage{siunitx} |
| 41 |
\begin{document} |
| 42 |
\DocInput{\jobname.dtx} |
| 43 |
\end{document} |
| 44 |
%</driver> |
| 45 |
% \fi |
| 46 |
% |
| 47 |
% \GetFileInfo{siunitx.sty} |
| 48 |
% |
| 49 |
% \title{^^A |
| 50 |
% \pkg{siunitx} -- Overall set up^^A |
| 51 |
% \thanks{This file describes \fileversion, |
| 52 |
% last revised \filedate.}^^A |
| 53 |
% } |
| 54 |
% |
| 55 |
% \author{^^A |
| 56 |
% Joseph Wright^^A |
| 57 |
% \thanks{^^A |
| 58 |
% E-mail: |
| 59 |
% \email{[email protected]}^^A |
| 60 |
% }^^A |
| 61 |
% } |
| 62 |
% |
| 63 |
% \date{Released \filedate} |
| 64 |
% |
| 65 |
% \maketitle |
| 66 |
% |
| 67 |
% \begin{documentation} |
| 68 |
% |
| 69 |
% ^^A API documentation is given on a per-module basis: |
| 70 |
% ^^A see the siunitx-<module>.dtx files |
| 71 |
% |
| 72 |
% \end{documentation} |
| 73 |
% |
| 74 |
% \begin{implementation} |
| 75 |
% |
| 76 |
% \section{\pkg{siunitx} implementation} |
| 77 |
% |
| 78 |
% Start the \pkg{DocStrip} guards. |
| 79 |
% \begin{macrocode} |
| 80 |
%<*package> |
| 81 |
% \end{macrocode} |
| 82 |
% |
| 83 |
% Identify the internal prefix. |
| 84 |
% \begin{macrocode} |
| 85 |
%<@@=siunitx> |
| 86 |
% \end{macrocode} |
| 87 |
% |
| 88 |
% \begin{macrocode} |
| 89 |
%<*init> |
| 90 |
% \end{macrocode} |
| 91 |
% |
| 92 |
% \subsection{Provide a kernel command} |
| 93 |
% |
| 94 |
% \begin{macro}{\IfFormatAtLeastTF} |
| 95 |
% Not present in older kernels: use the \LaTeXe{} mechanism as this is correct |
| 96 |
% for this case. |
| 97 |
% \begin{macrocode} |
| 98 |
\providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion} |
| 99 |
% \end{macrocode} |
| 100 |
% \end{macro} |
| 101 |
% |
| 102 |
% \subsection{Initial set up} |
| 103 |
% |
| 104 |
% \begin{macrocode} |
| 105 |
\IfFormatAtLeastTF{2022-11-01} |
| 106 |
{} |
| 107 |
{% |
| 108 |
\PackageError{siunitx}{LaTeX kernel too old} |
| 109 |
{% |
| 110 |
You need a newer LaTeX to use this release of siunitx.\MessageBreak |
| 111 |
Loading~siunitx~will~abort!% |
| 112 |
}% |
| 113 |
\endinput |
| 114 |
} |
| 115 |
% \end{macrocode} |
| 116 |
% |
| 117 |
% Allow rollback to version~\version{2}: if we need to, version~\version{1} |
| 118 |
% could eventually be added here too. |
| 119 |
% \begin{macrocode} |
| 120 |
\DeclareRelease{2}{2010-05-23}{siunitx-v2.sty} |
| 121 |
\DeclareRelease{v2}{2010-05-23}{siunitx-v2.sty} |
| 122 |
\DeclareCurrentRelease{}{2021-05-17} |
| 123 |
% \end{macrocode} |
| 124 |
% |
| 125 |
% Make sure that the version of \pkg{l3kernel} in use is sufficiently new. |
| 126 |
% We use \cs{ExplFileDate} as \cs{@ifpackagelater} doesn't work for pre-loaded |
| 127 |
% \pkg{expl3} in the absence of the package. |
| 128 |
% \begin{macrocode} |
| 129 |
\@ifl@t@r\ExplLoaderFileDate{2023-10-10} |
| 130 |
{} |
| 131 |
{% |
| 132 |
\PackageError{siunitx}{Support package expl3 too old} |
| 133 |
{% |
| 134 |
You need to update your installation of 'l3kernel'.\MessageBreak |
| 135 |
Loading~siunitx~will~abort!% |
| 136 |
}% |
| 137 |
\endinput |
| 138 |
}% |
| 139 |
% \end{macrocode} |
| 140 |
% |
| 141 |
% Identify the package and give the over all version information. |
| 142 |
% \begin{macrocode} |
| 143 |
\ProvidesExplPackage {siunitx} {2026-05-15} {3.5.5} |
| 144 |
{A comprehensive (SI) units package} |
| 145 |
% \end{macrocode} |
| 146 |
% |
| 147 |
% \subsection{Safety checks} |
| 148 |
% |
| 149 |
% \begin{macro}{\@@_load_check:} |
| 150 |
% There are a number of packages that are incompatible with \pkg{siunitx} |
| 151 |
% as they cover the same concepts and in some cases define the same command |
| 152 |
% names. These are all tested at the point of loading to try to trap |
| 153 |
% issues, and a couple are also tested later as it's possible for them to |
| 154 |
% load without an obvious error if \pkg{siunitx} was loaded first. |
| 155 |
% \begin{macrocode} |
| 156 |
\msg_new:nnnn { siunitx } { incompatible-package } |
| 157 |
{ Package~'#1'~incompatible. } |
| 158 |
{ The~#1~package~and~siunitx~are~incompatible. } |
| 159 |
\cs_new_protected:Npn \@@_load_check:n #1 |
| 160 |
{ |
| 161 |
\@ifpackageloaded {#1} |
| 162 |
{ \msg_error:nne { siunitx } { incompatible-package } {#1} } |
| 163 |
{ } |
| 164 |
} |
| 165 |
\clist_map_function:nN |
| 166 |
{ SIunits , sistyle , units , unitsdef , fancyunits } |
| 167 |
\@@_load_check:n |
| 168 |
\AtBeginDocument |
| 169 |
{ |
| 170 |
\clist_map_function:nN { SIunits , sistyle , units } |
| 171 |
\@@_load_check:n |
| 172 |
} |
| 173 |
% \end{macrocode} |
| 174 |
%\end{macro} |
| 175 |
% |
| 176 |
% \subsection{Top-level scratch space} |
| 177 |
% |
| 178 |
% \begin{macro}{\l_@@_tmp_tl} |
| 179 |
% Scratch space for the interfaces. |
| 180 |
% \begin{macrocode} |
| 181 |
\tl_new:N \l_@@_tmp_tl |
| 182 |
% \end{macrocode} |
| 183 |
% \end{macro} |
| 184 |
% |
| 185 |
% \begin{macrocode} |
| 186 |
%</init> |
| 187 |
% \end{macrocode} |
| 188 |
% |
| 189 |
% \begin{macrocode} |
| 190 |
%<*options> |
| 191 |
% \end{macrocode} |
| 192 |
% |
| 193 |
% \subsection{Load time options} |
| 194 |
% |
| 195 |
% \begin{variable} |
| 196 |
% { |
| 197 |
% \l_@@_v2_options_bool , |
| 198 |
% \l_@@_v2_cmds_bool , |
| 199 |
% \l_@@_list_tl , |
| 200 |
% \l_@@_product_tl , |
| 201 |
% \l_@@_column_type_tl |
| 202 |
% } |
| 203 |
% \begin{macrocode} |
| 204 |
\keys_define:nn { siunitx } |
| 205 |
{ |
| 206 |
disable-deprecated-options .bool_set:N = |
| 207 |
\l_@@_disable_options_bool , |
| 208 |
disable-deprecated-options .usage:n = |
| 209 |
load , |
| 210 |
disable-deprecated-commands .bool_set:N = |
| 211 |
\l_@@_disable_cmds_bool , |
| 212 |
disable-deprecated-commands .usage:n = |
| 213 |
load , |
| 214 |
list-input-separator .tl_set:N = |
| 215 |
\l_@@_list_tl , |
| 216 |
list-input-separator .usage:n = |
| 217 |
load , |
| 218 |
product-input-separator .tl_set:N = |
| 219 |
\l_@@_product_tl , |
| 220 |
product-input-separator .usage:n = |
| 221 |
load , |
| 222 |
table-column-type .tl_set:N = |
| 223 |
\l_@@_column_type_tl , |
| 224 |
table-column-type .usage:n = |
| 225 |
load |
| 226 |
} |
| 227 |
\keys_set:nn { siunitx } |
| 228 |
{ |
| 229 |
disable-deprecated-options = false , |
| 230 |
disable-deprecated-commands = false , |
| 231 |
list-input-separator = ; , |
| 232 |
product-input-separator = x , |
| 233 |
table-column-type = S |
| 234 |
} |
| 235 |
% \end{macrocode} |
| 236 |
% \end{variable} |
| 237 |
% |
| 238 |
% \subsection{Option handling} |
| 239 |
% |
| 240 |
% Some messages. |
| 241 |
% \begin{macrocode} |
| 242 |
\msg_new:nnn { siunitx } { option-deprecated } |
| 243 |
{ |
| 244 |
Option~"#1"~has~been~deprecated~in~this~release.\\ \\ |
| 245 |
Use~"#2"~as~a~replacement. |
| 246 |
} |
| 247 |
% \end{macrocode} |
| 248 |
% |
| 249 |
% \begin{variable}{\g_@@_deprecated_seq} |
| 250 |
% Used to avoid repeatedly warning about deprecated options: needed at the |
| 251 |
% top level. |
| 252 |
% \begin{macrocode} |
| 253 |
\seq_new:N \g_@@_deprecated_seq |
| 254 |
% \end{macrocode} |
| 255 |
% \end{variable} |
| 256 |
% |
| 257 |
% \begin{macro}{\@@_deprecated_info:nn} |
| 258 |
% To avoid repeated messages. |
| 259 |
% \begin{macrocode} |
| 260 |
\cs_new_protected:Npn \@@_deprecated_info:nn #1#2 |
| 261 |
{ |
| 262 |
\seq_if_in:NnF \g_@@_deprecated_seq {#1} |
| 263 |
{ \msg_info:nnnn { siunitx } { option-deprecated } {#1} {#2} } |
| 264 |
\seq_gput_right:Nn \g_@@_deprecated_seq {#1} |
| 265 |
} |
| 266 |
% \end{macrocode} |
| 267 |
% \end{macro} |
| 268 |
% |
| 269 |
% \begin{macrocode} |
| 270 |
\ProcessKeyOptions |
| 271 |
% \end{macrocode} |
| 272 |
% |
| 273 |
% \begin{macro}{\@@_option_deprecated:nn} |
| 274 |
% \begin{macro}{\@@_option_deprecated:nnn} |
| 275 |
% Rather than list all of the older options, simply redirect to a warning. |
| 276 |
% \begin{macrocode} |
| 277 |
\bool_if:NT \l_@@_disable_options_bool |
| 278 |
{ |
| 279 |
\cs_set_protected:Npn \@@_option_deprecated:nn #1#2 |
| 280 |
{ \@@_option_removed:n {#1} } |
| 281 |
\cs_set_protected:Npn \@@_option_deprecated:nnn #1#2#3 |
| 282 |
{ \@@_option_removed:n {#1} } |
| 283 |
} |
| 284 |
% \end{macrocode} |
| 285 |
% \end{macro} |
| 286 |
% \end{macro} |
| 287 |
% |
| 288 |
% \begin{macrocode} |
| 289 |
%</options> |
| 290 |
% \end{macrocode} |
| 291 |
% |
| 292 |
% \subsection{User interfaces} |
| 293 |
% |
| 294 |
% \begin{macrocode} |
| 295 |
%<*interfaces> |
| 296 |
% \end{macrocode} |
| 297 |
% |
| 298 |
% The user interfaces are defined in terms of documented code-level ones. |
| 299 |
% This is all done here, and will appear in the \file{.sty} file before the |
| 300 |
% relevant code. Things could be re-arranged by \pkg{DocStrip} but there is no |
| 301 |
% advantage. |
| 302 |
% |
| 303 |
% \subsubsection{Preamble commands} |
| 304 |
% |
| 305 |
% \begin{macro} |
| 306 |
% { |
| 307 |
% \DeclareSIPower , |
| 308 |
% \DeclareSIPrefix , |
| 309 |
% \DeclareSIQualifier , |
| 310 |
% \DeclareSIUnit |
| 311 |
% } |
| 312 |
% Pass data to the code layer. |
| 313 |
% \begin{macrocode} |
| 314 |
\NewDocumentCommand \DeclareSIPower { +m +m m } |
| 315 |
{ |
| 316 |
\siunitx_declare_power:NNn #1 #2 {#3} |
| 317 |
} |
| 318 |
\NewDocumentCommand \DeclareSIPrefix { +m m m } |
| 319 |
{ |
| 320 |
\siunitx_declare_prefix:Nnn #1 {#3} {#2} |
| 321 |
} |
| 322 |
\NewDocumentCommand \DeclareSIQualifier { +m m } |
| 323 |
{ |
| 324 |
\siunitx_declare_qualifier:Nn #1 {#2} |
| 325 |
} |
| 326 |
\NewDocumentCommand \DeclareSIUnit { o +m m } |
| 327 |
{ |
| 328 |
\IfNoValueTF {#1} |
| 329 |
{ \siunitx_declare_unit:Nn #2 {#3} } |
| 330 |
{ \siunitx_declare_unit:Nnn #2 {#3} {#1} } |
| 331 |
} |
| 332 |
% \end{macrocode} |
| 333 |
% \end{macro} |
| 334 |
% |
| 335 |
% \subsubsection{Document commands} |
| 336 |
% |
| 337 |
% \begin{macro}{\qty} |
| 338 |
% \begin{macrocode} |
| 339 |
\AtBeginDocument |
| 340 |
{ |
| 341 |
\@ifpackageloaded { physics } |
| 342 |
{ |
| 343 |
\msg_new:nnn { siunitx } { physics-pkg } |
| 344 |
{ |
| 345 |
Detected~the~"physics"~package: \\ |
| 346 |
omitting~definition~of~\token_to_str:N \qty. |
| 347 |
\\ \\ |
| 348 |
If~you~want~to~use~\qty with~the~siunitx~definition,~add~ |
| 349 |
\\ \\ |
| 350 |
\iow_indent:n |
| 351 |
{ |
| 352 |
\token_to_str:N \AtBeginDocument |
| 353 |
{ |
| 354 |
\token_to_str:N \RenewCommandCopy |
| 355 |
\token_to_str:N \qty \token_to_str:N \SI |
| 356 |
} |
| 357 |
} |
| 358 |
\\ \\ |
| 359 |
to~your~preamble. |
| 360 |
} |
| 361 |
\msg_warning:nn { siunitx } { physics-pkg } |
| 362 |
} |
| 363 |
{ } |
| 364 |
} |
| 365 |
\@ifpackageloaded { physics } |
| 366 |
{ \use_none:nnnn } |
| 367 |
{ } |
| 368 |
\NewDocumentCommand \qty { O { } m > { \TrimSpaces } m } |
| 369 |
{ |
| 370 |
\mode_leave_vertical: |
| 371 |
\group_begin: |
| 372 |
\siunitx_unit_options_apply:n {#3} |
| 373 |
\keys_set:nn { siunitx } {#1} |
| 374 |
\siunitx_quantity:nn {#2} {#3} |
| 375 |
\group_end: |
| 376 |
} |
| 377 |
% \end{macrocode} |
| 378 |
% \end{macro} |
| 379 |
% |
| 380 |
% \begin{macro}{\ang, \duration, \num, \unit} |
| 381 |
% All of a standard form: start a paragraph (if required), set local |
| 382 |
% key values, do the formatting, print the result. |
| 383 |
% \begin{macrocode} |
| 384 |
\NewDocumentCommand \ang { O { } > { \SplitArgument { 2 } { ; } } m } |
| 385 |
{ |
| 386 |
\mode_leave_vertical: |
| 387 |
\group_begin: |
| 388 |
\keys_set:nn { siunitx } {#1} |
| 389 |
\@@_angle:nnn #2 |
| 390 |
\group_end: |
| 391 |
} |
| 392 |
\NewDocumentCommand \duration { O { } > { \SplitArgument { 2 } { ; } } m } |
| 393 |
{ |
| 394 |
\mode_leave_vertical: |
| 395 |
\group_begin: |
| 396 |
\keys_set:nn { siunitx } {#1} |
| 397 |
\@@_duration:nnn #2 |
| 398 |
\group_end: |
| 399 |
} |
| 400 |
\NewDocumentCommand \num { O { } m } |
| 401 |
{ |
| 402 |
\mode_leave_vertical: |
| 403 |
\group_begin: |
| 404 |
\keys_set:nn { siunitx } {#1} |
| 405 |
\siunitx_number_format:nN {#2} \l_@@_tmp_tl |
| 406 |
\siunitx_print_number:V \l_@@_tmp_tl |
| 407 |
\group_end: |
| 408 |
} |
| 409 |
\NewDocumentCommand \unit { O { } > { \TrimSpaces } m } |
| 410 |
{ |
| 411 |
\mode_leave_vertical: |
| 412 |
\group_begin: |
| 413 |
\siunitx_unit_options_apply:n {#2} |
| 414 |
\keys_set:nn { siunitx } {#1} |
| 415 |
\siunitx_unit_format:nN {#2} \l_@@_tmp_tl |
| 416 |
\siunitx_print_unit:V \l_@@_tmp_tl |
| 417 |
\group_end: |
| 418 |
} |
| 419 |
% \end{macrocode} |
| 420 |
% \end{macro} |
| 421 |
% |
| 422 |
% \begin{macro} |
| 423 |
% {\qtylist, \numlist, \qtyproduct, \numproduct, \qtyrange, \numproduct} |
| 424 |
% Interfaces for compound values. |
| 425 |
% \begin{macrocode} |
| 426 |
\ExpandArgs { Ne } \NewDocumentCommand \qtylist |
| 427 |
{ |
| 428 |
O { } |
| 429 |
> { \SplitList { \exp_not:V \l_@@_list_tl } } m |
| 430 |
> { \TrimSpaces } m |
| 431 |
} |
| 432 |
{ |
| 433 |
\mode_leave_vertical: |
| 434 |
\group_begin: |
| 435 |
\siunitx_unit_options_apply:n {#3} |
| 436 |
\keys_set:nn { siunitx } {#1} |
| 437 |
\siunitx_quantity_list:nn {#2} {#3} |
| 438 |
\group_end: |
| 439 |
} |
| 440 |
\ExpandArgs { Ne } \NewDocumentCommand \numlist |
| 441 |
{ |
| 442 |
O { } |
| 443 |
> { \SplitList { \exp_not:V \l_@@_list_tl } } m |
| 444 |
} |
| 445 |
{ |
| 446 |
\mode_leave_vertical: |
| 447 |
\group_begin: |
| 448 |
\keys_set:nn { siunitx } {#1} |
| 449 |
\siunitx_number_list:n {#2} |
| 450 |
\group_end: |
| 451 |
} |
| 452 |
\ExpandArgs { Ne } \NewDocumentCommand \qtyproduct |
| 453 |
{ |
| 454 |
O { } |
| 455 |
> { \SplitList { \exp_not:V \l_@@_product_tl } } m |
| 456 |
> { \TrimSpaces } m |
| 457 |
} |
| 458 |
{ |
| 459 |
\mode_leave_vertical: |
| 460 |
\group_begin: |
| 461 |
\siunitx_unit_options_apply:n {#3} |
| 462 |
\keys_set:nn { siunitx } {#1} |
| 463 |
\siunitx_quantity_product:nn {#2} {#3} |
| 464 |
\group_end: |
| 465 |
} |
| 466 |
\ExpandArgs { Ne } \NewDocumentCommand \numproduct |
| 467 |
{ |
| 468 |
O { } |
| 469 |
> { \SplitList { \exp_not:V \l_@@_product_tl } } m |
| 470 |
} |
| 471 |
{ |
| 472 |
\mode_leave_vertical: |
| 473 |
\group_begin: |
| 474 |
\keys_set:nn { siunitx } {#1} |
| 475 |
\siunitx_number_product:n {#2} |
| 476 |
\group_end: |
| 477 |
} |
| 478 |
\NewDocumentCommand \qtyrange { O { } m m > { \TrimSpaces } m } |
| 479 |
{ |
| 480 |
\mode_leave_vertical: |
| 481 |
\group_begin: |
| 482 |
\siunitx_unit_options_apply:n {#4} |
| 483 |
\keys_set:nn { siunitx } {#1} |
| 484 |
\siunitx_quantity_range:nnn {#2} {#3} {#4} |
| 485 |
\group_end: |
| 486 |
} |
| 487 |
\NewDocumentCommand \numrange { O { } m m } |
| 488 |
{ |
| 489 |
\mode_leave_vertical: |
| 490 |
\group_begin: |
| 491 |
\keys_set:nn { siunitx } {#1} |
| 492 |
\siunitx_number_range:nn {#2} {#3} |
| 493 |
\group_end: |
| 494 |
} |
| 495 |
% \end{macrocode} |
| 496 |
% \end{macro} |
| 497 |
% |
| 498 |
% \begin{macro}{\complexnum, \complexqty} |
| 499 |
% Interfaces for complex numbers. |
| 500 |
% \begin{macrocode} |
| 501 |
\ExpandArgs { Ne } \NewDocumentCommand \complexnum |
| 502 |
{ O { } > { \SplitArgument { 1 } { \c_colon_str } } m } |
| 503 |
{ |
| 504 |
\mode_leave_vertical: |
| 505 |
\group_begin: |
| 506 |
\keys_set:nn { siunitx } {#1} |
| 507 |
\@@_complex_number_aux:nn #2 |
| 508 |
\group_end: |
| 509 |
} |
| 510 |
\ExpandArgs { Ne } \NewDocumentCommand \complexqty |
| 511 |
{ O { } > { \SplitArgument { 1 } { \c_colon_str } } m m } |
| 512 |
{ |
| 513 |
\mode_leave_vertical: |
| 514 |
\group_begin: |
| 515 |
\siunitx_unit_options_apply:n {#3} |
| 516 |
\keys_set:nn { siunitx } {#1} |
| 517 |
\@@_complex_quantity_aux:nnn #2 {#3} |
| 518 |
\group_end: |
| 519 |
} |
| 520 |
% \end{macrocode} |
| 521 |
% \end{macro} |
| 522 |
% |
| 523 |
% \begin{macro}{\tablenum} |
| 524 |
% Slightly odd set up at present: we have to have the |\ignorespaces|. |
| 525 |
% \begin{macrocode} |
| 526 |
\NewDocumentCommand \tablenum { O { } m } |
| 527 |
{ |
| 528 |
\mode_leave_vertical: |
| 529 |
\group_begin: |
| 530 |
\keys_set:nn { siunitx } {#1} |
| 531 |
\siunitx_cell_begin:w |
| 532 |
\ignorespaces #2 |
| 533 |
\siunitx_cell_end: |
| 534 |
\group_end: |
| 535 |
} |
| 536 |
% \end{macrocode} |
| 537 |
% \end{macro} |
| 538 |
% |
| 539 |
% \begin{macro}{\sisetup} |
| 540 |
% A very thin wrapper. |
| 541 |
% \begin{macrocode} |
| 542 |
\NewDocumentCommand \sisetup { m } |
| 543 |
{ \keys_set:nn { siunitx } {#1} } |
| 544 |
% \end{macrocode} |
| 545 |
% \end{macro} |
| 546 |
% |
| 547 |
% \subsection{\enquote{Glue} commands} |
| 548 |
% |
| 549 |
% \begin{macro}{\@@_angle:nnn, \@@_duration:nnn} |
| 550 |
% The document level interface for \cs{ang} and \cs{duration} need some |
| 551 |
% \enquote{glue} to work with the code-level API. |
| 552 |
% \begin{macrocode} |
| 553 |
\cs_new_protected:Npn \@@_angle:nnn #1#2#3 |
| 554 |
{ |
| 555 |
\tl_if_novalue:nTF {#2} |
| 556 |
{ \siunitx_angle:n {#1} } |
| 557 |
{ |
| 558 |
\tl_if_novalue:nTF {#3} |
| 559 |
{ \siunitx_angle:nnn {#1} {#2} { } } |
| 560 |
{ \siunitx_angle:nnn {#1} {#2} {#3} } |
| 561 |
} |
| 562 |
} |
| 563 |
\cs_new_protected:Npn \@@_duration:nnn #1#2#3 |
| 564 |
{ |
| 565 |
\tl_if_novalue:nTF {#2} |
| 566 |
{ \siunitx_duration:n {#1} } |
| 567 |
{ |
| 568 |
\tl_if_novalue:nTF {#3} |
| 569 |
{ \siunitx_duration:nnn {#1} {#2} { } } |
| 570 |
{ \siunitx_duration:nnn {#1} {#2} {#3} } |
| 571 |
} |
| 572 |
} |
| 573 |
% \end{macrocode} |
| 574 |
% \end{macro} |
| 575 |
% |
| 576 |
% \begin{macro}{\@@_complex_number_aux:nn} |
| 577 |
% \begin{macro}{\@@_complex_quantity_aux:nnn} |
| 578 |
% The same idea for complex values. |
| 579 |
% \begin{macrocode} |
| 580 |
\cs_new_protected:Npn \@@_complex_number_aux:nn #1#2 |
| 581 |
{ |
| 582 |
\tl_if_novalue:nTF {#2} |
| 583 |
{ \siunitx_complex_number:n {#1} } |
| 584 |
{ \siunitx_complex_number:nn {#1} {#2} } |
| 585 |
} |
| 586 |
\cs_new_protected:Npn \@@_complex_quantity_aux:nnn #1#2#3 |
| 587 |
{ |
| 588 |
\tl_if_novalue:nTF {#2} |
| 589 |
{ \siunitx_complex_quantity:nn {#1} {#3} } |
| 590 |
{ \siunitx_complex_quantity:nnn {#1} {#2} {#3} } |
| 591 |
} |
| 592 |
% \end{macrocode} |
| 593 |
% \end{macro} |
| 594 |
% \end{macro} |
| 595 |
% |
| 596 |
% \subsection{Table column} |
| 597 |
% |
| 598 |
% User interfaces in tabular constructs are provided using the mechanisms from |
| 599 |
% the \pkg{array} package. |
| 600 |
% \begin{macrocode} |
| 601 |
\RequirePackage { array } |
| 602 |
% \end{macrocode} |
| 603 |
% |
| 604 |
% \begin{macro}{\@@_declare_column:Nnn} |
| 605 |
% Creating numerical columns requires that these are declared before anything |
| 606 |
% else in \cs{NC@list}: this is necessary to work with optional arguments. |
| 607 |
% This means a bit of manual effort after the simple declaration of a new |
| 608 |
% column type. |
| 609 |
% \begin{macrocode} |
| 610 |
\cs_new_protected:Npn \@@_declare_column:Nnn #1#2#3 |
| 611 |
{ |
| 612 |
\cs_if_exist:cT { NC@find@ #1 } |
| 613 |
{ |
| 614 |
\cs_undefine:c { NC@find@ #1 } |
| 615 |
\cs_set_protected:Npn \@@_tmp:w ##1 \NC@do #1 ##2 \q_stop |
| 616 |
{ \NC@list {##1##2} } |
| 617 |
\exp_after:wN \@@_tmp:w \the \NC@list \q_stop |
| 618 |
\msg_warning:nnn { siunitx } { column-overwritten } {#1} |
| 619 |
} |
| 620 |
\newcolumntype {#1} { } |
| 621 |
\cs_set_protected:Npn \@@_tmp:w \NC@do ##1##2 \NC@do #1 |
| 622 |
{ \NC@list { \NC@do ##1 \NC@do #1 ##2 } } |
| 623 |
\exp_after:wN \@@_tmp:w \the \NC@list |
| 624 |
\ExpandArgs { Nc } \renewcommand * { NC@rewrite@ #1 } [ 1 ] [ ] |
| 625 |
{ |
| 626 |
\@temptokena \expandafter |
| 627 |
{ |
| 628 |
\the \@temptokena |
| 629 |
> {#2} c < {#3} |
| 630 |
} |
| 631 |
\NC@find |
| 632 |
} |
| 633 |
} |
| 634 |
\msg_new:nnn { siunitx } { column-overwritten } |
| 635 |
{ Tabular~column~type~"#1"~overwritten~with~siunitx~definition. } |
| 636 |
% \end{macrocode} |
| 637 |
% When \pkg{mdwtab} is loaded the syntax required is slightly different. |
| 638 |
% \begin{macrocode} |
| 639 |
\AtBeginDocument |
| 640 |
{ |
| 641 |
\@ifpackageloaded { mdwtab } |
| 642 |
{ |
| 643 |
\cs_set_protected:Npn \@@_declare_column:Nnn #1#2#3 |
| 644 |
{ |
| 645 |
\cs_if_exist:cT { NC@find@ #1 } |
| 646 |
{ |
| 647 |
\cs_undefine:c { NC@find@ #1 } |
| 648 |
\msg_warning:nnn { siunitx } { column-overwritten } {#1} |
| 649 |
} |
| 650 |
\newcolumntype {#1} [ 1 ] [ ] |
| 651 |
{ > {#2} c < {#3} } |
| 652 |
} |
| 653 |
} |
| 654 |
{ } |
| 655 |
\tl_map_inline:Nn \l_@@_column_type_tl |
| 656 |
{ |
| 657 |
\@@_declare_column:Nnn #1 |
| 658 |
{ |
| 659 |
\keys_set:nn { siunitx } {##1} |
| 660 |
\siunitx_cell_begin:w |
| 661 |
} |
| 662 |
{ \siunitx_cell_end: } |
| 663 |
} |
| 664 |
} |
| 665 |
% \end{macrocode} |
| 666 |
% \end{macro} |
| 667 |
% |
| 668 |
% \subsection{Document commands in bookmarks} |
| 669 |
% |
| 670 |
% In bookmarks, the \pkg{siunitx} document commands need to produce simple |
| 671 |
% strings that represent their input as far as possible. |
| 672 |
% |
| 673 |
% \begin{macro}{\@@_bookmark_cmd:Nn} |
| 674 |
% To keep things fast, expandable versions of the document command are |
| 675 |
% created only once. As here we are at the top-level for internal names, |
| 676 |
% we can use the various parts of \pkg{siunitx-compound} that would otherwise |
| 677 |
% be inaccessible. |
| 678 |
% \begin{macrocode} |
| 679 |
\cs_new_protected:Npn \@@_bookmark_cmd:Nnn #1#2#3 |
| 680 |
{ |
| 681 |
\ExpandArgs { c } \DeclareExpandableDocumentCommand |
| 682 |
{ \cs_to_str:N #1 \c_space_tl ( pdfstring ~ context ) } |
| 683 |
{#2} {#3} |
| 684 |
} |
| 685 |
\@@_bookmark_cmd:Nnn \qty { o m m } { #2 ~ #3 } |
| 686 |
\@@_bookmark_cmd:Nnn \ang { m } { \@@_angle:n {#1} } |
| 687 |
\@@_bookmark_cmd:Nnn \duration { m } { \@@_duration:n {#1} } |
| 688 |
\@@_bookmark_cmd:Nnn \num { o m } { #2 } |
| 689 |
\@@_bookmark_cmd:Nnn \unit { o m } { #2 } |
| 690 |
\@@_bookmark_cmd:Nnn \numlist { o m } |
| 691 |
{ |
| 692 |
\@@_list_use:nnVVV {#2} { } |
| 693 |
\l_siunitx_list_separator_pair_tl |
| 694 |
\l_siunitx_list_separator_tl |
| 695 |
\l_siunitx_list_separator_final_tl |
| 696 |
} |
| 697 |
\@@_bookmark_cmd:Nnn \qtylist { o m m } |
| 698 |
{ |
| 699 |
\@@_list_use:nnVVV {#2} {#3} |
| 700 |
\l_siunitx_list_separator_pair_tl |
| 701 |
\l_siunitx_list_separator_tl |
| 702 |
\l_siunitx_list_separator_final_tl |
| 703 |
} |
| 704 |
\@@_bookmark_cmd:Nnn \numproduct { o m } { } |
| 705 |
\@@_bookmark_cmd:Nnn \qtyproduct { o m m } { } |
| 706 |
\@@_bookmark_cmd:Nnn \numrange { o m m } |
| 707 |
{ #2 \tl_use:N \l_siunitx_range_phrase_tl #3 } |
| 708 |
\@@_bookmark_cmd:Nnn \qtyrange { o m m m } |
| 709 |
{ #2 ~ #4 \tl_use:N \l_siunitx_range_phrase_tl #3 ~ #4 } |
| 710 |
% \end{macrocode} |
| 711 |
% \end{macro} |
| 712 |
% We also need the v2 names. |
| 713 |
% \begin{macrocode} |
| 714 |
\@@_bookmark_cmd:Nnn \si { o m } { #2 } |
| 715 |
\@@_bookmark_cmd:Nnn \SI { o m O { } m } { #3 #2 ~ #4 } |
| 716 |
\@@_bookmark_cmd:Nnn \SIlist { o m m } |
| 717 |
{ |
| 718 |
\@@_list_use:nnVVV {#2} {#3} |
| 719 |
\l_siunitx_list_separator_pair_tl |
| 720 |
\l_siunitx_list_separator_tl |
| 721 |
\l_siunitx_list_separator_final_tl |
| 722 |
} |
| 723 |
\@@_bookmark_cmd:Nnn \SIrange { o m m m } |
| 724 |
{ #2 ~ #4 \tl_use:N \l_siunitx_range_phrase_tl #3 ~ #4 } |
| 725 |
% \end{macrocode} |
| 726 |
% |
| 727 |
% \begin{variable}{\c_@@_bookmark_seq} |
| 728 |
% Commands usable in bookmarks |
| 729 |
% \begin{macrocode} |
| 730 |
\seq_const_from_clist:Nn \c_@@_bookmark_seq |
| 731 |
{ |
| 732 |
\ang , \qty , \num , \unit , |
| 733 |
\numlist , \qtylist , |
| 734 |
\numrange , \qtyrange , |
| 735 |
\si , \SI , \SIlist , \SIrange |
| 736 |
} |
| 737 |
% \end{macrocode} |
| 738 |
% \end{variable} |
| 739 |
% |
| 740 |
% Activate the document commands here: the unit macros are handled in |
| 741 |
% \pkg{siunitx-final}. |
| 742 |
% \begin{macrocode} |
| 743 |
\AtBeginDocument |
| 744 |
{ |
| 745 |
\@ifpackageloaded { hyperref } |
| 746 |
{ |
| 747 |
\pdfstringdefDisableCommands |
| 748 |
{ |
| 749 |
\seq_map_inline:Nn \c_@@_bookmark_seq |
| 750 |
{ |
| 751 |
\ExpandArgs { Nc } \DeclareCommandCopy #1 |
| 752 |
{ \cs_to_str:N #1 \c_space_tl ( pdfstring ~ context ) } |
| 753 |
} |
| 754 |
} |
| 755 |
\pdfstringdefDisableCommands |
| 756 |
{ |
| 757 |
\siunitx_unit_pdfstring_context: |
| 758 |
\cs_if_exist:NT \FB@fg { \def \fg { \FB@fg } } |
| 759 |
\edef \H |
| 760 |
{ |
| 761 |
\exp_not:c { PU-cmd } |
| 762 |
\exp_not:N \H |
| 763 |
\exp_not:c { PU \token_to_str:N \H } |
| 764 |
} |
| 765 |
} |
| 766 |
} |
| 767 |
{ } |
| 768 |
} |
| 769 |
% \end{macrocode} |
| 770 |
% |
| 771 |
% \begin{macro}[EXP]{\@@_angle:n} |
| 772 |
% \begin{macro}[EXP]{\@@_duration:w} |
| 773 |
% Expandable splitting of the angle: simply enough, also outputs the |
| 774 |
% \begin{macrocode} |
| 775 |
\cs_new:Npn \@@_angle:n #1 |
| 776 |
{ \@@_angle:w #1 ; ; ; \q_stop } |
| 777 |
\cs_new:Npn \@@_angle:w #1 ; #2 ; #3 ; #4 \q_stop |
| 778 |
{ |
| 779 |
\tl_if_blank:nF {#1} |
| 780 |
{ #1 \degree } |
| 781 |
\tl_if_blank:nF {#2} |
| 782 |
{ |
| 783 |
\tl_if_blank:nF {#1} { \c_space_tl } |
| 784 |
#2 \arcminute |
| 785 |
} |
| 786 |
\tl_if_blank:nF {#3} |
| 787 |
{ |
| 788 |
\tl_if_blank:nF {#1#2} { \c_space_tl } |
| 789 |
#3 \arcsecond |
| 790 |
} |
| 791 |
} |
| 792 |
% \end{macrocode} |
| 793 |
% \end{macro} |
| 794 |
% \end{macro} |
| 795 |
% \begin{macro}[EXP]{\@@_duration:n} |
| 796 |
% \begin{macro}[EXP]{\@@_duration:w} |
| 797 |
% \begin{macrocode} |
| 798 |
\cs_new:Npn \@@_duration:n #1 |
| 799 |
{ \@@_angle:w #1 ; ; ; \q_stop } |
| 800 |
\cs_new:Npn \@@_duration:w #1 ; #2 ; #3 ; #4 \q_stop |
| 801 |
{ |
| 802 |
\tl_if_blank:nF {#1} |
| 803 |
{ #1 ~ \hour } |
| 804 |
\tl_if_blank:nF {#2} |
| 805 |
{ |
| 806 |
\tl_if_blank:nF {#1} { \c_space_tl } |
| 807 |
#2 ~ \minute |
| 808 |
} |
| 809 |
\tl_if_blank:nF {#3} |
| 810 |
{ |
| 811 |
\tl_if_blank:nF {#1#2} { \c_space_tl } |
| 812 |
#3 ~ \second |
| 813 |
} |
| 814 |
} |
| 815 |
% \end{macrocode} |
| 816 |
% \end{macro} |
| 817 |
% \end{macro} |
| 818 |
% |
| 819 |
% \begin{macro}[EXP] |
| 820 |
% {\@@_list_use:nnnnn, \@@_list_use:nnVVV, \@@_list_use_aux:nnnnn} |
| 821 |
% \begin{macro}[EXP]{\@@_list_use_auxi:w} |
| 822 |
% \begin{macro}[EXP]{\@@_list_use_auxii:nnw, \@@_list_use_auxiii:nnw} |
| 823 |
% \begin{macro}[EXP]{\@@_list_count:n} |
| 824 |
% \begin{macro}[EXP]{\@@_list_count:w} |
| 825 |
% Copies of the ideas in the \pkg{l3clist} module but using |;| as a list |
| 826 |
% separator. The functions have to be extended to allow for a unit argument. |
| 827 |
% \begin{macrocode} |
| 828 |
\cs_new:Npn \@@_list_use:nnnnn #1#2#3#4#5 |
| 829 |
{ |
| 830 |
\tl_if_blank:nTF {#2} |
| 831 |
{ \@@_list_use_aux:nnnnn {#1} { } } |
| 832 |
{ \@@_list_use_aux:nnnnn {#1} { ~ #2 } } |
| 833 |
{#3} {#4} {#5} |
| 834 |
} |
| 835 |
\cs_generate_variant:Nn \@@_list_use:nnnnn { nnVVV } |
| 836 |
\cs_new:Npn \@@_list_use_aux:nnnnn #1#2#3#4#5 |
| 837 |
{ |
| 838 |
\int_case:nnF { \@@_list_count:n {#1} } |
| 839 |
{ |
| 840 |
{ 0 } { } |
| 841 |
{ 1 } { \@@_list_use_auxi:nw {#2} #1 ; ; { } } |
| 842 |
{ 2 } { \@@_list_use_auxi:nw {#2} #1 ; {#3} } |
| 843 |
} |
| 844 |
{ |
| 845 |
\@@_list_use_auxii:nnw {#2} { } #1 ; |
| 846 |
\q_mark ; { \@@_list_use_auxii:nnw {#2} {#4} } |
| 847 |
\q_mark ; { \@@_list_use_auxiii:nnw {#2} {#5} } |
| 848 |
\q_stop { } |
| 849 |
} |
| 850 |
} |
| 851 |
\cs_new:Npn \@@_list_use_auxi:nw #1#2 ; #3 ; #4 |
| 852 |
{ #2 #1 #4 #3 \tl_if_blank:nF {#3} {#1} } |
| 853 |
\cs_new:Npn \@@_list_use_auxii:nnw |
| 854 |
#1#2#3 ; #4 ; #5 ; #6 \q_mark ; #7#8 \q_stop #9 |
| 855 |
{ #7 {#4} ; {#5} ; #6 \q_mark ; {#7} #8 \q_stop { #9 #2 #3 #1 } } |
| 856 |
\cs_new:Npn \@@_list_use_auxiii:nnw #1#2#3 ; #4 \q_stop #5 |
| 857 |
{ #5 #2 #3 #1 } |
| 858 |
\cs_new:Npe \@@_list_count:n #1 |
| 859 |
{ |
| 860 |
\exp_not:N \int_eval:n |
| 861 |
{ |
| 862 |
0 |
| 863 |
\exp_not:N \@@_list_count:w \c_space_tl |
| 864 |
#1 |
| 865 |
\exp_not:n { ; \s_stop \use_none_delimit_by_q_stop:w ; \q_stop } |
| 866 |
} |
| 867 |
} |
| 868 |
\cs_new:Npe \@@_list_count:w #1 ; |
| 869 |
{ |
| 870 |
\exp_not:N \use_none_delimit_by_s_stop:w #1 \exp_not:N \s_stop |
| 871 |
\exp_not:N \tl_if_blank:nF {#1} { + 1 } |
| 872 |
\exp_not:N \@@_list_count:w \c_space_tl |
| 873 |
} |
| 874 |
% \end{macrocode} |
| 875 |
% \end{macro} |
| 876 |
% \end{macro} |
| 877 |
% \end{macro} |
| 878 |
% \end{macro} |
| 879 |
% \end{macro} |
| 880 |
% |
| 881 |
% \begin{macrocode} |
| 882 |
%</interfaces> |
| 883 |
% \end{macrocode} |
| 884 |
% |
| 885 |
% \begin{macrocode} |
| 886 |
%</package> |
| 887 |
% \end{macrocode} |
| 888 |
% |
| 889 |
% \end{implementation} |
| 890 |
% |
| 891 |
% \PrintIndex |