| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% File: siunitx-compound.dtx Copyright (C) 2018-2021,2023-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\foreign{m}{\textit{#1}} |
| 32 |
% The next line is needed so that \GetFileInfo will be able to pick up |
| 33 |
% version data |
| 34 |
\usepackage{siunitx} |
| 35 |
\begin{document} |
| 36 |
\DocInput{\jobname.dtx} |
| 37 |
\end{document} |
| 38 |
%</driver> |
| 39 |
% \fi |
| 40 |
% |
| 41 |
% \GetFileInfo{siunitx.sty} |
| 42 |
% |
| 43 |
% \title{^^A |
| 44 |
% \pkg{siunitx-compound} -- Compound numbers and quantities^^A |
| 45 |
% \thanks{This file describes \fileversion, |
| 46 |
% last revised \filedate.}^^A |
| 47 |
% } |
| 48 |
% |
| 49 |
% \author{^^A |
| 50 |
% Joseph Wright^^A |
| 51 |
% \thanks{^^A |
| 52 |
% E-mail: |
| 53 |
% \email{[email protected]}^^A |
| 54 |
% }^^A |
| 55 |
% } |
| 56 |
% |
| 57 |
% \date{Released \filedate} |
| 58 |
% |
| 59 |
% \maketitle |
| 60 |
% |
| 61 |
% \begin{documentation} |
| 62 |
% |
| 63 |
% \section{Compound numbers and quantities} |
| 64 |
% |
| 65 |
% \begin{function}{\siunitx_compound_number:n} |
| 66 |
% \begin{syntax} |
| 67 |
% \cs{siunitx_compound_number:n} \Arg{entries} |
| 68 |
% \end{syntax} |
| 69 |
% Prints a set of numbers in the \meta{entries}, each of which should |
| 70 |
% be given as a \meta{balanced text}. Unlike \cs{siunitx_number_list:nn}, this |
| 71 |
% function may semantically take any form. |
| 72 |
% \end{function} |
| 73 |
% |
| 74 |
% \begin{function}{\siunitx_compound_quantity:nn} |
| 75 |
% \begin{syntax} |
| 76 |
% \cs{siunitx_compound_quantity:nn} \Arg{entries} \Arg{unit} |
| 77 |
% \end{syntax} |
| 78 |
% Prints a set of quantities in the \meta{entries}, each of which should |
| 79 |
% be given as a \meta{balanced text}. Unlike \cs{siunitx_quantity_list:nn}, |
| 80 |
% this function may semantically take any form. |
| 81 |
% \end{function} |
| 82 |
% |
| 83 |
% \begin{function}{\siunitx_number_list:n} |
| 84 |
% \begin{syntax} |
| 85 |
% \cs{siunitx_number_list:nn} \Arg{entries} |
| 86 |
% \end{syntax} |
| 87 |
% Prints the list of numbers in the \meta{entries}, each of which should |
| 88 |
% be given as a \meta{balanced text}. |
| 89 |
% \end{function} |
| 90 |
% |
| 91 |
% \begin{function}{\siunitx_quantity_list:nn} |
| 92 |
% \begin{syntax} |
| 93 |
% \cs{siunitx_quantity_list:nn} \Arg{entries} \Arg{unit} |
| 94 |
% \end{syntax} |
| 95 |
% Prints the list of quantities in the \meta{entries}, each of which should |
| 96 |
% be given as a \meta{balanced text}. |
| 97 |
% \end{function} |
| 98 |
% |
| 99 |
% \begin{function}{\siunitx_number_product:n} |
| 100 |
% \begin{syntax} |
| 101 |
% \cs{siunitx_number_product:n} \Arg{entries} |
| 102 |
% \end{syntax} |
| 103 |
% Prints the series of numbers in the \meta{entries}, each of which should |
| 104 |
% be given as a \meta{balanced text}. |
| 105 |
% \end{function} |
| 106 |
% |
| 107 |
% \begin{function}{\siunitx_quantity_product:nn} |
| 108 |
% \begin{syntax} |
| 109 |
% \cs{siunitx_number_product:n} \Arg{entries} \Arg{unit} |
| 110 |
% \end{syntax} |
| 111 |
% Prints the series of quantities in the \meta{entries}, each of which should |
| 112 |
% be given as a \meta{balanced text}. |
| 113 |
% \end{function} |
| 114 |
% |
| 115 |
% \begin{function}{\siunitx_number_range:nn} |
| 116 |
% \begin{syntax} |
| 117 |
% \cs{siunitx_number_range:nn} \Arg{start} \Arg{end} |
| 118 |
% \end{syntax} |
| 119 |
% Prints the range of numbers from the \meta{start} to the \meta{end}. |
| 120 |
% \end{function} |
| 121 |
% |
| 122 |
% \begin{function}{\siunitx_quantity_range:nnn} |
| 123 |
% \begin{syntax} |
| 124 |
% \cs{siunitx_number_range:nn} \Arg{start} \Arg{end} \Arg{unit} |
| 125 |
% \end{syntax} |
| 126 |
% Prints the range of quantities from the \meta{start} to the \meta{end}. |
| 127 |
% \end{function} |
| 128 |
% |
| 129 |
% \begin{variable} |
| 130 |
% { |
| 131 |
% \l_siunitx_list_separator_pair_tl, |
| 132 |
% \l_siunitx_list_separator_tl, |
| 133 |
% \l_siunitx_list_separator_final_tl |
| 134 |
% } |
| 135 |
% Separators for lists of numbers and quantities. |
| 136 |
% \end{variable} |
| 137 |
% |
| 138 |
% \begin{variable}{\l_siunitx_range_phrase_tl} |
| 139 |
% Phrase (or similar) used between limits of a range. |
| 140 |
% \end{variable} |
| 141 |
% |
| 142 |
% \begin{function}{compound-boundary-mode} |
| 143 |
% \begin{syntax} |
| 144 |
% |compound-boundary-mode| = |number|\verb"|"|text| |
| 145 |
% \end{syntax} |
| 146 |
% Choice which determines whether the material at the start and |
| 147 |
% end of a compound quantity are typeset a |number| or as |text|; |
| 148 |
% the latter is the standard setting. |
| 149 |
% \end{function} |
| 150 |
% |
| 151 |
% \begin{function}{compound-close-boundary, compound-open-boundary} |
| 152 |
% \begin{syntax} |
| 153 |
% |compound-close-boundary| = \meta{tokens}\\ |
| 154 |
% |compound-open-boundary| = \meta{tokens} |
| 155 |
% \end{syntax} |
| 156 |
% Literals which are inserted at the opening and closing boundary of a |
| 157 |
% compound quantity; they are not used when the number of items is one. The |
| 158 |
% standard settings set these empty. |
| 159 |
% \end{function} |
| 160 |
% |
| 161 |
% \begin{function}{compound-close-bracket, compound-open-bracket} |
| 162 |
% \begin{syntax} |
| 163 |
% |compound-close-bracket| = \meta{token} \\ |
| 164 |
% |compound-open-bracket| = \meta{token} |
| 165 |
% \end{syntax} |
| 166 |
% Literals containing the tokens inserted at the start and end of a compound |
| 167 |
% value when |compounds-units| is set to |bracket|. The standard settings are |
| 168 |
% |(| and |)|. |
| 169 |
% \end{function} |
| 170 |
% |
| 171 |
% \begin{function}{compound-exponents} |
| 172 |
% \begin{syntax} |
| 173 |
% |compound-exponents| = |combine|\verb"|"|combine-bracket|\verb"|"|individual| |
| 174 |
% \end{syntax} |
| 175 |
% \end{function} |
| 176 |
% |
| 177 |
% \begin{function}{compound-final-separator} |
| 178 |
% \begin{syntax} |
| 179 |
% |compound-final-separator| = \meta{text} |
| 180 |
% \end{syntax} |
| 181 |
% \end{function} |
| 182 |
% |
| 183 |
% \begin{function}{compound-independent-prefix} |
| 184 |
% \begin{syntax} |
| 185 |
% |compound-independent-prefix| = |true|\verb"|"|false| |
| 186 |
% \end{syntax} |
| 187 |
% Switch which determines whether unit prefixes are calculated |
| 188 |
% independently when units are repeated. The standard setting is |
| 189 |
% |false|. |
| 190 |
% \end{function} |
| 191 |
% |
| 192 |
% \begin{function}{compound-pair-separator} |
| 193 |
% \begin{syntax} |
| 194 |
% |compound-pair-separator| = \meta{text} |
| 195 |
% \end{syntax} |
| 196 |
% \end{function} |
| 197 |
% |
| 198 |
% \begin{function}{compound-separator} |
| 199 |
% \begin{syntax} |
| 200 |
% |compound-separator| = \meta{text} |
| 201 |
% \end{syntax} |
| 202 |
% \end{function} |
| 203 |
% |
| 204 |
% \begin{function}{compound-separator-mode} |
| 205 |
% \begin{syntax} |
| 206 |
% |compound-separator-mode| = |number|\verb"|"|text| |
| 207 |
% \end{syntax} |
| 208 |
% Choice which determines whether the separators between components |
| 209 |
% of compound quantity are typeset a |number| or as |text|; |
| 210 |
% the latter is the standard setting. |
| 211 |
% \end{function} |
| 212 |
% |
| 213 |
% \begin{function}{compound-units} |
| 214 |
% \begin{syntax} |
| 215 |
% |compound-units| = |bracket|\verb"|"|repeat|\verb"|"|single| |
| 216 |
% \end{syntax} |
| 217 |
% \end{function} |
| 218 |
% |
| 219 |
% \begin{function}{list-close-bracket, list-open-bracket} |
| 220 |
% \begin{syntax} |
| 221 |
% |list-close-bracket| = \meta{token} \\ |
| 222 |
% |list-open-bracket| = \meta{token} |
| 223 |
% \end{syntax} |
| 224 |
% Literals containing the tokens inserted at the start and end of a list when |
| 225 |
% |list-units| is set to |bracket|. The standard settings are |(| and |)|. |
| 226 |
% \end{function} |
| 227 |
% |
| 228 |
% \begin{function}{list-exponents} |
| 229 |
% \begin{syntax} |
| 230 |
% |list-exponents| = |combine|\verb"|"|combine-bracket|\verb"|"|individual| |
| 231 |
% \end{syntax} |
| 232 |
% \end{function} |
| 233 |
% |
| 234 |
% \begin{function}{list-final-separator} |
| 235 |
% \begin{syntax} |
| 236 |
% |list-final-separator| = \meta{text} |
| 237 |
% \end{syntax} |
| 238 |
% \end{function} |
| 239 |
% |
| 240 |
% \begin{function}{list-independent-prefix} |
| 241 |
% \begin{syntax} |
| 242 |
% |list-independent-prefix| = |true|\verb"|"|false| |
| 243 |
% \end{syntax} |
| 244 |
% Switch which determines whether unit prefixes are calculated |
| 245 |
% independently when units are repeated. The standard setting is |
| 246 |
% |false|. |
| 247 |
% \end{function} |
| 248 |
% |
| 249 |
% \begin{function}{list-pair-separator} |
| 250 |
% \begin{syntax} |
| 251 |
% |list-pair-separator| = \meta{text} |
| 252 |
% \end{syntax} |
| 253 |
% \end{function} |
| 254 |
% |
| 255 |
% \begin{function}{list-separator} |
| 256 |
% \begin{syntax} |
| 257 |
% |list-separator| = \meta{text} |
| 258 |
% \end{syntax} |
| 259 |
% \end{function} |
| 260 |
% |
| 261 |
% \begin{function}{list-units} |
| 262 |
% \begin{syntax} |
| 263 |
% |list-units| = |bracket|\verb"|"|repeat|\verb"|"|single| |
| 264 |
% \end{syntax} |
| 265 |
% \end{function} |
| 266 |
% |
| 267 |
% \begin{function}{product-close-bracket, product-open-bracket} |
| 268 |
% \begin{syntax} |
| 269 |
% |product-close-bracket| = \meta{token} \\ |
| 270 |
% |product-open-bracket| = \meta{token} |
| 271 |
% \end{syntax} |
| 272 |
% Literals containing the tokens inserted at the start and end of a product |
| 273 |
% when |product-units| is set to |bracket|. The standard settings are |(| |
| 274 |
% and |)|. |
| 275 |
% \end{function} |
| 276 |
% |
| 277 |
% \begin{function}{product-exponents} |
| 278 |
% \begin{syntax} |
| 279 |
% |product-exponents| = |combine|\verb"|"|combine-bracket|\verb"|"|individual| |
| 280 |
% \end{syntax} |
| 281 |
% \end{function} |
| 282 |
% |
| 283 |
% \begin{function}{product-independent-prefix} |
| 284 |
% \begin{syntax} |
| 285 |
% |product-independent-prefix| = |true|\verb"|"|false| |
| 286 |
% \end{syntax} |
| 287 |
% Switch which determines whether unit prefixes are calculated |
| 288 |
% independently when units are repeated. The standard setting is |
| 289 |
% |false|. |
| 290 |
% \end{function} |
| 291 |
% |
| 292 |
% \begin{function}{product-mode} |
| 293 |
% \begin{syntax} |
| 294 |
% |product-mode| = |phrase|\verb"|"|choice| |
| 295 |
% \end{syntax} |
| 296 |
% \end{function} |
| 297 |
% |
| 298 |
% \begin{function}{product-phrase} |
| 299 |
% \begin{syntax} |
| 300 |
% |product-phrase| = \meta{text} |
| 301 |
% \end{syntax} |
| 302 |
% \end{function} |
| 303 |
% |
| 304 |
% \begin{function}{product-symbol} |
| 305 |
% \begin{syntax} |
| 306 |
% |product-symbol| = \meta{symbol} |
| 307 |
% \end{syntax} |
| 308 |
% \end{function} |
| 309 |
% |
| 310 |
% \begin{function}{range-exponents} |
| 311 |
% \begin{syntax} |
| 312 |
% |range-exponents| = |combine|\verb"|"|combine-bracket|\verb"|"|individual| |
| 313 |
% \end{syntax} |
| 314 |
% \end{function} |
| 315 |
% |
| 316 |
% \begin{function}{range-close-bracket, range-open-bracket} |
| 317 |
% \begin{syntax} |
| 318 |
% |range-close-bracket| = \meta{token} \\ |
| 319 |
% |range-open-bracket| = \meta{token} |
| 320 |
% \end{syntax} |
| 321 |
% Literals containing the tokens inserted at the start and end of a range when |
| 322 |
% |range-units| is set to |bracket|. The standard settings are |(| and |)|. |
| 323 |
% \end{function} |
| 324 |
% |
| 325 |
% \begin{function}{range-independent-prefix} |
| 326 |
% \begin{syntax} |
| 327 |
% |range-independent-prefix| = |true|\verb"|"|false| |
| 328 |
% \end{syntax} |
| 329 |
% Switch which determines whether unit prefixes are calculated |
| 330 |
% independently when units are repeated. The standard setting is |
| 331 |
% |false|. |
| 332 |
% \end{function} |
| 333 |
% |
| 334 |
% \begin{function}{range-open-phrase} |
| 335 |
% \begin{syntax} |
| 336 |
% |range-open-phrase| = \meta{text} |
| 337 |
% \end{syntax} |
| 338 |
% Literal containing the material to be inserted at the start of a range. |
| 339 |
% The standard setting is empty. |
| 340 |
% \end{function} |
| 341 |
% |
| 342 |
% \begin{function}{range-phrase} |
| 343 |
% \begin{syntax} |
| 344 |
% |range-phrase| = \meta{text} |
| 345 |
% \end{syntax} |
| 346 |
% Literal containing the material to be inserted between the start and end |
| 347 |
% of a range. The standard setting contains the word \texttt{to} inside the |
| 348 |
% \cs{text} command, along with appropriate spacing commands to allow this |
| 349 |
% material to work in both math and text typesetting modes. |
| 350 |
% \end{function} |
| 351 |
% |
| 352 |
% \begin{function}{range-units} |
| 353 |
% \begin{syntax} |
| 354 |
% |range-units| = |bracket|\verb"|"|repeat|\verb"|"|single| |
| 355 |
% \end{syntax} |
| 356 |
% \end{function} |
| 357 |
% |
| 358 |
% \end{documentation} |
| 359 |
% |
| 360 |
% \begin{implementation} |
| 361 |
% |
| 362 |
% Start the \pkg{DocStrip} guards. |
| 363 |
% \begin{macrocode} |
| 364 |
%<*package> |
| 365 |
% \end{macrocode} |
| 366 |
% |
| 367 |
% \section{\pkg{siunitx-compound} implementation} |
| 368 |
% |
| 369 |
% \begin{macrocode} |
| 370 |
\cs_generate_variant:Nn \seq_use:Nnnn { NVVV } |
| 371 |
% \end{macrocode} |
| 372 |
% |
| 373 |
% \subsection{General mechanism} |
| 374 |
% |
| 375 |
% Identify the internal prefix. |
| 376 |
% \begin{macrocode} |
| 377 |
%<@@=siunitx_compound> |
| 378 |
% \end{macrocode} |
| 379 |
% |
| 380 |
% Typesetting lists, ranges and products of numbers or quantities has shared |
| 381 |
% features which mean they are best handled using a common mechanism. The aim |
| 382 |
% therefore is to abstract out enough of the process such that output-specific |
| 383 |
% aspects can be left to separate processes. |
| 384 |
% |
| 385 |
% \begin{variable}{\l_@@_tmp_fp, \l_@@_tmp_seq, \l_@@_tmp_tl} |
| 386 |
% Scratch space. |
| 387 |
% \begin{macrocode} |
| 388 |
\fp_new:N \l_@@_tmp_fp |
| 389 |
\seq_new:N \l_@@_tmp_seq |
| 390 |
\tl_new:N \l_@@_tmp_tl |
| 391 |
% \end{macrocode} |
| 392 |
% \end{variable} |
| 393 |
% |
| 394 |
% \begin{variable}{\l_@@_first_tl} |
| 395 |
% The first number in the list in internal format. |
| 396 |
% \begin{macrocode} |
| 397 |
\tl_new:N \l_@@_first_tl |
| 398 |
% \end{macrocode} |
| 399 |
% \end{variable} |
| 400 |
% |
| 401 |
% \begin{variable}{\l_@@_exp_tl} |
| 402 |
% For storing the combined exponent, if present. |
| 403 |
% \begin{macrocode} |
| 404 |
\tl_new:N \l_@@_exp_tl |
| 405 |
% \end{macrocode} |
| 406 |
% \end{variable} |
| 407 |
% |
| 408 |
% \begin{variable}{\l_@@_start_tl, \l_@@_end_tl} |
| 409 |
% Data on the end-of-list. |
| 410 |
% \begin{macrocode} |
| 411 |
\tl_new:N \l_@@_start_tl |
| 412 |
\tl_new:N \l_@@_end_tl |
| 413 |
% \end{macrocode} |
| 414 |
% \end{variable} |
| 415 |
% |
| 416 |
% \begin{variable}{\l_@@_count_int} |
| 417 |
% Data on the length-of-list. |
| 418 |
% \begin{macrocode} |
| 419 |
\int_new:N \l_@@_count_int |
| 420 |
% \end{macrocode} |
| 421 |
% \end{variable} |
| 422 |
% |
| 423 |
% \begin{variable}{\l_@@_unit_bool, \l_@@_unit_tl} |
| 424 |
% \begin{macrocode} |
| 425 |
\bool_new:N \l_@@_unit_bool |
| 426 |
\tl_new:N \l_@@_unit_tl |
| 427 |
% \end{macrocode} |
| 428 |
% \end{variable} |
| 429 |
% |
| 430 |
% \begin{variable} |
| 431 |
% { |
| 432 |
% \l_@@_boundary_text_bool , |
| 433 |
% \l_@@_boundary_close_tl , |
| 434 |
% \l_@@_bracket_close_tl , |
| 435 |
% \l_@@_independent_bool , |
| 436 |
% \l_@@_separator_final_tl , |
| 437 |
% \l_@@_separator_pair_tl , |
| 438 |
% \l_@@_boundary_open_tl , |
| 439 |
% \l_@@_bracket_open_tl , |
| 440 |
% \l_@@_separator_tl , |
| 441 |
% \l_@@_separator_text_bool , |
| 442 |
% \l_@@_exp_bracket_bool , |
| 443 |
% \l_@@_exp_combine_bool , |
| 444 |
% \l_@@_unit_bracket_bool , |
| 445 |
% \l_@@_unit_power_bool , |
| 446 |
% \l_@@_unit_repeat_bool , |
| 447 |
% } |
| 448 |
% List options. |
| 449 |
% \begin{macrocode} |
| 450 |
\bool_new:N \l_@@_boundary_text_bool |
| 451 |
\bool_new:N \l_@@_exp_bracket_bool |
| 452 |
\bool_new:N \l_@@_exp_combine_bool |
| 453 |
\bool_new:N \l_@@_separator_text_bool |
| 454 |
\bool_new:N \l_@@_unit_bracket_bool |
| 455 |
\bool_new:N \l_@@_unit_power_bool |
| 456 |
\bool_new:N \l_@@_unit_repeat_bool |
| 457 |
\keys_define:nn { siunitx } |
| 458 |
{ |
| 459 |
compound-boundary-mode .choice: , |
| 460 |
compound-boundary-mode / number .code:n = |
| 461 |
{ \bool_set_false:N \l_@@_boundary_text_bool } , |
| 462 |
compound-boundary-mode / text .code:n = |
| 463 |
{ \bool_set_true:N \l_@@_boundary_text_bool } , |
| 464 |
compound-close-boundary .tl_set:N = |
| 465 |
\l_@@_boundary_close_tl , |
| 466 |
compound-close-bracket .tl_set:N = |
| 467 |
\l_@@_bracket_close_tl , |
| 468 |
compound-exponents .choice: , |
| 469 |
compound-exponents / combine .code:n = |
| 470 |
{ |
| 471 |
\bool_set_false:N \l_@@_exp_bracket_bool |
| 472 |
\bool_set_true:N \l_@@_exp_combine_bool |
| 473 |
} , |
| 474 |
compound-exponents / combine-bracket .code:n = |
| 475 |
{ |
| 476 |
\bool_set_true:N \l_@@_exp_bracket_bool |
| 477 |
\bool_set_true:N \l_@@_exp_combine_bool |
| 478 |
} , |
| 479 |
compound-exponents / individual .code:n = |
| 480 |
{ |
| 481 |
\bool_set_false:N \l_@@_exp_bracket_bool |
| 482 |
\bool_set_false:N \l_@@_exp_combine_bool |
| 483 |
} , |
| 484 |
compound-final-separator .tl_set:N = |
| 485 |
\l_@@_separator_final_tl , |
| 486 |
compound-independent-prefix .bool_set:N = |
| 487 |
\l_@@_independent_bool , |
| 488 |
compound-pair-separator .tl_set:N = |
| 489 |
\l_@@_separator_pair_tl , |
| 490 |
compound-open-boundary .tl_set:N = |
| 491 |
\l_@@_boundary_open_tl , |
| 492 |
compound-open-bracket .tl_set:N = |
| 493 |
\l_@@_bracket_open_tl , |
| 494 |
compound-separator .tl_set:N = |
| 495 |
\l_@@_separator_tl , |
| 496 |
compound-separator-mode .choice: , |
| 497 |
compound-separator-mode / number .code:n = |
| 498 |
{ \bool_set_false:N \l_@@_separator_text_bool } , |
| 499 |
compound-separator-mode / text .code:n = |
| 500 |
{ \bool_set_true:N \l_@@_separator_text_bool } , |
| 501 |
compound-units .choice: , |
| 502 |
compound-units / bracket .code:n = |
| 503 |
{ |
| 504 |
\bool_set_true:N \l_@@_unit_bracket_bool |
| 505 |
\bool_set_false:N \l_@@_unit_power_bool |
| 506 |
\bool_set_false:N \l_@@_unit_repeat_bool |
| 507 |
} , |
| 508 |
compound-units / bracket-power .code:n = |
| 509 |
{ |
| 510 |
\bool_set_true:N \l_@@_unit_bracket_bool |
| 511 |
\bool_set_true:N \l_@@_unit_power_bool |
| 512 |
\bool_set_false:N \l_@@_unit_repeat_bool |
| 513 |
} , |
| 514 |
compound-units / power .code:n = |
| 515 |
{ |
| 516 |
\bool_set_false:N \l_@@_unit_bracket_bool |
| 517 |
\bool_set_true:N \l_@@_unit_power_bool |
| 518 |
\bool_set_false:N \l_@@_unit_repeat_bool |
| 519 |
} , |
| 520 |
compound-units / repeat .code:n = |
| 521 |
{ |
| 522 |
\bool_set_false:N \l_@@_unit_bracket_bool |
| 523 |
\bool_set_false:N \l_@@_unit_power_bool |
| 524 |
\bool_set_true:N \l_@@_unit_repeat_bool |
| 525 |
} , |
| 526 |
compound-units / single .code:n = |
| 527 |
{ |
| 528 |
\bool_set_false:N \l_@@_unit_bracket_bool |
| 529 |
\bool_set_false:N \l_@@_unit_power_bool |
| 530 |
\bool_set_false:N \l_@@_unit_repeat_bool |
| 531 |
} |
| 532 |
} |
| 533 |
% \end{macrocode} |
| 534 |
% \end{variable} |
| 535 |
% |
| 536 |
% \begin{macro}{\siunitx_compound_number:n} |
| 537 |
% \begin{macro}{\@@_format:n} |
| 538 |
% \begin{macro}{\@@_format:nn} |
| 539 |
% \begin{macro}{\@@_format:nnn, \@@_format:een} |
| 540 |
% Printing a generic set starts with the question of whether we want to |
| 541 |
% extract exponents. If we do, then there is the work to do with extraction. |
| 542 |
% Either way, the printing is handed off to a common function. We do a quick |
| 543 |
% count up-front to avoid excess work when there is not actually a list. |
| 544 |
% \begin{macrocode} |
| 545 |
\cs_new_protected:Npn \siunitx_compound_number:n #1 |
| 546 |
{ |
| 547 |
\group_begin: |
| 548 |
\bool_set_false:N \l_@@_unit_bool |
| 549 |
\@@_format:nn {#1} { } |
| 550 |
\@@_print:N \siunitx_print_number:e |
| 551 |
\group_end: |
| 552 |
} |
| 553 |
\cs_new_protected:Npn \@@_format:nn #1#2 |
| 554 |
{ |
| 555 |
\seq_clear:N \l_@@_tmp_seq |
| 556 |
\bool_if:NTF \l_siunitx_number_parse_bool |
| 557 |
{ |
| 558 |
\@@_format:een |
| 559 |
{ \tl_head:n {#1} } |
| 560 |
{ \tl_tail:n {#1} } |
| 561 |
{#2} |
| 562 |
} |
| 563 |
{ \tl_map_function:nN {#1} \@@_unparsed:n } |
| 564 |
} |
| 565 |
% \end{macrocode} |
| 566 |
% Formatting at a low level needs to know about units and numbers: we have to |
| 567 |
% exchange data between the two. Most of the business of handling the units |
| 568 |
% is left to a dedicated auxiliary. |
| 569 |
% \begin{macrocode} |
| 570 |
\cs_new_protected:Npn \@@_format:nnn #1#2#3 |
| 571 |
{ |
| 572 |
\tl_if_blank:nTF {#1} |
| 573 |
{ |
| 574 |
\tl_if_blank:nF {#2} |
| 575 |
{ \@@_format:nn {#2} {#3} } |
| 576 |
} |
| 577 |
{ \@@_format_aux:nnn {#1} {#2} {#3} } |
| 578 |
} |
| 579 |
\cs_generate_variant:Nn \@@_format:nnn { ee } |
| 580 |
\cs_new_protected:Npn \@@_format_aux:nnn #1#2#3 |
| 581 |
{ |
| 582 |
\siunitx_number_parse:nN {#1} \l_@@_tmp_tl |
| 583 |
\bool_if:NTF \l_@@_unit_bool |
| 584 |
{ \@@_format_units:nn {#2} {#3} } |
| 585 |
{ \siunitx_number_process:NN \l_@@_tmp_tl \l_@@_first_tl } |
| 586 |
\bool_lazy_and:nnTF |
| 587 |
{ \l_@@_exp_combine_bool } |
| 588 |
{ \int_compare_p:nNn { \tl_count:n {#2} } > 0 } |
| 589 |
{ \@@_extract_exponents: } |
| 590 |
{ |
| 591 |
\bool_if:NTF \l_@@_unit_bool |
| 592 |
{ |
| 593 |
\tl_set:Ne \l_@@_tmp_tl |
| 594 |
{ \siunitx_number_output:NN \l_@@_first_tl \q_nil } |
| 595 |
\tl_set:Ne \l_@@_tmp_tl |
| 596 |
{ \@@_uncert_bracket:N \l_@@_tmp_tl } |
| 597 |
} |
| 598 |
{ |
| 599 |
\tl_set:Ne \l_@@_tmp_tl |
| 600 |
{ \siunitx_number_output:N \l_@@_first_tl } |
| 601 |
} |
| 602 |
\seq_put_right:NV \l_@@_tmp_seq \l_@@_tmp_tl |
| 603 |
} |
| 604 |
\tl_map_function:nN {#2} \@@_parsed:n |
| 605 |
} |
| 606 |
% \end{macrocode} |
| 607 |
% \end{macro} |
| 608 |
% \end{macro} |
| 609 |
% \end{macro} |
| 610 |
% |
| 611 |
% \begin{macro}{\@@_extract_exponents:} |
| 612 |
% \begin{macro}{\@@_extract_exponents_auxi:w} |
| 613 |
% \begin{macro}{\@@_extract_exponents_auxii:nw} |
| 614 |
% \begin{macro}{\@@_extract_exponents_auxiii:nnnnnnn} |
| 615 |
% Extracting exponents means dealing with the first entry as a special case. |
| 616 |
% After that, apply fixed processing to all other entries, tidying up using |
| 617 |
% the number formatter. |
| 618 |
% \begin{macrocode} |
| 619 |
\cs_new_protected:Npn \@@_extract_exponents: |
| 620 |
{ |
| 621 |
\tl_set:Ne \l_@@_tmp_tl |
| 622 |
{ \siunitx_number_output:NN \l_@@_first_tl \q_nil } |
| 623 |
\exp_after:wN \@@_extract_exponents_auxi:w |
| 624 |
\l_@@_tmp_tl \q_stop |
| 625 |
} |
| 626 |
\cs_new_protected:Npn \@@_extract_exponents_auxi:w |
| 627 |
#1 \q_nil #2 \q_nil #3 \q_nil #4 \q_nil #5 \q_nil #6 \q_nil #7 \q_nil #8 |
| 628 |
\q_nil #9 \q_stop |
| 629 |
{ |
| 630 |
\@@_extract_exponents_auxii:nw {#1#2#3#4#5#6#7#8} #9 \q_stop |
| 631 |
} |
| 632 |
\cs_new_protected:Npn \@@_extract_exponents_auxii:nw |
| 633 |
#1#2 \q_nil #3 \q_nil #4 \q_stop |
| 634 |
{ |
| 635 |
\seq_put_right:Nn \l_@@_tmp_seq { #1#2 } |
| 636 |
\tl_set:Nn \l_@@_exp_tl { #3#4 } |
| 637 |
\exp_after:wN \@@_extract_exponents_auxiii:nnnnnnn |
| 638 |
\l_@@_first_tl |
| 639 |
} |
| 640 |
\cs_new_protected:Npn \@@_extract_exponents_auxiii:nnnnnnn |
| 641 |
#1#2#3#4#5#6#7 |
| 642 |
{ |
| 643 |
\keys_set:nn { siunitx } |
| 644 |
{ |
| 645 |
drop-exponent = true , |
| 646 |
exponent-mode = fixed , |
| 647 |
fixed-exponent = #6 0 #7 |
| 648 |
} |
| 649 |
} |
| 650 |
% \end{macrocode} |
| 651 |
% \end{macro} |
| 652 |
% \end{macro} |
| 653 |
% \end{macro} |
| 654 |
% \end{macro} |
| 655 |
% \end{macro} |
| 656 |
% |
| 657 |
% \begin{macro}{\@@_parsed:n, \@@_parsed_aux:n, \@@_unparsed:n} |
| 658 |
% The simple cases for parsing (or not) all entries. |
| 659 |
% \begin{macrocode} |
| 660 |
\cs_new_protected:Npn \@@_parsed:n #1 |
| 661 |
{ |
| 662 |
\tl_if_blank:nF {#1} |
| 663 |
{ \@@_parsed_aux:n {#1} } |
| 664 |
} |
| 665 |
\cs_new_protected:Npn \@@_parsed_aux:n #1 |
| 666 |
{ |
| 667 |
\bool_if:NTF \l_@@_unit_bool |
| 668 |
{ |
| 669 |
\siunitx_number_parse:nN {#1} \l_@@_tmp_tl |
| 670 |
\siunitx_number_process:NN \l_@@_tmp_tl \l_@@_tmp_tl |
| 671 |
\tl_set:Ne \l_@@_tmp_tl |
| 672 |
{ \siunitx_number_output:NN \l_@@_tmp_tl \q_nil } |
| 673 |
\tl_set:Ne \l_@@_tmp_tl |
| 674 |
{ \@@_uncert_bracket:N \l_@@_tmp_tl } |
| 675 |
} |
| 676 |
{ \siunitx_number_format:nN {#1} \l_@@_tmp_tl } |
| 677 |
\seq_put_right:NV \l_@@_tmp_seq \l_@@_tmp_tl |
| 678 |
} |
| 679 |
\cs_new_protected:Npn \@@_unparsed:n #1 |
| 680 |
{ |
| 681 |
\tl_if_blank:nF {#1} |
| 682 |
{ \seq_put_right:Nn \l_@@_tmp_seq { \ensuremath {#1} } } |
| 683 |
} |
| 684 |
% \end{macrocode} |
| 685 |
% \end{macro} |
| 686 |
% |
| 687 |
% \begin{macro}{\@@_format_units:nn} |
| 688 |
% \begin{macro} |
| 689 |
% { |
| 690 |
% \@@_format_combine-exponent:n , |
| 691 |
% \@@_format_extract-exponent:n , |
| 692 |
% \@@_format_input:n |
| 693 |
% } |
| 694 |
% \begin{macro} |
| 695 |
% { |
| 696 |
% \@@_format_combine-exponent:nn , |
| 697 |
% \@@_format_extract-exponent:nn |
| 698 |
% } |
| 699 |
% \begin{macro} |
| 700 |
% { |
| 701 |
% \@@_format_combine-exponent_aux:n , |
| 702 |
% \@@_format_extract-exponent_aux:n |
| 703 |
% } |
| 704 |
% \begin{macro}{\@@_extract_exp:nN, \@@_extract_exp:VN} |
| 705 |
% \begin{macro}{\@@_extract_exp:nnnnnnnN} |
| 706 |
% Actually formatting the units is much the same as is done in |
| 707 |
% the quantities module, except that we have to cover the multiplication |
| 708 |
% cases too: gets a bit repetitive. Notice that when combining exponents, |
| 709 |
% there is no adjustment to the original exponent: we purely need to |
| 710 |
% extract it. |
| 711 |
% \begin{macrocode} |
| 712 |
\cs_new_protected:Npn \@@_format_units:nn #1#2 |
| 713 |
{ |
| 714 |
\bool_if:NTF \l_@@_unit_power_bool |
| 715 |
{ |
| 716 |
\use:c { @@_format_ \l_siunitx_quantity_prefix_mode_str :nn } |
| 717 |
{#2} { \tl_count:n {#1} + 1 } |
| 718 |
} |
| 719 |
{ |
| 720 |
\use:c { @@_format_ \l_siunitx_quantity_prefix_mode_str :n } {#2} |
| 721 |
} |
| 722 |
} |
| 723 |
\cs_new_protected:cpe { @@_format_combine-exponent:n } #1 |
| 724 |
{ |
| 725 |
\exp_not:c { @@_format_combine-exponent_aux:n } |
| 726 |
{ |
| 727 |
\exp_not:N \siunitx_unit_format_combine_exponent:nnN |
| 728 |
{#1} |
| 729 |
} |
| 730 |
} |
| 731 |
\cs_new_protected:cpe { @@_format_combine-exponent:nn } #1#2 |
| 732 |
{ |
| 733 |
\exp_not:c { @@_format_combine-exponent_aux:n } |
| 734 |
{ |
| 735 |
\exp_not:N \siunitx_unit_format_multiply_combine_exponent:nnnN |
| 736 |
{#1} {#2} |
| 737 |
} |
| 738 |
} |
| 739 |
\cs_new_protected:cpn { @@_format_combine-exponent_aux:n } #1 |
| 740 |
{ |
| 741 |
\bool_set_true:N \l_@@_exp_combine_bool |
| 742 |
\siunitx_number_process:NN \l_@@_tmp_tl \l_@@_first_tl |
| 743 |
\@@_extract_exp:VN |
| 744 |
\l_@@_first_tl \l_@@_tmp_fp |
| 745 |
#1 \l_@@_tmp_fp \l_@@_unit_tl |
| 746 |
} |
| 747 |
\cs_new_protected:cpe { @@_format_extract-exponent:n } #1 |
| 748 |
{ |
| 749 |
\exp_not:c { @@_format_extract-exponent_aux:n } |
| 750 |
{ \exp_not:N \siunitx_unit_format_extract_prefixes:nNN {#1} } |
| 751 |
} |
| 752 |
\cs_new_protected:cpe { @@_format_extract-exponent:nn } #1#2 |
| 753 |
{ |
| 754 |
\exp_not:c { @@_format_extract-exponent_aux:n } |
| 755 |
{ |
| 756 |
\exp_not:N \siunitx_unit_format_multiply_extract_prefixes:nnNN |
| 757 |
{#1} {#2} |
| 758 |
} |
| 759 |
} |
| 760 |
\cs_new_protected:cpn { @@_format_extract-exponent_aux:n } #1 |
| 761 |
{ |
| 762 |
#1 \l_@@_unit_tl \l_@@_tmp_fp |
| 763 |
\tl_set:Ne \l_@@_tmp_tl |
| 764 |
{ \siunitx_number_adjust_exponent:Nn \l_@@_tmp_tl \l_@@_tmp_fp } |
| 765 |
\siunitx_number_process:NN \l_@@_tmp_tl \l_@@_first_tl |
| 766 |
\bool_set_true:N \l_@@_exp_combine_bool |
| 767 |
} |
| 768 |
\cs_new_protected:Npn \@@_format_input:n #1 |
| 769 |
{ |
| 770 |
\siunitx_number_process:NN \l_@@_tmp_tl \l_@@_first_tl |
| 771 |
\siunitx_unit_format:nN {#1} \l_@@_unit_tl |
| 772 |
} |
| 773 |
\cs_new_protected:Npn \@@_format_input:nn #1#2 |
| 774 |
{ |
| 775 |
\siunitx_number_process:NN \l_@@_tmp_tl \l_@@_first_tl |
| 776 |
\siunitx_unit_format_multiply:nnN {#1} {#2} \l_@@_unit_tl |
| 777 |
} |
| 778 |
\cs_new_protected:Npn \@@_extract_exp:nN #1#2 |
| 779 |
{ \@@_extract_exp:nnnnnnnN #1 #2 } |
| 780 |
\cs_generate_variant:Nn \@@_extract_exp:nN { V } |
| 781 |
\cs_new_protected:Npn \@@_extract_exp:nnnnnnnN #1#2#3#4#5#6#7#8 |
| 782 |
{ \fp_set:Nn #8 { #6 0 #7 } } |
| 783 |
% \end{macrocode} |
| 784 |
% \end{macro} |
| 785 |
% \end{macro} |
| 786 |
% \end{macro} |
| 787 |
% \end{macro} |
| 788 |
% \end{macro} |
| 789 |
% \end{macro} |
| 790 |
% |
| 791 |
% \begin{macro} |
| 792 |
% { |
| 793 |
% \siunitx_compound_quantity:nn , |
| 794 |
% \@@_quantity_auxi:nn , |
| 795 |
% \@@_quantity_auxii:nn |
| 796 |
% } |
| 797 |
% For quantities, life is more complex as there are interactions between the |
| 798 |
% options for exponents and units. The \cs{c_empty_tl} suppresses any |
| 799 |
% leading \texttt{1} if the unit starts \cs{per}; the \pkg{siunitx-print} |
| 800 |
% module will skip any printing in this case. |
| 801 |
% \begin{macrocode} |
| 802 |
\cs_new_protected:Npn \siunitx_compound_quantity:nn #1#2 |
| 803 |
{ |
| 804 |
\group_begin: |
| 805 |
\bool_lazy_all:nTF |
| 806 |
{ |
| 807 |
{ \l_@@_independent_bool } |
| 808 |
{ |
| 809 |
\str_if_eq_p:Vn |
| 810 |
\l_siunitx_quantity_prefix_mode_str |
| 811 |
{ combine-exponent } |
| 812 |
} |
| 813 |
{ \int_compare_p:nNn { \tl_count:n {#1} } > 1 } |
| 814 |
} |
| 815 |
{ \@@_quantity_auxi:nn } |
| 816 |
{ \@@_quantity_auxii:nn } |
| 817 |
{#1} {#2} |
| 818 |
\group_end: |
| 819 |
} |
| 820 |
% \end{macrocode} |
| 821 |
% The rather special case where all units are printed independently: |
| 822 |
% we just convert to a simple sequence then print. |
| 823 |
% \begin{macrocode} |
| 824 |
\cs_new_protected:Npn \@@_quantity_auxi:nn #1#2 |
| 825 |
{ |
| 826 |
\@@_print_boundary:V \l_@@_boundary_open_tl |
| 827 |
\seq_clear:N \l_@@_tmp_seq |
| 828 |
\tl_map_inline:nn {#1} |
| 829 |
{ |
| 830 |
\seq_put_right:Nn \l_@@_tmp_seq |
| 831 |
{ \siunitx_quantity:nn {##1} {#2} } |
| 832 |
} |
| 833 |
\seq_use:Nnnn \l_@@_tmp_seq |
| 834 |
{ \@@_print_separator:V \l_@@_separator_pair_tl } |
| 835 |
{ \@@_print_separator:V \l_@@_separator_tl } |
| 836 |
{ \@@_print_separator:V \l_@@_separator_final_tl } |
| 837 |
\@@_print_boundary:V \l_@@_boundary_close_tl |
| 838 |
} |
| 839 |
% \end{macrocode} |
| 840 |
% The business end for all other cases. |
| 841 |
% \begin{macrocode} |
| 842 |
\cs_new_protected:Npn \@@_quantity_auxii:nn #1#2 |
| 843 |
{ |
| 844 |
\bool_if:NT \l_@@_unit_bracket_bool |
| 845 |
{ \bool_set_true:N \l_@@_exp_bracket_bool } |
| 846 |
\bool_if:NT \l_@@_unit_repeat_bool |
| 847 |
{ \bool_set_false:N \l_@@_exp_combine_bool } |
| 848 |
\bool_lazy_or:nnT |
| 849 |
{ \l_@@_unit_bracket_bool } |
| 850 |
{ ! \l_@@_unit_repeat_bool } |
| 851 |
{ \bool_set_false:N \l_siunitx_number_bracket_ambiguous_bool } |
| 852 |
\bool_set_true:N \l_@@_unit_bool |
| 853 |
\@@_format:nn {#1} {#2} |
| 854 |
\bool_if:NF \l_siunitx_number_parse_bool |
| 855 |
{ \siunitx_unit_format:nN {#2} \l_@@_unit_tl } |
| 856 |
\str_if_eq:VnT \l_siunitx_quantity_prefix_mode_str { combine-exponent } |
| 857 |
{ \tl_clear:N \l_@@_exp_tl } |
| 858 |
\bool_if:NTF \l_@@_unit_repeat_bool |
| 859 |
{ \@@_print:N \@@_print_quantity:e } |
| 860 |
{ |
| 861 |
\bool_lazy_and:nnTF |
| 862 |
{ \l_@@_unit_bracket_bool } |
| 863 |
{ \tl_if_empty_p:N \l_@@_exp_tl } |
| 864 |
{ |
| 865 |
\siunitx_print_number:V \l_@@_bracket_open_tl |
| 866 |
\@@_print:N \siunitx_print_number:e |
| 867 |
\siunitx_print_number:V \l_@@_bracket_close_tl |
| 868 |
} |
| 869 |
{ \@@_print:N \siunitx_print_number:e } |
| 870 |
\@@_print_quantity:n { \c_empty_tl } |
| 871 |
} |
| 872 |
} |
| 873 |
% \end{macrocode} |
| 874 |
% \end{macro} |
| 875 |
% |
| 876 |
% \begin{macro}{\@@_print:N} |
| 877 |
% \begin{macro}{\@@_print:nnN, \@@_print:nVN, \@@_print:eeN} |
| 878 |
% \begin{macro}{\@@_print:nnnN, \@@_print:ennN} |
| 879 |
% \begin{macro}{\@@_print_aux:n} |
| 880 |
% \begin{macro}{\@@_print_aux:nn} |
| 881 |
% \begin{macro}{\@@_print_quantity:n, \@@_print_quantity:e} |
| 882 |
% \begin{macro} |
| 883 |
% { |
| 884 |
% \@@_print_boundary:n, \@@_print_boundary:V, |
| 885 |
% \@@_print_separator:n, \@@_print_separator:V |
| 886 |
% } |
| 887 |
% We now need to know how many entries there are: the reason we don't use |
| 888 |
% \cs{seq_use:Nnnn} is that we want to be able to insert |
| 889 |
% \cs{siunitx_print_\dots:n} in a controlled way. |
| 890 |
% \begin{macrocode} |
| 891 |
\cs_new_protected:Npn \@@_print:N #1 |
| 892 |
{ |
| 893 |
\bool_lazy_and:nnTF |
| 894 |
{ \l_@@_exp_bracket_bool } |
| 895 |
{ ! \tl_if_empty_p:N \l_@@_exp_tl } |
| 896 |
{ |
| 897 |
\@@_print:eeN |
| 898 |
{ \exp_not:V \l_@@_bracket_open_tl } |
| 899 |
{ |
| 900 |
\exp_not:V \l_@@_bracket_close_tl |
| 901 |
\exp_not:V \l_@@_exp_tl |
| 902 |
} |
| 903 |
#1 |
| 904 |
} |
| 905 |
{ \@@_print:nVN { } \l_@@_exp_tl #1 } |
| 906 |
} |
| 907 |
\cs_new_protected:Npn \@@_print:nnN #1#2#3 |
| 908 |
{ |
| 909 |
\@@_print:ennN |
| 910 |
{ \seq_count:N \l_@@_tmp_seq } {#1} {#2} #3 |
| 911 |
} |
| 912 |
\cs_generate_variant:Nn \@@_print:nnN { nV , ee } |
| 913 |
% \end{macrocode} |
| 914 |
% A rather long auxiliary as we want a way to have the brackets/exponent |
| 915 |
% available. The actual flow is simple enough: see how many entries there are |
| 916 |
% and print as required. To keep everything generic, we have some slightly |
| 917 |
% tricky saving of data to allow everything to go to the mapping. |
| 918 |
% \begin{macrocode} |
| 919 |
\cs_new_protected:Npn \@@_print:nnnN #1#2#3#4 |
| 920 |
{ |
| 921 |
\int_case:nnF {#1} |
| 922 |
{ |
| 923 |
{ 0 } { } |
| 924 |
{ 1 } |
| 925 |
{ |
| 926 |
#4 |
| 927 |
{ \seq_item:Nn \l_@@_tmp_seq { 1 } } |
| 928 |
} |
| 929 |
{ 2 } |
| 930 |
{ |
| 931 |
\@@_print_boundary:V \l_@@_boundary_open_tl |
| 932 |
#4 |
| 933 |
{ |
| 934 |
\exp_not:n {#2} |
| 935 |
\seq_item:Nn \l_@@_tmp_seq { 1 } |
| 936 |
} |
| 937 |
\@@_print_separator:V \l_@@_separator_pair_tl |
| 938 |
#4 |
| 939 |
{ |
| 940 |
\seq_item:Nn \l_@@_tmp_seq { 2 } |
| 941 |
\exp_not:n {#3} |
| 942 |
} |
| 943 |
\@@_print_boundary:V \l_@@_boundary_close_tl |
| 944 |
} |
| 945 |
} |
| 946 |
{ |
| 947 |
\int_set:Nn \l_@@_count_int {#1} |
| 948 |
\tl_set:Nn \l_@@_start_tl {#2} |
| 949 |
\tl_set:Nn \l_@@_end_tl {#3} |
| 950 |
\cs_set_eq:NN \@@_print_aux:n #4 |
| 951 |
\@@_print_boundary:V \l_@@_boundary_open_tl |
| 952 |
\seq_map_indexed_function:NN |
| 953 |
\l_@@_tmp_seq |
| 954 |
\@@_print_aux:nn |
| 955 |
\@@_print_boundary:V \l_@@_boundary_close_tl |
| 956 |
} |
| 957 |
} |
| 958 |
\cs_generate_variant:Nn \@@_print:nnnN { e } |
| 959 |
\cs_new_protected:Npn \@@_print_aux:n #1 { } |
| 960 |
\cs_new_protected:Npn \@@_print_aux:nn #1#2 |
| 961 |
{ |
| 962 |
\int_case:nnF {#1} |
| 963 |
{ |
| 964 |
{ 1 } |
| 965 |
{ |
| 966 |
\@@_print_aux:n |
| 967 |
{ |
| 968 |
\exp_not:V \l_@@_start_tl |
| 969 |
\exp_not:n {#2} |
| 970 |
} |
| 971 |
\@@_print_separator:V \l_@@_separator_tl |
| 972 |
} |
| 973 |
{ \l_@@_count_int - 1 } |
| 974 |
{ |
| 975 |
\@@_print_aux:n { \exp_not:n {#2} } |
| 976 |
\@@_print_separator:V \l_@@_separator_final_tl |
| 977 |
} |
| 978 |
{ \l_@@_count_int } |
| 979 |
{ |
| 980 |
\@@_print_aux:n |
| 981 |
{ |
| 982 |
\exp_not:n {#2} |
| 983 |
\exp_not:V \l_@@_end_tl |
| 984 |
} |
| 985 |
} |
| 986 |
} |
| 987 |
{ |
| 988 |
\@@_print_aux:n { \exp_not:n {#2} } |
| 989 |
\@@_print_separator:V \l_@@_separator_tl |
| 990 |
} |
| 991 |
} |
| 992 |
\cs_new_protected:Npn \@@_print_quantity:n #1 |
| 993 |
{ \siunitx_quantity_print:nV {#1} \l_@@_unit_tl } |
| 994 |
\cs_generate_variant:Nn \@@_print_quantity:n { e } |
| 995 |
\cs_new_protected:Npn \@@_print_boundary:n #1 |
| 996 |
{ |
| 997 |
\tl_if_blank:nF {#1} |
| 998 |
{ |
| 999 |
\bool_if:NTF \l_@@_boundary_text_bool |
| 1000 |
{ #1 } |
| 1001 |
{ \siunitx_print_number:n {#1} } |
| 1002 |
} |
| 1003 |
} |
| 1004 |
\cs_generate_variant:Nn \@@_print_boundary:n { V } |
| 1005 |
\cs_new_protected:Npn \@@_print_separator:n #1 |
| 1006 |
{ |
| 1007 |
\bool_if:NTF \l_@@_separator_text_bool |
| 1008 |
{ #1 } |
| 1009 |
{ \siunitx_print_number:n {#1} } |
| 1010 |
} |
| 1011 |
\cs_generate_variant:Nn \@@_print_separator:n { V } |
| 1012 |
% \end{macrocode} |
| 1013 |
% \end{macro} |
| 1014 |
% \end{macro} |
| 1015 |
% \end{macro} |
| 1016 |
% \end{macro} |
| 1017 |
% \end{macro} |
| 1018 |
% \end{macro} |
| 1019 |
% \end{macro} |
| 1020 |
% |
| 1021 |
% \begin{macro}[EXP]{\@@_uncert_bracket:N} |
| 1022 |
% \begin{macro}[EXP]{\@@_uncert_bracket:w} |
| 1023 |
% \begin{macro}[EXP]{\@@_uncert_bracket:nnw} |
| 1024 |
% Check for the case where there is a separate uncertainty but not exponent, |
| 1025 |
% when we are handling units. |
| 1026 |
% \begin{macrocode} |
| 1027 |
\cs_new:Npn \@@_uncert_bracket:N #1 |
| 1028 |
{ \exp_after:wN \@@_uncert_bracket:w #1 \q_stop } |
| 1029 |
\cs_new:Npn \@@_uncert_bracket:w |
| 1030 |
#1 \q_nil #2 \q_nil #3 \q_nil #4 \q_nil #5 \q_nil #6 \q_nil #7 \q_nil |
| 1031 |
#8 \q_nil #9 \q_stop |
| 1032 |
{ \@@_uncert_bracket:nnw {#1#2#3#4#5#6} {#7#8} #9 \q_stop } |
| 1033 |
\cs_new:Npn \@@_uncert_bracket:nnw #1#2 #3 \q_nil #4 \q_nil #5 \q_stop |
| 1034 |
{ |
| 1035 |
\bool_lazy_any:nTF |
| 1036 |
{ |
| 1037 |
{ ! \l_@@_unit_repeat_bool } |
| 1038 |
{ \tl_if_blank_p:n {#2#3} } |
| 1039 |
{ ! \tl_if_blank_p:n {#5} } |
| 1040 |
} |
| 1041 |
{ \exp_not:n {#1#2#3#4#5} } |
| 1042 |
{ |
| 1043 |
\exp_not:V \l_@@_bracket_open_tl |
| 1044 |
\exp_not:n {#1#2#3} |
| 1045 |
\exp_not:V \l_@@_bracket_close_tl |
| 1046 |
\exp_not:n {#4#5} |
| 1047 |
} |
| 1048 |
} |
| 1049 |
% \end{macrocode} |
| 1050 |
% \end{macro} |
| 1051 |
% \end{macro} |
| 1052 |
% \end{macro} |
| 1053 |
% |
| 1054 |
% \subsection{Lists} |
| 1055 |
% |
| 1056 |
% Identify the internal prefix. |
| 1057 |
% \begin{macrocode} |
| 1058 |
%<@@=siunitx_list> |
| 1059 |
% \end{macrocode} |
| 1060 |
% |
| 1061 |
% \begin{variable} |
| 1062 |
% { |
| 1063 |
% \l_@@_bracket_close_tl , |
| 1064 |
% \l_@@_independent_bool , |
| 1065 |
% \l_siunitx_list_separator_tl , |
| 1066 |
% \l_siunitx_list_separator_final_tl , |
| 1067 |
% \l_@@_bracket_open_tl , |
| 1068 |
% \l_siunitx_list_separator_pair_tl , |
| 1069 |
% \l_@@_exp_str , |
| 1070 |
% \l_@@_units_str |
| 1071 |
% } |
| 1072 |
% Options for products. |
| 1073 |
% \begin{macrocode} |
| 1074 |
\str_new:N \l_@@_exp_str |
| 1075 |
\str_new:N \l_@@_units_str |
| 1076 |
\keys_define:nn { siunitx } |
| 1077 |
{ |
| 1078 |
list-close-bracket .tl_set:N = |
| 1079 |
\l_@@_bracket_close_tl , |
| 1080 |
list-exponents .choices:nn = |
| 1081 |
{ combine , combine-bracket , individual } |
| 1082 |
{ \str_set_eq:NN \l_@@_exp_str \l_keys_choice_str } , |
| 1083 |
list-final-separator .tl_set:N = \l_siunitx_list_separator_final_tl , |
| 1084 |
list-independent-prefix .bool_set:N = |
| 1085 |
\l_@@_independent_bool , |
| 1086 |
list-open-bracket .tl_set:N = |
| 1087 |
\l_@@_bracket_open_tl , |
| 1088 |
list-pair-separator .tl_set:N = \l_siunitx_list_separator_pair_tl , |
| 1089 |
list-separator .tl_set:N = \l_siunitx_list_separator_tl , |
| 1090 |
list-units .choices:nn = |
| 1091 |
{ bracket , independent , repeat , single } |
| 1092 |
{ \str_set_eq:NN \l_@@_units_str \l_keys_choice_str } |
| 1093 |
} |
| 1094 |
% \end{macrocode} |
| 1095 |
% \end{variable} |
| 1096 |
% |
| 1097 |
% \begin{macro}{\siunitx_number_list:n} |
| 1098 |
% \begin{macro}{\siunitx_quantity_list:nn} |
| 1099 |
% \begin{macro}{\@@_aux:} |
| 1100 |
% Simply recover the settings and use as a list. |
| 1101 |
% \begin{macrocode} |
| 1102 |
\cs_new_protected:Npn \siunitx_number_list:n #1 |
| 1103 |
{ |
| 1104 |
\group_begin: |
| 1105 |
\@@_aux: |
| 1106 |
\siunitx_compound_number:n {#1} |
| 1107 |
\group_end: |
| 1108 |
} |
| 1109 |
\cs_new_protected:Npn \siunitx_quantity_list:nn #1#2 |
| 1110 |
{ |
| 1111 |
\group_begin: |
| 1112 |
\@@_aux: |
| 1113 |
\siunitx_compound_quantity:nn {#1} {#2} |
| 1114 |
\group_end: |
| 1115 |
} |
| 1116 |
\cs_new_protected:Npn \@@_aux: |
| 1117 |
{ |
| 1118 |
\keys_set:ne { siunitx } |
| 1119 |
{ |
| 1120 |
compound-close-bracket = |
| 1121 |
{ \exp_not:V \l_@@_bracket_close_tl } , |
| 1122 |
compound-close-boundary = , |
| 1123 |
compound-exponents = \l_@@_exp_str , |
| 1124 |
compound-final-separator = |
| 1125 |
{ \exp_not:V \l_siunitx_list_separator_final_tl } , |
| 1126 |
compound-independent-prefix = |
| 1127 |
\bool_if:NTF \l_@@_independent_bool { true } { false } , |
| 1128 |
compound-open-boundary = , |
| 1129 |
compound-open-bracket = |
| 1130 |
{ \exp_not:V \l_@@_bracket_open_tl } , |
| 1131 |
compound-pair-separator = |
| 1132 |
{ \exp_not:V \l_siunitx_list_separator_pair_tl } , |
| 1133 |
compound-separator = |
| 1134 |
{ \exp_not:V \l_siunitx_list_separator_tl } , |
| 1135 |
compound-separator-mode = text , |
| 1136 |
compound-units = \l_@@_units_str |
| 1137 |
} |
| 1138 |
} |
| 1139 |
% \end{macrocode} |
| 1140 |
% \end{macro} |
| 1141 |
% \end{macro} |
| 1142 |
% \end{macro} |
| 1143 |
% |
| 1144 |
% \subsection{Products} |
| 1145 |
% |
| 1146 |
% Identify the internal prefix. |
| 1147 |
% \begin{macrocode} |
| 1148 |
%<@@=siunitx_product> |
| 1149 |
% \end{macrocode} |
| 1150 |
% |
| 1151 |
% \begin{variable} |
| 1152 |
% { |
| 1153 |
% \l_@@_bracket_close_tl , |
| 1154 |
% \l_@@_exp_str , |
| 1155 |
% \l_@@_independent_bool , |
| 1156 |
% \l_@@_bracket_open_tl , |
| 1157 |
% \l_@@_phrase_bool , |
| 1158 |
% \l_@@_phrase_tl , |
| 1159 |
% \l_@@_symbol_tl , |
| 1160 |
% \l_@@_units_str |
| 1161 |
% } |
| 1162 |
% Options for products. |
| 1163 |
% \begin{macrocode} |
| 1164 |
\str_new:N \l_@@_exp_str |
| 1165 |
\bool_new:N \l_@@_phrase_bool |
| 1166 |
\str_new:N \l_@@_units_str |
| 1167 |
\keys_define:nn { siunitx } |
| 1168 |
{ |
| 1169 |
product-close-bracket .tl_set:N = |
| 1170 |
\l_@@_bracket_close_tl , |
| 1171 |
product-exponents .choices:nn = |
| 1172 |
{ combine , combine-bracket , individual } |
| 1173 |
{ \str_set_eq:NN \l_@@_exp_str \l_keys_choice_str } , |
| 1174 |
product-independent-prefix .bool_set:N = |
| 1175 |
\l_@@_independent_bool , |
| 1176 |
product-mode .choice: , |
| 1177 |
product-mode / phrase .code:n = |
| 1178 |
{ \bool_set_true:N \l_@@_phrase_bool } , |
| 1179 |
product-mode / symbol .code:n = |
| 1180 |
{ \bool_set_false:N \l_@@_phrase_bool } , |
| 1181 |
product-open-bracket .tl_set:N = |
| 1182 |
\l_@@_bracket_open_tl , |
| 1183 |
product-phrase .tl_set:N = \l_@@_phrase_tl , |
| 1184 |
product-symbol .tl_set:N = \l_@@_symbol_tl , |
| 1185 |
product-units .choices:nn = |
| 1186 |
{ bracket , bracket-power , independent , power , repeat , single } |
| 1187 |
{ \str_set_eq:NN \l_@@_units_str \l_keys_choice_str } |
| 1188 |
} |
| 1189 |
% \end{macrocode} |
| 1190 |
% \end{variable} |
| 1191 |
% |
| 1192 |
% \begin{macro}{\siunitx_number_product:n} |
| 1193 |
% \begin{macro}{\siunitx_quantity_product:nn} |
| 1194 |
% \begin{macro}{\@@_aux:} |
| 1195 |
% \begin{macro}{\@@_aux:n, \@@_aux:e} |
| 1196 |
% Simply recover the settings and use as a list. |
| 1197 |
% \begin{macrocode} |
| 1198 |
\cs_new_protected:Npn \siunitx_number_product:n #1 |
| 1199 |
{ |
| 1200 |
\group_begin: |
| 1201 |
\@@_aux: |
| 1202 |
\siunitx_compound_number:n {#1} |
| 1203 |
\group_end: |
| 1204 |
} |
| 1205 |
\cs_new_protected:Npn \siunitx_quantity_product:nn #1#2 |
| 1206 |
{ |
| 1207 |
\group_begin: |
| 1208 |
\@@_aux: |
| 1209 |
\siunitx_compound_quantity:nn {#1} {#2} |
| 1210 |
\group_end: |
| 1211 |
} |
| 1212 |
\cs_new_protected:Npn \@@_aux: |
| 1213 |
{ |
| 1214 |
\bool_if:NTF \l_@@_phrase_bool |
| 1215 |
{ \@@_aux:e { \exp_not:V \l_@@_phrase_tl } } |
| 1216 |
{ \@@_aux:e { { } \exp_not:V \l_@@_symbol_tl { } } } |
| 1217 |
} |
| 1218 |
\cs_new_protected:Npn \@@_aux:n #1 |
| 1219 |
{ |
| 1220 |
\keys_set:ne { siunitx } |
| 1221 |
{ |
| 1222 |
compound-close-boundary = , |
| 1223 |
compound-close-bracket = |
| 1224 |
{ \exp_not:V \l_@@_bracket_close_tl } , |
| 1225 |
compound-exponents = \l_@@_exp_str , |
| 1226 |
compound-final-separator = { \exp_not:n {#1} } , |
| 1227 |
compound-independent-prefix = |
| 1228 |
\bool_if:NTF \l_@@_independent_bool { true } { false } , |
| 1229 |
compound-open-boundary = , |
| 1230 |
compound-open-bracket = |
| 1231 |
{ \exp_not:V \l_@@_bracket_open_tl } , |
| 1232 |
compound-pair-separator = { \exp_not:n {#1} } , |
| 1233 |
compound-separator = { \exp_not:n {#1} } , |
| 1234 |
compound-separator-mode = |
| 1235 |
\bool_if:NTF \l_@@_phrase_bool { text } { number } , |
| 1236 |
compound-units = \l_@@_units_str |
| 1237 |
} |
| 1238 |
} |
| 1239 |
\cs_generate_variant:Nn \@@_aux:n { e } |
| 1240 |
% \end{macrocode} |
| 1241 |
% \end{macro} |
| 1242 |
% \end{macro} |
| 1243 |
% \end{macro} |
| 1244 |
% \end{macro} |
| 1245 |
% |
| 1246 |
% \subsection{Ranges} |
| 1247 |
% |
| 1248 |
% Identify the internal prefix. |
| 1249 |
% \begin{macrocode} |
| 1250 |
%<@@=siunitx_range> |
| 1251 |
% \end{macrocode} |
| 1252 |
% |
| 1253 |
% \begin{variable} |
| 1254 |
% { |
| 1255 |
% \l_@@_bracket_close_tl , |
| 1256 |
% \l_@@_exp_str , |
| 1257 |
% \l_@@_independent_bool , |
| 1258 |
% \l_@@_bracket_open_tl , |
| 1259 |
% \l_@@_open_tl , |
| 1260 |
% \l_siunitx_range_phrase_tl , |
| 1261 |
% \l_@@_units_str |
| 1262 |
% } |
| 1263 |
% Options for products. |
| 1264 |
% \begin{macrocode} |
| 1265 |
\str_new:N \l_@@_exp_str |
| 1266 |
\str_new:N \l_@@_units_str |
| 1267 |
\keys_define:nn { siunitx } |
| 1268 |
{ |
| 1269 |
range-close-bracket .tl_set:N = |
| 1270 |
\l_@@_bracket_close_tl , |
| 1271 |
range-exponents .choices:nn = |
| 1272 |
{ combine , combine-bracket , individual } |
| 1273 |
{ \str_set_eq:NN \l_@@_exp_str \l_keys_choice_str } , |
| 1274 |
range-independent-prefix .bool_set:N = |
| 1275 |
\l_@@_independent_bool , |
| 1276 |
range-open-bracket .tl_set:N = |
| 1277 |
\l_@@_bracket_open_tl , |
| 1278 |
range-open-phrase .tl_set:N = \l_@@_open_tl , |
| 1279 |
range-phrase .tl_set:N = \l_siunitx_range_phrase_tl , |
| 1280 |
range-units .choices:nn = |
| 1281 |
{ bracket , independent , repeat , single } |
| 1282 |
{ \str_set_eq:NN \l_@@_units_str \l_keys_choice_str } |
| 1283 |
} |
| 1284 |
% \end{macrocode} |
| 1285 |
% \end{variable} |
| 1286 |
% |
| 1287 |
% \begin{macro}{\siunitx_number_range:nn} |
| 1288 |
% \begin{macro}{\siunitx_quantity_range:nnn} |
| 1289 |
% \begin{macro}{\@@_aux:} |
| 1290 |
% Simply recover the settings and use as a list. |
| 1291 |
% \begin{macrocode} |
| 1292 |
\cs_new_protected:Npn \siunitx_number_range:nn #1#2 |
| 1293 |
{ |
| 1294 |
\group_begin: |
| 1295 |
\@@_aux: |
| 1296 |
\siunitx_compound_number:n { {#1} {#2} } |
| 1297 |
\group_end: |
| 1298 |
} |
| 1299 |
\cs_new_protected:Npn \siunitx_quantity_range:nnn #1#2#3 |
| 1300 |
{ |
| 1301 |
\group_begin: |
| 1302 |
\@@_aux: |
| 1303 |
\siunitx_compound_quantity:nn { {#1} {#2} } {#3} |
| 1304 |
\group_end: |
| 1305 |
} |
| 1306 |
\cs_new_protected:Npn \@@_aux: |
| 1307 |
{ |
| 1308 |
\keys_set:ne { siunitx } |
| 1309 |
{ |
| 1310 |
compound-boundary-mode = text , |
| 1311 |
compound-close-boundary = , |
| 1312 |
compound-close-bracket = |
| 1313 |
{ \exp_not:V \l_@@_bracket_close_tl } , |
| 1314 |
compound-exponents = \l_@@_exp_str , |
| 1315 |
compound-independent-prefix = |
| 1316 |
\bool_if:NTF \l_@@_independent_bool { true } { false } , |
| 1317 |
compound-open-boundary = { \exp_not:V \l_@@_open_tl } , |
| 1318 |
compound-open-bracket = |
| 1319 |
{ \exp_not:V \l_@@_bracket_open_tl } , |
| 1320 |
compound-pair-separator = |
| 1321 |
{ \exp_not:V \l_siunitx_range_phrase_tl } , |
| 1322 |
compound-separator-mode = text , |
| 1323 |
compound-units = \l_@@_units_str |
| 1324 |
} |
| 1325 |
} |
| 1326 |
% \end{macrocode} |
| 1327 |
% \end{macro} |
| 1328 |
% \end{macro} |
| 1329 |
% \end{macro} |
| 1330 |
% |
| 1331 |
% \subsection{Standard settings for module options} |
| 1332 |
% |
| 1333 |
% Some of these follow naturally from the point of definition |
| 1334 |
% (\foreign{e.g.}~boolean variables are always |false| to begin with), |
| 1335 |
% but for clarity everything is set here. |
| 1336 |
% \begin{macrocode} |
| 1337 |
\keys_set:nn { siunitx } |
| 1338 |
{ |
| 1339 |
compound-boundary-mode = text , |
| 1340 |
compound-close-boundary = , % ( |
| 1341 |
compound-close-bracket = ) , |
| 1342 |
compound-exponents = individual , |
| 1343 |
compound-final-separator = |
| 1344 |
{ |
| 1345 |
\TextOrMath { \space } { \ } |
| 1346 |
\text { and } |
| 1347 |
\TextOrMath { \space } { \ } |
| 1348 |
} , |
| 1349 |
compound-independent-prefix = false , |
| 1350 |
compound-open-boundary = , |
| 1351 |
compound-open-bracket = ( , % ) |
| 1352 |
compound-pair-separator = |
| 1353 |
{ |
| 1354 |
\TextOrMath { \space } { \ } |
| 1355 |
\text { and } |
| 1356 |
\TextOrMath { \space } { \ } |
| 1357 |
} , |
| 1358 |
compound-separator = |
| 1359 |
{ , \TextOrMath { \space } { \ } } , |
| 1360 |
compound-separator-mode = text , |
| 1361 |
compound-units = repeat , % ( |
| 1362 |
list-close-bracket = ) , |
| 1363 |
list-exponents = individual , |
| 1364 |
list-final-separator = |
| 1365 |
{ |
| 1366 |
\TextOrMath { \space } { \ } |
| 1367 |
\text { and } |
| 1368 |
\TextOrMath { \space } { \ } |
| 1369 |
} , |
| 1370 |
list-independent-prefix = false , |
| 1371 |
list-open-bracket = ( , % ) |
| 1372 |
list-pair-separator = |
| 1373 |
{ |
| 1374 |
\TextOrMath { \space } { \ } |
| 1375 |
\text { and } |
| 1376 |
\TextOrMath { \space } { \ } |
| 1377 |
} , |
| 1378 |
list-separator = |
| 1379 |
{ , \TextOrMath { \space } { \ } } , |
| 1380 |
list-units = repeat , % ( |
| 1381 |
product-close-bracket = ) , |
| 1382 |
product-exponents = individual , |
| 1383 |
product-independent-prefix = false , |
| 1384 |
product-mode = symbol , |
| 1385 |
product-open-bracket = ( , % ) |
| 1386 |
product-phrase = |
| 1387 |
{ |
| 1388 |
\TextOrMath { \space } { \ } |
| 1389 |
\text { by } |
| 1390 |
\TextOrMath { \space } { \ } |
| 1391 |
} , |
| 1392 |
product-symbol = \times , |
| 1393 |
product-units = repeat , % ( |
| 1394 |
range-close-bracket = ) , |
| 1395 |
range-exponents = individual , |
| 1396 |
range-independent-prefix = false , |
| 1397 |
range-open-bracket = ( , % ) |
| 1398 |
range-open-phrase = , |
| 1399 |
range-phrase = |
| 1400 |
{ |
| 1401 |
\TextOrMath { \space } { \ } |
| 1402 |
\text { to } |
| 1403 |
\TextOrMath { \space } { \ } |
| 1404 |
} , |
| 1405 |
range-units = repeat |
| 1406 |
} |
| 1407 |
% \end{macrocode} |
| 1408 |
% |
| 1409 |
% \begin{macrocode} |
| 1410 |
%</package> |
| 1411 |
% \end{macrocode} |
| 1412 |
% |
| 1413 |
% \end{implementation} |
| 1414 |
% |
| 1415 |
% \PrintIndex |