| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3skip.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2004-2011 Frank Mittelbach, The LaTeX Project |
| 6 |
% (C) 2012-2026 The LaTeX Project |
| 7 |
% |
| 8 |
% It may be distributed and/or modified under the conditions of the |
| 9 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 10 |
% license or (at your option) any later version. The latest version |
| 11 |
% of this license is in the file |
| 12 |
% |
| 13 |
% https://www.latex-project.org/lppl.txt |
| 14 |
% |
| 15 |
% This file is part of the "l3kernel bundle" (The Work in LPPL) |
| 16 |
% and all files in that bundle must be distributed together. |
| 17 |
% |
| 18 |
% ----------------------------------------------------------------------- |
| 19 |
% |
| 20 |
% The development version of the bundle can be found at |
| 21 |
% |
| 22 |
% https://github.com/latex3/latex3 |
| 23 |
% |
| 24 |
% for those people who are interested. |
| 25 |
% |
| 26 |
%<*driver> |
| 27 |
\documentclass[full,kernel]{l3doc} |
| 28 |
\begin{document} |
| 29 |
\DocInput{\jobname.dtx} |
| 30 |
\end{document} |
| 31 |
%</driver> |
| 32 |
% \fi |
| 33 |
% |
| 34 |
% \title{^^A |
| 35 |
% The \pkg{l3skip} module\\ Dimensions and skips^^A |
| 36 |
% } |
| 37 |
% |
| 38 |
% \author{^^A |
| 39 |
% The \LaTeX{} Project\thanks |
| 40 |
% {^^A |
| 41 |
% E-mail: |
| 42 |
% \href{mailto:[email protected]} |
| 43 |
% {[email protected]}^^A |
| 44 |
% }^^A |
| 45 |
% } |
| 46 |
% |
| 47 |
% \date{Released 2026-05-15} |
| 48 |
% |
| 49 |
% \maketitle |
| 50 |
% |
| 51 |
% \begin{documentation} |
| 52 |
% |
| 53 |
% \LaTeX3 provides two general length variables: \texttt{dim} and |
| 54 |
% \texttt{skip}. Lengths stored as \texttt{dim} variables have a fixed |
| 55 |
% length, whereas \texttt{skip} lengths have a rubber (stretch/shrink) |
| 56 |
% component. In addition, the \texttt{muskip} type is available for |
| 57 |
% use in math mode: this is a special form of \texttt{skip} where the |
| 58 |
% lengths involved are determined by the current math font (in |
| 59 |
% \texttt{mu)}. There are common features in the creation and setting of |
| 60 |
% length variables, but for clarity the functions are grouped by variable |
| 61 |
% type. |
| 62 |
% |
| 63 |
% Many functions take |
| 64 |
% \emph{dimension expressions} (\enquote{\meta{dim expr}}) or |
| 65 |
% \emph{skip expressions} (\enquote{\meta{skip expr}}) as arguments. |
| 66 |
% |
| 67 |
% |
| 68 |
% \section{Creating and initializing \texttt{dim} variables} |
| 69 |
% |
| 70 |
% \begin{function}{\dim_new:N, \dim_new:c} |
| 71 |
% \begin{syntax} |
| 72 |
% \cs{dim_new:N} \meta{dimension} |
| 73 |
% \end{syntax} |
| 74 |
% Creates a new \meta{dimension} or raises an error if the name is |
| 75 |
% already taken. The declaration is global. The \meta{dimension} |
| 76 |
% is initially equal to $0$\,pt. |
| 77 |
% \end{function} |
| 78 |
% |
| 79 |
% \begin{function}[added = 2012-03-05]{\dim_const:Nn, \dim_const:cn} |
| 80 |
% \begin{syntax} |
| 81 |
% \cs{dim_const:Nn} \meta{dimension} \Arg{dim expr} |
| 82 |
% \end{syntax} |
| 83 |
% Creates a new constant \meta{dimension} or raises an error if the |
| 84 |
% name is already taken. The value of the \meta{dimension} is set |
| 85 |
% globally to the \meta{dim expr}. |
| 86 |
% \end{function} |
| 87 |
% |
| 88 |
% \begin{function}{\dim_zero:N, \dim_zero:c, \dim_gzero:N, \dim_gzero:c} |
| 89 |
% \begin{syntax} |
| 90 |
% \cs{dim_zero:N} \meta{dimension} |
| 91 |
% \end{syntax} |
| 92 |
% Sets \meta{dimension} to $0$\,pt. |
| 93 |
% \end{function} |
| 94 |
% |
| 95 |
% \begin{function}[added = 2012-01-07] |
| 96 |
% {\dim_zero_new:N, \dim_zero_new:c, \dim_gzero_new:N, \dim_gzero_new:c} |
| 97 |
% \begin{syntax} |
| 98 |
% \cs{dim_zero_new:N} \meta{dimension} |
| 99 |
% \end{syntax} |
| 100 |
% Ensures that the \meta{dimension} exists globally by applying |
| 101 |
% \cs{dim_new:N} if necessary, then applies |
| 102 |
% \cs[index=dim_zero:N]{dim_(g)zero:N} to leave |
| 103 |
% the \meta{dimension} set to zero. |
| 104 |
% \end{function} |
| 105 |
% |
| 106 |
% \begin{function}[EXP, pTF, added=2012-03-03]{\dim_if_exist:N, \dim_if_exist:c} |
| 107 |
% \begin{syntax} |
| 108 |
% \cs{dim_if_exist_p:N} \meta{dimension} |
| 109 |
% \cs{dim_if_exist:NTF} \meta{dimension} \Arg{true code} \Arg{false code} |
| 110 |
% \end{syntax} |
| 111 |
% Tests whether the \meta{dimension} is currently defined. This does |
| 112 |
% not check that the \meta{dimension} really is a dimension variable. |
| 113 |
% \end{function} |
| 114 |
% |
| 115 |
% \section{Setting \texttt{dim} variables} |
| 116 |
% |
| 117 |
% \begin{function}[updated = 2011-10-22] |
| 118 |
% {\dim_add:Nn, \dim_add:cn, \dim_gadd:Nn, \dim_gadd:cn} |
| 119 |
% \begin{syntax} |
| 120 |
% \cs{dim_add:Nn} \meta{dimension} \Arg{dim expr} |
| 121 |
% \end{syntax} |
| 122 |
% Adds the result of the \meta{dim expr} to the current |
| 123 |
% content of the \meta{dimension}. |
| 124 |
% \end{function} |
| 125 |
% |
| 126 |
% \begin{function}[updated = 2011-10-22] |
| 127 |
% { |
| 128 |
% \dim_set:Nn, \dim_set:cn, \dim_set:NV, \dim_set:cV, |
| 129 |
% \dim_gset:Nn, \dim_gset:cn, \dim_gset:NV, \dim_gset:cV |
| 130 |
% } |
| 131 |
% \begin{syntax} |
| 132 |
% \cs{dim_set:Nn} \meta{dimension} \Arg{dim expr} |
| 133 |
% \end{syntax} |
| 134 |
% Sets \meta{dimension} to the value of \meta{dim expr}, which |
| 135 |
% must evaluate to a length with units. |
| 136 |
% \end{function} |
| 137 |
% |
| 138 |
% \begin{function} |
| 139 |
% { |
| 140 |
% \dim_set_eq:NN, \dim_set_eq:cN, \dim_set_eq:Nc, \dim_set_eq:cc, |
| 141 |
% \dim_gset_eq:NN, \dim_gset_eq:cN, \dim_gset_eq:Nc, \dim_gset_eq:cc |
| 142 |
% } |
| 143 |
% \begin{syntax} |
| 144 |
% \cs{dim_set_eq:NN} \meta{dimension_1} \meta{dimension_2} |
| 145 |
% \end{syntax} |
| 146 |
% Sets the content of \meta{dimension_1} equal to that of |
| 147 |
% \meta{dimension_2}. |
| 148 |
% \end{function} |
| 149 |
% |
| 150 |
% \begin{function}[updated = 2011-10-22] |
| 151 |
% {\dim_sub:Nn, \dim_sub:cn, \dim_gsub:Nn, \dim_gsub:cn} |
| 152 |
% \begin{syntax} |
| 153 |
% \cs{dim_sub:Nn} \meta{dimension} \Arg{dim expr} |
| 154 |
% \end{syntax} |
| 155 |
% Subtracts the result of the \meta{dim expr} from the |
| 156 |
% current content of the \meta{dimension}. |
| 157 |
% \end{function} |
| 158 |
% |
| 159 |
% \section{Utilities for dimension calculations} |
| 160 |
% |
| 161 |
% \begin{function}[updated = 2012-09-26, EXP]{\dim_abs:n} |
| 162 |
% \begin{syntax} |
| 163 |
% \cs{dim_abs:n} \Arg{dim expr} |
| 164 |
% \end{syntax} |
| 165 |
% Converts the \meta{dim expr} to its absolute value, leaving the result |
| 166 |
% in the input stream as a \meta{dimension denotation}. |
| 167 |
% \end{function} |
| 168 |
% |
| 169 |
% \begin{function}[added = 2012-09-09, updated = 2012-09-26, EXP] |
| 170 |
% {\dim_max:nn, \dim_min:nn} |
| 171 |
% \begin{syntax} |
| 172 |
% \cs{dim_max:nn} \Arg{dim expr_1} \Arg{dim expr_2} |
| 173 |
% \cs{dim_min:nn} \Arg{dim expr_1} \Arg{dim expr_2} |
| 174 |
% \end{syntax} |
| 175 |
% Evaluates the two \meta{dim exprs} and leaves either the |
| 176 |
% maximum or minimum value in the input stream as appropriate, as a |
| 177 |
% \meta{dimension denotation}. |
| 178 |
% \end{function} |
| 179 |
% |
| 180 |
% \begin{function}[updated = 2011-10-22, rEXP]{\dim_ratio:nn} |
| 181 |
% \begin{syntax} |
| 182 |
% \cs{dim_ratio:nn} \Arg{dim expr_1} \Arg{dim expr_2} |
| 183 |
% \end{syntax} |
| 184 |
% Parses the two \meta{dim exprs} and converts the ratio of |
| 185 |
% the two to a form suitable for use inside a \meta{dim expr}. |
| 186 |
% This ratio is then left in the input stream, allowing syntax such as |
| 187 |
% \begin{verbatim} |
| 188 |
% \dim_set:Nn \l_my_dim |
| 189 |
% { 10 pt * \dim_ratio:nn { 5 pt } { 10 pt } } |
| 190 |
% \end{verbatim} |
| 191 |
% The output of \cs{dim_ratio:nn} on full expansion is a ratio expression |
| 192 |
% between two integers, with all distances converted to scaled points. |
| 193 |
% Thus |
| 194 |
% \begin{verbatim} |
| 195 |
% \tl_set:Ne \l_my_tl { \dim_ratio:nn { 5 pt } { 10 pt } } |
| 196 |
% \tl_show:N \l_my_tl |
| 197 |
% \end{verbatim} |
| 198 |
% displays |327680/655360| on the terminal. |
| 199 |
% \end{function} |
| 200 |
% |
| 201 |
% \section{Dimension expression conditionals} |
| 202 |
% |
| 203 |
% \begin{function}[EXP,pTF] |
| 204 |
% { |
| 205 |
% \dim_compare:nNn, |
| 206 |
% \dim_compare:vNn, \dim_compare:nNv, \dim_compare:vNv |
| 207 |
% } |
| 208 |
% \begin{syntax} |
| 209 |
% \cs{dim_compare_p:nNn} \Arg{dim expr_1} \meta{relation} \Arg{dim expr_2} \\ |
| 210 |
% \cs{dim_compare:nNnTF} |
| 211 |
% ~~\Arg{dim expr_1} \meta{relation} \Arg{dim expr_2} |
| 212 |
% ~~\Arg{true code} \Arg{false code} |
| 213 |
% \end{syntax} |
| 214 |
% This function first evaluates each of the \meta{dim exprs} |
| 215 |
% as described for \cs{dim_eval:n}. The two results are then |
| 216 |
% compared using the \meta{relation}: |
| 217 |
% \begin{center} |
| 218 |
% \begin{tabular}{ll} |
| 219 |
% Equal & |=| \\ |
| 220 |
% Greater than & |>| \\ |
| 221 |
% Less than & |<| \\ |
| 222 |
% \end{tabular} |
| 223 |
% \end{center} |
| 224 |
% This function is less flexible than \cs{dim_compare:nTF} but around |
| 225 |
% $5$~times faster. |
| 226 |
% |
| 227 |
% Variables may be used directly in the \meta{dim exprs} here: as a result, |
| 228 |
% there is no need for |V|- (or |e|-) type variants. The |v|-type |
| 229 |
% variants are provided for convenience. |
| 230 |
% \end{function} |
| 231 |
% |
| 232 |
% \begin{function}[updated = 2013-01-13, EXP, pTF]{\dim_compare:n} |
| 233 |
% \begin{syntax} |
| 234 |
% \cs{dim_compare_p:n} \\ |
| 235 |
% ~~\{ \\ |
| 236 |
% ~~~~\meta{dim expr_1} \meta{relation_1} \\ |
| 237 |
% ~~~~\ldots{} \\ |
| 238 |
% ~~~~\meta{dim expr_N} \meta{relation_N} \\ |
| 239 |
% ~~~~\meta{dim expr_{N+1}} \\ |
| 240 |
% ~~\} \\ |
| 241 |
% \cs{dim_compare:nTF} |
| 242 |
% ~~\{ \\ |
| 243 |
% ~~~~\meta{dim expr_1} \meta{relation_1} \\ |
| 244 |
% ~~~~\ldots{} \\ |
| 245 |
% ~~~~\meta{dim expr_N} \meta{relation_N} \\ |
| 246 |
% ~~~~\meta{dim expr_{N+1}} \\ |
| 247 |
% ~~\} \\ |
| 248 |
% ~~\Arg{true code} \Arg{false code} |
| 249 |
% \end{syntax} |
| 250 |
% This function evaluates the \meta{dim exprs} as |
| 251 |
% described for \cs{dim_eval:n} and compares consecutive result using |
| 252 |
% the corresponding \meta{relation}, namely it compares |
| 253 |
% \meta{dim expr_1} and \meta{dim expr_2} using the \meta{relation_1}, |
| 254 |
% then \meta{dim expr_2} and \meta{dim expr_3} using the |
| 255 |
% \meta{relation_2}, until finally comparing \meta{dim expr_N} and |
| 256 |
% \meta{dim expr_{N+1}} using the \meta{relation_N}. The test yields |
| 257 |
% \texttt{true} if all comparisons are \texttt{true}. Each |
| 258 |
% \meta{dim expr} is evaluated only once, and the |
| 259 |
% evaluation is lazy, in the sense that if one comparison is |
| 260 |
% \texttt{false}, then no other \meta{dim expr} is |
| 261 |
% evaluated and no other comparison is performed. The |
| 262 |
% \meta{relations} can be any of the following: |
| 263 |
% \begin{center} |
| 264 |
% \begin{tabular}{ll} |
| 265 |
% Equal & |=| or |==| \\ |
| 266 |
% Greater than or equal to & |>=| \\ |
| 267 |
% Greater than & |>| \\ |
| 268 |
% Less than or equal to & |<=| \\ |
| 269 |
% Less than & |<| \\ |
| 270 |
% Not equal & |!=| \\ |
| 271 |
% \end{tabular} |
| 272 |
% \end{center} |
| 273 |
% This function is more flexible than \cs{dim_compare:nNnTF} but |
| 274 |
% around $5$~times slower. |
| 275 |
% \end{function} |
| 276 |
% |
| 277 |
% \begin{function}[added = 2013-07-24, EXP, noTF]{\dim_case:nn} |
| 278 |
% \begin{syntax} |
| 279 |
% \cs{dim_case:nnTF} \Arg{test dim expr} \\ |
| 280 |
% ~~|{| \\ |
| 281 |
% ~~~~\Arg{dim expr case_1} \Arg{code case_1} \\ |
| 282 |
% ~~~~\Arg{dim expr case_2} \Arg{code case_2} \\ |
| 283 |
% ~~~~\ldots \\ |
| 284 |
% ~~~~\Arg{dim expr case_n} \Arg{code case_n} \\ |
| 285 |
% ~~|}| \\ |
| 286 |
% ~~\Arg{true code} |
| 287 |
% ~~\Arg{false code} |
| 288 |
% \end{syntax} |
| 289 |
% This function evaluates the \meta{test dim expr} and |
| 290 |
% compares this in turn to each of the |
| 291 |
% \meta{dim expr case}s until a match is found. |
| 292 |
% If the two are equal then the |
| 293 |
% associated \meta{code} is left in the input stream |
| 294 |
% and other cases are discarded. If any of the |
| 295 |
% cases are matched, the \meta{true code} is also inserted into the |
| 296 |
% input stream (after the code for the appropriate case), while if none |
| 297 |
% match then the \meta{false code} is inserted. The function |
| 298 |
% \cs{dim_case:nn}, which does nothing if there is no match, is also |
| 299 |
% available. For example |
| 300 |
% \begin{verbatim} |
| 301 |
% \dim_set:Nn \l_tmpa_dim { 5 pt } |
| 302 |
% \dim_case:nnF |
| 303 |
% { 2 \l_tmpa_dim } |
| 304 |
% { |
| 305 |
% { 5 pt } { Small } |
| 306 |
% { 4 pt + 6 pt } { Medium } |
| 307 |
% { - 10 pt } { Negative } |
| 308 |
% } |
| 309 |
% { No idea! } |
| 310 |
% \end{verbatim} |
| 311 |
% leaves \enquote{\texttt{Medium}} in the input stream. |
| 312 |
% Since evaluation of the test expressions stops at the first |
| 313 |
% successful case, the order of possible matches should normally |
| 314 |
% be that the most likely are earlier: this will reduce the average |
| 315 |
% steps required to complete expansion. |
| 316 |
% \end{function} |
| 317 |
% |
| 318 |
% \section{Dimension expression loops} |
| 319 |
% |
| 320 |
% \begin{function}[rEXP]{\dim_do_until:nNnn} |
| 321 |
% \begin{syntax} |
| 322 |
% \cs{dim_do_until:nNnn} \Arg{dim expr_1} \meta{relation} \Arg{dim expr_2} \Arg{code} |
| 323 |
% \end{syntax} |
| 324 |
% Places the \meta{code} in the input stream for \TeX{} to process, and |
| 325 |
% then evaluates the relationship between the two |
| 326 |
% \meta{dim exprs} as described for \cs{dim_compare:nNnTF}. |
| 327 |
% If the test is \texttt{false} then the \meta{code} is inserted |
| 328 |
% into the input stream again and a loop occurs until the |
| 329 |
% \meta{relation} is \texttt{true}. |
| 330 |
% \end{function} |
| 331 |
% |
| 332 |
% \begin{function}[rEXP]{\dim_do_while:nNnn} |
| 333 |
% \begin{syntax} |
| 334 |
% \cs{dim_do_while:nNnn} \Arg{dim expr_1} \meta{relation} \Arg{dim expr_2} \Arg{code} |
| 335 |
% \end{syntax} |
| 336 |
% Places the \meta{code} in the input stream for \TeX{} to process, and |
| 337 |
% then evaluates the relationship between the two |
| 338 |
% \meta{dim exprs} as described for \cs{dim_compare:nNnTF}. |
| 339 |
% If the test is \texttt{true} then the \meta{code} is inserted |
| 340 |
% into the input stream again and a loop occurs until the |
| 341 |
% \meta{relation} is \texttt{false}. |
| 342 |
% \end{function} |
| 343 |
% |
| 344 |
% \begin{function}[rEXP]{\dim_until_do:nNnn} |
| 345 |
% \begin{syntax} |
| 346 |
% \cs{dim_until_do:nNnn} \Arg{dim expr_1} \meta{relation} \Arg{dim expr_2} \Arg{code} |
| 347 |
% \end{syntax} |
| 348 |
% Evaluates the relationship between the two \meta{dim exprs} |
| 349 |
% as described for \cs{dim_compare:nNnTF}, and then places the |
| 350 |
% \meta{code} in the input stream if the \meta{relation} is |
| 351 |
% \texttt{false}. After the \meta{code} has been processed by \TeX{} the |
| 352 |
% test is repeated, and a loop occurs until the test is |
| 353 |
% \texttt{true}. |
| 354 |
% \end{function} |
| 355 |
% |
| 356 |
% \begin{function}[rEXP]{\dim_while_do:nNnn} |
| 357 |
% \begin{syntax} |
| 358 |
% \cs{dim_while_do:nNnn} \Arg{dim expr_1} \meta{relation} \Arg{dim expr_2} \Arg{code} |
| 359 |
% \end{syntax} |
| 360 |
% Evaluates the relationship between the two \meta{dim exprs} |
| 361 |
% as described for \cs{dim_compare:nNnTF}, and then places the |
| 362 |
% \meta{code} in the input stream if the \meta{relation} is |
| 363 |
% \texttt{true}. After the \meta{code} has been processed by \TeX{} the |
| 364 |
% test is repeated, and a loop occurs until the test is |
| 365 |
% \texttt{false}. |
| 366 |
% \end{function} |
| 367 |
% |
| 368 |
% \begin{function}[updated = 2013-01-13, rEXP]{\dim_do_until:nn} |
| 369 |
% \begin{syntax} |
| 370 |
% \cs{dim_do_until:nn} \Arg{dimension relation} \Arg{code} |
| 371 |
% \end{syntax} |
| 372 |
% Places the \meta{code} in the input stream for \TeX{} to process, and |
| 373 |
% then evaluates the \meta{dimension relation} |
| 374 |
% as described for \cs{dim_compare:nTF}. |
| 375 |
% If the test is \texttt{false} then the \meta{code} is inserted |
| 376 |
% into the input stream again and a loop occurs until the |
| 377 |
% \meta{relation} is \texttt{true}. |
| 378 |
% \end{function} |
| 379 |
% |
| 380 |
% \begin{function}[updated = 2013-01-13, rEXP]{\dim_do_while:nn} |
| 381 |
% \begin{syntax} |
| 382 |
% \cs{dim_do_while:nn} \Arg{dimension relation} \Arg{code} |
| 383 |
% \end{syntax} |
| 384 |
% Places the \meta{code} in the input stream for \TeX{} to process, and |
| 385 |
% then evaluates the \meta{dimension relation} |
| 386 |
% as described for \cs{dim_compare:nTF}. |
| 387 |
% If the test is \texttt{true} then the \meta{code} is inserted |
| 388 |
% into the input stream again and a loop occurs until the |
| 389 |
% \meta{relation} is \texttt{false}. |
| 390 |
% \end{function} |
| 391 |
% |
| 392 |
% \begin{function}[updated = 2013-01-13, rEXP]{\dim_until_do:nn} |
| 393 |
% \begin{syntax} |
| 394 |
% \cs{dim_until_do:nn} \Arg{dimension relation} \Arg{code} |
| 395 |
% \end{syntax} |
| 396 |
% Evaluates the \meta{dimension relation} |
| 397 |
% as described for \cs{dim_compare:nTF}, and then places the |
| 398 |
% \meta{code} in the input stream if the \meta{relation} is |
| 399 |
% \texttt{false}. After the \meta{code} has been processed by \TeX{} the |
| 400 |
% test is repeated, and a loop occurs until the test is |
| 401 |
% \texttt{true}. |
| 402 |
% \end{function} |
| 403 |
% |
| 404 |
% \begin{function}[updated = 2013-01-13, rEXP]{\dim_while_do:nn} |
| 405 |
% \begin{syntax} |
| 406 |
% \cs{dim_while_do:nn} \Arg{dimension relation} \Arg{code} |
| 407 |
% \end{syntax} |
| 408 |
% Evaluates the \meta{dimension relation} |
| 409 |
% as described for \cs{dim_compare:nTF}, and then places the |
| 410 |
% \meta{code} in the input stream if the \meta{relation} is |
| 411 |
% \texttt{true}. After the \meta{code} has been processed by \TeX{} the |
| 412 |
% test is repeated, and a loop occurs until the test is |
| 413 |
% \texttt{false}. |
| 414 |
% \end{function} |
| 415 |
% |
| 416 |
% \section{Dimension step functions} |
| 417 |
% |
| 418 |
% \begin{function}[added = 2018-02-18, rEXP] |
| 419 |
% {\dim_step_function:nnnN} |
| 420 |
% \begin{syntax} |
| 421 |
% \cs{dim_step_function:nnnN} \Arg{initial value} \Arg{step} \Arg{final value} \meta{function} |
| 422 |
% \end{syntax} |
| 423 |
% This function first evaluates the \meta{initial value}, \meta{step} |
| 424 |
% and \meta{final value}, all of which should be dimension expressions. |
| 425 |
% The \meta{function} is then placed in front of each \meta{value} |
| 426 |
% from the \meta{initial value} to the \meta{final value} in turn |
| 427 |
% (using \meta{step} between each \meta{value}). The \meta{step} must |
| 428 |
% be non-zero. If the \meta{step} is positive, the loop stops when |
| 429 |
% the \meta{value} becomes larger than the \meta{final value}. If the |
| 430 |
% \meta{step} is negative, the loop stops when the \meta{value} |
| 431 |
% becomes smaller than the \meta{final value}. The \meta{function} |
| 432 |
% should absorb one argument. |
| 433 |
% \end{function} |
| 434 |
% |
| 435 |
% \begin{function}[added = 2018-02-18] |
| 436 |
% {\dim_step_inline:nnnn} |
| 437 |
% \begin{syntax} |
| 438 |
% \cs{dim_step_inline:nnnn} \Arg{initial value} \Arg{step} \Arg{final value} \Arg{code} |
| 439 |
% \end{syntax} |
| 440 |
% This function first evaluates the \meta{initial value}, \meta{step} |
| 441 |
% and \meta{final value}, all of which should be dimension expressions. |
| 442 |
% Then for each \meta{value} from the \meta{initial value} to the |
| 443 |
% \meta{final value} in turn (using \meta{step} between each |
| 444 |
% \meta{value}), the \meta{code} is inserted into the input stream |
| 445 |
% with |#1| replaced by the current \meta{value}. Thus the |
| 446 |
% \meta{code} should define a function of one argument~(|#1|). |
| 447 |
% \end{function} |
| 448 |
% |
| 449 |
% \begin{function}[added = 2018-02-18] |
| 450 |
% {\dim_step_variable:nnnNn} |
| 451 |
% \begin{syntax} |
| 452 |
% \cs{dim_step_variable:nnnNn} \\ |
| 453 |
% ~~\Arg{initial value} \Arg{step} \Arg{final value} \meta{tl~var} \Arg{code} |
| 454 |
% \end{syntax} |
| 455 |
% This function first evaluates the \meta{initial value}, \meta{step} |
| 456 |
% and \meta{final value}, all of which should be dimension expressions. |
| 457 |
% Then for each \meta{value} from the \meta{initial value} to the |
| 458 |
% \meta{final value} in turn (using \meta{step} between each |
| 459 |
% \meta{value}), the \meta{code} is inserted into the input stream, |
| 460 |
% with the \meta{tl~var} defined as the current \meta{value}. Thus |
| 461 |
% the \meta{code} should make use of the \meta{tl~var}. |
| 462 |
% \end{function} |
| 463 |
% |
| 464 |
% \section{Using \texttt{dim} expressions and variables} |
| 465 |
% |
| 466 |
% \begin{function}[updated = 2011-10-22, EXP]{\dim_eval:n} |
| 467 |
% \begin{syntax} |
| 468 |
% \cs{dim_eval:n} \Arg{dim expr} |
| 469 |
% \end{syntax} |
| 470 |
% Evaluates the \meta{dim expr}, expanding any |
| 471 |
% dimensions and token list variables within the \meta{expression} |
| 472 |
% to their content (without requiring \cs{dim_use:N}/\cs{tl_use:N}) |
| 473 |
% and applying the standard mathematical rules. The result of the |
| 474 |
% calculation is left in the input stream as a |
| 475 |
% \meta{dimension denotation} after two expansions. This is |
| 476 |
% expressed in points (\texttt{pt}), and requires suitable |
| 477 |
% termination if used in a \TeX{}-style assignment as it is \emph{not} |
| 478 |
% an \meta{internal dimension}. |
| 479 |
% \end{function} |
| 480 |
% |
| 481 |
% \begin{function}[EXP, added = 2018-11-03]{\dim_sign:n} |
| 482 |
% \begin{syntax} |
| 483 |
% \cs{dim_sign:n} \Arg{dim expr} |
| 484 |
% \end{syntax} |
| 485 |
% Evaluates the \meta{dim expr} then leaves $1$ or $0$ or $-1$ in the |
| 486 |
% input stream according to the sign of the result. |
| 487 |
% \end{function} |
| 488 |
% |
| 489 |
% \begin{function}[EXP]{\dim_use:N, \dim_use:c} |
| 490 |
% \begin{syntax} |
| 491 |
% \cs{dim_use:N} \meta{dimension} |
| 492 |
% \end{syntax} |
| 493 |
% Recovers the content of a \meta{dimension} and places it directly |
| 494 |
% in the input stream. An error is raised if the variable does |
| 495 |
% not exist or if it is invalid. Can be omitted in places where a |
| 496 |
% \meta{dimension} is required (such as in the argument of |
| 497 |
% \cs{dim_eval:n}). |
| 498 |
% \begin{texnote} |
| 499 |
% \cs{dim_use:N} is the \TeX{} primitive \tn{the}: this is one of |
| 500 |
% several \LaTeX3 names for this primitive. |
| 501 |
% \end{texnote} |
| 502 |
% \end{function} |
| 503 |
% |
| 504 |
% \begin{function}[added = 2014-07-15, EXP]{\dim_to_decimal:n} |
| 505 |
% \begin{syntax} |
| 506 |
% \cs{dim_to_decimal:n} \Arg{dim expr} |
| 507 |
% \end{syntax} |
| 508 |
% Evaluates the \meta{dim expr}, and leaves the result, |
| 509 |
% expressed in points (\texttt{pt}) in the input stream, with \emph{no |
| 510 |
% units}. The result is rounded by \TeX{} to at most five decimal |
| 511 |
% places. If the decimal part of the result is zero, it is omitted, |
| 512 |
% together with the decimal marker. |
| 513 |
% |
| 514 |
% For example |
| 515 |
% \begin{verbatim} |
| 516 |
% \dim_to_decimal:n { 1bp } |
| 517 |
% \end{verbatim} |
| 518 |
% leaves |1.00374| in the input stream, i.e., the magnitude of |
| 519 |
% one \enquote{big point} when converted to (\TeX{}) points. |
| 520 |
% \end{function} |
| 521 |
% |
| 522 |
% \begin{function}[added = 2014-07-15, updated = 2023-05-20, EXP] |
| 523 |
% {\dim_to_decimal_in_bp:n} |
| 524 |
% \begin{syntax} |
| 525 |
% \cs{dim_to_decimal_in_bp:n} \Arg{dim expr} |
| 526 |
% \end{syntax} |
| 527 |
% Evaluates the \meta{dim expr}, and leaves the result, |
| 528 |
% expressed in big points (\texttt{bp}) in the input stream, with \emph{no |
| 529 |
% units}. The result is rounded by \TeX{} to at most five decimal |
| 530 |
% places. If the decimal part of the result is zero, it is omitted, |
| 531 |
% together with the decimal marker. |
| 532 |
% |
| 533 |
% For example |
| 534 |
% \begin{verbatim} |
| 535 |
% \dim_to_decimal_in_bp:n { 1pt } |
| 536 |
% \end{verbatim} |
| 537 |
% leaves |0.99628| in the input stream, i.e., the magnitude of |
| 538 |
% one (\TeX{}) point when converted to big points. |
| 539 |
% \begin{texnote} |
| 540 |
% The implementation of this function is re-entrant: the result of |
| 541 |
% \begin{verbatim} |
| 542 |
% \dim_compare:nNnTF |
| 543 |
% { <x>bp } = |
| 544 |
% { \dim_to_decimal_in_bp:n { <x>bp } bp } |
| 545 |
% \end{verbatim} |
| 546 |
% will be logically \texttt{true}. The decimal representations may |
| 547 |
% differ provided they produce the same \TeX{} dimension. |
| 548 |
% \end{texnote} |
| 549 |
% \end{function} |
| 550 |
% |
| 551 |
% \begin{function}[added = 2023-05-20, EXP] |
| 552 |
% { |
| 553 |
% \dim_to_decimal_in_cc:n , |
| 554 |
% \dim_to_decimal_in_cm:n , |
| 555 |
% \dim_to_decimal_in_dd:n , |
| 556 |
% \dim_to_decimal_in_in:n , |
| 557 |
% \dim_to_decimal_in_mm:n , |
| 558 |
% \dim_to_decimal_in_pc:n |
| 559 |
% } |
| 560 |
% \begin{syntax} |
| 561 |
% \cs{dim_to_decimal_in_cm:n} \Arg{dim expr} |
| 562 |
% \end{syntax} |
| 563 |
% Evaluates the \meta{dim expr}, and leaves the result, |
| 564 |
% expressed with the appropriate scaling in the input stream, with |
| 565 |
% \emph{no units}. If the decimal part of the result is zero, it is omitted, |
| 566 |
% together with the decimal marker. The precisions of the result is limited |
| 567 |
% to a maximum of five decimal places with trailing zeros omitted. |
| 568 |
% |
| 569 |
% The maximum \TeX{} allowable dimension value (available as |
| 570 |
% \tn{maxdimen} in plain \TeX{} and \LaTeX{} and \cs{c_max_dim} in |
| 571 |
% \pkg{expl3}) can only be expressed exactly in the units |
| 572 |
% \texttt{pt}, \texttt{bp} and \texttt{sp}. The maximum allowable |
| 573 |
% input values to five decimal places are\\ |
| 574 |
% \begin{center} |
| 575 |
% \begin{tabular}{@{}>{$}r<{$}@{\,}l@{}} |
| 576 |
% 1276.00215 & cc \\ |
| 577 |
% 575.83174 & cm \\ |
| 578 |
% 15312.02584 & dd \\ |
| 579 |
% 226.70540 & in \\ |
| 580 |
% 5758.31742 & mm \\ |
| 581 |
% 1365.33333 & pc \\ |
| 582 |
% \end{tabular} |
| 583 |
% \end{center} |
| 584 |
% (Note that these are not all equal, but rather any larger value will overflow |
| 585 |
% due to the way \TeX{} converts to \texttt{sp}.) |
| 586 |
% Values given to five decimal places larger that these will result in \TeX{} |
| 587 |
% errors; the behavior if additional decimal places are given depends on the |
| 588 |
% \TeX{} internals and thus larger values are \emph{not} supported by |
| 589 |
% \pkg{expl3}. |
| 590 |
% \begin{texnote} |
| 591 |
% The implementation of these functions is re-entrant: the result of |
| 592 |
% \begin{verbatim} |
| 593 |
% \dim_compare:nNnTF |
| 594 |
% { <x><unit> } = |
| 595 |
% { \dim_to_decimal_in_<unit>:n { <x><unit> } <unit> } |
| 596 |
% \end{verbatim} |
| 597 |
% will be logically \texttt{true}. The decimal representations may |
| 598 |
% differ provided they produce the same \TeX{} dimension. |
| 599 |
% \end{texnote} |
| 600 |
% \end{function} |
| 601 |
% |
| 602 |
% \begin{function}[added = 2015-05-18, EXP]{\dim_to_decimal_in_sp:n} |
| 603 |
% \begin{syntax} |
| 604 |
% \cs{dim_to_decimal_in_sp:n} \Arg{dim expr} |
| 605 |
% \end{syntax} |
| 606 |
% Evaluates the \meta{dim expr}, and leaves the result, |
| 607 |
% expressed in scaled points (\texttt{sp}) in the input stream, with \emph{no |
| 608 |
% units}. The result is necessarily an integer. |
| 609 |
% \end{function} |
| 610 |
% |
| 611 |
% \begin{function}[added = 2014-07-15, updated = 2023-05-20, EXP] |
| 612 |
% {\dim_to_decimal_in_unit:nn} |
| 613 |
% \begin{syntax} |
| 614 |
% \cs{dim_to_decimal_in_unit:nn} \Arg{dim expr_1} \Arg{dim expr_2} |
| 615 |
% \end{syntax} |
| 616 |
% Evaluates the \meta{dim exprs}, and leaves the value of |
| 617 |
% \meta{dim expr_1}, expressed in a unit given by \meta{dim expr_2}, in |
| 618 |
% the input stream. If the decimal part of the result |
| 619 |
% is zero, it is omitted, together with the decimal marker. |
| 620 |
% The precisions of the result is limited |
| 621 |
% to a maximum of five decimal places with trailing zeros omitted. |
| 622 |
% |
| 623 |
% For example |
| 624 |
% \begin{verbatim} |
| 625 |
% \dim_to_decimal_in_unit:nn { 1bp } { 1mm } |
| 626 |
% \end{verbatim} |
| 627 |
% leaves |0.35278| in the input stream, i.e., the magnitude of |
| 628 |
% one big point when expressed in millimetres. The conversions do |
| 629 |
% \emph{not} guarantee that \TeX{} would yield identical results |
| 630 |
% for the direct input in an equality test, thus for instance |
| 631 |
% \begin{verbatim} |
| 632 |
% \dim_compare:nNnTF |
| 633 |
% { 1bp } = |
| 634 |
% { \dim_to_decimal_in_unit:nn { 1bp } { 1mm } mm } |
| 635 |
% \end{verbatim} |
| 636 |
% will take the \texttt{false} branch. |
| 637 |
% \end{function} |
| 638 |
% |
| 639 |
% \begin{function}[EXP, added = 2012-05-08, tested = m3fp-convert002] |
| 640 |
% {\dim_to_fp:n} |
| 641 |
% \begin{syntax} |
| 642 |
% \cs{dim_to_fp:n} \Arg{dim expr} |
| 643 |
% \end{syntax} |
| 644 |
% Expands to an internal floating point number equal to the value of |
| 645 |
% the \meta{dim expr} in \texttt{pt}. Since dimension expressions are |
| 646 |
% evaluated much faster than their floating point equivalent, |
| 647 |
% \cs{dim_to_fp:n} can be used to speed up parts of a computation |
| 648 |
% where a low precision and a smaller range are acceptable. |
| 649 |
% \end{function} |
| 650 |
% |
| 651 |
% \section{Viewing \texttt{dim} variables} |
| 652 |
% |
| 653 |
% \begin{function}{\dim_show:N, \dim_show:c} |
| 654 |
% \begin{syntax} |
| 655 |
% \cs{dim_show:N} \meta{dimension} |
| 656 |
% \end{syntax} |
| 657 |
% Displays the value of the \meta{dimension} on the terminal. |
| 658 |
% \end{function} |
| 659 |
% |
| 660 |
% \begin{function}[added = 2011-11-22, updated = 2015-08-07]{\dim_show:n} |
| 661 |
% \begin{syntax} |
| 662 |
% \cs{dim_show:n} \Arg{dim expr} |
| 663 |
% \end{syntax} |
| 664 |
% Displays the result of evaluating the \meta{dim expr} |
| 665 |
% on the terminal. |
| 666 |
% \end{function} |
| 667 |
% |
| 668 |
% \begin{function}[added = 2014-08-22, updated = 2015-08-03]{\dim_log:N, \dim_log:c} |
| 669 |
% \begin{syntax} |
| 670 |
% \cs{dim_log:N} \meta{dimension} |
| 671 |
% \end{syntax} |
| 672 |
% Writes the value of the \meta{dimension} in the log file. |
| 673 |
% \end{function} |
| 674 |
% |
| 675 |
% \begin{function}[added = 2014-08-22, updated = 2015-08-07]{\dim_log:n} |
| 676 |
% \begin{syntax} |
| 677 |
% \cs{dim_log:n} \Arg{dim expr} |
| 678 |
% \end{syntax} |
| 679 |
% Writes the result of evaluating the \meta{dim expr} |
| 680 |
% in the log file. |
| 681 |
% \end{function} |
| 682 |
% |
| 683 |
% \section{Constant dimensions} |
| 684 |
% |
| 685 |
% \begin{variable}{\c_max_dim} |
| 686 |
% The maximum value that can be stored as a dimension. This can also |
| 687 |
% be used as a component of a skip. |
| 688 |
% \end{variable} |
| 689 |
% |
| 690 |
% \begin{variable}{\c_zero_dim} |
| 691 |
% A zero length as a dimension. This can also be used as a component |
| 692 |
% of a skip. |
| 693 |
% \end{variable} |
| 694 |
% |
| 695 |
% \section{Scratch dimensions} |
| 696 |
% |
| 697 |
% \begin{variable}{\l_tmpa_dim, \l_tmpb_dim} |
| 698 |
% Scratch dimension for local assignment. These are never used by |
| 699 |
% the kernel code, and so are safe for use with any \LaTeX3-defined |
| 700 |
% function. However, they may be overwritten by other non-kernel |
| 701 |
% code and so should only be used for short-term storage. |
| 702 |
% \end{variable} |
| 703 |
% |
| 704 |
% \begin{variable}{\g_tmpa_dim, \g_tmpb_dim} |
| 705 |
% Scratch dimension for global assignment. These are never used by |
| 706 |
% the kernel code, and so are safe for use with any \LaTeX3-defined |
| 707 |
% function. However, they may be overwritten by other non-kernel |
| 708 |
% code and so should only be used for short-term storage. |
| 709 |
% \end{variable} |
| 710 |
% |
| 711 |
% \section{Inserting dimensions into the output} |
| 712 |
% |
| 713 |
% \begin{function}[added = 2026-02-01] |
| 714 |
% {\dim_horizontal:N, \dim_horizontal:c, \dim_horizontal:n} |
| 715 |
% \begin{syntax} |
| 716 |
% \cs{dim_horizontal:N} \meta{dim} |
| 717 |
% \cs{dim_horizontal:n} \Arg{dim expr} |
| 718 |
% \end{syntax} |
| 719 |
% Inserts a horizontal \meta{dim} into the current list. |
| 720 |
% \begin{texnote} |
| 721 |
% \cs{dim_horizontal:N} is a wrapper around the \TeX{} primitive |
| 722 |
% \tn{kern}. |
| 723 |
% \end{texnote} |
| 724 |
% \end{function} |
| 725 |
% |
| 726 |
% \begin{function}[added = 2026-02-01] |
| 727 |
% {\dim_vertical:N, \dim_vertical:c, \dim_vertical:n} |
| 728 |
% \begin{syntax} |
| 729 |
% \cs{dim_vertical:N} \meta{dim} |
| 730 |
% \cs{dim_vertical:n} \Arg{dim expr} |
| 731 |
% \end{syntax} |
| 732 |
% Inserts a vertical \meta{dim} into the current list. |
| 733 |
% \begin{texnote} |
| 734 |
% \cs{dim_vertical:N} is a wrapper around the \TeX{} primitive |
| 735 |
% \tn{kern}. |
| 736 |
% \end{texnote} |
| 737 |
% \end{function} |
| 738 |
% |
| 739 |
% \section{Creating and initializing \texttt{skip} variables} |
| 740 |
% |
| 741 |
% \begin{function}{\skip_new:N, \skip_new:c} |
| 742 |
% \begin{syntax} |
| 743 |
% \cs{skip_new:N} \meta{skip} |
| 744 |
% \end{syntax} |
| 745 |
% Creates a new \meta{skip} or raises an error if the name is |
| 746 |
% already taken. The declaration is global. The \meta{skip} |
| 747 |
% is initially equal to $0$\,pt. |
| 748 |
% \end{function} |
| 749 |
% |
| 750 |
% \begin{function}[added = 2012-03-05]{\skip_const:Nn, \skip_const:cn} |
| 751 |
% \begin{syntax} |
| 752 |
% \cs{skip_const:Nn} \meta{skip} \Arg{skip expr} |
| 753 |
% \end{syntax} |
| 754 |
% Creates a new constant \meta{skip} or raises an error if the |
| 755 |
% name is already taken. The value of the \meta{skip} is set |
| 756 |
% globally to the \meta{skip expr}. |
| 757 |
% \end{function} |
| 758 |
% |
| 759 |
% \begin{function}{\skip_zero:N, \skip_zero:c, \skip_gzero:N, \skip_gzero:c} |
| 760 |
% \begin{syntax} |
| 761 |
% \cs{skip_zero:N} \meta{skip} |
| 762 |
% \end{syntax} |
| 763 |
% Sets \meta{skip} to $0$\,pt. |
| 764 |
% \end{function} |
| 765 |
% |
| 766 |
% \begin{function}[added = 2012-01-07] |
| 767 |
% {\skip_zero_new:N, \skip_zero_new:c, \skip_gzero_new:N, \skip_gzero_new:c} |
| 768 |
% \begin{syntax} |
| 769 |
% \cs{skip_zero_new:N} \meta{skip} |
| 770 |
% \end{syntax} |
| 771 |
% Ensures that the \meta{skip} exists globally by applying |
| 772 |
% \cs{skip_new:N} if necessary, then applies |
| 773 |
% \cs[index=skip_zero:N]{skip_(g)zero:N} to leave |
| 774 |
% the \meta{skip} set to zero. |
| 775 |
% \end{function} |
| 776 |
% |
| 777 |
% \begin{function}[EXP, pTF, added=2012-03-03] |
| 778 |
% {\skip_if_exist:N, \skip_if_exist:c} |
| 779 |
% \begin{syntax} |
| 780 |
% \cs{skip_if_exist_p:N} \meta{skip} |
| 781 |
% \cs{skip_if_exist:NTF} \meta{skip} \Arg{true code} \Arg{false code} |
| 782 |
% \end{syntax} |
| 783 |
% Tests whether the \meta{skip} is currently defined. This does not |
| 784 |
% check that the \meta{skip} really is a skip variable. |
| 785 |
% \end{function} |
| 786 |
% |
| 787 |
% \section{Setting \texttt{skip} variables} |
| 788 |
% |
| 789 |
% \begin{function}[updated = 2011-10-22] |
| 790 |
% {\skip_add:Nn, \skip_add:cn, \skip_gadd:Nn, \skip_gadd:cn} |
| 791 |
% \begin{syntax} |
| 792 |
% \cs{skip_add:Nn} \meta{skip} \Arg{skip expr} |
| 793 |
% \end{syntax} |
| 794 |
% Adds the result of the \meta{skip expr} to the current |
| 795 |
% content of the \meta{skip}. |
| 796 |
% \end{function} |
| 797 |
% |
| 798 |
% \begin{function}[updated = 2011-10-22] |
| 799 |
% { |
| 800 |
% \skip_set:Nn, \skip_set:cn, \skip_set:NV, \skip_set:cV, |
| 801 |
% \skip_gset:Nn, \skip_gset:cn, \skip_gset:NV, \skip_gset:cV |
| 802 |
% } |
| 803 |
% \begin{syntax} |
| 804 |
% \cs{skip_set:Nn} \meta{skip} \Arg{skip expr} |
| 805 |
% \end{syntax} |
| 806 |
% Sets \meta{skip} to the value of \meta{skip expr}, which |
| 807 |
% must evaluate to a length with units and may include a rubber |
| 808 |
% component (for example |1 cm plus 0.5 cm|). |
| 809 |
% \end{function} |
| 810 |
% |
| 811 |
% \begin{function} |
| 812 |
% { |
| 813 |
% \skip_set_eq:NN, \skip_set_eq:cN, \skip_set_eq:Nc, \skip_set_eq:cc, |
| 814 |
% \skip_gset_eq:NN, \skip_gset_eq:cN, \skip_gset_eq:Nc, \skip_gset_eq:cc |
| 815 |
% } |
| 816 |
% \begin{syntax} |
| 817 |
% \cs{skip_set_eq:NN} \meta{skip_1} \meta{skip_2} |
| 818 |
% \end{syntax} |
| 819 |
% Sets the content of \meta{skip_1} equal to that of \meta{skip_2}. |
| 820 |
% \end{function} |
| 821 |
% |
| 822 |
% \begin{function}[updated = 2011-10-22] |
| 823 |
% {\skip_sub:Nn, \skip_sub:cn, \skip_gsub:Nn, \skip_gsub:cn} |
| 824 |
% \begin{syntax} |
| 825 |
% \cs{skip_sub:Nn} \meta{skip} \Arg{skip expr} |
| 826 |
% \end{syntax} |
| 827 |
% Subtracts the result of the \meta{skip expr} from the |
| 828 |
% current content of the \meta{skip}. |
| 829 |
% \end{function} |
| 830 |
% |
| 831 |
% \section{Skip expression conditionals} |
| 832 |
% |
| 833 |
% \begin{function}[EXP,pTF]{\skip_if_eq:nn} |
| 834 |
% \begin{syntax} |
| 835 |
% \cs{skip_if_eq_p:nn} \Arg{skip expr_1} \Arg{skip expr_2} |
| 836 |
% \cs{skip_if_eq:nnTF} |
| 837 |
% ~~\Arg{skip expr_1} \Arg{skip expr_2} |
| 838 |
% ~~\Arg{true code} \Arg{false code} |
| 839 |
% \end{syntax} |
| 840 |
% This function first evaluates each of the |
| 841 |
% \meta{skip exprs} as described for \cs{skip_eval:n}. |
| 842 |
% The two results are then compared for exact equality, |
| 843 |
% i.e., both the fixed and rubber components must be the same |
| 844 |
% for the test to be true. |
| 845 |
% \end{function} |
| 846 |
% |
| 847 |
% \begin{function}[EXP, pTF, added = 2012-03-05]{\skip_if_finite:n} |
| 848 |
% \begin{syntax} |
| 849 |
% \cs{skip_if_finite_p:n} \Arg{skip expr} |
| 850 |
% \cs{skip_if_finite:nTF} \Arg{skip expr} \Arg{true code} \Arg{false code} |
| 851 |
% \end{syntax} |
| 852 |
% Evaluates the \meta{skip expr} as described for \cs{skip_eval:n}, |
| 853 |
% and then tests if all of its components are finite. |
| 854 |
% \end{function} |
| 855 |
% |
| 856 |
% \section{Using \texttt{skip} expressions and variables} |
| 857 |
% |
| 858 |
% \begin{function}[updated = 2011-10-22, EXP]{\skip_eval:n} |
| 859 |
% \begin{syntax} |
| 860 |
% \cs{skip_eval:n} \Arg{skip expr} |
| 861 |
% \end{syntax} |
| 862 |
% Evaluates the \meta{skip expr}, expanding any skips |
| 863 |
% and token list variables within the \meta{expression} |
| 864 |
% to their content (without requiring \cs{skip_use:N}/\cs{tl_use:N}) |
| 865 |
% and applying the standard mathematical rules. The result of the |
| 866 |
% calculation is left in the input stream as a \meta{glue denotation} |
| 867 |
% after two expansions. This is expressed in points (\texttt{pt}), |
| 868 |
% and requires suitable termination if used in a \TeX{}-style |
| 869 |
% assignment as it is \emph{not} an \meta{internal glue}. |
| 870 |
% \end{function} |
| 871 |
% |
| 872 |
% \begin{function}[EXP]{\skip_use:N, \skip_use:c} |
| 873 |
% \begin{syntax} |
| 874 |
% \cs{skip_use:N} \meta{skip} |
| 875 |
% \end{syntax} |
| 876 |
% Recovers the content of a \meta{skip} and places it directly |
| 877 |
% in the input stream. An error is raised if the variable does |
| 878 |
% not exist or if it is invalid. Can be omitted in places where a |
| 879 |
% \meta{dimension} or \meta{skip} is required (such as in the argument of |
| 880 |
% \cs{skip_eval:n}). |
| 881 |
% \begin{texnote} |
| 882 |
% \cs{skip_use:N} is the \TeX{} primitive \tn{the}: this is one of |
| 883 |
% several \LaTeX3 names for this primitive. |
| 884 |
% \end{texnote} |
| 885 |
% \end{function} |
| 886 |
% |
| 887 |
% \section{Viewing \texttt{skip} variables} |
| 888 |
% |
| 889 |
% \begin{function}[updated = 2015-08-03]{\skip_show:N, \skip_show:c} |
| 890 |
% \begin{syntax} |
| 891 |
% \cs{skip_show:N} \meta{skip} |
| 892 |
% \end{syntax} |
| 893 |
% Displays the value of the \meta{skip} on the terminal. |
| 894 |
% \end{function} |
| 895 |
% |
| 896 |
% \begin{function}[added = 2011-11-22, updated = 2015-08-07]{\skip_show:n} |
| 897 |
% \begin{syntax} |
| 898 |
% \cs{skip_show:n} \Arg{skip expr} |
| 899 |
% \end{syntax} |
| 900 |
% Displays the result of evaluating the \meta{skip expr} |
| 901 |
% on the terminal. |
| 902 |
% \end{function} |
| 903 |
% |
| 904 |
% \begin{function}[added = 2014-08-22, updated = 2015-08-03]{\skip_log:N, \skip_log:c} |
| 905 |
% \begin{syntax} |
| 906 |
% \cs{skip_log:N} \meta{skip} |
| 907 |
% \end{syntax} |
| 908 |
% Writes the value of the \meta{skip} in the log file. |
| 909 |
% \end{function} |
| 910 |
% |
| 911 |
% \begin{function}[added = 2014-08-22, updated = 2015-08-07]{\skip_log:n} |
| 912 |
% \begin{syntax} |
| 913 |
% \cs{skip_log:n} \Arg{skip expr} |
| 914 |
% \end{syntax} |
| 915 |
% Writes the result of evaluating the \meta{skip expr} |
| 916 |
% in the log file. |
| 917 |
% \end{function} |
| 918 |
% |
| 919 |
% \section{Constant skips} |
| 920 |
% |
| 921 |
% \begin{variable}[updated = 2012-11-02]{\c_max_skip} |
| 922 |
% The maximum value that can be stored as a skip (equal to |
| 923 |
% \cs{c_max_dim} in length), with no stretch nor shrink component. |
| 924 |
% \end{variable} |
| 925 |
% |
| 926 |
% \begin{variable}[updated = 2012-11-01]{\c_zero_skip} |
| 927 |
% A zero length as a skip, with no stretch nor shrink component. |
| 928 |
% \end{variable} |
| 929 |
% |
| 930 |
% \section{Scratch skips} |
| 931 |
% |
| 932 |
% \begin{variable}{\l_tmpa_skip, \l_tmpb_skip} |
| 933 |
% Scratch skip for local assignment. These are never used by |
| 934 |
% the kernel code, and so are safe for use with any \LaTeX3-defined |
| 935 |
% function. However, they may be overwritten by other non-kernel |
| 936 |
% code and so should only be used for short-term storage. |
| 937 |
% \end{variable} |
| 938 |
% |
| 939 |
% \begin{variable}{\g_tmpa_skip, \g_tmpb_skip} |
| 940 |
% Scratch skip for global assignment. These are never used by |
| 941 |
% the kernel code, and so are safe for use with any \LaTeX3-defined |
| 942 |
% function. However, they may be overwritten by other non-kernel |
| 943 |
% code and so should only be used for short-term storage. |
| 944 |
% \end{variable} |
| 945 |
% |
| 946 |
% \section{Inserting skips into the output} |
| 947 |
% |
| 948 |
% \begin{function}[updated = 2011-10-22] |
| 949 |
% {\skip_horizontal:N, \skip_horizontal:c, \skip_horizontal:n} |
| 950 |
% \begin{syntax} |
| 951 |
% \cs{skip_horizontal:N} \meta{skip} |
| 952 |
% \cs{skip_horizontal:n} \Arg{skip expr} |
| 953 |
% \end{syntax} |
| 954 |
% Inserts a horizontal \meta{skip} into the current list. |
| 955 |
% The argument can also be a \meta{dim}. |
| 956 |
% \begin{texnote} |
| 957 |
% \cs{skip_horizontal:N} is the \TeX{} primitive \tn{hskip}. |
| 958 |
% \end{texnote} |
| 959 |
% \end{function} |
| 960 |
% |
| 961 |
% \begin{function}[updated = 2011-10-22] |
| 962 |
% {\skip_vertical:N, \skip_vertical:c, \skip_vertical:n} |
| 963 |
% \begin{syntax} |
| 964 |
% \cs{skip_vertical:N} \meta{skip} |
| 965 |
% \cs{skip_vertical:n} \Arg{skip expr} |
| 966 |
% \end{syntax} |
| 967 |
% Inserts a vertical \meta{skip} into the current list. |
| 968 |
% The argument can also be a \meta{dim}. |
| 969 |
% \begin{texnote} |
| 970 |
% \cs{skip_vertical:N} is the \TeX{} primitive \tn{vskip}. |
| 971 |
% \end{texnote} |
| 972 |
% \end{function} |
| 973 |
% |
| 974 |
% \section{Creating and initializing \texttt{muskip} variables} |
| 975 |
% |
| 976 |
% \begin{function}{\muskip_new:N, \muskip_new:c} |
| 977 |
% \begin{syntax} |
| 978 |
% \cs{muskip_new:N} \meta{muskip} |
| 979 |
% \end{syntax} |
| 980 |
% Creates a new \meta{muskip} or raises an error if the name is |
| 981 |
% already taken. The declaration is global. The \meta{muskip} |
| 982 |
% is initially equal to $0$\,mu. |
| 983 |
% \end{function} |
| 984 |
% |
| 985 |
% \begin{function}[added = 2012-03-05]{\muskip_const:Nn, \muskip_const:cn} |
| 986 |
% \begin{syntax} |
| 987 |
% \cs{muskip_const:Nn} \meta{muskip} \Arg{muskip expr} |
| 988 |
% \end{syntax} |
| 989 |
% Creates a new constant \meta{muskip} or raises an error if the |
| 990 |
% name is already taken. The value of the \meta{muskip} is set |
| 991 |
% globally to the \meta{muskip expr}. |
| 992 |
% \end{function} |
| 993 |
% |
| 994 |
% \begin{function} |
| 995 |
% {\muskip_zero:N, \muskip_zero:c, \muskip_gzero:N, \muskip_gzero:c} |
| 996 |
% \begin{syntax} |
| 997 |
% \cs{skip_zero:N} \meta{muskip} |
| 998 |
% \end{syntax} |
| 999 |
% Sets \meta{muskip} to $0$\,mu. |
| 1000 |
% \end{function} |
| 1001 |
% |
| 1002 |
% \begin{function}[added = 2012-01-07] |
| 1003 |
% { |
| 1004 |
% \muskip_zero_new:N, \muskip_zero_new:c, |
| 1005 |
% \muskip_gzero_new:N, \muskip_gzero_new:c |
| 1006 |
% } |
| 1007 |
% \begin{syntax} |
| 1008 |
% \cs{muskip_zero_new:N} \meta{muskip} |
| 1009 |
% \end{syntax} |
| 1010 |
% Ensures that the \meta{muskip} exists globally by applying |
| 1011 |
% \cs{muskip_new:N} if necessary, then applies |
| 1012 |
% \cs[index=muskip_zero:N]{muskip_(g)zero:N} |
| 1013 |
% to leave the \meta{muskip} set to zero. |
| 1014 |
% \end{function} |
| 1015 |
% |
| 1016 |
% \begin{function}[EXP, pTF, added=2012-03-03] |
| 1017 |
% {\muskip_if_exist:N, \muskip_if_exist:c} |
| 1018 |
% \begin{syntax} |
| 1019 |
% \cs{muskip_if_exist_p:N} \meta{muskip} |
| 1020 |
% \cs{muskip_if_exist:NTF} \meta{muskip} \Arg{true code} \Arg{false code} |
| 1021 |
% \end{syntax} |
| 1022 |
% Tests whether the \meta{muskip} is currently defined. This does not |
| 1023 |
% check that the \meta{muskip} really is a muskip variable. |
| 1024 |
% \end{function} |
| 1025 |
% |
| 1026 |
% \section{Setting \texttt{muskip} variables} |
| 1027 |
% |
| 1028 |
% \begin{function}[updated = 2011-10-22] |
| 1029 |
% {\muskip_add:Nn, \muskip_add:cn, \muskip_gadd:Nn, \muskip_gadd:cn} |
| 1030 |
% \begin{syntax} |
| 1031 |
% \cs{muskip_add:Nn} \meta{muskip} \Arg{muskip expr} |
| 1032 |
% \end{syntax} |
| 1033 |
% Adds the result of the \meta{muskip expr} to the current |
| 1034 |
% content of the \meta{muskip}. |
| 1035 |
% \end{function} |
| 1036 |
% |
| 1037 |
% \begin{function}[updated = 2011-10-22] |
| 1038 |
% { |
| 1039 |
% \muskip_set:Nn, \muskip_set:cn, \muskip_set:NV, \muskip_set:cV, |
| 1040 |
% \muskip_gset:Nn, \muskip_gset:cn, \muskip_gset:NV, \muskip_gset:cV |
| 1041 |
% } |
| 1042 |
% \begin{syntax} |
| 1043 |
% \cs{muskip_set:Nn} \meta{muskip} \Arg{muskip expr} |
| 1044 |
% \end{syntax} |
| 1045 |
% Sets \meta{muskip} to the value of \meta{muskip expr}, which |
| 1046 |
% must evaluate to a math length with units and may include a rubber |
| 1047 |
% component (for example |1 mu plus 0.5 mu|. |
| 1048 |
% \end{function} |
| 1049 |
% |
| 1050 |
% \begin{function} |
| 1051 |
% { |
| 1052 |
% \muskip_set_eq:NN, \muskip_set_eq:cN, |
| 1053 |
% \muskip_set_eq:Nc, \muskip_set_eq:cc, |
| 1054 |
% \muskip_gset_eq:NN, \muskip_gset_eq:cN, |
| 1055 |
% \muskip_gset_eq:Nc, \muskip_gset_eq:cc |
| 1056 |
% } |
| 1057 |
% \begin{syntax} |
| 1058 |
% \cs{muskip_set_eq:NN} \meta{muskip_1} \meta{muskip_2} |
| 1059 |
% \end{syntax} |
| 1060 |
% Sets the content of \meta{muskip_1} equal to that of |
| 1061 |
% \meta{muskip_2}. |
| 1062 |
% \end{function} |
| 1063 |
% |
| 1064 |
% \begin{function}[updated = 2011-10-22] |
| 1065 |
% {\muskip_sub:Nn, \muskip_sub:cn, \muskip_gsub:Nn, \muskip_gsub:cn} |
| 1066 |
% \begin{syntax} |
| 1067 |
% \cs{muskip_sub:Nn} \meta{muskip} \Arg{muskip expr} |
| 1068 |
% \end{syntax} |
| 1069 |
% Subtracts the result of the \meta{muskip expr} from the |
| 1070 |
% current content of the \meta{muskip}. |
| 1071 |
% \end{function} |
| 1072 |
% |
| 1073 |
% \section{Using \texttt{muskip} expressions and variables} |
| 1074 |
% |
| 1075 |
% \begin{function}[updated = 2011-10-22, EXP]{\muskip_eval:n} |
| 1076 |
% \begin{syntax} |
| 1077 |
% \cs{muskip_eval:n} \Arg{muskip expr} |
| 1078 |
% \end{syntax} |
| 1079 |
% Evaluates the \meta{muskip expr}, expanding any skips |
| 1080 |
% and token list variables within the \meta{expression} |
| 1081 |
% to their content (without requiring \cs{muskip_use:N}/\cs{tl_use:N}) |
| 1082 |
% and applying the standard mathematical rules. The result of the |
| 1083 |
% calculation is left in the input stream as a \meta{muglue denotation} |
| 1084 |
% after two expansions. This is expressed in \texttt{mu}, |
| 1085 |
% and requires suitable termination if used in a \TeX{}-style |
| 1086 |
% assignment as it is \emph{not} an \meta{internal muglue}. |
| 1087 |
% \end{function} |
| 1088 |
% |
| 1089 |
% \begin{function}[EXP]{\muskip_use:N, \muskip_use:c} |
| 1090 |
% \begin{syntax} |
| 1091 |
% \cs{muskip_use:N} \meta{muskip} |
| 1092 |
% \end{syntax} |
| 1093 |
% Recovers the content of a \meta{skip} and places it directly |
| 1094 |
% in the input stream. An error is raised if the variable does |
| 1095 |
% not exist or if it is invalid. Can be omitted in places where a |
| 1096 |
% \meta{dimension} is required (such as in the argument of |
| 1097 |
% \cs{muskip_eval:n}). |
| 1098 |
% \begin{texnote} |
| 1099 |
% \cs{muskip_use:N} is the \TeX{} primitive \tn{the}: this is one of |
| 1100 |
% several \LaTeX3 names for this primitive. |
| 1101 |
% \end{texnote} |
| 1102 |
% \end{function} |
| 1103 |
% |
| 1104 |
% \section{Viewing \texttt{muskip} variables} |
| 1105 |
% |
| 1106 |
% \begin{function}[updated = 2015-08-03]{\muskip_show:N, \muskip_show:c} |
| 1107 |
% \begin{syntax} |
| 1108 |
% \cs{muskip_show:N} \meta{muskip} |
| 1109 |
% \end{syntax} |
| 1110 |
% Displays the value of the \meta{muskip} on the terminal. |
| 1111 |
% \end{function} |
| 1112 |
% |
| 1113 |
% \begin{function}[added = 2011-11-22, updated = 2015-08-07]{\muskip_show:n} |
| 1114 |
% \begin{syntax} |
| 1115 |
% \cs{muskip_show:n} \Arg{muskip expr} |
| 1116 |
% \end{syntax} |
| 1117 |
% Displays the result of evaluating the \meta{muskip expr} |
| 1118 |
% on the terminal. |
| 1119 |
% \end{function} |
| 1120 |
% |
| 1121 |
% \begin{function}[added = 2014-08-22, updated = 2015-08-03]{\muskip_log:N, \muskip_log:c} |
| 1122 |
% \begin{syntax} |
| 1123 |
% \cs{muskip_log:N} \meta{muskip} |
| 1124 |
% \end{syntax} |
| 1125 |
% Writes the value of the \meta{muskip} in the log file. |
| 1126 |
% \end{function} |
| 1127 |
% |
| 1128 |
% \begin{function}[added = 2014-08-22, updated = 2015-08-07]{\muskip_log:n} |
| 1129 |
% \begin{syntax} |
| 1130 |
% \cs{muskip_log:n} \Arg{muskip expr} |
| 1131 |
% \end{syntax} |
| 1132 |
% Writes the result of evaluating the \meta{muskip expr} |
| 1133 |
% in the log file. |
| 1134 |
% \end{function} |
| 1135 |
% |
| 1136 |
% \section{Constant muskips} |
| 1137 |
% |
| 1138 |
% \begin{variable}{\c_max_muskip} |
| 1139 |
% The maximum value that can be stored as a muskip, with no stretch |
| 1140 |
% nor shrink component. |
| 1141 |
% \end{variable} |
| 1142 |
% |
| 1143 |
% \begin{variable}{\c_zero_muskip} |
| 1144 |
% A zero length as a muskip, with no stretch nor shrink component. |
| 1145 |
% \end{variable} |
| 1146 |
% |
| 1147 |
% \section{Scratch muskips} |
| 1148 |
% |
| 1149 |
% \begin{variable}{\l_tmpa_muskip, \l_tmpb_muskip} |
| 1150 |
% Scratch muskip for local assignment. These are never used by |
| 1151 |
% the kernel code, and so are safe for use with any \LaTeX3-defined |
| 1152 |
% function. However, they may be overwritten by other non-kernel |
| 1153 |
% code and so should only be used for short-term storage. |
| 1154 |
% \end{variable} |
| 1155 |
% |
| 1156 |
% \begin{variable}{\g_tmpa_muskip, \g_tmpb_muskip} |
| 1157 |
% Scratch muskip for global assignment. These are never used by |
| 1158 |
% the kernel code, and so are safe for use with any \LaTeX3-defined |
| 1159 |
% function. However, they may be overwritten by other non-kernel |
| 1160 |
% code and so should only be used for short-term storage. |
| 1161 |
% \end{variable} |
| 1162 |
% |
| 1163 |
% \section{Primitive conditional} |
| 1164 |
% |
| 1165 |
% \begin{function}[EXP]{\if_dim:w} |
| 1166 |
% \begin{syntax} |
| 1167 |
% \cs{if_dim:w} \meta{dimen_1} \meta{relation} \meta{dimen_2} |
| 1168 |
% ~~\meta{true code} |
| 1169 |
% \cs{else:} |
| 1170 |
% ~~\meta{false} |
| 1171 |
% \cs{fi:} |
| 1172 |
% \end{syntax} |
| 1173 |
% Compare two dimensions. The \meta{relation} is one of |
| 1174 |
% |<|, |=| or |>| with category code $12$. |
| 1175 |
% \begin{texnote} |
| 1176 |
% This is the \TeX{} primitive \tn{ifdim}. |
| 1177 |
% \end{texnote} |
| 1178 |
% \end{function} |
| 1179 |
% |
| 1180 |
% \end{documentation} |
| 1181 |
% |
| 1182 |
% \begin{implementation} |
| 1183 |
% |
| 1184 |
% \section{\pkg{l3skip} implementation} |
| 1185 |
% |
| 1186 |
% \begin{macrocode} |
| 1187 |
%<*code> |
| 1188 |
% \end{macrocode} |
| 1189 |
% |
| 1190 |
% \begin{macrocode} |
| 1191 |
%<@@=dim> |
| 1192 |
% \end{macrocode} |
| 1193 |
% |
| 1194 |
% \subsection{Length primitives renamed} |
| 1195 |
% |
| 1196 |
% \begin{macro}{\if_dim:w} |
| 1197 |
% \begin{macro}{\@@_eval:w} |
| 1198 |
% \begin{macro}{\@@_eval_end:} |
| 1199 |
% Primitives renamed. |
| 1200 |
% \begin{macrocode} |
| 1201 |
\cs_new_eq:NN \if_dim:w \tex_ifdim:D |
| 1202 |
\cs_new_eq:NN \@@_eval:w \tex_dimexpr:D |
| 1203 |
\cs_new_eq:NN \@@_eval_end: \tex_relax:D |
| 1204 |
% \end{macrocode} |
| 1205 |
% \end{macro} |
| 1206 |
% \end{macro} |
| 1207 |
% \end{macro} |
| 1208 |
% |
| 1209 |
% \subsection{Internal auxiliaries} |
| 1210 |
% |
| 1211 |
% \begin{variable}{\s_@@_mark,\s_@@_stop} |
| 1212 |
% Internal scan marks. |
| 1213 |
% \begin{macrocode} |
| 1214 |
\scan_new:N \s_@@_mark |
| 1215 |
\scan_new:N \s_@@_stop |
| 1216 |
% \end{macrocode} |
| 1217 |
% \end{variable} |
| 1218 |
% |
| 1219 |
% \begin{macro}[EXP]{\@@_use_none_delimit_by_s_stop:w} |
| 1220 |
% Functions to gobble up to a scan mark. |
| 1221 |
% \begin{macrocode} |
| 1222 |
\cs_new:Npn \@@_use_none_delimit_by_s_stop:w #1 \s_@@_stop { } |
| 1223 |
% \end{macrocode} |
| 1224 |
% \end{macro} |
| 1225 |
% |
| 1226 |
% \subsection{Creating and initializing \texttt{dim} variables} |
| 1227 |
% |
| 1228 |
% \begin{macro}{\dim_new:N, \dim_new:c} |
| 1229 |
% Allocating \meta{dim} registers \ldots |
| 1230 |
% \begin{macrocode} |
| 1231 |
\cs_new_protected:Npn \dim_new:N #1 |
| 1232 |
{ |
| 1233 |
\__kernel_chk_if_free_cs:N #1 |
| 1234 |
\cs:w newdimen \cs_end: #1 |
| 1235 |
} |
| 1236 |
\cs_generate_variant:Nn \dim_new:N { c } |
| 1237 |
% \end{macrocode} |
| 1238 |
% \end{macro} |
| 1239 |
% |
| 1240 |
% \begin{macro}{\dim_const:Nn, \dim_const:cn} |
| 1241 |
% Contrarily to integer constants, we cannot avoid using a register, |
| 1242 |
% even for constants. We cannot use \cs{dim_gset:Nn} because |
| 1243 |
% debugging code would complain that the constant is not a global |
| 1244 |
% variable. Since \cs{dim_const:Nn} does not need to be fast, use |
| 1245 |
% \cs{dim_eval:n} to avoid needing a debugging patch that wraps the |
| 1246 |
% expression in checking code. |
| 1247 |
% \begin{macrocode} |
| 1248 |
\cs_new_protected:Npn \dim_const:Nn #1#2 |
| 1249 |
{ |
| 1250 |
\dim_new:N #1 |
| 1251 |
\tex_global:D #1 = \dim_eval:n {#2} \scan_stop: |
| 1252 |
} |
| 1253 |
\cs_generate_variant:Nn \dim_const:Nn { c } |
| 1254 |
% \end{macrocode} |
| 1255 |
% \end{macro} |
| 1256 |
% |
| 1257 |
% \begin{macro}{\dim_zero:N, \dim_zero:c} |
| 1258 |
% \begin{macro}{\dim_gzero:N, \dim_gzero:c} |
| 1259 |
% Reset the register to zero. Using \cs{c_zero_skip} deals with the |
| 1260 |
% case where the variable passed is incorrectly a skip (for example a |
| 1261 |
% \LaTeXe{} length). Besides, these functions are then simply copied |
| 1262 |
% for \cs{skip_zero:N} and related functions. |
| 1263 |
% \begin{macrocode} |
| 1264 |
\cs_new_protected:Npn \dim_zero:N #1 { #1 = \c_zero_skip } |
| 1265 |
\cs_new_protected:Npn \dim_gzero:N #1 |
| 1266 |
{ \tex_global:D #1 = \c_zero_skip } |
| 1267 |
\cs_generate_variant:Nn \dim_zero:N { c } |
| 1268 |
\cs_generate_variant:Nn \dim_gzero:N { c } |
| 1269 |
% \end{macrocode} |
| 1270 |
% \end{macro} |
| 1271 |
% \end{macro} |
| 1272 |
% |
| 1273 |
% \begin{macro} |
| 1274 |
% {\dim_zero_new:N, \dim_zero_new:c, \dim_gzero_new:N, \dim_gzero_new:c} |
| 1275 |
% Create a register if needed, otherwise clear it. |
| 1276 |
% \begin{macrocode} |
| 1277 |
\cs_new_protected:Npn \dim_zero_new:N #1 |
| 1278 |
{ \dim_if_exist:NTF #1 { \dim_zero:N #1 } { \dim_new:N #1 } } |
| 1279 |
\cs_new_protected:Npn \dim_gzero_new:N #1 |
| 1280 |
{ \dim_if_exist:NTF #1 { \dim_gzero:N #1 } { \dim_new:N #1 } } |
| 1281 |
\cs_generate_variant:Nn \dim_zero_new:N { c } |
| 1282 |
\cs_generate_variant:Nn \dim_gzero_new:N { c } |
| 1283 |
% \end{macrocode} |
| 1284 |
% \end{macro} |
| 1285 |
% |
| 1286 |
% \begin{macro}[pTF]{\dim_if_exist:N, \dim_if_exist:c} |
| 1287 |
% Copies of the \texttt{cs} functions defined in \pkg{l3basics}. |
| 1288 |
% \begin{macrocode} |
| 1289 |
\prg_new_eq_conditional:NNn \dim_if_exist:N \cs_if_exist:N |
| 1290 |
{ TF , T , F , p } |
| 1291 |
\prg_new_eq_conditional:NNn \dim_if_exist:c \cs_if_exist:c |
| 1292 |
{ TF , T , F , p } |
| 1293 |
% \end{macrocode} |
| 1294 |
% \end{macro} |
| 1295 |
% |
| 1296 |
% \subsection{Setting \texttt{dim} variables} |
| 1297 |
% |
| 1298 |
% \begin{macro}{\dim_set:Nn, \dim_set:cn, \dim_set:NV, \dim_set:cV} |
| 1299 |
% \begin{macro}{\dim_gset:Nn, \dim_gset:cn, \dim_gset:NV, \dim_gset:cV} |
| 1300 |
% Setting dimensions is easy enough but when debugging we want both to |
| 1301 |
% check that the variable is correctly local/global and to wrap the |
| 1302 |
% expression in some code. The \cs{scan_stop:} deals with the case |
| 1303 |
% where the variable passed is a skip (for example a \LaTeXe{} |
| 1304 |
% length). |
| 1305 |
% \begin{macrocode} |
| 1306 |
\cs_new_protected:Npn \dim_set:Nn #1#2 |
| 1307 |
{ #1 = \@@_eval:w #2 \@@_eval_end: \scan_stop: } |
| 1308 |
\cs_new_protected:Npn \dim_gset:Nn #1#2 |
| 1309 |
{ \tex_global:D #1 = \@@_eval:w #2 \@@_eval_end: \scan_stop: } |
| 1310 |
\cs_generate_variant:Nn \dim_set:Nn { NV , c , cV } |
| 1311 |
\cs_generate_variant:Nn \dim_gset:Nn { NV , c , cV } |
| 1312 |
% \end{macrocode} |
| 1313 |
% \end{macro} |
| 1314 |
% \end{macro} |
| 1315 |
% |
| 1316 |
% \begin{macro}{\dim_set_eq:NN, \dim_set_eq:cN, \dim_set_eq:Nc, \dim_set_eq:cc} |
| 1317 |
% \begin{macro} |
| 1318 |
% {\dim_gset_eq:NN, \dim_gset_eq:cN, \dim_gset_eq:Nc, \dim_gset_eq:cc} |
| 1319 |
% All straightforward, with a \cs{scan_stop:} to deal with the case |
| 1320 |
% where |#1| is (incorrectly) a skip. |
| 1321 |
% \begin{macrocode} |
| 1322 |
\cs_new_protected:Npn \dim_set_eq:NN #1#2 |
| 1323 |
{ #1 = #2 \scan_stop: } |
| 1324 |
\cs_generate_variant:Nn \dim_set_eq:NN { c , Nc , cc } |
| 1325 |
\cs_new_protected:Npn \dim_gset_eq:NN #1#2 |
| 1326 |
{ \tex_global:D #1 = #2 \scan_stop: } |
| 1327 |
\cs_generate_variant:Nn \dim_gset_eq:NN { c , Nc , cc } |
| 1328 |
% \end{macrocode} |
| 1329 |
% \end{macro} |
| 1330 |
% \end{macro} |
| 1331 |
% |
| 1332 |
% \begin{macro}{\dim_add:Nn, \dim_add:cn} |
| 1333 |
% \begin{macro}{\dim_gadd:Nn, \dim_gadd:cn} |
| 1334 |
% \begin{macro}{\dim_sub:Nn, \dim_sub:cn} |
| 1335 |
% \begin{macro}{\dim_gsub:Nn, \dim_gsub:cn} |
| 1336 |
% Using |by| here would slow things down just to detect nonsensical |
| 1337 |
% cases such as passing |\dimen 123| as the first argument. |
| 1338 |
% Using \cs{scan_stop:} deals with skip variables. Since |
| 1339 |
% debugging checks that the variable is correctly local/global, the |
| 1340 |
% global versions cannot be defined as \cs{tex_global:D} followed by |
| 1341 |
% the local versions. |
| 1342 |
% \begin{macrocode} |
| 1343 |
\cs_new_protected:Npn \dim_add:Nn #1#2 |
| 1344 |
{ \tex_advance:D #1 \@@_eval:w #2 \@@_eval_end: \scan_stop: } |
| 1345 |
\cs_new_protected:Npn \dim_gadd:Nn #1#2 |
| 1346 |
{ |
| 1347 |
\tex_global:D \tex_advance:D #1 |
| 1348 |
\@@_eval:w #2 \@@_eval_end: \scan_stop: |
| 1349 |
} |
| 1350 |
\cs_generate_variant:Nn \dim_add:Nn { c } |
| 1351 |
\cs_generate_variant:Nn \dim_gadd:Nn { c } |
| 1352 |
\cs_new_protected:Npn \dim_sub:Nn #1#2 |
| 1353 |
{ \tex_advance:D #1 - \@@_eval:w #2 \@@_eval_end: \scan_stop: } |
| 1354 |
\cs_new_protected:Npn \dim_gsub:Nn #1#2 |
| 1355 |
{ |
| 1356 |
\tex_global:D \tex_advance:D #1 |
| 1357 |
-\@@_eval:w #2 \@@_eval_end: \scan_stop: |
| 1358 |
} |
| 1359 |
\cs_generate_variant:Nn \dim_sub:Nn { c } |
| 1360 |
\cs_generate_variant:Nn \dim_gsub:Nn { c } |
| 1361 |
% \end{macrocode} |
| 1362 |
% \end{macro} |
| 1363 |
% \end{macro} |
| 1364 |
% \end{macro} |
| 1365 |
% \end{macro} |
| 1366 |
% |
| 1367 |
% \subsection{Utilities for dimension calculations} |
| 1368 |
% |
| 1369 |
% \begin{macro}{\@@_sep:} |
| 1370 |
% \begin{macrocode} |
| 1371 |
\cs_new_eq:NN \@@_sep: \__kernel_int_sep: |
| 1372 |
% \end{macrocode} |
| 1373 |
% \end{macro} |
| 1374 |
% |
| 1375 |
% \begin{macro}[EXP]{\dim_abs:n} |
| 1376 |
% \begin{macro}[EXP]{\@@_abs:N} |
| 1377 |
% \UnitTested |
| 1378 |
% \begin{macro}[EXP]{\dim_max:nn} |
| 1379 |
% \begin{macro}[EXP]{\dim_min:nn} |
| 1380 |
% \begin{macro}[EXP]{\@@_maxmin:wwN} |
| 1381 |
% \UnitTested |
| 1382 |
% \UnitTested |
| 1383 |
% Functions for $\min$, $\max$, and absolute value with only one evaluation. |
| 1384 |
% The absolute value is evaluated by removing a leading~|-| if present. |
| 1385 |
% \begin{macrocode} |
| 1386 |
\cs_new:Npn \dim_abs:n #1 |
| 1387 |
{ |
| 1388 |
\exp_after:wN \@@_abs:N |
| 1389 |
\dim_use:N \@@_eval:w #1 \@@_eval_end: |
| 1390 |
} |
| 1391 |
\cs_new:Npn \@@_abs:N #1 |
| 1392 |
{ \if_meaning:w - #1 \else: \exp_after:wN #1 \fi: } |
| 1393 |
\cs_new:Npn \dim_max:nn #1#2 |
| 1394 |
{ |
| 1395 |
\dim_use:N \@@_eval:w \exp_after:wN \@@_maxmin:wwN |
| 1396 |
\dim_use:N \@@_eval:w #1 \exp_after:wN \@@_sep: |
| 1397 |
\dim_use:N \@@_eval:w #2 \@@_sep: |
| 1398 |
> |
| 1399 |
\@@_eval_end: |
| 1400 |
} |
| 1401 |
\cs_new:Npn \dim_min:nn #1#2 |
| 1402 |
{ |
| 1403 |
\dim_use:N \@@_eval:w \exp_after:wN \@@_maxmin:wwN |
| 1404 |
\dim_use:N \@@_eval:w #1 \exp_after:wN \@@_sep: |
| 1405 |
\dim_use:N \@@_eval:w #2 \@@_sep: |
| 1406 |
< |
| 1407 |
\@@_eval_end: |
| 1408 |
} |
| 1409 |
\cs_new:Npn \@@_maxmin:wwN #1 \@@_sep: #2 \@@_sep: #3 |
| 1410 |
{ |
| 1411 |
\if_dim:w #1 #3 #2 ~ |
| 1412 |
#1 |
| 1413 |
\else: |
| 1414 |
#2 |
| 1415 |
\fi: |
| 1416 |
} |
| 1417 |
% \end{macrocode} |
| 1418 |
% \end{macro} |
| 1419 |
% \end{macro} |
| 1420 |
% \end{macro} |
| 1421 |
% \end{macro} |
| 1422 |
% \end{macro} |
| 1423 |
% |
| 1424 |
% \begin{macro}{\dim_ratio:nn} |
| 1425 |
% \begin{macro}{\@@_ratio:n} |
| 1426 |
% With dimension expressions, something like |10 pt * ( 5 pt / 10 pt )| does |
| 1427 |
% not work. Instead, the ratio part needs to be converted to an integer |
| 1428 |
% expression. Using \cs{int_value:w} forces everything into |sp|, avoiding |
| 1429 |
% any decimal parts. |
| 1430 |
% \begin{macrocode} |
| 1431 |
\cs_new:Npn \dim_ratio:nn #1#2 |
| 1432 |
{ \@@_ratio:n {#1} / \@@_ratio:n {#2} } |
| 1433 |
\cs_new:Npn \@@_ratio:n #1 |
| 1434 |
{ \int_value:w \@@_eval:w (#1) \@@_eval_end: } |
| 1435 |
% \end{macrocode} |
| 1436 |
% \end{macro} |
| 1437 |
% \end{macro} |
| 1438 |
% |
| 1439 |
% \subsection{Dimension expression conditionals} |
| 1440 |
% |
| 1441 |
% \begin{macro}[pTF, EXP] |
| 1442 |
% { |
| 1443 |
% \dim_compare:nNn , |
| 1444 |
% \dim_compare:vNn , |
| 1445 |
% \dim_compare:nNv , |
| 1446 |
% \dim_compare:vNv |
| 1447 |
% } |
| 1448 |
% Simple comparison. |
| 1449 |
% \begin{macrocode} |
| 1450 |
\prg_new_conditional:Npnn \dim_compare:nNn #1#2#3 { p , T , F , TF } |
| 1451 |
{ |
| 1452 |
\if_dim:w \@@_eval:w #1 #2 \@@_eval:w #3 \@@_eval_end: |
| 1453 |
\prg_return_true: \else: \prg_return_false: \fi: |
| 1454 |
} |
| 1455 |
\cs_new:Npn \dim_compare_p:vNn #1#2#3 |
| 1456 |
{ \dim_compare_p:nNn { \use:c {#1} } #2 {#3} } |
| 1457 |
\cs_new:Npn \dim_compare_p:nNv #1#2#3 |
| 1458 |
{ \dim_compare_p:nNn {#1} #2 { \use:c {#3} } } |
| 1459 |
\cs_new:Npn \dim_compare_p:vNv #1#2#3 |
| 1460 |
{ \dim_compare_p:nNn { \use:c {#1} } #2 { \use:c {#3} } } |
| 1461 |
\clist_map_inline:nn { T , F , TF } |
| 1462 |
{ |
| 1463 |
\cs_new:cpe { dim_compare:vNn #1 } ##1##2##3 |
| 1464 |
{ |
| 1465 |
\exp_not:c { dim_compare:nNn #1 } |
| 1466 |
{ \exp_not:N \use:c {##1} } ##2 {##3} |
| 1467 |
} |
| 1468 |
\cs_new:cpe { dim_compare:nNv #1 } ##1##2##3 |
| 1469 |
{ |
| 1470 |
\exp_not:c { dim_compare:nNn #1 } |
| 1471 |
{##1} ##2 { \exp_not:N \use:c {##3} } |
| 1472 |
} |
| 1473 |
\cs_new:cpe { dim_compare:vNv #1 } ##1##2##3 |
| 1474 |
{ |
| 1475 |
\exp_not:c { dim_compare:nNn #1 } |
| 1476 |
{ \exp_not:N \use:c {##1} } ##2 { \exp_not:N \use:c {##3} } |
| 1477 |
} |
| 1478 |
} |
| 1479 |
% \end{macrocode} |
| 1480 |
% \end{macro} |
| 1481 |
% |
| 1482 |
% \begin{macro}[pTF, EXP]{\dim_compare:n} |
| 1483 |
% \begin{macro}[EXP]{\@@_compare:w, \@@_compare:wNN} |
| 1484 |
% \begin{macro}[EXP] |
| 1485 |
% { |
| 1486 |
% \@@_compare_=:w, |
| 1487 |
% \@@_compare_!:w, |
| 1488 |
% \@@_compare_<:w, |
| 1489 |
% \@@_compare_>:w |
| 1490 |
% } |
| 1491 |
% \begin{macro}{\@@_compare_error:} |
| 1492 |
% This code is adapted from the \cs{int_compare:nTF} function. First |
| 1493 |
% make sure that there is at least one relation operator, by |
| 1494 |
% evaluating a dimension expression with a trailing |
| 1495 |
% \cs{@@_compare_error:}. Just like for integers, the looping |
| 1496 |
% auxiliary \cs{@@_compare:wNN} closes a primitive conditional and |
| 1497 |
% opens a new one. It is actually easier to grab a dimension operand |
| 1498 |
% than an integer one, because once evaluated, dimensions all end with |
| 1499 |
% \texttt{pt} (with category other). Thus we do not need specific |
| 1500 |
% auxiliaries for the three \enquote{simple} relations |<|, |=|, |
| 1501 |
% and~|>|. |
| 1502 |
% \begin{macrocode} |
| 1503 |
\prg_new_conditional:Npnn \dim_compare:n #1 { p , T , F , TF } |
| 1504 |
{ |
| 1505 |
\exp_after:wN \@@_compare:w |
| 1506 |
\dim_use:N \@@_eval:w #1 \@@_compare_error: |
| 1507 |
} |
| 1508 |
\cs_new:Npn \@@_compare:w #1 \@@_compare_error: |
| 1509 |
{ |
| 1510 |
\exp_after:wN \if_false: \exp:w \exp_end_continue_f:w |
| 1511 |
\@@_compare:wNN #1 ? { = \@@_compare_end:w \else: } \s_@@_stop |
| 1512 |
} |
| 1513 |
\exp_args:Nno \use:nn |
| 1514 |
{ \cs_new:Npn \@@_compare:wNN #1 } { \tl_to_str:n {pt} #2#3 } |
| 1515 |
{ |
| 1516 |
\if_meaning:w = #3 |
| 1517 |
\use:c { @@_compare_#2:w } |
| 1518 |
\fi: |
| 1519 |
#1 pt \exp_stop_f: |
| 1520 |
\prg_return_false: |
| 1521 |
\exp_after:wN \@@_use_none_delimit_by_s_stop:w |
| 1522 |
\fi: |
| 1523 |
\reverse_if:N \if_dim:w #1 pt #2 |
| 1524 |
\exp_after:wN \@@_compare:wNN |
| 1525 |
\dim_use:N \@@_eval:w #3 |
| 1526 |
} |
| 1527 |
\cs_new:cpn { @@_compare_ ! :w } |
| 1528 |
#1 \reverse_if:N #2 ! #3 = { #1 #2 = #3 } |
| 1529 |
\cs_new:cpn { @@_compare_ = :w } |
| 1530 |
#1 \@@_eval:w = { #1 \@@_eval:w } |
| 1531 |
\cs_new:cpn { @@_compare_ < :w } |
| 1532 |
#1 \reverse_if:N #2 < #3 = { #1 #2 > #3 } |
| 1533 |
\cs_new:cpn { @@_compare_ > :w } |
| 1534 |
#1 \reverse_if:N #2 > #3 = { #1 #2 < #3 } |
| 1535 |
\cs_new:Npn \@@_compare_end:w #1 \prg_return_false: #2 \s_@@_stop |
| 1536 |
{ #1 \prg_return_false: \else: \prg_return_true: \fi: } |
| 1537 |
\cs_new_protected:Npn \@@_compare_error: |
| 1538 |
{ |
| 1539 |
\if_int_compare:w \c_zero_int \c_zero_int \fi: |
| 1540 |
= |
| 1541 |
\@@_compare_error: |
| 1542 |
} |
| 1543 |
% \end{macrocode} |
| 1544 |
% \end{macro} |
| 1545 |
% \end{macro} |
| 1546 |
% \end{macro} |
| 1547 |
% \end{macro} |
| 1548 |
% |
| 1549 |
% \begin{macro}[EXP, noTF]{\dim_case:nn} |
| 1550 |
% \begin{macro}{\@@_case:nnTF} |
| 1551 |
% \begin{macro}{\@@_case:nw, \@@_case_end:nw} |
| 1552 |
% For dimension cases, the first task to fully expand the check |
| 1553 |
% condition. The over all idea is then much the same as for |
| 1554 |
% \cs{str_case:nnTF} as described in \pkg{l3basics}. |
| 1555 |
% \begin{macrocode} |
| 1556 |
\cs_new:Npn \dim_case:nnTF #1 |
| 1557 |
{ |
| 1558 |
\exp:w |
| 1559 |
\exp_args:Nf \@@_case:nnTF { \dim_eval:n {#1} } |
| 1560 |
} |
| 1561 |
\cs_new:Npn \dim_case:nnT #1#2#3 |
| 1562 |
{ |
| 1563 |
\exp:w |
| 1564 |
\exp_args:Nf \@@_case:nnTF { \dim_eval:n {#1} } {#2} {#3} { } |
| 1565 |
} |
| 1566 |
\cs_new:Npn \dim_case:nnF #1#2 |
| 1567 |
{ |
| 1568 |
\exp:w |
| 1569 |
\exp_args:Nf \@@_case:nnTF { \dim_eval:n {#1} } {#2} { } |
| 1570 |
} |
| 1571 |
\cs_new:Npn \dim_case:nn #1#2 |
| 1572 |
{ |
| 1573 |
\exp:w |
| 1574 |
\exp_args:Nf \@@_case:nnTF { \dim_eval:n {#1} } {#2} { } { } |
| 1575 |
} |
| 1576 |
\cs_new:Npn \@@_case:nnTF #1#2#3#4 |
| 1577 |
{ \@@_case:nw {#1} #2 {#1} { } \s_@@_mark {#3} \s_@@_mark {#4} \s_@@_stop } |
| 1578 |
\cs_new:Npn \@@_case:nw #1#2#3 |
| 1579 |
{ |
| 1580 |
\dim_compare:nNnTF {#1} = {#2} |
| 1581 |
{ \@@_case_end:nw {#3} } |
| 1582 |
{ \@@_case:nw {#1} } |
| 1583 |
} |
| 1584 |
\cs_new:Npn \@@_case_end:nw #1#2#3 \s_@@_mark #4#5 \s_@@_stop |
| 1585 |
{ \exp_end: #1 #4 } |
| 1586 |
% \end{macrocode} |
| 1587 |
% \end{macro} |
| 1588 |
% \end{macro} |
| 1589 |
% \end{macro} |
| 1590 |
% |
| 1591 |
% \subsection{Dimension expression loops} |
| 1592 |
% |
| 1593 |
% \begin{macro}{\dim_while_do:nn} |
| 1594 |
% \begin{macro}{\dim_until_do:nn} |
| 1595 |
% \begin{macro}{\dim_do_while:nn} |
| 1596 |
% \begin{macro}{\dim_do_until:nn} |
| 1597 |
% |while_do| and |do_while| functions for dimensions. Same as for the |
| 1598 |
% |int| type only the names have changed. |
| 1599 |
% \begin{macrocode} |
| 1600 |
\cs_new:Npn \dim_while_do:nn #1#2 |
| 1601 |
{ |
| 1602 |
\dim_compare:nT {#1} |
| 1603 |
{ |
| 1604 |
#2 |
| 1605 |
\dim_while_do:nn {#1} {#2} |
| 1606 |
} |
| 1607 |
} |
| 1608 |
\cs_new:Npn \dim_until_do:nn #1#2 |
| 1609 |
{ |
| 1610 |
\dim_compare:nF {#1} |
| 1611 |
{ |
| 1612 |
#2 |
| 1613 |
\dim_until_do:nn {#1} {#2} |
| 1614 |
} |
| 1615 |
} |
| 1616 |
\cs_new:Npn \dim_do_while:nn #1#2 |
| 1617 |
{ |
| 1618 |
#2 |
| 1619 |
\dim_compare:nT {#1} |
| 1620 |
{ \dim_do_while:nn {#1} {#2} } |
| 1621 |
} |
| 1622 |
\cs_new:Npn \dim_do_until:nn #1#2 |
| 1623 |
{ |
| 1624 |
#2 |
| 1625 |
\dim_compare:nF {#1} |
| 1626 |
{ \dim_do_until:nn {#1} {#2} } |
| 1627 |
} |
| 1628 |
% \end{macrocode} |
| 1629 |
% \end{macro} |
| 1630 |
% \end{macro} |
| 1631 |
% \end{macro} |
| 1632 |
% \end{macro} |
| 1633 |
% |
| 1634 |
% \begin{macro}{\dim_while_do:nNnn} |
| 1635 |
% \begin{macro}{\dim_until_do:nNnn} |
| 1636 |
% \begin{macro}{\dim_do_while:nNnn} |
| 1637 |
% \begin{macro}{\dim_do_until:nNnn} |
| 1638 |
% |while_do| and |do_while| functions for dimensions. Same as for the |
| 1639 |
% |int| type only the names have changed. |
| 1640 |
% \begin{macrocode} |
| 1641 |
\cs_new:Npn \dim_while_do:nNnn #1#2#3#4 |
| 1642 |
{ |
| 1643 |
\dim_compare:nNnT {#1} #2 {#3} |
| 1644 |
{ |
| 1645 |
#4 |
| 1646 |
\dim_while_do:nNnn {#1} #2 {#3} {#4} |
| 1647 |
} |
| 1648 |
} |
| 1649 |
\cs_new:Npn \dim_until_do:nNnn #1#2#3#4 |
| 1650 |
{ |
| 1651 |
\dim_compare:nNnF {#1} #2 {#3} |
| 1652 |
{ |
| 1653 |
#4 |
| 1654 |
\dim_until_do:nNnn {#1} #2 {#3} {#4} |
| 1655 |
} |
| 1656 |
} |
| 1657 |
\cs_new:Npn \dim_do_while:nNnn #1#2#3#4 |
| 1658 |
{ |
| 1659 |
#4 |
| 1660 |
\dim_compare:nNnT {#1} #2 {#3} |
| 1661 |
{ \dim_do_while:nNnn {#1} #2 {#3} {#4} } |
| 1662 |
} |
| 1663 |
\cs_new:Npn \dim_do_until:nNnn #1#2#3#4 |
| 1664 |
{ |
| 1665 |
#4 |
| 1666 |
\dim_compare:nNnF {#1} #2 {#3} |
| 1667 |
{ \dim_do_until:nNnn {#1} #2 {#3} {#4} } |
| 1668 |
} |
| 1669 |
% \end{macrocode} |
| 1670 |
% \end{macro} |
| 1671 |
% \end{macro} |
| 1672 |
% \end{macro} |
| 1673 |
% \end{macro} |
| 1674 |
% |
| 1675 |
% \subsection{Dimension step functions} |
| 1676 |
% |
| 1677 |
% \begin{macro}{\dim_step_function:nnnN} |
| 1678 |
% \begin{macro}{\@@_step:wwwN, \@@_step:NnnnN} |
| 1679 |
% Before all else, evaluate the initial value, step, and final value. |
| 1680 |
% Repeating a function by steps first needs a check on the direction |
| 1681 |
% of the steps. After that, do the function for the start value then |
| 1682 |
% step and loop around. It would be more symmetrical to test for a |
| 1683 |
% step size of zero before checking the sign, but we optimize for the |
| 1684 |
% most frequent case (positive step). |
| 1685 |
% \begin{macrocode} |
| 1686 |
\cs_new:Npn \dim_step_function:nnnN #1#2#3 |
| 1687 |
{ |
| 1688 |
\exp_after:wN \@@_step:wwwN |
| 1689 |
\tex_the:D \@@_eval:w #1 \exp_after:wN \@@_sep: |
| 1690 |
\tex_the:D \@@_eval:w #2 \exp_after:wN \@@_sep: |
| 1691 |
\tex_the:D \@@_eval:w #3 \@@_sep: |
| 1692 |
} |
| 1693 |
\cs_new:Npn \@@_step:wwwN #1 \@@_sep: #2 \@@_sep: #3 \@@_sep: #4 |
| 1694 |
{ |
| 1695 |
\dim_compare:nNnTF {#2} > \c_zero_dim |
| 1696 |
{ \@@_step:NnnnN > } |
| 1697 |
{ |
| 1698 |
\dim_compare:nNnTF {#2} = \c_zero_dim |
| 1699 |
{ |
| 1700 |
\msg_expandable_error:nnn { kernel } { zero-step } {#4} |
| 1701 |
\use_none:nnnn |
| 1702 |
} |
| 1703 |
{ \@@_step:NnnnN < } |
| 1704 |
} |
| 1705 |
{#1} {#2} {#3} #4 |
| 1706 |
} |
| 1707 |
\cs_new:Npn \@@_step:NnnnN #1#2#3#4#5 |
| 1708 |
{ |
| 1709 |
\dim_compare:nNnF {#2} #1 {#4} |
| 1710 |
{ |
| 1711 |
#5 {#2} |
| 1712 |
\exp_args:NNf \@@_step:NnnnN |
| 1713 |
#1 { \dim_eval:n { #2 + #3 } } {#3} {#4} #5 |
| 1714 |
} |
| 1715 |
} |
| 1716 |
% \end{macrocode} |
| 1717 |
% \end{macro} |
| 1718 |
% \end{macro} |
| 1719 |
% |
| 1720 |
% \begin{macro}{\dim_step_inline:nnnn} |
| 1721 |
% \begin{macro}{\dim_step_variable:nnnNn} |
| 1722 |
% \begin{macro}{\@@_step:NNnnnn} |
| 1723 |
% The approach here is to build a function, with a global integer |
| 1724 |
% required to make the nesting safe (as seen in other in line |
| 1725 |
% functions), and map that function using \cs{dim_step_function:nnnN}. |
| 1726 |
% We put a \cs{prg_break_point:Nn} so that \texttt{map_break} |
| 1727 |
% functions from other modules correctly decrement \cs{g__kernel_prg_map_int} |
| 1728 |
% before looking for their own break point. The first argument is |
| 1729 |
% \cs{scan_stop:}, so that no breaking function recognizes this break |
| 1730 |
% point as its own. |
| 1731 |
% \begin{macrocode} |
| 1732 |
\cs_new_protected:Npn \dim_step_inline:nnnn |
| 1733 |
{ |
| 1734 |
\int_gincr:N \g__kernel_prg_map_int |
| 1735 |
\exp_args:NNc \@@_step:NNnnnn |
| 1736 |
\cs_gset_protected:Npn |
| 1737 |
{ @@_map_ \int_use:N \g__kernel_prg_map_int :w } |
| 1738 |
} |
| 1739 |
\cs_new_protected:Npn \dim_step_variable:nnnNn #1#2#3#4#5 |
| 1740 |
{ |
| 1741 |
\int_gincr:N \g__kernel_prg_map_int |
| 1742 |
\exp_args:NNc \@@_step:NNnnnn |
| 1743 |
\cs_gset_protected:Npe |
| 1744 |
{ @@_map_ \int_use:N \g__kernel_prg_map_int :w } |
| 1745 |
{#1}{#2}{#3} |
| 1746 |
{ |
| 1747 |
\tl_set:Nn \exp_not:N #4 {##1} |
| 1748 |
\exp_not:n {#5} |
| 1749 |
} |
| 1750 |
} |
| 1751 |
\cs_new_protected:Npn \@@_step:NNnnnn #1#2#3#4#5#6 |
| 1752 |
{ |
| 1753 |
#1 #2 ##1 {#6} |
| 1754 |
\dim_step_function:nnnN {#3} {#4} {#5} #2 |
| 1755 |
\prg_break_point:Nn \scan_stop: { \int_gdecr:N \g__kernel_prg_map_int } |
| 1756 |
} |
| 1757 |
% \end{macrocode} |
| 1758 |
% \end{macro} |
| 1759 |
% \end{macro} |
| 1760 |
% \end{macro} |
| 1761 |
% |
| 1762 |
% \subsection{Using \texttt{dim} expressions and variables} |
| 1763 |
% |
| 1764 |
% \begin{macro}{\dim_eval:n} |
| 1765 |
% Evaluating a dimension expression expandably. |
| 1766 |
% \begin{macrocode} |
| 1767 |
\cs_new:Npn \dim_eval:n #1 |
| 1768 |
{ \dim_use:N \@@_eval:w #1 \@@_eval_end: } |
| 1769 |
% \end{macrocode} |
| 1770 |
% \end{macro} |
| 1771 |
% |
| 1772 |
% \begin{macro}[EXP]{\dim_sign:n, \@@_sign:Nw} |
| 1773 |
% See \cs{dim_abs:n}. Contrarily to \cs{int_sign:n} the case of a |
| 1774 |
% zero dimension cannot be distinguished from a positive dimension by |
| 1775 |
% looking only at the first character, since |0.2pt| and |0pt| start |
| 1776 |
% the same way. We need explicit comparisons. We start by |
| 1777 |
% distinguishing the most common case of a positive dimension. |
| 1778 |
% \begin{macrocode} |
| 1779 |
\cs_new:Npn \dim_sign:n #1 |
| 1780 |
{ |
| 1781 |
\int_value:w \exp_after:wN \@@_sign:Nw |
| 1782 |
\dim_use:N \@@_eval:w #1 \@@_eval_end: \@@_sep: |
| 1783 |
\exp_stop_f: |
| 1784 |
} |
| 1785 |
\cs_new:Npn \@@_sign:Nw #1#2 \@@_sep: |
| 1786 |
{ |
| 1787 |
\if_dim:w #1#2 > \c_zero_dim |
| 1788 |
1 |
| 1789 |
\else: |
| 1790 |
\if_meaning:w - #1 |
| 1791 |
-1 |
| 1792 |
\else: |
| 1793 |
0 |
| 1794 |
\fi: |
| 1795 |
\fi: |
| 1796 |
} |
| 1797 |
% \end{macrocode} |
| 1798 |
% \end{macro} |
| 1799 |
% |
| 1800 |
% \begin{macro}{\dim_use:N, \dim_use:c} |
| 1801 |
% Accessing a \meta{dim}. We hand-code the |c| variant for some speed gain. |
| 1802 |
% \begin{macrocode} |
| 1803 |
\cs_new_eq:NN \dim_use:N \tex_the:D |
| 1804 |
\cs_new:Npn \dim_use:c #1 { \tex_the:D \cs:w #1 \cs_end: } |
| 1805 |
% \end{macrocode} |
| 1806 |
% \end{macro} |
| 1807 |
% |
| 1808 |
% \begin{macro}[EXP]{\dim_to_decimal:n} |
| 1809 |
% \begin{macro}[EXP]{\@@_to_decimal:w} |
| 1810 |
% A function which comes up often enough to deserve a place in the |
| 1811 |
% kernel. Evaluate the dimension expression~|#1| then remove the |
| 1812 |
% trailing \texttt{pt}. When debugging is enabled, the argument is |
| 1813 |
% put in parentheses as this prevents the dimension expression from |
| 1814 |
% terminating early and leaving extra tokens lying around. This is |
| 1815 |
% used a lot by low-level manipulations. |
| 1816 |
% \begin{macrocode} |
| 1817 |
\cs_new:Npn \dim_to_decimal:n #1 |
| 1818 |
{ |
| 1819 |
\exp_after:wN |
| 1820 |
\@@_to_decimal:w \dim_use:N \@@_eval:w #1 \@@_eval_end: |
| 1821 |
} |
| 1822 |
\use:e |
| 1823 |
{ |
| 1824 |
\cs_new:Npn \exp_not:N \@@_to_decimal:w |
| 1825 |
#1 . #2 \tl_to_str:n { pt } |
| 1826 |
} |
| 1827 |
{ |
| 1828 |
\int_compare:nNnTF {#2} > \c_zero_int |
| 1829 |
{ #1 . #2 } |
| 1830 |
{ #1 } |
| 1831 |
} |
| 1832 |
% \end{macrocode} |
| 1833 |
% \end{macro} |
| 1834 |
% \end{macro} |
| 1835 |
% |
| 1836 |
% \begin{macro}[EXP]{\dim_to_fp:n} |
| 1837 |
% Defined in \pkg{l3fp-convert}, documented here. |
| 1838 |
% \end{macro} |
| 1839 |
% |
| 1840 |
% \subsection{Conversion of \texttt{dim} to other units} |
| 1841 |
% |
| 1842 |
% The conversion from \texttt{pt} or \texttt{sp} to other units is complicated |
| 1843 |
% by the fact that \TeX{}'s conversion to \texttt{sp} involves rounding and |
| 1844 |
% hard-coded ratios. In order to give re-entrant outcomes, we therefore need |
| 1845 |
% to do quite a bit of work: see |
| 1846 |
% \url{https://github.com/latex3/latex3/issues/954} for detailed discussion. |
| 1847 |
% After dealing with the trivial case, we therefore have some work to do. |
| 1848 |
% The code to do this is contributed by Ruixi Zhang. |
| 1849 |
% |
| 1850 |
% \begin{macro}[EXP]{\dim_to_decimal_in_sp:n} |
| 1851 |
% The one easy case: the only requirement here is that we avoid an |
| 1852 |
% overflow. |
| 1853 |
% \begin{macrocode} |
| 1854 |
\cs_new:Npn \dim_to_decimal_in_sp:n #1 |
| 1855 |
{ \int_value:w \@@_eval:w #1 \@@_eval_end: } |
| 1856 |
% \end{macrocode} |
| 1857 |
% \end{macro} |
| 1858 |
% |
| 1859 |
% \begin{macro}[EXP] |
| 1860 |
% { |
| 1861 |
% \dim_to_decimal_in_bp:n , |
| 1862 |
% \dim_to_decimal_in_cc:n , |
| 1863 |
% \dim_to_decimal_in_cm:n , |
| 1864 |
% \dim_to_decimal_in_dd:n , |
| 1865 |
% \dim_to_decimal_in_in:n , |
| 1866 |
% \dim_to_decimal_in_mm:n , |
| 1867 |
% \dim_to_decimal_in_pc:n |
| 1868 |
% } |
| 1869 |
% \begin{macro}[EXP]{\@@_to_decimal_aux:w} |
| 1870 |
% We first set up a helper macro \cs[no-index]{@@_tmp:w} which takes two |
| 1871 |
% arguments. The first argument is one of the following engine-defined |
| 1872 |
% units: |in|,~|pc|, |cm|, |mm|, |bp|, |dd|, |cc|, |nd|, and~|nc|. |
| 1873 |
% The second argument is $\frac{1}{2}\delta^{-1}$ in reduced fraction, |
| 1874 |
% where $\delta>1$~is the engine-defined conversion factor for each unit. |
| 1875 |
% Note that $\delta$~must be strictly larger than~$1$ for the following |
| 1876 |
% algorithm to work. |
| 1877 |
% |
| 1878 |
% Here is how the algorithm works: Suppose that a user inputs a |
| 1879 |
% non-negative dimension in a unit that has conversion factor~$\delta>1$. |
| 1880 |
% Then this dimension is internally represented as $X$\,sp, where |
| 1881 |
% $X=\lfloor N\delta\rfloor$ for some integer $N\ge0$. We then seek a |
| 1882 |
% formula to express this $N$ using~$X$. |
| 1883 |
% The \cs[no-index]{dim_to_decimal_in_<unit>:n} functions shall return |
| 1884 |
% the number $N/2^{16}$ in decimal. This way, we guarantee the returned |
| 1885 |
% decimal followed by the original unit will parse to exactly~$X$\,sp. |
| 1886 |
% |
| 1887 |
% So how do we get $N$ from~$X$? Well, since $X=\lfloor N\delta\rfloor$, |
| 1888 |
% we have $X\le N\delta<X+1$ and $X\delta^{-1}\le N<(X+1)\delta^{-1}$. |
| 1889 |
% Let's focus on the midpoint of this bounding interval for~$N$. The |
| 1890 |
% midpoint is $(X+\frac{1}{2})\delta^{-1}$. The fact $\delta>1$ implies |
| 1891 |
% that the bounding interval is shorter than~$1$ in length. Thus, |
| 1892 |
% (1)~$\hbox{midpoint}+\frac{1}{2}>N$ and |
| 1893 |
% (2)~$\hbox{midpoint}+\frac{1}{2}<N+1$. In other words, |
| 1894 |
% $N=\lfloor\hbox{midpoint}+\frac{1}{2}\rfloor$. As long as we can |
| 1895 |
% rewrite the midpoint as the result of a \enquote{scaling operation} of \eTeX, |
| 1896 |
% the $\lfloor\ldots+\frac{1}{2}\rfloor$ part will follow naturally. |
| 1897 |
% Indeed we can: $\hbox{midpoint}=(2X+1)\times(\frac{1}{2}\delta^{-1})$. |
| 1898 |
% |
| 1899 |
% Addendum: If $\delta\ge2$, then the bounding interval for~$N$ is at |
| 1900 |
% most~$\frac{1}{2}$ wide in length. In this case, the leftpoint |
| 1901 |
% $X\delta^{-1}$ suffices as $N=\lfloor X\delta^{-1}+\frac{1}{2}\rfloor$. |
| 1902 |
% Six out of the nine units listed above can be handled in this way, |
| 1903 |
% which is much simpler than using midpoint. But three remaining units |
| 1904 |
% have $1<\delta<2$; they are |bp|~($\delta=7227/7200$), |
| 1905 |
% |nd|~($\delta=685/642$), and |dd|~($\delta=1238/1157$), |
| 1906 |
% and these three must be handled using midpoint. |
| 1907 |
% For consistency, we shall use the midpoint approach for all nine units. |
| 1908 |
% \begin{macrocode} |
| 1909 |
\group_begin: |
| 1910 |
\cs_set_protected:Npn \@@_tmp:w #1#2 |
| 1911 |
{ |
| 1912 |
\cs_new:cpn { dim_to_decimal_in_ #1 :n } ##1 |
| 1913 |
{ |
| 1914 |
\exp_after:wN \@@_to_decimal_aux:w |
| 1915 |
\int_value:w \@@_eval:w ##1 \@@_eval_end: \@@_sep: #2 \@@_sep: |
| 1916 |
} |
| 1917 |
} |
| 1918 |
% \end{macrocode} |
| 1919 |
% Conversions to other units are now coded. |
| 1920 |
% Consult the pdf\/\TeX{} source for each conversion factor~$\delta$. |
| 1921 |
% Each factor $\frac{1}{2}\delta^{-1}$ is hand-coded |
| 1922 |
% for accuracy (and speed). As the units \texttt{nc} and \texttt{nd} |
| 1923 |
% are not supported by \XeTeX{} or (u)p\TeX{}, they are not included |
| 1924 |
% here. |
| 1925 |
% \begin{macrocode} |
| 1926 |
\@@_tmp:w { in } { 50 / 7227 } % delta = 7227/100 |
| 1927 |
\@@_tmp:w { pc } { 1 / 24 } % delta = 12/1 |
| 1928 |
\@@_tmp:w { cm } { 127 / 7227 } % delta = 7227/254 |
| 1929 |
\@@_tmp:w { mm } { 1270 / 7227 } % delta = 7227/2540 |
| 1930 |
\@@_tmp:w { bp } { 400 / 803 } % delta = 7227/7200 |
| 1931 |
\@@_tmp:w { dd } { 1157 / 2476 } % delta = 1238/1157 |
| 1932 |
\@@_tmp:w { cc } { 1157 / 29712 } % delta = 14856/1157 |
| 1933 |
\group_end: |
| 1934 |
% \end{macrocode} |
| 1935 |
% The tokens after \cs{@@_to_decimal_aux:w} shall have the following form: |
| 1936 |
% |<number>|\cs{@@_sep:}|<half of delta inverse>|\cs{@@_sep:}, where |
| 1937 |
% |<number>| represents the input dimension in |sp| unit. |
| 1938 |
% If |<number>| is positive, then |#1| is its leading digit and |#2| |
| 1939 |
% (possibly empty) is all the remaining digits; |
| 1940 |
% If |<number>| is zero, then |#1| is~|0|$_{12}$ and |#2| is empty; |
| 1941 |
% If |<number>| is negative, then |#1| is its sign~|-|$_{12}$ and |#2| |
| 1942 |
% is all its digits. |
| 1943 |
% In all three cases, |#1#2| is the original |<number>|. We can use |#1| |
| 1944 |
% to decide whether to use the |-1| formula or the |+1| formula. |
| 1945 |
% \begin{macrocode} |
| 1946 |
\cs_new:Npn \@@_to_decimal_aux:w #1#2 \@@_sep: #3 \@@_sep: |
| 1947 |
{ |
| 1948 |
\dim_to_decimal:n |
| 1949 |
{ |
| 1950 |
% \end{macrocode} |
| 1951 |
% We need different formulae depending on whether the user input dimension |
| 1952 |
% is negative or not. |
| 1953 |
% For negative dimension (internally represented as $X$\,sp), the formula |
| 1954 |
% is $(2X-1)\times(\frac{1}{2}\delta^{-1})$. |
| 1955 |
% For non-negative dimension, the formula |
| 1956 |
% is $(2X+1)\times(\frac{1}{2}\delta^{-1})$. |
| 1957 |
% The intermediate step doubles the dimension~$X$. |
| 1958 |
% To avoid overflow, we must invoke \cs[no-index]{int_eval:n}. |
| 1959 |
% \begin{macrocode} |
| 1960 |
\int_eval:n |
| 1961 |
{ ( 2 * #1#2 \if:w #1 - - \else: + \fi: 1 ) * #3 } |
| 1962 |
% \end{macrocode} |
| 1963 |
% Now we append~|sp| to finish the dimension specification. |
| 1964 |
% \begin{macrocode} |
| 1965 |
sp |
| 1966 |
} |
| 1967 |
} |
| 1968 |
% \end{macrocode} |
| 1969 |
% \end{macro} |
| 1970 |
% \end{macro} |
| 1971 |
% |
| 1972 |
% \begin{macro}[EXP]{\dim_to_decimal_in_unit:nn} |
| 1973 |
% \begin{macrocode} |
| 1974 |
\cs_new:Npn \dim_to_decimal_in_unit:nn #1#2 |
| 1975 |
{ |
| 1976 |
\exp_after:wN \@@_chk_unit:w |
| 1977 |
\int_value:w \@@_eval:w #2 \@@_eval_end: \@@_sep: {#1} |
| 1978 |
} |
| 1979 |
% \end{macrocode} |
| 1980 |
% \end{macro} |
| 1981 |
% \begin{macro}[EXP]{\@@_chk_unit:w} |
| 1982 |
% The tokens after \cs{@@_chk_unit:w} shall have the following form: |
| 1983 |
% |<number2>|\cs{@@_sep:}|{<dimexpr1>}|, where |<number2>| represents |
| 1984 |
% |<dimexpr2>| in |sp| unit. |
| 1985 |
% If |#1| is~|0|$_{12}$, the \enquote{unit} |<dimexpr2>| must also be zero. |
| 1986 |
% So we throw out a \enquote{division by zero} error message at this point. |
| 1987 |
% Otherwise, if |#1| is~|-|$_{12}$, we shall negate both |<dimexpr1>| and |
| 1988 |
% |<dimexpr2>| for later procedures. |
| 1989 |
% \begin{macrocode} |
| 1990 |
\cs_new:Npn \@@_chk_unit:w #1#2 \@@_sep: #3 |
| 1991 |
{ |
| 1992 |
\token_if_eq_charcode:NNTF #1 0 |
| 1993 |
{ \msg_expandable_error:nn { dim } { zero-unit } } |
| 1994 |
{ |
| 1995 |
\exp_after:wN \@@_branch_unit:w |
| 1996 |
\int_value:w \if:w #1 - - \fi: \@@_eval:w #3 \exp_after:wN \@@_sep: |
| 1997 |
\int_value:w \if:w #1 - - \fi: #1#2 \@@_sep: |
| 1998 |
} |
| 1999 |
} |
| 2000 |
% \end{macrocode} |
| 2001 |
% \end{macro} |
| 2002 |
% \begin{macro}[EXP]{\@@_branch_unit:w} |
| 2003 |
% The tokens after \cs{@@_branch_unit:w} shall have the following form: |
| 2004 |
% |<number1>|\cs{@@_sep:}|<number2>|\cs{@@_sep:}, where |<number1>| |
| 2005 |
% represents |<dimexpr1>| in |
| 2006 |
% |sp| unit (whose sign is taken care of) and |<number2>| represents the |
| 2007 |
% absolute value of |<dimexpr2>| in |sp| unit (which is strictly positive). |
| 2008 |
% |
| 2009 |
% As explained, the formulae $(2X\pm1)\times(\frac{1}{2}\delta^{-1})$ work |
| 2010 |
% if and only if $\delta=|<number2>|/65536>1$. This corresponds to |
| 2011 |
% |<dimexpr2>| strictly larger than 1\,pt in absolute value. |
| 2012 |
% In this case, we simply call \cs{@@_to_decimal_aux:w} and supply |
| 2013 |
% $\frac{1}{2}\delta^{-1}=32768/|<number2>|$ as |<half of delta inverse>|. |
| 2014 |
% |
| 2015 |
% Otherwise if $|<number2>|=65536$, then |<dimexpr2>| is 1\,pt in absolute |
| 2016 |
% value and we call \cs{dim_to_decimal:n} directly. |
| 2017 |
% |
| 2018 |
% Otherwise $0<|<number2>|<65536$ and we shall proceed differently. |
| 2019 |
% |
| 2020 |
% For unit less than 1\,pt, write $n=|<number2>|$, then $\delta=n/65536<1$. |
| 2021 |
% The midpoint formulae are not optimal. Let's go back to the inequalities |
| 2022 |
% $X\delta^{-1}\le N<(X+1)\delta^{-1}$. Since now $\delta<1$, the bounding |
| 2023 |
% interval is wider than~$1$ in length. Consider the ceiling integer |
| 2024 |
% $M=\lceil X\delta^{-1}\rceil$, then $X\delta^{-1}\le M<(X+1)\delta^{-1}$, |
| 2025 |
% or equivalently $X\le M\delta<X+1$, and thus $\lfloor M\delta\rfloor=X$. |
| 2026 |
% The key point here is that we \emph{don't} need to solve for~$N$; |
| 2027 |
% in fact, any integer that can reproduce~$X$ (such as~$M$) is good enough. |
| 2028 |
% So the algorithm goes like this: (1)~Compute rounding of $X\delta^{-1}$, |
| 2029 |
% i.e., $M'=\lfloor X\delta^{-1}+\frac{1}{2}\rfloor$; this $M'$ could be |
| 2030 |
% either $M$ or $M-1$. (2)~Check if $\lfloor M'\delta\rfloor=X$, i.e., |
| 2031 |
% whether our candidate $M'$ can reproduce~$X$. If so, then this $M'$ is |
| 2032 |
% good enough; if not, then we add one to~$M'$. |
| 2033 |
% |
| 2034 |
% But when $0<n<65536$, we cannot delay the problem of overflow any more. |
| 2035 |
% For $X\delta^{-1}=X\times65536/n$, where $X$ can go up to $2^{30}-1$ and |
| 2036 |
% $n$ can be as small as~$1$, the result is well over $2^{31}-1$ (largest |
| 2037 |
% integer allowed within |\numexpr|). |
| 2038 |
% For example, |\dim_to_decimal_in_unit:nn { \maxdimen } { 1sp }|. |
| 2039 |
% Here, all inputs are legal, so we should be able to output |1073741823| |
| 2040 |
% \emph{without} causing arithmetic overflow. |
| 2041 |
% |
| 2042 |
% As a workaround, let's write $X=qn+r$ with some $q\ge0$ and $0\le r<n$. |
| 2043 |
% Then $X\delta^{-1}=65536q+65536r/n$, and so |
| 2044 |
% $M'=65536q+\lfloor65536r/n+\frac{1}{2}\rfloor=65536q+R'$. |
| 2045 |
% Computing $R'$ will never overflow. If this $R'$ can reproduce~$r$, then |
| 2046 |
% it is good enough; otherwise we add one to~$R'$. In the end, we shall |
| 2047 |
% output $q+R'/65536$ in decimal. |
| 2048 |
% |
| 2049 |
% Note: $q=\lfloor X/n\rfloor=\lfloor\frac{2X-n}{2n}+\frac{1}{2}\rfloor$ |
| 2050 |
% represents the \enquote{integer} part, while $0\le R'\le65536$ represents the |
| 2051 |
% \enquote{fractional} part. (Can $R'=65536$ really happen? Didn't investigate.) |
| 2052 |
% \begin{macrocode} |
| 2053 |
\cs_new:Npn \@@_branch_unit:w #1 \@@_sep: #2 \@@_sep: |
| 2054 |
{ |
| 2055 |
\int_compare:nNnTF {#2} > { 65536 } |
| 2056 |
{ \@@_to_decimal_aux:w #1 \@@_sep: 32768 / #2 \@@_sep: } |
| 2057 |
{ |
| 2058 |
\int_compare:nNnTF {#2} = { 65536 } |
| 2059 |
{ \dim_to_decimal:n { #1sp } } |
| 2060 |
{ \@@_get_quotient:w #1 \@@_sep: #2 \@@_sep: } |
| 2061 |
} |
| 2062 |
} |
| 2063 |
% \end{macrocode} |
| 2064 |
% \end{macro} |
| 2065 |
% \begin{macro}[EXP]{\@@_get_quotient:w} |
| 2066 |
% We wish to get the quotient $q$ via rounding of $\frac{2X-n}{2n}$. |
| 2067 |
% When $0\le X<n/2$, we have $\frac{2X-n}{2n}<0$. So, strictly speaking, |
| 2068 |
% |\numexpr| performs its rounding as |
| 2069 |
% $\lceil\frac{2X-n}{2n}-\frac{1}{2}\rceil$, not exactly what we want. |
| 2070 |
% However, lucky for us, only $X=0$ makes |
| 2071 |
% $\lceil\frac{2X-n}{2n}-\frac{1}{2}\rceil=-1\neq0$ (we want~$0$); |
| 2072 |
% all other $0<X<n/2$ make $\lceil\frac{2X-n}{2n}-\frac{1}{2}\rceil=0=q$. |
| 2073 |
% Thus, let's filter out $X=0$ early. |
| 2074 |
% If $X\neq0$, we extract its sign and leave the sign to the back. |
| 2075 |
% The sign does not participate in any calculations (also the code works |
| 2076 |
% with positive integers only). The sign is used at the last stages when |
| 2077 |
% we parse the decimal output. |
| 2078 |
% |
| 2079 |
% After \cs{@@_get_quotient:w} has done its job, either we have the |
| 2080 |
% decimal~|0|, or we have \cs{@@_get_remainder:w} followed by |
| 2081 |
% $q$\cs{@@_sep:}$\lvert X\rvert$\cs{@@_sep:}$n$\cs{@@_sep:}|<sign of X>|\cs{@@_sep:}. |
| 2082 |
% \begin{macrocode} |
| 2083 |
\cs_new:Npn \@@_get_quotient:w #1#2 \@@_sep: #3 \@@_sep: |
| 2084 |
{ |
| 2085 |
\token_if_eq_charcode:NNTF #1 0 |
| 2086 |
{ 0 } |
| 2087 |
{ |
| 2088 |
\token_if_eq_charcode:NNTF #1 - |
| 2089 |
{ |
| 2090 |
\exp_after:wN \exp_after:wN \exp_after:wN \@@_get_remainder:w |
| 2091 |
\int_eval:n { ( 2 * #2 - #3 ) / ( 2 * #3 ) } \@@_sep: |
| 2092 |
#2 \@@_sep: #3 \@@_sep: - \@@_sep: |
| 2093 |
} |
| 2094 |
{ |
| 2095 |
\exp_after:wN \exp_after:wN \exp_after:wN \@@_get_remainder:w |
| 2096 |
\int_eval:n { ( 2 * #1#2 - #3 ) / ( 2 * #3 ) } \@@_sep: |
| 2097 |
#1#2 \@@_sep: #3 \@@_sep: \@@_sep: |
| 2098 |
} |
| 2099 |
} |
| 2100 |
} |
| 2101 |
% \end{macrocode} |
| 2102 |
% \end{macro} |
| 2103 |
% \begin{macro}[EXP]{\@@_get_remainder:w} |
| 2104 |
% \cs{@@_get_remainder:w} does not need to read the sign. |
| 2105 |
% After finding the remainder~$r$, the number~$\lvert X\rvert$ is no longer |
| 2106 |
% needed. We should then have \cs{@@_convert_remainder:w} followed by |
| 2107 |
% $r$\cs{@@_sep:}$n$\cs{@@_sep:}$q$\cs{@@_sep:}|<sign of X>|\cs{@@_sep:}. |
| 2108 |
% \begin{macrocode} |
| 2109 |
\cs_new:Npn \@@_get_remainder:w #1 \@@_sep: #2 \@@_sep: #3 \@@_sep: |
| 2110 |
{ |
| 2111 |
\exp_after:wN \exp_after:wN \exp_after:wN \@@_convert_remainder:w |
| 2112 |
\int_eval:n { #2 - #1 * #3 } \@@_sep: |
| 2113 |
#3 \@@_sep: #1 \@@_sep: |
| 2114 |
} |
| 2115 |
% \end{macrocode} |
| 2116 |
% \end{macro} |
| 2117 |
% \begin{macro}[EXP]{\@@_convert_remainder:w} |
| 2118 |
% This is trivial. We compute $R'=\lfloor65536r/n+\frac{1}{2}\rfloor$, |
| 2119 |
% then leave \cs{@@_test_candidate:w} followed by |
| 2120 |
% $R'$\cs{@@_sep:}$r$\cs{@@_sep:}$n$\cs{@@_sep:}$q$\cs{@@_sep:}|<sign of X>|\cs{@@_sep:}. |
| 2121 |
% \begin{macrocode} |
| 2122 |
\cs_new:Npn \@@_convert_remainder:w #1 \@@_sep: #2 \@@_sep: |
| 2123 |
{ |
| 2124 |
\exp_after:wN \exp_after:wN \exp_after:wN \@@_test_candidate:w |
| 2125 |
\int_eval:n { #1 * 65536 / #2 } \@@_sep: |
| 2126 |
#1 \@@_sep: #2 \@@_sep: |
| 2127 |
} |
| 2128 |
% \end{macrocode} |
| 2129 |
% \end{macro} |
| 2130 |
% \begin{macro}[EXP]{\@@_test_candidate:w} |
| 2131 |
% Now the fun part: We take $R'$, $r$ and~$n$ to test whether |
| 2132 |
% $r=\lfloor R'\delta\rfloor$. This is done as a dimension comparison. |
| 2133 |
% The left-hand side, $r$, is simply |r sp|. The right-hand side, |
| 2134 |
% $\lfloor R'\delta\rfloor$, is exactly |<R' as decimal><dimen = n sp>|. |
| 2135 |
% If the result is true, then we've found~$R'$; |
| 2136 |
% otherwise we add one to~$R'$. |
| 2137 |
% After this step, $r$ and~$n$ are no longer needed. We should then have |
| 2138 |
% \cs{@@_parse_decimal:w} followed by $R'$\cs{@@_sep:}$q$\cs{@@_sep:}|<sign of X>|\cs{@@_sep:}. |
| 2139 |
% \begin{macrocode} |
| 2140 |
\cs_new:Npn \@@_test_candidate:w #1 \@@_sep: #2 \@@_sep: #3 \@@_sep: |
| 2141 |
{ |
| 2142 |
\dim_compare:nNnTF { #2sp } = |
| 2143 |
{ \dim_to_decimal:n { #1sp } \@@_eval:w #3sp \@@_eval_end: } |
| 2144 |
{ \@@_parse_decimal:w #1 \@@_sep: } |
| 2145 |
{ |
| 2146 |
\@@_parse_decimal:w \int_eval:n { #1 + 1 } \@@_sep: |
| 2147 |
} |
| 2148 |
} |
| 2149 |
% \end{macrocode} |
| 2150 |
% \end{macro} |
| 2151 |
% \begin{macro}[EXP]{\@@_parse_decimal:w, \@@_parse_decimal_aux:w} |
| 2152 |
% The Grand Finale: We sum $q$ and $R'/65536$ together, and negate the |
| 2153 |
% result if necessary. These are all done expandably. |
| 2154 |
% If $0<R'/65536<1$, the integer summation is naturally terminated at the |
| 2155 |
% decimal point. If $R'/65536=0$ (or~$1$?), the summation is terminated |
| 2156 |
% at the \cs{@@_sep:}. The auxiliary function \cs{@@_parse_decimal_aux:w} |
| 2157 |
% takes care of both cases. |
| 2158 |
% \begin{macrocode} |
| 2159 |
\cs_new:Npn \@@_parse_decimal:w #1 \@@_sep: #2 \@@_sep: #3 \@@_sep: |
| 2160 |
{ |
| 2161 |
\exp_after:wN \@@_parse_decimal_aux:w |
| 2162 |
\int_value:w #3 \int_eval:w #2 + \dim_to_decimal:n { #1sp } \@@_sep: |
| 2163 |
} |
| 2164 |
\cs_new:Npn \@@_parse_decimal_aux:w #1 \@@_sep: {#1} |
| 2165 |
% \end{macrocode} |
| 2166 |
% \end{macro} |
| 2167 |
% |
| 2168 |
% \subsection{Viewing \texttt{dim} variables} |
| 2169 |
% |
| 2170 |
% \begin{macro}{\dim_show:N, \dim_show:c} |
| 2171 |
% Diagnostics. |
| 2172 |
% \begin{macrocode} |
| 2173 |
\cs_new_eq:NN \dim_show:N \__kernel_register_show:N |
| 2174 |
\cs_generate_variant:Nn \dim_show:N { c } |
| 2175 |
% \end{macrocode} |
| 2176 |
% \end{macro} |
| 2177 |
% |
| 2178 |
% \begin{macro}{\dim_show:n} |
| 2179 |
% Diagnostics. We don't use the \TeX{} primitive \tn{showthe} to show |
| 2180 |
% dimension expressions: this gives a more unified output. |
| 2181 |
% \begin{macrocode} |
| 2182 |
\cs_new_protected:Npn \dim_show:n |
| 2183 |
{ \__kernel_msg_show_eval:Nn \dim_eval:n } |
| 2184 |
% \end{macrocode} |
| 2185 |
% \end{macro} |
| 2186 |
% |
| 2187 |
% \begin{macro}{\dim_log:N, \dim_log:c, \dim_log:n} |
| 2188 |
% Diagnostics. Redirect output of \cs{dim_show:n} to the log. |
| 2189 |
% \begin{macrocode} |
| 2190 |
\cs_new_eq:NN \dim_log:N \__kernel_register_log:N |
| 2191 |
\cs_new_eq:NN \dim_log:c \__kernel_register_log:c |
| 2192 |
\cs_new_protected:Npn \dim_log:n |
| 2193 |
{ \__kernel_msg_log_eval:Nn \dim_eval:n } |
| 2194 |
% \end{macrocode} |
| 2195 |
% \end{macro} |
| 2196 |
% |
| 2197 |
% \subsection{Constant dimensions} |
| 2198 |
% |
| 2199 |
% \begin{variable}{\c_zero_dim, \c_max_dim} |
| 2200 |
% Constant dimensions. |
| 2201 |
% \begin{macrocode} |
| 2202 |
\dim_const:Nn \c_zero_dim { 0 pt } |
| 2203 |
\dim_const:Nn \c_max_dim { 16383.99999 pt } |
| 2204 |
% \end{macrocode} |
| 2205 |
% \end{variable} |
| 2206 |
% |
| 2207 |
% \subsection{Scratch dimensions} |
| 2208 |
% |
| 2209 |
% \begin{variable}{\l_tmpa_dim, \l_tmpb_dim} |
| 2210 |
% \begin{variable}{\g_tmpa_dim, \g_tmpb_dim} |
| 2211 |
% We provide two local and two global scratch registers, maybe we |
| 2212 |
% need more or less. |
| 2213 |
% \begin{macrocode} |
| 2214 |
\dim_new:N \l_tmpa_dim |
| 2215 |
\dim_new:N \l_tmpb_dim |
| 2216 |
\dim_new:N \g_tmpa_dim |
| 2217 |
\dim_new:N \g_tmpb_dim |
| 2218 |
% \end{macrocode} |
| 2219 |
% \end{variable} |
| 2220 |
% \end{variable} |
| 2221 |
% |
| 2222 |
% \subsection{Inserting dimensions into the output} |
| 2223 |
% |
| 2224 |
% \begin{macro} |
| 2225 |
% { |
| 2226 |
% \dim_horizontal:n , |
| 2227 |
% \dim_horizontal:N , |
| 2228 |
% \dim_horizontal:c , |
| 2229 |
% \dim_vertical:n , |
| 2230 |
% \dim_vertical:N , |
| 2231 |
% \dim_vertical:c |
| 2232 |
% } |
| 2233 |
% \begin{macro}{\@@_kern:n} |
| 2234 |
% \TeX{} does not treat kerns differently in horizontal and vertical mode. |
| 2235 |
% As we want skips and kerns to have similar behavior, we try to get similar |
| 2236 |
% results. |
| 2237 |
% \begin{macrocode} |
| 2238 |
\cs_new_protected:Npn \dim_horizontal:n #1 |
| 2239 |
{ |
| 2240 |
\mode_leave_vertical: |
| 2241 |
\@@_kern:n {#1} |
| 2242 |
} |
| 2243 |
\cs_set_eq:NN \dim_horizontal:N \dim_horizontal:n |
| 2244 |
\cs_generate_variant:Nn \dim_horizontal:N { c } |
| 2245 |
\cs_new_protected:Npn \dim_vertical:n #1 |
| 2246 |
{ |
| 2247 |
\mode_if_vertical:F |
| 2248 |
{ \par } |
| 2249 |
\@@_kern:n {#1} |
| 2250 |
} |
| 2251 |
\cs_set_eq:NN \dim_vertical:N \dim_vertical:n |
| 2252 |
\cs_generate_variant:Nn \dim_vertical:N { c } |
| 2253 |
\cs_new_protected:Npn \@@_kern:n #1 |
| 2254 |
{ \tex_kern:D \tex_dimexpr:D #1 \scan_stop: } |
| 2255 |
% \end{macrocode} |
| 2256 |
% \end{macro} |
| 2257 |
% \end{macro} |
| 2258 |
% |
| 2259 |
% \subsection{Creating and initializing \texttt{skip} variables} |
| 2260 |
% |
| 2261 |
% \begin{macrocode} |
| 2262 |
%<@@=skip> |
| 2263 |
% \end{macrocode} |
| 2264 |
% |
| 2265 |
% \begin{variable}{\s_@@_stop} |
| 2266 |
% Internal scan marks. |
| 2267 |
% \begin{macrocode} |
| 2268 |
\scan_new:N \s_@@_stop |
| 2269 |
% \end{macrocode} |
| 2270 |
% \end{variable} |
| 2271 |
% |
| 2272 |
% \begin{macro}{\skip_new:N, \skip_new:c} |
| 2273 |
% Allocation of a new internal registers. |
| 2274 |
% \begin{macrocode} |
| 2275 |
\cs_new_protected:Npn \skip_new:N #1 |
| 2276 |
{ |
| 2277 |
\__kernel_chk_if_free_cs:N #1 |
| 2278 |
\cs:w newskip \cs_end: #1 |
| 2279 |
} |
| 2280 |
\cs_generate_variant:Nn \skip_new:N { c } |
| 2281 |
% \end{macrocode} |
| 2282 |
% \end{macro} |
| 2283 |
% |
| 2284 |
% \begin{macro}{\skip_const:Nn, \skip_const:cn} |
| 2285 |
% Contrarily to integer constants, we cannot avoid using a register, |
| 2286 |
% even for constants. See \cs{dim_const:Nn} for why we cannot use |
| 2287 |
% \cs{skip_gset:Nn}. |
| 2288 |
% \begin{macrocode} |
| 2289 |
\cs_new_protected:Npn \skip_const:Nn #1#2 |
| 2290 |
{ |
| 2291 |
\skip_new:N #1 |
| 2292 |
\tex_global:D #1 = \skip_eval:n {#2} \scan_stop: |
| 2293 |
} |
| 2294 |
\cs_generate_variant:Nn \skip_const:Nn { c } |
| 2295 |
% \end{macrocode} |
| 2296 |
% \end{macro} |
| 2297 |
% |
| 2298 |
% \begin{macro}{\skip_zero:N, \skip_zero:c} |
| 2299 |
% \begin{macro}{\skip_gzero:N, \skip_gzero:c} |
| 2300 |
% Reset the register to zero. |
| 2301 |
% \begin{macrocode} |
| 2302 |
\cs_new_eq:NN \skip_zero:N \dim_zero:N |
| 2303 |
\cs_new_eq:NN \skip_gzero:N \dim_gzero:N |
| 2304 |
\cs_generate_variant:Nn \skip_zero:N { c } |
| 2305 |
\cs_generate_variant:Nn \skip_gzero:N { c } |
| 2306 |
% \end{macrocode} |
| 2307 |
% \end{macro} |
| 2308 |
% \end{macro} |
| 2309 |
% |
| 2310 |
% \begin{macro} |
| 2311 |
% {\skip_zero_new:N, \skip_zero_new:c, \skip_gzero_new:N, \skip_gzero_new:c} |
| 2312 |
% Create a register if needed, otherwise clear it. |
| 2313 |
% \begin{macrocode} |
| 2314 |
\cs_new_protected:Npn \skip_zero_new:N #1 |
| 2315 |
{ \skip_if_exist:NTF #1 { \skip_zero:N #1 } { \skip_new:N #1 } } |
| 2316 |
\cs_new_protected:Npn \skip_gzero_new:N #1 |
| 2317 |
{ \skip_if_exist:NTF #1 { \skip_gzero:N #1 } { \skip_new:N #1 } } |
| 2318 |
\cs_generate_variant:Nn \skip_zero_new:N { c } |
| 2319 |
\cs_generate_variant:Nn \skip_gzero_new:N { c } |
| 2320 |
% \end{macrocode} |
| 2321 |
% \end{macro} |
| 2322 |
% |
| 2323 |
% \begin{macro}[pTF]{\skip_if_exist:N, \skip_if_exist:c} |
| 2324 |
% Copies of the \texttt{cs} functions defined in \pkg{l3basics}. |
| 2325 |
% \begin{macrocode} |
| 2326 |
\prg_new_eq_conditional:NNn \skip_if_exist:N \cs_if_exist:N |
| 2327 |
{ TF , T , F , p } |
| 2328 |
\prg_new_eq_conditional:NNn \skip_if_exist:c \cs_if_exist:c |
| 2329 |
{ TF , T , F , p } |
| 2330 |
% \end{macrocode} |
| 2331 |
% \end{macro} |
| 2332 |
% |
| 2333 |
% \subsection{Setting \texttt{skip} variables} |
| 2334 |
% |
| 2335 |
% \begin{macro}{\skip_set:Nn, \skip_set:cn, \skip_set:NV, \skip_set:cV} |
| 2336 |
% \begin{macro}{\skip_gset:Nn, \skip_gset:cn, \skip_gset:NV, \skip_gset:cV} |
| 2337 |
% Much the same as for dimensions. |
| 2338 |
% \begin{macrocode} |
| 2339 |
\cs_new_protected:Npn \skip_set:Nn #1#2 |
| 2340 |
{ #1 = \tex_glueexpr:D #2 \scan_stop: } |
| 2341 |
\cs_new_protected:Npn \skip_gset:Nn #1#2 |
| 2342 |
{ \tex_global:D #1 = \tex_glueexpr:D #2 \scan_stop: } |
| 2343 |
\cs_generate_variant:Nn \skip_set:Nn { NV , c , cV } |
| 2344 |
\cs_generate_variant:Nn \skip_gset:Nn { NV , c , cV } |
| 2345 |
% \end{macrocode} |
| 2346 |
% \end{macro} |
| 2347 |
% \end{macro} |
| 2348 |
% |
| 2349 |
% \begin{macro} |
| 2350 |
% {\skip_set_eq:NN, \skip_set_eq:cN, \skip_set_eq:Nc, \skip_set_eq:cc} |
| 2351 |
% \begin{macro} |
| 2352 |
% {\skip_gset_eq:NN, \skip_gset_eq:cN, \skip_gset_eq:Nc, \skip_gset_eq:cc} |
| 2353 |
% All straightforward. |
| 2354 |
% \begin{macrocode} |
| 2355 |
\cs_new_protected:Npn \skip_set_eq:NN #1#2 { #1 = #2 } |
| 2356 |
\cs_generate_variant:Nn \skip_set_eq:NN { c , Nc , cc } |
| 2357 |
\cs_new_protected:Npn \skip_gset_eq:NN #1#2 { \tex_global:D #1 = #2 } |
| 2358 |
\cs_generate_variant:Nn \skip_gset_eq:NN { c , Nc , cc } |
| 2359 |
% \end{macrocode} |
| 2360 |
% \end{macro} |
| 2361 |
% \end{macro} |
| 2362 |
% |
| 2363 |
% \begin{macro}{\skip_add:Nn, \skip_add:cn} |
| 2364 |
% \begin{macro}{\skip_gadd:Nn, \skip_gadd:cn} |
| 2365 |
% \begin{macro}{\skip_sub:Nn, \skip_sub:cn} |
| 2366 |
% \begin{macro}{\skip_gsub:Nn, \skip_gsub:cn} |
| 2367 |
% Using |by| here deals with the (incorrect) case |\skip123|. |
| 2368 |
% \begin{macrocode} |
| 2369 |
\cs_new_protected:Npn \skip_add:Nn #1#2 |
| 2370 |
{ \tex_advance:D #1 \tex_glueexpr:D #2 \scan_stop: } |
| 2371 |
\cs_new_protected:Npn \skip_gadd:Nn #1#2 |
| 2372 |
{ \tex_global:D \tex_advance:D #1 \tex_glueexpr:D #2 \scan_stop: } |
| 2373 |
\cs_generate_variant:Nn \skip_add:Nn { c } |
| 2374 |
\cs_generate_variant:Nn \skip_gadd:Nn { c } |
| 2375 |
\cs_new_protected:Npn \skip_sub:Nn #1#2 |
| 2376 |
{ \tex_advance:D #1 - \tex_glueexpr:D #2 \scan_stop: } |
| 2377 |
\cs_new_protected:Npn \skip_gsub:Nn #1#2 |
| 2378 |
{ \tex_global:D \tex_advance:D #1 - \tex_glueexpr:D #2 \scan_stop: } |
| 2379 |
\cs_generate_variant:Nn \skip_sub:Nn { c } |
| 2380 |
\cs_generate_variant:Nn \skip_gsub:Nn { c } |
| 2381 |
% \end{macrocode} |
| 2382 |
% \end{macro} |
| 2383 |
% \end{macro} |
| 2384 |
% \end{macro} |
| 2385 |
% \end{macro} |
| 2386 |
% |
| 2387 |
% \subsection{Skip expression conditionals} |
| 2388 |
% |
| 2389 |
% \begin{macro}[pTF]{\skip_if_eq:nn} |
| 2390 |
% Comparing skips means doing two expansions to make strings, and then |
| 2391 |
% testing them. As a result, only equality is tested. |
| 2392 |
% \begin{macrocode} |
| 2393 |
\prg_new_conditional:Npnn \skip_if_eq:nn #1#2 { p , T , F , TF } |
| 2394 |
{ |
| 2395 |
\str_if_eq:eeTF { \skip_eval:n {#1} } { \skip_eval:n {#2} } |
| 2396 |
{ \prg_return_true: } |
| 2397 |
{ \prg_return_false: } |
| 2398 |
} |
| 2399 |
% \end{macrocode} |
| 2400 |
% \end{macro} |
| 2401 |
% |
| 2402 |
% \begin{macro}{\@@_sep:} |
| 2403 |
% \begin{macrocode} |
| 2404 |
\cs_new_eq:NN \@@_sep: \__kernel_int_sep: |
| 2405 |
% \end{macrocode} |
| 2406 |
% \end{macro} |
| 2407 |
% |
| 2408 |
% \begin{macro}[EXP,pTF]{\skip_if_finite:n} |
| 2409 |
% \begin{macro}[EXP]{\@@_if_finite:wwNw} |
| 2410 |
% With \eTeX{}, we have an easy access to the order of infinities of |
| 2411 |
% the stretch and shrink components of a skip. However, to access |
| 2412 |
% both, we either need to evaluate the expression twice, or evaluate |
| 2413 |
% it, then call an auxiliary to extract both pieces of information |
| 2414 |
% from the result. Since we are going to need an auxiliary anyways, |
| 2415 |
% it is quicker to make it search for the string \texttt{fil} which |
| 2416 |
% characterizes infinite glue. |
| 2417 |
% \begin{macrocode} |
| 2418 |
\cs_set_protected:Npn \@@_tmp:w #1 |
| 2419 |
{ |
| 2420 |
\prg_new_conditional:Npnn \skip_if_finite:n ##1 { p , T , F , TF } |
| 2421 |
{ |
| 2422 |
\exp_after:wN \@@_if_finite:wwNw |
| 2423 |
\skip_use:N \tex_glueexpr:D ##1 \@@_sep: \prg_return_false: |
| 2424 |
#1 \@@_sep: \prg_return_true: \s_@@_stop |
| 2425 |
} |
| 2426 |
\cs_new:Npn \@@_if_finite:wwNw ##1 #1 ##2 \@@_sep: ##3 ##4 \s_@@_stop {##3} |
| 2427 |
} |
| 2428 |
\exp_args:No \@@_tmp:w { \tl_to_str:n { fil } } |
| 2429 |
% \end{macrocode} |
| 2430 |
% \end{macro} |
| 2431 |
% \end{macro} |
| 2432 |
% |
| 2433 |
% \subsection{Using \texttt{skip} expressions and variables} |
| 2434 |
% |
| 2435 |
% \begin{macro}{\skip_eval:n} |
| 2436 |
% Evaluating a skip expression expandably. |
| 2437 |
% \begin{macrocode} |
| 2438 |
\cs_new:Npn \skip_eval:n #1 |
| 2439 |
{ \skip_use:N \tex_glueexpr:D #1 \scan_stop: } |
| 2440 |
% \end{macrocode} |
| 2441 |
% \end{macro} |
| 2442 |
% |
| 2443 |
% \begin{macro}{\skip_use:N, \skip_use:c} |
| 2444 |
% Accessing a \meta{skip}. |
| 2445 |
% \begin{macrocode} |
| 2446 |
\cs_new_eq:NN \skip_use:N \dim_use:N |
| 2447 |
\cs_new_eq:NN \skip_use:c \dim_use:c |
| 2448 |
% \end{macrocode} |
| 2449 |
% \end{macro} |
| 2450 |
% |
| 2451 |
% \subsection{Inserting skips into the output} |
| 2452 |
% |
| 2453 |
% \begin{macro}{\skip_horizontal:N, \skip_horizontal:c, \skip_horizontal:n} |
| 2454 |
% \begin{macro}{\skip_vertical:N, \skip_vertical:c, \skip_vertical:n} |
| 2455 |
% Inserting skips. |
| 2456 |
% \begin{macrocode} |
| 2457 |
\cs_new_eq:NN \skip_horizontal:N \tex_hskip:D |
| 2458 |
\cs_new:Npn \skip_horizontal:n #1 |
| 2459 |
{ \tex_hskip:D \tex_glueexpr:D #1 \scan_stop: } |
| 2460 |
\cs_new_eq:NN \skip_vertical:N \tex_vskip:D |
| 2461 |
\cs_new:Npn \skip_vertical:n #1 |
| 2462 |
{ \tex_vskip:D \tex_glueexpr:D #1 \scan_stop: } |
| 2463 |
\cs_generate_variant:Nn \skip_horizontal:N { c } |
| 2464 |
\cs_generate_variant:Nn \skip_vertical:N { c } |
| 2465 |
% \end{macrocode} |
| 2466 |
% \end{macro} |
| 2467 |
% \end{macro} |
| 2468 |
% |
| 2469 |
% \subsection{Viewing \texttt{skip} variables} |
| 2470 |
% |
| 2471 |
% \begin{macro}{\skip_show:N, \skip_show:c} |
| 2472 |
% Diagnostics. |
| 2473 |
% \begin{macrocode} |
| 2474 |
\cs_new_eq:NN \skip_show:N \__kernel_register_show:N |
| 2475 |
\cs_generate_variant:Nn \skip_show:N { c } |
| 2476 |
% \end{macrocode} |
| 2477 |
% \end{macro} |
| 2478 |
% |
| 2479 |
% \begin{macro}{\skip_show:n} |
| 2480 |
% Diagnostics. We don't use the \TeX{} primitive \tn{showthe} to show |
| 2481 |
% skip expressions: this gives a more unified output. |
| 2482 |
% \begin{macrocode} |
| 2483 |
\cs_new_protected:Npn \skip_show:n |
| 2484 |
{ \__kernel_msg_show_eval:Nn \skip_eval:n } |
| 2485 |
% \end{macrocode} |
| 2486 |
% \end{macro} |
| 2487 |
% |
| 2488 |
% \begin{macro}{\skip_log:N, \skip_log:c, \skip_log:n} |
| 2489 |
% Diagnostics. Redirect output of \cs{skip_show:n} to the log. |
| 2490 |
% \begin{macrocode} |
| 2491 |
\cs_new_eq:NN \skip_log:N \__kernel_register_log:N |
| 2492 |
\cs_new_eq:NN \skip_log:c \__kernel_register_log:c |
| 2493 |
\cs_new_protected:Npn \skip_log:n |
| 2494 |
{ \__kernel_msg_log_eval:Nn \skip_eval:n } |
| 2495 |
% \end{macrocode} |
| 2496 |
% \end{macro} |
| 2497 |
% |
| 2498 |
% \subsection{Constant skips} |
| 2499 |
% |
| 2500 |
% \begin{macro}{\c_zero_skip, \c_max_skip} |
| 2501 |
% Skips with no rubber component are just dimensions but need to terminate |
| 2502 |
% correctly. |
| 2503 |
% \begin{macrocode} |
| 2504 |
\skip_const:Nn \c_zero_skip { \c_zero_dim } |
| 2505 |
\skip_const:Nn \c_max_skip { \c_max_dim } |
| 2506 |
% \end{macrocode} |
| 2507 |
% \end{macro} |
| 2508 |
% |
| 2509 |
% \subsection{Scratch skips} |
| 2510 |
% |
| 2511 |
% \begin{variable}{\l_tmpa_skip, \l_tmpb_skip} |
| 2512 |
% \begin{variable}{\g_tmpa_skip, \g_tmpb_skip} |
| 2513 |
% We provide two local and two global scratch registers, maybe we |
| 2514 |
% need more or less. |
| 2515 |
% \begin{macrocode} |
| 2516 |
\skip_new:N \l_tmpa_skip |
| 2517 |
\skip_new:N \l_tmpb_skip |
| 2518 |
\skip_new:N \g_tmpa_skip |
| 2519 |
\skip_new:N \g_tmpb_skip |
| 2520 |
% \end{macrocode} |
| 2521 |
% \end{variable} |
| 2522 |
% \end{variable} |
| 2523 |
% |
| 2524 |
% \subsection{Creating and initializing \texttt{muskip} variables} |
| 2525 |
% |
| 2526 |
% \begin{macro}{\muskip_new:N, \muskip_new:c} |
| 2527 |
% And then we add muskips. |
| 2528 |
% \begin{macrocode} |
| 2529 |
\cs_new_protected:Npn \muskip_new:N #1 |
| 2530 |
{ |
| 2531 |
\__kernel_chk_if_free_cs:N #1 |
| 2532 |
\cs:w newmuskip \cs_end: #1 |
| 2533 |
} |
| 2534 |
\cs_generate_variant:Nn \muskip_new:N { c } |
| 2535 |
% \end{macrocode} |
| 2536 |
% \end{macro} |
| 2537 |
% |
| 2538 |
% \begin{macro}{\muskip_const:Nn, \muskip_const:cn} |
| 2539 |
% See \cs{skip_const:Nn}. |
| 2540 |
% \begin{macrocode} |
| 2541 |
\cs_new_protected:Npn \muskip_const:Nn #1#2 |
| 2542 |
{ |
| 2543 |
\muskip_new:N #1 |
| 2544 |
\tex_global:D #1 = \muskip_eval:n {#2} \scan_stop: |
| 2545 |
} |
| 2546 |
\cs_generate_variant:Nn \muskip_const:Nn { c } |
| 2547 |
% \end{macrocode} |
| 2548 |
% \end{macro} |
| 2549 |
% |
| 2550 |
% \begin{macro}{\muskip_zero:N, \muskip_zero:c} |
| 2551 |
% \begin{macro}{\muskip_gzero:N, \muskip_gzero:c} |
| 2552 |
% Reset the register to zero. |
| 2553 |
% \begin{macrocode} |
| 2554 |
\cs_new_protected:Npn \muskip_zero:N #1 |
| 2555 |
{ #1 = \c_zero_muskip } |
| 2556 |
\cs_new_protected:Npn \muskip_gzero:N #1 |
| 2557 |
{ \tex_global:D #1 = \c_zero_muskip } |
| 2558 |
\cs_generate_variant:Nn \muskip_zero:N { c } |
| 2559 |
\cs_generate_variant:Nn \muskip_gzero:N { c } |
| 2560 |
% \end{macrocode} |
| 2561 |
% \end{macro} |
| 2562 |
% \end{macro} |
| 2563 |
% |
| 2564 |
% \begin{macro} |
| 2565 |
% { |
| 2566 |
% \muskip_zero_new:N, \muskip_zero_new:c, |
| 2567 |
% \muskip_gzero_new:N, \muskip_gzero_new:c |
| 2568 |
% } |
| 2569 |
% Create a register if needed, otherwise clear it. |
| 2570 |
% \begin{macrocode} |
| 2571 |
\cs_new_protected:Npn \muskip_zero_new:N #1 |
| 2572 |
{ \muskip_if_exist:NTF #1 { \muskip_zero:N #1 } { \muskip_new:N #1 } } |
| 2573 |
\cs_new_protected:Npn \muskip_gzero_new:N #1 |
| 2574 |
{ \muskip_if_exist:NTF #1 { \muskip_gzero:N #1 } { \muskip_new:N #1 } } |
| 2575 |
\cs_generate_variant:Nn \muskip_zero_new:N { c } |
| 2576 |
\cs_generate_variant:Nn \muskip_gzero_new:N { c } |
| 2577 |
% \end{macrocode} |
| 2578 |
% \end{macro} |
| 2579 |
% |
| 2580 |
% \begin{macro}[pTF]{\muskip_if_exist:N, \muskip_if_exist:c} |
| 2581 |
% Copies of the \texttt{cs} functions defined in \pkg{l3basics}. |
| 2582 |
% \begin{macrocode} |
| 2583 |
\prg_new_eq_conditional:NNn \muskip_if_exist:N \cs_if_exist:N |
| 2584 |
{ TF , T , F , p } |
| 2585 |
\prg_new_eq_conditional:NNn \muskip_if_exist:c \cs_if_exist:c |
| 2586 |
{ TF , T , F , p } |
| 2587 |
% \end{macrocode} |
| 2588 |
% \end{macro} |
| 2589 |
% |
| 2590 |
% \subsection{Setting \texttt{muskip} variables} |
| 2591 |
% |
| 2592 |
% \begin{macro}{\muskip_set:Nn, \muskip_set:cn, \muskip_set:NV, \muskip_set:cV} |
| 2593 |
% \begin{macro}{\muskip_gset:Nn, \muskip_gset:cn, \muskip_gset:NV, \muskip_gset:cV} |
| 2594 |
% This should be pretty familiar. |
| 2595 |
% \begin{macrocode} |
| 2596 |
\cs_new_protected:Npn \muskip_set:Nn #1#2 |
| 2597 |
{ #1 = \tex_muexpr:D #2 \scan_stop: } |
| 2598 |
\cs_new_protected:Npn \muskip_gset:Nn #1#2 |
| 2599 |
{ \tex_global:D #1 = \tex_muexpr:D #2 \scan_stop: } |
| 2600 |
\cs_generate_variant:Nn \muskip_set:Nn { NV , c , cV } |
| 2601 |
\cs_generate_variant:Nn \muskip_gset:Nn { NV , c , cV } |
| 2602 |
% \end{macrocode} |
| 2603 |
% \end{macro} |
| 2604 |
% \end{macro} |
| 2605 |
% |
| 2606 |
% \begin{macro} |
| 2607 |
% { |
| 2608 |
% \muskip_set_eq:NN, \muskip_set_eq:cN, |
| 2609 |
% \muskip_set_eq:Nc, \muskip_set_eq:cc |
| 2610 |
% } |
| 2611 |
% \begin{macro} |
| 2612 |
% { |
| 2613 |
% \muskip_gset_eq:NN, \muskip_gset_eq:cN, |
| 2614 |
% \muskip_gset_eq:Nc, \muskip_gset_eq:cc |
| 2615 |
% } |
| 2616 |
% All straightforward. |
| 2617 |
% \begin{macrocode} |
| 2618 |
\cs_new_protected:Npn \muskip_set_eq:NN #1#2 { #1 = #2 } |
| 2619 |
\cs_generate_variant:Nn \muskip_set_eq:NN { c , Nc , cc } |
| 2620 |
\cs_new_protected:Npn \muskip_gset_eq:NN #1#2 { \tex_global:D #1 = #2 } |
| 2621 |
\cs_generate_variant:Nn \muskip_gset_eq:NN { c , Nc , cc } |
| 2622 |
% \end{macrocode} |
| 2623 |
% \end{macro} |
| 2624 |
% \end{macro} |
| 2625 |
% |
| 2626 |
% \begin{macro}{\muskip_add:Nn, \muskip_add:cn} |
| 2627 |
% \begin{macro}{\muskip_gadd:Nn, \muskip_gadd:cn} |
| 2628 |
% \begin{macro}{\muskip_sub:Nn, \muskip_sub:cn} |
| 2629 |
% \begin{macro}{\muskip_gsub:Nn, \muskip_gsub:cn} |
| 2630 |
% Using |by| here deals with the (incorrect) case |\muskip123|. |
| 2631 |
% \begin{macrocode} |
| 2632 |
\cs_new_protected:Npn \muskip_add:Nn #1#2 |
| 2633 |
{ \tex_advance:D #1 \tex_muexpr:D #2 \scan_stop: } |
| 2634 |
\cs_new_protected:Npn \muskip_gadd:Nn #1#2 |
| 2635 |
{ \tex_global:D \tex_advance:D #1 \tex_muexpr:D #2 \scan_stop: } |
| 2636 |
\cs_generate_variant:Nn \muskip_add:Nn { c } |
| 2637 |
\cs_generate_variant:Nn \muskip_gadd:Nn { c } |
| 2638 |
\cs_new_protected:Npn \muskip_sub:Nn #1#2 |
| 2639 |
{ \tex_advance:D #1 - \tex_muexpr:D #2 \scan_stop: } |
| 2640 |
\cs_new_protected:Npn \muskip_gsub:Nn #1#2 |
| 2641 |
{ \tex_global:D \tex_advance:D #1 - \tex_muexpr:D #2 \scan_stop: } |
| 2642 |
\cs_generate_variant:Nn \muskip_sub:Nn { c } |
| 2643 |
\cs_generate_variant:Nn \muskip_gsub:Nn { c } |
| 2644 |
% \end{macrocode} |
| 2645 |
% \end{macro} |
| 2646 |
% \end{macro} |
| 2647 |
% \end{macro} |
| 2648 |
% \end{macro} |
| 2649 |
% |
| 2650 |
% \subsection{Using \texttt{muskip} expressions and variables} |
| 2651 |
% |
| 2652 |
% \begin{macro}{\muskip_eval:n} |
| 2653 |
% Evaluating a muskip expression expandably. |
| 2654 |
% \begin{macrocode} |
| 2655 |
\cs_new:Npn \muskip_eval:n #1 |
| 2656 |
{ \muskip_use:N \tex_muexpr:D #1 \scan_stop: } |
| 2657 |
% \end{macrocode} |
| 2658 |
% \end{macro} |
| 2659 |
% |
| 2660 |
% \begin{macro}{\muskip_use:N, \muskip_use:c} |
| 2661 |
% Accessing a \meta{muskip}. |
| 2662 |
% \begin{macrocode} |
| 2663 |
\cs_new_eq:NN \muskip_use:N \dim_use:N |
| 2664 |
\cs_new_eq:NN \muskip_use:c \dim_use:c |
| 2665 |
% \end{macrocode} |
| 2666 |
% \end{macro} |
| 2667 |
% |
| 2668 |
% \subsection{Viewing \texttt{muskip} variables} |
| 2669 |
% |
| 2670 |
% \begin{macro}{\muskip_show:N, \muskip_show:c} |
| 2671 |
% Diagnostics. |
| 2672 |
% \begin{macrocode} |
| 2673 |
\cs_new_eq:NN \muskip_show:N \__kernel_register_show:N |
| 2674 |
\cs_generate_variant:Nn \muskip_show:N { c } |
| 2675 |
% \end{macrocode} |
| 2676 |
% \end{macro} |
| 2677 |
% |
| 2678 |
% \begin{macro}{\muskip_show:n} |
| 2679 |
% Diagnostics. We don't use the \TeX{} primitive \tn{showthe} to show |
| 2680 |
% muskip expressions: this gives a more unified output. |
| 2681 |
% \begin{macrocode} |
| 2682 |
\cs_new_protected:Npn \muskip_show:n |
| 2683 |
{ \__kernel_msg_show_eval:Nn \muskip_eval:n } |
| 2684 |
% \end{macrocode} |
| 2685 |
% \end{macro} |
| 2686 |
% |
| 2687 |
% \begin{macro}{\muskip_log:N, \muskip_log:c, \muskip_log:n} |
| 2688 |
% Diagnostics. Redirect output of \cs{muskip_show:n} to the log. |
| 2689 |
% \begin{macrocode} |
| 2690 |
\cs_new_eq:NN \muskip_log:N \__kernel_register_log:N |
| 2691 |
\cs_new_eq:NN \muskip_log:c \__kernel_register_log:c |
| 2692 |
\cs_new_protected:Npn \muskip_log:n |
| 2693 |
{ \__kernel_msg_log_eval:Nn \muskip_eval:n } |
| 2694 |
% \end{macrocode} |
| 2695 |
% \end{macro} |
| 2696 |
% |
| 2697 |
% \subsection{Constant muskips} |
| 2698 |
% |
| 2699 |
% \begin{macro}{\c_zero_muskip} |
| 2700 |
% \begin{macro}{\c_max_muskip} |
| 2701 |
% Constant muskips given by their value. |
| 2702 |
% \begin{macrocode} |
| 2703 |
\muskip_const:Nn \c_zero_muskip { 0 mu } |
| 2704 |
\muskip_const:Nn \c_max_muskip { 16383.99999 mu } |
| 2705 |
% \end{macrocode} |
| 2706 |
% \end{macro} |
| 2707 |
% \end{macro} |
| 2708 |
% |
| 2709 |
% \subsection{Scratch muskips} |
| 2710 |
% |
| 2711 |
% \begin{variable}{\l_tmpa_muskip, \l_tmpb_muskip} |
| 2712 |
% \begin{variable}{\g_tmpa_muskip, \g_tmpb_muskip} |
| 2713 |
% We provide two local and two global scratch registers, maybe we |
| 2714 |
% need more or less. |
| 2715 |
% \begin{macrocode} |
| 2716 |
\muskip_new:N \l_tmpa_muskip |
| 2717 |
\muskip_new:N \l_tmpb_muskip |
| 2718 |
\muskip_new:N \g_tmpa_muskip |
| 2719 |
\muskip_new:N \g_tmpb_muskip |
| 2720 |
% \end{macrocode} |
| 2721 |
% \end{variable} |
| 2722 |
% \end{variable} |
| 2723 |
% |
| 2724 |
% \begin{macrocode} |
| 2725 |
%</code> |
| 2726 |
% \end{macrocode} |
| 2727 |
% |
| 2728 |
% \end{implementation} |
| 2729 |
% |
| 2730 |
% \PrintIndex |