Debian Codegraph @

texmf-dist/source/latex-dev/l3kernel/l3keys.dtx

raw
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-26}
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}. This function does \emph{not} examine
993 % inherited keys: the key only exists if defined explicitly.
994 % \end{function}
995 %
996 % \begin{function}[added = 2011-08-21,EXP,pTF, updated = 2017-11-14]
997 % {\keys_if_choice_exist:nnn}
998 % \begin{syntax}
999 % \cs{keys_if_choice_exist_p:nnn} \Arg{module} \Arg{key} \Arg{choice} \\
1000 % \cs{keys_if_choice_exist:nnnTF} \Arg{module} \Arg{key} \Arg{choice} \Arg{true code} \Arg{false code}
1001 % \end{syntax}
1002 % Tests if the \meta{choice} is defined for the \meta{key} within the
1003 % \meta{module}, i.e., if any code has been defined for
1004 % \meta{key}/\meta{choice}. The test is \texttt{false} if the \meta{key}
1005 % itself is not defined.
1006 % \end{function}
1007 %
1008 % \begin{function}[updated = 2015-08-09]{\keys_show:nn}
1009 % \begin{syntax}
1010 % \cs{keys_show:nn} \Arg{module} \Arg{key}
1011 % \end{syntax}
1012 % Displays in the terminal
1013 % the information associated to the \meta{key} for a \meta{module},
1014 % including the function which is used to actually implement it.
1015 % \end{function}
1016 %
1017 % \begin{function}[added = 2014-08-22, updated = 2015-08-09]{\keys_log:nn}
1018 % \begin{syntax}
1019 % \cs{keys_log:nn} \Arg{module} \Arg{key}
1020 % \end{syntax}
1021 % Writes in the log file the information associated to the \meta{key}
1022 % for a \meta{module}. See also \cs{keys_show:nn} which displays the
1023 % result in the terminal.
1024 % \end{function}
1025 %
1026 % \section{Low-level interface for parsing key--val lists}
1027 %
1028 % To re-cap from earlier, a key--value list is input of the form
1029 % \begin{verbatim}
1030 % KeyOne = ValueOne ,
1031 % KeyTwo = ValueTwo ,
1032 % KeyThree
1033 % \end{verbatim}
1034 % where each key--value pair is separated by a comma from the rest of
1035 % the list, and each key--value pair does not necessarily contain an
1036 % equals sign or a value! Processing this type of input correctly
1037 % requires a number of careful steps, to correctly account for
1038 % braces, spaces and the category codes of separators.
1039 %
1040 % While the functions described earlier are used as a high-level interface
1041 % for processing such input, in special circumstances you may wish to use
1042 % a lower-level approach.
1043 % The low-level parsing system converts a \meta{key--value list}
1044 % into \meta{keys} and associated \meta{values}. After the parsing phase
1045 % is completed, the resulting keys and values (or keys alone) are
1046 % available for further processing. This processing is not carried out by the
1047 % low-level parser itself, and so the parser requires the names of
1048 % two functions along with the key--value list. One function is
1049 % needed to process key--value pairs (it receives two arguments),
1050 % and a second function is required for keys given without any value
1051 % (it is called with a single argument).
1052 %
1053 % The parser does not double |#| tokens or expand any input. Active
1054 % tokens |=| and |,| appearing at the outer level of braces are converted
1055 % to category \enquote{other} (12) so that the parser does not \enquote{miss}
1056 % any due to category code changes. Spaces are removed from the ends
1057 % of the keys and values. Keys and values which are given in braces
1058 % have exactly one set removed (after space trimming), thus
1059 % \begin{verbatim}
1060 % key = {value here},
1061 % \end{verbatim}
1062 % and
1063 % \begin{verbatim}
1064 % key = value here,
1065 % \end{verbatim}
1066 % are treated identically.
1067 %
1068 % \begin{function}[rEXP, added=2020-12-19, updated = 2021-05-10]
1069 % {\keyval_parse:nnn, \keyval_parse:nnV, \keyval_parse:nnv}
1070 % \begin{syntax}
1071 % \cs{keyval_parse:nnn} \Arg{code_1} \Arg{code_2} \Arg{key--value list}
1072 % \end{syntax}
1073 % Parses the \meta{key--value list} into a series of \meta{keys} and
1074 % associated \meta{values}, or keys alone (if no \meta{value} was
1075 % given). \meta{code_1} receives each \meta{key} (with no \meta{value}) as a
1076 % trailing brace group, whereas \meta{code_2} is appended by two brace groups,
1077 % the \meta{key} and \meta{value}.
1078 % The order of the \meta{keys} in the \meta{key--value list}
1079 % is preserved. Thus
1080 % \begin{verbatim}
1081 % \keyval_parse:nnn
1082 % { \use_none:nn { code 1 } }
1083 % { \use_none:nnn { code 2 } }
1084 % { key1 = value1 , key2 = value2, key3 = , key4 }
1085 % \end{verbatim}
1086 % is converted into an input stream
1087 % \begin{verbatim}
1088 % \use_none:nnn { code 2 } { key1 } { value1 }
1089 % \use_none:nnn { code 2 } { key2 } { value2 }
1090 % \use_none:nnn { code 2 } { key3 } { }
1091 % \use_none:nn { code 1 } { key4 }
1092 % \end{verbatim}
1093 % Note that there is a difference between an empty value (an equals
1094 % sign followed by nothing) and a missing value (no equals sign at
1095 % all). Spaces are trimmed from the ends of the \meta{key} and \meta{value},
1096 % then one \emph{outer} set of braces is removed from the \meta{key}
1097 % and \meta{value} as part of the processing. If you need exactly the output
1098 % shown above, you'll need to either \texttt{e}-type or \texttt{x}-type expand
1099 % the function.
1100 % \begin{texnote}
1101 % The result of each list element is returned within \cs{exp_not:n}, which
1102 % means that the converted input stream does not expand further when
1103 % appearing in an \texttt{e}-type or \texttt{x}-type argument expansion.
1104 % \end{texnote}
1105 % \end{function}
1106 %
1107 % \begin{function}[rEXP, updated = 2021-05-10]
1108 % {\keyval_parse:NNn, \keyval_parse:NNV, \keyval_parse:NNv}
1109 % \begin{syntax}
1110 % \cs{keyval_parse:NNn} \meta{function_1} \meta{function_2} \Arg{key--value list}
1111 % \end{syntax}
1112 % Parses the \meta{key--value list} into a series of \meta{keys} and
1113 % associated \meta{values}, or keys alone (if no \meta{value} was
1114 % given). \meta{function_1} should take one argument, while
1115 % \meta{function_2} should absorb two arguments. After
1116 % \cs{keyval_parse:NNn} has parsed the \meta{key--value list},
1117 % \meta{function_1} is used to process keys given with no value
1118 % and \meta{function_2} is used to process keys given with a
1119 % value. The order of the \meta{keys} in the \meta{key--value list}
1120 % is preserved. Thus
1121 % \begin{verbatim}
1122 % \keyval_parse:NNn \function:n \function:nn
1123 % { key1 = value1 , key2 = value2, key3 = , key4 }
1124 % \end{verbatim}
1125 % is converted into an input stream
1126 % \begin{verbatim}
1127 % \function:nn { key1 } { value1 }
1128 % \function:nn { key2 } { value2 }
1129 % \function:nn { key3 } { }
1130 % \function:n { key4 }
1131 % \end{verbatim}
1132 % Note that there is a difference between an empty value (an equals
1133 % sign followed by nothing) and a missing value (no equals sign at
1134 % all). Spaces are trimmed from the ends of the \meta{key} and \meta{value},
1135 % then one \emph{outer} set of braces is removed from the \meta{key}
1136 % and \meta{value} as part of the processing.
1137 %
1138 % This shares the implementation of \cs{keyval_parse:nnn}, the difference is
1139 % only semantically.
1140 % \begin{texnote}
1141 % The result is returned within \cs{exp_not:n}, which means that the
1142 % converted input stream does not expand further when appearing in an
1143 % \texttt{e}-type or \texttt{x}-type argument expansion.
1144 % \end{texnote}
1145 % \end{function}
1146 %
1147 % \begin{function}[added = 2026-02-09]{\keyval_map_inline:nnn}
1148 % \begin{syntax}
1149 % \cs{keyval_map_inline:nnn} \Arg{key--value list} \Arg{inline function_1} \Arg{inline function_2}
1150 % \end{syntax}
1151 % Applies the \meta{inline function_1} to every key in the \meta{key--value
1152 % list} which got no value, and \meta{inline function_2} to every key in the
1153 % \meta{key--value list} which got a value. The \meta{inline function_1}
1154 % should consist of code that receives keys without a value as |#1|, and
1155 % \meta{inline function_2} receives each key as |#1| and each value as |#2|.
1156 % \end{function}
1157 %
1158 % \begin{function}[added = 2026-02-09, rEXP]{\keyval_map_break:}
1159 % Used to terminate a \cs[no-index]{keyval_map_\ldots{}} function before all
1160 % entries in the \meta{key--value list} have been processed. This
1161 % normally takes place within a conditional statement, for example
1162 % \begin{verbatim}
1163 % \keyval_map_inline:nnn { foo, bar = baz, bingo, boom, ... }
1164 % {
1165 % \str_if_eq:nnTF { #1 } { bingo }
1166 % { \clist_map_break: }
1167 % {
1168 % % Do something useful
1169 % }
1170 % }
1171 % {
1172 % % Do more useful things
1173 % }
1174 % \end{verbatim}
1175 % See also \cs{keyval_map_break:n}.
1176 % Use outside of a \cs[no-index]{keyval_map_\ldots{}} scenario leads to low
1177 % level \TeX{} errors.
1178 % \begin{texnote}
1179 % When the mapping is broken, additional tokens may be inserted
1180 % before further items are taken
1181 % from the input stream. This depends on the design of the mapping
1182 % function.
1183 % \end{texnote}
1184 % \end{function}
1185 %
1186 % \begin{function}[added = 2026-02-09, rEXP]{\keyval_map_break:n}
1187 % \begin{syntax}
1188 % \cs{keyval_map_break:n} \Arg{code}
1189 % \end{syntax}
1190 % Used to terminate a \cs[no-index]{keyval_map_\ldots{}} function before all
1191 % entries in the \meta{key--value list} have been processed, inserting
1192 % the \meta{code} after the mapping has ended. This
1193 % normally takes place within a conditional statement, for example
1194 % \begin{verbatim}
1195 % \keyval_map_inline:nnn { foo, bar = baz, bingo, boom, ... }
1196 % {
1197 % \str_if_eq:nnTF { #1 } { bingo }
1198 % { \keyval_map_break:n { <code> } }
1199 % {
1200 % % Do something useful
1201 % }
1202 % }
1203 % {
1204 % % Do more useful things
1205 % }
1206 % \end{verbatim}
1207 % Use outside of a \cs[no-index]{keyval_map_\ldots{}} scenario leads to low
1208 % level \TeX{} errors.
1209 % \begin{texnote}
1210 % When the mapping is broken, additional tokens may be inserted
1211 % before the \meta{code} is
1212 % inserted into the input stream.
1213 % This depends on the design of the mapping function.
1214 % \end{texnote}
1215 % \end{function}
1216 %
1217 % \end{documentation}
1218 %
1219 % \begin{implementation}
1220 %
1221 % \section{\pkg{l3keys} implementation}
1222 %
1223 % \begin{macrocode}
1224 %<*code>
1225 % \end{macrocode}
1226 %
1227 % \subsection{Low-level interface}
1228 %
1229 % The low-level key parser's implementation is based heavily on \pkg{expkv}.
1230 % Compared to \pkg{keyval} it adds a number of additional \enquote{safety}
1231 % requirements and allows to process the parsed list of key--value pairs in a
1232 % variety of ways. The net result is that this code needs around one and a half
1233 % the amount of time as \pkg{keyval} to parse the same list of keys. To optimize
1234 % speed as far as reasonably practical, a number of lower-level approaches are
1235 % taken rather than using the higher-level \pkg{expl3} interfaces.
1236 %
1237 % \begin{macrocode}
1238 %<@@=keyval>
1239 % \end{macrocode}
1240 %
1241 % \begin{variable}{\s_@@_nil,\s_@@_mark,\s_@@_stop,\s_@@_tail}
1242 % \begin{macrocode}
1243 \scan_new:N \s_@@_nil
1244 \scan_new:N \s_@@_mark
1245 \scan_new:N \s_@@_stop
1246 \scan_new:N \s_@@_tail
1247 % \end{macrocode}
1248 % \end{variable}
1249 %
1250 % \begin{variable}{\l__kernel_keyval_allow_blank_keys_bool}
1251 % The general behavior of the \pkg{l3keys} module is to throw an error on
1252 % blank key names. However to support the usage of \cs{keyval_parse:nnn} in
1253 % the \pkg{l3prop} module we allow this error to be switched off temporarily
1254 % and just ignore blank names.
1255 % \begin{macrocode}
1256 \bool_new:N \l__kernel_keyval_allow_blank_keys_bool
1257 % \end{macrocode}
1258 % \end{variable}
1259 %
1260 % This temporary macro will be used since some of the definitions will need an
1261 % active comma or equals sign. Inside of this macro |#1| will be the active
1262 % comma and |#2| will be the active equals sign.
1263 % \begin{macrocode}
1264 \group_begin:
1265 \cs_set_protected:Npn \@@_tmp:nn #1#2
1266 {
1267 % \end{macrocode}
1268 %
1269 % \begin{macro}[rEXP]
1270 % {
1271 % \keyval_parse:nnn, \keyval_parse:nnV, \keyval_parse:nnv,
1272 % \keyval_parse:NNn, \keyval_parse:NNV, \keyval_parse:NNv
1273 % }
1274 % The main function starts the first of two loops. The outer loop splits the
1275 % key--value list at active commas, the inner loop will do so at other commas.
1276 % The use of \cs{s_@@_mark} here prevents loss of braces from the key
1277 % argument.
1278 % \begin{macrocode}
1279 \cs_new:Npn \keyval_parse:nnn ##1 ##2 ##3
1280 {
1281 \__kernel_exp_not:w \tex_expanded:D
1282 {
1283 {
1284 \@@_loop_active:nnw {##1} {##2}
1285 \s_@@_mark ##3 #1 \s_@@_tail #1
1286 }
1287 }
1288 }
1289 \cs_new_eq:NN \keyval_parse:NNn \keyval_parse:nnn
1290 % \end{macrocode}
1291 % \end{macro}
1292 %
1293 % \begin{macro}[EXP]{\@@_loop_active:nnw}
1294 % First a fast test for the end of the loop is done, it'll gobble everything
1295 % up to a \cs{s_@@_tail}. The loop ending macro will gobble everything to the
1296 % last comma in this definition.
1297 % If the end isn't reached yet, start the second loop splitting at other
1298 % commas, the next iteration of this first loop will be inserted by the end of
1299 % \cs{@@_loop_other:nnw}.
1300 % \begin{macrocode}
1301 \cs_new:Npn \@@_loop_active:nnw ##1 ##2 ##3 #1
1302 {
1303 \@@_if_recursion_tail:w ##3
1304 \@@_end_loop_active:w \s_@@_tail
1305 \@@_loop_other:nnw {##1} {##2} ##3 , \s_@@_tail ,
1306 }
1307 % \end{macrocode}
1308 % \end{macro}
1309 %
1310 % \begin{macro}[EXP]{\@@_split_other:w, \@@_split_active:w}
1311 % These two macros allow to split at the first equals sign of category 12 or
1312 % 13. At the same time they also execute branching by inserting the first
1313 % token following \cs{s_@@_mark} that followed the equals sign. Hence they
1314 % also test for the presence of such an equals sign simultaneously.
1315 % \begin{macrocode}
1316 \cs_new:Npn \@@_split_other:w ##1 = ##2 \s_@@_mark ##3
1317 { ##3 ##1 \s_@@_stop \s_@@_mark ##2 }
1318 \cs_new:Npn \@@_split_active:w ##1 #2 ##2 \s_@@_mark ##3
1319 { ##3 ##1 \s_@@_stop \s_@@_mark ##2 }
1320 % \end{macrocode}
1321 % \end{macro}
1322 %
1323 % \begin{macro}[EXP]{\@@_loop_other:nnw}
1324 % The second loop uses the same test for its end as the first loop, next it
1325 % splits at the first active equals sign using \cs{@@_split_active:w}. The
1326 % \cs{s_@@_nil} prevents accidental brace stripping and acts as a delimiter in
1327 % the next steps. First testing for an active equals sign will reduce the
1328 % number of necessary expansion steps for the expected average use case of
1329 % other equals signs and hence perform better on average.
1330 % \begin{macrocode}
1331 \cs_new:Npn \@@_loop_other:nnw ##1 ##2 ##3 ,
1332 {
1333 \@@_if_recursion_tail:w ##3
1334 \@@_end_loop_other:w \s_@@_tail
1335 \@@_split_active:w ##3 \s_@@_nil
1336 \s_@@_mark \@@_split_active_auxi:w
1337 #2 \s_@@_mark \@@_clean_up_active:w
1338 {##1} {##2}
1339 \s_@@_mark
1340 }
1341 % \end{macrocode}
1342 % \end{macro}
1343 %
1344 % \begin{macro}[EXP]{\@@_split_active_auxi:w}
1345 % \begin{macro}[EXP]{\@@_split_active_auxii:w}
1346 % \begin{macro}[EXP]{\@@_split_active_auxiii:w}
1347 % \begin{macro}[EXP]{\@@_split_active_auxiv:w}
1348 % \begin{macro}[EXP]{\@@_split_active_auxv:w}
1349 % After \cs{@@_split_active:w} the following will only be called if there was
1350 % at least one active equals sign in the current key--value pair. Therefore
1351 % this is the execution branch for a key--value pair with an active equals
1352 % sign. |##1| will be everything up to the first active equals sign. First it
1353 % tests for other equals signs in the key name, which will eventually throw an
1354 % error via \cs{@@_misplaced_equal_after_active_error:w}. If none was found we
1355 % forward the key to \cs{@@_split_active_auxii:w}.
1356 % \begin{macrocode}
1357 \cs_new:Npn \@@_split_active_auxi:w ##1 \s_@@_stop
1358 {
1359 \@@_split_other:w ##1 \s_@@_nil
1360 \s_@@_mark \@@_misplaced_equal_after_active_error:w
1361 = \s_@@_mark \@@_split_active_auxii:w
1362 }
1363 % \end{macrocode}
1364 % \cs{@@_split_active_auxii:w} gets the correct key name with a leading
1365 % \cs{s_@@_mark} as |##1|. It has to sanitize the remainder of the previous
1366 % test and trims the key name which will be forwarded to
1367 % \cs{@@_split_active_auxiii:w}.
1368 % \begin{macrocode}
1369 \cs_new:Npn \@@_split_active_auxii:w
1370 ##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_after_active_error:w
1371 \s_@@_stop \s_@@_mark
1372 ##2 \s_@@_nil #2 \s_@@_mark \@@_clean_up_active:w
1373 { \@@_trim:nN {##1} \@@_split_active_auxiii:w ##2 \s_@@_nil }
1374 % \end{macrocode}
1375 % Next we test for a misplaced active equals sign in the value, if none is
1376 % found \cs{@@_split_active_auxiv:w} will be called.
1377 % \begin{macrocode}
1378 \cs_new:Npn \@@_split_active_auxiii:w ##1 ##2 \s_@@_nil
1379 {
1380 \@@_split_active:w ##2 \s_@@_nil
1381 \s_@@_mark \@@_misplaced_equal_in_split_error:w
1382 #2 \s_@@_mark \@@_split_active_auxiv:w
1383 {##1}
1384 }
1385 % \end{macrocode}
1386 % This runs the last test after sanitizing the remainder of the previous one.
1387 % This time test for a misplaced equals sign of category 12 in the value.
1388 % Finally the last auxiliary macro will be called.
1389 % \begin{macrocode}
1390 \cs_new:Npn \@@_split_active_auxiv:w
1391 ##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_in_split_error:w
1392 \s_@@_stop \s_@@_mark
1393 {
1394 \@@_split_other:w ##1 \s_@@_nil
1395 \s_@@_mark \@@_misplaced_equal_in_split_error:w
1396 = \s_@@_mark \@@_split_active_auxv:w
1397 }
1398 % \end{macrocode}
1399 % This last macro in this execution branch sanitizes the last test, trims the
1400 % value and passes it to \cs{@@_pair:nnnn}.
1401 % \begin{macrocode}
1402 \cs_new:Npn \@@_split_active_auxv:w
1403 ##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_in_split_error:w
1404 \s_@@_stop \s_@@_mark
1405 { \@@_trim:nN { ##1 } \@@_pair:nnnn }
1406 % \end{macrocode}
1407 % \end{macro}
1408 % \end{macro}
1409 % \end{macro}
1410 % \end{macro}
1411 % \end{macro}
1412 %
1413 % \begin{macro}[EXP]{\@@_clean_up_active:w}
1414 % The following is the branch taken if the key--value pair doesn't contain an
1415 % active equals sign. The remainder of that test will be cleaned up by
1416 % \cs{@@_clean_up_active:w} which will then split at an equals sign of
1417 % category other.
1418 % \begin{macrocode}
1419 \cs_new:Npn \@@_clean_up_active:w
1420 ##1 \s_@@_nil \s_@@_mark \@@_split_active_auxi:w \s_@@_stop \s_@@_mark
1421 {
1422 \@@_split_other:w ##1 \s_@@_nil
1423 \s_@@_mark \@@_split_other_auxi:w
1424 = \s_@@_mark \@@_clean_up_other:w
1425 }
1426 % \end{macrocode}
1427 % \end{macro}
1428 %
1429 % \begin{macro}[EXP]{\@@_split_other_auxi:w}
1430 % \begin{macro}[EXP]{\@@_split_other_auxii:w}
1431 % \begin{macro}[EXP]{\@@_split_other_auxiii:w}
1432 % This is executed if the key--value pair doesn't contain an active equals
1433 % sign but at least one other. |##1| of \cs{@@_split_other_auxi:w} will
1434 % contain the complete key name, which is trimmed and forwarded to the next
1435 % auxiliary macro.
1436 % \begin{macrocode}
1437 \cs_new:Npn \@@_split_other_auxi:w ##1 \s_@@_stop
1438 { \@@_trim:nN { ##1 } \@@_split_other_auxii:w }
1439 % \end{macrocode}
1440 % We know that the value doesn't contain misplaced active equals signs but we
1441 % have to test for others. Also we need to sanitize the previous test, which
1442 % is done here and not earlier to avoid superfluous argument grabbing.
1443 % \begin{macrocode}
1444 \cs_new:Npn \@@_split_other_auxii:w
1445 ##1 ##2 \s_@@_nil = \s_@@_mark \@@_clean_up_other:w
1446 {
1447 \@@_split_other:w ##2 \s_@@_nil
1448 \s_@@_mark \@@_misplaced_equal_in_split_error:w
1449 = \s_@@_mark \@@_split_other_auxiii:w
1450 { ##1 }
1451 }
1452 % \end{macrocode}
1453 % \cs{@@_split_other_auxiii:w} sanitizes the test for other equals signs,
1454 % trims the value and forwards it to \cs{@@_pair:nnnn}.
1455 % \begin{macrocode}
1456 \cs_new:Npn \@@_split_other_auxiii:w
1457 ##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_in_split_error:w
1458 \s_@@_stop \s_@@_mark
1459 { \@@_trim:nN { ##1 } \@@_pair:nnnn }
1460 % \end{macrocode}
1461 % \end{macro}
1462 % \end{macro}
1463 % \end{macro}
1464 %
1465 % \begin{macro}[EXP]{\@@_clean_up_other:w}
1466 % \cs{@@_clean_up_other:w} is the last branch that might exist. It is called
1467 % if no equals sign was found, hence the only possibilities left are a blank
1468 % list element, which is to be skipped, or a lonely key. If it's no empty list
1469 % element this will trim the key name and forward it to \cs{@@_key:nn}.
1470 % \begin{macrocode}
1471 \cs_new:Npn \@@_clean_up_other:w
1472 ##1 \s_@@_nil \s_@@_mark \@@_split_other_auxi:w \s_@@_stop \s_@@_mark
1473 {
1474 \@@_if_blank:w ##1 \s_@@_nil \s_@@_stop \@@_blank_true:w
1475 \s_@@_mark \s_@@_stop
1476 \@@_trim:nN { ##1 } \@@_key:nn
1477 }
1478 % \end{macrocode}
1479 % \end{macro}
1480 %
1481 % \begin{macro}[EXP]{\@@_misplaced_equal_after_active_error:w}
1482 % \begin{macro}[EXP]{\@@_misplaced_equal_in_split_error:w}
1483 % All these two macros do is gobble the remainder of the current other loop
1484 % execution and throw an error. Afterwards they have to insert the next loop
1485 % iteration.
1486 % \begin{macrocode}
1487 \cs_new:Npn \@@_misplaced_equal_after_active_error:w
1488 \s_@@_mark ##1 \s_@@_stop \s_@@_mark ##2 \s_@@_nil
1489 = \s_@@_mark \@@_split_active_auxii:w
1490 \s_@@_mark ##3 \s_@@_nil
1491 #2 \s_@@_mark \@@_clean_up_active:w
1492 {
1493 \msg_expandable_error:nn
1494 { keyval } { misplaced-equals-sign }
1495 \@@_loop_other:nnw
1496 }
1497 \cs_new:Npn \@@_misplaced_equal_in_split_error:w
1498 \s_@@_mark ##1 \s_@@_stop \s_@@_mark ##2 \s_@@_nil
1499 ##3 \s_@@_mark ##4 ##5
1500 {
1501 \msg_expandable_error:nn
1502 { keyval } { misplaced-equals-sign }
1503 \@@_loop_other:nnw
1504 }
1505 % \end{macrocode}
1506 % \end{macro}
1507 % \end{macro}
1508 %
1509 % \begin{macro}[EXP]{\@@_end_loop_other:w, \@@_end_loop_active:w}
1510 % All that's left for the parsing loops are the macros which end the
1511 % recursion. Both just gobble the remaining tokens of the respective loop
1512 % including the next recursion call. \cs{@@_end_loop_other:w} also has to
1513 % insert the next iteration of the active loop.
1514 % \begin{macrocode}
1515 \cs_new:Npn \@@_end_loop_other:w
1516 \s_@@_tail
1517 \@@_split_active:w
1518 \s_@@_mark \s_@@_tail
1519 \s_@@_nil \s_@@_mark
1520 \@@_split_active_auxi:w
1521 #2 \s_@@_mark \@@_clean_up_active:w
1522 { \@@_loop_active:nnw }
1523 \cs_new:Npn \@@_end_loop_active:w
1524 \s_@@_tail
1525 \@@_loop_other:nnw ##1 \s_@@_mark \s_@@_tail , \s_@@_tail ,
1526 { }
1527 % \end{macrocode}
1528 % \end{macro}
1529 %
1530 % The parsing loops are done, so here ends the definition of \cs{@@_tmp:nn},
1531 % which will finally set up the macros.
1532 % \begin{macrocode}
1533 }
1534 \char_set_catcode_active:n { `\, }
1535 \char_set_catcode_active:n { `\= }
1536 \@@_tmp:nn , =
1537 \group_end:
1538 \cs_generate_variant:Nn \keyval_parse:NNn { NNV , NNv }
1539 \cs_generate_variant:Nn \keyval_parse:nnn { nnV , nnv }
1540 % \end{macrocode}
1541 %
1542 % \begin{macro}[EXP]{\@@_pair:nnnn, \@@_key:nn}
1543 % These macros will be called on the parsed keys and values of the key--value
1544 % list. All arguments are completely trimmed. They test for blank key names
1545 % and call the functions passed to \cs{keyval_parse:nnn} inside of
1546 % \cs{exp_not:n} with the correct arguments. Afterwards they insert the next
1547 % iteration of the other loop.
1548 % \begin{macrocode}
1549 \group_begin:
1550 \cs_set_protected:Npn \@@_tmp:nn #1#2
1551 {
1552 \cs_new:Npn \@@_pair:nnnn ##1 ##2 ##3 ##4
1553 {
1554 \@@_if_blank:w \s_@@_mark ##2 \s_@@_nil \s_@@_stop \@@_blank_key_error:w
1555 \s_@@_mark \s_@@_stop
1556 #1
1557 \exp_not:n { ##4 {##2} {##1} }
1558 #2
1559 \@@_loop_other:nnw {##3} {##4}
1560 }
1561 \cs_new:Npn \@@_key:nn ##1 ##2
1562 {
1563 \@@_if_blank:w \s_@@_mark ##1 \s_@@_nil \s_@@_stop \@@_blank_key_error:w
1564 \s_@@_mark \s_@@_stop
1565 #1
1566 \exp_not:n { ##2 {##1} }
1567 #2
1568 \@@_loop_other:nnw {##2}
1569 }
1570 }
1571 \@@_tmp:nn { } { }
1572 \group_end:
1573 % \end{macrocode}
1574 % \end{macro}
1575 %
1576 % \begin{macro}[EXP]{\@@_if_empty:w,\@@_if_blank:w,\@@_if_recursion_tail:w}
1577 % All these tests work by gobbling tokens until a certain combination is met,
1578 % which makes them pretty fast. The test for a blank argument should be called
1579 % with an arbitrary token following the argument. Each of these utilize the
1580 % fact that the argument will contain a leading \cs{s_@@_mark}.
1581 % \begin{macrocode}
1582 \cs_new:Npn \@@_if_empty:w #1 \s_@@_mark \s_@@_stop { }
1583 \cs_new:Npn \@@_if_blank:w \s_@@_mark #1 { \@@_if_empty:w \s_@@_mark }
1584 \cs_new:Npn \@@_if_recursion_tail:w \s_@@_mark #1 \s_@@_tail { }
1585 % \end{macrocode}
1586 % \end{macro}
1587 %
1588 % \begin{macro}[EXP]{\@@_blank_true:w,\@@_blank_key_error:w}
1589 % These macros will be called if the tests above didn't gobble them, they
1590 % execute the branching.
1591 % \begin{macrocode}
1592 \cs_new:Npn \@@_blank_true:w \s_@@_mark \s_@@_stop \@@_trim:nN #1 \@@_key:nn
1593 { \@@_loop_other:nnw }
1594 \cs_new:Npn \@@_blank_key_error:w \s_@@_mark \s_@@_stop #1 \@@_loop_other:nnw
1595 {
1596 \bool_if:NTF \l__kernel_keyval_allow_blank_keys_bool
1597 { #1 }
1598 { \msg_expandable_error:nn { keyval } { blank-key-name } }
1599 \@@_loop_other:nnw
1600 }
1601 % \end{macrocode}
1602 % \end{macro}
1603 %
1604 % Two messages for the low level parsing system.
1605 % \begin{macrocode}
1606 \msg_new:nnn { keyval } { misplaced-equals-sign }
1607 { Misplaced~'='~in~key-value~input~\msg_line_context: }
1608 \msg_new:nnn { keyval } { blank-key-name }
1609 { Blank~key~name~in~key-value~input~\msg_line_context: }
1610 \prop_gput:Nnn \g_msg_module_name_prop { keyval } { LaTeX }
1611 \prop_gput:Nnn \g_msg_module_type_prop { keyval } { }
1612 % \end{macrocode}
1613 %
1614 % \begin{macro}[EXP]{\@@_trim:nN}
1615 % \begin{macro}[EXP]
1616 % {\@@_trim_auxi:w,\@@_trim_auxii:w,\@@_trim_auxiii:w,\@@_trim_auxiv:w}
1617 % And an adapted version of \cs{__tl_trim_spaces:nn} which is a bit faster for
1618 % our use case, as it can strip the braces at the end. This is pretty much the
1619 % same concept, so I won't comment on it here. The speed gain by using this
1620 % instead of \cs{tl_trim_spaces_apply:nN} is about 10\,\% of the total time for
1621 % \cs{keyval_parse:NNn} with one key and one key--value pair, so I think it's
1622 % worth it.
1623 % \begin{macrocode}
1624 \group_begin:
1625 \cs_set_protected:Npn \@@_tmp:n #1
1626 {
1627 \cs_new:Npn \@@_trim:nN ##1
1628 {
1629 \@@_trim_auxi:w
1630 ##1
1631 \s_@@_nil
1632 \s_@@_mark #1 { }
1633 \s_@@_mark \@@_trim_auxii:w
1634 \@@_trim_auxiii:w
1635 #1 \s_@@_nil
1636 \@@_trim_auxiv:w
1637 }
1638 \cs_new:Npn \@@_trim_auxi:w ##1 \s_@@_mark #1 ##2 \s_@@_mark ##3
1639 {
1640 ##3
1641 \@@_trim_auxi:w
1642 \s_@@_mark
1643 ##2
1644 \s_@@_mark #1 {##1}
1645 }
1646 \cs_new:Npn \@@_trim_auxii:w \@@_trim_auxi:w \s_@@_mark \s_@@_mark ##1
1647 {
1648 \@@_trim_auxiii:w
1649 ##1
1650 }
1651 \cs_new:Npn \@@_trim_auxiii:w ##1 #1 \s_@@_nil ##2
1652 {
1653 ##2
1654 ##1 \s_@@_nil
1655 \@@_trim_auxiii:w
1656 }
1657 % \end{macrocode}
1658 % This is the one macro which differs from the original definition.
1659 % \begin{macrocode}
1660 \cs_new:Npn \@@_trim_auxiv:w
1661 \s_@@_mark ##1 \s_@@_nil
1662 \@@_trim_auxiii:w \s_@@_nil \@@_trim_auxiii:w
1663 ##2
1664 { ##2 { ##1 } }
1665 }
1666 \@@_tmp:n { ~ }
1667 \group_end:
1668 % \end{macrocode}
1669 % \end{macro}
1670 % \end{macro}
1671 %
1672 % \begin{macro}{\keyval_map_inline:nnn}
1673 % Unlike many other mapping functions we don't need to keep a global stack of
1674 % definitions for our auxiliary macros, instead we can contain their
1675 % definition in a group and use \cs{keyval_parse:NNn} which we fully expand
1676 % twice before the group is closed. This has the drawback that any breaking of
1677 % the map happens after the entire list was already parsed, so has a
1678 % performance penalty in that case. However, these should be rather rare
1679 % occasions and the simplicity of the code should warrant them. Another
1680 % drawback of this approach is that the expansion of the internal macros is
1681 % left in the input stream for every element.
1682 %
1683 % The break point can remain outside of the braces containing the loop, since
1684 % by the time any user code from the argument to the break statement is executed,
1685 % the brace group will have been consumed.
1686 % \begin{macrocode}
1687 \cs_new_protected:Npn \keyval_map_inline:nnn #1#2#3
1688 {
1689 \group_begin:
1690 \cs_set:Npn \@@_tmp:n ##1 { \exp_not:n {#2} }
1691 \cs_set:Npn \@@_tmp:nn ##1##2 { \exp_not:n {#3} }
1692 \exp_args:NNe \exp_last_unbraced:Ne
1693 \group_end:
1694 { \keyval_parse:NNn \@@_tmp:n \@@_tmp:nn {#1} }
1695 \prg_break_point:Nn \keyval_map_break: { }
1696 }
1697 % \end{macrocode}
1698 % \end{macro}
1699 %
1700 % \begin{macro}{\keyval_map_break:, \keyval_map_break:n}
1701 % Simple code using the \cs{prg_map_break:Nn} mechanism.
1702 % \begin{macrocode}
1703 \cs_new:Npn \keyval_map_break: { \prg_map_break:Nn \keyval_map_break: { } }
1704 \cs_new:Npn \keyval_map_break:n { \prg_map_break:Nn \keyval_map_break: }
1705 % \end{macrocode}
1706 % \end{macro}
1707 %
1708 % \subsection{Constants and variables}
1709 %
1710 % \begin{macrocode}
1711 %<@@=keys>
1712 % \end{macrocode}
1713 %
1714 % \begin{variable}
1715 % {
1716 % \c_@@_code_root_str ,
1717 % \c_@@_check_root_str ,
1718 % \c_@@_default_root_str ,
1719 % \c_@@_groups_root_str ,
1720 % \c_@@_inherit_root_str ,
1721 % \c_@@_type_root_str
1722 % }
1723 % Various storage areas for the different data which make up keys.
1724 % \begin{macrocode}
1725 \str_const:Nn \c_@@_code_root_str { key~code~>~ }
1726 \str_const:Nn \c_@@_check_root_str { key~check~>~ }
1727 \str_const:Nn \c_@@_default_root_str { key~default~>~ }
1728 \str_const:Nn \c_@@_groups_root_str { key~groups~>~ }
1729 \str_const:Nn \c_@@_inherit_root_str { key~inherit~>~ }
1730 \str_const:Nn \c_@@_type_root_str { key~type~>~ }
1731 % \end{macrocode}
1732 % \end{variable}
1733 %
1734 % \begin{variable}{\c_@@_props_root_str}
1735 % The prefix for storing properties.
1736 % \begin{macrocode}
1737 \str_const:Nn \c_@@_props_root_str { key~prop~>~ }
1738 % \end{macrocode}
1739 % \end{variable}
1740 %
1741 % \begin{variable}{\l_keys_choice_int, \l_keys_choice_str}
1742 % Publicly accessible data on which choice is being used when several
1743 % are generated as a set.
1744 % \begin{macrocode}
1745 \int_new:N \l_keys_choice_int
1746 \str_new:N \l_keys_choice_str
1747 % \end{macrocode}
1748 % \end{variable}
1749 % \begin{variable}[deprecated]{\l_keys_choice_tl}
1750 % The |tl| version is deprecated but has to be handled manually.
1751 % \begin{macrocode}
1752 \tl_new:N \l_keys_choice_tl
1753 % \end{macrocode}
1754 % \end{variable}
1755 %
1756 % \begin{variable}{\l_@@_exp_str}
1757 % The expansion postfix of a key name.
1758 % \begin{macrocode}
1759 \str_new:N \l_@@_exp_str
1760 % \end{macrocode}
1761 % \end{variable}
1762 %
1763 % \begin{variable}{\l_@@_groups_clist}
1764 % Used for storing and recovering the list of groups which apply to a key:
1765 % set as a comma list but at one point we have to use this for a token
1766 % list recovery.
1767 % \begin{macrocode}
1768 \clist_new:N \l_@@_groups_clist
1769 % \end{macrocode}
1770 % \end{variable}
1771 %
1772 % \begin{variable}{\l_@@_inherit_bool}
1773 % For inheritance, particularly for recursion.
1774 % \begin{macrocode}
1775 \bool_new:N \l_@@_inherit_bool
1776 % \end{macrocode}
1777 % \end{variable}
1778 %
1779 % \begin{variable}{\l_@@_inherit_clist}
1780 % For normalization.
1781 % \begin{macrocode}
1782 \clist_new:N \l_@@_inherit_clist
1783 % \end{macrocode}
1784 % \end{variable}
1785 %
1786 % \begin{variable}{\l_keys_key_str}
1787 % The name of a key itself: needed when setting keys.
1788 % \begin{macrocode}
1789 \str_new:N \l_keys_key_str
1790 % \end{macrocode}
1791 % \end{variable}
1792 %
1793 % \begin{variable}[deprecated]{\l_keys_key_tl}
1794 % The |tl| version is deprecated but has to be handled manually.
1795 % \begin{macrocode}
1796 \tl_new:N \l_keys_key_tl
1797 % \end{macrocode}
1798 % \end{variable}
1799 %
1800 % \begin{variable}{\l_@@_module_str}
1801 % The module for an entire set of keys.
1802 % \begin{macrocode}
1803 \str_new:N \l_@@_module_str
1804 % \end{macrocode}
1805 % \end{variable}
1806 %
1807 % \begin{variable}{\l_@@_no_value_bool}
1808 % A marker is needed internally to show if only a key or a key plus a
1809 % value was seen: this is recorded here.
1810 % \begin{macrocode}
1811 \bool_new:N \l_@@_no_value_bool
1812 % \end{macrocode}
1813 % \end{variable}
1814 %
1815 % \begin{variable}{\l_@@_only_known_bool}
1816 % Used to track if only \enquote{known} keys are being set.
1817 % \begin{macrocode}
1818 \bool_new:N \l_@@_only_known_bool
1819 % \end{macrocode}
1820 % \end{variable}
1821 %
1822 % \begin{variable}{\l_keys_path_str}
1823 % The \enquote{path} of the current key is stored here: this is
1824 % available to the programmer and so is public.
1825 % \begin{macrocode}
1826 \str_new:N \l_keys_path_str
1827 % \end{macrocode}
1828 % \end{variable}
1829 %
1830 % \begin{variable}[deprecated]{\l_keys_path_tl}
1831 % The older version is deprecated but has to be handled manually.
1832 % \begin{macrocode}
1833 \tl_new:N \l_keys_path_tl
1834 % \end{macrocode}
1835 % \end{variable}
1836 %
1837 % \begin{variable}{\l_@@_inherit_str}
1838 % \begin{macrocode}
1839 \str_new:N \l_@@_inherit_str
1840 % \end{macrocode}
1841 % \end{variable}
1842 %
1843 % \begin{variable}{\l_@@_relative_tl}
1844 % The relative path for passing keys back to the user. As this can
1845 % be explicitly no-value, it must be a token list.
1846 % \begin{macrocode}
1847 \tl_new:N \l_@@_relative_tl
1848 \tl_set:Nn \l_@@_relative_tl { \q_@@_no_value }
1849 % \end{macrocode}
1850 % \end{variable}
1851 %
1852 % \begin{variable}{\l_@@_property_str}
1853 % The \enquote{property} begin set for a key at definition time is
1854 % stored here.
1855 % \begin{macrocode}
1856 \str_new:N \l_@@_property_str
1857 % \end{macrocode}
1858 % \end{variable}
1859 %
1860 % \begin{variable}{\l_@@_selective_bool, \l_@@_exclude_bool}
1861 % Two booleans for using key groups: one to indicate that \enquote{selective}
1862 % setting is active, a second to specify which type (\enquote{opt-in}
1863 % or \enquote{opt-out}).
1864 % \begin{macrocode}
1865 \bool_new:N \l_@@_selective_bool
1866 \bool_new:N \l_@@_exclude_bool
1867 % \end{macrocode}
1868 % \end{variable}
1869 %
1870 % \begin{variable}{\l_@@_selective_clist}
1871 % The list of key groups being filtered in or out during selective setting.
1872 % \begin{macrocode}
1873 \clist_new:N \l_@@_selective_clist
1874 % \end{macrocode}
1875 % \end{variable}
1876 %
1877 % \begin{variable}{\l_@@_tmp_clist}
1878 % Scratch space used as a data dump.
1879 % \begin{macrocode}
1880 \clist_new:N \l_@@_tmp_clist
1881 % \end{macrocode}
1882 % \end{variable}
1883 %
1884 % \begin{variable}{\l_@@_unused_clist}
1885 % Used when setting only some keys to store those left over.
1886 % \begin{macrocode}
1887 \clist_new:N \l_@@_unused_clist
1888 % \end{macrocode}
1889 % \end{variable}
1890 %
1891 % \begin{variable}{\l_keys_value_tl}
1892 % The value given for a key: may be empty if no value was given.
1893 % \begin{macrocode}
1894 \tl_new:N \l_keys_value_tl
1895 % \end{macrocode}
1896 % \end{variable}
1897 %
1898 % \begin{variable}{\l_@@_tmp_bool, \l_@@_tmpa_tl, \l_@@_tmpb_tl}
1899 % Scratch space.
1900 % \begin{macrocode}
1901 \bool_new:N \l_@@_tmp_bool
1902 \tl_new:N \l_@@_tmpa_tl
1903 \tl_new:N \l_@@_tmpb_tl
1904 % \end{macrocode}
1905 % \end{variable}
1906 %
1907 % \begin{variable}{\l_@@_precompile_bool, \l_@@_precompile_tl}
1908 % For digesting keys.
1909 % \begin{macrocode}
1910 \bool_new:N \l_@@_precompile_bool
1911 \tl_new:N \l_@@_precompile_tl
1912 % \end{macrocode}
1913 % \end{variable}
1914 %
1915 % \begin{variable}{\l_keys_usage_load_prop, \l_keys_usage_preamble_prop}
1916 % Global data for document-level information.
1917 % \begin{macrocode}
1918 \prop_new:N \l_keys_usage_load_prop
1919 \prop_new:N \l_keys_usage_preamble_prop
1920 % \end{macrocode}
1921 % \end{variable}
1922 %
1923 % \subsubsection{Internal auxiliaries}
1924 %
1925 % \begin{variable}{\s_@@_nil,\s_@@_mark,\s_@@_stop}
1926 % Internal scan marks.
1927 % \begin{macrocode}
1928 \scan_new:N \s_@@_nil
1929 \scan_new:N \s_@@_mark
1930 \scan_new:N \s_@@_stop
1931 % \end{macrocode}
1932 % \end{variable}
1933 %
1934 % \begin{variable}{\q_@@_no_value}
1935 % Internal quarks.
1936 % \begin{macrocode}
1937 \quark_new:N \q_@@_no_value
1938 % \end{macrocode}
1939 % \end{variable}
1940 %
1941 % \begin{macro}[pTF]{\@@_quark_if_no_value:N}
1942 % Branching quark conditional.
1943 % \begin{macrocode}
1944 \__kernel_quark_new_conditional:Nn \@@_quark_if_no_value:N { TF }
1945 % \end{macrocode}
1946 % \end{macro}
1947 %
1948 % \begin{macro}{\@@_precompile:n}
1949 % An auxiliary to allow cleaner showing of code.
1950 % \begin{macrocode}
1951 \cs_new_protected:Npn \@@_precompile:n #1
1952 {
1953 \bool_if:NTF \l_@@_precompile_bool
1954 { \tl_put_right:Nn \l_@@_precompile_tl }
1955 { \use:n }
1956 {#1}
1957 }
1958 % \end{macrocode}
1959 % \end{macro}
1960 %
1961 % \begin{macro}{\@@_cs_undefine:c}
1962 % Local version of \cs{cs_undefine:c} to avoid sprinkling
1963 % \cs{tex_undefined:D} everywhere.
1964 % \begin{macrocode}
1965 \cs_new_protected:Npn \@@_cs_undefine:c #1
1966 {
1967 \if_cs_exist:w #1 \cs_end:
1968 \else:
1969 \use_i:nnnn
1970 \fi:
1971 \cs_set_eq:cN {#1} \tex_undefined:D
1972 }
1973 % \end{macrocode}
1974 % \end{macro}
1975 %
1976 % \subsection{The key defining mechanism}
1977 %
1978 % \begin{macro}{\keys_define:nn, \keys_define:ne, \keys_define:nx}
1979 % The public function for definitions is just a wrapper for the lower
1980 % level mechanism, more or less. The outer function is designed to
1981 % keep a track of the current module, to allow safe nesting. The module is set
1982 % removing any leading |/| (which is not needed here).
1983 % \begin{macrocode}
1984 \cs_new_protected:Npn \keys_define:nn #1#2
1985 {
1986 \use:e
1987 {
1988 \exp_not:n
1989 {
1990 \str_set:Ne \l_@@_module_str { \@@_trim_spaces:n {#1} }
1991 \keyval_parse:NNn \@@_define:n \@@_define:nn {#2}
1992 }
1993 \@@_reset_var:N \l_@@_module_str
1994 \@@_reset_var:N \l_@@_inherit_str
1995 \@@_reset_var:N \l_keys_choice_tl
1996 \@@_reset_var:N \l_keys_choice_str
1997 \@@_reset_var:N \l_keys_key_tl
1998 \@@_reset_var:N \l_keys_key_str
1999 \@@_reset_var:N \l_keys_path_tl
2000 \@@_reset_var:N \l_keys_path_str
2001 \@@_reset_var:N \l_keys_value_tl
2002 \int_set:Nn \l_keys_choice_int { \int_use:N \l_keys_choice_int }
2003 }
2004 }
2005 \cs_generate_variant:Nn \keys_define:nn { ne , nx }
2006 % \end{macrocode}
2007 % \end{macro}
2008 %
2009 % \begin{macro}{\@@_define:n}
2010 % \begin{macro}{\@@_define:nn}
2011 % \begin{macro}{\@@_define_aux:nn}
2012 % The outer functions here record whether a value was given and then
2013 % converge on a common internal mechanism. There is first a search for
2014 % a property in the current key name, then a check to make sure it is
2015 % known before the code hands off to the next step.
2016 % \begin{macrocode}
2017 \cs_new_protected:Npn \@@_define:n #1
2018 {
2019 \bool_set_true:N \l_@@_no_value_bool
2020 \@@_define_aux:nn {#1} { }
2021 }
2022 \cs_new_protected:Npn \@@_define:nn #1#2
2023 {
2024 \bool_set_false:N \l_@@_no_value_bool
2025 \@@_define_aux:nn {#1} {#2}
2026 }
2027 \cs_new_protected:Npn \@@_define_aux:nn #1#2
2028 {
2029 \@@_property_find:n {#1}
2030 \cs_if_exist:cTF { \c_@@_props_root_str \l_@@_property_str }
2031 { \@@_define_code:n {#2} }
2032 {
2033 \str_if_empty:NF \l_@@_property_str
2034 {
2035 \msg_error:nnee { keys } { property-unknown }
2036 \l_@@_property_str \l_keys_path_str
2037 }
2038 }
2039 }
2040 % \end{macrocode}
2041 % \end{macro}
2042 % \end{macro}
2043 % \end{macro}
2044 %
2045 % \begin{macro}{\@@_property_find:n}
2046 % \begin{macro}[EXP]{\@@_property_find_auxi:w}
2047 % \begin{macro}{\@@_property_find_auxii:w}
2048 % \begin{macro}[EXP]
2049 % {
2050 % \@@_property_find_auxiii:w ,
2051 % \@@_property_find_auxiv:w
2052 % }
2053 % \begin{macro}{\@@_property_find_err:w}
2054 % Searching for a property means finding the last |.| in the input,
2055 % and storing the text before and after it. Everything is first turned into
2056 % strings, so there is no problem using \cs{cs_set_nopar:Npe} instead of
2057 % \cs{str_set:Ne} to set \cs{l_keys_path_str}. To gain further speed, brace
2058 % tricks are used and \cs{@@_property_find_auxiv:w} is defined as expandable.
2059 % Since spaces will already be trimmed from the module we can omit it from the
2060 % argument to \cs{@@_trim_spaces:n}.
2061 % \begin{macrocode}
2062 \cs_new_protected:Npn \@@_property_find:n #1
2063 {
2064 \exp_after:wN \@@_property_find_auxi:w \tl_to_str:n {#1}
2065 \s_@@_nil \@@_property_find_auxii:w
2066 . \s_@@_nil \@@_property_find_err:w
2067 }
2068 \cs_new:Npn \@@_property_find_auxi:w #1 . #2 \s_@@_nil #3
2069 {
2070 #3 #1 \s_@@_mark #2 \s_@@_nil #3
2071 }
2072 \cs_new_protected:Npn \@@_property_find_auxii:w
2073 #1 \s_@@_mark #2 \s_@@_nil \@@_property_find_auxii:w . \s_@@_nil
2074 \@@_property_find_err:w
2075 {
2076 \cs_set_nopar:Npe \l_keys_path_str
2077 {
2078 \str_if_empty:NF \l_@@_module_str { \l_@@_module_str / }
2079 \exp_after:wN \@@_trim_spaces:n \tex_expanded:D {{
2080 #1
2081 \if_false: }}} \fi:
2082 \@@_property_find_auxi:w #2 \s_@@_nil \@@_property_find_auxiii:w
2083 . \s_@@_nil \@@_property_find_auxiv:w
2084 }
2085 \cs_new:Npn \@@_property_find_auxiii:w #1 \s_@@_mark #2 . #3 \s_@@_nil #4
2086 {
2087 . #1 #4 #2 \s_@@_mark #3 \s_@@_nil #4
2088 }
2089 \cs_new:Npn \@@_property_find_auxiv:w
2090 #1 \s_@@_nil \@@_property_find_auxiii:w
2091 \s_@@_mark \s_@@_nil \@@_property_find_auxiv:w
2092 {
2093 \if_false: {{{ \fi: }}}
2094 \cs_set_nopar:Npe \l_@@_property_str { . #1 }
2095 \tl_set_eq:NN \l_keys_path_tl \l_keys_path_str
2096 }
2097 \cs_new_protected:Npn \@@_property_find_err:w
2098 #1 \s_@@_nil #2 \@@_property_find_err:w
2099 {
2100 \str_clear:N \l_@@_property_str
2101 \msg_error:nnn { keys } { no-property } {#1}
2102 }
2103 % \end{macrocode}
2104 % \end{macro}
2105 % \end{macro}
2106 % \end{macro}
2107 % \end{macro}
2108 % \end{macro}
2109 %
2110 % \begin{macro}{\@@_define_code:n}
2111 % \begin{macro}[EXP]{\@@_define_code:nnn}
2112 % \begin{macro}[EXP]{\@@_define_code:w}
2113 % Two possible cases. If there is a value for the key, then just use
2114 % the function. If not, then a check to make sure there is no need for
2115 % a value with the property. If there should be one then complain,
2116 % otherwise execute it. For a \LaTeXe{} property like |.code| which
2117 % doesn't contain a |:|, treat it as having arity 1 and pass the
2118 % (empty) value to it.
2119 % \begin{macrocode}
2120 \cs_new_protected:Npn \@@_define_code:n #1
2121 {
2122 \bool_if:NTF \l_@@_no_value_bool
2123 {
2124 \@@_define_code:nnn
2125 { \use:c { \c_@@_props_root_str \l_@@_property_str } {#1} }
2126 { \use:c { \c_@@_props_root_str \l_@@_property_str } }
2127 {
2128 \msg_error:nnee { keys } { property-requires-value }
2129 \l_@@_property_str \l_keys_path_str
2130 }
2131 }
2132 { \use:c { \c_@@_props_root_str \l_@@_property_str } {#1} }
2133 }
2134 \cs_new:Npe \@@_define_code:nnn
2135 {
2136 \exp_not:N \exp_after:wN \exp_not:N \@@_define_code:w
2137 \exp_not:N \l_@@_property_str
2138 \c_colon_str \c_colon_str
2139 \exp_not:N \s_@@_stop
2140 }
2141 \use:e
2142 {
2143 \cs_new:Npn \exp_not:N \@@_define_code:w
2144 #1 \c_colon_str #2 \c_colon_str #3 \exp_not:N \s_@@_stop
2145 }
2146 {
2147 \tl_if_empty:nTF {#3}
2148 { \use_i:nnn }
2149 {
2150 \tl_if_empty:nTF {#2}
2151 { \use_ii:nnn }
2152 { \use_iii:nnn }
2153 }
2154 }
2155 % \end{macrocode}
2156 % \end{macro}
2157 % \end{macro}
2158 % \end{macro}
2159 %
2160 % \subsection{Turning properties into actions}
2161 %
2162 % \begin{macro}
2163 % {
2164 % \@@_bool_set:Nn, \@@_bool_set:cn,
2165 % \@@_bool_set_inverse:Nn, \@@_bool_set_inverse:cn
2166 % }
2167 % \begin{macro}{\@@_bool_set:Nnnn}
2168 % Boolean keys are really just choices, but all done by hand. The
2169 % second argument here is the scope: either empty or \texttt{ g } for
2170 % global.
2171 % \begin{macrocode}
2172 \cs_new_protected:Npn \@@_bool_set:Nn #1#2
2173 { \@@_bool_set:Nnnn #1 {#2} { true } { false } }
2174 \cs_generate_variant:Nn \@@_bool_set:Nn { c }
2175 \cs_new_protected:Npn \@@_bool_set_inverse:Nn #1#2
2176 { \@@_bool_set:Nnnn #1 {#2} { false } { true } }
2177 \cs_generate_variant:Nn \@@_bool_set_inverse:Nn { c }
2178 \cs_new_protected:Npn \@@_bool_set:Nnnn #1#2#3#4
2179 {
2180 \bool_if_exist:NF #1 { \bool_new:N #1 }
2181 \@@_choice_make:
2182 \@@_cmd_set:ne { \l_keys_path_str / true }
2183 { \exp_not:c { bool_ #2 set_ #3 :N } \exp_not:N #1 }
2184 \@@_cmd_set:ne { \l_keys_path_str / false }
2185 { \exp_not:c { bool_ #2 set_ #4 :N } \exp_not:N #1 }
2186 \@@_cmd_set_direct:nn { \l_keys_path_str / unknown }
2187 {
2188 \msg_error:nne { keys } { boolean-values-only }
2189 \l_keys_path_str
2190 }
2191 \@@_default_set:n { true }
2192 }
2193 \cs_generate_variant:Nn \@@_bool_set:Nn { c }
2194 % \end{macrocode}
2195 % \end{macro}
2196 % \end{macro}
2197 %
2198 % \begin{macro}{\@@_choice_make:, \@@_multichoice_make:}
2199 % \begin{macro}{\@@_choice_make:N}
2200 % \begin{macro}{\@@_choice_make_aux:N}
2201 % To make a choice from a key, two steps: set the code, and set the
2202 % unknown key. As multichoices and choices are essentially the same bar one
2203 % function, the code is given together.
2204 % \begin{macrocode}
2205 \cs_new_protected:Npn \@@_choice_make:
2206 { \@@_choice_make:N \@@_choice_find:n }
2207 \cs_new_protected:Npn \@@_multichoice_make:
2208 { \@@_choice_make:N \@@_multichoice_find:n }
2209 \cs_new_protected:Npn \@@_choice_make:N #1
2210 {
2211 \cs_if_exist:cTF
2212 { \c_@@_type_root_str \@@_parent:o \l_keys_path_str }
2213 {
2214 \str_if_eq:vnTF
2215 { \c_@@_type_root_str \@@_parent:o \l_keys_path_str }
2216 { choice }
2217 {
2218 \msg_error:nnee { keys } { nested-choice-key }
2219 \l_keys_path_tl { \@@_parent:o \l_keys_path_str }
2220 }
2221 { \@@_choice_make_aux:N #1 }
2222 }
2223 { \@@_choice_make_aux:N #1 }
2224 }
2225 \cs_new_protected:Npn \@@_choice_make_aux:N #1
2226 {
2227 \cs_set_nopar:cpn { \c_@@_type_root_str \l_keys_path_str }
2228 { choice }
2229 \@@_cmd_set_direct:nn \l_keys_path_str { #1 {##1} }
2230 \@@_cmd_set_direct:nn { \l_keys_path_str / unknown }
2231 {
2232 \msg_error:nnee { keys } { choice-unknown }
2233 \l_keys_path_str {##1}
2234 }
2235 }
2236 % \end{macrocode}
2237 % \end{macro}
2238 % \end{macro}
2239 % \end{macro}
2240 %
2241 % \begin{macro}{\@@_choices_make:nn, \@@_multichoices_make:nn}
2242 % \begin{macro}{\@@_choices_make:Nnn}
2243 % Auto-generating choices means setting up the root key as a choice, then
2244 % defining each choice in turn.
2245 % \begin{macrocode}
2246 \cs_new_protected:Npn \@@_choices_make:nn
2247 { \@@_choices_make:Nnn \@@_choice_make: }
2248 \cs_new_protected:Npn \@@_multichoices_make:nn
2249 { \@@_choices_make:Nnn \@@_multichoice_make: }
2250 \cs_new_protected:Npn \@@_choices_make:Nnn #1#2#3
2251 {
2252 #1
2253 \int_zero:N \l_keys_choice_int
2254 \clist_map_inline:nn {#2}
2255 {
2256 \int_incr:N \l_keys_choice_int
2257 \@@_cmd_set:ne
2258 { \l_keys_path_str / \@@_trim_spaces:n {##1} }
2259 {
2260 \str_set:Nn \exp_not:N \l_keys_choice_str {##1}
2261 \tl_set:Nn \exp_not:N \l_keys_choice_tl {##1}
2262 \int_set:Nn \exp_not:N \l_keys_choice_int
2263 { \int_use:N \l_keys_choice_int }
2264 \exp_not:n {#3}
2265 }
2266 }
2267 }
2268 % \end{macrocode}
2269 % \end{macro}
2270 % \end{macro}
2271 %
2272 % \begin{macro}
2273 % {
2274 % \@@_cmd_set:nn, \@@_cmd_set:Vn, \@@_cmd_set:ne, \@@_cmd_set:Vo,
2275 % \@@_cmd_set_direct:nn
2276 % }
2277 % Setting the code for a key first logs if appropriate that we are
2278 % defining a new key, then saves the code.
2279 % \begin{macrocode}
2280 \cs_new_protected:Npn \@@_cmd_set:nn #1#2
2281 { \@@_cmd_set_direct:nn {#1} { \@@_precompile:n {#2} } }
2282 \cs_generate_variant:Nn \@@_cmd_set:nn { ne , Vn , Vo }
2283 \cs_new_protected:Npn \@@_cmd_set_direct:nn #1#2
2284 { \cs_set_protected:cpn { \c_@@_code_root_str #1 } ##1 {#2} }
2285 % \end{macrocode}
2286 % \end{macro}
2287 %
2288 % \begin{macro}{\@@_cs_set:NNpn, \@@_cs_set:Ncpn}
2289 % Creating control sequences is a bit more tricky than other cases as
2290 % we need to pick up the |p| argument. To make the internals look clearer,
2291 % the trailing |n| argument here is just for appearance.
2292 % \begin{macrocode}
2293 \cs_new_protected:Npn \@@_cs_set:NNpn #1#2#3#
2294 {
2295 \cs_set_protected:cpe { \c_@@_code_root_str \l_keys_path_str } ##1
2296 {
2297 \@@_precompile:n
2298 { #1 \exp_not:N #2 \exp_not:n {#3} {##1} }
2299 }
2300 \use_none:n
2301 }
2302 \cs_generate_variant:Nn \@@_cs_set:NNpn { Nc }
2303 % \end{macrocode}
2304 % \end{macro}
2305 %
2306 % \begin{macro}{\@@_default_set:n}
2307 % Setting a default value is easy. These are stored using \cs{cs_set_nopar:cpe} as this
2308 % avoids any worries about whether a token list exists.
2309 % \begin{macrocode}
2310 \cs_new_protected:Npn \@@_default_set:n #1
2311 {
2312 \tl_if_empty:nTF {#1}
2313 {
2314 \@@_cs_undefine:c
2315 { \c_@@_default_root_str \l_keys_path_str }
2316 }
2317 {
2318 \cs_set_nopar:cpe
2319 { \c_@@_default_root_str \l_keys_path_str }
2320 { \exp_not:n {#1} }
2321 \@@_value_requirement:nn { required } { false }
2322 }
2323 }
2324 % \end{macrocode}
2325 % \end{macro}
2326 %
2327 % \begin{macro}{\@@_groups_set:n}
2328 % Assigning a key to one or more groups uses comma lists. As the list of
2329 % groups only exists if there is anything to do, the setting is done using
2330 % a scratch list. For the usual grouping reasons we use the low-level
2331 % approach to undefining a list. We also use the low-level approach for
2332 % the other case to avoid tripping up the |check-declarations| code.
2333 % \begin{macrocode}
2334 \cs_new_protected:Npn \@@_groups_set:n #1
2335 {
2336 \clist_set:Ne \l_@@_groups_clist { \tl_to_str:n {#1} }
2337 \clist_if_empty:NTF \l_@@_groups_clist
2338 {
2339 \@@_cs_undefine:c
2340 { \c_@@_groups_root_str \l_keys_path_str }
2341 }
2342 {
2343 \cs_set_eq:cN { \c_@@_groups_root_str \l_keys_path_str }
2344 \l_@@_groups_clist
2345 }
2346 }
2347 % \end{macrocode}
2348 % \end{macro}
2349 %
2350 % \begin{macro}{\@@_inherit_init:n}
2351 % Inheritance means ignoring anything already said about the key:
2352 % zap the lot and set up.
2353 % \begin{macrocode}
2354 \cs_new_protected:Npn \@@_inherit_init:n #1
2355 {
2356 \@@_undefine:
2357 \clist_set:Nn \l_@@_inherit_clist {#1}
2358 \cs_set_eq:cN { \c_@@_inherit_root_str \l_keys_path_str }
2359 \l_@@_inherit_clist
2360 }
2361 % \end{macrocode}
2362 % \end{macro}
2363 %
2364 % \begin{macro}{\@@_initialize:n}
2365 % A set up for initialization: just run the code if it exists.
2366 % We need to set the key string here, using the deprecated \texttt{tl~var}
2367 % as a piece of scratch space. We need to test \emph{first} for the key in
2368 % the current tree then any inheritance.
2369 % \begin{macrocode}
2370 \cs_new_protected:Npn \@@_initialize:n #1
2371 {
2372 \exp_after:wN \@@_find_key_module:wNN
2373 \l_keys_path_str \s_@@_stop
2374 \l_keys_key_tl \l_keys_key_str
2375 \tl_set_eq:NN \l_keys_key_tl \l_keys_key_str
2376 \tl_set:Nn \l_keys_value_tl {#1}
2377 \cs_if_exist:cTF { \c_@@_code_root_str \l_keys_path_str }
2378 {
2379 \str_clear:N \l_@@_inherit_str
2380 \@@_execute:nn \l_keys_path_str {#1}
2381 }
2382 { \@@_inherit:NNn \c_@@_code_root_str \@@_execute:n { } }
2383 }
2384 % \end{macrocode}
2385 % \end{macro}
2386 %
2387 % \begin{macro}{\@@_legacy_if_set:nn, \@@_legacy_if_inverse:nn}
2388 % \begin{macro}{\@@_legacy_if_inverse:nnnn}
2389 % Much the same as \pkg{expl3} booleans, except we assume that the switch
2390 % exists.
2391 % \begin{macrocode}
2392 \cs_new_protected:Npn \@@_legacy_if_set:nn #1#2
2393 { \@@_legacy_if_set:nnnn {#1} {#2} { true } { false } }
2394 \cs_new_protected:Npn \@@_legacy_if_set_inverse:nn #1#2
2395 { \@@_legacy_if_set:nnnn {#1} {#2} { false } { true } }
2396 \cs_new_protected:Npn \@@_legacy_if_set:nnnn #1#2#3#4
2397 {
2398 \@@_choice_make:
2399 \@@_cmd_set:ne { \l_keys_path_str / true }
2400 { \exp_not:c { legacy_if_#2 set_ #3 :n } { \exp_not:n {#1} } }
2401 \@@_cmd_set:ne { \l_keys_path_str / false }
2402 { \exp_not:c { legacy_if_#2 set_ #4 :n } { \exp_not:n {#1} } }
2403 \@@_cmd_set:nn { \l_keys_path_str / unknown }
2404 {
2405 \msg_error:nne { keys } { boolean-values-only }
2406 \l_keys_path_str
2407 }
2408 \@@_default_set:n { true }
2409 \cs_if_exist:cF { if#1 }
2410 {
2411 \cs:w newif \exp_after:wN \cs_end:
2412 \cs:w if#1 \cs_end:
2413 }
2414 }
2415 % \end{macrocode}
2416 % \end{macro}
2417 % \end{macro}
2418 %
2419 % \begin{macro}{\@@_meta_make:n}
2420 % \begin{macro}{\@@_meta_make:nn}
2421 % To create a meta-key, simply set up to pass data through. The internal
2422 % function is used here as a meta key should respect the prevailing
2423 % filtering, etc.
2424 % \begin{macrocode}
2425 \cs_new_protected:Npn \@@_meta_make:n
2426 { \exp_args:NV \@@_meta_make:nn \l_@@_module_str }
2427 \cs_new_protected:Npn \@@_meta_make:nn #1#2
2428 {
2429 \exp_args:NV \@@_cmd_set_direct:nn
2430 \l_keys_path_str { \@@_set:nn {#1} {#2} }
2431 }
2432 % \end{macrocode}
2433 % \end{macro}
2434 % \end{macro}
2435 %
2436 % \begin{macro}{\@@_prop_put:Nn, \@@_prop_put:cn}
2437 % Much the same as other variables, but needs a dedicated auxiliary.
2438 % \begin{macrocode}
2439 \cs_new_protected:Npn \@@_prop_put:Nn #1#2
2440 {
2441 \prop_if_exist:NF #1 { \prop_new:N #1 }
2442 \exp_after:wN \@@_find_key_module:wNN \l_keys_path_str \s_@@_stop
2443 \l_@@_tmpa_tl \l_@@_tmpb_tl
2444 \@@_cmd_set:ne \l_keys_path_str
2445 {
2446 \exp_not:c { prop_ #2 put:Nnn }
2447 \exp_not:N #1
2448 { \l_@@_tmpb_tl }
2449 \exp_not:n { {##1} }
2450 }
2451 }
2452 \cs_generate_variant:Nn \@@_prop_put:Nn { c }
2453 % \end{macrocode}
2454 % \end{macro}
2455 %
2456 % \begin{macro}{\@@_undefine:}
2457 % Undefining a key has to be done without \cs{cs_undefine:c} as that
2458 % function acts globally.
2459 % \begin{macrocode}
2460 \cs_new_protected:Npn \@@_undefine:
2461 {
2462 \clist_map_inline:nn
2463 { code , default , groups , inherit , type , check }
2464 {
2465 \@@_cs_undefine:c
2466 { \tl_use:c { c_@@_ ##1 _root_str } \l_keys_path_str }
2467 }
2468 }
2469 % \end{macrocode}
2470 % \end{macro}
2471 %
2472 % \begin{macro}{\@@_value_requirement:nn}
2473 % \begin{macro}{\@@_check_forbidden:, \@@_check_required:}
2474 % Validating key input is done using a second function which runs before
2475 % the main key code. Setting that up means setting it equal to a generic
2476 % stub which does the check. This approach makes the lookup very fast at
2477 % the cost of one additional csname per key that needs it. The cleanup here
2478 % has to know the structure of the following code.
2479 % \begin{macrocode}
2480 \cs_new_protected:Npn \@@_value_requirement:nn #1#2
2481 {
2482 \str_case:nnF {#2}
2483 {
2484 { true }
2485 {
2486 \cs_set_eq:cc
2487 { \c_@@_check_root_str \l_keys_path_str }
2488 { @@_check_ #1 : }
2489 }
2490 { false }
2491 {
2492 \cs_if_eq:ccT
2493 { \c_@@_check_root_str \l_keys_path_str }
2494 { @@_check_ #1 : }
2495 {
2496 \@@_cs_undefine:c
2497 { \c_@@_check_root_str \l_keys_path_str }
2498 }
2499 }
2500 }
2501 {
2502 \msg_error:nne { keys }
2503 { boolean-values-only }
2504 { .value_ #1 :n }
2505 }
2506 }
2507 \cs_new_protected:Npn \@@_check_forbidden:
2508 {
2509 \bool_if:NF \l_@@_no_value_bool
2510 {
2511 \msg_error:nnee { keys } { value-forbidden }
2512 \l_keys_path_str \l_keys_value_tl
2513 \use_none:nnn
2514 }
2515 }
2516 \cs_new_protected:Npn \@@_check_required:
2517 {
2518 \bool_if:NT \l_@@_no_value_bool
2519 {
2520 \msg_error:nne { keys } { value-required }
2521 \l_keys_path_str
2522 \use_none:nnn
2523 }
2524 }
2525 % \end{macrocode}
2526 % \end{macro}
2527 % \end{macro}
2528 %
2529 % \begin{macro}{\@@_usage:n}
2530 % \begin{macro}{\@@_usage:NN}
2531 % \begin{macro}{\@@_usage:w}
2532 % \begin{macro}{\@@_usage_aux:w}
2533 % Save the relevant data.
2534 % \begin{macrocode}
2535 \cs_new_protected:Npn \@@_usage:n #1
2536 {
2537 \str_case:nnF {#1}
2538 {
2539 { general }
2540 {
2541 \@@_usage:NN \l_keys_usage_load_prop
2542 \c_false_bool
2543 \@@_usage:NN \l_keys_usage_preamble_prop
2544 \c_false_bool
2545 }
2546 { load }
2547 {
2548 \@@_usage:NN \l_keys_usage_load_prop
2549 \c_true_bool
2550 \@@_usage:NN \l_keys_usage_preamble_prop
2551 \c_false_bool
2552 }
2553 { preamble }
2554 {
2555 \@@_usage:NN \l_keys_usage_load_prop
2556 \c_false_bool
2557 \@@_usage:NN \l_keys_usage_preamble_prop
2558 \c_true_bool
2559 }
2560 }
2561 {
2562 \msg_error:nnnn { keys }
2563 { choice-unknown }
2564 { .usage:n }
2565 {#1}
2566 }
2567 }
2568 \cs_new_protected:Npn \@@_usage:NN #1#2
2569 {
2570 \prop_get:NVNF #1 \l_@@_module_str \l_@@_tmpa_tl
2571 { \tl_clear:N \l_@@_tmpa_tl }
2572 \tl_set:Ne \l_@@_tmpb_tl
2573 {
2574 \exp_after:wN \exp_after:wN \exp_after:wN \@@_usage:w \exp_after:wN
2575 \l_keys_path_str \exp_after:wN / \exp_after:wN \s_@@_stop
2576 \exp_after:wN { \l_keys_path_str }
2577 }
2578 \bool_if:NTF #2
2579 { \clist_put_right:NV \l_@@_tmpa_tl \l_@@_tmpb_tl }
2580 { \clist_remove_all:NV \l_@@_tmpa_tl \l_@@_tmpb_tl }
2581 \prop_put:NVV #1 \l_@@_module_str
2582 \l_@@_tmpa_tl
2583 }
2584 \cs_new:Npn \@@_usage:w #1 / #2 \s_@@_stop #3
2585 {
2586 \tl_if_blank:nTF {#2}
2587 {#1}
2588 { \@@_usage_aux:w #3 \s_@@_stop }
2589 }
2590 \cs_new:Npn \@@_usage_aux:w #1 / #2 \s_@@_stop {#2}
2591 % \end{macrocode}
2592 % \end{macro}
2593 % \end{macro}
2594 % \end{macro}
2595 % \end{macro}
2596 %
2597 % \begin{macro}{\@@_variable_set:NnnN, \@@_variable_set:cnnN}
2598 % \begin{macro}{\@@_variable_set_required:NnnN, \@@_variable_set_required:cnnN}
2599 % Setting a variable takes the type and scope separately so that
2600 % it is easy to make a new variable if needed.
2601 % \begin{macrocode}
2602 \cs_new_protected:Npn \@@_variable_set:NnnN #1#2#3#4
2603 {
2604 \use:c { #2_if_exist:NF } #1 { \use:c { #2 _new:N } #1 }
2605 \@@_cmd_set:ne \l_keys_path_str
2606 {
2607 \exp_not:c { #2 _ #3 set:N #4 }
2608 \exp_not:N #1
2609 \exp_not:n { {##1} }
2610 }
2611 }
2612 \cs_generate_variant:Nn \@@_variable_set:NnnN { c }
2613 \cs_new_protected:Npn \@@_variable_set_required:NnnN #1#2#3#4
2614 {
2615 \@@_variable_set:NnnN #1 {#2} {#3} #4
2616 \@@_value_requirement:nn { required } { true }
2617 }
2618 \cs_generate_variant:Nn \@@_variable_set_required:NnnN { c }
2619 % \end{macrocode}
2620 % \end{macro}
2621 % \end{macro}
2622 %
2623 % \subsection{Creating key properties}
2624 %
2625 % The key property functions are all wrappers for internal functions,
2626 % meaning that things stay readable and can also be altered later on.
2627 %
2628 % Importantly, while key properties have \enquote{normal} argument specs, the
2629 % underlying code always supplies one braced argument to these. As such, argument
2630 % expansion is handled by hand rather than using the standard tools. This shows
2631 % up particularly for the two-argument properties, where things would otherwise
2632 % go badly wrong.
2633 %
2634 % \begin{macro}{.bool_set:N, .bool_set:c}
2635 % \begin{macro}{.bool_gset:N, .bool_gset:c}
2636 % One function for this.
2637 % \begin{macrocode}
2638 \cs_new_protected:cpn { \c_@@_props_root_str .bool_set:N } #1
2639 { \@@_bool_set:Nn #1 { } }
2640 \cs_new_protected:cpn { \c_@@_props_root_str .bool_set:c } #1
2641 { \@@_bool_set:cn {#1} { } }
2642 \cs_new_protected:cpn { \c_@@_props_root_str .bool_gset:N } #1
2643 { \@@_bool_set:Nn #1 { g } }
2644 \cs_new_protected:cpn { \c_@@_props_root_str .bool_gset:c } #1
2645 { \@@_bool_set:cn {#1} { g } }
2646 % \end{macrocode}
2647 % \end{macro}
2648 % \end{macro}
2649 %
2650 % \begin{macro}{.bool_set_inverse:N, .bool_set_inverse:c}
2651 % \begin{macro}{.bool_gset_inverse:N, .bool_gset_inverse:c}
2652 % One function for this.
2653 % \begin{macrocode}
2654 \cs_new_protected:cpn { \c_@@_props_root_str .bool_set_inverse:N } #1
2655 { \@@_bool_set_inverse:Nn #1 { } }
2656 \cs_new_protected:cpn { \c_@@_props_root_str .bool_set_inverse:c } #1
2657 { \@@_bool_set_inverse:cn {#1} { } }
2658 \cs_new_protected:cpn { \c_@@_props_root_str .bool_gset_inverse:N } #1
2659 { \@@_bool_set_inverse:Nn #1 { g } }
2660 \cs_new_protected:cpn { \c_@@_props_root_str .bool_gset_inverse:c } #1
2661 { \@@_bool_set_inverse:cn {#1} { g } }
2662 % \end{macrocode}
2663 % \end{macro}
2664 % \end{macro}
2665 %
2666 % \begin{macro}{.choice:}
2667 % Making a choice is handled internally, as it is also needed by
2668 % \texttt{.generate_choices:n}.
2669 % \begin{macrocode}
2670 \cs_new_protected:cpn { \c_@@_props_root_str .choice: }
2671 { \@@_choice_make: }
2672 % \end{macrocode}
2673 % \end{macro}
2674 %
2675 % \begin{macro}{.choices:nn, .choices:Vn, .choices:en, .choices:on, .choices:xn}
2676 % For auto-generation of a series of mutually-exclusive choices.
2677 % Here, |#1| consists of two separate
2678 % arguments, hence the slightly odd-looking implementation.
2679 % \begin{macrocode}
2680 \cs_new_protected:cpn { \c_@@_props_root_str .choices:nn } #1
2681 { \@@_choices_make:nn #1 }
2682 \cs_new_protected:cpn { \c_@@_props_root_str .choices:Vn } #1
2683 { \exp_args:NV \@@_choices_make:nn #1 }
2684 \cs_new_protected:cpn { \c_@@_props_root_str .choices:en } #1
2685 { \exp_args:Ne \@@_choices_make:nn #1 }
2686 \cs_new_protected:cpn { \c_@@_props_root_str .choices:on } #1
2687 { \exp_args:No \@@_choices_make:nn #1 }
2688 \cs_new_protected:cpn { \c_@@_props_root_str .choices:xn } #1
2689 { \exp_args:Nx \@@_choices_make:nn #1 }
2690 % \end{macrocode}
2691 % \end{macro}
2692 %
2693 % \begin{macro}{.code:n}
2694 % Creating code is simply a case of passing through to the underlying
2695 % \texttt{set} function.
2696 % \begin{macrocode}
2697 \cs_new_protected:cpn { \c_@@_props_root_str .code:n } #1
2698 { \@@_cmd_set:nn \l_keys_path_str {#1} }
2699 % \end{macrocode}
2700 % \end{macro}
2701 %
2702 % \begin{macro}{.clist_set:N, .clist_set:c}
2703 % \begin{macro}{.clist_gset:N, .clist_gset:c}
2704 % \begin{macrocode}
2705 \cs_new_protected:cpn { \c_@@_props_root_str .clist_set:N } #1
2706 { \@@_variable_set:NnnN #1 { clist } { } n }
2707 \cs_new_protected:cpn { \c_@@_props_root_str .clist_set:c } #1
2708 { \@@_variable_set:cnnN {#1} { clist } { } n }
2709 \cs_new_protected:cpn { \c_@@_props_root_str .clist_gset:N } #1
2710 { \@@_variable_set:NnnN #1 { clist } { g } n }
2711 \cs_new_protected:cpn { \c_@@_props_root_str .clist_gset:c } #1
2712 { \@@_variable_set:cnnN {#1} { clist } { g } n }
2713 % \end{macrocode}
2714 % \end{macro}
2715 % \end{macro}
2716 %
2717 % \begin{macro}
2718 % {.cs_set:Np, .cs_set:cp, .cs_set_protected:Np, .cs_set_protected:cp}
2719 % \begin{macro}
2720 % {.cs_gset:Np, .cs_gset:cp, .cs_gset_protected:Np, .cs_gset_protected:cp}
2721 % \begin{macrocode}
2722 \cs_new_protected:cpn { \c_@@_props_root_str .cs_set:Np } #1
2723 { \@@_cs_set:NNpn \cs_set:Npn #1 { } }
2724 \cs_new_protected:cpn { \c_@@_props_root_str .cs_set:cp } #1
2725 { \@@_cs_set:Ncpn \cs_set:Npn #1 { } }
2726 \cs_new_protected:cpn { \c_@@_props_root_str .cs_set_protected:Np } #1
2727 { \@@_cs_set:NNpn \cs_set_protected:Npn #1 { } }
2728 \cs_new_protected:cpn { \c_@@_props_root_str .cs_set_protected:cp } #1
2729 { \@@_cs_set:Ncpn \cs_set_protected:Npn #1 { } }
2730 \cs_new_protected:cpn { \c_@@_props_root_str .cs_gset:Np } #1
2731 { \@@_cs_set:NNpn \cs_gset:Npn #1 { } }
2732 \cs_new_protected:cpn { \c_@@_props_root_str .cs_gset:cp } #1
2733 { \@@_cs_set:Ncpn \cs_gset:Npn #1 { } }
2734 \cs_new_protected:cpn { \c_@@_props_root_str .cs_gset_protected:Np } #1
2735 { \@@_cs_set:NNpn \cs_gset_protected:Npn #1 { } }
2736 \cs_new_protected:cpn { \c_@@_props_root_str .cs_gset_protected:cp } #1
2737 { \@@_cs_set:Ncpn \cs_gset_protected:Npn #1 { } }
2738 % \end{macrocode}
2739 % \end{macro}
2740 % \end{macro}
2741 %
2742 % \begin{macro}{.default:n, .default:V, .default:e, .default:o, .default:x}
2743 % Expansion is left to the internal functions.
2744 % \begin{macrocode}
2745 \cs_new_protected:cpn { \c_@@_props_root_str .default:n } #1
2746 { \@@_default_set:n {#1} }
2747 \cs_new_protected:cpn { \c_@@_props_root_str .default:V } #1
2748 { \exp_args:NV \@@_default_set:n #1 }
2749 \cs_new_protected:cpn { \c_@@_props_root_str .default:e } #1
2750 { \exp_args:Ne \@@_default_set:n {#1} }
2751 \cs_new_protected:cpn { \c_@@_props_root_str .default:o } #1
2752 { \exp_args:No \@@_default_set:n {#1} }
2753 \cs_new_protected:cpn { \c_@@_props_root_str .default:x } #1
2754 { \exp_args:Nx \@@_default_set:n {#1} }
2755 % \end{macrocode}
2756 % \end{macro}
2757 %
2758 % \begin{macro}{.dim_set:N, .dim_set:c}
2759 % \begin{macro}{.dim_gset:N, .dim_gset:c}
2760 % Setting a variable is very easy: just pass the data along.
2761 % \begin{macrocode}
2762 \cs_new_protected:cpn { \c_@@_props_root_str .dim_set:N } #1
2763 { \@@_variable_set_required:NnnN #1 { dim } { } n }
2764 \cs_new_protected:cpn { \c_@@_props_root_str .dim_set:c } #1
2765 { \@@_variable_set_required:cnnN {#1} { dim } { } n }
2766 \cs_new_protected:cpn { \c_@@_props_root_str .dim_gset:N } #1
2767 { \@@_variable_set_required:NnnN #1 { dim } { g } n }
2768 \cs_new_protected:cpn { \c_@@_props_root_str .dim_gset:c } #1
2769 { \@@_variable_set_required:cnnN {#1} { dim } { g } n }
2770 % \end{macrocode}
2771 % \end{macro}
2772 % \end{macro}
2773 %
2774 % \begin{macro}{.fp_set:N, .fp_set:c}
2775 % \begin{macro}{.fp_gset:N, .fp_gset:c}
2776 % Setting a variable is very easy: just pass the data along.
2777 % \begin{macrocode}
2778 \cs_new_protected:cpn { \c_@@_props_root_str .fp_set:N } #1
2779 { \@@_variable_set_required:NnnN #1 { fp } { } n }
2780 \cs_new_protected:cpn { \c_@@_props_root_str .fp_set:c } #1
2781 { \@@_variable_set_required:cnnN {#1} { fp } { } n }
2782 \cs_new_protected:cpn { \c_@@_props_root_str .fp_gset:N } #1
2783 { \@@_variable_set_required:NnnN #1 { fp } { g } n }
2784 \cs_new_protected:cpn { \c_@@_props_root_str .fp_gset:c } #1
2785 { \@@_variable_set_required:cnnN {#1} { fp } { g } n }
2786 % \end{macrocode}
2787 % \end{macro}
2788 % \end{macro}
2789 %
2790 % \begin{macro}{.groups:n}
2791 % A single property to create groups of keys.
2792 % \begin{macrocode}
2793 \cs_new_protected:cpn { \c_@@_props_root_str .groups:n } #1
2794 { \@@_groups_set:n {#1} }
2795 % \end{macrocode}
2796 % \end{macro}
2797 %
2798 % \begin{macro}{.inherit:n}
2799 % Nothing complex: only one variant at the moment!
2800 % \begin{macrocode}
2801 \cs_new_protected:cpn { \c_@@_props_root_str .inherit:n } #1
2802 { \@@_inherit_init:n {#1} }
2803 % \end{macrocode}
2804 % \end{macro}
2805 %
2806 % \begin{macro}{.initial:n, .initial:V, .initial:e, .initial:o, .initial:x}
2807 % The standard hand-off approach.
2808 % \begin{macrocode}
2809 \cs_new_protected:cpn { \c_@@_props_root_str .initial:n } #1
2810 { \@@_initialize:n {#1} }
2811 \cs_new_protected:cpn { \c_@@_props_root_str .initial:V } #1
2812 { \exp_args:NV \@@_initialize:n #1 }
2813 \cs_new_protected:cpn { \c_@@_props_root_str .initial:e } #1
2814 { \exp_args:Ne \@@_initialize:n {#1} }
2815 \cs_new_protected:cpn { \c_@@_props_root_str .initial:o } #1
2816 { \exp_args:No \@@_initialize:n {#1} }
2817 \cs_new_protected:cpn { \c_@@_props_root_str .initial:x } #1
2818 { \exp_args:Nx \@@_initialize:n {#1} }
2819 % \end{macrocode}
2820 % \end{macro}
2821 %
2822 % \begin{macro}{.int_set:N, .int_set:c}
2823 % \begin{macro}{.int_gset:N, .int_gset:c}
2824 % Setting a variable is very easy: just pass the data along.
2825 % \begin{macrocode}
2826 \cs_new_protected:cpn { \c_@@_props_root_str .int_set:N } #1
2827 { \@@_variable_set_required:NnnN #1 { int } { } n }
2828 \cs_new_protected:cpn { \c_@@_props_root_str .int_set:c } #1
2829 { \@@_variable_set_required:cnnN {#1} { int } { } n }
2830 \cs_new_protected:cpn { \c_@@_props_root_str .int_gset:N } #1
2831 { \@@_variable_set_required:NnnN #1 { int } { g } n }
2832 \cs_new_protected:cpn { \c_@@_props_root_str .int_gset:c } #1
2833 { \@@_variable_set_required:cnnN {#1} { int } { g } n }
2834 % \end{macrocode}
2835 % \end{macro}
2836 % \end{macro}
2837 %
2838 % \begin{macro}
2839 % {
2840 % .legacy_if_set:n, .legacy_if_gset:n,
2841 % .legacy_if_set_inverse:n, .legacy_if_gset_inverse:n
2842 % }
2843 % \begin{macrocode}
2844 \cs_new_protected:cpn { \c_@@_props_root_str .legacy_if_set:n } #1
2845 { \@@_legacy_if_set:nn {#1} { } }
2846 \cs_new_protected:cpn { \c_@@_props_root_str .legacy_if_gset:n } #1
2847 { \@@_legacy_if_set:nn {#1} { g } }
2848 \cs_new_protected:cpn { \c_@@_props_root_str .legacy_if_set_inverse:n } #1
2849 { \@@_legacy_if_set_inverse:nn {#1} { } }
2850 \cs_new_protected:cpn { \c_@@_props_root_str .legacy_if_gset_inverse:n } #1
2851 { \@@_legacy_if_set_inverse:nn {#1} { g } }
2852 % \end{macrocode}
2853 % \end{macro}
2854 %
2855 % \begin{macro}{.meta:n}
2856 % Making a meta is handled internally.
2857 % \begin{macrocode}
2858 \cs_new_protected:cpn { \c_@@_props_root_str .meta:n } #1
2859 { \@@_meta_make:n {#1} }
2860 % \end{macrocode}
2861 % \end{macro}
2862 %
2863 % \begin{macro}{.meta:nn}
2864 % Meta with path: potentially lots of variants, but for the moment
2865 % no so many defined.
2866 % \begin{macrocode}
2867 \cs_new_protected:cpn { \c_@@_props_root_str .meta:nn } #1
2868 { \@@_meta_make:nn #1 }
2869 % \end{macrocode}
2870 % \end{macro}
2871 %
2872 % \begin{macro}{.multichoice:}
2873 % \begin{macro}{.multichoices:nn, .multichoices:Vn, .multichoices:en, .multichoices:on, .multichoices:xn}
2874 % The same idea as \texttt{.choice:} and \texttt{.choices:nn}, but
2875 % where more than one choice is allowed.
2876 % \begin{macrocode}
2877 \cs_new_protected:cpn { \c_@@_props_root_str .multichoice: }
2878 { \@@_multichoice_make: }
2879 \cs_new_protected:cpn { \c_@@_props_root_str .multichoices:nn } #1
2880 { \@@_multichoices_make:nn #1 }
2881 \cs_new_protected:cpn { \c_@@_props_root_str .multichoices:Vn } #1
2882 { \exp_args:NV \@@_multichoices_make:nn #1 }
2883 \cs_new_protected:cpn { \c_@@_props_root_str .multichoices:en } #1
2884 { \exp_args:Ne \@@_multichoices_make:nn #1 }
2885 \cs_new_protected:cpn { \c_@@_props_root_str .multichoices:on } #1
2886 { \exp_args:No \@@_multichoices_make:nn #1 }
2887 \cs_new_protected:cpn { \c_@@_props_root_str .multichoices:xn } #1
2888 { \exp_args:Nx \@@_multichoices_make:nn #1 }
2889 % \end{macrocode}
2890 % \end{macro}
2891 % \end{macro}
2892 %
2893 % \begin{macro}{.muskip_set:N, .muskip_set:c, .muskip_gset:N, .muskip_gset:c}
2894 % Setting a variable is very easy: just pass the data along.
2895 % \begin{macrocode}
2896 \cs_new_protected:cpn { \c_@@_props_root_str .muskip_set:N } #1
2897 { \@@_variable_set_required:NnnN #1 { muskip } { } n }
2898 \cs_new_protected:cpn { \c_@@_props_root_str .muskip_set:c } #1
2899 { \@@_variable_set_required:cnnN {#1} { muskip } { } n }
2900 \cs_new_protected:cpn { \c_@@_props_root_str .muskip_gset:N } #1
2901 { \@@_variable_set_required:NnnN #1 { muskip } { g } n }
2902 \cs_new_protected:cpn { \c_@@_props_root_str .muskip_gset:c } #1
2903 { \@@_variable_set_required:cnnN {#1} { muskip } { g } n }
2904 % \end{macrocode}
2905 % \end{macro}
2906 %
2907 % \begin{macro}{.prop_put:N, .prop_put:c, .prop_gput:N, .prop_gput:c}
2908 % Setting a variable is very easy: just pass the data along.
2909 % \begin{macrocode}
2910 \cs_new_protected:cpn { \c_@@_props_root_str .prop_put:N } #1
2911 { \@@_prop_put:Nn #1 { } }
2912 \cs_new_protected:cpn { \c_@@_props_root_str .prop_put:c } #1
2913 { \@@_prop_put:cn {#1} { } }
2914 \cs_new_protected:cpn { \c_@@_props_root_str .prop_gput:N } #1
2915 { \@@_prop_put:Nn #1 { g } }
2916 \cs_new_protected:cpn { \c_@@_props_root_str .prop_gput:c } #1
2917 { \@@_prop_put:cn {#1} { g } }
2918 % \end{macrocode}
2919 % \end{macro}
2920 %
2921 % \begin{macro}{.skip_set:N, .skip_set:c}
2922 % \begin{macro}{.skip_gset:N, .skip_gset:c}
2923 % Setting a variable is very easy: just pass the data along.
2924 % \begin{macrocode}
2925 \cs_new_protected:cpn { \c_@@_props_root_str .skip_set:N } #1
2926 { \@@_variable_set_required:NnnN #1 { skip } { } n }
2927 \cs_new_protected:cpn { \c_@@_props_root_str .skip_set:c } #1
2928 { \@@_variable_set_required:cnnN {#1} { skip } { } n }
2929 \cs_new_protected:cpn { \c_@@_props_root_str .skip_gset:N } #1
2930 { \@@_variable_set_required:NnnN #1 { skip } { g } n }
2931 \cs_new_protected:cpn { \c_@@_props_root_str .skip_gset:c } #1
2932 { \@@_variable_set_required:cnnN {#1} { skip } { g } n }
2933 % \end{macrocode}
2934 % \end{macro}
2935 % \end{macro}
2936 %
2937 % \begin{macro}{.str_set:N, .str_set:c}
2938 % \begin{macro}{.str_gset:N, .str_gset:c}
2939 % \begin{macro}{.str_set_e:N, .str_set_e:c}
2940 % \begin{macro}{.str_gset_e:N, .str_gset_e:c}
2941 % Setting a variable is very easy: just pass the data along.
2942 % \begin{macrocode}
2943 \cs_new_protected:cpn { \c_@@_props_root_str .str_set:N } #1
2944 { \@@_variable_set:NnnN #1 { str } { } n }
2945 \cs_new_protected:cpn { \c_@@_props_root_str .str_set:c } #1
2946 { \@@_variable_set:cnnN {#1} { str } { } n }
2947 \cs_new_protected:cpn { \c_@@_props_root_str .str_set_e:N } #1
2948 { \@@_variable_set:NnnN #1 { str } { } e }
2949 \cs_new_protected:cpn { \c_@@_props_root_str .str_set_e:c } #1
2950 { \@@_variable_set:cnnN {#1} { str } { } e }
2951 \cs_new_protected:cpn { \c_@@_props_root_str .str_gset:N } #1
2952 { \@@_variable_set:NnnN #1 { str } { g } n }
2953 \cs_new_protected:cpn { \c_@@_props_root_str .str_gset:c } #1
2954 { \@@_variable_set:cnnN {#1} { str } { g } n }
2955 \cs_new_protected:cpn { \c_@@_props_root_str .str_gset_e:N } #1
2956 { \@@_variable_set:NnnN #1 { str } { g } e }
2957 \cs_new_protected:cpn { \c_@@_props_root_str .str_gset_e:c } #1
2958 { \@@_variable_set:cnnN {#1} { str } { g } e }
2959 % \end{macrocode}
2960 % \end{macro}
2961 % \end{macro}
2962 % \end{macro}
2963 % \end{macro}
2964 %
2965 % \begin{macro}{.tl_set:N, .tl_set:c}
2966 % \begin{macro}{.tl_gset:N, .tl_gset:c}
2967 % \begin{macro}{.tl_set_e:N, .tl_set_e:c}
2968 % \begin{macro}{.tl_gset_e:N, .tl_gset_e:c}
2969 % Setting a variable is very easy: just pass the data along.
2970 % \begin{macrocode}
2971 \cs_new_protected:cpn { \c_@@_props_root_str .tl_set:N } #1
2972 { \@@_variable_set:NnnN #1 { tl } { } n }
2973 \cs_new_protected:cpn { \c_@@_props_root_str .tl_set:c } #1
2974 { \@@_variable_set:cnnN {#1} { tl } { } n }
2975 \cs_new_protected:cpn { \c_@@_props_root_str .tl_set_e:N } #1
2976 { \@@_variable_set:NnnN #1 { tl } { } e }
2977 \cs_new_protected:cpn { \c_@@_props_root_str .tl_set_e:c } #1
2978 { \@@_variable_set:cnnN {#1} { tl } { } e }
2979 \cs_new_protected:cpn { \c_@@_props_root_str .tl_gset:N } #1
2980 { \@@_variable_set:NnnN #1 { tl } { g } n }
2981 \cs_new_protected:cpn { \c_@@_props_root_str .tl_gset:c } #1
2982 { \@@_variable_set:cnnN {#1} { tl } { g } n }
2983 \cs_new_protected:cpn { \c_@@_props_root_str .tl_gset_e:N } #1
2984 { \@@_variable_set:NnnN #1 { tl } { g } e }
2985 \cs_new_protected:cpn { \c_@@_props_root_str .tl_gset_e:c } #1
2986 { \@@_variable_set:cnnN {#1} { tl } { g } e }
2987 % \end{macrocode}
2988 % \end{macro}
2989 % \end{macro}
2990 % \end{macro}
2991 % \end{macro}
2992 %
2993 % \begin{macro}{.undefine:}
2994 % Another simple wrapper.
2995 % \begin{macrocode}
2996 \cs_new_protected:cpn { \c_@@_props_root_str .undefine: }
2997 { \@@_undefine: }
2998 % \end{macrocode}
2999 % \end{macro}
3000 %
3001 % \begin{macro}{.usage:n}
3002 % \begin{macrocode}
3003 \cs_new_protected:cpn { \c_@@_props_root_str .usage:n } #1
3004 { \@@_usage:n {#1} }
3005 % \end{macrocode}
3006 % \end{macro}
3007 %
3008 % \begin{macro}{.value_forbidden:n}
3009 % \begin{macro}{.value_required:n}
3010 % These are very similar, so both call the same function.
3011 % \begin{macrocode}
3012 \cs_new_protected:cpn { \c_@@_props_root_str .value_forbidden:n } #1
3013 { \@@_value_requirement:nn { forbidden } {#1} }
3014 \cs_new_protected:cpn { \c_@@_props_root_str .value_required:n } #1
3015 { \@@_value_requirement:nn { required } {#1} }
3016 % \end{macrocode}
3017 % \end{macro}
3018 % \end{macro}
3019 %
3020 % \subsection{Setting keys}
3021 %
3022 % \begin{macro}{\@@_set:nnnnNn}
3023 % \begin{macro}[EXP]{\@@_reset_bool:N, \@@_reset_var:N}
3024 % \begin{macro}{\@@_set:nn}
3025 % \begin{macro}{\@@_set:nnn}
3026 % The aim here is to allow nesting of key setting without needing lots of
3027 % tracking. That is done by expanding the appropriate tokens \enquote{around}
3028 % the core keyval parsing. As there are several different sub-paths, this
3029 % needs a few steps and some generic auxiliaries. The arguments here are
3030 % \begin{enumerate}
3031 % \item The root for keys
3032 % \item The key groups
3033 % \item The keys themselves
3034 % \item The relative root for return of unset keys
3035 % \item The \texttt{clist} var for returning unset keys
3036 % \item The code to set up the correct selection approach
3037 % \end{enumerate}
3038 % \begin{macrocode}
3039 \cs_new_protected:Npn \@@_set:nnnnNn #1#2#3#4#5#6
3040 {
3041 \use:e
3042 {
3043 \exp_not:n
3044 {
3045 \clist_clear:N \l_@@_unused_clist
3046 \clist_set:Ne \l_@@_selective_clist { \tl_to_str:n {#2} }
3047 \tl_set:Nn \l_@@_relative_tl {#4}
3048 #6
3049 \@@_set:nn {#1} {#3}
3050 \clist_set_eq:NN #5 \l_@@_unused_clist
3051 }
3052 \@@_reset_bool:N \l_@@_only_known_bool
3053 \@@_reset_bool:N \l_@@_exclude_bool
3054 \@@_reset_bool:N \l_@@_selective_bool
3055 \@@_reset_var:N \l_@@_unused_clist
3056 \@@_reset_var:N \l_@@_selective_clist
3057 \@@_reset_var:N \l_@@_relative_tl
3058 \@@_reset_var:N \l_@@_inherit_str
3059 \@@_reset_var:N \l_keys_choice_tl
3060 \@@_reset_var:N \l_keys_choice_str
3061 \@@_reset_var:N \l_keys_key_tl
3062 \@@_reset_var:N \l_keys_key_str
3063 \@@_reset_var:N \l_keys_path_tl
3064 \@@_reset_var:N \l_keys_path_str
3065 \@@_reset_var:N \l_keys_value_tl
3066 \int_set:Nn \l_keys_choice_int { \int_use:N \l_keys_choice_int }
3067 }
3068 }
3069 \cs_new:Npn \@@_reset_bool:N #1
3070 {
3071 \exp_not:c
3072 { bool_set_ \bool_if:NTF #1 { true } { false } :N }
3073 \exp_not:N #1
3074 }
3075 \cs_new:Npn \@@_reset_var:N #1
3076 {
3077 \exp_not:n
3078 { \__kernel_tl_set:Nx #1 }
3079 { \exp_not:N \exp_not:n { \exp_not:o { #1 } } }
3080 }
3081 \cs_new_protected:Npn \@@_set:nn #1#2
3082 { \exp_args:No \@@_set:nnn \l_@@_module_str {#1} {#2} }
3083 \cs_new_protected:Npn \@@_set:nnn #1#2#3
3084 {
3085 \str_set:Ne \l_@@_module_str { \@@_trim_spaces:n {#2} }
3086 \keyval_parse:NNn \@@_set_keyval:n \@@_set_keyval:nn {#3}
3087 \str_set:Nn \l_@@_module_str {#1}
3088 }
3089 % \end{macrocode}
3090 % \end{macro}
3091 % \end{macro}
3092 % \end{macro}
3093 % \end{macro}
3094 %
3095 % \begin{macro}
3096 % {
3097 % \keys_set:nn, \keys_set:nV, \keys_set:nv, \keys_set:ne,
3098 % \keys_set:no, \keys_set:nx
3099 % }
3100 % A simple wrapper allowing for nesting.
3101 % \begin{macrocode}
3102 \cs_new_protected:Npn \keys_set:nn #1#2
3103 {
3104 \@@_set:nnnnNn
3105 {#1} { } {#2} { \q_@@_no_value } \l_@@_tmp_clist
3106 {
3107 \bool_set_false:N \l_@@_only_known_bool
3108 \bool_set_false:N \l_@@_exclude_bool
3109 \bool_set_false:N \l_@@_selective_bool
3110 }
3111 }
3112 \cs_generate_variant:Nn \keys_set:nn { nV , nv , ne , no , nx }
3113 % \end{macrocode}
3114 % \end{macro}
3115 %
3116 % \begin{macro}
3117 % {
3118 % \keys_set_known:nnnN, \keys_set_known:nVnN,
3119 % \keys_set_known:nvnN, \keys_set_known:nenN,
3120 % \keys_set_known:nonN
3121 % }
3122 % \begin{macro}
3123 % {
3124 % \keys_set_known:nnN, \keys_set_known:nVN,
3125 % \keys_set_known:nvN, \keys_set_known:neN,
3126 % \keys_set_known:noN
3127 % }
3128 % \begin{macro}
3129 % {
3130 % \keys_set_known:nn, \keys_set_known:nV,
3131 % \keys_set_known:nv, \keys_set_known:ne,
3132 % \keys_set_known:no
3133 % }
3134 % Simply set the right variables.
3135 % \begin{macrocode}
3136 \cs_new_protected:Npn \keys_set_known:nnnN #1#2#3#4
3137 {
3138 \@@_set:nnnnNn
3139 {#1} { } {#2} {#3} #4
3140 {
3141 \bool_set_true:N \l_@@_only_known_bool
3142 \bool_set_false:N \l_@@_exclude_bool
3143 \bool_set_false:N \l_@@_selective_bool
3144 }
3145 }
3146 \cs_generate_variant:Nn \keys_set_known:nnnN { nV , nv , ne , no }
3147 \cs_new_protected:Npn \keys_set_known:nnN #1#2#3
3148 { \keys_set_known:nnnN {#1} {#2} { \q_@@_no_value } #3 }
3149 \cs_generate_variant:Nn \keys_set_known:nnN { nV , nv , ne , no }
3150 \cs_new_protected:Npn \keys_set_known:nn #1#2
3151 { \keys_set_known:nnnN {#1} {#2} { \q_@@_no_value } \l_@@_tmp_clist }
3152 \cs_generate_variant:Nn \keys_set_known:nn { nV , nv , ne , no }
3153 % \end{macrocode}
3154 % \end{macro}
3155 % \end{macro}
3156 % \end{macro}
3157 %
3158 % \begin{macro}
3159 % {
3160 % \keys_set_exclude_groups:nnnN, \keys_set_exclude_groups:nnVN,
3161 % \keys_set_exclude_groups:nnvN, \keys_set_exclude_groups:nnoN
3162 % }
3163 % \begin{macro}
3164 % {
3165 % \keys_set_exclude_groups:nnnnN, \keys_set_exclude_groups:nnVnN,
3166 % \keys_set_exclude_groups:nnvnN, \keys_set_exclude_groups:nnonN
3167 % }
3168 % \begin{macro}
3169 % {
3170 % \keys_set_exclude_groups:nnn, \keys_set_exclude_groups:nnV,
3171 % \keys_set_exclude_groups:nnv, \keys_set_exclude_groups:nno
3172 % }
3173 % \begin{macro}
3174 % {
3175 % \keys_set_groups:nnnN, \keys_set_groups:nnVN,
3176 % \keys_set_groups:nnvN, \keys_set_groups:nnoN
3177 % }
3178 % \begin{macro}
3179 % {
3180 % \keys_set_groups:nnnnN, \keys_set_groups:nnVnN,
3181 % \keys_set_groups:nnvnN, \keys_set_groups:nnonN
3182 % }
3183 % \begin{macro}
3184 % {
3185 % \keys_set_groups:nnn, \keys_set_groups:nnV,
3186 % \keys_set_groups:nnv, \keys_set_groups:nno
3187 % }
3188 % The same for (exclusion) groups.
3189 % \begin{macrocode}
3190 \cs_new_protected:Npn \keys_set_exclude_groups:nnnnN #1#2#3#4#5
3191 {
3192 \@@_set:nnnnNn
3193 {#1} {#2} {#3} {#4} #5
3194 {
3195 \bool_set_false:N \l_@@_only_known_bool
3196 \bool_set_true:N \l_@@_exclude_bool
3197 \bool_set_true:N \l_@@_selective_bool
3198 }
3199 }
3200 \cs_generate_variant:Nn \keys_set_exclude_groups:nnnnN { nnV , nnv , nno }
3201 \cs_new_protected:Npn \keys_set_exclude_groups:nnnN #1#2#3#4
3202 { \keys_set_exclude_groups:nnnnN {#1} {#2} {#3} { \q_@@_no_value } #4 }
3203 \cs_generate_variant:Nn \keys_set_exclude_groups:nnnN { nnV , nnv , nno }
3204 \cs_new_protected:Npn \keys_set_exclude_groups:nnn #1#2#3
3205 {
3206 \keys_set_exclude_groups:nnnnN {#1} {#2} {#3}
3207 { \q_@@_no_value } \l_@@_tmp_clist
3208 }
3209 \cs_generate_variant:Nn \keys_set_exclude_groups:nnn { nnV , nnv , nno }
3210 \cs_new_protected:Npn \keys_set_groups:nnnnN #1#2#3#4#5
3211 {
3212 \@@_set:nnnnNn
3213 {#1} {#2} {#3} {#4} #5
3214 {
3215 \bool_set_false:N \l_@@_only_known_bool
3216 \bool_set_false:N \l_@@_exclude_bool
3217 \bool_set_true:N \l_@@_selective_bool
3218 }
3219 }
3220 \cs_generate_variant:Nn \keys_set_groups:nnnnN { nnV , nnv , nno }
3221 \cs_new_protected:Npn \keys_set_groups:nnnN #1#2#3#4
3222 { \keys_set_groups:nnnnN {#1} {#2} {#3} { \q_@@_no_value } #4 }
3223 \cs_generate_variant:Nn \keys_set_groups:nnnN { nnV , nnv , nno }
3224 \cs_new_protected:Npn \keys_set_groups:nnn #1#2#3
3225 {
3226 \keys_set_groups:nnnnN {#1} {#2} {#3}
3227 { \q_@@_no_value } \l_@@_tmp_clist
3228 }
3229 \cs_generate_variant:Nn \keys_set_groups:nnn { nnV , nnv , nno }
3230 % \end{macrocode}
3231 % \end{macro}
3232 % \end{macro}
3233 % \end{macro}
3234 % \end{macro}
3235 % \end{macro}
3236 % \end{macro}
3237 %
3238 % \begin{macro}{\keys_precompile:nnN}
3239 % A simple wrapper.
3240 % \begin{macrocode}
3241 \cs_new_protected:Npn \keys_precompile:nnN #1#2#3
3242 {
3243 \bool_set_true:N \l_@@_precompile_bool
3244 \tl_clear:N \l_@@_precompile_tl
3245 \keys_set:nn {#1} {#2}
3246 \bool_set_false:N \l_@@_precompile_bool
3247 \tl_set_eq:NN #3 \l_@@_precompile_tl
3248 }
3249 % \end{macrocode}
3250 % \end{macro}
3251 %
3252 % \begin{macro}{\@@_set_keyval:n, \@@_set_keyval:nn}
3253 % \begin{macro}{\@@_set_keyval:nnn, \@@_set_keyval:onn}
3254 % \begin{macro}{\@@_find_key_module:wNN}
3255 % \begin{macro}
3256 % {
3257 % \@@_find_key_module_auxi:Nw ,
3258 % \@@_find_key_module_auxii:Nw ,
3259 % \@@_find_key_module_auxiii:Nn ,
3260 % \@@_find_key_module_auxiv:Nw ,
3261 % \@@_find_key_module_auxv:Nw
3262 % }
3263 % \begin{macro}{\@@_set_selective:}
3264 % A shared system once again. First, set the current path and add a
3265 % default if needed. There are then checks to see if a value is
3266 % required or forbidden. If everything passes, move on to execute the
3267 % code.
3268 % \begin{macrocode}
3269 \cs_new_protected:Npn \@@_set_keyval:n #1
3270 {
3271 \bool_set_true:N \l_@@_no_value_bool
3272 \@@_set_keyval:onn \l_@@_module_str {#1} { }
3273 }
3274 \cs_new_protected:Npn \@@_set_keyval:nn #1#2
3275 {
3276 \bool_set_false:N \l_@@_no_value_bool
3277 \@@_set_keyval:onn \l_@@_module_str {#1} {#2}
3278 }
3279 % \end{macrocode}
3280 % The key path here can be fully defined, after which there is a search
3281 % for the key and module names: the user may have passed them with part
3282 % of what is actually the module (for our purposes) in the key name. As
3283 % that happens on a per-key basis, we use the stack approach to restore
3284 % the module name without a group.
3285 % \begin{macrocode}
3286 \cs_new_protected:Npn \@@_set_keyval:nnn #1#2#3
3287 {
3288 \__kernel_tl_set:Nx \l_keys_path_str
3289 {
3290 \tl_if_blank:nF {#1}
3291 { #1 / }
3292 \@@_trim_spaces:n {#2}
3293 }
3294 \str_clear:N \l_@@_module_str
3295 \str_clear:N \l_@@_inherit_str
3296 \exp_after:wN \@@_find_key_module:wNN \l_keys_path_str \s_@@_stop
3297 \l_@@_module_str \l_keys_key_str
3298 \str_set:Ne \l_keys_path_str
3299 {
3300 \l_@@_module_str
3301 \str_if_empty:NF \l_@@_module_str { / }
3302 \l_keys_key_str
3303 }
3304 \tl_set_eq:NN \l_keys_key_tl \l_keys_key_str
3305 \@@_value_or_default:n {#3}
3306 \bool_if:NTF \l_@@_selective_bool
3307 \@@_set_selective:
3308 \@@_execute:
3309 \str_set:Nn \l_@@_module_str {#1}
3310 }
3311 \cs_generate_variant:Nn \@@_set_keyval:nnn { o }
3312 % \end{macrocode}
3313 % This function uses \cs{cs_set_nopar:Npe} internally for performance reasons,
3314 % the argument |#1| is already a string in every usage, so turning it into a
3315 % string again seems unnecessary. The expansion part of a key is always stored
3316 % in the same place, so that is not passed along.
3317 % \begin{macrocode}
3318 \cs_new_protected:Npn \@@_find_key_module:wNN #1 \s_@@_stop #2#3
3319 {
3320 \@@_find_key_module_auxi:Nw #2 #1 \s_@@_nil \@@_find_key_module_auxii:Nw
3321 / \s_@@_nil \@@_find_key_module_auxiv:Nw #3
3322 }
3323 \cs_new_protected:Npn \@@_find_key_module_auxi:Nw #1 #2 / #3 \s_@@_nil #4
3324 {
3325 #4 #1 #2 \s_@@_mark #3 \s_@@_nil #4
3326 }
3327 \cs_new_protected:Npn \@@_find_key_module_auxii:Nw
3328 #1 #2 \s_@@_mark #3 \s_@@_nil \@@_find_key_module_auxii:Nw
3329 {
3330 \cs_set_nopar:Npe #1 { \tl_if_empty:NF #1 { #1 / } #2 }
3331 \@@_find_key_module_auxi:Nw #1 #3 \s_@@_nil \@@_find_key_module_auxiii:Nw
3332 }
3333 \cs_new_protected:Npn \@@_find_key_module_auxiii:Nw #1 #2 \s_@@_mark
3334 {
3335 \cs_set_nopar:Npe #1 { \tl_if_empty:NF #1 { #1 / } #2 }
3336 \@@_find_key_module_auxi:Nw #1
3337 }
3338 \cs_new_protected:Npe \@@_find_key_module_auxiv:Nw
3339 #1 #2 \s_@@_nil #3 \s_@@_mark
3340 \s_@@_nil \@@_find_key_module_auxiv:Nw #4
3341 {
3342 \exp_not:N \@@_find_key_module_auxv:Nw #4
3343 #2 \token_to_str:N : n \token_to_str:N : \s_@@_mark
3344 }
3345 \use:e
3346 {
3347 \cs_new_protected:Npn \exp_not:N \@@_find_key_module_auxv:Nw
3348 #1 #2 \token_to_str:N : #3 \token_to_str:N : #4 \s_@@_mark
3349 }
3350 {
3351 \cs_set_nopar:Npn #1 {#2}
3352 \cs_set_nopar:Npn \l_@@_exp_str {#3}
3353 }
3354 % \end{macrocode}
3355 % If selective setting is active, there are a number of possible sub-cases
3356 % to consider. The key name may not be known at all or if it is, it may not
3357 % have any groups assigned. There is then the question of whether the
3358 % selection is opt-in or opt-out.
3359 % \begin{macrocode}
3360 \cs_new_protected:Npn \@@_set_selective:
3361 {
3362 \cs_if_exist:cTF { \c_@@_groups_root_str \l_keys_path_str }
3363 {
3364 \clist_set_eq:Nc \l_@@_groups_clist
3365 { \c_@@_groups_root_str \l_keys_path_str }
3366 \@@_check_groups:
3367 }
3368 {
3369 \bool_if:NTF \l_@@_exclude_bool
3370 \@@_execute:
3371 \@@_store_unused:
3372 }
3373 }
3374 % \end{macrocode}
3375 % In the case where selective setting requires a comparison of the list
3376 % of groups which apply to a key with the list of those which have been
3377 % set active. That requires two mappings, and again a different outcome
3378 % depending on whether opt-in or opt-out is set.
3379 % It is safe to use \cs{clist_if_in:NnTF} because
3380 % both \cs{l_@@_selective_clist} and \cs{l_@@_groups_clist} contain the
3381 % groups as strings, without leading/trailing spaces in any item,
3382 % since the \pkg{l3clist} functions were applied to the result of
3383 % applying \cs{tl_to_str:n}.
3384 % \begin{macrocode}
3385 \cs_new_protected:Npn \@@_check_groups:
3386 {
3387 \bool_set_false:N \l_@@_tmp_bool
3388 \clist_map_inline:Nn \l_@@_selective_clist
3389 {
3390 \clist_if_in:NnT \l_@@_groups_clist {##1}
3391 {
3392 \bool_set_true:N \l_@@_tmp_bool
3393 \clist_map_break:
3394 }
3395 }
3396 \bool_if:NTF \l_@@_tmp_bool
3397 {
3398 \bool_if:NTF \l_@@_exclude_bool
3399 \@@_store_unused:
3400 \@@_execute:
3401 }
3402 {
3403 \bool_if:NTF \l_@@_exclude_bool
3404 \@@_execute:
3405 \@@_store_unused:
3406 }
3407 }
3408 % \end{macrocode}
3409 % \end{macro}
3410 % \end{macro}
3411 % \end{macro}
3412 % \end{macro}
3413 % \end{macro}
3414 %
3415 % \begin{macro}{\@@_value_or_default:n}
3416 % \begin{macro}{\@@_default_inherit:}
3417 % \begin{macro}
3418 % {
3419 % \@@_value_set:Nn, \@@_value_set:No, \@@_value_set:NV,
3420 % \@@_value_set:Nv, \@@_value_set:Ne,
3421 % }
3422 % \begin{macro}{\@@_value_set:NN, \@@_value_set:Nc}
3423 % If a value is given, return it as |#1|, otherwise send a default if
3424 % available.
3425 % \begin{macrocode}
3426 \cs_new_protected:Npn \@@_value_or_default:n #1
3427 {
3428 \bool_if:NTF \l_@@_no_value_bool
3429 {
3430 \cs_if_exist:cTF { \c_@@_default_root_str \l_keys_path_str }
3431 {
3432 \tl_set_eq:Nc
3433 \l_keys_value_tl
3434 { \c_@@_default_root_str \l_keys_path_str }
3435 }
3436 {
3437 \tl_clear:N \l_keys_value_tl
3438 \cs_if_exist:cT
3439 { \c_@@_inherit_root_str \@@_parent:o \l_keys_path_str }
3440 { \@@_inherit:NNn \c_@@_default_root_str \@@_default:n { } }
3441 }
3442 }
3443 {
3444 \cs_if_exist_use:cF { @@_value_set:N \l_@@_exp_str }
3445 {
3446 \msg_error:nnV { keys } { unknown-expansion } \l_@@_exp_str
3447 \use_none:nn
3448 }
3449 \l_keys_value_tl {#1}
3450 }
3451 }
3452 \cs_new_protected:Npn \@@_default:n #1
3453 { \tl_set_eq:Nc \l_keys_value_tl { \c_@@_default_root_str #1 } }
3454 \cs_new_eq:NN \@@_value_set:Nn \tl_set:Nn
3455 \cs_generate_variant:Nn \@@_value_set:Nn { No , NV , Nv , Ne }
3456 \cs_new_protected:Npn \@@_value_set:NN #1#2 { \tl_set:Nn #1 {#2} }
3457 \cs_generate_variant:Nn \@@_value_set:NN { Nc }
3458 % \end{macrocode}
3459 % \end{macro}
3460 % \end{macro}
3461 % \end{macro}
3462 % \end{macro}
3463 %
3464 % \begin{macro}{\@@_execute:}
3465 % \begin{macro}{\@@_execute:n}
3466 % \begin{macro}{\@@_execute_unknown:}
3467 % \begin{macro}[EXP]{\@@_execute:nn, \@@_execute:no}
3468 % \begin{macro}{\@@_store_unused:,\@@_store_unused_aux:}
3469 % Actually executing a key is done in two parts. First, look for the
3470 % key itself, then look for the \texttt{unknown} key with the same
3471 % path. If both of these fail, complain. What exactly happens if a key
3472 % is unknown depends on whether unknown keys are being skipped or if
3473 % an error should be raised.
3474 % \begin{macrocode}
3475 \cs_new_protected:Npn \@@_execute:
3476 {
3477 \cs_if_exist:cTF { \c_@@_code_root_str \l_keys_path_str }
3478 { \@@_execute:n { \l_keys_path_str } }
3479 {
3480 \@@_inherit:NNn \c_@@_code_root_str \@@_execute:n
3481 { \@@_execute_unknown: }
3482 }
3483 }
3484 \cs_new_protected:Npn \@@_execute:n #1
3485 {
3486 \cs_if_exist_use:c { \c_@@_check_root_str #1 }
3487 \@@_execute:no {#1} \l_keys_value_tl
3488 }
3489 \cs_new_protected:Npn \@@_execute_unknown:
3490 {
3491 \bool_if:NTF \l_@@_only_known_bool
3492 { \@@_store_unused: }
3493 {
3494 \cs_if_exist:cTF
3495 { \c_@@_code_root_str \l_@@_module_str / unknown }
3496 {
3497 \bool_if:NT \l_@@_no_value_bool
3498 {
3499 \cs_if_exist:cT
3500 { \c_@@_default_root_str \l_@@_module_str / unknown }
3501 {
3502 \tl_set_eq:Nc
3503 \l_keys_value_tl
3504 { \c_@@_default_root_str \l_@@_module_str / unknown }
3505 }
3506 }
3507 \@@_execute:no { \l_@@_module_str / unknown } \l_keys_value_tl
3508 }
3509 {
3510 \msg_error:nnee { keys } { unknown }
3511 \l_keys_path_str \l_@@_module_str
3512 }
3513 }
3514 }
3515 % \end{macrocode}
3516 % A key's code is in the control sequence with csname
3517 % \cs{c_@@_code_root_str} |#1|. We expand it once to get the
3518 % replacement text (with argument |#2|) and call \cs{use:n}
3519 % with this replacement as its argument. This ensures that any
3520 % undefined control sequence error in the key's code will lead to an
3521 % error message of the form |<argument>|\ldots{}\meta{control
3522 % sequence} in which one can read the (undefined) \meta{control
3523 % sequence} in full, rather than an error message that starts with the
3524 % potentially very long key name, which would make the (undefined)
3525 % \meta{control sequence} be truncated or sometimes completely hidden.
3526 % See \url{https://github.com/latex3/latex2e/issues/351}.
3527 % \begin{macrocode}
3528 \cs_new:Npn \@@_execute:nn #1#2
3529 { \@@_execute:no {#1} { \prg_do_nothing: #2 } }
3530 \cs_new:Npn \@@_execute:no #1#2
3531 {
3532 \exp_args:NNo \exp_args:No \use:n
3533 {
3534 \cs:w \c_@@_code_root_str #1 \exp_after:wN \cs_end:
3535 \exp_after:wN {#2}
3536 }
3537 }
3538 % \end{macrocode}
3539 % When there is no relative path, things here are easy: just save the key
3540 % name and value. When we are working with a relative path, first we
3541 % need to turn it into a string: that can't happen earlier as we need
3542 % to store \cs{q_@@_no_value}. Then, use a standard delimited approach to fish
3543 % out the partial path.
3544 % \begin{macrocode}
3545 \cs_new_protected:Npn \@@_store_unused:
3546 {
3547 \@@_quark_if_no_value:NTF \l_@@_relative_tl
3548 {
3549 \clist_put_right:Ne \l_@@_unused_clist
3550 {
3551 \l_keys_key_str
3552 \bool_if:NF \l_@@_no_value_bool
3553 { = { \exp_not:o \l_keys_value_tl } }
3554 }
3555 }
3556 {
3557 \tl_if_empty:NTF \l_@@_relative_tl
3558 {
3559 \clist_put_right:Ne \l_@@_unused_clist
3560 {
3561 \l_keys_path_str
3562 \bool_if:NF \l_@@_no_value_bool
3563 { = { \exp_not:o \l_keys_value_tl } }
3564 }
3565 }
3566 { \@@_store_unused_aux: }
3567 }
3568 }
3569 \cs_new_protected:Npn \@@_store_unused_aux:
3570 {
3571 \__kernel_tl_set:Nx \l_@@_relative_tl
3572 { \exp_args:No \@@_trim_spaces:n \l_@@_relative_tl }
3573 \use:e
3574 {
3575 \cs_set_protected:Npn \@@_store_unused:w
3576 ##1 \l_@@_relative_tl /
3577 ##2 \l_@@_relative_tl /
3578 ##3 \s_@@_stop
3579 }
3580 {
3581 \tl_if_blank:nF {##1}
3582 {
3583 \msg_error:nnee { keys } { bad-relative-key-path }
3584 \l_keys_path_str
3585 \l_@@_relative_tl
3586 }
3587 \clist_put_right:Ne \l_@@_unused_clist
3588 {
3589 \exp_not:n {##2}
3590 \bool_if:NF \l_@@_no_value_bool
3591 { = { \exp_not:o \l_keys_value_tl } }
3592 }
3593 }
3594 \use:e
3595 {
3596 \@@_store_unused:w \l_keys_path_str
3597 \l_@@_relative_tl / \l_@@_relative_tl /
3598 \s_@@_stop
3599 }
3600 }
3601 \cs_new_protected:Npn \@@_store_unused:w { }
3602 % \end{macrocode}
3603 % \end{macro}
3604 % \end{macro}
3605 % \end{macro}
3606 % \end{macro}
3607 % \end{macro}
3608 %
3609 % \begin{macro}{\@@_inherit:NNn}
3610 % \begin{macro}{\@@_inherit:nNN}
3611 % Dealing with inheritance and recursion makes life a little interesting.
3612 % \begin{macrocode}
3613 \cs_new_protected:Npn \@@_inherit:NNn #1#2#3
3614 {
3615 \bool_set_false:N \l_@@_inherit_bool
3616 \cs_if_exist:cT
3617 { \c_@@_inherit_root_str \@@_parent:o \l_keys_path_str }
3618 {
3619 \clist_map_inline:cn
3620 { \c_@@_inherit_root_str \@@_parent:o \l_keys_path_str }
3621 { \@@_inherit:nNN {##1} #1 #2 }
3622 }
3623 \bool_if:NF \l_@@_inherit_bool
3624 {#3}
3625 }
3626 \cs_new_protected:Npn \@@_inherit:nNN #1#2#3
3627 {
3628 \cs_if_exist:cTF
3629 { #2 #1 / \l_keys_key_str }
3630 {
3631 \str_set:Nn \l_@@_inherit_str {#1}
3632 #3 { #1 / \l_keys_key_str }
3633 \clist_map_break:n
3634 { \bool_set_true:N \l_@@_inherit_bool }
3635 }
3636 {
3637 \cs_if_exist:cT
3638 { \c_@@_inherit_root_str #1 }
3639 {
3640 \clist_map_inline:cn { \c_@@_inherit_root_str #1 }
3641 { \@@_inherit:nNN {##1} #2 #3 }
3642 \bool_if:NT \l_@@_inherit_bool
3643 { \clist_map_break: }
3644 }
3645 }
3646 }
3647 % \end{macrocode}
3648 % \end{macro}
3649 % \end{macro}
3650 %
3651 % \begin{macro}[EXP]{\@@_choice_find:n}
3652 % \begin{macro}[EXP]{\@@_choice_find:nn}
3653 % \begin{macro}[EXP]{\@@_multichoice_find:n}
3654 % Executing a choice has two parts. First, try the choice given, then
3655 % if that fails call the unknown key. That always exists, as it is created
3656 % when a choice is first made. So there is no need for any escape code.
3657 % For multiple choices, the same code ends up used in a mapping.
3658 % \begin{macrocode}
3659 \cs_new:Npn \@@_choice_find:n #1
3660 {
3661 \str_if_empty:NTF \l_@@_inherit_str
3662 { \@@_choice_find:nn \l_keys_path_str {#1} }
3663 {
3664 \@@_choice_find:nn
3665 { \l_@@_inherit_str / \l_keys_key_str } {#1}
3666 }
3667 }
3668 \cs_new:Npn \@@_choice_find:nn #1#2
3669 {
3670 \cs_if_exist:cTF { \c_@@_code_root_str #1 / \@@_trim_spaces:n {#2} }
3671 { \@@_execute:nn { #1 / \@@_trim_spaces:n {#2} } {#2} }
3672 { \@@_execute:nn { #1 / unknown } {#2} }
3673 }
3674 \cs_new:Npn \@@_multichoice_find:n #1
3675 { \clist_map_function:nN {#1} \@@_choice_find:n }
3676 % \end{macrocode}
3677 % \end{macro}
3678 % \end{macro}
3679 % \end{macro}
3680 %
3681 % \subsection{Utilities}
3682 %
3683 % \begin{macro}[EXP]{\@@_parent:o}
3684 % \begin{macro}[EXP]
3685 % {
3686 % \@@_parent_auxi:w ,
3687 % \@@_parent_auxii:w ,
3688 % \@@_parent_auxiii:n ,
3689 % \@@_parent_auxiv:w
3690 % }
3691 % Used to strip off the ending part of the key path after the last~|/|.
3692 % \begin{macrocode}
3693 \cs_new:Npn \@@_parent:o #1
3694 {
3695 \exp_after:wN \@@_parent_auxi:w #1 \q_nil \@@_parent_auxii:w
3696 / \q_nil \@@_parent_auxiv:w
3697 }
3698 \cs_new:Npn \@@_parent_auxi:w #1 / #2 \q_nil #3
3699 {
3700 #3 { #1 } #2 \q_nil #3
3701 }
3702 \cs_new:Npn \@@_parent_auxii:w #1 #2 \q_nil \@@_parent_auxii:w
3703 {
3704 #1 \@@_parent_auxi:w #2 \q_nil \@@_parent_auxiii:n
3705 }
3706 \cs_new:Npn \@@_parent_auxiii:n #1
3707 {
3708 / #1 \@@_parent_auxi:w
3709 }
3710 \cs_new:Npn \@@_parent_auxiv:w #1 \q_nil \@@_parent_auxiv:w
3711 {
3712 }
3713 % \end{macrocode}
3714 % \end{macro}
3715 % \end{macro}
3716 %
3717 % \begin{macro}[EXP]{\@@_trim_spaces:n}
3718 % \begin{macro}[EXP]
3719 % {
3720 % \@@_trim_spaces_auxi:w ,
3721 % \@@_trim_spaces_auxii:w ,
3722 % \@@_trim_spaces_auxiii:w
3723 % }
3724 % Space stripping has to allow for the fact that the key here might have
3725 % several parts, and spaces need to be stripped from each part. Since the key
3726 % name is turned into a string groups can't be stripped accidentally and the
3727 % precautions of \cs{tl_trim_spaces:n} aren't necessary, in this case it is
3728 % much faster to just directly strip spaces around |/|.
3729 % \begin{macrocode}
3730 \group_begin:
3731 \cs_set:Npn \@@_tmp:w #1
3732 {
3733 \cs_new:Npn \@@_trim_spaces:n ##1
3734 {
3735 \exp_after:wN \@@_trim_spaces_auxi:w \tl_to_str:n { / ##1 } /
3736 \s_@@_nil \@@_trim_spaces_auxi:w
3737 \s_@@_mark \@@_trim_spaces_auxii:w
3738 #1 / #1
3739 \s_@@_nil \@@_trim_spaces_auxii:w
3740 \s_@@_mark \@@_trim_spaces_auxiii:w
3741 }
3742 }
3743 \@@_tmp:w { ~ }
3744 \group_end:
3745 \cs_new:Npn \@@_trim_spaces_auxi:w #1 ~ / #2 \s_@@_nil #3
3746 {
3747 #3 #1 / #2 \s_@@_nil #3
3748 }
3749 \cs_new:Npn \@@_trim_spaces_auxii:w #1 / ~ #2 \s_@@_mark #3
3750 {
3751 #3 #1 / #2 \s_@@_mark #3
3752 }
3753 \cs_new:Npn \@@_trim_spaces_auxiii:w
3754 / #1 /
3755 \s_@@_nil \@@_trim_spaces_auxi:w
3756 \s_@@_mark \@@_trim_spaces_auxii:w
3757 /
3758 \s_@@_nil \@@_trim_spaces_auxii:w
3759 \s_@@_mark \@@_trim_spaces_auxiii:w
3760 {
3761 #1
3762 }
3763 % \end{macrocode}
3764 % \end{macro}
3765 % \end{macro}
3766 %
3767 % \begin{macro}[EXP,pTF]{\keys_if_exist:nn}
3768 % \begin{macro}[EXP]{\@@_if_exist:nn, \@@_if_exist:ee}
3769 % A utility for others to see if a key exists.
3770 % \begin{macrocode}
3771 \prg_new_conditional:Npnn \keys_if_exist:nn #1#2 { p , T , F , TF }
3772 {
3773 \@@_if_exist:ee
3774 { \@@_trim_spaces:n {#1} }
3775 { \@@_trim_spaces:n {#2} }
3776 }
3777 \prg_generate_conditional_variant:Nnn \keys_if_exist:nn { ne } { p , T , F , TF }
3778 \cs_new:Npn \@@_if_exist:nn #1#2
3779 {
3780 \cs_if_exist:cTF
3781 { \c_@@_code_root_str #1 \tl_if_blank:nF {#1} { / } #2 }
3782 { \prg_return_true: }
3783 { \prg_return_false: }
3784 }
3785 \cs_generate_variant:Nn \@@_if_exist:nn { ee }
3786 % \end{macrocode}
3787 % \end{macro}
3788 % \end{macro}
3789 %
3790 % \begin{macro}[EXP,pTF]{\keys_if_choice_exist:nnn}
3791 % \begin{macro}[EXP]{\@@_if_exist:nnn, \@@_if_exist:eee}
3792 % Just an alternative view on \cs{keys_if_exist:nnTF}.
3793 % \begin{macrocode}
3794 \prg_new_conditional:Npnn \keys_if_choice_exist:nnn #1#2#3
3795 { p , T , F , TF }
3796 {
3797 \@@_if_exist:eee
3798 { \@@_trim_spaces:n {#1} }
3799 { \@@_trim_spaces:n {#2} }
3800 { \@@_trim_spaces:n {#3} }
3801 }
3802 \cs_new:Npn \@@_if_exist:nnn #1#2#3
3803 {
3804 \cs_if_exist:cTF
3805 {
3806 \c_@@_code_root_str
3807 #1 \tl_if_blank:nF {#1} { / }
3808 #2 \tl_if_blank:nF {#2} { / }
3809 #3
3810 }
3811 { \prg_return_true: }
3812 { \prg_return_false: }
3813 }
3814 \cs_generate_variant:Nn \@@_if_exist:nnn { eee }
3815 % \end{macrocode}
3816 % \end{macro}
3817 % \end{macro}
3818 %
3819 % \begin{macro}{\keys_show:nn, \keys_log:nn}
3820 % \begin{macro}{\@@_show:Nnn, \@@_show_aux:Nnn, , \@@_show_aux:Nee}
3821 % \begin{macro}{\@@_show:n}
3822 % \begin{macro}{\@@_show:w}
3823 % \begin{macro}{\@@_show:Nw}
3824 % To show a key, show its code using a message.
3825 % \begin{macrocode}
3826 \cs_new_protected:Npn \keys_show:nn
3827 { \@@_show:Nnn \msg_show:nneeee }
3828 \cs_new_protected:Npn \keys_log:nn
3829 { \@@_show:Nnn \msg_log:nneeee }
3830 \cs_new_protected:Npn \@@_show:Nnn #1#2#3
3831 {
3832 \@@_show_aux:Nee
3833 #1
3834 { \@@_trim_spaces:n {#2} }
3835 { \@@_trim_spaces:n {#3} }
3836 }
3837 \cs_new_protected:Npn \@@_show_aux:Nnn #1#2#3
3838 {
3839 #1 { keys } { show-key }
3840 { #2 \tl_if_blank:nF {#2} { / } #3 }
3841 {
3842 \keys_if_exist:nnT {#2} {#3}
3843 {
3844 \exp_args:Nnf \msg_show_item_unbraced:nn { code }
3845 {
3846 \exp_args:Ne \@@_show:n
3847 {
3848 \exp_args:Nc \cs_replacement_spec:N
3849 {
3850 \c_@@_code_root_str
3851 #2 \tl_if_blank:nF {#2} { / } #3
3852 }
3853 }
3854 }
3855 }
3856 }
3857 { } { }
3858 }
3859 \cs_generate_variant:Nn \@@_show_aux:Nnn { Nee }
3860 \cs_new:Npe \@@_show:n #1
3861 {
3862 \exp_not:N \@@_show:w
3863 #1
3864 \tl_to_str:n { \@@_precompile:n }
3865 #1
3866 \tl_to_str:n { \@@_precompile:n }
3867 \exp_not:N \s_@@_stop
3868 }
3869 \use:e
3870 {
3871 \cs_new:Npn \exp_not:N \@@_show:w
3872 #1 \tl_to_str:n { \@@_precompile:n }
3873 #2 \tl_to_str:n { \@@_precompile:n }
3874 #3 \exp_not:N \s_@@_stop
3875 }
3876 {
3877 \tl_if_blank:nTF {#2}
3878 {#1}
3879 { \@@_show:Nw #2 \s_@@_stop }
3880 }
3881 \use:e
3882 {
3883 \cs_new:Npn \exp_not:N \@@_show:Nw #1#2
3884 \c_right_brace_str \exp_not:N \s_@@_stop
3885 }
3886 {#2}
3887 % \end{macrocode}
3888 % \end{macro}
3889 % \end{macro}
3890 % \end{macro}
3891 % \end{macro}
3892 % \end{macro}
3893 %
3894 % \subsection{Messages}
3895 %
3896 % For when there is a need to complain.
3897 % \begin{macrocode}
3898 \msg_new:nnnn { keys } { bad-relative-key-path }
3899 { The~key~'#1'~is~not~inside~the~'#2'~path. }
3900 { The~key~'#1'~cannot~be~expressed~relative~to~path~'#2'. }
3901 \msg_new:nnnn { keys } { boolean-values-only }
3902 { Key~'#1'~accepts~boolean~values~only. }
3903 { The~key~'#1'~only~accepts~the~values~'true'~and~'false'. }
3904 \msg_new:nnnn { keys } { choice-unknown }
3905 { Key~'#1'~accepts~only~a~fixed~set~of~choices. }
3906 {
3907 The~key~'#1'~only~accepts~predefined~values,~
3908 and~'#2'~is~not~one~of~these.
3909 }
3910 \msg_new:nnnn { keys } { unknown }
3911 { The~key~'#1'~is~unknown~and~is~being~ignored. }
3912 {
3913 The~module~'#2'~does~not~have~a~key~called~'#1'.\\
3914 Check~that~you~have~spelled~the~key~name~correctly.
3915 }
3916 \msg_new:nnnn { keys } { unknown-expansion }
3917 { The~value~expansion~'#1'~is~unknown. }
3918 {
3919 Key~values~can~only~be~expanded~using~one~of~the~pre-defined~methods:~
3920 n,~o,~V,~v,~e,~N~or~c.
3921 }
3922 \msg_new:nnnn { keys } { nested-choice-key }
3923 { Attempt~to~define~'#1'~as~a~nested~choice~key. }
3924 {
3925 The~key~'#1'~cannot~be~defined~as~a~choice~as~the~parent~key~'#2'~is~
3926 itself~a~choice.
3927 }
3928 \msg_new:nnnn { keys } { value-forbidden }
3929 { The~key~'#1'~does~not~take~a~value. }
3930 {
3931 The~key~'#1'~should~be~given~without~a~value.\\
3932 The~value~'#2'~was~present:~the~key~will~be~ignored.
3933 }
3934 \msg_new:nnnn { keys } { value-required }
3935 { The~key~'#1'~requires~a~value. }
3936 {
3937 The~key~'#1'~must~have~a~value.\\
3938 No~value~was~present:~the~key~will~be~ignored.
3939 }
3940 \msg_new:nnn { keys } { show-key }
3941 {
3942 The~key~#1~
3943 \tl_if_empty:nTF {#2}
3944 { is~undefined. }
3945 { has~the~properties: #2 . }
3946 }
3947 \prop_gput:Nnn \g_msg_module_name_prop { keys } { LaTeX }
3948 \prop_gput:Nnn \g_msg_module_type_prop { keys } { }
3949 % \end{macrocode}
3950 %
3951 % \begin{macrocode}
3952 %</code>
3953 % \end{macrocode}
3954 %
3955 %\end{implementation}
3956 %
3957 %\PrintIndex