| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3keys.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2006-2026 The LaTeX Project |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% https://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "l3kernel bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/latex3 |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
% |
| 25 |
%<*driver> |
| 26 |
\documentclass[full,kernel]{l3doc} |
| 27 |
\begin{document} |
| 28 |
\DocInput{\jobname.dtx} |
| 29 |
\end{document} |
| 30 |
%</driver> |
| 31 |
% \fi |
| 32 |
% |
| 33 |
% \title{^^A |
| 34 |
% The \pkg{l3keys} module\\ Key--value interfaces^^A |
| 35 |
% } |
| 36 |
% |
| 37 |
% \author{^^A |
| 38 |
% The \LaTeX{} Project\thanks |
| 39 |
% {^^A |
| 40 |
% E-mail: |
| 41 |
% \href{mailto:[email protected]} |
| 42 |
% {[email protected]}^^A |
| 43 |
% }^^A |
| 44 |
% } |
| 45 |
% |
| 46 |
% \date{Released 2026-05-15} |
| 47 |
% |
| 48 |
% \maketitle |
| 49 |
% |
| 50 |
% \begin{documentation} |
| 51 |
% |
| 52 |
% The key--value method is a popular system for creating large numbers |
| 53 |
% of settings for controlling function or package behavior. The |
| 54 |
% system normally results in input of the form |
| 55 |
% \begin{verbatim} |
| 56 |
% \MyModuleSetup{ |
| 57 |
% key-one = value one, |
| 58 |
% key-two = value two |
| 59 |
% } |
| 60 |
% \end{verbatim} |
| 61 |
% or |
| 62 |
% \begin{verbatim} |
| 63 |
% \MyModuleMacro[ |
| 64 |
% key-one = value one, |
| 65 |
% key-two = value two |
| 66 |
% ]{argument} |
| 67 |
% \end{verbatim} |
| 68 |
% for the user. |
| 69 |
% |
| 70 |
% The high level functions here are intended as a method to create |
| 71 |
% key--value controls. Keys are themselves created using a key--value |
| 72 |
% interface, minimizing the number of functions and arguments |
| 73 |
% required. Each key is created by setting one or more \emph{properties} |
| 74 |
% of the key: |
| 75 |
% \begin{verbatim} |
| 76 |
% \keys_define:nn { mymodule } |
| 77 |
% { |
| 78 |
% key-one .code:n = code including parameter #1, |
| 79 |
% key-two .tl_set:N = \l_mymodule_store_tl |
| 80 |
% } |
| 81 |
% \end{verbatim} |
| 82 |
% These values can then be set as with other key--value approaches: |
| 83 |
% \begin{verbatim} |
| 84 |
% \keys_set:nn { mymodule } |
| 85 |
% { |
| 86 |
% key-one = value one, |
| 87 |
% key-two = value two |
| 88 |
% } |
| 89 |
% \end{verbatim} |
| 90 |
% As illustrated, keys are created inside a \meta{module}: a set of related |
| 91 |
% keys, typically those for a single module/\LaTeXe{} package. See |
| 92 |
% Section~\ref{sec:l3keys:subdivision} for suggestions on how to divide |
| 93 |
% large numbers of keys for a single module. |
| 94 |
% |
| 95 |
% At a document level, \cs{keys_set:nn} is used within a |
| 96 |
% document function, for example |
| 97 |
% \begin{verbatim} |
| 98 |
% \DeclareDocumentCommand \MyModuleSetup { m } |
| 99 |
% { \keys_set:nn { mymodule } { #1 } } |
| 100 |
% \DeclareDocumentCommand \MyModuleMacro { o m } |
| 101 |
% { |
| 102 |
% \group_begin: |
| 103 |
% \keys_set:nn { mymodule } { #1 } |
| 104 |
% % Main code for \MyModuleMacro |
| 105 |
% \group_end: |
| 106 |
% } |
| 107 |
% \end{verbatim} |
| 108 |
% |
| 109 |
% Key names may contain any tokens except |:|, as they are handled internally |
| 110 |
% using \cs{tl_to_str:n}. As discussed in |
| 111 |
% section~\ref{sec:l3keys:subdivision}, it is suggested that the character |
| 112 |
% |/| is reserved for sub-division of keys into different subsets. |
| 113 |
% Functions and variables are \emph{not} expanded when creating |
| 114 |
% key names, and so |
| 115 |
% \begin{verbatim} |
| 116 |
% \tl_set:Nn \l_mymodule_tmp_tl { key } |
| 117 |
% \keys_define:nn { mymodule } |
| 118 |
% { |
| 119 |
% \l_mymodule_tmp_tl .code:n = code |
| 120 |
% } |
| 121 |
% \end{verbatim} |
| 122 |
% creates a key called |\l_mymodule_tmp_tl|, and not one called |
| 123 |
% \texttt{key}. |
| 124 |
% |
| 125 |
% \section{Creating keys} |
| 126 |
% |
| 127 |
% \begin{function}[updated = 2017-11-14] |
| 128 |
% {\keys_define:nn, \keys_define:ne} |
| 129 |
% \begin{syntax} |
| 130 |
% \cs{keys_define:nn} \Arg{module} \Arg{keyval list} |
| 131 |
% \end{syntax} |
| 132 |
% Parses the \meta{keyval list} and defines the keys listed there for |
| 133 |
% \meta{module}. The \meta{module} name is treated as a string. |
| 134 |
% In practice the |
| 135 |
% \meta{module} should be chosen to be unique to the module in question |
| 136 |
% (unless deliberately adding keys to an existing module). |
| 137 |
% |
| 138 |
% The \meta{keyval list} should consist of one or more key names along |
| 139 |
% with an associated key \emph{property}. The properties of a key |
| 140 |
% determine how it acts. The individual properties are described |
| 141 |
% in the following text; a typical use of \cs{keys_define:nn} might |
| 142 |
% read |
| 143 |
% \begin{verbatim} |
| 144 |
% \keys_define:nn { mymodule } |
| 145 |
% { |
| 146 |
% keyname .code:n = Some~code~using~#1, |
| 147 |
% keyname .value_required:n = true |
| 148 |
% } |
| 149 |
% \end{verbatim} |
| 150 |
% where the properties of the key begin from the |.| after the key |
| 151 |
% name. |
| 152 |
% \end{function} |
| 153 |
% |
| 154 |
% The various properties available take either no arguments at |
| 155 |
% all, or require one or more arguments. This is indicated in the |
| 156 |
% name of the property using an argument specification. In the following |
| 157 |
% discussion, each property is illustrated attached to an |
| 158 |
% arbitrary \meta{key}, which when used may be supplied with a |
| 159 |
% \meta{value}. All key \emph{definitions} are local. |
| 160 |
% |
| 161 |
% Key properties are applied in the reading order and so the ordering |
| 162 |
% is significant. Key properties which define \enquote{actions}, such |
| 163 |
% as |.code:n|, |.tl_set:N|, etc., override one another. |
| 164 |
% Some other properties are mutually exclusive, notably |.value_required:n| |
| 165 |
% and |.value_forbidden:n|, and so they replace one another. However, |
| 166 |
% properties covering non-exclusive behaviors may be given in any order. Thus |
| 167 |
% for example the following definitions are equivalent. |
| 168 |
% \begin{verbatim} |
| 169 |
% \keys_define:nn { mymodule } |
| 170 |
% { |
| 171 |
% keyname .code:n = Some~code~using~#1, |
| 172 |
% keyname .value_required:n = true |
| 173 |
% } |
| 174 |
% \keys_define:nn { mymodule } |
| 175 |
% { |
| 176 |
% keyname .value_required:n = true, |
| 177 |
% keyname .code:n = Some~code~using~#1 |
| 178 |
% } |
| 179 |
% \end{verbatim} |
| 180 |
% Note that all key properties define the key within the current \TeX{} group, |
| 181 |
% with an exception that the special |.undefine:| property \emph{undefines} the |
| 182 |
% key within the current \TeX{} group. |
| 183 |
% |
| 184 |
% \begin{function}[updated = 2013-07-08] |
| 185 |
% {.bool_set:N, .bool_set:c, .bool_gset:N, .bool_gset:c} |
| 186 |
% \begin{syntax} |
| 187 |
% \meta{key} .bool_set:N = \meta{boolean} |
| 188 |
% \end{syntax} |
| 189 |
% Defines \meta{key} to set \meta{boolean} to \meta{value}. If the |
| 190 |
% \meta{value} is given, it must be one either \enquote{\texttt{true}} or |
| 191 |
% \enquote{\texttt{false}}); it may be omitted, which is equivalent to |
| 192 |
% \texttt{true}. If the variable does not exist, it will be created globally |
| 193 |
% at the point that the key is set up. |
| 194 |
% \end{function} |
| 195 |
% |
| 196 |
% \begin{function}[added = 2011-08-28, updated = 2013-07-08] |
| 197 |
% { |
| 198 |
% .bool_set_inverse:N, .bool_set_inverse:c, |
| 199 |
% .bool_gset_inverse:N, .bool_gset_inverse:c |
| 200 |
% } |
| 201 |
% \begin{syntax} |
| 202 |
% \meta{key} .bool_set_inverse:N = \meta{boolean} |
| 203 |
% \end{syntax} |
| 204 |
% Defines \meta{key} to set \meta{boolean} to the logical |
| 205 |
% inverse of \meta{value} (which must be either \enquote{\texttt{true}} or |
| 206 |
% \enquote{\texttt{false}}). |
| 207 |
% If the \meta{boolean} does not exist, it will be created globally |
| 208 |
% at the point that the key is set up. |
| 209 |
% \end{function} |
| 210 |
% |
| 211 |
% \begin{function}{.choice:} |
| 212 |
% \begin{syntax} |
| 213 |
% \meta{key} .choice: |
| 214 |
% \end{syntax} |
| 215 |
% Sets \meta{key} to act as a choice key. Each valid choice |
| 216 |
% for \meta{key} must then be created, as discussed in |
| 217 |
% section~\ref{sec:l3keys:choice}. |
| 218 |
% \end{function} |
| 219 |
% |
| 220 |
% \begin{function}[added = 2011-08-21, updated = 2013-07-10] |
| 221 |
% {.choices:nn, .choices:Vn, .choices:en, .choices:on} |
| 222 |
% \begin{syntax} |
| 223 |
% \meta{key} .choices:nn = \Arg{choices} \Arg{code} |
| 224 |
% \end{syntax} |
| 225 |
% Sets \meta{key} to act as a choice key, and defines a series \meta{choices} |
| 226 |
% which are implemented using the \meta{code}. Inside \meta{code}, |
| 227 |
% \cs{l_keys_choice_str} will be the name of the choice made, and |
| 228 |
% \cs{l_keys_choice_int} will be the position of the choice in the list |
| 229 |
% of \meta{choices} (indexed from~$1$). |
| 230 |
% Choices are discussed in detail in section~\ref{sec:l3keys:choice}. |
| 231 |
% \end{function} |
| 232 |
% |
| 233 |
% \begin{function}[added = 2011-09-11] |
| 234 |
% {.clist_set:N, .clist_set:c, .clist_gset:N, .clist_gset:c} |
| 235 |
% \begin{syntax} |
| 236 |
% \meta{key} .clist_set:N = \meta{comma list variable} |
| 237 |
% \end{syntax} |
| 238 |
% Defines \meta{key} to set \meta{comma list variable} to \meta{value}. |
| 239 |
% Spaces around commas and empty items will be stripped. |
| 240 |
% If the variable does not exist, it |
| 241 |
% is created globally at the point that the key is set up. |
| 242 |
% \end{function} |
| 243 |
% |
| 244 |
% \begin{function}[updated = 2013-07-10]{.code:n} |
| 245 |
% \begin{syntax} |
| 246 |
% \meta{key} .code:n = \Arg{code} |
| 247 |
% \end{syntax} |
| 248 |
% Stores the \meta{code} for execution when \meta{key} is used. |
| 249 |
% The \meta{code} can include one parameter (|#1|), which will be the |
| 250 |
% \meta{value} given for the \meta{key}. |
| 251 |
% \end{function} |
| 252 |
% |
| 253 |
% \begin{function}[added = 2020-01-11] |
| 254 |
% { |
| 255 |
% .cs_set:Np, .cs_set:cp, |
| 256 |
% .cs_set_protected:Np, .cs_set_protected:cp, |
| 257 |
% .cs_gset:Np, .cs_gset:cp, |
| 258 |
% .cs_gset_protected:Np, .cs_gset_protected:cp, |
| 259 |
% } |
| 260 |
% \begin{syntax} |
| 261 |
% \meta{key} .cs_set:Np = \meta{control sequence} \meta{arg.~spec.} |
| 262 |
% \end{syntax} |
| 263 |
% Defines \meta{key} to set \meta{control sequence} to have \meta{arg.~spec.} |
| 264 |
% and replacement text \meta{value}. |
| 265 |
% \end{function} |
| 266 |
% |
| 267 |
% \begin{function}[updated = 2013-07-09] |
| 268 |
% {.default:n, .default:V, .default:e, .default:o} |
| 269 |
% \begin{syntax} |
| 270 |
% \meta{key} .default:n = \Arg{default} |
| 271 |
% \end{syntax} |
| 272 |
% Creates a \meta{default} value for \meta{key}, which is used if no |
| 273 |
% value is given. This will be used if only the key name is given, |
| 274 |
% but not if a blank \meta{value} is given: |
| 275 |
% \begin{verbatim} |
| 276 |
% \keys_define:nn { mymodule } |
| 277 |
% { |
| 278 |
% key .code:n = Hello~#1, |
| 279 |
% key .default:n = World |
| 280 |
% } |
| 281 |
% \keys_set:nn { mymodule } |
| 282 |
% { |
| 283 |
% key = Fred, % Prints 'Hello Fred' |
| 284 |
% key, % Prints 'Hello World' |
| 285 |
% key = , % Prints 'Hello ' |
| 286 |
% } |
| 287 |
% \end{verbatim} |
| 288 |
% The default does not affect keys where values are required or |
| 289 |
% forbidden. Thus a required value cannot be supplied by a default |
| 290 |
% value, and giving a default value for a key which cannot take a value |
| 291 |
% does not trigger an error. |
| 292 |
% |
| 293 |
% When no value is given for a key as part of \cs{keys_set:nn}, the |
| 294 |
% \texttt{.default:n} value provides the value before key properties are |
| 295 |
% considered. The only exception is when the \texttt{.value_required:n} |
| 296 |
% property is active: a required value cannot be supplied by the default, |
| 297 |
% and must be explicitly given as part of \cs{keys_set:nn}. |
| 298 |
% \end{function} |
| 299 |
% |
| 300 |
% \begin{function}[updated = 2020-01-17] |
| 301 |
% {.dim_set:N, .dim_set:c, .dim_gset:N, .dim_gset:c} |
| 302 |
% \begin{syntax} |
| 303 |
% \meta{key} .dim_set:N = \meta{dimension} |
| 304 |
% \end{syntax} |
| 305 |
% Defines \meta{key} to set \meta{dimension} to \meta{value} (which |
| 306 |
% must a dimension expression). If the variable does not exist, it |
| 307 |
% is created globally at the point that the key is set up. The key will |
| 308 |
% require a value at point-of-use unless a default is set. |
| 309 |
% \end{function} |
| 310 |
% |
| 311 |
% \begin{function}[updated = 2020-01-17] |
| 312 |
% {.fp_set:N, .fp_set:c, .fp_gset:N, .fp_gset:c} |
| 313 |
% \begin{syntax} |
| 314 |
% \meta{key} .fp_set:N = \meta{fp var} |
| 315 |
% \end{syntax} |
| 316 |
% Defines \meta{key} to set \meta{fp var} to \meta{value} |
| 317 |
% (which must a floating point expression). If the variable does not exist, |
| 318 |
% it is created globally at the point that the key is set up. The key will |
| 319 |
% require a value at point-of-use unless a default is set. |
| 320 |
% \end{function} |
| 321 |
% |
| 322 |
% \begin{function}[added = 2013-07-14] |
| 323 |
% {.groups:n} |
| 324 |
% \begin{syntax} |
| 325 |
% \meta{key} .groups:n = \Arg{groups} |
| 326 |
% \end{syntax} |
| 327 |
% Defines \meta{key} as belonging to the \meta{groups} (a |
| 328 |
% comma-separated list). Groups |
| 329 |
% provide a \enquote{secondary axis} for selectively setting keys, and are |
| 330 |
% described in Section~\ref{sec:l3keys:selective}. |
| 331 |
% \begin{texnote} |
| 332 |
% The \meta{groups} argument is turned into a string then |
| 333 |
% interpreted as a comma-separated list, so group names cannot |
| 334 |
% contain commas nor start or end with a space character. |
| 335 |
% \end{texnote} |
| 336 |
% \end{function} |
| 337 |
% |
| 338 |
% \begin{function}[added = 2016-11-22]{.inherit:n} |
| 339 |
% \begin{syntax} |
| 340 |
% \meta{key} .inherit:n = \Arg{parents} |
| 341 |
% \end{syntax} |
| 342 |
% Specifies that the \meta{key} path should inherit the keys listed |
| 343 |
% as any of the \meta{parents} (a comma list), which can be a module |
| 344 |
% or a sub-division thereof. For example, after setting |
| 345 |
% \begin{verbatim} |
| 346 |
% \keys_define:nn { foo } { test .code:n = \tl_show:n {#1} } |
| 347 |
% \keys_define:nn { } { bar .inherit:n = foo } |
| 348 |
% \end{verbatim} |
| 349 |
% setting |
| 350 |
% \begin{verbatim} |
| 351 |
% \keys_set:nn { bar } { test = a } |
| 352 |
% \end{verbatim} |
| 353 |
% will be equivalent to |
| 354 |
% \begin{verbatim} |
| 355 |
% \keys_set:nn { foo } { test = a } |
| 356 |
% \end{verbatim} |
| 357 |
% Inheritance applies at point of use, not at definition, thus keys may |
| 358 |
% be added to the \meta{parent} after the use of \texttt{.inherit:n} |
| 359 |
% and will be active. |
| 360 |
% If more than one \meta{parent} is specified, the presence of the |
| 361 |
% \meta{key} will be tested for each in turn, with the first successful |
| 362 |
% hit taking priority. |
| 363 |
% \end{function} |
| 364 |
% |
| 365 |
% \begin{function}[updated = 2013-07-09] |
| 366 |
% {.initial:n, .initial:V, .initial:e, .initial:o} |
| 367 |
% \begin{syntax} |
| 368 |
% \meta{key} .initial:n = \Arg{value} |
| 369 |
% \end{syntax} |
| 370 |
% Initializes the \meta{key} with the \meta{value}, equivalent to |
| 371 |
% \begin{quote}\ttfamily |
| 372 |
% \cs{keys_set:nn} \Arg{module} \{ \meta{key} = \meta{value} \} |
| 373 |
% \end{quote} |
| 374 |
% \end{function} |
| 375 |
% |
| 376 |
% \begin{function}[updated = 2020-01-17] |
| 377 |
% {.int_set:N, .int_set:c, .int_gset:N, .int_gset:c} |
| 378 |
% \begin{syntax} |
| 379 |
% \meta{key} .int_set:N = \meta{integer} |
| 380 |
% \end{syntax} |
| 381 |
% Defines \meta{key} to set \meta{integer} to \meta{value} (which |
| 382 |
% must be an integer expression). If the variable does not exist, it |
| 383 |
% is created globally at the point that the key is set up. The key will |
| 384 |
% require a value at point-of-use unless a default is set. |
| 385 |
% \end{function} |
| 386 |
% |
| 387 |
% \begin{function}[updated = 2022-01-15] |
| 388 |
% { |
| 389 |
% .legacy_if_set:n, .legacy_if_gset:n, |
| 390 |
% .legacy_if_set_inverse:n, .legacy_if_gset_inverse:n |
| 391 |
% } |
| 392 |
% \begin{syntax} |
| 393 |
% \meta{key} .legacy_if_set:n = \meta{switch} |
| 394 |
% \end{syntax} |
| 395 |
% Defines \meta{key} to set legacy \cs[no-index]{if\meta{switch}} to \meta{value} |
| 396 |
% (which must be either \enquote{\texttt{true}} or \enquote{\texttt{false}}). |
| 397 |
% The \meta{switch} is the name of the switch \emph{without the leading |
| 398 |
% \texttt{if}}. |
| 399 |
% |
| 400 |
% The \texttt{inverse} versions will set the \meta{switch} to the logical |
| 401 |
% opposite of the \meta{value}. |
| 402 |
% \end{function} |
| 403 |
% |
| 404 |
% \begin{function}[updated = 2013-07-10]{.meta:n} |
| 405 |
% \begin{syntax} |
| 406 |
% \meta{key} .meta:n = \Arg{keyval list} |
| 407 |
% \end{syntax} |
| 408 |
% Makes \meta{key} a meta-key, which will set \meta{keyval list} in |
| 409 |
% one go. The \meta{keyval list} can refer as |#1| to the value given |
| 410 |
% at the time the \meta{key} is used (or, if no value is given, the |
| 411 |
% \meta{key}'s default value). |
| 412 |
% \end{function} |
| 413 |
% |
| 414 |
% \begin{function}[added = 2013-07-10]{.meta:nn} |
| 415 |
% \begin{syntax} |
| 416 |
% \meta{key} .meta:nn = \Arg{path} \Arg{keyval list} |
| 417 |
% \end{syntax} |
| 418 |
% Makes \meta{key} a meta-key, which will set \meta{keyval list} in |
| 419 |
% one go using the \meta{path} in place of the current one. The |
| 420 |
% \meta{keyval list} can refer as |#1| to the value given at the time |
| 421 |
% the \meta{key} is used (or, if no value is given, the \meta{key}'s |
| 422 |
% default value). |
| 423 |
% \end{function} |
| 424 |
% |
| 425 |
% \begin{function}[added = 2011-08-21]{.multichoice:} |
| 426 |
% \begin{syntax} |
| 427 |
% \meta{key} .multichoice: |
| 428 |
% \end{syntax} |
| 429 |
% Sets \meta{key} to act as a multiple choice key. Each valid choice |
| 430 |
% for \meta{key} must then be created, as discussed in |
| 431 |
% section~\ref{sec:l3keys:choice}. |
| 432 |
% \end{function} |
| 433 |
% |
| 434 |
% \begin{function}[added = 2011-08-21, updated = 2013-07-10] |
| 435 |
% {.multichoices:nn, .multichoices:Vn, .multichoices:en, .multichoices:on} |
| 436 |
% \begin{syntax} |
| 437 |
% \meta{key} .multichoices:nn \Arg{choices} \Arg{code} |
| 438 |
% \end{syntax} |
| 439 |
% Sets \meta{key} to act as a multiple choice key, and defines a series |
| 440 |
% \meta{choices} |
| 441 |
% which are implemented using the \meta{code}. Inside \meta{code}, |
| 442 |
% \cs{l_keys_choice_str} will be the name of the choice made, and |
| 443 |
% \cs{l_keys_choice_int} will be the position of the choice in the list |
| 444 |
% of \meta{choices} (indexed from~$1$). |
| 445 |
% Choices are discussed in detail in section~\ref{sec:l3keys:choice}. |
| 446 |
% \end{function} |
| 447 |
% |
| 448 |
% \begin{function}[added = 2019-05-05, updated = 2020-01-17] |
| 449 |
% {.muskip_set:N, .muskip_set:c, .muskip_gset:N, .muskip_gset:c} |
| 450 |
% \begin{syntax} |
| 451 |
% \meta{key} .muskip_set:N = \meta{muskip} |
| 452 |
% \end{syntax} |
| 453 |
% Defines \meta{key} to set \meta{muskip} to \meta{value} (which |
| 454 |
% must be a muskip expression). If the variable does not exist, it |
| 455 |
% is created globally at the point that the key is set up. The key will |
| 456 |
% require a value at point-of-use unless a default is set. |
| 457 |
% \end{function} |
| 458 |
% |
| 459 |
% \begin{function}[added = 2019-01-31] |
| 460 |
% {.prop_put:N, .prop_put:c, .prop_gput:N, .prop_gput:c} |
| 461 |
% \begin{syntax} |
| 462 |
% \meta{key} .prop_put:N = \meta{property list} |
| 463 |
% \end{syntax} |
| 464 |
% Defines \meta{key} to put the \meta{value} onto the \meta{property list} |
| 465 |
% stored under the \meta{key}. |
| 466 |
% If the variable does not exist, it |
| 467 |
% is created globally at the point that the key is set up. |
| 468 |
% \end{function} |
| 469 |
% |
| 470 |
% \begin{function}[updated = 2020-01-17] |
| 471 |
% {.skip_set:N, .skip_set:c, .skip_gset:N, .skip_gset:c} |
| 472 |
% \begin{syntax} |
| 473 |
% \meta{key} .skip_set:N = \meta{skip} |
| 474 |
% \end{syntax} |
| 475 |
% Defines \meta{key} to set \meta{skip} to \meta{value} (which |
| 476 |
% must be a skip expression). If the variable does not exist, it |
| 477 |
% is created globally at the point that the key is set up. The key will |
| 478 |
% require a value at point-of-use unless a default is set. |
| 479 |
% \end{function} |
| 480 |
% |
| 481 |
% \begin{function}[added = 2021-10-30] |
| 482 |
% {.str_set:N, .str_set:c, .str_gset:N, .str_gset:c} |
| 483 |
% \begin{syntax} |
| 484 |
% \meta{key} .str_set:N = \meta{string variable} |
| 485 |
% \end{syntax} |
| 486 |
% Defines \meta{key} to set \meta{string variable} to \meta{value}. |
| 487 |
% If the variable does not exist, it is created globally |
| 488 |
% at the point that the key is set up. |
| 489 |
% \end{function} |
| 490 |
% |
| 491 |
% \begin{function}[added = 2023-09-18] |
| 492 |
% {.str_set_e:N, .str_set_e:c, .str_gset_e:N, .str_gset_e:c} |
| 493 |
% \begin{syntax} |
| 494 |
% \meta{key} .str_set_e:N = \meta{string variable} |
| 495 |
% \end{syntax} |
| 496 |
% Defines \meta{key} to set \meta{string variable} to \meta{value}, |
| 497 |
% which will be subjected to an \texttt{e}-type expansion |
| 498 |
% (i.e., using \cs{str_set:Ne}). If the variable does not exist, |
| 499 |
% it is created globally at the point that the key is set up. |
| 500 |
% \end{function} |
| 501 |
% |
| 502 |
% \begin{function}{.tl_set:N, .tl_set:c, .tl_gset:N, .tl_gset:c} |
| 503 |
% \begin{syntax} |
| 504 |
% \meta{key} .tl_set:N = \meta{tl~var} |
| 505 |
% \end{syntax} |
| 506 |
% Defines \meta{key} to set \meta{tl~var} to \meta{value}. |
| 507 |
% If the variable does not exist, it is created globally |
| 508 |
% at the point that the key is set up. |
| 509 |
% \end{function} |
| 510 |
% |
| 511 |
% \begin{function}[added = 2023-09-18] |
| 512 |
% {.tl_set_e:N, .tl_set_e:c, .tl_gset_e:N, .tl_gset_e:c} |
| 513 |
% \begin{syntax} |
| 514 |
% \meta{key} .tl_set_e:N = \meta{tl~var} |
| 515 |
% \end{syntax} |
| 516 |
% Defines \meta{key} to set \meta{tl~var} to \meta{value}, |
| 517 |
% which will be subjected to an \texttt{e}-type expansion |
| 518 |
% (i.e., using \cs{tl_set:Ne}). If the variable does not exist, |
| 519 |
% it is created globally at the point that the key is set up. |
| 520 |
% \end{function} |
| 521 |
% |
| 522 |
% \begin{function}[added = 2015-07-14]{.undefine:} |
| 523 |
% \begin{syntax} |
| 524 |
% \meta{key} .undefine: |
| 525 |
% \end{syntax} |
| 526 |
% Removes the definition of the \meta{key} within the current \TeX{} group. |
| 527 |
% \end{function} |
| 528 |
% |
| 529 |
% \begin{function}[added = 2015-07-14]{.value_forbidden:n} |
| 530 |
% \begin{syntax} |
| 531 |
% \meta{key} .value_forbidden:n = \texttt{true\string|false} |
| 532 |
% \end{syntax} |
| 533 |
% Specifies that \meta{key} cannot receive a \meta{value} when used. |
| 534 |
% If a \meta{value} is given then an error will be issued. Setting |
| 535 |
% the property \enquote{\texttt{false}} cancels the restriction. |
| 536 |
% \end{function} |
| 537 |
% |
| 538 |
% \begin{function}[added = 2015-07-14]{.value_required:n} |
| 539 |
% \begin{syntax} |
| 540 |
% \meta{key} .value_required:n = \texttt{true\string|false} |
| 541 |
% \end{syntax} |
| 542 |
% Specifies that \meta{key} must receive a \meta{value} when used. |
| 543 |
% If a \meta{value} is not given then an error will be issued. Setting |
| 544 |
% the property \enquote{\texttt{false}} cancels the restriction. |
| 545 |
% \end{function} |
| 546 |
% |
| 547 |
% \section{Sub-dividing keys} |
| 548 |
% \label{sec:l3keys:subdivision} |
| 549 |
% |
| 550 |
% When creating large numbers of keys, it may be desirable to divide |
| 551 |
% them into several subsets for a given module. This can be achieved |
| 552 |
% either by adding a sub-division to the module name: |
| 553 |
% \begin{verbatim} |
| 554 |
% \keys_define:nn { mymodule / subset } |
| 555 |
% { key .code:n = code } |
| 556 |
% \end{verbatim} |
| 557 |
% or to the key name: |
| 558 |
% \begin{verbatim} |
| 559 |
% \keys_define:nn { mymodule } |
| 560 |
% { subset / key .code:n = code } |
| 561 |
% \end{verbatim} |
| 562 |
% As illustrated, the best choice of token for sub-dividing keys in |
| 563 |
% this way is |/|. This is because of the method that is |
| 564 |
% used to represent keys internally. Both of the above code fragments |
| 565 |
% set the same key, which has full name \texttt{mymodule/subset/key}. |
| 566 |
% |
| 567 |
% As illustrated in the next section, this subdivision is |
| 568 |
% particularly relevant to making multiple choices. |
| 569 |
% |
| 570 |
% \section{Choice and multiple choice keys} |
| 571 |
% \label{sec:l3keys:choice} |
| 572 |
% |
| 573 |
% The \pkg{l3keys} system supports two types of choice key, in which a series |
| 574 |
% of pre-defined input values are linked to varying implementations. Choice |
| 575 |
% keys are usually created so that the various values are mutually-exclusive: |
| 576 |
% only one can apply at any one time. \enquote{Multiple} choice keys are also |
| 577 |
% supported: these allow a selection of values to be chosen at the same time. |
| 578 |
% |
| 579 |
% Mutually-exclusive choices are created by setting the \texttt{.choice:} |
| 580 |
% property: |
| 581 |
% \begin{verbatim} |
| 582 |
% \keys_define:nn { mymodule } |
| 583 |
% { key .choice: } |
| 584 |
% \end{verbatim} |
| 585 |
% For keys which are set up as choices, the valid choices are generated |
| 586 |
% by creating sub-keys of the choice key. This can be carried out in |
| 587 |
% two ways. |
| 588 |
% |
| 589 |
% In many cases, choices execute similar code which is dependent only |
| 590 |
% on the name of the choice or the position of the choice in the |
| 591 |
% list of all possibilities. Here, the keys can share the same code, and can |
| 592 |
% be rapidly created using the \texttt{.choices:nn} property. |
| 593 |
% \begin{verbatim} |
| 594 |
% \keys_define:nn { mymodule } |
| 595 |
% { |
| 596 |
% key .choices:nn = |
| 597 |
% { choice-a, choice-b, choice-c } |
| 598 |
% { |
| 599 |
% You~gave~choice~'\str_use:N \l_keys_choice_str',~ |
| 600 |
% which~is~in~position~\int_use:N \l_keys_choice_int \c_space_tl |
| 601 |
% in~the~list. |
| 602 |
% } |
| 603 |
% } |
| 604 |
% \end{verbatim} |
| 605 |
% The index \cs{l_keys_choice_int} in the list of choices starts at~$1$. |
| 606 |
% |
| 607 |
% \begin{variable}[updated = 2025-09-29] |
| 608 |
% {\l_keys_choice_int, \l_keys_choice_str} |
| 609 |
% Inside the code block for a choice generated using \texttt{.choices:nn}, |
| 610 |
% the variables \cs{l_keys_choice_str} and \cs{l_keys_choice_int} are |
| 611 |
% available to indicate the name of the current choice, and its position in |
| 612 |
% the comma list. The position is indexed from~$1$. Note that, as with |
| 613 |
% standard key code generated using \texttt{.code:n}, the value passed to |
| 614 |
% the key (i.e., the choice name) is also available as |#1|. |
| 615 |
% \end{variable} |
| 616 |
% |
| 617 |
% On the other hand, it is sometimes useful to create choices which |
| 618 |
% use entirely different code from one another. This can be achieved |
| 619 |
% by setting the \texttt{.choice:} property of a key, then manually |
| 620 |
% defining sub-keys. |
| 621 |
% \begin{verbatim} |
| 622 |
% \keys_define:nn { mymodule } |
| 623 |
% { |
| 624 |
% key .choice:, |
| 625 |
% key / choice-a .code:n = code-a, |
| 626 |
% key / choice-b .code:n = code-b, |
| 627 |
% key / choice-c .code:n = code-c, |
| 628 |
% } |
| 629 |
% \end{verbatim} |
| 630 |
% |
| 631 |
% It is possible to mix the two methods, but manually-created choices |
| 632 |
% should \emph{not} use \cs{l_keys_choice_str} or \cs{l_keys_choice_int}. |
| 633 |
% These variables do not have defined behavior when used outside of |
| 634 |
% code created using \texttt{.choices:nn} |
| 635 |
% (i.e., anything might happen). |
| 636 |
% |
| 637 |
% It is possible to allow choice keys to take values which have not previously |
| 638 |
% been defined by adding code for the special \texttt{unknown} choice. The |
| 639 |
% general behavior of the \texttt{unknown} key is described in |
| 640 |
% Section~\ref{sec:l3keys:unknown}. A typical example in the case of a choice |
| 641 |
% would be to issue a custom error message: |
| 642 |
% \begin{verbatim} |
| 643 |
% \keys_define:nn { mymodule } |
| 644 |
% { |
| 645 |
% key .choice:, |
| 646 |
% key / choice-a .code:n = code-a, |
| 647 |
% key / choice-b .code:n = code-b, |
| 648 |
% key / choice-c .code:n = code-c, |
| 649 |
% key / unknown .code:n = |
| 650 |
% \msg_error:nneee { mymodule } { unknown-choice } |
| 651 |
% { key } % Name of choice key |
| 652 |
% { choice-a , choice-b , choice-c } % Valid choices |
| 653 |
% { \exp_not:n {#1} } % Invalid choice given |
| 654 |
% } |
| 655 |
% \end{verbatim} |
| 656 |
% |
| 657 |
% Multiple choices are created in a very similar manner to mutually-exclusive |
| 658 |
% choices, using the properties \texttt{.multichoice:} and |
| 659 |
% \texttt{.multichoices:nn}. As with mutually exclusive choices, multiple |
| 660 |
% choices are defined as sub-keys. Thus both |
| 661 |
% \begin{verbatim} |
| 662 |
% \keys_define:nn { mymodule } |
| 663 |
% { |
| 664 |
% key .multichoices:nn = |
| 665 |
% { choice-a, choice-b, choice-c } |
| 666 |
% { |
| 667 |
% You~gave~choice~'\str_use:N \l_keys_choice_str',~ |
| 668 |
% which~is~in~position~ |
| 669 |
% \int_use:N \l_keys_choice_int \c_space_tl |
| 670 |
% in~the~list. |
| 671 |
% } |
| 672 |
% } |
| 673 |
% \end{verbatim} |
| 674 |
% and |
| 675 |
% \begin{verbatim} |
| 676 |
% \keys_define:nn { mymodule } |
| 677 |
% { |
| 678 |
% key .multichoice:, |
| 679 |
% key / choice-a .code:n = code-a, |
| 680 |
% key / choice-b .code:n = code-b, |
| 681 |
% key / choice-c .code:n = code-c, |
| 682 |
% } |
| 683 |
% \end{verbatim} |
| 684 |
% are valid. |
| 685 |
% |
| 686 |
% When a multiple choice key is set |
| 687 |
% \begin{verbatim} |
| 688 |
% \keys_set:nn { mymodule } |
| 689 |
% { |
| 690 |
% key = { a , b , c } % 'key' defined as a multiple choice |
| 691 |
% } |
| 692 |
% \end{verbatim} |
| 693 |
% each choice is applied in turn, equivalent to a \texttt{clist} mapping or |
| 694 |
% to applying each value individually: |
| 695 |
% \begin{verbatim} |
| 696 |
% \keys_set:nn { mymodule } |
| 697 |
% { |
| 698 |
% key = a , |
| 699 |
% key = b , |
| 700 |
% key = c , |
| 701 |
% } |
| 702 |
% \end{verbatim} |
| 703 |
% Thus each separate choice will have passed to it the |
| 704 |
% \cs{l_keys_choice_str} and \cs{l_keys_choice_int} in exactly |
| 705 |
% the same way as described for \texttt{.choices:nn}. |
| 706 |
% |
| 707 |
% \section{Key usage scope} |
| 708 |
% |
| 709 |
% Some keys will be used as settings which have a strictly limited scope |
| 710 |
% of usage. Some will be only available once, others will only be valid |
| 711 |
% until typesetting begins. To allow formats to support this in a structured |
| 712 |
% way, \pkg{l3keys} allows this information to be specified using the |
| 713 |
% \texttt{.usage:n} property. |
| 714 |
% |
| 715 |
% \begin{function}[added = 2022-01-10]{.usage:n} |
| 716 |
% \begin{syntax} |
| 717 |
% \meta{key} .usage:n = \meta{scope} |
| 718 |
% \end{syntax} |
| 719 |
% Defines the \meta{key} to have usage within the \meta{scope}, which |
| 720 |
% should be one of \texttt{general}, \texttt{preamble} or \texttt{load}. |
| 721 |
% \end{function} |
| 722 |
% |
| 723 |
% \begin{variable}[added = 2022-01-10] |
| 724 |
% {\l_keys_usage_load_prop, \l_keys_usage_preamble_prop} |
| 725 |
% \pkg{l3keys} itself does \emph{not} attempt to redefine keys based on the |
| 726 |
% usage scope. Rather, this information is made available with these |
| 727 |
% two property lists. These hold an entry for each module (prefix); the |
| 728 |
% value of each entry is a comma-separated list of the usage-restricted |
| 729 |
% key(s). |
| 730 |
% \end{variable} |
| 731 |
% |
| 732 |
% \section{Setting keys} |
| 733 |
% |
| 734 |
% \begin{function}[updated = 2017-11-14] |
| 735 |
% { |
| 736 |
% \keys_set:nn, \keys_set:nV, \keys_set:nv, \keys_set:ne, |
| 737 |
% \keys_set:no, |
| 738 |
% } |
| 739 |
% \begin{syntax} |
| 740 |
% \cs{keys_set:nn} \Arg{module} \Arg{keyval list} |
| 741 |
% \end{syntax} |
| 742 |
% Parses the \meta{keyval list}, and sets those keys which are defined |
| 743 |
% for \meta{module}. The behavior on finding an unknown key can be set |
| 744 |
% by defining a special \texttt{unknown} key: this is illustrated |
| 745 |
% later. |
| 746 |
% \end{function} |
| 747 |
% |
| 748 |
% \begin{variable}[updated = 2020-02-08] |
| 749 |
% {\l_keys_path_str, \l_keys_key_str, \l_keys_value_tl} |
| 750 |
% For each key processed, information of the full \emph{path} of the |
| 751 |
% key, the \emph{name} of the key and the \emph{value} of the key is |
| 752 |
% available within two string and one token list variables. |
| 753 |
% These may be used within the code of the key. |
| 754 |
% |
| 755 |
% The \emph{path} of the key is a \enquote{full} description of the key, |
| 756 |
% and is unique for each key. It consists of the module and full key name, |
| 757 |
% thus for example |
| 758 |
% \begin{verbatim} |
| 759 |
% \keys_set:nn { mymodule } { key-a = some-value } |
| 760 |
% \end{verbatim} |
| 761 |
% has path \texttt{mymodule/key-a} while |
| 762 |
% \begin{verbatim} |
| 763 |
% \keys_set:nn { mymodule } { subset / key-a = some-value } |
| 764 |
% \end{verbatim} |
| 765 |
% has path \texttt{mymodule/subset/key-a}. This information is stored in |
| 766 |
% \cs{l_keys_path_str}. |
| 767 |
% |
| 768 |
% The \emph{name} of the key is the part of the path after the last |
| 769 |
% \texttt{/}, and thus is not unique. In the preceding examples, both keys |
| 770 |
% have name \texttt{key-a} despite having different paths. This information |
| 771 |
% is stored in \cs{l_keys_key_str}. |
| 772 |
% |
| 773 |
% The \emph{value} is everything after the \texttt{=}, which may be |
| 774 |
% empty if no value was given. This is stored in \cs{l_keys_value_tl}, and |
| 775 |
% is not processed in any way by \cs{keys_set:nn}. |
| 776 |
% \end{variable} |
| 777 |
% |
| 778 |
% \subsection{Expanding the values of keys} |
| 779 |
% |
| 780 |
% To allow the user to apply expansion of values when the key is set, |
| 781 |
% key names can be |
| 782 |
% followed by an expansion specifier. This is given by appending |:| and a |
| 783 |
% single letter specifier to the key name. The latter are the normal argument |
| 784 |
% specifiers for \pkg{expl3}, thus may be one of \texttt{n} (redundant but |
| 785 |
% supported), \texttt{o}, \texttt{V}, \texttt{v} or \texttt{e}, or |
| 786 |
% \texttt{N} (again redundant) or \texttt{c}. Thus for example |
| 787 |
% \begin{verbatim} |
| 788 |
% \tl_new:N \l__mymodule_value_tl |
| 789 |
% \dim_new:N \l__mymodule_value_dim |
| 790 |
% \keys_define:nn { mymodule } { key .code:n = \tl_show:n { "#1" } } |
| 791 |
% \tl_set:Nn \l__mymodule_value_tl { value } |
| 792 |
% \dim_set:Nn \l__mymodule_value_dim { 123pt } |
| 793 |
% \keys_set:nn { mymodule } { key = value } |
| 794 |
% \keys_set:nn { mymodule } { key:o = \l__mymodule_value_tl } |
| 795 |
% \keys_set:nn { mymodule } { key:V = \l__mymodule_value_dim } |
| 796 |
% \keys_set:nn { mymodule } |
| 797 |
% { |
| 798 |
% key:e = |
| 799 |
% \l__mymodule_value_tl \c_space_tl |
| 800 |
% \dim_use:N \l__mymodule_value_dim |
| 801 |
% } |
| 802 |
% \end{verbatim} |
| 803 |
% will result in the output |
| 804 |
% \begin{verbatim} |
| 805 |
% "value" |
| 806 |
% "value" |
| 807 |
% "123.0pt" |
| 808 |
% "value 123.0pt" |
| 809 |
% \end{verbatim} |
| 810 |
% |
| 811 |
% \section{Handling of unknown keys} |
| 812 |
% \label{sec:l3keys:unknown} |
| 813 |
% |
| 814 |
% If a key has not previously been defined (is unknown), \cs{keys_set:nn} |
| 815 |
% looks for a special \texttt{unknown} key for the same module, and if this is |
| 816 |
% not defined raises an error indicating that the key name was unknown. This |
| 817 |
% mechanism can be used for example to issue custom error texts. The |
| 818 |
% \texttt{unknown} key also supports the \texttt{.default:n} property. |
| 819 |
% \begin{verbatim} |
| 820 |
% \keys_define:nn { mymodule } |
| 821 |
% { |
| 822 |
% unknown .code:n = |
| 823 |
% You~tried~to~set~key~'\l_keys_key_str'~to~'#1'. , |
| 824 |
% unknown .default:V = \c_novalue_tl |
| 825 |
% } |
| 826 |
% \end{verbatim} |
| 827 |
% |
| 828 |
% Key inheritance does \emph{not} include looking for the special |
| 829 |
% \texttt{unknown} key. Handling of \texttt{unknown} keys should |
| 830 |
% be set up explicitly for each path where it applies. |
| 831 |
% |
| 832 |
% \section{Selective key setting} |
| 833 |
% \label{sec:l3keys:selective} |
| 834 |
% |
| 835 |
% In some cases it may be useful to be able to select only some keys for |
| 836 |
% setting, even though these keys have the same path. For example, with |
| 837 |
% a set of keys defined using |
| 838 |
% \begin{verbatim} |
| 839 |
% \keys_define:nn { mymodule } |
| 840 |
% { |
| 841 |
% key-one .code:n = { \my_func:n {#1} } , |
| 842 |
% key-two .tl_set:N = \l_my_a_tl , |
| 843 |
% key-three .tl_set:N = \l_my_b_tl , |
| 844 |
% key-four .fp_set:N = \l_my_a_fp , |
| 845 |
% } |
| 846 |
% \end{verbatim} |
| 847 |
% the use of \cs{keys_set:nn} attempts to set all four keys. However, in |
| 848 |
% some contexts it may only be sensible to set some keys, or to control the |
| 849 |
% order of setting. To do this, keys may be assigned to \emph{groups}: |
| 850 |
% arbitrary sets which are independent of the key tree. Thus modifying the |
| 851 |
% example to read |
| 852 |
% \begin{verbatim} |
| 853 |
% \keys_define:nn { mymodule } |
| 854 |
% { |
| 855 |
% key-one .code:n = { \my_func:n {#1} } , |
| 856 |
% key-one .groups:n = { first } , |
| 857 |
% key-two .tl_set:N = \l_my_a_tl , |
| 858 |
% key-two .groups:n = { first } , |
| 859 |
% key-three .tl_set:N = \l_my_b_tl , |
| 860 |
% key-three .groups:n = { second } , |
| 861 |
% key-four .fp_set:N = \l_my_a_fp , |
| 862 |
% } |
| 863 |
% \end{verbatim} |
| 864 |
% assigns \texttt{key-one} and \texttt{key-two} to group \texttt{first}, |
| 865 |
% \texttt{key-three} to group \texttt{second}, while \texttt{key-four} is |
| 866 |
% not assigned to a group. |
| 867 |
% |
| 868 |
% Selective key setting may be achieved either by selecting one or more |
| 869 |
% groups to be made \enquote{active}, or by marking one or more groups to |
| 870 |
% be ignored in key setting. |
| 871 |
% |
| 872 |
% \begin{function}[added = 2011-08-23, updated = 2019-01-29] |
| 873 |
% { |
| 874 |
% \keys_set_known:nn, \keys_set_known:nV, |
| 875 |
% \keys_set_known:nv, \keys_set_known:ne, |
| 876 |
% \keys_set_known:no, |
| 877 |
% \keys_set_known:nnN, \keys_set_known:nVN, |
| 878 |
% \keys_set_known:nvN, \keys_set_known:neN, |
| 879 |
% \keys_set_known:noN, |
| 880 |
% \keys_set_known:nnnN, \keys_set_known:nVnN, |
| 881 |
% \keys_set_known:nvnN, \keys_set_known:nenN, |
| 882 |
% \keys_set_known:nonN |
| 883 |
% } |
| 884 |
% \begin{syntax} |
| 885 |
% \cs{keys_set_known:nn} \Arg{module} \Arg{keyval list} |
| 886 |
% \cs{keys_set_known:nnN} \Arg{module} \Arg{keyval list} \meta{tl~var} |
| 887 |
% \cs{keys_set_known:nnnN} \Arg{module} \Arg{keyval list} \Arg{root} \meta{tl~var} |
| 888 |
% \end{syntax} |
| 889 |
% These functions set keys which are known for the \meta{module}, and |
| 890 |
% simply ignore other keys. The \cs{keys_set_known:nn} function parses the |
| 891 |
% \meta{keyval list}, and sets those keys which are defined for |
| 892 |
% \meta{module}. Any keys which are unknown are not processed further by |
| 893 |
% the parser. |
| 894 |
% |
| 895 |
% In addition, \cs{keys_set_known:nnN} and \cs{keys_set_known:nnnN} |
| 896 |
% store the key--value pairs for unknown keys in the \meta{tl~var} |
| 897 |
% in comma-separated form (i.e., an edited version of the |
| 898 |
% \meta{keyval list}). When a \meta{root} is given |
| 899 |
% (\cs{keys_set_known:nnnN}), the key--value entries are returned |
| 900 |
% relative to this point in the key tree. When it is absent, only the |
| 901 |
% key name and value are provided. The correct list is returned by |
| 902 |
% nested calls. |
| 903 |
% \end{function} |
| 904 |
% |
| 905 |
% \begin{function}[added = 2013-07-14, updated = 2024-05-08] |
| 906 |
% { |
| 907 |
% \keys_set_groups:nnn, \keys_set_groups:nnV, |
| 908 |
% \keys_set_groups:nnv, \keys_set_groups:nno, |
| 909 |
% \keys_set_groups:nnnN, \keys_set_groups:nnVN, |
| 910 |
% \keys_set_groups:nnvN, \keys_set_groups:nnoN, |
| 911 |
% \keys_set_groups:nnnnN, \keys_set_groups:nnVnN, |
| 912 |
% \keys_set_groups:nnvnN, \keys_set_groups:nnonN, |
| 913 |
% } |
| 914 |
% \begin{syntax} |
| 915 |
% \cs{keys_set_groups:nnn} \Arg{module} \Arg{groups} \Arg{keyval list} |
| 916 |
% \cs{keys_set_groups:nnnN} \Arg{module} \Arg{groups} \Arg{keyval list} \meta{tl~var} |
| 917 |
% \cs{keys_set_groups:nnnnN} \Arg{module} \Arg{groups} \Arg{keyval list} \Arg{root} \meta{tl~var} |
| 918 |
% \end{syntax} |
| 919 |
% These functions activate key selection in an \enquote{opt-in} sense: |
| 920 |
% only keys assigned to one or more of the \meta{groups} specified are set. |
| 921 |
% The \meta{groups} are given as a comma-separated list. Unknown keys are |
| 922 |
% not assigned to any group and are thus never set. |
| 923 |
% |
| 924 |
% In addition, \cs{keys_set_groups:nnnN} and \cs{keys_set_groups:nnnnN} |
| 925 |
% store the key--value pairs for skipped keys in the \meta{tl~var} |
| 926 |
% in comma-separated form (i.e., an edited version of the |
| 927 |
% \meta{keyval list}). When a \meta{root} is given |
| 928 |
% (\cs{keys_set_groups:nnnnN}), the key--value entries are returned |
| 929 |
% relative to this point in the key tree. When it is absent, only the |
| 930 |
% key name and value are provided. The correct list is returned by |
| 931 |
% nested calls. |
| 932 |
% \end{function} |
| 933 |
% |
| 934 |
% \begin{function}[added = 2024-01-10] |
| 935 |
% { |
| 936 |
% \keys_set_exclude_groups:nnn, \keys_set_exclude_groups:nnV, |
| 937 |
% \keys_set_exclude_groups:nnv, \keys_set_exclude_groups:nno, |
| 938 |
% \keys_set_exclude_groups:nnnN, \keys_set_exclude_groups:nnVN, |
| 939 |
% \keys_set_exclude_groups:nnvN, \keys_set_exclude_groups:nnoN, |
| 940 |
% \keys_set_exclude_groups:nnnnN, \keys_set_exclude_groups:nnVnN, |
| 941 |
% \keys_set_exclude_groups:nnvnN, \keys_set_exclude_groups:nnonN, |
| 942 |
% } |
| 943 |
% \begin{syntax} |
| 944 |
% \cs{keys_set_exclude_groups:nnn} \Arg{module} \Arg{groups} \Arg{keyval list} |
| 945 |
% \cs{keys_set_exclude_groups:nnnN} \Arg{module} \Arg{groups} \Arg{keyval list} \meta{tl~var} |
| 946 |
% \cs{keys_set_exclude_groups:nnnnN} \Arg{module} \Arg{groups} \Arg{keyval list} \Arg{root} \meta{tl~var} |
| 947 |
% \end{syntax} |
| 948 |
% These functions activate key selection in an \enquote{opt-out} sense: |
| 949 |
% keys assigned to one or more of the \meta{groups} specified are |
| 950 |
% \emph{not} set. The \meta{groups} are given as a comma-separated list. |
| 951 |
% Unknown keys are not assigned to any group and are thus always set. |
| 952 |
% |
| 953 |
% In addition, \cs{keys_set_exclude_groups:nnnN} and |
| 954 |
% \cs{keys_set_exclude_groups:nnnnN} store the key--value pairs for |
| 955 |
% skipped keys in the \meta{tl~var} in comma-separated form |
| 956 |
% (i.e., an edited version of the \meta{keyval list}). When a |
| 957 |
% \meta{root} is given (\cs{keys_set_exclude_groups:nnnnN}), the |
| 958 |
% key--value entries are returned relative to this point in the key |
| 959 |
% tree. When it is absent, only the key name and value are provided. |
| 960 |
% The correct list is returned by nested calls. |
| 961 |
% \end{function} |
| 962 |
% |
| 963 |
% \section{Precompiling keys} |
| 964 |
% |
| 965 |
% \begin{function}[added = 2022-03-09]{\keys_precompile:nnN} |
| 966 |
% \begin{syntax} |
| 967 |
% \cs{keys_precompile:nnN} \Arg{module} \Arg{keyval list} \meta{tl~var} |
| 968 |
% \end{syntax} |
| 969 |
% Parses the \meta{keyval list} as for \cs{keys_set:nn}, placing the |
| 970 |
% resulting code for those which set variables or functions into the |
| 971 |
% \meta{tl~var}. Thus this function \enquote{precompiles} the keyval list into |
| 972 |
% a set of results which can be applied rapidly. |
| 973 |
% |
| 974 |
% It is important to note that when precompiling keys, no expansion of variables |
| 975 |
% takes place. This means that any key setting which simply stores variable names, |
| 976 |
% rather than variable values, may not work correctly. Most notably, any |
| 977 |
% key setting which uses key status variables (\cs{l_keys_key_str}, etc.) |
| 978 |
% will yield unpredictable outcomes. As such, keys |
| 979 |
% intended to be precompiled should fully expand any values at the point of |
| 980 |
% setting. |
| 981 |
% \end{function} |
| 982 |
% |
| 983 |
% \section{Utility functions for keys} |
| 984 |
% |
| 985 |
% \begin{function}[EXP, pTF, updated = 2022-01-10] |
| 986 |
% {\keys_if_exist:nn, \keys_if_exist:ne} |
| 987 |
% \begin{syntax} |
| 988 |
% \cs{keys_if_exist_p:nn} \Arg{module} \Arg{key} \\ |
| 989 |
% \cs{keys_if_exist:nnTF} \Arg{module} \Arg{key} \Arg{true code} \Arg{false code} |
| 990 |
% \end{syntax} |
| 991 |
% Tests if the \meta{key} exists for \meta{module}, i.e., if any code |
| 992 |
% has been defined for \meta{key}. |
| 993 |
% \end{function} |
| 994 |
% |
| 995 |
% \begin{function}[added = 2011-08-21,EXP,pTF, updated = 2017-11-14] |
| 996 |
% {\keys_if_choice_exist:nnn} |
| 997 |
% \begin{syntax} |
| 998 |
% \cs{keys_if_choice_exist_p:nnn} \Arg{module} \Arg{key} \Arg{choice} \\ |
| 999 |
% \cs{keys_if_choice_exist:nnnTF} \Arg{module} \Arg{key} \Arg{choice} \Arg{true code} \Arg{false code} |
| 1000 |
% \end{syntax} |
| 1001 |
% Tests if the \meta{choice} is defined for the \meta{key} within the |
| 1002 |
% \meta{module}, i.e., if any code has been defined for |
| 1003 |
% \meta{key}/\meta{choice}. The test is \texttt{false} if the \meta{key} |
| 1004 |
% itself is not defined. |
| 1005 |
% \end{function} |
| 1006 |
% |
| 1007 |
% \begin{function}[updated = 2015-08-09]{\keys_show:nn} |
| 1008 |
% \begin{syntax} |
| 1009 |
% \cs{keys_show:nn} \Arg{module} \Arg{key} |
| 1010 |
% \end{syntax} |
| 1011 |
% Displays in the terminal |
| 1012 |
% the information associated to the \meta{key} for a \meta{module}, |
| 1013 |
% including the function which is used to actually implement it. |
| 1014 |
% \end{function} |
| 1015 |
% |
| 1016 |
% \begin{function}[added = 2014-08-22, updated = 2015-08-09]{\keys_log:nn} |
| 1017 |
% \begin{syntax} |
| 1018 |
% \cs{keys_log:nn} \Arg{module} \Arg{key} |
| 1019 |
% \end{syntax} |
| 1020 |
% Writes in the log file the information associated to the \meta{key} |
| 1021 |
% for a \meta{module}. See also \cs{keys_show:nn} which displays the |
| 1022 |
% result in the terminal. |
| 1023 |
% \end{function} |
| 1024 |
% |
| 1025 |
% \section{Low-level interface for parsing key--val lists} |
| 1026 |
% |
| 1027 |
% To re-cap from earlier, a key--value list is input of the form |
| 1028 |
% \begin{verbatim} |
| 1029 |
% KeyOne = ValueOne , |
| 1030 |
% KeyTwo = ValueTwo , |
| 1031 |
% KeyThree |
| 1032 |
% \end{verbatim} |
| 1033 |
% where each key--value pair is separated by a comma from the rest of |
| 1034 |
% the list, and each key--value pair does not necessarily contain an |
| 1035 |
% equals sign or a value! Processing this type of input correctly |
| 1036 |
% requires a number of careful steps, to correctly account for |
| 1037 |
% braces, spaces and the category codes of separators. |
| 1038 |
% |
| 1039 |
% While the functions described earlier are used as a high-level interface |
| 1040 |
% for processing such input, in special circumstances you may wish to use |
| 1041 |
% a lower-level approach. |
| 1042 |
% The low-level parsing system converts a \meta{key--value list} |
| 1043 |
% into \meta{keys} and associated \meta{values}. After the parsing phase |
| 1044 |
% is completed, the resulting keys and values (or keys alone) are |
| 1045 |
% available for further processing. This processing is not carried out by the |
| 1046 |
% low-level parser itself, and so the parser requires the names of |
| 1047 |
% two functions along with the key--value list. One function is |
| 1048 |
% needed to process key--value pairs (it receives two arguments), |
| 1049 |
% and a second function is required for keys given without any value |
| 1050 |
% (it is called with a single argument). |
| 1051 |
% |
| 1052 |
% The parser does not double |#| tokens or expand any input. Active |
| 1053 |
% tokens |=| and |,| appearing at the outer level of braces are converted |
| 1054 |
% to category \enquote{other} (12) so that the parser does not \enquote{miss} |
| 1055 |
% any due to category code changes. Spaces are removed from the ends |
| 1056 |
% of the keys and values. Keys and values which are given in braces |
| 1057 |
% have exactly one set removed (after space trimming), thus |
| 1058 |
% \begin{verbatim} |
| 1059 |
% key = {value here}, |
| 1060 |
% \end{verbatim} |
| 1061 |
% and |
| 1062 |
% \begin{verbatim} |
| 1063 |
% key = value here, |
| 1064 |
% \end{verbatim} |
| 1065 |
% are treated identically. |
| 1066 |
% |
| 1067 |
% \begin{function}[rEXP, added=2020-12-19, updated = 2021-05-10] |
| 1068 |
% {\keyval_parse:nnn, \keyval_parse:nnV, \keyval_parse:nnv} |
| 1069 |
% \begin{syntax} |
| 1070 |
% \cs{keyval_parse:nnn} \Arg{code_1} \Arg{code_2} \Arg{key--value list} |
| 1071 |
% \end{syntax} |
| 1072 |
% Parses the \meta{key--value list} into a series of \meta{keys} and |
| 1073 |
% associated \meta{values}, or keys alone (if no \meta{value} was |
| 1074 |
% given). \meta{code_1} receives each \meta{key} (with no \meta{value}) as a |
| 1075 |
% trailing brace group, whereas \meta{code_2} is appended by two brace groups, |
| 1076 |
% the \meta{key} and \meta{value}. |
| 1077 |
% The order of the \meta{keys} in the \meta{key--value list} |
| 1078 |
% is preserved. Thus |
| 1079 |
% \begin{verbatim} |
| 1080 |
% \keyval_parse:nnn |
| 1081 |
% { \use_none:nn { code 1 } } |
| 1082 |
% { \use_none:nnn { code 2 } } |
| 1083 |
% { key1 = value1 , key2 = value2, key3 = , key4 } |
| 1084 |
% \end{verbatim} |
| 1085 |
% is converted into an input stream |
| 1086 |
% \begin{verbatim} |
| 1087 |
% \use_none:nnn { code 2 } { key1 } { value1 } |
| 1088 |
% \use_none:nnn { code 2 } { key2 } { value2 } |
| 1089 |
% \use_none:nnn { code 2 } { key3 } { } |
| 1090 |
% \use_none:nn { code 1 } { key4 } |
| 1091 |
% \end{verbatim} |
| 1092 |
% Note that there is a difference between an empty value (an equals |
| 1093 |
% sign followed by nothing) and a missing value (no equals sign at |
| 1094 |
% all). Spaces are trimmed from the ends of the \meta{key} and \meta{value}, |
| 1095 |
% then one \emph{outer} set of braces is removed from the \meta{key} |
| 1096 |
% and \meta{value} as part of the processing. If you need exactly the output |
| 1097 |
% shown above, you'll need to either \texttt{e}-type or \texttt{x}-type expand |
| 1098 |
% the function. |
| 1099 |
% \begin{texnote} |
| 1100 |
% The result of each list element is returned within \cs{exp_not:n}, which |
| 1101 |
% means that the converted input stream does not expand further when |
| 1102 |
% appearing in an \texttt{e}-type or \texttt{x}-type argument expansion. |
| 1103 |
% \end{texnote} |
| 1104 |
% \end{function} |
| 1105 |
% |
| 1106 |
% \begin{function}[rEXP, updated = 2021-05-10] |
| 1107 |
% {\keyval_parse:NNn, \keyval_parse:NNV, \keyval_parse:NNv} |
| 1108 |
% \begin{syntax} |
| 1109 |
% \cs{keyval_parse:NNn} \meta{function_1} \meta{function_2} \Arg{key--value list} |
| 1110 |
% \end{syntax} |
| 1111 |
% Parses the \meta{key--value list} into a series of \meta{keys} and |
| 1112 |
% associated \meta{values}, or keys alone (if no \meta{value} was |
| 1113 |
% given). \meta{function_1} should take one argument, while |
| 1114 |
% \meta{function_2} should absorb two arguments. After |
| 1115 |
% \cs{keyval_parse:NNn} has parsed the \meta{key--value list}, |
| 1116 |
% \meta{function_1} is used to process keys given with no value |
| 1117 |
% and \meta{function_2} is used to process keys given with a |
| 1118 |
% value. The order of the \meta{keys} in the \meta{key--value list} |
| 1119 |
% is preserved. Thus |
| 1120 |
% \begin{verbatim} |
| 1121 |
% \keyval_parse:NNn \function:n \function:nn |
| 1122 |
% { key1 = value1 , key2 = value2, key3 = , key4 } |
| 1123 |
% \end{verbatim} |
| 1124 |
% is converted into an input stream |
| 1125 |
% \begin{verbatim} |
| 1126 |
% \function:nn { key1 } { value1 } |
| 1127 |
% \function:nn { key2 } { value2 } |
| 1128 |
% \function:nn { key3 } { } |
| 1129 |
% \function:n { key4 } |
| 1130 |
% \end{verbatim} |
| 1131 |
% Note that there is a difference between an empty value (an equals |
| 1132 |
% sign followed by nothing) and a missing value (no equals sign at |
| 1133 |
% all). Spaces are trimmed from the ends of the \meta{key} and \meta{value}, |
| 1134 |
% then one \emph{outer} set of braces is removed from the \meta{key} |
| 1135 |
% and \meta{value} as part of the processing. |
| 1136 |
% |
| 1137 |
% This shares the implementation of \cs{keyval_parse:nnn}, the difference is |
| 1138 |
% only semantically. |
| 1139 |
% \begin{texnote} |
| 1140 |
% The result is returned within \cs{exp_not:n}, which means that the |
| 1141 |
% converted input stream does not expand further when appearing in an |
| 1142 |
% \texttt{e}-type or \texttt{x}-type argument expansion. |
| 1143 |
% \end{texnote} |
| 1144 |
% \end{function} |
| 1145 |
% |
| 1146 |
% \begin{function}[added = 2026-02-09]{\keyval_map_inline:nnn} |
| 1147 |
% \begin{syntax} |
| 1148 |
% \cs{keyval_map_inline:nnn} \Arg{key--value list} \Arg{inline function_1} \Arg{inline function_2} |
| 1149 |
% \end{syntax} |
| 1150 |
% Applies the \meta{inline function_1} to every key in the \meta{key--value |
| 1151 |
% list} which got no value, and \meta{inline function_2} to every key in the |
| 1152 |
% \meta{key--value list} which got a value. The \meta{inline function_1} |
| 1153 |
% should consist of code that receives keys without a value as |#1|, and |
| 1154 |
% \meta{inline function_2} receives each key as |#1| and each value as |#2|. |
| 1155 |
% \end{function} |
| 1156 |
% |
| 1157 |
% \begin{function}[added = 2026-02-09, rEXP]{\keyval_map_break:} |
| 1158 |
% Used to terminate a \cs[no-index]{keyval_map_\ldots{}} function before all |
| 1159 |
% entries in the \meta{key--value list} have been processed. This |
| 1160 |
% normally takes place within a conditional statement, for example |
| 1161 |
% \begin{verbatim} |
| 1162 |
% \keyval_map_inline:nnn { foo, bar = baz, bingo, boom, ... } |
| 1163 |
% { |
| 1164 |
% \str_if_eq:nnTF { #1 } { bingo } |
| 1165 |
% { \clist_map_break: } |
| 1166 |
% { |
| 1167 |
% % Do something useful |
| 1168 |
% } |
| 1169 |
% } |
| 1170 |
% { |
| 1171 |
% % Do more useful things |
| 1172 |
% } |
| 1173 |
% \end{verbatim} |
| 1174 |
% See also \cs{keyval_map_break:n}. |
| 1175 |
% Use outside of a \cs[no-index]{keyval_map_\ldots{}} scenario leads to low |
| 1176 |
% level \TeX{} errors. |
| 1177 |
% \begin{texnote} |
| 1178 |
% When the mapping is broken, additional tokens may be inserted |
| 1179 |
% before further items are taken |
| 1180 |
% from the input stream. This depends on the design of the mapping |
| 1181 |
% function. |
| 1182 |
% \end{texnote} |
| 1183 |
% \end{function} |
| 1184 |
% |
| 1185 |
% \begin{function}[added = 2026-02-09, rEXP]{\keyval_map_break:n} |
| 1186 |
% \begin{syntax} |
| 1187 |
% \cs{keyval_map_break:n} \Arg{code} |
| 1188 |
% \end{syntax} |
| 1189 |
% Used to terminate a \cs[no-index]{keyval_map_\ldots{}} function before all |
| 1190 |
% entries in the \meta{key--value list} have been processed, inserting |
| 1191 |
% the \meta{code} after the mapping has ended. This |
| 1192 |
% normally takes place within a conditional statement, for example |
| 1193 |
% \begin{verbatim} |
| 1194 |
% \keyval_map_inline:nnn { foo, bar = baz, bingo, boom, ... } |
| 1195 |
% { |
| 1196 |
% \str_if_eq:nnTF { #1 } { bingo } |
| 1197 |
% { \keyval_map_break:n { <code> } } |
| 1198 |
% { |
| 1199 |
% % Do something useful |
| 1200 |
% } |
| 1201 |
% } |
| 1202 |
% { |
| 1203 |
% % Do more useful things |
| 1204 |
% } |
| 1205 |
% \end{verbatim} |
| 1206 |
% Use outside of a \cs[no-index]{keyval_map_\ldots{}} scenario leads to low |
| 1207 |
% level \TeX{} errors. |
| 1208 |
% \begin{texnote} |
| 1209 |
% When the mapping is broken, additional tokens may be inserted |
| 1210 |
% before the \meta{code} is |
| 1211 |
% inserted into the input stream. |
| 1212 |
% This depends on the design of the mapping function. |
| 1213 |
% \end{texnote} |
| 1214 |
% \end{function} |
| 1215 |
% |
| 1216 |
% \end{documentation} |
| 1217 |
% |
| 1218 |
% \begin{implementation} |
| 1219 |
% |
| 1220 |
% \section{\pkg{l3keys} implementation} |
| 1221 |
% |
| 1222 |
% \begin{macrocode} |
| 1223 |
%<*code> |
| 1224 |
% \end{macrocode} |
| 1225 |
% |
| 1226 |
% \subsection{Low-level interface} |
| 1227 |
% |
| 1228 |
% The low-level key parser's implementation is based heavily on \pkg{expkv}. |
| 1229 |
% Compared to \pkg{keyval} it adds a number of additional \enquote{safety} |
| 1230 |
% requirements and allows to process the parsed list of key--value pairs in a |
| 1231 |
% variety of ways. The net result is that this code needs around one and a half |
| 1232 |
% the amount of time as \pkg{keyval} to parse the same list of keys. To optimize |
| 1233 |
% speed as far as reasonably practical, a number of lower-level approaches are |
| 1234 |
% taken rather than using the higher-level \pkg{expl3} interfaces. |
| 1235 |
% |
| 1236 |
% \begin{macrocode} |
| 1237 |
%<@@=keyval> |
| 1238 |
% \end{macrocode} |
| 1239 |
% |
| 1240 |
% \begin{variable}{\s_@@_nil,\s_@@_mark,\s_@@_stop,\s_@@_tail} |
| 1241 |
% \begin{macrocode} |
| 1242 |
\scan_new:N \s_@@_nil |
| 1243 |
\scan_new:N \s_@@_mark |
| 1244 |
\scan_new:N \s_@@_stop |
| 1245 |
\scan_new:N \s_@@_tail |
| 1246 |
% \end{macrocode} |
| 1247 |
% \end{variable} |
| 1248 |
% |
| 1249 |
% \begin{variable}{\l__kernel_keyval_allow_blank_keys_bool} |
| 1250 |
% The general behavior of the \pkg{l3keys} module is to throw an error on |
| 1251 |
% blank key names. However to support the usage of \cs{keyval_parse:nnn} in |
| 1252 |
% the \pkg{l3prop} module we allow this error to be switched off temporarily |
| 1253 |
% and just ignore blank names. |
| 1254 |
% \begin{macrocode} |
| 1255 |
\bool_new:N \l__kernel_keyval_allow_blank_keys_bool |
| 1256 |
% \end{macrocode} |
| 1257 |
% \end{variable} |
| 1258 |
% |
| 1259 |
% This temporary macro will be used since some of the definitions will need an |
| 1260 |
% active comma or equals sign. Inside of this macro |#1| will be the active |
| 1261 |
% comma and |#2| will be the active equals sign. |
| 1262 |
% \begin{macrocode} |
| 1263 |
\group_begin: |
| 1264 |
\cs_set_protected:Npn \@@_tmp:nn #1#2 |
| 1265 |
{ |
| 1266 |
% \end{macrocode} |
| 1267 |
% |
| 1268 |
% \begin{macro}[rEXP] |
| 1269 |
% { |
| 1270 |
% \keyval_parse:nnn, \keyval_parse:nnV, \keyval_parse:nnv, |
| 1271 |
% \keyval_parse:NNn, \keyval_parse:NNV, \keyval_parse:NNv |
| 1272 |
% } |
| 1273 |
% The main function starts the first of two loops. The outer loop splits the |
| 1274 |
% key--value list at active commas, the inner loop will do so at other commas. |
| 1275 |
% The use of \cs{s_@@_mark} here prevents loss of braces from the key |
| 1276 |
% argument. |
| 1277 |
% \begin{macrocode} |
| 1278 |
\cs_new:Npn \keyval_parse:nnn ##1 ##2 ##3 |
| 1279 |
{ |
| 1280 |
\__kernel_exp_not:w \tex_expanded:D |
| 1281 |
{ |
| 1282 |
{ |
| 1283 |
\@@_loop_active:nnw {##1} {##2} |
| 1284 |
\s_@@_mark ##3 #1 \s_@@_tail #1 |
| 1285 |
} |
| 1286 |
} |
| 1287 |
} |
| 1288 |
\cs_new_eq:NN \keyval_parse:NNn \keyval_parse:nnn |
| 1289 |
% \end{macrocode} |
| 1290 |
% \end{macro} |
| 1291 |
% |
| 1292 |
% \begin{macro}[EXP]{\@@_loop_active:nnw} |
| 1293 |
% First a fast test for the end of the loop is done, it'll gobble everything |
| 1294 |
% up to a \cs{s_@@_tail}. The loop ending macro will gobble everything to the |
| 1295 |
% last comma in this definition. |
| 1296 |
% If the end isn't reached yet, start the second loop splitting at other |
| 1297 |
% commas, the next iteration of this first loop will be inserted by the end of |
| 1298 |
% \cs{@@_loop_other:nnw}. |
| 1299 |
% \begin{macrocode} |
| 1300 |
\cs_new:Npn \@@_loop_active:nnw ##1 ##2 ##3 #1 |
| 1301 |
{ |
| 1302 |
\@@_if_recursion_tail:w ##3 |
| 1303 |
\@@_end_loop_active:w \s_@@_tail |
| 1304 |
\@@_loop_other:nnw {##1} {##2} ##3 , \s_@@_tail , |
| 1305 |
} |
| 1306 |
% \end{macrocode} |
| 1307 |
% \end{macro} |
| 1308 |
% |
| 1309 |
% \begin{macro}[EXP]{\@@_split_other:w, \@@_split_active:w} |
| 1310 |
% These two macros allow to split at the first equals sign of category 12 or |
| 1311 |
% 13. At the same time they also execute branching by inserting the first |
| 1312 |
% token following \cs{s_@@_mark} that followed the equals sign. Hence they |
| 1313 |
% also test for the presence of such an equals sign simultaneously. |
| 1314 |
% \begin{macrocode} |
| 1315 |
\cs_new:Npn \@@_split_other:w ##1 = ##2 \s_@@_mark ##3 |
| 1316 |
{ ##3 ##1 \s_@@_stop \s_@@_mark ##2 } |
| 1317 |
\cs_new:Npn \@@_split_active:w ##1 #2 ##2 \s_@@_mark ##3 |
| 1318 |
{ ##3 ##1 \s_@@_stop \s_@@_mark ##2 } |
| 1319 |
% \end{macrocode} |
| 1320 |
% \end{macro} |
| 1321 |
% |
| 1322 |
% \begin{macro}[EXP]{\@@_loop_other:nnw} |
| 1323 |
% The second loop uses the same test for its end as the first loop, next it |
| 1324 |
% splits at the first active equals sign using \cs{@@_split_active:w}. The |
| 1325 |
% \cs{s_@@_nil} prevents accidental brace stripping and acts as a delimiter in |
| 1326 |
% the next steps. First testing for an active equals sign will reduce the |
| 1327 |
% number of necessary expansion steps for the expected average use case of |
| 1328 |
% other equals signs and hence perform better on average. |
| 1329 |
% \begin{macrocode} |
| 1330 |
\cs_new:Npn \@@_loop_other:nnw ##1 ##2 ##3 , |
| 1331 |
{ |
| 1332 |
\@@_if_recursion_tail:w ##3 |
| 1333 |
\@@_end_loop_other:w \s_@@_tail |
| 1334 |
\@@_split_active:w ##3 \s_@@_nil |
| 1335 |
\s_@@_mark \@@_split_active_auxi:w |
| 1336 |
#2 \s_@@_mark \@@_clean_up_active:w |
| 1337 |
{##1} {##2} |
| 1338 |
\s_@@_mark |
| 1339 |
} |
| 1340 |
% \end{macrocode} |
| 1341 |
% \end{macro} |
| 1342 |
% |
| 1343 |
% \begin{macro}[EXP]{\@@_split_active_auxi:w} |
| 1344 |
% \begin{macro}[EXP]{\@@_split_active_auxii:w} |
| 1345 |
% \begin{macro}[EXP]{\@@_split_active_auxiii:w} |
| 1346 |
% \begin{macro}[EXP]{\@@_split_active_auxiv:w} |
| 1347 |
% \begin{macro}[EXP]{\@@_split_active_auxv:w} |
| 1348 |
% After \cs{@@_split_active:w} the following will only be called if there was |
| 1349 |
% at least one active equals sign in the current key--value pair. Therefore |
| 1350 |
% this is the execution branch for a key--value pair with an active equals |
| 1351 |
% sign. |##1| will be everything up to the first active equals sign. First it |
| 1352 |
% tests for other equals signs in the key name, which will eventually throw an |
| 1353 |
% error via \cs{@@_misplaced_equal_after_active_error:w}. If none was found we |
| 1354 |
% forward the key to \cs{@@_split_active_auxii:w}. |
| 1355 |
% \begin{macrocode} |
| 1356 |
\cs_new:Npn \@@_split_active_auxi:w ##1 \s_@@_stop |
| 1357 |
{ |
| 1358 |
\@@_split_other:w ##1 \s_@@_nil |
| 1359 |
\s_@@_mark \@@_misplaced_equal_after_active_error:w |
| 1360 |
= \s_@@_mark \@@_split_active_auxii:w |
| 1361 |
} |
| 1362 |
% \end{macrocode} |
| 1363 |
% \cs{@@_split_active_auxii:w} gets the correct key name with a leading |
| 1364 |
% \cs{s_@@_mark} as |##1|. It has to sanitize the remainder of the previous |
| 1365 |
% test and trims the key name which will be forwarded to |
| 1366 |
% \cs{@@_split_active_auxiii:w}. |
| 1367 |
% \begin{macrocode} |
| 1368 |
\cs_new:Npn \@@_split_active_auxii:w |
| 1369 |
##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_after_active_error:w |
| 1370 |
\s_@@_stop \s_@@_mark |
| 1371 |
##2 \s_@@_nil #2 \s_@@_mark \@@_clean_up_active:w |
| 1372 |
{ \@@_trim:nN {##1} \@@_split_active_auxiii:w ##2 \s_@@_nil } |
| 1373 |
% \end{macrocode} |
| 1374 |
% Next we test for a misplaced active equals sign in the value, if none is |
| 1375 |
% found \cs{@@_split_active_auxiv:w} will be called. |
| 1376 |
% \begin{macrocode} |
| 1377 |
\cs_new:Npn \@@_split_active_auxiii:w ##1 ##2 \s_@@_nil |
| 1378 |
{ |
| 1379 |
\@@_split_active:w ##2 \s_@@_nil |
| 1380 |
\s_@@_mark \@@_misplaced_equal_in_split_error:w |
| 1381 |
#2 \s_@@_mark \@@_split_active_auxiv:w |
| 1382 |
{##1} |
| 1383 |
} |
| 1384 |
% \end{macrocode} |
| 1385 |
% This runs the last test after sanitizing the remainder of the previous one. |
| 1386 |
% This time test for a misplaced equals sign of category 12 in the value. |
| 1387 |
% Finally the last auxiliary macro will be called. |
| 1388 |
% \begin{macrocode} |
| 1389 |
\cs_new:Npn \@@_split_active_auxiv:w |
| 1390 |
##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_in_split_error:w |
| 1391 |
\s_@@_stop \s_@@_mark |
| 1392 |
{ |
| 1393 |
\@@_split_other:w ##1 \s_@@_nil |
| 1394 |
\s_@@_mark \@@_misplaced_equal_in_split_error:w |
| 1395 |
= \s_@@_mark \@@_split_active_auxv:w |
| 1396 |
} |
| 1397 |
% \end{macrocode} |
| 1398 |
% This last macro in this execution branch sanitizes the last test, trims the |
| 1399 |
% value and passes it to \cs{@@_pair:nnnn}. |
| 1400 |
% \begin{macrocode} |
| 1401 |
\cs_new:Npn \@@_split_active_auxv:w |
| 1402 |
##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_in_split_error:w |
| 1403 |
\s_@@_stop \s_@@_mark |
| 1404 |
{ \@@_trim:nN { ##1 } \@@_pair:nnnn } |
| 1405 |
% \end{macrocode} |
| 1406 |
% \end{macro} |
| 1407 |
% \end{macro} |
| 1408 |
% \end{macro} |
| 1409 |
% \end{macro} |
| 1410 |
% \end{macro} |
| 1411 |
% |
| 1412 |
% \begin{macro}[EXP]{\@@_clean_up_active:w} |
| 1413 |
% The following is the branch taken if the key--value pair doesn't contain an |
| 1414 |
% active equals sign. The remainder of that test will be cleaned up by |
| 1415 |
% \cs{@@_clean_up_active:w} which will then split at an equals sign of |
| 1416 |
% category other. |
| 1417 |
% \begin{macrocode} |
| 1418 |
\cs_new:Npn \@@_clean_up_active:w |
| 1419 |
##1 \s_@@_nil \s_@@_mark \@@_split_active_auxi:w \s_@@_stop \s_@@_mark |
| 1420 |
{ |
| 1421 |
\@@_split_other:w ##1 \s_@@_nil |
| 1422 |
\s_@@_mark \@@_split_other_auxi:w |
| 1423 |
= \s_@@_mark \@@_clean_up_other:w |
| 1424 |
} |
| 1425 |
% \end{macrocode} |
| 1426 |
% \end{macro} |
| 1427 |
% |
| 1428 |
% \begin{macro}[EXP]{\@@_split_other_auxi:w} |
| 1429 |
% \begin{macro}[EXP]{\@@_split_other_auxii:w} |
| 1430 |
% \begin{macro}[EXP]{\@@_split_other_auxiii:w} |
| 1431 |
% This is executed if the key--value pair doesn't contain an active equals |
| 1432 |
% sign but at least one other. |##1| of \cs{@@_split_other_auxi:w} will |
| 1433 |
% contain the complete key name, which is trimmed and forwarded to the next |
| 1434 |
% auxiliary macro. |
| 1435 |
% \begin{macrocode} |
| 1436 |
\cs_new:Npn \@@_split_other_auxi:w ##1 \s_@@_stop |
| 1437 |
{ \@@_trim:nN { ##1 } \@@_split_other_auxii:w } |
| 1438 |
% \end{macrocode} |
| 1439 |
% We know that the value doesn't contain misplaced active equals signs but we |
| 1440 |
% have to test for others. Also we need to sanitize the previous test, which |
| 1441 |
% is done here and not earlier to avoid superfluous argument grabbing. |
| 1442 |
% \begin{macrocode} |
| 1443 |
\cs_new:Npn \@@_split_other_auxii:w |
| 1444 |
##1 ##2 \s_@@_nil = \s_@@_mark \@@_clean_up_other:w |
| 1445 |
{ |
| 1446 |
\@@_split_other:w ##2 \s_@@_nil |
| 1447 |
\s_@@_mark \@@_misplaced_equal_in_split_error:w |
| 1448 |
= \s_@@_mark \@@_split_other_auxiii:w |
| 1449 |
{ ##1 } |
| 1450 |
} |
| 1451 |
% \end{macrocode} |
| 1452 |
% \cs{@@_split_other_auxiii:w} sanitizes the test for other equals signs, |
| 1453 |
% trims the value and forwards it to \cs{@@_pair:nnnn}. |
| 1454 |
% \begin{macrocode} |
| 1455 |
\cs_new:Npn \@@_split_other_auxiii:w |
| 1456 |
##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_in_split_error:w |
| 1457 |
\s_@@_stop \s_@@_mark |
| 1458 |
{ \@@_trim:nN { ##1 } \@@_pair:nnnn } |
| 1459 |
% \end{macrocode} |
| 1460 |
% \end{macro} |
| 1461 |
% \end{macro} |
| 1462 |
% \end{macro} |
| 1463 |
% |
| 1464 |
% \begin{macro}[EXP]{\@@_clean_up_other:w} |
| 1465 |
% \cs{@@_clean_up_other:w} is the last branch that might exist. It is called |
| 1466 |
% if no equals sign was found, hence the only possibilities left are a blank |
| 1467 |
% list element, which is to be skipped, or a lonely key. If it's no empty list |
| 1468 |
% element this will trim the key name and forward it to \cs{@@_key:nn}. |
| 1469 |
% \begin{macrocode} |
| 1470 |
\cs_new:Npn \@@_clean_up_other:w |
| 1471 |
##1 \s_@@_nil \s_@@_mark \@@_split_other_auxi:w \s_@@_stop \s_@@_mark |
| 1472 |
{ |
| 1473 |
\@@_if_blank:w ##1 \s_@@_nil \s_@@_stop \@@_blank_true:w |
| 1474 |
\s_@@_mark \s_@@_stop |
| 1475 |
\@@_trim:nN { ##1 } \@@_key:nn |
| 1476 |
} |
| 1477 |
% \end{macrocode} |
| 1478 |
% \end{macro} |
| 1479 |
% |
| 1480 |
% \begin{macro}[EXP]{\@@_misplaced_equal_after_active_error:w} |
| 1481 |
% \begin{macro}[EXP]{\@@_misplaced_equal_in_split_error:w} |
| 1482 |
% All these two macros do is gobble the remainder of the current other loop |
| 1483 |
% execution and throw an error. Afterwards they have to insert the next loop |
| 1484 |
% iteration. |
| 1485 |
% \begin{macrocode} |
| 1486 |
\cs_new:Npn \@@_misplaced_equal_after_active_error:w |
| 1487 |
\s_@@_mark ##1 \s_@@_stop \s_@@_mark ##2 \s_@@_nil |
| 1488 |
= \s_@@_mark \@@_split_active_auxii:w |
| 1489 |
\s_@@_mark ##3 \s_@@_nil |
| 1490 |
#2 \s_@@_mark \@@_clean_up_active:w |
| 1491 |
{ |
| 1492 |
\msg_expandable_error:nn |
| 1493 |
{ keyval } { misplaced-equals-sign } |
| 1494 |
\@@_loop_other:nnw |
| 1495 |
} |
| 1496 |
\cs_new:Npn \@@_misplaced_equal_in_split_error:w |
| 1497 |
\s_@@_mark ##1 \s_@@_stop \s_@@_mark ##2 \s_@@_nil |
| 1498 |
##3 \s_@@_mark ##4 ##5 |
| 1499 |
{ |
| 1500 |
\msg_expandable_error:nn |
| 1501 |
{ keyval } { misplaced-equals-sign } |
| 1502 |
\@@_loop_other:nnw |
| 1503 |
} |
| 1504 |
% \end{macrocode} |
| 1505 |
% \end{macro} |
| 1506 |
% \end{macro} |
| 1507 |
% |
| 1508 |
% \begin{macro}[EXP]{\@@_end_loop_other:w, \@@_end_loop_active:w} |
| 1509 |
% All that's left for the parsing loops are the macros which end the |
| 1510 |
% recursion. Both just gobble the remaining tokens of the respective loop |
| 1511 |
% including the next recursion call. \cs{@@_end_loop_other:w} also has to |
| 1512 |
% insert the next iteration of the active loop. |
| 1513 |
% \begin{macrocode} |
| 1514 |
\cs_new:Npn \@@_end_loop_other:w |
| 1515 |
\s_@@_tail |
| 1516 |
\@@_split_active:w |
| 1517 |
\s_@@_mark \s_@@_tail |
| 1518 |
\s_@@_nil \s_@@_mark |
| 1519 |
\@@_split_active_auxi:w |
| 1520 |
#2 \s_@@_mark \@@_clean_up_active:w |
| 1521 |
{ \@@_loop_active:nnw } |
| 1522 |
\cs_new:Npn \@@_end_loop_active:w |
| 1523 |
\s_@@_tail |
| 1524 |
\@@_loop_other:nnw ##1 \s_@@_mark \s_@@_tail , \s_@@_tail , |
| 1525 |
{ } |
| 1526 |
% \end{macrocode} |
| 1527 |
% \end{macro} |
| 1528 |
% |
| 1529 |
% The parsing loops are done, so here ends the definition of \cs{@@_tmp:nn}, |
| 1530 |
% which will finally set up the macros. |
| 1531 |
% \begin{macrocode} |
| 1532 |
} |
| 1533 |
\char_set_catcode_active:n { `\, } |
| 1534 |
\char_set_catcode_active:n { `\= } |
| 1535 |
\@@_tmp:nn , = |
| 1536 |
\group_end: |
| 1537 |
\cs_generate_variant:Nn \keyval_parse:NNn { NNV , NNv } |
| 1538 |
\cs_generate_variant:Nn \keyval_parse:nnn { nnV , nnv } |
| 1539 |
% \end{macrocode} |
| 1540 |
% |
| 1541 |
% \begin{macro}[EXP]{\@@_pair:nnnn, \@@_key:nn} |
| 1542 |
% These macros will be called on the parsed keys and values of the key--value |
| 1543 |
% list. All arguments are completely trimmed. They test for blank key names |
| 1544 |
% and call the functions passed to \cs{keyval_parse:nnn} inside of |
| 1545 |
% \cs{exp_not:n} with the correct arguments. Afterwards they insert the next |
| 1546 |
% iteration of the other loop. |
| 1547 |
% \begin{macrocode} |
| 1548 |
\group_begin: |
| 1549 |
\cs_set_protected:Npn \@@_tmp:nn #1#2 |
| 1550 |
{ |
| 1551 |
\cs_new:Npn \@@_pair:nnnn ##1 ##2 ##3 ##4 |
| 1552 |
{ |
| 1553 |
\@@_if_blank:w \s_@@_mark ##2 \s_@@_nil \s_@@_stop \@@_blank_key_error:w |
| 1554 |
\s_@@_mark \s_@@_stop |
| 1555 |
#1 |
| 1556 |
\exp_not:n { ##4 {##2} {##1} } |
| 1557 |
#2 |
| 1558 |
\@@_loop_other:nnw {##3} {##4} |
| 1559 |
} |
| 1560 |
\cs_new:Npn \@@_key:nn ##1 ##2 |
| 1561 |
{ |
| 1562 |
\@@_if_blank:w \s_@@_mark ##1 \s_@@_nil \s_@@_stop \@@_blank_key_error:w |
| 1563 |
\s_@@_mark \s_@@_stop |
| 1564 |
#1 |
| 1565 |
\exp_not:n { ##2 {##1} } |
| 1566 |
#2 |
| 1567 |
\@@_loop_other:nnw {##2} |
| 1568 |
} |
| 1569 |
} |
| 1570 |
\@@_tmp:nn { } { } |
| 1571 |
\group_end: |
| 1572 |
% \end{macrocode} |
| 1573 |
% \end{macro} |
| 1574 |
% |
| 1575 |
% \begin{macro}[EXP]{\@@_if_empty:w,\@@_if_blank:w,\@@_if_recursion_tail:w} |
| 1576 |
% All these tests work by gobbling tokens until a certain combination is met, |
| 1577 |
% which makes them pretty fast. The test for a blank argument should be called |
| 1578 |
% with an arbitrary token following the argument. Each of these utilize the |
| 1579 |
% fact that the argument will contain a leading \cs{s_@@_mark}. |
| 1580 |
% \begin{macrocode} |
| 1581 |
\cs_new:Npn \@@_if_empty:w #1 \s_@@_mark \s_@@_stop { } |
| 1582 |
\cs_new:Npn \@@_if_blank:w \s_@@_mark #1 { \@@_if_empty:w \s_@@_mark } |
| 1583 |
\cs_new:Npn \@@_if_recursion_tail:w \s_@@_mark #1 \s_@@_tail { } |
| 1584 |
% \end{macrocode} |
| 1585 |
% \end{macro} |
| 1586 |
% |
| 1587 |
% \begin{macro}[EXP]{\@@_blank_true:w,\@@_blank_key_error:w} |
| 1588 |
% These macros will be called if the tests above didn't gobble them, they |
| 1589 |
% execute the branching. |
| 1590 |
% \begin{macrocode} |
| 1591 |
\cs_new:Npn \@@_blank_true:w \s_@@_mark \s_@@_stop \@@_trim:nN #1 \@@_key:nn |
| 1592 |
{ \@@_loop_other:nnw } |
| 1593 |
\cs_new:Npn \@@_blank_key_error:w \s_@@_mark \s_@@_stop #1 \@@_loop_other:nnw |
| 1594 |
{ |
| 1595 |
\bool_if:NTF \l__kernel_keyval_allow_blank_keys_bool |
| 1596 |
{ #1 } |
| 1597 |
{ \msg_expandable_error:nn { keyval } { blank-key-name } } |
| 1598 |
\@@_loop_other:nnw |
| 1599 |
} |
| 1600 |
% \end{macrocode} |
| 1601 |
% \end{macro} |
| 1602 |
% |
| 1603 |
% Two messages for the low level parsing system. |
| 1604 |
% \begin{macrocode} |
| 1605 |
\msg_new:nnn { keyval } { misplaced-equals-sign } |
| 1606 |
{ Misplaced~'='~in~key-value~input~\msg_line_context: } |
| 1607 |
\msg_new:nnn { keyval } { blank-key-name } |
| 1608 |
{ Blank~key~name~in~key-value~input~\msg_line_context: } |
| 1609 |
\prop_gput:Nnn \g_msg_module_name_prop { keyval } { LaTeX } |
| 1610 |
\prop_gput:Nnn \g_msg_module_type_prop { keyval } { } |
| 1611 |
% \end{macrocode} |
| 1612 |
% |
| 1613 |
% \begin{macro}[EXP]{\@@_trim:nN} |
| 1614 |
% \begin{macro}[EXP] |
| 1615 |
% {\@@_trim_auxi:w,\@@_trim_auxii:w,\@@_trim_auxiii:w,\@@_trim_auxiv:w} |
| 1616 |
% And an adapted version of \cs{__tl_trim_spaces:nn} which is a bit faster for |
| 1617 |
% our use case, as it can strip the braces at the end. This is pretty much the |
| 1618 |
% same concept, so I won't comment on it here. The speed gain by using this |
| 1619 |
% instead of \cs{tl_trim_spaces_apply:nN} is about 10\,\% of the total time for |
| 1620 |
% \cs{keyval_parse:NNn} with one key and one key--value pair, so I think it's |
| 1621 |
% worth it. |
| 1622 |
% \begin{macrocode} |
| 1623 |
\group_begin: |
| 1624 |
\cs_set_protected:Npn \@@_tmp:n #1 |
| 1625 |
{ |
| 1626 |
\cs_new:Npn \@@_trim:nN ##1 |
| 1627 |
{ |
| 1628 |
\@@_trim_auxi:w |
| 1629 |
##1 |
| 1630 |
\s_@@_nil |
| 1631 |
\s_@@_mark #1 { } |
| 1632 |
\s_@@_mark \@@_trim_auxii:w |
| 1633 |
\@@_trim_auxiii:w |
| 1634 |
#1 \s_@@_nil |
| 1635 |
\@@_trim_auxiv:w |
| 1636 |
} |
| 1637 |
\cs_new:Npn \@@_trim_auxi:w ##1 \s_@@_mark #1 ##2 \s_@@_mark ##3 |
| 1638 |
{ |
| 1639 |
##3 |
| 1640 |
\@@_trim_auxi:w |
| 1641 |
\s_@@_mark |
| 1642 |
##2 |
| 1643 |
\s_@@_mark #1 {##1} |
| 1644 |
} |
| 1645 |
\cs_new:Npn \@@_trim_auxii:w \@@_trim_auxi:w \s_@@_mark \s_@@_mark ##1 |
| 1646 |
{ |
| 1647 |
\@@_trim_auxiii:w |
| 1648 |
##1 |
| 1649 |
} |
| 1650 |
\cs_new:Npn \@@_trim_auxiii:w ##1 #1 \s_@@_nil ##2 |
| 1651 |
{ |
| 1652 |
##2 |
| 1653 |
##1 \s_@@_nil |
| 1654 |
\@@_trim_auxiii:w |
| 1655 |
} |
| 1656 |
% \end{macrocode} |
| 1657 |
% This is the one macro which differs from the original definition. |
| 1658 |
% \begin{macrocode} |
| 1659 |
\cs_new:Npn \@@_trim_auxiv:w |
| 1660 |
\s_@@_mark ##1 \s_@@_nil |
| 1661 |
\@@_trim_auxiii:w \s_@@_nil \@@_trim_auxiii:w |
| 1662 |
##2 |
| 1663 |
{ ##2 { ##1 } } |
| 1664 |
} |
| 1665 |
\@@_tmp:n { ~ } |
| 1666 |
\group_end: |
| 1667 |
% \end{macrocode} |
| 1668 |
% \end{macro} |
| 1669 |
% \end{macro} |
| 1670 |
% |
| 1671 |
% \begin{macro}{\keyval_map_inline:nnn} |
| 1672 |
% Unlike many other mapping functions we don't need to keep a global stack of |
| 1673 |
% definitions for our auxiliary macros, instead we can contain their |
| 1674 |
% definition in a group and use \cs{keyval_parse:NNn} which we fully expand |
| 1675 |
% twice before the group is closed. This has the drawback that any breaking of |
| 1676 |
% the map happens after the entire list was already parsed, so has a |
| 1677 |
% performance penalty in that case. However, these should be rather rare |
| 1678 |
% occasions and the simplicity of the code should warrant them. Another |
| 1679 |
% drawback of this approach is that the expansion of the internal macros is |
| 1680 |
% left in the input stream for every element. |
| 1681 |
% |
| 1682 |
% The break point can remain outside of the braces containing the loop, since |
| 1683 |
% by the time any user code from the argument to the break statement is executed, |
| 1684 |
% the brace group will have been consumed. |
| 1685 |
% \begin{macrocode} |
| 1686 |
\cs_new_protected:Npn \keyval_map_inline:nnn #1#2#3 |
| 1687 |
{ |
| 1688 |
\group_begin: |
| 1689 |
\cs_set:Npn \@@_tmp:n ##1 { \exp_not:n {#2} } |
| 1690 |
\cs_set:Npn \@@_tmp:nn ##1##2 { \exp_not:n {#3} } |
| 1691 |
\exp_args:NNe \exp_last_unbraced:Ne |
| 1692 |
\group_end: |
| 1693 |
{ \keyval_parse:NNn \@@_tmp:n \@@_tmp:nn {#1} } |
| 1694 |
\prg_break_point:Nn \keyval_map_break: { } |
| 1695 |
} |
| 1696 |
% \end{macrocode} |
| 1697 |
% \end{macro} |
| 1698 |
% |
| 1699 |
% \begin{macro}{\keyval_map_break:, \keyval_map_break:n} |
| 1700 |
% Simple code using the \cs{prg_map_break:Nn} mechanism. |
| 1701 |
% \begin{macrocode} |
| 1702 |
\cs_new:Npn \keyval_map_break: { \prg_map_break:Nn \keyval_map_break: { } } |
| 1703 |
\cs_new:Npn \keyval_map_break:n { \prg_map_break:Nn \keyval_map_break: } |
| 1704 |
% \end{macrocode} |
| 1705 |
% \end{macro} |
| 1706 |
% |
| 1707 |
% \subsection{Constants and variables} |
| 1708 |
% |
| 1709 |
% \begin{macrocode} |
| 1710 |
%<@@=keys> |
| 1711 |
% \end{macrocode} |
| 1712 |
% |
| 1713 |
% \begin{variable} |
| 1714 |
% { |
| 1715 |
% \c_@@_code_root_str , |
| 1716 |
% \c_@@_check_root_str , |
| 1717 |
% \c_@@_default_root_str , |
| 1718 |
% \c_@@_groups_root_str , |
| 1719 |
% \c_@@_inherit_root_str , |
| 1720 |
% \c_@@_type_root_str |
| 1721 |
% } |
| 1722 |
% Various storage areas for the different data which make up keys. |
| 1723 |
% \begin{macrocode} |
| 1724 |
\str_const:Nn \c_@@_code_root_str { key~code~>~ } |
| 1725 |
\str_const:Nn \c_@@_check_root_str { key~check~>~ } |
| 1726 |
\str_const:Nn \c_@@_default_root_str { key~default~>~ } |
| 1727 |
\str_const:Nn \c_@@_groups_root_str { key~groups~>~ } |
| 1728 |
\str_const:Nn \c_@@_inherit_root_str { key~inherit~>~ } |
| 1729 |
\str_const:Nn \c_@@_type_root_str { key~type~>~ } |
| 1730 |
% \end{macrocode} |
| 1731 |
% \end{variable} |
| 1732 |
% |
| 1733 |
% \begin{variable}{\c_@@_props_root_str} |
| 1734 |
% The prefix for storing properties. |
| 1735 |
% \begin{macrocode} |
| 1736 |
\str_const:Nn \c_@@_props_root_str { key~prop~>~ } |
| 1737 |
% \end{macrocode} |
| 1738 |
% \end{variable} |
| 1739 |
% |
| 1740 |
% \begin{variable}{\l_keys_choice_int, \l_keys_choice_str} |
| 1741 |
% Publicly accessible data on which choice is being used when several |
| 1742 |
% are generated as a set. |
| 1743 |
% \begin{macrocode} |
| 1744 |
\int_new:N \l_keys_choice_int |
| 1745 |
\str_new:N \l_keys_choice_str |
| 1746 |
% \end{macrocode} |
| 1747 |
% \end{variable} |
| 1748 |
% \begin{variable}[deprecated]{\l_keys_choice_tl} |
| 1749 |
% The |tl| version is deprecated but has to be handled manually. |
| 1750 |
% \begin{macrocode} |
| 1751 |
\tl_new:N \l_keys_choice_tl |
| 1752 |
% \end{macrocode} |
| 1753 |
% \end{variable} |
| 1754 |
% |
| 1755 |
% \begin{variable}{\l_@@_exp_str} |
| 1756 |
% The expansion postfix of a key name. |
| 1757 |
% \begin{macrocode} |
| 1758 |
\str_new:N \l_@@_exp_str |
| 1759 |
% \end{macrocode} |
| 1760 |
% \end{variable} |
| 1761 |
% |
| 1762 |
% \begin{variable}{\l_@@_groups_clist} |
| 1763 |
% Used for storing and recovering the list of groups which apply to a key: |
| 1764 |
% set as a comma list but at one point we have to use this for a token |
| 1765 |
% list recovery. |
| 1766 |
% \begin{macrocode} |
| 1767 |
\clist_new:N \l_@@_groups_clist |
| 1768 |
% \end{macrocode} |
| 1769 |
% \end{variable} |
| 1770 |
% |
| 1771 |
% \begin{variable}{\l_@@_inherit_bool} |
| 1772 |
% For inheritance, particularly for recursion. |
| 1773 |
% \begin{macrocode} |
| 1774 |
\bool_new:N \l_@@_inherit_bool |
| 1775 |
% \end{macrocode} |
| 1776 |
% \end{variable} |
| 1777 |
% |
| 1778 |
% \begin{variable}{\l_@@_inherit_clist} |
| 1779 |
% For normalization. |
| 1780 |
% \begin{macrocode} |
| 1781 |
\clist_new:N \l_@@_inherit_clist |
| 1782 |
% \end{macrocode} |
| 1783 |
% \end{variable} |
| 1784 |
% |
| 1785 |
% \begin{variable}{\l_keys_key_str} |
| 1786 |
% The name of a key itself: needed when setting keys. |
| 1787 |
% \begin{macrocode} |
| 1788 |
\str_new:N \l_keys_key_str |
| 1789 |
% \end{macrocode} |
| 1790 |
% \end{variable} |
| 1791 |
% |
| 1792 |
% \begin{variable}[deprecated]{\l_keys_key_tl} |
| 1793 |
% The |tl| version is deprecated but has to be handled manually. |
| 1794 |
% \begin{macrocode} |
| 1795 |
\tl_new:N \l_keys_key_tl |
| 1796 |
% \end{macrocode} |
| 1797 |
% \end{variable} |
| 1798 |
% |
| 1799 |
% \begin{variable}{\l_@@_module_str} |
| 1800 |
% The module for an entire set of keys. |
| 1801 |
% \begin{macrocode} |
| 1802 |
\str_new:N \l_@@_module_str |
| 1803 |
% \end{macrocode} |
| 1804 |
% \end{variable} |
| 1805 |
% |
| 1806 |
% \begin{variable}{\l_@@_no_value_bool} |
| 1807 |
% A marker is needed internally to show if only a key or a key plus a |
| 1808 |
% value was seen: this is recorded here. |
| 1809 |
% \begin{macrocode} |
| 1810 |
\bool_new:N \l_@@_no_value_bool |
| 1811 |
% \end{macrocode} |
| 1812 |
% \end{variable} |
| 1813 |
% |
| 1814 |
% \begin{variable}{\l_@@_only_known_bool} |
| 1815 |
% Used to track if only \enquote{known} keys are being set. |
| 1816 |
% \begin{macrocode} |
| 1817 |
\bool_new:N \l_@@_only_known_bool |
| 1818 |
% \end{macrocode} |
| 1819 |
% \end{variable} |
| 1820 |
% |
| 1821 |
% \begin{variable}{\l_keys_path_str} |
| 1822 |
% The \enquote{path} of the current key is stored here: this is |
| 1823 |
% available to the programmer and so is public. |
| 1824 |
% \begin{macrocode} |
| 1825 |
\str_new:N \l_keys_path_str |
| 1826 |
% \end{macrocode} |
| 1827 |
% \end{variable} |
| 1828 |
% |
| 1829 |
% \begin{variable}[deprecated]{\l_keys_path_tl} |
| 1830 |
% The older version is deprecated but has to be handled manually. |
| 1831 |
% \begin{macrocode} |
| 1832 |
\tl_new:N \l_keys_path_tl |
| 1833 |
% \end{macrocode} |
| 1834 |
% \end{variable} |
| 1835 |
% |
| 1836 |
% \begin{variable}{\l_@@_inherit_str} |
| 1837 |
% \begin{macrocode} |
| 1838 |
\str_new:N \l_@@_inherit_str |
| 1839 |
% \end{macrocode} |
| 1840 |
% \end{variable} |
| 1841 |
% |
| 1842 |
% \begin{variable}{\l_@@_relative_tl} |
| 1843 |
% The relative path for passing keys back to the user. As this can |
| 1844 |
% be explicitly no-value, it must be a token list. |
| 1845 |
% \begin{macrocode} |
| 1846 |
\tl_new:N \l_@@_relative_tl |
| 1847 |
\tl_set:Nn \l_@@_relative_tl { \q_@@_no_value } |
| 1848 |
% \end{macrocode} |
| 1849 |
% \end{variable} |
| 1850 |
% |
| 1851 |
% \begin{variable}{\l_@@_property_str} |
| 1852 |
% The \enquote{property} begin set for a key at definition time is |
| 1853 |
% stored here. |
| 1854 |
% \begin{macrocode} |
| 1855 |
\str_new:N \l_@@_property_str |
| 1856 |
% \end{macrocode} |
| 1857 |
% \end{variable} |
| 1858 |
% |
| 1859 |
% \begin{variable}{\l_@@_selective_bool, \l_@@_exclude_bool} |
| 1860 |
% Two booleans for using key groups: one to indicate that \enquote{selective} |
| 1861 |
% setting is active, a second to specify which type (\enquote{opt-in} |
| 1862 |
% or \enquote{opt-out}). |
| 1863 |
% \begin{macrocode} |
| 1864 |
\bool_new:N \l_@@_selective_bool |
| 1865 |
\bool_new:N \l_@@_exclude_bool |
| 1866 |
% \end{macrocode} |
| 1867 |
% \end{variable} |
| 1868 |
% |
| 1869 |
% \begin{variable}{\l_@@_selective_clist} |
| 1870 |
% The list of key groups being filtered in or out during selective setting. |
| 1871 |
% \begin{macrocode} |
| 1872 |
\clist_new:N \l_@@_selective_clist |
| 1873 |
% \end{macrocode} |
| 1874 |
% \end{variable} |
| 1875 |
% |
| 1876 |
% \begin{variable}{\l_@@_tmp_clist} |
| 1877 |
% Scratch space used as a data dump. |
| 1878 |
% \begin{macrocode} |
| 1879 |
\clist_new:N \l_@@_tmp_clist |
| 1880 |
% \end{macrocode} |
| 1881 |
% \end{variable} |
| 1882 |
% |
| 1883 |
% \begin{variable}{\l_@@_unused_clist} |
| 1884 |
% Used when setting only some keys to store those left over. |
| 1885 |
% \begin{macrocode} |
| 1886 |
\clist_new:N \l_@@_unused_clist |
| 1887 |
% \end{macrocode} |
| 1888 |
% \end{variable} |
| 1889 |
% |
| 1890 |
% \begin{variable}{\l_keys_value_tl} |
| 1891 |
% The value given for a key: may be empty if no value was given. |
| 1892 |
% \begin{macrocode} |
| 1893 |
\tl_new:N \l_keys_value_tl |
| 1894 |
% \end{macrocode} |
| 1895 |
% \end{variable} |
| 1896 |
% |
| 1897 |
% \begin{variable}{\l_@@_tmp_bool, \l_@@_tmpa_tl, \l_@@_tmpb_tl} |
| 1898 |
% Scratch space. |
| 1899 |
% \begin{macrocode} |
| 1900 |
\bool_new:N \l_@@_tmp_bool |
| 1901 |
\tl_new:N \l_@@_tmpa_tl |
| 1902 |
\tl_new:N \l_@@_tmpb_tl |
| 1903 |
% \end{macrocode} |
| 1904 |
% \end{variable} |
| 1905 |
% |
| 1906 |
% \begin{variable}{\l_@@_precompile_bool, \l_@@_precompile_tl} |
| 1907 |
% For digesting keys. |
| 1908 |
% \begin{macrocode} |
| 1909 |
\bool_new:N \l_@@_precompile_bool |
| 1910 |
\tl_new:N \l_@@_precompile_tl |
| 1911 |
% \end{macrocode} |
| 1912 |
% \end{variable} |
| 1913 |
% |
| 1914 |
% \begin{variable}{\l_keys_usage_load_prop, \l_keys_usage_preamble_prop} |
| 1915 |
% Global data for document-level information. |
| 1916 |
% \begin{macrocode} |
| 1917 |
\prop_new:N \l_keys_usage_load_prop |
| 1918 |
\prop_new:N \l_keys_usage_preamble_prop |
| 1919 |
% \end{macrocode} |
| 1920 |
% \end{variable} |
| 1921 |
% |
| 1922 |
% \subsubsection{Internal auxiliaries} |
| 1923 |
% |
| 1924 |
% \begin{variable}{\s_@@_nil,\s_@@_mark,\s_@@_stop} |
| 1925 |
% Internal scan marks. |
| 1926 |
% \begin{macrocode} |
| 1927 |
\scan_new:N \s_@@_nil |
| 1928 |
\scan_new:N \s_@@_mark |
| 1929 |
\scan_new:N \s_@@_stop |
| 1930 |
% \end{macrocode} |
| 1931 |
% \end{variable} |
| 1932 |
% |
| 1933 |
% \begin{variable}{\q_@@_no_value} |
| 1934 |
% Internal quarks. |
| 1935 |
% \begin{macrocode} |
| 1936 |
\quark_new:N \q_@@_no_value |
| 1937 |
% \end{macrocode} |
| 1938 |
% \end{variable} |
| 1939 |
% |
| 1940 |
% \begin{macro}[pTF]{\@@_quark_if_no_value:N} |
| 1941 |
% Branching quark conditional. |
| 1942 |
% \begin{macrocode} |
| 1943 |
\__kernel_quark_new_conditional:Nn \@@_quark_if_no_value:N { TF } |
| 1944 |
% \end{macrocode} |
| 1945 |
% \end{macro} |
| 1946 |
% |
| 1947 |
% \begin{macro}{\@@_precompile:n} |
| 1948 |
% An auxiliary to allow cleaner showing of code. |
| 1949 |
% \begin{macrocode} |
| 1950 |
\cs_new_protected:Npn \@@_precompile:n #1 |
| 1951 |
{ |
| 1952 |
\bool_if:NTF \l_@@_precompile_bool |
| 1953 |
{ \tl_put_right:Nn \l_@@_precompile_tl } |
| 1954 |
{ \use:n } |
| 1955 |
{#1} |
| 1956 |
} |
| 1957 |
% \end{macrocode} |
| 1958 |
% \end{macro} |
| 1959 |
% |
| 1960 |
% \begin{macro}{\@@_cs_undefine:c} |
| 1961 |
% Local version of \cs{cs_undefine:c} to avoid sprinkling |
| 1962 |
% \cs{tex_undefined:D} everywhere. |
| 1963 |
% \begin{macrocode} |
| 1964 |
\cs_new_protected:Npn \@@_cs_undefine:c #1 |
| 1965 |
{ |
| 1966 |
\if_cs_exist:w #1 \cs_end: |
| 1967 |
\else: |
| 1968 |
\use_i:nnnn |
| 1969 |
\fi: |
| 1970 |
\cs_set_eq:cN {#1} \tex_undefined:D |
| 1971 |
} |
| 1972 |
% \end{macrocode} |
| 1973 |
% \end{macro} |
| 1974 |
% |
| 1975 |
% \subsection{The key defining mechanism} |
| 1976 |
% |
| 1977 |
% \begin{macro}{\keys_define:nn, \keys_define:ne, \keys_define:nx} |
| 1978 |
% The public function for definitions is just a wrapper for the lower |
| 1979 |
% level mechanism, more or less. The outer function is designed to |
| 1980 |
% keep a track of the current module, to allow safe nesting. The module is set |
| 1981 |
% removing any leading |/| (which is not needed here). |
| 1982 |
% \begin{macrocode} |
| 1983 |
\cs_new_protected:Npn \keys_define:nn #1#2 |
| 1984 |
{ |
| 1985 |
\use:e |
| 1986 |
{ |
| 1987 |
\exp_not:n |
| 1988 |
{ |
| 1989 |
\str_set:Ne \l_@@_module_str { \@@_trim_spaces:n {#1} } |
| 1990 |
\keyval_parse:NNn \@@_define:n \@@_define:nn {#2} |
| 1991 |
} |
| 1992 |
\@@_reset_var:N \l_@@_module_str |
| 1993 |
\@@_reset_var:N \l_@@_inherit_str |
| 1994 |
\@@_reset_var:N \l_keys_choice_tl |
| 1995 |
\@@_reset_var:N \l_keys_choice_str |
| 1996 |
\@@_reset_var:N \l_keys_key_tl |
| 1997 |
\@@_reset_var:N \l_keys_key_str |
| 1998 |
\@@_reset_var:N \l_keys_path_tl |
| 1999 |
\@@_reset_var:N \l_keys_path_str |
| 2000 |
\@@_reset_var:N \l_keys_value_tl |
| 2001 |
\int_set:Nn \l_keys_choice_int { \int_use:N \l_keys_choice_int } |
| 2002 |
} |
| 2003 |
} |
| 2004 |
\cs_generate_variant:Nn \keys_define:nn { ne , nx } |
| 2005 |
% \end{macrocode} |
| 2006 |
% \end{macro} |
| 2007 |
% |
| 2008 |
% \begin{macro}{\@@_define:n} |
| 2009 |
% \begin{macro}{\@@_define:nn} |
| 2010 |
% \begin{macro}{\@@_define_aux:nn} |
| 2011 |
% The outer functions here record whether a value was given and then |
| 2012 |
% converge on a common internal mechanism. There is first a search for |
| 2013 |
% a property in the current key name, then a check to make sure it is |
| 2014 |
% known before the code hands off to the next step. |
| 2015 |
% \begin{macrocode} |
| 2016 |
\cs_new_protected:Npn \@@_define:n #1 |
| 2017 |
{ |
| 2018 |
\bool_set_true:N \l_@@_no_value_bool |
| 2019 |
\@@_define_aux:nn {#1} { } |
| 2020 |
} |
| 2021 |
\cs_new_protected:Npn \@@_define:nn #1#2 |
| 2022 |
{ |
| 2023 |
\bool_set_false:N \l_@@_no_value_bool |
| 2024 |
\@@_define_aux:nn {#1} {#2} |
| 2025 |
} |
| 2026 |
\cs_new_protected:Npn \@@_define_aux:nn #1#2 |
| 2027 |
{ |
| 2028 |
\@@_property_find:n {#1} |
| 2029 |
\cs_if_exist:cTF { \c_@@_props_root_str \l_@@_property_str } |
| 2030 |
{ \@@_define_code:n {#2} } |
| 2031 |
{ |
| 2032 |
\str_if_empty:NF \l_@@_property_str |
| 2033 |
{ |
| 2034 |
\msg_error:nnee { keys } { property-unknown } |
| 2035 |
\l_@@_property_str \l_keys_path_str |
| 2036 |
} |
| 2037 |
} |
| 2038 |
} |
| 2039 |
% \end{macrocode} |
| 2040 |
% \end{macro} |
| 2041 |
% \end{macro} |
| 2042 |
% \end{macro} |
| 2043 |
% |
| 2044 |
% \begin{macro}{\@@_property_find:n} |
| 2045 |
% \begin{macro}[EXP]{\@@_property_find_auxi:w} |
| 2046 |
% \begin{macro}{\@@_property_find_auxii:w} |
| 2047 |
% \begin{macro}[EXP] |
| 2048 |
% { |
| 2049 |
% \@@_property_find_auxiii:w , |
| 2050 |
% \@@_property_find_auxiv:w |
| 2051 |
% } |
| 2052 |
% \begin{macro}{\@@_property_find_err:w} |
| 2053 |
% Searching for a property means finding the last |.| in the input, |
| 2054 |
% and storing the text before and after it. Everything is first turned into |
| 2055 |
% strings, so there is no problem using \cs{cs_set_nopar:Npe} instead of |
| 2056 |
% \cs{str_set:Ne} to set \cs{l_keys_path_str}. To gain further speed, brace |
| 2057 |
% tricks are used and \cs{@@_property_find_auxiv:w} is defined as expandable. |
| 2058 |
% Since spaces will already be trimmed from the module we can omit it from the |
| 2059 |
% argument to \cs{@@_trim_spaces:n}. |
| 2060 |
% \begin{macrocode} |
| 2061 |
\cs_new_protected:Npn \@@_property_find:n #1 |
| 2062 |
{ |
| 2063 |
\exp_after:wN \@@_property_find_auxi:w \tl_to_str:n {#1} |
| 2064 |
\s_@@_nil \@@_property_find_auxii:w |
| 2065 |
. \s_@@_nil \@@_property_find_err:w |
| 2066 |
} |
| 2067 |
\cs_new:Npn \@@_property_find_auxi:w #1 . #2 \s_@@_nil #3 |
| 2068 |
{ |
| 2069 |
#3 #1 \s_@@_mark #2 \s_@@_nil #3 |
| 2070 |
} |
| 2071 |
\cs_new_protected:Npn \@@_property_find_auxii:w |
| 2072 |
#1 \s_@@_mark #2 \s_@@_nil \@@_property_find_auxii:w . \s_@@_nil |
| 2073 |
\@@_property_find_err:w |
| 2074 |
{ |
| 2075 |
\cs_set_nopar:Npe \l_keys_path_str |
| 2076 |
{ |
| 2077 |
\str_if_empty:NF \l_@@_module_str { \l_@@_module_str / } |
| 2078 |
\exp_after:wN \@@_trim_spaces:n \tex_expanded:D {{ |
| 2079 |
#1 |
| 2080 |
\if_false: }}} \fi: |
| 2081 |
\@@_property_find_auxi:w #2 \s_@@_nil \@@_property_find_auxiii:w |
| 2082 |
. \s_@@_nil \@@_property_find_auxiv:w |
| 2083 |
} |
| 2084 |
\cs_new:Npn \@@_property_find_auxiii:w #1 \s_@@_mark #2 . #3 \s_@@_nil #4 |
| 2085 |
{ |
| 2086 |
. #1 #4 #2 \s_@@_mark #3 \s_@@_nil #4 |
| 2087 |
} |
| 2088 |
\cs_new:Npn \@@_property_find_auxiv:w |
| 2089 |
#1 \s_@@_nil \@@_property_find_auxiii:w |
| 2090 |
\s_@@_mark \s_@@_nil \@@_property_find_auxiv:w |
| 2091 |
{ |
| 2092 |
\if_false: {{{ \fi: }}} |
| 2093 |
\cs_set_nopar:Npe \l_@@_property_str { . #1 } |
| 2094 |
\tl_set_eq:NN \l_keys_path_tl \l_keys_path_str |
| 2095 |
} |
| 2096 |
\cs_new_protected:Npn \@@_property_find_err:w |
| 2097 |
#1 \s_@@_nil #2 \@@_property_find_err:w |
| 2098 |
{ |
| 2099 |
\str_clear:N \l_@@_property_str |
| 2100 |
\msg_error:nnn { keys } { no-property } {#1} |
| 2101 |
} |
| 2102 |
% \end{macrocode} |
| 2103 |
% \end{macro} |
| 2104 |
% \end{macro} |
| 2105 |
% \end{macro} |
| 2106 |
% \end{macro} |
| 2107 |
% \end{macro} |
| 2108 |
% |
| 2109 |
% \begin{macro}{\@@_define_code:n} |
| 2110 |
% \begin{macro}[EXP]{\@@_define_code:nnn} |
| 2111 |
% \begin{macro}[EXP]{\@@_define_code:w} |
| 2112 |
% Two possible cases. If there is a value for the key, then just use |
| 2113 |
% the function. If not, then a check to make sure there is no need for |
| 2114 |
% a value with the property. If there should be one then complain, |
| 2115 |
% otherwise execute it. For a \LaTeXe{} property like |.code| which |
| 2116 |
% doesn't contain a |:|, treat it as having arity 1 and pass the |
| 2117 |
% (empty) value to it. |
| 2118 |
% \begin{macrocode} |
| 2119 |
\cs_new_protected:Npn \@@_define_code:n #1 |
| 2120 |
{ |
| 2121 |
\bool_if:NTF \l_@@_no_value_bool |
| 2122 |
{ |
| 2123 |
\@@_define_code:nnn |
| 2124 |
{ \use:c { \c_@@_props_root_str \l_@@_property_str } {#1} } |
| 2125 |
{ \use:c { \c_@@_props_root_str \l_@@_property_str } } |
| 2126 |
{ |
| 2127 |
\msg_error:nnee { keys } { property-requires-value } |
| 2128 |
\l_@@_property_str \l_keys_path_str |
| 2129 |
} |
| 2130 |
} |
| 2131 |
{ \use:c { \c_@@_props_root_str \l_@@_property_str } {#1} } |
| 2132 |
} |
| 2133 |
\cs_new:Npe \@@_define_code:nnn |
| 2134 |
{ |
| 2135 |
\exp_not:N \exp_after:wN \exp_not:N \@@_define_code:w |
| 2136 |
\exp_not:N \l_@@_property_str |
| 2137 |
\c_colon_str \c_colon_str |
| 2138 |
\exp_not:N \s_@@_stop |
| 2139 |
} |
| 2140 |
\use:e |
| 2141 |
{ |
| 2142 |
\cs_new:Npn \exp_not:N \@@_define_code:w |
| 2143 |
#1 \c_colon_str #2 \c_colon_str #3 \exp_not:N \s_@@_stop |
| 2144 |
} |
| 2145 |
{ |
| 2146 |
\tl_if_empty:nTF {#3} |
| 2147 |
{ \use_i:nnn } |
| 2148 |
{ |
| 2149 |
\tl_if_empty:nTF {#2} |
| 2150 |
{ \use_ii:nnn } |
| 2151 |
{ \use_iii:nnn } |
| 2152 |
} |
| 2153 |
} |
| 2154 |
% \end{macrocode} |
| 2155 |
% \end{macro} |
| 2156 |
% \end{macro} |
| 2157 |
% \end{macro} |
| 2158 |
% |
| 2159 |
% \subsection{Turning properties into actions} |
| 2160 |
% |
| 2161 |
% \begin{macro} |
| 2162 |
% { |
| 2163 |
% \@@_bool_set:Nn, \@@_bool_set:cn, |
| 2164 |
% \@@_bool_set_inverse:Nn, \@@_bool_set_inverse:cn |
| 2165 |
% } |
| 2166 |
% \begin{macro}{\@@_bool_set:Nnnn} |
| 2167 |
% Boolean keys are really just choices, but all done by hand. The |
| 2168 |
% second argument here is the scope: either empty or \texttt{ g } for |
| 2169 |
% global. |
| 2170 |
% \begin{macrocode} |
| 2171 |
\cs_new_protected:Npn \@@_bool_set:Nn #1#2 |
| 2172 |
{ \@@_bool_set:Nnnn #1 {#2} { true } { false } } |
| 2173 |
\cs_generate_variant:Nn \@@_bool_set:Nn { c } |
| 2174 |
\cs_new_protected:Npn \@@_bool_set_inverse:Nn #1#2 |
| 2175 |
{ \@@_bool_set:Nnnn #1 {#2} { false } { true } } |
| 2176 |
\cs_generate_variant:Nn \@@_bool_set_inverse:Nn { c } |
| 2177 |
\cs_new_protected:Npn \@@_bool_set:Nnnn #1#2#3#4 |
| 2178 |
{ |
| 2179 |
\bool_if_exist:NF #1 { \bool_new:N #1 } |
| 2180 |
\@@_choice_make: |
| 2181 |
\@@_cmd_set:ne { \l_keys_path_str / true } |
| 2182 |
{ \exp_not:c { bool_ #2 set_ #3 :N } \exp_not:N #1 } |
| 2183 |
\@@_cmd_set:ne { \l_keys_path_str / false } |
| 2184 |
{ \exp_not:c { bool_ #2 set_ #4 :N } \exp_not:N #1 } |
| 2185 |
\@@_cmd_set_direct:nn { \l_keys_path_str / unknown } |
| 2186 |
{ |
| 2187 |
\msg_error:nne { keys } { boolean-values-only } |
| 2188 |
\l_keys_path_str |
| 2189 |
} |
| 2190 |
\@@_default_set:n { true } |
| 2191 |
} |
| 2192 |
\cs_generate_variant:Nn \@@_bool_set:Nn { c } |
| 2193 |
% \end{macrocode} |
| 2194 |
% \end{macro} |
| 2195 |
% \end{macro} |
| 2196 |
% |
| 2197 |
% \begin{macro}{\@@_choice_make:, \@@_multichoice_make:} |
| 2198 |
% \begin{macro}{\@@_choice_make:N} |
| 2199 |
% \begin{macro}{\@@_choice_make_aux:N} |
| 2200 |
% To make a choice from a key, two steps: set the code, and set the |
| 2201 |
% unknown key. As multichoices and choices are essentially the same bar one |
| 2202 |
% function, the code is given together. |
| 2203 |
% \begin{macrocode} |
| 2204 |
\cs_new_protected:Npn \@@_choice_make: |
| 2205 |
{ \@@_choice_make:N \@@_choice_find:n } |
| 2206 |
\cs_new_protected:Npn \@@_multichoice_make: |
| 2207 |
{ \@@_choice_make:N \@@_multichoice_find:n } |
| 2208 |
\cs_new_protected:Npn \@@_choice_make:N #1 |
| 2209 |
{ |
| 2210 |
\cs_if_exist:cTF |
| 2211 |
{ \c_@@_type_root_str \@@_parent:o \l_keys_path_str } |
| 2212 |
{ |
| 2213 |
\str_if_eq:vnTF |
| 2214 |
{ \c_@@_type_root_str \@@_parent:o \l_keys_path_str } |
| 2215 |
{ choice } |
| 2216 |
{ |
| 2217 |
\msg_error:nnee { keys } { nested-choice-key } |
| 2218 |
\l_keys_path_tl { \@@_parent:o \l_keys_path_str } |
| 2219 |
} |
| 2220 |
{ \@@_choice_make_aux:N #1 } |
| 2221 |
} |
| 2222 |
{ \@@_choice_make_aux:N #1 } |
| 2223 |
} |
| 2224 |
\cs_new_protected:Npn \@@_choice_make_aux:N #1 |
| 2225 |
{ |
| 2226 |
\cs_set_nopar:cpn { \c_@@_type_root_str \l_keys_path_str } |
| 2227 |
{ choice } |
| 2228 |
\@@_cmd_set_direct:nn \l_keys_path_str { #1 {##1} } |
| 2229 |
\@@_cmd_set_direct:nn { \l_keys_path_str / unknown } |
| 2230 |
{ |
| 2231 |
\msg_error:nnee { keys } { choice-unknown } |
| 2232 |
\l_keys_path_str {##1} |
| 2233 |
} |
| 2234 |
} |
| 2235 |
% \end{macrocode} |
| 2236 |
% \end{macro} |
| 2237 |
% \end{macro} |
| 2238 |
% \end{macro} |
| 2239 |
% |
| 2240 |
% \begin{macro}{\@@_choices_make:nn, \@@_multichoices_make:nn} |
| 2241 |
% \begin{macro}{\@@_choices_make:Nnn} |
| 2242 |
% Auto-generating choices means setting up the root key as a choice, then |
| 2243 |
% defining each choice in turn. |
| 2244 |
% \begin{macrocode} |
| 2245 |
\cs_new_protected:Npn \@@_choices_make:nn |
| 2246 |
{ \@@_choices_make:Nnn \@@_choice_make: } |
| 2247 |
\cs_new_protected:Npn \@@_multichoices_make:nn |
| 2248 |
{ \@@_choices_make:Nnn \@@_multichoice_make: } |
| 2249 |
\cs_new_protected:Npn \@@_choices_make:Nnn #1#2#3 |
| 2250 |
{ |
| 2251 |
#1 |
| 2252 |
\int_zero:N \l_keys_choice_int |
| 2253 |
\clist_map_inline:nn {#2} |
| 2254 |
{ |
| 2255 |
\int_incr:N \l_keys_choice_int |
| 2256 |
\@@_cmd_set:ne |
| 2257 |
{ \l_keys_path_str / \@@_trim_spaces:n {##1} } |
| 2258 |
{ |
| 2259 |
\str_set:Nn \exp_not:N \l_keys_choice_str {##1} |
| 2260 |
\tl_set:Nn \exp_not:N \l_keys_choice_tl {##1} |
| 2261 |
\int_set:Nn \exp_not:N \l_keys_choice_int |
| 2262 |
{ \int_use:N \l_keys_choice_int } |
| 2263 |
\exp_not:n {#3} |
| 2264 |
} |
| 2265 |
} |
| 2266 |
} |
| 2267 |
% \end{macrocode} |
| 2268 |
% \end{macro} |
| 2269 |
% \end{macro} |
| 2270 |
% |
| 2271 |
% \begin{macro} |
| 2272 |
% { |
| 2273 |
% \@@_cmd_set:nn, \@@_cmd_set:Vn, \@@_cmd_set:ne, \@@_cmd_set:Vo, |
| 2274 |
% \@@_cmd_set_direct:nn |
| 2275 |
% } |
| 2276 |
% Setting the code for a key first logs if appropriate that we are |
| 2277 |
% defining a new key, then saves the code. |
| 2278 |
% \begin{macrocode} |
| 2279 |
\cs_new_protected:Npn \@@_cmd_set:nn #1#2 |
| 2280 |
{ \@@_cmd_set_direct:nn {#1} { \@@_precompile:n {#2} } } |
| 2281 |
\cs_generate_variant:Nn \@@_cmd_set:nn { ne , Vn , Vo } |
| 2282 |
\cs_new_protected:Npn \@@_cmd_set_direct:nn #1#2 |
| 2283 |
{ \cs_set_protected:cpn { \c_@@_code_root_str #1 } ##1 {#2} } |
| 2284 |
% \end{macrocode} |
| 2285 |
% \end{macro} |
| 2286 |
% |
| 2287 |
% \begin{macro}{\@@_cs_set:NNpn, \@@_cs_set:Ncpn} |
| 2288 |
% Creating control sequences is a bit more tricky than other cases as |
| 2289 |
% we need to pick up the |p| argument. To make the internals look clearer, |
| 2290 |
% the trailing |n| argument here is just for appearance. |
| 2291 |
% \begin{macrocode} |
| 2292 |
\cs_new_protected:Npn \@@_cs_set:NNpn #1#2#3# |
| 2293 |
{ |
| 2294 |
\cs_set_protected:cpe { \c_@@_code_root_str \l_keys_path_str } ##1 |
| 2295 |
{ |
| 2296 |
\@@_precompile:n |
| 2297 |
{ #1 \exp_not:N #2 \exp_not:n {#3} {##1} } |
| 2298 |
} |
| 2299 |
\use_none:n |
| 2300 |
} |
| 2301 |
\cs_generate_variant:Nn \@@_cs_set:NNpn { Nc } |
| 2302 |
% \end{macrocode} |
| 2303 |
% \end{macro} |
| 2304 |
% |
| 2305 |
% \begin{macro}{\@@_default_set:n} |
| 2306 |
% Setting a default value is easy. These are stored using \cs{cs_set_nopar:cpe} as this |
| 2307 |
% avoids any worries about whether a token list exists. |
| 2308 |
% \begin{macrocode} |
| 2309 |
\cs_new_protected:Npn \@@_default_set:n #1 |
| 2310 |
{ |
| 2311 |
\tl_if_empty:nTF {#1} |
| 2312 |
{ |
| 2313 |
\@@_cs_undefine:c |
| 2314 |
{ \c_@@_default_root_str \l_keys_path_str } |
| 2315 |
} |
| 2316 |
{ |
| 2317 |
\cs_set_nopar:cpe |
| 2318 |
{ \c_@@_default_root_str \l_keys_path_str } |
| 2319 |
{ \exp_not:n {#1} } |
| 2320 |
\@@_value_requirement:nn { required } { false } |
| 2321 |
} |
| 2322 |
} |
| 2323 |
% \end{macrocode} |
| 2324 |
% \end{macro} |
| 2325 |
% |
| 2326 |
% \begin{macro}{\@@_groups_set:n} |
| 2327 |
% Assigning a key to one or more groups uses comma lists. As the list of |
| 2328 |
% groups only exists if there is anything to do, the setting is done using |
| 2329 |
% a scratch list. For the usual grouping reasons we use the low-level |
| 2330 |
% approach to undefining a list. We also use the low-level approach for |
| 2331 |
% the other case to avoid tripping up the |check-declarations| code. |
| 2332 |
% \begin{macrocode} |
| 2333 |
\cs_new_protected:Npn \@@_groups_set:n #1 |
| 2334 |
{ |
| 2335 |
\clist_set:Ne \l_@@_groups_clist { \tl_to_str:n {#1} } |
| 2336 |
\clist_if_empty:NTF \l_@@_groups_clist |
| 2337 |
{ |
| 2338 |
\@@_cs_undefine:c |
| 2339 |
{ \c_@@_groups_root_str \l_keys_path_str } |
| 2340 |
} |
| 2341 |
{ |
| 2342 |
\cs_set_eq:cN { \c_@@_groups_root_str \l_keys_path_str } |
| 2343 |
\l_@@_groups_clist |
| 2344 |
} |
| 2345 |
} |
| 2346 |
% \end{macrocode} |
| 2347 |
% \end{macro} |
| 2348 |
% |
| 2349 |
% \begin{macro}{\@@_inherit:n} |
| 2350 |
% Inheritance means ignoring anything already said about the key: |
| 2351 |
% zap the lot and set up. |
| 2352 |
% \begin{macrocode} |
| 2353 |
\cs_new_protected:Npn \@@_inherit:n #1 |
| 2354 |
{ |
| 2355 |
\@@_undefine: |
| 2356 |
\clist_set:Nn \l_@@_inherit_clist {#1} |
| 2357 |
\cs_set_eq:cN { \c_@@_inherit_root_str \l_keys_path_str } |
| 2358 |
\l_@@_inherit_clist |
| 2359 |
} |
| 2360 |
% \end{macrocode} |
| 2361 |
% \end{macro} |
| 2362 |
% |
| 2363 |
% \begin{macro}{\@@_initialize:n} |
| 2364 |
% A set up for initialization: just run the code if it exists. |
| 2365 |
% We need to set the key string here, using the deprecated \texttt{tl~var} |
| 2366 |
% as a piece of scratch space. We need to test \emph{first} for the key in |
| 2367 |
% the current tree then any inheritance. |
| 2368 |
% \begin{macrocode} |
| 2369 |
\cs_new_protected:Npn \@@_initialize:n #1 |
| 2370 |
{ |
| 2371 |
\exp_after:wN \@@_find_key_module:wNN |
| 2372 |
\l_keys_path_str \s_@@_stop |
| 2373 |
\l_keys_key_tl \l_keys_key_str |
| 2374 |
\tl_set_eq:NN \l_keys_key_tl \l_keys_key_str |
| 2375 |
\tl_set:Nn \l_keys_value_tl {#1} |
| 2376 |
\cs_if_exist:cTF { \c_@@_code_root_str \l_keys_path_str } |
| 2377 |
{ |
| 2378 |
\str_clear:N \l_@@_inherit_str |
| 2379 |
\@@_execute:nn \l_keys_path_str {#1} |
| 2380 |
} |
| 2381 |
{ |
| 2382 |
\cs_if_exist:cT |
| 2383 |
{ \c_@@_inherit_root_str \@@_parent:o \l_keys_path_str } |
| 2384 |
{ \@@_execute_inherit: } |
| 2385 |
} |
| 2386 |
} |
| 2387 |
% \end{macrocode} |
| 2388 |
% \end{macro} |
| 2389 |
% |
| 2390 |
% \begin{macro}{\@@_legacy_if_set:nn, \@@_legacy_if_inverse:nn} |
| 2391 |
% \begin{macro}{\@@_legacy_if_inverse:nnnn} |
| 2392 |
% Much the same as \pkg{expl3} booleans, except we assume that the switch |
| 2393 |
% exists. |
| 2394 |
% \begin{macrocode} |
| 2395 |
\cs_new_protected:Npn \@@_legacy_if_set:nn #1#2 |
| 2396 |
{ \@@_legacy_if_set:nnnn {#1} {#2} { true } { false } } |
| 2397 |
\cs_new_protected:Npn \@@_legacy_if_set_inverse:nn #1#2 |
| 2398 |
{ \@@_legacy_if_set:nnnn {#1} {#2} { false } { true } } |
| 2399 |
\cs_new_protected:Npn \@@_legacy_if_set:nnnn #1#2#3#4 |
| 2400 |
{ |
| 2401 |
\@@_choice_make: |
| 2402 |
\@@_cmd_set:ne { \l_keys_path_str / true } |
| 2403 |
{ \exp_not:c { legacy_if_#2 set_ #3 :n } { \exp_not:n {#1} } } |
| 2404 |
\@@_cmd_set:ne { \l_keys_path_str / false } |
| 2405 |
{ \exp_not:c { legacy_if_#2 set_ #4 :n } { \exp_not:n {#1} } } |
| 2406 |
\@@_cmd_set:nn { \l_keys_path_str / unknown } |
| 2407 |
{ |
| 2408 |
\msg_error:nne { keys } { boolean-values-only } |
| 2409 |
\l_keys_path_str |
| 2410 |
} |
| 2411 |
\@@_default_set:n { true } |
| 2412 |
\cs_if_exist:cF { if#1 } |
| 2413 |
{ |
| 2414 |
\cs:w newif \exp_after:wN \cs_end: |
| 2415 |
\cs:w if#1 \cs_end: |
| 2416 |
} |
| 2417 |
} |
| 2418 |
% \end{macrocode} |
| 2419 |
% \end{macro} |
| 2420 |
% \end{macro} |
| 2421 |
% |
| 2422 |
% \begin{macro}{\@@_meta_make:n} |
| 2423 |
% \begin{macro}{\@@_meta_make:nn} |
| 2424 |
% To create a meta-key, simply set up to pass data through. The internal |
| 2425 |
% function is used here as a meta key should respect the prevailing |
| 2426 |
% filtering, etc. |
| 2427 |
% \begin{macrocode} |
| 2428 |
\cs_new_protected:Npn \@@_meta_make:n |
| 2429 |
{ \exp_args:NV \@@_meta_make:nn \l_@@_module_str } |
| 2430 |
\cs_new_protected:Npn \@@_meta_make:nn #1#2 |
| 2431 |
{ |
| 2432 |
\exp_args:NV \@@_cmd_set_direct:nn |
| 2433 |
\l_keys_path_str { \@@_set:nn {#1} {#2} } |
| 2434 |
} |
| 2435 |
% \end{macrocode} |
| 2436 |
% \end{macro} |
| 2437 |
% \end{macro} |
| 2438 |
% |
| 2439 |
% \begin{macro}{\@@_prop_put:Nn, \@@_prop_put:cn} |
| 2440 |
% Much the same as other variables, but needs a dedicated auxiliary. |
| 2441 |
% \begin{macrocode} |
| 2442 |
\cs_new_protected:Npn \@@_prop_put:Nn #1#2 |
| 2443 |
{ |
| 2444 |
\prop_if_exist:NF #1 { \prop_new:N #1 } |
| 2445 |
\exp_after:wN \@@_find_key_module:wNN \l_keys_path_str \s_@@_stop |
| 2446 |
\l_@@_tmpa_tl \l_@@_tmpb_tl |
| 2447 |
\@@_cmd_set:ne \l_keys_path_str |
| 2448 |
{ |
| 2449 |
\exp_not:c { prop_ #2 put:Nnn } |
| 2450 |
\exp_not:N #1 |
| 2451 |
{ \l_@@_tmpb_tl } |
| 2452 |
\exp_not:n { {##1} } |
| 2453 |
} |
| 2454 |
} |
| 2455 |
\cs_generate_variant:Nn \@@_prop_put:Nn { c } |
| 2456 |
% \end{macrocode} |
| 2457 |
% \end{macro} |
| 2458 |
% |
| 2459 |
% \begin{macro}{\@@_undefine:} |
| 2460 |
% Undefining a key has to be done without \cs{cs_undefine:c} as that |
| 2461 |
% function acts globally. |
| 2462 |
% \begin{macrocode} |
| 2463 |
\cs_new_protected:Npn \@@_undefine: |
| 2464 |
{ |
| 2465 |
\clist_map_inline:nn |
| 2466 |
{ code , default , groups , inherit , type , check } |
| 2467 |
{ |
| 2468 |
\@@_cs_undefine:c |
| 2469 |
{ \tl_use:c { c_@@_ ##1 _root_str } \l_keys_path_str } |
| 2470 |
} |
| 2471 |
} |
| 2472 |
% \end{macrocode} |
| 2473 |
% \end{macro} |
| 2474 |
% |
| 2475 |
% \begin{macro}{\@@_value_requirement:nn} |
| 2476 |
% \begin{macro}{\@@_check_forbidden:, \@@_check_required:} |
| 2477 |
% Validating key input is done using a second function which runs before |
| 2478 |
% the main key code. Setting that up means setting it equal to a generic |
| 2479 |
% stub which does the check. This approach makes the lookup very fast at |
| 2480 |
% the cost of one additional csname per key that needs it. The cleanup here |
| 2481 |
% has to know the structure of the following code. |
| 2482 |
% \begin{macrocode} |
| 2483 |
\cs_new_protected:Npn \@@_value_requirement:nn #1#2 |
| 2484 |
{ |
| 2485 |
\str_case:nnF {#2} |
| 2486 |
{ |
| 2487 |
{ true } |
| 2488 |
{ |
| 2489 |
\cs_set_eq:cc |
| 2490 |
{ \c_@@_check_root_str \l_keys_path_str } |
| 2491 |
{ @@_check_ #1 : } |
| 2492 |
} |
| 2493 |
{ false } |
| 2494 |
{ |
| 2495 |
\cs_if_eq:ccT |
| 2496 |
{ \c_@@_check_root_str \l_keys_path_str } |
| 2497 |
{ @@_check_ #1 : } |
| 2498 |
{ |
| 2499 |
\@@_cs_undefine:c |
| 2500 |
{ \c_@@_check_root_str \l_keys_path_str } |
| 2501 |
} |
| 2502 |
} |
| 2503 |
} |
| 2504 |
{ |
| 2505 |
\msg_error:nne { keys } |
| 2506 |
{ boolean-values-only } |
| 2507 |
{ .value_ #1 :n } |
| 2508 |
} |
| 2509 |
} |
| 2510 |
\cs_new_protected:Npn \@@_check_forbidden: |
| 2511 |
{ |
| 2512 |
\bool_if:NF \l_@@_no_value_bool |
| 2513 |
{ |
| 2514 |
\msg_error:nnee { keys } { value-forbidden } |
| 2515 |
\l_keys_path_str \l_keys_value_tl |
| 2516 |
\use_none:nnn |
| 2517 |
} |
| 2518 |
} |
| 2519 |
\cs_new_protected:Npn \@@_check_required: |
| 2520 |
{ |
| 2521 |
\bool_if:NT \l_@@_no_value_bool |
| 2522 |
{ |
| 2523 |
\msg_error:nne { keys } { value-required } |
| 2524 |
\l_keys_path_str |
| 2525 |
\use_none:nnn |
| 2526 |
} |
| 2527 |
} |
| 2528 |
% \end{macrocode} |
| 2529 |
% \end{macro} |
| 2530 |
% \end{macro} |
| 2531 |
% |
| 2532 |
% \begin{macro}{\@@_usage:n} |
| 2533 |
% \begin{macro}{\@@_usage:NN} |
| 2534 |
% \begin{macro}{\@@_usage:w} |
| 2535 |
% \begin{macro}{\@@_usage_aux:w} |
| 2536 |
% Save the relevant data. |
| 2537 |
% \begin{macrocode} |
| 2538 |
\cs_new_protected:Npn \@@_usage:n #1 |
| 2539 |
{ |
| 2540 |
\str_case:nnF {#1} |
| 2541 |
{ |
| 2542 |
{ general } |
| 2543 |
{ |
| 2544 |
\@@_usage:NN \l_keys_usage_load_prop |
| 2545 |
\c_false_bool |
| 2546 |
\@@_usage:NN \l_keys_usage_preamble_prop |
| 2547 |
\c_false_bool |
| 2548 |
} |
| 2549 |
{ load } |
| 2550 |
{ |
| 2551 |
\@@_usage:NN \l_keys_usage_load_prop |
| 2552 |
\c_true_bool |
| 2553 |
\@@_usage:NN \l_keys_usage_preamble_prop |
| 2554 |
\c_false_bool |
| 2555 |
} |
| 2556 |
{ preamble } |
| 2557 |
{ |
| 2558 |
\@@_usage:NN \l_keys_usage_load_prop |
| 2559 |
\c_false_bool |
| 2560 |
\@@_usage:NN \l_keys_usage_preamble_prop |
| 2561 |
\c_true_bool |
| 2562 |
} |
| 2563 |
} |
| 2564 |
{ |
| 2565 |
\msg_error:nnnn { keys } |
| 2566 |
{ choice-unknown } |
| 2567 |
{ .usage:n } |
| 2568 |
{#1} |
| 2569 |
} |
| 2570 |
} |
| 2571 |
\cs_new_protected:Npn \@@_usage:NN #1#2 |
| 2572 |
{ |
| 2573 |
\prop_get:NVNF #1 \l_@@_module_str \l_@@_tmpa_tl |
| 2574 |
{ \tl_clear:N \l_@@_tmpa_tl } |
| 2575 |
\tl_set:Ne \l_@@_tmpb_tl |
| 2576 |
{ |
| 2577 |
\exp_after:wN \exp_after:wN \exp_after:wN \@@_usage:w \exp_after:wN |
| 2578 |
\l_keys_path_str \exp_after:wN / \exp_after:wN \s_@@_stop |
| 2579 |
\exp_after:wN { \l_keys_path_str } |
| 2580 |
} |
| 2581 |
\bool_if:NTF #2 |
| 2582 |
{ \clist_put_right:NV \l_@@_tmpa_tl \l_@@_tmpb_tl } |
| 2583 |
{ \clist_remove_all:NV \l_@@_tmpa_tl \l_@@_tmpb_tl } |
| 2584 |
\prop_put:NVV #1 \l_@@_module_str |
| 2585 |
\l_@@_tmpa_tl |
| 2586 |
} |
| 2587 |
\cs_new:Npn \@@_usage:w #1 / #2 \s_@@_stop #3 |
| 2588 |
{ |
| 2589 |
\tl_if_blank:nTF {#2} |
| 2590 |
{#1} |
| 2591 |
{ \@@_usage_aux:w #3 \s_@@_stop } |
| 2592 |
} |
| 2593 |
\cs_new:Npn \@@_usage_aux:w #1 / #2 \s_@@_stop {#2} |
| 2594 |
% \end{macrocode} |
| 2595 |
% \end{macro} |
| 2596 |
% \end{macro} |
| 2597 |
% \end{macro} |
| 2598 |
% \end{macro} |
| 2599 |
% |
| 2600 |
% \begin{macro}{\@@_variable_set:NnnN, \@@_variable_set:cnnN} |
| 2601 |
% \begin{macro}{\@@_variable_set_required:NnnN, \@@_variable_set_required:cnnN} |
| 2602 |
% Setting a variable takes the type and scope separately so that |
| 2603 |
% it is easy to make a new variable if needed. |
| 2604 |
% \begin{macrocode} |
| 2605 |
\cs_new_protected:Npn \@@_variable_set:NnnN #1#2#3#4 |
| 2606 |
{ |
| 2607 |
\use:c { #2_if_exist:NF } #1 { \use:c { #2 _new:N } #1 } |
| 2608 |
\@@_cmd_set:ne \l_keys_path_str |
| 2609 |
{ |
| 2610 |
\exp_not:c { #2 _ #3 set:N #4 } |
| 2611 |
\exp_not:N #1 |
| 2612 |
\exp_not:n { {##1} } |
| 2613 |
} |
| 2614 |
} |
| 2615 |
\cs_generate_variant:Nn \@@_variable_set:NnnN { c } |
| 2616 |
\cs_new_protected:Npn \@@_variable_set_required:NnnN #1#2#3#4 |
| 2617 |
{ |
| 2618 |
\@@_variable_set:NnnN #1 {#2} {#3} #4 |
| 2619 |
\@@_value_requirement:nn { required } { true } |
| 2620 |
} |
| 2621 |
\cs_generate_variant:Nn \@@_variable_set_required:NnnN { c } |
| 2622 |
% \end{macrocode} |
| 2623 |
% \end{macro} |
| 2624 |
% \end{macro} |
| 2625 |
% |
| 2626 |
% \subsection{Creating key properties} |
| 2627 |
% |
| 2628 |
% The key property functions are all wrappers for internal functions, |
| 2629 |
% meaning that things stay readable and can also be altered later on. |
| 2630 |
% |
| 2631 |
% Importantly, while key properties have \enquote{normal} argument specs, the |
| 2632 |
% underlying code always supplies one braced argument to these. As such, argument |
| 2633 |
% expansion is handled by hand rather than using the standard tools. This shows |
| 2634 |
% up particularly for the two-argument properties, where things would otherwise |
| 2635 |
% go badly wrong. |
| 2636 |
% |
| 2637 |
% \begin{macro}{.bool_set:N, .bool_set:c} |
| 2638 |
% \begin{macro}{.bool_gset:N, .bool_gset:c} |
| 2639 |
% One function for this. |
| 2640 |
% \begin{macrocode} |
| 2641 |
\cs_new_protected:cpn { \c_@@_props_root_str .bool_set:N } #1 |
| 2642 |
{ \@@_bool_set:Nn #1 { } } |
| 2643 |
\cs_new_protected:cpn { \c_@@_props_root_str .bool_set:c } #1 |
| 2644 |
{ \@@_bool_set:cn {#1} { } } |
| 2645 |
\cs_new_protected:cpn { \c_@@_props_root_str .bool_gset:N } #1 |
| 2646 |
{ \@@_bool_set:Nn #1 { g } } |
| 2647 |
\cs_new_protected:cpn { \c_@@_props_root_str .bool_gset:c } #1 |
| 2648 |
{ \@@_bool_set:cn {#1} { g } } |
| 2649 |
% \end{macrocode} |
| 2650 |
% \end{macro} |
| 2651 |
% \end{macro} |
| 2652 |
% |
| 2653 |
% \begin{macro}{.bool_set_inverse:N, .bool_set_inverse:c} |
| 2654 |
% \begin{macro}{.bool_gset_inverse:N, .bool_gset_inverse:c} |
| 2655 |
% One function for this. |
| 2656 |
% \begin{macrocode} |
| 2657 |
\cs_new_protected:cpn { \c_@@_props_root_str .bool_set_inverse:N } #1 |
| 2658 |
{ \@@_bool_set_inverse:Nn #1 { } } |
| 2659 |
\cs_new_protected:cpn { \c_@@_props_root_str .bool_set_inverse:c } #1 |
| 2660 |
{ \@@_bool_set_inverse:cn {#1} { } } |
| 2661 |
\cs_new_protected:cpn { \c_@@_props_root_str .bool_gset_inverse:N } #1 |
| 2662 |
{ \@@_bool_set_inverse:Nn #1 { g } } |
| 2663 |
\cs_new_protected:cpn { \c_@@_props_root_str .bool_gset_inverse:c } #1 |
| 2664 |
{ \@@_bool_set_inverse:cn {#1} { g } } |
| 2665 |
% \end{macrocode} |
| 2666 |
% \end{macro} |
| 2667 |
% \end{macro} |
| 2668 |
% |
| 2669 |
% \begin{macro}{.choice:} |
| 2670 |
% Making a choice is handled internally, as it is also needed by |
| 2671 |
% \texttt{.generate_choices:n}. |
| 2672 |
% \begin{macrocode} |
| 2673 |
\cs_new_protected:cpn { \c_@@_props_root_str .choice: } |
| 2674 |
{ \@@_choice_make: } |
| 2675 |
% \end{macrocode} |
| 2676 |
% \end{macro} |
| 2677 |
% |
| 2678 |
% \begin{macro}{.choices:nn, .choices:Vn, .choices:en, .choices:on, .choices:xn} |
| 2679 |
% For auto-generation of a series of mutually-exclusive choices. |
| 2680 |
% Here, |#1| consists of two separate |
| 2681 |
% arguments, hence the slightly odd-looking implementation. |
| 2682 |
% \begin{macrocode} |
| 2683 |
\cs_new_protected:cpn { \c_@@_props_root_str .choices:nn } #1 |
| 2684 |
{ \@@_choices_make:nn #1 } |
| 2685 |
\cs_new_protected:cpn { \c_@@_props_root_str .choices:Vn } #1 |
| 2686 |
{ \exp_args:NV \@@_choices_make:nn #1 } |
| 2687 |
\cs_new_protected:cpn { \c_@@_props_root_str .choices:en } #1 |
| 2688 |
{ \exp_args:Ne \@@_choices_make:nn #1 } |
| 2689 |
\cs_new_protected:cpn { \c_@@_props_root_str .choices:on } #1 |
| 2690 |
{ \exp_args:No \@@_choices_make:nn #1 } |
| 2691 |
\cs_new_protected:cpn { \c_@@_props_root_str .choices:xn } #1 |
| 2692 |
{ \exp_args:Nx \@@_choices_make:nn #1 } |
| 2693 |
% \end{macrocode} |
| 2694 |
% \end{macro} |
| 2695 |
% |
| 2696 |
% \begin{macro}{.code:n} |
| 2697 |
% Creating code is simply a case of passing through to the underlying |
| 2698 |
% \texttt{set} function. |
| 2699 |
% \begin{macrocode} |
| 2700 |
\cs_new_protected:cpn { \c_@@_props_root_str .code:n } #1 |
| 2701 |
{ \@@_cmd_set:nn \l_keys_path_str {#1} } |
| 2702 |
% \end{macrocode} |
| 2703 |
% \end{macro} |
| 2704 |
% |
| 2705 |
% \begin{macro}{.clist_set:N, .clist_set:c} |
| 2706 |
% \begin{macro}{.clist_gset:N, .clist_gset:c} |
| 2707 |
% \begin{macrocode} |
| 2708 |
\cs_new_protected:cpn { \c_@@_props_root_str .clist_set:N } #1 |
| 2709 |
{ \@@_variable_set:NnnN #1 { clist } { } n } |
| 2710 |
\cs_new_protected:cpn { \c_@@_props_root_str .clist_set:c } #1 |
| 2711 |
{ \@@_variable_set:cnnN {#1} { clist } { } n } |
| 2712 |
\cs_new_protected:cpn { \c_@@_props_root_str .clist_gset:N } #1 |
| 2713 |
{ \@@_variable_set:NnnN #1 { clist } { g } n } |
| 2714 |
\cs_new_protected:cpn { \c_@@_props_root_str .clist_gset:c } #1 |
| 2715 |
{ \@@_variable_set:cnnN {#1} { clist } { g } n } |
| 2716 |
% \end{macrocode} |
| 2717 |
% \end{macro} |
| 2718 |
% \end{macro} |
| 2719 |
% |
| 2720 |
% \begin{macro} |
| 2721 |
% {.cs_set:Np, .cs_set:cp, .cs_set_protected:Np, .cs_set_protected:cp} |
| 2722 |
% \begin{macro} |
| 2723 |
% {.cs_gset:Np, .cs_gset:cp, .cs_gset_protected:Np, .cs_gset_protected:cp} |
| 2724 |
% \begin{macrocode} |
| 2725 |
\cs_new_protected:cpn { \c_@@_props_root_str .cs_set:Np } #1 |
| 2726 |
{ \@@_cs_set:NNpn \cs_set:Npn #1 { } } |
| 2727 |
\cs_new_protected:cpn { \c_@@_props_root_str .cs_set:cp } #1 |
| 2728 |
{ \@@_cs_set:Ncpn \cs_set:Npn #1 { } } |
| 2729 |
\cs_new_protected:cpn { \c_@@_props_root_str .cs_set_protected:Np } #1 |
| 2730 |
{ \@@_cs_set:NNpn \cs_set_protected:Npn #1 { } } |
| 2731 |
\cs_new_protected:cpn { \c_@@_props_root_str .cs_set_protected:cp } #1 |
| 2732 |
{ \@@_cs_set:Ncpn \cs_set_protected:Npn #1 { } } |
| 2733 |
\cs_new_protected:cpn { \c_@@_props_root_str .cs_gset:Np } #1 |
| 2734 |
{ \@@_cs_set:NNpn \cs_gset:Npn #1 { } } |
| 2735 |
\cs_new_protected:cpn { \c_@@_props_root_str .cs_gset:cp } #1 |
| 2736 |
{ \@@_cs_set:Ncpn \cs_gset:Npn #1 { } } |
| 2737 |
\cs_new_protected:cpn { \c_@@_props_root_str .cs_gset_protected:Np } #1 |
| 2738 |
{ \@@_cs_set:NNpn \cs_gset_protected:Npn #1 { } } |
| 2739 |
\cs_new_protected:cpn { \c_@@_props_root_str .cs_gset_protected:cp } #1 |
| 2740 |
{ \@@_cs_set:Ncpn \cs_gset_protected:Npn #1 { } } |
| 2741 |
% \end{macrocode} |
| 2742 |
% \end{macro} |
| 2743 |
% \end{macro} |
| 2744 |
% |
| 2745 |
% \begin{macro}{.default:n, .default:V, .default:e, .default:o, .default:x} |
| 2746 |
% Expansion is left to the internal functions. |
| 2747 |
% \begin{macrocode} |
| 2748 |
\cs_new_protected:cpn { \c_@@_props_root_str .default:n } #1 |
| 2749 |
{ \@@_default_set:n {#1} } |
| 2750 |
\cs_new_protected:cpn { \c_@@_props_root_str .default:V } #1 |
| 2751 |
{ \exp_args:NV \@@_default_set:n #1 } |
| 2752 |
\cs_new_protected:cpn { \c_@@_props_root_str .default:e } #1 |
| 2753 |
{ \exp_args:Ne \@@_default_set:n {#1} } |
| 2754 |
\cs_new_protected:cpn { \c_@@_props_root_str .default:o } #1 |
| 2755 |
{ \exp_args:No \@@_default_set:n {#1} } |
| 2756 |
\cs_new_protected:cpn { \c_@@_props_root_str .default:x } #1 |
| 2757 |
{ \exp_args:Nx \@@_default_set:n {#1} } |
| 2758 |
% \end{macrocode} |
| 2759 |
% \end{macro} |
| 2760 |
% |
| 2761 |
% \begin{macro}{.dim_set:N, .dim_set:c} |
| 2762 |
% \begin{macro}{.dim_gset:N, .dim_gset:c} |
| 2763 |
% Setting a variable is very easy: just pass the data along. |
| 2764 |
% \begin{macrocode} |
| 2765 |
\cs_new_protected:cpn { \c_@@_props_root_str .dim_set:N } #1 |
| 2766 |
{ \@@_variable_set_required:NnnN #1 { dim } { } n } |
| 2767 |
\cs_new_protected:cpn { \c_@@_props_root_str .dim_set:c } #1 |
| 2768 |
{ \@@_variable_set_required:cnnN {#1} { dim } { } n } |
| 2769 |
\cs_new_protected:cpn { \c_@@_props_root_str .dim_gset:N } #1 |
| 2770 |
{ \@@_variable_set_required:NnnN #1 { dim } { g } n } |
| 2771 |
\cs_new_protected:cpn { \c_@@_props_root_str .dim_gset:c } #1 |
| 2772 |
{ \@@_variable_set_required:cnnN {#1} { dim } { g } n } |
| 2773 |
% \end{macrocode} |
| 2774 |
% \end{macro} |
| 2775 |
% \end{macro} |
| 2776 |
% |
| 2777 |
% \begin{macro}{.fp_set:N, .fp_set:c} |
| 2778 |
% \begin{macro}{.fp_gset:N, .fp_gset:c} |
| 2779 |
% Setting a variable is very easy: just pass the data along. |
| 2780 |
% \begin{macrocode} |
| 2781 |
\cs_new_protected:cpn { \c_@@_props_root_str .fp_set:N } #1 |
| 2782 |
{ \@@_variable_set_required:NnnN #1 { fp } { } n } |
| 2783 |
\cs_new_protected:cpn { \c_@@_props_root_str .fp_set:c } #1 |
| 2784 |
{ \@@_variable_set_required:cnnN {#1} { fp } { } n } |
| 2785 |
\cs_new_protected:cpn { \c_@@_props_root_str .fp_gset:N } #1 |
| 2786 |
{ \@@_variable_set_required:NnnN #1 { fp } { g } n } |
| 2787 |
\cs_new_protected:cpn { \c_@@_props_root_str .fp_gset:c } #1 |
| 2788 |
{ \@@_variable_set_required:cnnN {#1} { fp } { g } n } |
| 2789 |
% \end{macrocode} |
| 2790 |
% \end{macro} |
| 2791 |
% \end{macro} |
| 2792 |
% |
| 2793 |
% \begin{macro}{.groups:n} |
| 2794 |
% A single property to create groups of keys. |
| 2795 |
% \begin{macrocode} |
| 2796 |
\cs_new_protected:cpn { \c_@@_props_root_str .groups:n } #1 |
| 2797 |
{ \@@_groups_set:n {#1} } |
| 2798 |
% \end{macrocode} |
| 2799 |
% \end{macro} |
| 2800 |
% |
| 2801 |
% \begin{macro}{.inherit:n} |
| 2802 |
% Nothing complex: only one variant at the moment! |
| 2803 |
% \begin{macrocode} |
| 2804 |
\cs_new_protected:cpn { \c_@@_props_root_str .inherit:n } #1 |
| 2805 |
{ \@@_inherit:n {#1} } |
| 2806 |
% \end{macrocode} |
| 2807 |
% \end{macro} |
| 2808 |
% |
| 2809 |
% \begin{macro}{.initial:n, .initial:V, .initial:e, .initial:o, .initial:x} |
| 2810 |
% The standard hand-off approach. |
| 2811 |
% \begin{macrocode} |
| 2812 |
\cs_new_protected:cpn { \c_@@_props_root_str .initial:n } #1 |
| 2813 |
{ \@@_initialize:n {#1} } |
| 2814 |
\cs_new_protected:cpn { \c_@@_props_root_str .initial:V } #1 |
| 2815 |
{ \exp_args:NV \@@_initialize:n #1 } |
| 2816 |
\cs_new_protected:cpn { \c_@@_props_root_str .initial:e } #1 |
| 2817 |
{ \exp_args:Ne \@@_initialize:n {#1} } |
| 2818 |
\cs_new_protected:cpn { \c_@@_props_root_str .initial:o } #1 |
| 2819 |
{ \exp_args:No \@@_initialize:n {#1} } |
| 2820 |
\cs_new_protected:cpn { \c_@@_props_root_str .initial:x } #1 |
| 2821 |
{ \exp_args:Nx \@@_initialize:n {#1} } |
| 2822 |
% \end{macrocode} |
| 2823 |
% \end{macro} |
| 2824 |
% |
| 2825 |
% \begin{macro}{.int_set:N, .int_set:c} |
| 2826 |
% \begin{macro}{.int_gset:N, .int_gset:c} |
| 2827 |
% Setting a variable is very easy: just pass the data along. |
| 2828 |
% \begin{macrocode} |
| 2829 |
\cs_new_protected:cpn { \c_@@_props_root_str .int_set:N } #1 |
| 2830 |
{ \@@_variable_set_required:NnnN #1 { int } { } n } |
| 2831 |
\cs_new_protected:cpn { \c_@@_props_root_str .int_set:c } #1 |
| 2832 |
{ \@@_variable_set_required:cnnN {#1} { int } { } n } |
| 2833 |
\cs_new_protected:cpn { \c_@@_props_root_str .int_gset:N } #1 |
| 2834 |
{ \@@_variable_set_required:NnnN #1 { int } { g } n } |
| 2835 |
\cs_new_protected:cpn { \c_@@_props_root_str .int_gset:c } #1 |
| 2836 |
{ \@@_variable_set_required:cnnN {#1} { int } { g } n } |
| 2837 |
% \end{macrocode} |
| 2838 |
% \end{macro} |
| 2839 |
% \end{macro} |
| 2840 |
% |
| 2841 |
% \begin{macro} |
| 2842 |
% { |
| 2843 |
% .legacy_if_set:n, .legacy_if_gset:n, |
| 2844 |
% .legacy_if_set_inverse:n, .legacy_if_gset_inverse:n |
| 2845 |
% } |
| 2846 |
% \begin{macrocode} |
| 2847 |
\cs_new_protected:cpn { \c_@@_props_root_str .legacy_if_set:n } #1 |
| 2848 |
{ \@@_legacy_if_set:nn {#1} { } } |
| 2849 |
\cs_new_protected:cpn { \c_@@_props_root_str .legacy_if_gset:n } #1 |
| 2850 |
{ \@@_legacy_if_set:nn {#1} { g } } |
| 2851 |
\cs_new_protected:cpn { \c_@@_props_root_str .legacy_if_set_inverse:n } #1 |
| 2852 |
{ \@@_legacy_if_set_inverse:nn {#1} { } } |
| 2853 |
\cs_new_protected:cpn { \c_@@_props_root_str .legacy_if_gset_inverse:n } #1 |
| 2854 |
{ \@@_legacy_if_set_inverse:nn {#1} { g } } |
| 2855 |
% \end{macrocode} |
| 2856 |
% \end{macro} |
| 2857 |
% |
| 2858 |
% \begin{macro}{.meta:n} |
| 2859 |
% Making a meta is handled internally. |
| 2860 |
% \begin{macrocode} |
| 2861 |
\cs_new_protected:cpn { \c_@@_props_root_str .meta:n } #1 |
| 2862 |
{ \@@_meta_make:n {#1} } |
| 2863 |
% \end{macrocode} |
| 2864 |
% \end{macro} |
| 2865 |
% |
| 2866 |
% \begin{macro}{.meta:nn} |
| 2867 |
% Meta with path: potentially lots of variants, but for the moment |
| 2868 |
% no so many defined. |
| 2869 |
% \begin{macrocode} |
| 2870 |
\cs_new_protected:cpn { \c_@@_props_root_str .meta:nn } #1 |
| 2871 |
{ \@@_meta_make:nn #1 } |
| 2872 |
% \end{macrocode} |
| 2873 |
% \end{macro} |
| 2874 |
% |
| 2875 |
% \begin{macro}{.multichoice:} |
| 2876 |
% \begin{macro}{.multichoices:nn, .multichoices:Vn, .multichoices:en, .multichoices:on, .multichoices:xn} |
| 2877 |
% The same idea as \texttt{.choice:} and \texttt{.choices:nn}, but |
| 2878 |
% where more than one choice is allowed. |
| 2879 |
% \begin{macrocode} |
| 2880 |
\cs_new_protected:cpn { \c_@@_props_root_str .multichoice: } |
| 2881 |
{ \@@_multichoice_make: } |
| 2882 |
\cs_new_protected:cpn { \c_@@_props_root_str .multichoices:nn } #1 |
| 2883 |
{ \@@_multichoices_make:nn #1 } |
| 2884 |
\cs_new_protected:cpn { \c_@@_props_root_str .multichoices:Vn } #1 |
| 2885 |
{ \exp_args:NV \@@_multichoices_make:nn #1 } |
| 2886 |
\cs_new_protected:cpn { \c_@@_props_root_str .multichoices:en } #1 |
| 2887 |
{ \exp_args:Ne \@@_multichoices_make:nn #1 } |
| 2888 |
\cs_new_protected:cpn { \c_@@_props_root_str .multichoices:on } #1 |
| 2889 |
{ \exp_args:No \@@_multichoices_make:nn #1 } |
| 2890 |
\cs_new_protected:cpn { \c_@@_props_root_str .multichoices:xn } #1 |
| 2891 |
{ \exp_args:Nx \@@_multichoices_make:nn #1 } |
| 2892 |
% \end{macrocode} |
| 2893 |
% \end{macro} |
| 2894 |
% \end{macro} |
| 2895 |
% |
| 2896 |
% \begin{macro}{.muskip_set:N, .muskip_set:c, .muskip_gset:N, .muskip_gset:c} |
| 2897 |
% Setting a variable is very easy: just pass the data along. |
| 2898 |
% \begin{macrocode} |
| 2899 |
\cs_new_protected:cpn { \c_@@_props_root_str .muskip_set:N } #1 |
| 2900 |
{ \@@_variable_set_required:NnnN #1 { muskip } { } n } |
| 2901 |
\cs_new_protected:cpn { \c_@@_props_root_str .muskip_set:c } #1 |
| 2902 |
{ \@@_variable_set_required:cnnN {#1} { muskip } { } n } |
| 2903 |
\cs_new_protected:cpn { \c_@@_props_root_str .muskip_gset:N } #1 |
| 2904 |
{ \@@_variable_set_required:NnnN #1 { muskip } { g } n } |
| 2905 |
\cs_new_protected:cpn { \c_@@_props_root_str .muskip_gset:c } #1 |
| 2906 |
{ \@@_variable_set_required:cnnN {#1} { muskip } { g } n } |
| 2907 |
% \end{macrocode} |
| 2908 |
% \end{macro} |
| 2909 |
% |
| 2910 |
% \begin{macro}{.prop_put:N, .prop_put:c, .prop_gput:N, .prop_gput:c} |
| 2911 |
% Setting a variable is very easy: just pass the data along. |
| 2912 |
% \begin{macrocode} |
| 2913 |
\cs_new_protected:cpn { \c_@@_props_root_str .prop_put:N } #1 |
| 2914 |
{ \@@_prop_put:Nn #1 { } } |
| 2915 |
\cs_new_protected:cpn { \c_@@_props_root_str .prop_put:c } #1 |
| 2916 |
{ \@@_prop_put:cn {#1} { } } |
| 2917 |
\cs_new_protected:cpn { \c_@@_props_root_str .prop_gput:N } #1 |
| 2918 |
{ \@@_prop_put:Nn #1 { g } } |
| 2919 |
\cs_new_protected:cpn { \c_@@_props_root_str .prop_gput:c } #1 |
| 2920 |
{ \@@_prop_put:cn {#1} { g } } |
| 2921 |
% \end{macrocode} |
| 2922 |
% \end{macro} |
| 2923 |
% |
| 2924 |
% \begin{macro}{.skip_set:N, .skip_set:c} |
| 2925 |
% \begin{macro}{.skip_gset:N, .skip_gset:c} |
| 2926 |
% Setting a variable is very easy: just pass the data along. |
| 2927 |
% \begin{macrocode} |
| 2928 |
\cs_new_protected:cpn { \c_@@_props_root_str .skip_set:N } #1 |
| 2929 |
{ \@@_variable_set_required:NnnN #1 { skip } { } n } |
| 2930 |
\cs_new_protected:cpn { \c_@@_props_root_str .skip_set:c } #1 |
| 2931 |
{ \@@_variable_set_required:cnnN {#1} { skip } { } n } |
| 2932 |
\cs_new_protected:cpn { \c_@@_props_root_str .skip_gset:N } #1 |
| 2933 |
{ \@@_variable_set_required:NnnN #1 { skip } { g } n } |
| 2934 |
\cs_new_protected:cpn { \c_@@_props_root_str .skip_gset:c } #1 |
| 2935 |
{ \@@_variable_set_required:cnnN {#1} { skip } { g } n } |
| 2936 |
% \end{macrocode} |
| 2937 |
% \end{macro} |
| 2938 |
% \end{macro} |
| 2939 |
% |
| 2940 |
% \begin{macro}{.str_set:N, .str_set:c} |
| 2941 |
% \begin{macro}{.str_gset:N, .str_gset:c} |
| 2942 |
% \begin{macro}{.str_set_e:N, .str_set_e:c} |
| 2943 |
% \begin{macro}{.str_gset_e:N, .str_gset_e:c} |
| 2944 |
% Setting a variable is very easy: just pass the data along. |
| 2945 |
% \begin{macrocode} |
| 2946 |
\cs_new_protected:cpn { \c_@@_props_root_str .str_set:N } #1 |
| 2947 |
{ \@@_variable_set:NnnN #1 { str } { } n } |
| 2948 |
\cs_new_protected:cpn { \c_@@_props_root_str .str_set:c } #1 |
| 2949 |
{ \@@_variable_set:cnnN {#1} { str } { } n } |
| 2950 |
\cs_new_protected:cpn { \c_@@_props_root_str .str_set_e:N } #1 |
| 2951 |
{ \@@_variable_set:NnnN #1 { str } { } e } |
| 2952 |
\cs_new_protected:cpn { \c_@@_props_root_str .str_set_e:c } #1 |
| 2953 |
{ \@@_variable_set:cnnN {#1} { str } { } e } |
| 2954 |
\cs_new_protected:cpn { \c_@@_props_root_str .str_gset:N } #1 |
| 2955 |
{ \@@_variable_set:NnnN #1 { str } { g } n } |
| 2956 |
\cs_new_protected:cpn { \c_@@_props_root_str .str_gset:c } #1 |
| 2957 |
{ \@@_variable_set:cnnN {#1} { str } { g } n } |
| 2958 |
\cs_new_protected:cpn { \c_@@_props_root_str .str_gset_e:N } #1 |
| 2959 |
{ \@@_variable_set:NnnN #1 { str } { g } e } |
| 2960 |
\cs_new_protected:cpn { \c_@@_props_root_str .str_gset_e:c } #1 |
| 2961 |
{ \@@_variable_set:cnnN {#1} { str } { g } e } |
| 2962 |
% \end{macrocode} |
| 2963 |
% \end{macro} |
| 2964 |
% \end{macro} |
| 2965 |
% \end{macro} |
| 2966 |
% \end{macro} |
| 2967 |
% |
| 2968 |
% \begin{macro}{.tl_set:N, .tl_set:c} |
| 2969 |
% \begin{macro}{.tl_gset:N, .tl_gset:c} |
| 2970 |
% \begin{macro}{.tl_set_e:N, .tl_set_e:c} |
| 2971 |
% \begin{macro}{.tl_gset_e:N, .tl_gset_e:c} |
| 2972 |
% Setting a variable is very easy: just pass the data along. |
| 2973 |
% \begin{macrocode} |
| 2974 |
\cs_new_protected:cpn { \c_@@_props_root_str .tl_set:N } #1 |
| 2975 |
{ \@@_variable_set:NnnN #1 { tl } { } n } |
| 2976 |
\cs_new_protected:cpn { \c_@@_props_root_str .tl_set:c } #1 |
| 2977 |
{ \@@_variable_set:cnnN {#1} { tl } { } n } |
| 2978 |
\cs_new_protected:cpn { \c_@@_props_root_str .tl_set_e:N } #1 |
| 2979 |
{ \@@_variable_set:NnnN #1 { tl } { } e } |
| 2980 |
\cs_new_protected:cpn { \c_@@_props_root_str .tl_set_e:c } #1 |
| 2981 |
{ \@@_variable_set:cnnN {#1} { tl } { } e } |
| 2982 |
\cs_new_protected:cpn { \c_@@_props_root_str .tl_gset:N } #1 |
| 2983 |
{ \@@_variable_set:NnnN #1 { tl } { g } n } |
| 2984 |
\cs_new_protected:cpn { \c_@@_props_root_str .tl_gset:c } #1 |
| 2985 |
{ \@@_variable_set:cnnN {#1} { tl } { g } n } |
| 2986 |
\cs_new_protected:cpn { \c_@@_props_root_str .tl_gset_e:N } #1 |
| 2987 |
{ \@@_variable_set:NnnN #1 { tl } { g } e } |
| 2988 |
\cs_new_protected:cpn { \c_@@_props_root_str .tl_gset_e:c } #1 |
| 2989 |
{ \@@_variable_set:cnnN {#1} { tl } { g } e } |
| 2990 |
% \end{macrocode} |
| 2991 |
% \end{macro} |
| 2992 |
% \end{macro} |
| 2993 |
% \end{macro} |
| 2994 |
% \end{macro} |
| 2995 |
% |
| 2996 |
% \begin{macro}{.undefine:} |
| 2997 |
% Another simple wrapper. |
| 2998 |
% \begin{macrocode} |
| 2999 |
\cs_new_protected:cpn { \c_@@_props_root_str .undefine: } |
| 3000 |
{ \@@_undefine: } |
| 3001 |
% \end{macrocode} |
| 3002 |
% \end{macro} |
| 3003 |
% |
| 3004 |
% \begin{macro}{.usage:n} |
| 3005 |
% \begin{macrocode} |
| 3006 |
\cs_new_protected:cpn { \c_@@_props_root_str .usage:n } #1 |
| 3007 |
{ \@@_usage:n {#1} } |
| 3008 |
% \end{macrocode} |
| 3009 |
% \end{macro} |
| 3010 |
% |
| 3011 |
% \begin{macro}{.value_forbidden:n} |
| 3012 |
% \begin{macro}{.value_required:n} |
| 3013 |
% These are very similar, so both call the same function. |
| 3014 |
% \begin{macrocode} |
| 3015 |
\cs_new_protected:cpn { \c_@@_props_root_str .value_forbidden:n } #1 |
| 3016 |
{ \@@_value_requirement:nn { forbidden } {#1} } |
| 3017 |
\cs_new_protected:cpn { \c_@@_props_root_str .value_required:n } #1 |
| 3018 |
{ \@@_value_requirement:nn { required } {#1} } |
| 3019 |
% \end{macrocode} |
| 3020 |
% \end{macro} |
| 3021 |
% \end{macro} |
| 3022 |
% |
| 3023 |
% \subsection{Setting keys} |
| 3024 |
% |
| 3025 |
% \begin{macro}{\@@_set:nnnnNn} |
| 3026 |
% \begin{macro}[EXP]{\@@_reset_bool:N, \@@_reset_var:N} |
| 3027 |
% \begin{macro}{\@@_set:nn} |
| 3028 |
% \begin{macro}{\@@_set:nnn} |
| 3029 |
% The aim here is to allow nesting of key setting without needing lots of |
| 3030 |
% tracking. That is done by expanding the appropriate tokens \enquote{around} |
| 3031 |
% the core keyval parsing. As there are several different sub-paths, this |
| 3032 |
% needs a few steps and some generic auxiliaries. The arguments here are |
| 3033 |
% \begin{enumerate} |
| 3034 |
% \item The root for keys |
| 3035 |
% \item The key groups |
| 3036 |
% \item The keys themselves |
| 3037 |
% \item The relative root for return of unset keys |
| 3038 |
% \item The \texttt{clist} var for returning unset keys |
| 3039 |
% \item The code to set up the correct selection approach |
| 3040 |
% \end{enumerate} |
| 3041 |
% \begin{macrocode} |
| 3042 |
\cs_new_protected:Npn \@@_set:nnnnNn #1#2#3#4#5#6 |
| 3043 |
{ |
| 3044 |
\use:e |
| 3045 |
{ |
| 3046 |
\exp_not:n |
| 3047 |
{ |
| 3048 |
\clist_clear:N \l_@@_unused_clist |
| 3049 |
\clist_set:Ne \l_@@_selective_clist { \tl_to_str:n {#2} } |
| 3050 |
\tl_set:Nn \l_@@_relative_tl {#4} |
| 3051 |
#6 |
| 3052 |
\@@_set:nn {#1} {#3} |
| 3053 |
\clist_set_eq:NN #5 \l_@@_unused_clist |
| 3054 |
} |
| 3055 |
\@@_reset_bool:N \l_@@_only_known_bool |
| 3056 |
\@@_reset_bool:N \l_@@_exclude_bool |
| 3057 |
\@@_reset_bool:N \l_@@_selective_bool |
| 3058 |
\@@_reset_var:N \l_@@_unused_clist |
| 3059 |
\@@_reset_var:N \l_@@_selective_clist |
| 3060 |
\@@_reset_var:N \l_@@_relative_tl |
| 3061 |
\@@_reset_var:N \l_@@_inherit_str |
| 3062 |
\@@_reset_var:N \l_keys_choice_tl |
| 3063 |
\@@_reset_var:N \l_keys_choice_str |
| 3064 |
\@@_reset_var:N \l_keys_key_tl |
| 3065 |
\@@_reset_var:N \l_keys_key_str |
| 3066 |
\@@_reset_var:N \l_keys_path_tl |
| 3067 |
\@@_reset_var:N \l_keys_path_str |
| 3068 |
\@@_reset_var:N \l_keys_value_tl |
| 3069 |
\int_set:Nn \l_keys_choice_int { \int_use:N \l_keys_choice_int } |
| 3070 |
} |
| 3071 |
} |
| 3072 |
\cs_new:Npn \@@_reset_bool:N #1 |
| 3073 |
{ |
| 3074 |
\exp_not:c |
| 3075 |
{ bool_set_ \bool_if:NTF #1 { true } { false } :N } |
| 3076 |
\exp_not:N #1 |
| 3077 |
} |
| 3078 |
\cs_new:Npn \@@_reset_var:N #1 |
| 3079 |
{ |
| 3080 |
\exp_not:n |
| 3081 |
{ \__kernel_tl_set:Nx #1 } |
| 3082 |
{ \exp_not:N \exp_not:n { \exp_not:o { #1 } } } |
| 3083 |
} |
| 3084 |
\cs_new_protected:Npn \@@_set:nn #1#2 |
| 3085 |
{ \exp_args:No \@@_set:nnn \l_@@_module_str {#1} {#2} } |
| 3086 |
\cs_new_protected:Npn \@@_set:nnn #1#2#3 |
| 3087 |
{ |
| 3088 |
\str_set:Ne \l_@@_module_str { \@@_trim_spaces:n {#2} } |
| 3089 |
\keyval_parse:NNn \@@_set_keyval:n \@@_set_keyval:nn {#3} |
| 3090 |
\str_set:Nn \l_@@_module_str {#1} |
| 3091 |
} |
| 3092 |
% \end{macrocode} |
| 3093 |
% \end{macro} |
| 3094 |
% \end{macro} |
| 3095 |
% \end{macro} |
| 3096 |
% \end{macro} |
| 3097 |
% |
| 3098 |
% \begin{macro} |
| 3099 |
% { |
| 3100 |
% \keys_set:nn, \keys_set:nV, \keys_set:nv, \keys_set:ne, |
| 3101 |
% \keys_set:no, \keys_set:nx |
| 3102 |
% } |
| 3103 |
% A simple wrapper allowing for nesting. |
| 3104 |
% \begin{macrocode} |
| 3105 |
\cs_new_protected:Npn \keys_set:nn #1#2 |
| 3106 |
{ |
| 3107 |
\@@_set:nnnnNn |
| 3108 |
{#1} { } {#2} { \q_@@_no_value } \l_@@_tmp_clist |
| 3109 |
{ |
| 3110 |
\bool_set_false:N \l_@@_only_known_bool |
| 3111 |
\bool_set_false:N \l_@@_exclude_bool |
| 3112 |
\bool_set_false:N \l_@@_selective_bool |
| 3113 |
} |
| 3114 |
} |
| 3115 |
\cs_generate_variant:Nn \keys_set:nn { nV , nv , ne , no , nx } |
| 3116 |
% \end{macrocode} |
| 3117 |
% \end{macro} |
| 3118 |
% |
| 3119 |
% \begin{macro} |
| 3120 |
% { |
| 3121 |
% \keys_set_known:nnnN, \keys_set_known:nVnN, |
| 3122 |
% \keys_set_known:nvnN, \keys_set_known:nenN, |
| 3123 |
% \keys_set_known:nonN |
| 3124 |
% } |
| 3125 |
% \begin{macro} |
| 3126 |
% { |
| 3127 |
% \keys_set_known:nnN, \keys_set_known:nVN, |
| 3128 |
% \keys_set_known:nvN, \keys_set_known:neN, |
| 3129 |
% \keys_set_known:noN |
| 3130 |
% } |
| 3131 |
% \begin{macro} |
| 3132 |
% { |
| 3133 |
% \keys_set_known:nn, \keys_set_known:nV, |
| 3134 |
% \keys_set_known:nv, \keys_set_known:ne, |
| 3135 |
% \keys_set_known:no |
| 3136 |
% } |
| 3137 |
% Simply set the right variables. |
| 3138 |
% \begin{macrocode} |
| 3139 |
\cs_new_protected:Npn \keys_set_known:nnnN #1#2#3#4 |
| 3140 |
{ |
| 3141 |
\@@_set:nnnnNn |
| 3142 |
{#1} { } {#2} {#3} #4 |
| 3143 |
{ |
| 3144 |
\bool_set_true:N \l_@@_only_known_bool |
| 3145 |
\bool_set_false:N \l_@@_exclude_bool |
| 3146 |
\bool_set_false:N \l_@@_selective_bool |
| 3147 |
} |
| 3148 |
} |
| 3149 |
\cs_generate_variant:Nn \keys_set_known:nnnN { nV , nv , ne , no } |
| 3150 |
\cs_new_protected:Npn \keys_set_known:nnN #1#2#3 |
| 3151 |
{ \keys_set_known:nnnN {#1} {#2} { \q_@@_no_value } #3 } |
| 3152 |
\cs_generate_variant:Nn \keys_set_known:nnN { nV , nv , ne , no } |
| 3153 |
\cs_new_protected:Npn \keys_set_known:nn #1#2 |
| 3154 |
{ \keys_set_known:nnnN {#1} {#2} { \q_@@_no_value } \l_@@_tmp_clist } |
| 3155 |
\cs_generate_variant:Nn \keys_set_known:nn { nV , nv , ne , no } |
| 3156 |
% \end{macrocode} |
| 3157 |
% \end{macro} |
| 3158 |
% \end{macro} |
| 3159 |
% \end{macro} |
| 3160 |
% |
| 3161 |
% \begin{macro} |
| 3162 |
% { |
| 3163 |
% \keys_set_exclude_groups:nnnN, \keys_set_exclude_groups:nnVN, |
| 3164 |
% \keys_set_exclude_groups:nnvN, \keys_set_exclude_groups:nnoN |
| 3165 |
% } |
| 3166 |
% \begin{macro} |
| 3167 |
% { |
| 3168 |
% \keys_set_exclude_groups:nnnnN, \keys_set_exclude_groups:nnVnN, |
| 3169 |
% \keys_set_exclude_groups:nnvnN, \keys_set_exclude_groups:nnonN |
| 3170 |
% } |
| 3171 |
% \begin{macro} |
| 3172 |
% { |
| 3173 |
% \keys_set_exclude_groups:nnn, \keys_set_exclude_groups:nnV, |
| 3174 |
% \keys_set_exclude_groups:nnv, \keys_set_exclude_groups:nno |
| 3175 |
% } |
| 3176 |
% \begin{macro} |
| 3177 |
% { |
| 3178 |
% \keys_set_groups:nnnN, \keys_set_groups:nnVN, |
| 3179 |
% \keys_set_groups:nnvN, \keys_set_groups:nnoN |
| 3180 |
% } |
| 3181 |
% \begin{macro} |
| 3182 |
% { |
| 3183 |
% \keys_set_groups:nnnnN, \keys_set_groups:nnVnN, |
| 3184 |
% \keys_set_groups:nnvnN, \keys_set_groups:nnonN |
| 3185 |
% } |
| 3186 |
% \begin{macro} |
| 3187 |
% { |
| 3188 |
% \keys_set_groups:nnn, \keys_set_groups:nnV, |
| 3189 |
% \keys_set_groups:nnv, \keys_set_groups:nno |
| 3190 |
% } |
| 3191 |
% The same for (exclusion) groups. |
| 3192 |
% \begin{macrocode} |
| 3193 |
\cs_new_protected:Npn \keys_set_exclude_groups:nnnnN #1#2#3#4#5 |
| 3194 |
{ |
| 3195 |
\@@_set:nnnnNn |
| 3196 |
{#1} {#2} {#3} {#4} #5 |
| 3197 |
{ |
| 3198 |
\bool_set_false:N \l_@@_only_known_bool |
| 3199 |
\bool_set_true:N \l_@@_exclude_bool |
| 3200 |
\bool_set_true:N \l_@@_selective_bool |
| 3201 |
} |
| 3202 |
} |
| 3203 |
\cs_generate_variant:Nn \keys_set_exclude_groups:nnnnN { nnV , nnv , nno } |
| 3204 |
\cs_new_protected:Npn \keys_set_exclude_groups:nnnN #1#2#3#4 |
| 3205 |
{ \keys_set_exclude_groups:nnnnN {#1} {#2} {#3} { \q_@@_no_value } #4 } |
| 3206 |
\cs_generate_variant:Nn \keys_set_exclude_groups:nnnN { nnV , nnv , nno } |
| 3207 |
\cs_new_protected:Npn \keys_set_exclude_groups:nnn #1#2#3 |
| 3208 |
{ |
| 3209 |
\keys_set_exclude_groups:nnnnN {#1} {#2} {#3} |
| 3210 |
{ \q_@@_no_value } \l_@@_tmp_clist |
| 3211 |
} |
| 3212 |
\cs_generate_variant:Nn \keys_set_exclude_groups:nnn { nnV , nnv , nno } |
| 3213 |
\cs_new_protected:Npn \keys_set_groups:nnnnN #1#2#3#4#5 |
| 3214 |
{ |
| 3215 |
\@@_set:nnnnNn |
| 3216 |
{#1} {#2} {#3} {#4} #5 |
| 3217 |
{ |
| 3218 |
\bool_set_false:N \l_@@_only_known_bool |
| 3219 |
\bool_set_false:N \l_@@_exclude_bool |
| 3220 |
\bool_set_true:N \l_@@_selective_bool |
| 3221 |
} |
| 3222 |
} |
| 3223 |
\cs_generate_variant:Nn \keys_set_groups:nnnnN { nnV , nnv , nno } |
| 3224 |
\cs_new_protected:Npn \keys_set_groups:nnnN #1#2#3#4 |
| 3225 |
{ \keys_set_groups:nnnnN {#1} {#2} {#3} { \q_@@_no_value } #4 } |
| 3226 |
\cs_generate_variant:Nn \keys_set_groups:nnnN { nnV , nnv , nno } |
| 3227 |
\cs_new_protected:Npn \keys_set_groups:nnn #1#2#3 |
| 3228 |
{ |
| 3229 |
\keys_set_groups:nnnnN {#1} {#2} {#3} |
| 3230 |
{ \q_@@_no_value } \l_@@_tmp_clist |
| 3231 |
} |
| 3232 |
\cs_generate_variant:Nn \keys_set_groups:nnn { nnV , nnv , nno } |
| 3233 |
% \end{macrocode} |
| 3234 |
% \end{macro} |
| 3235 |
% \end{macro} |
| 3236 |
% \end{macro} |
| 3237 |
% \end{macro} |
| 3238 |
% \end{macro} |
| 3239 |
% \end{macro} |
| 3240 |
% |
| 3241 |
% \begin{macro}{\keys_precompile:nnN} |
| 3242 |
% A simple wrapper. |
| 3243 |
% \begin{macrocode} |
| 3244 |
\cs_new_protected:Npn \keys_precompile:nnN #1#2#3 |
| 3245 |
{ |
| 3246 |
\bool_set_true:N \l_@@_precompile_bool |
| 3247 |
\tl_clear:N \l_@@_precompile_tl |
| 3248 |
\keys_set:nn {#1} {#2} |
| 3249 |
\bool_set_false:N \l_@@_precompile_bool |
| 3250 |
\tl_set_eq:NN #3 \l_@@_precompile_tl |
| 3251 |
} |
| 3252 |
% \end{macrocode} |
| 3253 |
% \end{macro} |
| 3254 |
% |
| 3255 |
% \begin{macro}{\@@_set_keyval:n, \@@_set_keyval:nn} |
| 3256 |
% \begin{macro}{\@@_set_keyval:nnn, \@@_set_keyval:onn} |
| 3257 |
% \begin{macro}{\@@_find_key_module:wNN} |
| 3258 |
% \begin{macro} |
| 3259 |
% { |
| 3260 |
% \@@_find_key_module_auxi:Nw , |
| 3261 |
% \@@_find_key_module_auxii:Nw , |
| 3262 |
% \@@_find_key_module_auxiii:Nn , |
| 3263 |
% \@@_find_key_module_auxiv:Nw , |
| 3264 |
% \@@_find_key_module_auxv:Nw |
| 3265 |
% } |
| 3266 |
% \begin{macro}{\@@_set_selective:} |
| 3267 |
% A shared system once again. First, set the current path and add a |
| 3268 |
% default if needed. There are then checks to see if a value is |
| 3269 |
% required or forbidden. If everything passes, move on to execute the |
| 3270 |
% code. |
| 3271 |
% \begin{macrocode} |
| 3272 |
\cs_new_protected:Npn \@@_set_keyval:n #1 |
| 3273 |
{ |
| 3274 |
\bool_set_true:N \l_@@_no_value_bool |
| 3275 |
\@@_set_keyval:onn \l_@@_module_str {#1} { } |
| 3276 |
} |
| 3277 |
\cs_new_protected:Npn \@@_set_keyval:nn #1#2 |
| 3278 |
{ |
| 3279 |
\bool_set_false:N \l_@@_no_value_bool |
| 3280 |
\@@_set_keyval:onn \l_@@_module_str {#1} {#2} |
| 3281 |
} |
| 3282 |
% \end{macrocode} |
| 3283 |
% The key path here can be fully defined, after which there is a search |
| 3284 |
% for the key and module names: the user may have passed them with part |
| 3285 |
% of what is actually the module (for our purposes) in the key name. As |
| 3286 |
% that happens on a per-key basis, we use the stack approach to restore |
| 3287 |
% the module name without a group. |
| 3288 |
% \begin{macrocode} |
| 3289 |
\cs_new_protected:Npn \@@_set_keyval:nnn #1#2#3 |
| 3290 |
{ |
| 3291 |
\__kernel_tl_set:Nx \l_keys_path_str |
| 3292 |
{ |
| 3293 |
\tl_if_blank:nF {#1} |
| 3294 |
{ #1 / } |
| 3295 |
\@@_trim_spaces:n {#2} |
| 3296 |
} |
| 3297 |
\str_clear:N \l_@@_module_str |
| 3298 |
\str_clear:N \l_@@_inherit_str |
| 3299 |
\exp_after:wN \@@_find_key_module:wNN \l_keys_path_str \s_@@_stop |
| 3300 |
\l_@@_module_str \l_keys_key_str |
| 3301 |
\str_set:Ne \l_keys_path_str |
| 3302 |
{ |
| 3303 |
\l_@@_module_str |
| 3304 |
\str_if_empty:NF \l_@@_module_str { / } |
| 3305 |
\l_keys_key_str |
| 3306 |
} |
| 3307 |
\tl_set_eq:NN \l_keys_key_tl \l_keys_key_str |
| 3308 |
\@@_value_or_default:n {#3} |
| 3309 |
\bool_if:NTF \l_@@_selective_bool |
| 3310 |
\@@_set_selective: |
| 3311 |
\@@_execute: |
| 3312 |
\str_set:Nn \l_@@_module_str {#1} |
| 3313 |
} |
| 3314 |
\cs_generate_variant:Nn \@@_set_keyval:nnn { o } |
| 3315 |
% \end{macrocode} |
| 3316 |
% This function uses \cs{cs_set_nopar:Npe} internally for performance reasons, |
| 3317 |
% the argument |#1| is already a string in every usage, so turning it into a |
| 3318 |
% string again seems unnecessary. The expansion part of a key is always stored |
| 3319 |
% in the same place, so that is not passed along. |
| 3320 |
% \begin{macrocode} |
| 3321 |
\cs_new_protected:Npn \@@_find_key_module:wNN #1 \s_@@_stop #2#3 |
| 3322 |
{ |
| 3323 |
\@@_find_key_module_auxi:Nw #2 #1 \s_@@_nil \@@_find_key_module_auxii:Nw |
| 3324 |
/ \s_@@_nil \@@_find_key_module_auxiv:Nw #3 |
| 3325 |
} |
| 3326 |
\cs_new_protected:Npn \@@_find_key_module_auxi:Nw #1 #2 / #3 \s_@@_nil #4 |
| 3327 |
{ |
| 3328 |
#4 #1 #2 \s_@@_mark #3 \s_@@_nil #4 |
| 3329 |
} |
| 3330 |
\cs_new_protected:Npn \@@_find_key_module_auxii:Nw |
| 3331 |
#1 #2 \s_@@_mark #3 \s_@@_nil \@@_find_key_module_auxii:Nw |
| 3332 |
{ |
| 3333 |
\cs_set_nopar:Npe #1 { \tl_if_empty:NF #1 { #1 / } #2 } |
| 3334 |
\@@_find_key_module_auxi:Nw #1 #3 \s_@@_nil \@@_find_key_module_auxiii:Nw |
| 3335 |
} |
| 3336 |
\cs_new_protected:Npn \@@_find_key_module_auxiii:Nw #1 #2 \s_@@_mark |
| 3337 |
{ |
| 3338 |
\cs_set_nopar:Npe #1 { \tl_if_empty:NF #1 { #1 / } #2 } |
| 3339 |
\@@_find_key_module_auxi:Nw #1 |
| 3340 |
} |
| 3341 |
\cs_new_protected:Npe \@@_find_key_module_auxiv:Nw |
| 3342 |
#1 #2 \s_@@_nil #3 \s_@@_mark |
| 3343 |
\s_@@_nil \@@_find_key_module_auxiv:Nw #4 |
| 3344 |
{ |
| 3345 |
\exp_not:N \@@_find_key_module_auxv:Nw #4 |
| 3346 |
#2 \token_to_str:N : n \token_to_str:N : \s_@@_mark |
| 3347 |
} |
| 3348 |
\use:e |
| 3349 |
{ |
| 3350 |
\cs_new_protected:Npn \exp_not:N \@@_find_key_module_auxv:Nw |
| 3351 |
#1 #2 \token_to_str:N : #3 \token_to_str:N : #4 \s_@@_mark |
| 3352 |
} |
| 3353 |
{ |
| 3354 |
\cs_set_nopar:Npn #1 {#2} |
| 3355 |
\cs_set_nopar:Npn \l_@@_exp_str {#3} |
| 3356 |
} |
| 3357 |
% \end{macrocode} |
| 3358 |
% If selective setting is active, there are a number of possible sub-cases |
| 3359 |
% to consider. The key name may not be known at all or if it is, it may not |
| 3360 |
% have any groups assigned. There is then the question of whether the |
| 3361 |
% selection is opt-in or opt-out. |
| 3362 |
% \begin{macrocode} |
| 3363 |
\cs_new_protected:Npn \@@_set_selective: |
| 3364 |
{ |
| 3365 |
\cs_if_exist:cTF { \c_@@_groups_root_str \l_keys_path_str } |
| 3366 |
{ |
| 3367 |
\clist_set_eq:Nc \l_@@_groups_clist |
| 3368 |
{ \c_@@_groups_root_str \l_keys_path_str } |
| 3369 |
\@@_check_groups: |
| 3370 |
} |
| 3371 |
{ |
| 3372 |
\bool_if:NTF \l_@@_exclude_bool |
| 3373 |
\@@_execute: |
| 3374 |
\@@_store_unused: |
| 3375 |
} |
| 3376 |
} |
| 3377 |
% \end{macrocode} |
| 3378 |
% In the case where selective setting requires a comparison of the list |
| 3379 |
% of groups which apply to a key with the list of those which have been |
| 3380 |
% set active. That requires two mappings, and again a different outcome |
| 3381 |
% depending on whether opt-in or opt-out is set. |
| 3382 |
% It is safe to use \cs{clist_if_in:NnTF} because |
| 3383 |
% both \cs{l_@@_selective_clist} and \cs{l_@@_groups_clist} contain the |
| 3384 |
% groups as strings, without leading/trailing spaces in any item, |
| 3385 |
% since the \pkg{l3clist} functions were applied to the result of |
| 3386 |
% applying \cs{tl_to_str:n}. |
| 3387 |
% \begin{macrocode} |
| 3388 |
\cs_new_protected:Npn \@@_check_groups: |
| 3389 |
{ |
| 3390 |
\bool_set_false:N \l_@@_tmp_bool |
| 3391 |
\clist_map_inline:Nn \l_@@_selective_clist |
| 3392 |
{ |
| 3393 |
\clist_if_in:NnT \l_@@_groups_clist {##1} |
| 3394 |
{ |
| 3395 |
\bool_set_true:N \l_@@_tmp_bool |
| 3396 |
\clist_map_break: |
| 3397 |
} |
| 3398 |
} |
| 3399 |
\bool_if:NTF \l_@@_tmp_bool |
| 3400 |
{ |
| 3401 |
\bool_if:NTF \l_@@_exclude_bool |
| 3402 |
\@@_store_unused: |
| 3403 |
\@@_execute: |
| 3404 |
} |
| 3405 |
{ |
| 3406 |
\bool_if:NTF \l_@@_exclude_bool |
| 3407 |
\@@_execute: |
| 3408 |
\@@_store_unused: |
| 3409 |
} |
| 3410 |
} |
| 3411 |
% \end{macrocode} |
| 3412 |
% \end{macro} |
| 3413 |
% \end{macro} |
| 3414 |
% \end{macro} |
| 3415 |
% \end{macro} |
| 3416 |
% \end{macro} |
| 3417 |
% |
| 3418 |
% \begin{macro}{\@@_value_or_default:n} |
| 3419 |
% \begin{macro}{\@@_default_inherit:} |
| 3420 |
% \begin{macro} |
| 3421 |
% { |
| 3422 |
% \@@_value_set:Nn, \@@_value_set:No, \@@_value_set:NV, |
| 3423 |
% \@@_value_set:Nv, \@@_value_set:Ne, |
| 3424 |
% } |
| 3425 |
% \begin{macro}{\@@_value_set:NN, \@@_value_set:Nc} |
| 3426 |
% If a value is given, return it as |#1|, otherwise send a default if |
| 3427 |
% available. |
| 3428 |
% \begin{macrocode} |
| 3429 |
\cs_new_protected:Npn \@@_value_or_default:n #1 |
| 3430 |
{ |
| 3431 |
\bool_if:NTF \l_@@_no_value_bool |
| 3432 |
{ |
| 3433 |
\cs_if_exist:cTF { \c_@@_default_root_str \l_keys_path_str } |
| 3434 |
{ |
| 3435 |
\tl_set_eq:Nc |
| 3436 |
\l_keys_value_tl |
| 3437 |
{ \c_@@_default_root_str \l_keys_path_str } |
| 3438 |
} |
| 3439 |
{ |
| 3440 |
\tl_clear:N \l_keys_value_tl |
| 3441 |
\cs_if_exist:cT |
| 3442 |
{ \c_@@_inherit_root_str \@@_parent:o \l_keys_path_str } |
| 3443 |
{ \@@_default_inherit: } |
| 3444 |
} |
| 3445 |
} |
| 3446 |
{ |
| 3447 |
\cs_if_exist_use:cF { @@_value_set:N \l_@@_exp_str } |
| 3448 |
{ |
| 3449 |
\msg_error:nnV { keys } { unknown-expansion } \l_@@_exp_str |
| 3450 |
\use_none:nn |
| 3451 |
} |
| 3452 |
\l_keys_value_tl {#1} |
| 3453 |
} |
| 3454 |
} |
| 3455 |
\cs_new_protected:Npn \@@_default_inherit: |
| 3456 |
{ |
| 3457 |
\clist_map_inline:cn |
| 3458 |
{ \c_@@_inherit_root_str \@@_parent:o \l_keys_path_str } |
| 3459 |
{ |
| 3460 |
\cs_if_exist:cT |
| 3461 |
{ \c_@@_default_root_str ##1 / \l_keys_key_str } |
| 3462 |
{ |
| 3463 |
\tl_set_eq:Nc |
| 3464 |
\l_keys_value_tl |
| 3465 |
{ \c_@@_default_root_str ##1 / \l_keys_key_str } |
| 3466 |
\clist_map_break: |
| 3467 |
} |
| 3468 |
} |
| 3469 |
} |
| 3470 |
\cs_new_eq:NN \@@_value_set:Nn \tl_set:Nn |
| 3471 |
\cs_generate_variant:Nn \@@_value_set:Nn { No , NV , Nv , Ne } |
| 3472 |
\cs_new_protected:Npn \@@_value_set:NN #1#2 { \tl_set:Nn #1 {#2} } |
| 3473 |
\cs_generate_variant:Nn \@@_value_set:NN { Nc } |
| 3474 |
% \end{macrocode} |
| 3475 |
% \end{macro} |
| 3476 |
% \end{macro} |
| 3477 |
% \end{macro} |
| 3478 |
% \end{macro} |
| 3479 |
% |
| 3480 |
% \begin{macro}{\@@_execute:, \@@_execute_inherit:, \@@_execute_unknown:} |
| 3481 |
% \begin{macro}{\@@_execute_inherit:n} |
| 3482 |
% \begin{macro}[EXP]{\@@_execute:nn, \@@_execute:no} |
| 3483 |
% \begin{macro}{\@@_store_unused:,\@@_store_unused_aux:} |
| 3484 |
% Actually executing a key is done in two parts. First, look for the |
| 3485 |
% key itself, then look for the \texttt{unknown} key with the same |
| 3486 |
% path. If both of these fail, complain. What exactly happens if a key |
| 3487 |
% is unknown depends on whether unknown keys are being skipped or if |
| 3488 |
% an error should be raised. |
| 3489 |
% \begin{macrocode} |
| 3490 |
\cs_new_protected:Npn \@@_execute: |
| 3491 |
{ |
| 3492 |
\cs_if_exist:cTF { \c_@@_code_root_str \l_keys_path_str } |
| 3493 |
{ |
| 3494 |
\cs_if_exist_use:c { \c_@@_check_root_str \l_keys_path_str } |
| 3495 |
\@@_execute:no \l_keys_path_str \l_keys_value_tl |
| 3496 |
} |
| 3497 |
{ |
| 3498 |
\cs_if_exist:cTF |
| 3499 |
{ \c_@@_inherit_root_str \@@_parent:o \l_keys_path_str } |
| 3500 |
{ \@@_execute_inherit: } |
| 3501 |
{ \@@_execute_unknown: } |
| 3502 |
} |
| 3503 |
} |
| 3504 |
% \end{macrocode} |
| 3505 |
% Dealing with inheritance and recursion makes life a little interesting. |
| 3506 |
% \begin{macrocode} |
| 3507 |
\cs_new_protected:Npn \@@_execute_inherit: |
| 3508 |
{ |
| 3509 |
\bool_set_false:N \l_@@_inherit_bool |
| 3510 |
\clist_map_inline:cn |
| 3511 |
{ \c_@@_inherit_root_str \@@_parent:o \l_keys_path_str } |
| 3512 |
{ \@@_execute_inherit:n {##1} } |
| 3513 |
\bool_if:NF \l_@@_inherit_bool |
| 3514 |
{ \@@_execute_unknown: } |
| 3515 |
} |
| 3516 |
\cs_new_protected:Npn \@@_execute_inherit:n #1 |
| 3517 |
{ |
| 3518 |
\cs_if_exist:cTF |
| 3519 |
{ \c_@@_code_root_str #1 / \l_keys_key_str } |
| 3520 |
{ |
| 3521 |
\str_set:Nn \l_@@_inherit_str {#1} |
| 3522 |
\cs_if_exist_use:c { \c_@@_check_root_str #1 / \l_keys_key_str } |
| 3523 |
\@@_execute:no { #1 / \l_keys_key_str } \l_keys_value_tl |
| 3524 |
\clist_map_break:n |
| 3525 |
{ \bool_set_true:N \l_@@_inherit_bool } |
| 3526 |
} |
| 3527 |
{ |
| 3528 |
\cs_if_exist:cT |
| 3529 |
{ \c_@@_inherit_root_str #1 } |
| 3530 |
{ |
| 3531 |
\clist_map_inline:cn { \c_@@_inherit_root_str #1 } |
| 3532 |
{ \@@_execute_inherit:n {##1} } |
| 3533 |
\bool_if:NT \l_@@_inherit_bool |
| 3534 |
{ \clist_map_break: } |
| 3535 |
} |
| 3536 |
} |
| 3537 |
} |
| 3538 |
\cs_new_protected:Npn \@@_execute_unknown: |
| 3539 |
{ |
| 3540 |
\bool_if:NTF \l_@@_only_known_bool |
| 3541 |
{ \@@_store_unused: } |
| 3542 |
{ |
| 3543 |
\cs_if_exist:cTF |
| 3544 |
{ \c_@@_code_root_str \l_@@_module_str / unknown } |
| 3545 |
{ |
| 3546 |
\bool_if:NT \l_@@_no_value_bool |
| 3547 |
{ |
| 3548 |
\cs_if_exist:cT |
| 3549 |
{ \c_@@_default_root_str \l_@@_module_str / unknown } |
| 3550 |
{ |
| 3551 |
\tl_set_eq:Nc |
| 3552 |
\l_keys_value_tl |
| 3553 |
{ \c_@@_default_root_str \l_@@_module_str / unknown } |
| 3554 |
} |
| 3555 |
} |
| 3556 |
\@@_execute:no { \l_@@_module_str / unknown } \l_keys_value_tl |
| 3557 |
} |
| 3558 |
{ |
| 3559 |
\msg_error:nnee { keys } { unknown } |
| 3560 |
\l_keys_path_str \l_@@_module_str |
| 3561 |
} |
| 3562 |
} |
| 3563 |
} |
| 3564 |
% \end{macrocode} |
| 3565 |
% A key's code is in the control sequence with csname |
| 3566 |
% \cs{c_@@_code_root_str} |#1|. We expand it once to get the |
| 3567 |
% replacement text (with argument |#2|) and call \cs{use:n} |
| 3568 |
% with this replacement as its argument. This ensures that any |
| 3569 |
% undefined control sequence error in the key's code will lead to an |
| 3570 |
% error message of the form |<argument>|\ldots{}\meta{control |
| 3571 |
% sequence} in which one can read the (undefined) \meta{control |
| 3572 |
% sequence} in full, rather than an error message that starts with the |
| 3573 |
% potentially very long key name, which would make the (undefined) |
| 3574 |
% \meta{control sequence} be truncated or sometimes completely hidden. |
| 3575 |
% See \url{https://github.com/latex3/latex2e/issues/351}. |
| 3576 |
% \begin{macrocode} |
| 3577 |
\cs_new:Npn \@@_execute:nn #1#2 |
| 3578 |
{ \@@_execute:no {#1} { \prg_do_nothing: #2 } } |
| 3579 |
\cs_new:Npn \@@_execute:no #1#2 |
| 3580 |
{ |
| 3581 |
\exp_args:NNo \exp_args:No \use:n |
| 3582 |
{ |
| 3583 |
\cs:w \c_@@_code_root_str #1 \exp_after:wN \cs_end: |
| 3584 |
\exp_after:wN {#2} |
| 3585 |
} |
| 3586 |
} |
| 3587 |
% \end{macrocode} |
| 3588 |
% When there is no relative path, things here are easy: just save the key |
| 3589 |
% name and value. When we are working with a relative path, first we |
| 3590 |
% need to turn it into a string: that can't happen earlier as we need |
| 3591 |
% to store \cs{q_@@_no_value}. Then, use a standard delimited approach to fish |
| 3592 |
% out the partial path. |
| 3593 |
% \begin{macrocode} |
| 3594 |
\cs_new_protected:Npn \@@_store_unused: |
| 3595 |
{ |
| 3596 |
\@@_quark_if_no_value:NTF \l_@@_relative_tl |
| 3597 |
{ |
| 3598 |
\clist_put_right:Ne \l_@@_unused_clist |
| 3599 |
{ |
| 3600 |
\l_keys_key_str |
| 3601 |
\bool_if:NF \l_@@_no_value_bool |
| 3602 |
{ = { \exp_not:o \l_keys_value_tl } } |
| 3603 |
} |
| 3604 |
} |
| 3605 |
{ |
| 3606 |
\tl_if_empty:NTF \l_@@_relative_tl |
| 3607 |
{ |
| 3608 |
\clist_put_right:Ne \l_@@_unused_clist |
| 3609 |
{ |
| 3610 |
\l_keys_path_str |
| 3611 |
\bool_if:NF \l_@@_no_value_bool |
| 3612 |
{ = { \exp_not:o \l_keys_value_tl } } |
| 3613 |
} |
| 3614 |
} |
| 3615 |
{ \@@_store_unused_aux: } |
| 3616 |
} |
| 3617 |
} |
| 3618 |
\cs_new_protected:Npn \@@_store_unused_aux: |
| 3619 |
{ |
| 3620 |
\__kernel_tl_set:Nx \l_@@_relative_tl |
| 3621 |
{ \exp_args:No \@@_trim_spaces:n \l_@@_relative_tl } |
| 3622 |
\use:e |
| 3623 |
{ |
| 3624 |
\cs_set_protected:Npn \@@_store_unused:w |
| 3625 |
##1 \l_@@_relative_tl / |
| 3626 |
##2 \l_@@_relative_tl / |
| 3627 |
##3 \s_@@_stop |
| 3628 |
} |
| 3629 |
{ |
| 3630 |
\tl_if_blank:nF {##1} |
| 3631 |
{ |
| 3632 |
\msg_error:nnee { keys } { bad-relative-key-path } |
| 3633 |
\l_keys_path_str |
| 3634 |
\l_@@_relative_tl |
| 3635 |
} |
| 3636 |
\clist_put_right:Ne \l_@@_unused_clist |
| 3637 |
{ |
| 3638 |
\exp_not:n {##2} |
| 3639 |
\bool_if:NF \l_@@_no_value_bool |
| 3640 |
{ = { \exp_not:o \l_keys_value_tl } } |
| 3641 |
} |
| 3642 |
} |
| 3643 |
\use:e |
| 3644 |
{ |
| 3645 |
\@@_store_unused:w \l_keys_path_str |
| 3646 |
\l_@@_relative_tl / \l_@@_relative_tl / |
| 3647 |
\s_@@_stop |
| 3648 |
} |
| 3649 |
} |
| 3650 |
\cs_new_protected:Npn \@@_store_unused:w { } |
| 3651 |
% \end{macrocode} |
| 3652 |
% \end{macro} |
| 3653 |
% \end{macro} |
| 3654 |
% \end{macro} |
| 3655 |
% \end{macro} |
| 3656 |
% |
| 3657 |
% \begin{macro}[EXP]{\@@_choice_find:n} |
| 3658 |
% \begin{macro}[EXP]{\@@_choice_find:nn} |
| 3659 |
% \begin{macro}[EXP]{\@@_multichoice_find:n} |
| 3660 |
% Executing a choice has two parts. First, try the choice given, then |
| 3661 |
% if that fails call the unknown key. That always exists, as it is created |
| 3662 |
% when a choice is first made. So there is no need for any escape code. |
| 3663 |
% For multiple choices, the same code ends up used in a mapping. |
| 3664 |
% \begin{macrocode} |
| 3665 |
\cs_new:Npn \@@_choice_find:n #1 |
| 3666 |
{ |
| 3667 |
\str_if_empty:NTF \l_@@_inherit_str |
| 3668 |
{ \@@_choice_find:nn \l_keys_path_str {#1} } |
| 3669 |
{ |
| 3670 |
\@@_choice_find:nn |
| 3671 |
{ \l_@@_inherit_str / \l_keys_key_str } {#1} |
| 3672 |
} |
| 3673 |
} |
| 3674 |
\cs_new:Npn \@@_choice_find:nn #1#2 |
| 3675 |
{ |
| 3676 |
\cs_if_exist:cTF { \c_@@_code_root_str #1 / \@@_trim_spaces:n {#2} } |
| 3677 |
{ \@@_execute:nn { #1 / \@@_trim_spaces:n {#2} } {#2} } |
| 3678 |
{ \@@_execute:nn { #1 / unknown } {#2} } |
| 3679 |
} |
| 3680 |
\cs_new:Npn \@@_multichoice_find:n #1 |
| 3681 |
{ \clist_map_function:nN {#1} \@@_choice_find:n } |
| 3682 |
% \end{macrocode} |
| 3683 |
% \end{macro} |
| 3684 |
% \end{macro} |
| 3685 |
% \end{macro} |
| 3686 |
% |
| 3687 |
% \subsection{Utilities} |
| 3688 |
% |
| 3689 |
% \begin{macro}[EXP]{\@@_parent:o} |
| 3690 |
% \begin{macro}[EXP] |
| 3691 |
% { |
| 3692 |
% \@@_parent_auxi:w , |
| 3693 |
% \@@_parent_auxii:w , |
| 3694 |
% \@@_parent_auxiii:n , |
| 3695 |
% \@@_parent_auxiv:w |
| 3696 |
% } |
| 3697 |
% Used to strip off the ending part of the key path after the last~|/|. |
| 3698 |
% \begin{macrocode} |
| 3699 |
\cs_new:Npn \@@_parent:o #1 |
| 3700 |
{ |
| 3701 |
\exp_after:wN \@@_parent_auxi:w #1 \q_nil \@@_parent_auxii:w |
| 3702 |
/ \q_nil \@@_parent_auxiv:w |
| 3703 |
} |
| 3704 |
\cs_new:Npn \@@_parent_auxi:w #1 / #2 \q_nil #3 |
| 3705 |
{ |
| 3706 |
#3 { #1 } #2 \q_nil #3 |
| 3707 |
} |
| 3708 |
\cs_new:Npn \@@_parent_auxii:w #1 #2 \q_nil \@@_parent_auxii:w |
| 3709 |
{ |
| 3710 |
#1 \@@_parent_auxi:w #2 \q_nil \@@_parent_auxiii:n |
| 3711 |
} |
| 3712 |
\cs_new:Npn \@@_parent_auxiii:n #1 |
| 3713 |
{ |
| 3714 |
/ #1 \@@_parent_auxi:w |
| 3715 |
} |
| 3716 |
\cs_new:Npn \@@_parent_auxiv:w #1 \q_nil \@@_parent_auxiv:w |
| 3717 |
{ |
| 3718 |
} |
| 3719 |
% \end{macrocode} |
| 3720 |
% \end{macro} |
| 3721 |
% \end{macro} |
| 3722 |
% |
| 3723 |
% \begin{macro}[EXP]{\@@_trim_spaces:n} |
| 3724 |
% \begin{macro}[EXP] |
| 3725 |
% { |
| 3726 |
% \@@_trim_spaces_auxi:w , |
| 3727 |
% \@@_trim_spaces_auxii:w , |
| 3728 |
% \@@_trim_spaces_auxiii:w |
| 3729 |
% } |
| 3730 |
% Space stripping has to allow for the fact that the key here might have |
| 3731 |
% several parts, and spaces need to be stripped from each part. Since the key |
| 3732 |
% name is turned into a string groups can't be stripped accidentally and the |
| 3733 |
% precautions of \cs{tl_trim_spaces:n} aren't necessary, in this case it is |
| 3734 |
% much faster to just directly strip spaces around |/|. |
| 3735 |
% \begin{macrocode} |
| 3736 |
\group_begin: |
| 3737 |
\cs_set:Npn \@@_tmp:w #1 |
| 3738 |
{ |
| 3739 |
\cs_new:Npn \@@_trim_spaces:n ##1 |
| 3740 |
{ |
| 3741 |
\exp_after:wN \@@_trim_spaces_auxi:w \tl_to_str:n { / ##1 } / |
| 3742 |
\s_@@_nil \@@_trim_spaces_auxi:w |
| 3743 |
\s_@@_mark \@@_trim_spaces_auxii:w |
| 3744 |
#1 / #1 |
| 3745 |
\s_@@_nil \@@_trim_spaces_auxii:w |
| 3746 |
\s_@@_mark \@@_trim_spaces_auxiii:w |
| 3747 |
} |
| 3748 |
} |
| 3749 |
\@@_tmp:w { ~ } |
| 3750 |
\group_end: |
| 3751 |
\cs_new:Npn \@@_trim_spaces_auxi:w #1 ~ / #2 \s_@@_nil #3 |
| 3752 |
{ |
| 3753 |
#3 #1 / #2 \s_@@_nil #3 |
| 3754 |
} |
| 3755 |
\cs_new:Npn \@@_trim_spaces_auxii:w #1 / ~ #2 \s_@@_mark #3 |
| 3756 |
{ |
| 3757 |
#3 #1 / #2 \s_@@_mark #3 |
| 3758 |
} |
| 3759 |
\cs_new:Npn \@@_trim_spaces_auxiii:w |
| 3760 |
/ #1 / |
| 3761 |
\s_@@_nil \@@_trim_spaces_auxi:w |
| 3762 |
\s_@@_mark \@@_trim_spaces_auxii:w |
| 3763 |
/ |
| 3764 |
\s_@@_nil \@@_trim_spaces_auxii:w |
| 3765 |
\s_@@_mark \@@_trim_spaces_auxiii:w |
| 3766 |
{ |
| 3767 |
#1 |
| 3768 |
} |
| 3769 |
% \end{macrocode} |
| 3770 |
% \end{macro} |
| 3771 |
% \end{macro} |
| 3772 |
% |
| 3773 |
% \begin{macro}[EXP,pTF]{\keys_if_exist:nn} |
| 3774 |
% \begin{macro}[EXP]{\@@_if_exist:nn, \@@_if_exist:ee} |
| 3775 |
% A utility for others to see if a key exists. |
| 3776 |
% \begin{macrocode} |
| 3777 |
\prg_new_conditional:Npnn \keys_if_exist:nn #1#2 { p , T , F , TF } |
| 3778 |
{ |
| 3779 |
\@@_if_exist:ee |
| 3780 |
{ \@@_trim_spaces:n {#1} } |
| 3781 |
{ \@@_trim_spaces:n {#2} } |
| 3782 |
} |
| 3783 |
\prg_generate_conditional_variant:Nnn \keys_if_exist:nn { ne } { p , T , F , TF } |
| 3784 |
\cs_new:Npn \@@_if_exist:nn #1#2 |
| 3785 |
{ |
| 3786 |
\cs_if_exist:cTF |
| 3787 |
{ \c_@@_code_root_str #1 \tl_if_blank:nF {#1} { / } #2 } |
| 3788 |
{ \prg_return_true: } |
| 3789 |
{ \prg_return_false: } |
| 3790 |
} |
| 3791 |
\cs_generate_variant:Nn \@@_if_exist:nn { ee } |
| 3792 |
% \end{macrocode} |
| 3793 |
% \end{macro} |
| 3794 |
% \end{macro} |
| 3795 |
% |
| 3796 |
% \begin{macro}[EXP,pTF]{\keys_if_choice_exist:nnn} |
| 3797 |
% \begin{macro}[EXP]{\@@_if_exist:nnn, \@@_if_exist:eee} |
| 3798 |
% Just an alternative view on \cs{keys_if_exist:nnTF}. |
| 3799 |
% \begin{macrocode} |
| 3800 |
\prg_new_conditional:Npnn \keys_if_choice_exist:nnn #1#2#3 |
| 3801 |
{ p , T , F , TF } |
| 3802 |
{ |
| 3803 |
\@@_if_exist:eee |
| 3804 |
{ \@@_trim_spaces:n {#1} } |
| 3805 |
{ \@@_trim_spaces:n {#2} } |
| 3806 |
{ \@@_trim_spaces:n {#3} } |
| 3807 |
} |
| 3808 |
\cs_new:Npn \@@_if_exist:nnn #1#2#3 |
| 3809 |
{ |
| 3810 |
\cs_if_exist:cTF |
| 3811 |
{ |
| 3812 |
\c_@@_code_root_str |
| 3813 |
#1 \tl_if_blank:nF {#1} { / } |
| 3814 |
#2 \tl_if_blank:nF {#2} { / } |
| 3815 |
#3 |
| 3816 |
} |
| 3817 |
{ \prg_return_true: } |
| 3818 |
{ \prg_return_false: } |
| 3819 |
} |
| 3820 |
\cs_generate_variant:Nn \@@_if_exist:nnn { eee } |
| 3821 |
% \end{macrocode} |
| 3822 |
% \end{macro} |
| 3823 |
% \end{macro} |
| 3824 |
% |
| 3825 |
% \begin{macro}{\keys_show:nn, \keys_log:nn} |
| 3826 |
% \begin{macro}{\@@_show:Nnn, \@@_show_aux:Nnn, , \@@_show_aux:Nee} |
| 3827 |
% \begin{macro}{\@@_show:n} |
| 3828 |
% \begin{macro}{\@@_show:w} |
| 3829 |
% \begin{macro}{\@@_show:Nw} |
| 3830 |
% To show a key, show its code using a message. |
| 3831 |
% \begin{macrocode} |
| 3832 |
\cs_new_protected:Npn \keys_show:nn |
| 3833 |
{ \@@_show:Nnn \msg_show:nneeee } |
| 3834 |
\cs_new_protected:Npn \keys_log:nn |
| 3835 |
{ \@@_show:Nnn \msg_log:nneeee } |
| 3836 |
\cs_new_protected:Npn \@@_show:Nnn #1#2#3 |
| 3837 |
{ |
| 3838 |
\@@_show_aux:Nee |
| 3839 |
#1 |
| 3840 |
{ \@@_trim_spaces:n {#2} } |
| 3841 |
{ \@@_trim_spaces:n {#3} } |
| 3842 |
} |
| 3843 |
\cs_new_protected:Npn \@@_show_aux:Nnn #1#2#3 |
| 3844 |
{ |
| 3845 |
#1 { keys } { show-key } |
| 3846 |
{ #2 \tl_if_blank:nF {#2} { / } #3 } |
| 3847 |
{ |
| 3848 |
\keys_if_exist:nnT {#2} {#3} |
| 3849 |
{ |
| 3850 |
\exp_args:Nnf \msg_show_item_unbraced:nn { code } |
| 3851 |
{ |
| 3852 |
\exp_args:Ne \@@_show:n |
| 3853 |
{ |
| 3854 |
\exp_args:Nc \cs_replacement_spec:N |
| 3855 |
{ |
| 3856 |
\c_@@_code_root_str |
| 3857 |
#2 \tl_if_blank:nF {#2} { / } #3 |
| 3858 |
} |
| 3859 |
} |
| 3860 |
} |
| 3861 |
} |
| 3862 |
} |
| 3863 |
{ } { } |
| 3864 |
} |
| 3865 |
\cs_generate_variant:Nn \@@_show_aux:Nnn { Nee } |
| 3866 |
\cs_new:Npe \@@_show:n #1 |
| 3867 |
{ |
| 3868 |
\exp_not:N \@@_show:w |
| 3869 |
#1 |
| 3870 |
\tl_to_str:n { \@@_precompile:n } |
| 3871 |
#1 |
| 3872 |
\tl_to_str:n { \@@_precompile:n } |
| 3873 |
\exp_not:N \s_@@_stop |
| 3874 |
} |
| 3875 |
\use:e |
| 3876 |
{ |
| 3877 |
\cs_new:Npn \exp_not:N \@@_show:w |
| 3878 |
#1 \tl_to_str:n { \@@_precompile:n } |
| 3879 |
#2 \tl_to_str:n { \@@_precompile:n } |
| 3880 |
#3 \exp_not:N \s_@@_stop |
| 3881 |
} |
| 3882 |
{ |
| 3883 |
\tl_if_blank:nTF {#2} |
| 3884 |
{#1} |
| 3885 |
{ \@@_show:Nw #2 \s_@@_stop } |
| 3886 |
} |
| 3887 |
\use:e |
| 3888 |
{ |
| 3889 |
\cs_new:Npn \exp_not:N \@@_show:Nw #1#2 |
| 3890 |
\c_right_brace_str \exp_not:N \s_@@_stop |
| 3891 |
} |
| 3892 |
{#2} |
| 3893 |
% \end{macrocode} |
| 3894 |
% \end{macro} |
| 3895 |
% \end{macro} |
| 3896 |
% \end{macro} |
| 3897 |
% \end{macro} |
| 3898 |
% \end{macro} |
| 3899 |
% |
| 3900 |
% \subsection{Messages} |
| 3901 |
% |
| 3902 |
% For when there is a need to complain. |
| 3903 |
% \begin{macrocode} |
| 3904 |
\msg_new:nnnn { keys } { bad-relative-key-path } |
| 3905 |
{ The~key~'#1'~is~not~inside~the~'#2'~path. } |
| 3906 |
{ The~key~'#1'~cannot~be~expressed~relative~to~path~'#2'. } |
| 3907 |
\msg_new:nnnn { keys } { boolean-values-only } |
| 3908 |
{ Key~'#1'~accepts~boolean~values~only. } |
| 3909 |
{ The~key~'#1'~only~accepts~the~values~'true'~and~'false'. } |
| 3910 |
\msg_new:nnnn { keys } { choice-unknown } |
| 3911 |
{ Key~'#1'~accepts~only~a~fixed~set~of~choices. } |
| 3912 |
{ |
| 3913 |
The~key~'#1'~only~accepts~predefined~values,~ |
| 3914 |
and~'#2'~is~not~one~of~these. |
| 3915 |
} |
| 3916 |
\msg_new:nnnn { keys } { unknown } |
| 3917 |
{ The~key~'#1'~is~unknown~and~is~being~ignored. } |
| 3918 |
{ |
| 3919 |
The~module~'#2'~does~not~have~a~key~called~'#1'.\\ |
| 3920 |
Check~that~you~have~spelled~the~key~name~correctly. |
| 3921 |
} |
| 3922 |
\msg_new:nnnn { keys } { unknown-expansion } |
| 3923 |
{ The~value~expansion~'#1'~is~unknown. } |
| 3924 |
{ |
| 3925 |
Key~values~can~only~be~expanded~using~one~of~the~pre-defined~methods:~ |
| 3926 |
n,~o,~V,~v,~e,~N~or~c. |
| 3927 |
} |
| 3928 |
\msg_new:nnnn { keys } { nested-choice-key } |
| 3929 |
{ Attempt~to~define~'#1'~as~a~nested~choice~key. } |
| 3930 |
{ |
| 3931 |
The~key~'#1'~cannot~be~defined~as~a~choice~as~the~parent~key~'#2'~is~ |
| 3932 |
itself~a~choice. |
| 3933 |
} |
| 3934 |
\msg_new:nnnn { keys } { value-forbidden } |
| 3935 |
{ The~key~'#1'~does~not~take~a~value. } |
| 3936 |
{ |
| 3937 |
The~key~'#1'~should~be~given~without~a~value.\\ |
| 3938 |
The~value~'#2'~was~present:~the~key~will~be~ignored. |
| 3939 |
} |
| 3940 |
\msg_new:nnnn { keys } { value-required } |
| 3941 |
{ The~key~'#1'~requires~a~value. } |
| 3942 |
{ |
| 3943 |
The~key~'#1'~must~have~a~value.\\ |
| 3944 |
No~value~was~present:~the~key~will~be~ignored. |
| 3945 |
} |
| 3946 |
\msg_new:nnn { keys } { show-key } |
| 3947 |
{ |
| 3948 |
The~key~#1~ |
| 3949 |
\tl_if_empty:nTF {#2} |
| 3950 |
{ is~undefined. } |
| 3951 |
{ has~the~properties: #2 . } |
| 3952 |
} |
| 3953 |
\prop_gput:Nnn \g_msg_module_name_prop { keys } { LaTeX } |
| 3954 |
\prop_gput:Nnn \g_msg_module_type_prop { keys } { } |
| 3955 |
% \end{macrocode} |
| 3956 |
% |
| 3957 |
% \begin{macrocode} |
| 3958 |
%</code> |
| 3959 |
% \end{macrocode} |
| 3960 |
% |
| 3961 |
%\end{implementation} |
| 3962 |
% |
| 3963 |
%\PrintIndex |