Debian Codegraph @

texmf-dist/source/latex/base/ltkeys.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2021-2025
4 % The LaTeX Project and any individual authors listed elsewhere
5 % in this file.
6 %
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
9 %
10 % It may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 % https://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2008 or later.
17 %
18 % This file has the LPPL maintenance status "maintained".
19 %
20 % The list of all files belonging to the LaTeX base distribution is
21 % given in the file `manifest.txt'. See also `legal.txt' for additional
22 % information.
23 %
24 % The list of derived (unpacked) files belonging to the distribution
25 % and covered by LPPL is defined by the unpacking scripts (with
26 % extension .ins) which are part of the distribution.
27 %
28 % \fi
29 %
30 % \iffalse
31 %%% From File: ltkeys.dtx
32 %
33 %<*driver>
34 % \fi
35 \ProvidesFile{ltkeys.dtx}
36 [2025/06/27 v1.0q LaTeX Kernel (Keyval options)]
37 % \iffalse
38 \documentclass{l3doc}
39 \GetFileInfo{ltkeys.dtx}
40 \title{\filename}
41 \date{\filedate}
42 \author{%
43 \LaTeX{} Team}
44
45 \begin{document}
46 \maketitle
47 \DocInput{ltkeys.dtx}
48 \end{document}
49 %</driver>
50 % \fi
51 %
52 % \section{Creating and using keyval options}
53 %
54 % As with any key--value input, using key--value pairs as package or
55 % class options has two parts: creating the key options and setting (using)
56 % them. Options created in this way \emph{may} be used after package loading
57 % as general key--value settings: this will depend on the nature of the
58 % underlying code.
59 %
60 % \begin{function}{\DeclareKeys}
61 % \begin{syntax}
62 % \cs{DeclareKeys} \oarg{family} \marg{declarations}
63 % \end{syntax}
64 % Creates a series of options from a comma-separated \meta{declarations} list.
65 % The \meta{family} is a namespace for the keys; if not given, the basename of
66 % the current class or package is used.
67 % Each entry in the \meta{declarations} (a commas-separated list)
68 % is a key--value pair, with the \meta{key} having one
69 % or more \meta{properties}. A small number of \enquote{basic}
70 % \meta{properties} are described below. The full range of properties,
71 % provided by \pkg{l3keys}, can also be used for more powerful processing.
72 % See \texttt{interface3} for the full details.
73 %
74 % The basic properties provided here are
75 % \begin{itemize}
76 % \item \texttt{.code} --- execute arbitrary code
77 % \item \texttt{.if} --- sets a \TeX{} \cs{if...} switch
78 % \item \texttt{.ifnot} --- sets an inverted \TeX{} \cs{if...} switch
79 % \item \texttt{.pass-to-packages} --- for class options, this specifies
80 % whether the option should be treated \enquote{global} (read by packages
81 % from the global list); for package options this property has no effect
82 % \item \texttt{.store} --- stores a value in a macro
83 % \item \texttt{.usage} -- defines whether the option can be given only
84 % when loading (\texttt{load}), in the preamble (\texttt{preamble}) or
85 % has no limitation on scope (\texttt{general})
86 % \end{itemize}
87 % The part of the \meta{key} before the \meta{property} is the \meta{name},
88 % with the \meta{value} working with the \meta{property} to define the
89 % behaviour of the option.
90 %
91 % For example, with
92 % \begin{verbatim}
93 % \DeclareKeys[mypkg]
94 % {
95 % draft.if = @mypkg@draft ,
96 % draft.usage = preamble ,
97 % name.store = \@mypkg@name ,
98 % name.usage = load ,
99 % second-name.store = \@mypkg@other@name
100 % }
101 % \end{verbatim}
102 % three options would be create. The option \texttt{draft} can be given
103 % anywhere in the preamble, and will set a switch called \cs{if@mypkg@draft}.
104 % The option \texttt{name} can only be given during package loading, and will
105 % save whatever value it is given in \cs{@mypkg@name}. Finally, the option
106 % \texttt{second-name} can be given anywhere, and will save its value in
107 % \cs{@mypkg@other@name}.
108 %
109 % Keys created \emph{before} the use of \cs{ProcessKeyOptions} act as
110 % package options.
111 % \end{function}
112 %
113 % \begin{function}{\DeclareUnknownKeyHandler}
114 % \begin{syntax}
115 % \cs{DeclareUnknownKeyHandler} \oarg{family} \marg{code}
116 % \end{syntax}
117 % The function \cs{DeclareUnknownKeyHandler} may be used to define
118 % the behavior when an undefined key is encountered. The \meta{code}
119 % will receive the unknown key name as |#1| and the value as |#2|.
120 % These can then be processed as appropriate, e.g.~by forwarding
121 % to another package.
122 % \end{function}
123 %
124 % \begin{function}{\ProcessKeyOptions}
125 % \begin{syntax}
126 % \cs{ProcessKeyOptions} \oarg{families}
127 % \end{syntax}
128 % The \cs{ProcessKeyOptions} function is used to check the current
129 % option list against the keys defined for \meta{families} (a comma-separated
130 % list). Global (class) options and local (package) options are checked when
131 % this function is called in a package. Where there is more than one
132 % \meta{family} in the list of \meta{families}, processing takes place in
133 % the order of the \meta{families}. Every key known in a \meta{family} is
134 % passed for processing, thus a key defined in more than one \meta{family}
135 % will be processed several times, and if the code paths are shared, the
136 % outcome will be determined by the last entry in the list of \meta{families}.
137 % \end{function}
138 %
139 % \begin{function}{\SetKeys}
140 % \begin{syntax}
141 % \cs{SetKeys} \oarg{family} \Arg{keyvals}
142 % \end{syntax}
143 % Sets (applies) the explicit list of \meta{keyvals} for the \meta{family}:
144 % it the latter is not given, the value of \cs{@currname} used. This command
145 % may be used within a package to set options before or after using
146 % \cs{ProcessKeyOptions}.
147 % \end{function}
148 %
149 % \StopEventually{}
150 %
151 % \subsection{Implementation of \pkg{ltkeys}}
152 %
153 % \begin{macrocode}
154 %<@@=keys>
155 % \end{macrocode}
156 %
157 % \begin{macrocode}
158 %<*2ekernel>
159 % \end{macrocode}
160 %
161 % \begin{macrocode}
162 \ExplSyntaxOn
163 % \end{macrocode}
164 %
165 % \subsection{Key properties}
166 %
167 % \begin{macro}{.code, .if, .ifnot, .store, .usage}
168 % \changes{v1.0b}{2022/02/05}
169 % {Create properties in \texttt{ltkeys}}
170 % \changes{v1.0c}{2022/02/07}
171 % {Correct \texttt.{.code} property}
172 % \changes{v1.0i}{2022/06/22}
173 % {Add \texttt.{.notif} property}
174 % \begin{macrocode}
175 \group_begin:
176 \cs_set_protected:Npn \@@_tmp:nn #1#2
177 {
178 \quark_if_recursion_tail_stop:n {#1}
179 \cs_new_eq:cc
180 { \c_@@_props_root_str . #2 }
181 { \c_@@_props_root_str . #1 }
182 \@@_tmp:nn
183 }
184 \@@_tmp:nn
185 { code:n } { code }
186 { legacy_if_set:n } { if }
187 { legacy_if_set_inverse:n } { ifnot }
188 { tl_set:N } { store }
189 { usage:n } { usage }
190 { \q_recursion_tail } { }
191 \q_recursion_stop
192 \group_end:
193 % \end{macrocode}
194 % \end{macro}
195 %
196 % \begin{macro}{.pass-to-packages}
197 % \changes{v1.0n}{2024/06/19}{New key property}
198 % \begin{macro}{\@@_scope:n}
199 % \changes{v1.0n}{2024/06/19}{New function}
200 % \begin{macro}{\@@_scope:N}
201 % \changes{v1.0n}{2024/06/19}{New function}
202 % \changes{v1.0o}{2024/06/20}{Ensure only key name is stored}
203 % Used to force options to be global: as this property (uniquely) has
204 % an \emph{optional} value, there is a bit of work to do.
205 % \begin{macrocode}
206 \cs_new_protected:cpn { \c_@@_props_root_str .pass-to-packages }
207 {
208 \bool_if:NTF \l_@@_no_value_bool
209 { \@@_scope:n { true } }
210 { \@@_scope:n }
211 }
212 \cs_new_protected:Npn \@@_scope:n #1
213 {
214 \str_case:nnF {#1}
215 {
216 { true }
217 { \@@_scope:N \clist_put_right:NV }
218 { false }
219 { \@@_scope:N \clist_remove_all:NV }
220 }
221 {
222 \msg_error:nnnn { keys }
223 { choice-unknown }
224 { .pass-to-packages }
225 {#1}
226 }
227 }
228 \cs_new_protected:Npn \@@_scope:N #1
229 {
230 \exp_after:wN \@@_find_key_module:wNN
231 \l_keys_path_str \s_@@_stop
232 \l_keys_key_tl \l_keys_key_str
233 #1 \l_@@_forced_global_clist \l_keys_key_str
234 }
235 % \end{macrocode}
236 % \end{macro}
237 % \end{macro}
238 % \end{macro}
239 %
240 % \subsection{Main mechanism}
241 %
242 % \begin{macrocode}
243 \cs_generate_variant:Nn \clist_if_in:NnT { Ne }
244 \cs_generate_variant:Nn \clist_if_in:NnTF { Ne }
245 \cs_generate_variant:Nn \clist_put_right:Nn { Nv }
246 % \end{macrocode}
247 %
248 % \begin{macro}{\l_@@_class_only_clist}
249 % \changes{v1.0n}{2024/06/19}{New variable}
250 % Used to track class-only options.
251 % \begin{macrocode}
252 \clist_new:N \l_@@_class_only_clist
253 % \end{macrocode}
254 % \end{macro}
255 %
256 % \begin{macro}{\l_@@_forced_global_clist}
257 % \changes{v1.0n}{2024/06/19}{New variable}
258 % Used to force options to be global.
259 % \begin{macrocode}
260 \clist_new:N \l_@@_forced_global_clist
261 % \end{macrocode}
262 % \end{macro}
263 %
264 % \begin{macro}{\l_@@_options_clist}
265 % A single list is used for all options, into which they are collected
266 % before processing.
267 % \begin{macrocode}
268 \clist_new:N \l_@@_options_clist
269 % \end{macrocode}
270 % \end{macro}
271 %
272 % \begin{macro}{\l_@@_local_clist}
273 % \changes{v1.0q}{2025/06/25}{New variable}
274 % Holds the local options when appropriate: otherwise empty. Needed as
275 % the \LaTeXe{} setup here can be equal to \cs{scan_stop:}, which is not
276 % generally supported.
277 % \begin{macrocode}
278 \clist_new:N \l_@@_local_clist
279 % \end{macrocode}
280 % \end{macro}
281 %
282 % \begin{variable}{\l_@@_options_loading_bool}
283 % Used to indicate we are in the loading phase: controls the outcome
284 % of warnings.
285 % \begin{macrocode}
286 \bool_new:N \l_@@_options_loading_bool
287 % \end{macrocode}
288 % \end{variable}
289 %
290 % \begin{macro}{\@@_options:n}
291 % \changes{v1.0f}{2022/03/18}{Simplify to always cover global options}
292 % \begin{macro}{\@@_options_aux:n}
293 % \changes{v1.0b}{2022/01/15}
294 % {Clear option list in end-of-package hook}
295 % \changes{v1.0l}{2022/10/20}
296 % {Define key option handler in \pkg{ltkeys}}
297 % \changes{v1.0i}{2022/07/05}{Support \cs{CurrentOption}}
298 % \changes{v1.0p}{2025/01/15}{Only process global options on first pass}
299 % \changes{v1.0q}{2025/06/25}{Revise for multiple family support}
300 % The main function calls functions to collect up the global and local
301 % options into \cs{l_@@_options_clist} before calling the
302 % underlying functions to actually do the processing. So that a suitable
303 % message is produced if the option is unknown, the special
304 % \texttt{unknown} key is set if it does not already exist for the
305 % current family, and is cleaned up afterwards if required. To allow
306 % the \LaTeXe{} layer to know this mechanism is active, and to deal
307 % with the key family not matching the file name, we store the family
308 % in all cases. Global options are only considered the first time a
309 % package is loaded: this is tracked using
310 % |opt@handler@\@currname.\@currext|, as this is defined once keyval
311 % processing has been applied for the first time.
312 % \begin{macrocode}
313 \cs_new_protected:Npn \@@_options:n #1
314 { \@@_options_expand_module:Nn \@@_options_aux:n {#1} }
315 \cs_new_protected:Npn \@@_options_aux:n #1
316 {
317 \@@_options_local:
318 \clist_map_inline:nn {#1}
319 {
320 \clist_clear:N \l_@@_options_clist
321 \cs_if_exist:cF { opt@handler@ \@currname . \@currext }
322 { \@@_options_global:n {##1} }
323 \@@_options_local:n {##1}
324 \bool_set_true:N \l_@@_options_loading_bool
325 \clist_map_variable:NNn \l_@@_options_clist \CurrentOption
326 { \keys_set:nV {##1} \CurrentOption }
327 \bool_set_false:N \l_@@_options_loading_bool
328 \@@_options_loaded:n {##1}
329 }
330 \clist_if_empty:NF \l_@@_unused_clist
331 {
332 \clist_map_inline:Nn \l_@@_unused_clist
333 {
334 \msg_error:nnxx { keys } { option-unknown }
335 {##1} { \@currname }
336 }
337 }
338 \cs_if_exist:cF { opt@handler@ \@currname . \@currext }
339 {
340 \cs_gset_protected:cpn { opt@handler@ \@currname . \@currext }
341 { \ProcessKeyOptions [ {#1} ] }
342 }
343 \AtEndOfPackage { \cs_set_eq:NN \@unprocessedoptions \scan_stop: }
344 }
345 % \end{macrocode}
346 % \changes{v1.0j}{2022/07/23}
347 % {Output `public' package name in messages}
348 % \begin{macrocode}
349 \msg_new:nnnn { keys } { option-unknown }
350 { Unknown~option~'#1'~for~package~#2. }
351 {
352 LaTeX~has~been~asked~to~set~an~option~called~'#1'~
353 but~the~package~"\msg_module_name:n {#2}"~has~not~created~an~option~with~this~name.
354 }
355 % \end{macrocode}
356 % \end{macro}
357 % \end{macro}
358 %
359 % \begin{macro}{\@@_options_global:n}
360 % \changes{v1.0f}{2022/03/18}{Simplify to always cover global options}
361 % \changes{v1.0h}{2022/06/20}{Use raw options data}
362 % Global (class) options are handled differently for \LaTeXe{} packages
363 % and classes. Hence this function is essentially a check on the current
364 % file type. The initial test is needed as \LaTeXe{} allows variables to
365 % be equal to \cs{scan_stop:}, which is usually forbidden in \pkg{expl3}
366 % code.
367 % \begin{macrocode}
368 \cs_new_protected:Npn \@@_options_global:n #1
369 {
370 \cs_if_eq:NNF \@raw@classoptionslist \scan_stop:
371 {
372 \cs_if_eq:NNTF \@currext \@clsextension
373 { \@@_options_class:n {#1} }
374 { \@@_options_package:n {#1} }
375 }
376 }
377 % \end{macrocode}
378 % \end{macro}
379 %
380 % \begin{macro}{\@@_options_class:n}
381 % \changes{v1.0g}{2022/06/16}{Better handling of option removal}
382 % \changes{v1.0h}{2022/06/19}{Further work on handling of option removal}
383 % \changes{v1.0h}{2022/06/20}{Use raw options data}
384 % \changes{v1.0m}{2024/01/13}{Trim spaces off key names}
385 % \changes{v1.0n}{2024/06/19}{Refactor function}
386 % \begin{macro}{\@@_options_class:nnn}
387 % \changes{v1.0h}{2022/06/20}{New function}
388 % \changes{v1.0i}{2022/07/05}{Correct naming of raw class options storage}
389 % \changes{v1.0l}{2022/10/22}{Correct handling of unused option list}
390 % \changes{v1.0n}{2024/06/19}{Refactor function}
391 % \changes{v1.0n}{2024/06/19}{Track options used by classes}
392 % \begin{macro}{\@@_options_class:nn}
393 % \changes{v1.0n}{2024/06/19}{New function}
394 % For classes, each option (stripped of any content after |=|)
395 % is checked for existence as a key. If found, the option is added to
396 % the combined list for processing. On the other hand, unused options
397 % are stored up in \cs{@unusedoptionlist}. An earlier version of
398 % this code checked for the \texttt{unknown} key just once and
399 % if found short-cutted the loop: that though makes handling more
400 % complex situations harder, so we take the performance hit instead.
401 % Options used by classes are tracked but the catch-all \texttt{unknown}
402 % is excluded (hence not using a lazy evaluation for the key testing).
403 % \begin{macrocode}
404 \cs_new_protected:Npn \@@_options_class:n #1
405 {
406 \cs_if_free:cF { @raw@opt@ \@currname . \@currext }
407 {
408 \clist_map_inline:cn { @raw@opt@ \@currname . \@currext }
409 {
410 \exp_args:Ne \@@_options_class:nnn
411 { \tl_trim_spaces:e { \@@_remove_equals:n {##1} } }
412 {##1} {#1}
413 }
414 }
415 }
416 \cs_new_protected:Npn \@@_options_class:nnn #1#2#3
417 {
418 \keys_if_exist:nnTF {#3} {#1}
419 {
420 \@@_options_class:nn {#1} {#2}
421 \clist_put_right:Ne \l_@@_class_only_clist { \tl_to_str:n {#1} }
422 }
423 {
424 \keys_if_exist:nnTF {#3} { unknown }
425 { \@@_options_class:nn {#1} {#2} }
426 {
427 \clist_if_in:NnF \@unusedoptionlist {#1}
428 { \clist_put_right:Nn \@unusedoptionlist {#1} }
429 }
430 }
431 }
432 \cs_new_protected:Npn \@@_options_class:nn #1#2
433 {
434 \clist_remove_all:Nn \@unusedoptionlist {#1}
435 \clist_put_right:Nn \l_@@_options_clist {#2}
436 }
437 % \end{macrocode}
438 % \end{macro}
439 % \end{macro}
440 % \end{macro}
441 %
442 % \begin{macro}{\@@_options_package:n}
443 % \changes{v1.0g}{2022/06/16}{Better handling of option removal}
444 % \changes{v1.0h}{2022/06/19}{Further work on handling of option removal}
445 % \changes{v1.0h}{2022/06/20}{Use raw options data}
446 % \changes{v1.0m}{2024/01/13}{Trim spaces off key names}
447 % \begin{macro}{\@@_options_package:nnn}
448 % \changes{v1.0h}{2022/06/19}{New function}
449 % \changes{v1.0n}{2024/06/19}{Skip options given to packages}
450 % \begin{macro}{\@@_options_package:nn}
451 % \changes{v1.0n}{2024/06/19}{New functions}
452 % For global options when processing a package, the tasks are slightly
453 % different from those for a class. The check is the same, but here
454 % there is nothing to do if the option is not applicable. Each valid
455 % option also needs to be removed from \cs{@unusedoptionlist}.
456 % \begin{macrocode}
457 \cs_new_protected:Npn \@@_options_package:n #1
458 {
459 \clist_map_inline:Nn \@raw@classoptionslist
460 {
461 \exp_args:Ne \@@_options_package:nnn
462 { \tl_trim_spaces:e { \@@_remove_equals:n {##1} } }
463 {##1} {#1}
464 }
465 }
466 % \end{macrocode}
467 % The forced-global test here needs to use \cs{tl_to_str:n} as the data come
468 % from a key name, which is always a string.
469 % \begin{macrocode}
470 \cs_new_protected:Npn \@@_options_package:nnn #1#2#3
471 {
472 \keys_if_exist:nnT {#3} {#1}
473 {
474 \clist_if_in:NeTF \l_@@_class_only_clist { \tl_to_str:n {#1} }
475 {
476 \clist_if_in:NeT \l_@@_forced_global_clist { \tl_to_str:n {#1} }
477 { \@@_options_package:nn {#1} {#2} }
478 }
479 { \@@_options_package:nn {#1} {#2} }
480 }
481 }
482 \cs_new_protected:Npn \@@_options_package:nn #1#2
483 {
484 \clist_put_right:Nn \l_@@_options_clist {#2}
485 \clist_remove_all:Nn \@unusedoptionlist {#1}
486 }
487 % \end{macrocode}
488 % \end{macro}
489 % \end{macro}
490 % \end{macro}
491 %
492 % \begin{macro}{\@@_options_local:}
493 % \changes{v1.0h}{2022/06/20}{Use raw options data}
494 % \changes{v1.0q}{2025/06/25}{Revise for multiple family support}
495 % If local options are found, they are added to the processing list.
496 % \LaTeXe{} stores options for each file in a macro which may or may not
497 % exist, hence the need to use \cs{cs_if_exist:c}. For tracking the unused
498 % options, we need to hold only the option name, hence needing a mapping.
499 % \begin{macrocode}
500 \cs_new_protected:Npn \@@_options_local:
501 {
502 \clist_clear:N \l_@@_local_clist
503 \cs_if_eq:NNF \@currext \@clsextension
504 {
505 \cs_if_exist:cT { @raw@opt@ \@currname . \@currext }
506 {
507 \clist_set_eq:Nc \l_@@_local_clist
508 { @raw@opt@ \@currname . \@currext }
509 }
510 }
511 \clist_map_inline:Nn \l_@@_local_clist
512 {
513 \clist_put_right:Ne \l_@@_unused_clist
514 { \tl_trim_spaces:e { \@@_remove_equals:n {##1} } }
515 }
516 }
517 % \end{macrocode}
518 % \end{macro}
519 %
520 % \begin{macro}{\@@_options_local:n}
521 % \changes{v1.0q}{2025/06/25}{New function}
522 % \begin{macro}{\@@_options_local:nnn}
523 % \changes{v1.0q}{2025/06/25}{New function}
524 % A simpler version of the code used for package options: we stack up those
525 % that are known, unless the family supports unknown keys in which case we hover
526 % up everything.
527 % \begin{macrocode}
528 \cs_new_protected:Npn \@@_options_local:n #1
529 {
530 \keys_if_exist:nnTF {#1} { unknown }
531 {
532 \clist_put_right:NV \l_@@_options_clist \l_@@_local_clist
533 \clist_clear:N \l_@@_unused_clist
534 }
535 {
536 \clist_map_inline:Nn \l_@@_local_clist
537 {
538 \exp_args:Ne \@@_options_local:nnn
539 { \tl_trim_spaces:e { \@@_remove_equals:n {##1} } }
540 {##1} {#1}
541 }
542 }
543 }
544 \cs_new_protected:Npn \@@_options_local:nnn #1#2#3
545 {
546 \keys_if_exist:nnT {#3} {#1}
547 {
548 \clist_put_right:Nn \l_@@_options_clist {#2}
549 \clist_remove_all:Nn \l_@@_unused_clist {#1}
550 }
551 }
552 % \end{macrocode}
553 % \end{macro}
554 % \end{macro}
555 %
556 % \begin{macro}[EXP]{\@@_remove_equals:n}
557 % \begin{macro}[EXP]{\@@_remove_equals:w}
558 % As the name suggests, this is a simple function to remove an equals
559 % sign from the input. This is all wrapped up in an \texttt{n} function
560 % so that there will always be a sign available.
561 % \begin{macrocode}
562 \cs_new:Npn \@@_remove_equals:n #1
563 { \@@_remove_equals:w #1 = \s_@@_stop }
564 \cs_new:Npn \@@_remove_equals:w #1 = #2 \s_@@_stop { \exp_not:n {#1} }
565 % \end{macrocode}
566 % \end{macro}
567 % \end{macro}
568 %
569 % \subsection{The document interfaces}
570 %
571 % \begin{macrocode}
572 \cs_generate_variant:Nn \keys_define:nn { nx }
573 % \end{macrocode}
574 %
575 % \begin{macro}{\@@_options_expand_module:Nn}
576 % \changes{v1.0e}{2022/02/21}
577 % {Faster approach to module expansion}
578 % \begin{macro}{\@@_options_expand_module:nN}
579 % To deal with active characters inside the module argument whilst also
580 % expanding that argument, we use a combination of \texttt{c}- and
581 % \texttt{f}-type expansion. This works as the definitions for active
582 % UTF-8 bytes contain an \cs{ifincsname} test.
583 % \begin{macrocode}
584 \cs_new_protected:Npn \@@_options_expand_module:Nn #1#2
585 {
586 \cs:w @@_options_expand_module:nN \use:e { \cs_end: {#2} } #1
587 }
588 \cs_new_protected:Npn \@@_options_expand_module:nN #1#2
589 { #2 {#1} }
590 % \end{macrocode}
591 % \end{macro}
592 % \end{macro}
593 %
594 % \begin{macro}{\DeclareKeys}
595 % \changes{v1.0c}{2022/02/15}{Expand module argument}
596 % \changes{v1.0d}{2022/02/16}{Allow for active characters in module argument}
597 % Defining key options is quite straight-forward: we have an intermediate
598 % function to allow for potential set-up steps.
599 % \begin{macrocode}
600 \NewDocumentCommand \DeclareKeys { O { \@currname } +m }
601 { \@@_options_expand_module:Nn \keys_define:nn {#1} {#2} }
602 % \end{macrocode}
603 % \end{macro}
604 %
605 % \begin{macro}{\DeclareUnknownKeyHandler}
606 % \changes{v1.0c}{2022/02/15}{Added \cs{DeclareUnknownKeysHandler}}
607 % \changes{v1.0d}{2022/02/16}{Allow for active characters in module argument}
608 % \changes{v1.0d}{2022/02/16}
609 % {Rename \cs{DeclareUnknownKeysHandler} to \cs{DeclareUnknownKeyHandler}}
610 % \begin{macrocode}
611 \NewDocumentCommand \DeclareUnknownKeyHandler { O { \@currname } +m }
612 {
613 \cs_set_protected:cpn { @@_unknown_handler_ #1 :nn } ##1##2 {#2}
614 \@@_options_expand_module:Nn \keys_define:nx {#1}
615 {
616 unknown .code:n =
617 \exp_not:N \exp_args:NV
618 \exp_not:c { @@_unknown_handler_ #1 :nn }
619 \exp_not:N \l_keys_key_str {####1}
620 }
621 }
622 % \end{macrocode}
623 % \end{macro}
624 %
625 % \begin{macro}{\ProcessKeyOptions}
626 % \changes{v1.0c}{2022/02/15}{Expand module argument}
627 % \changes{v1.0d}{2022/02/16}{Allow for active characters in module argument}
628 % \changes{v1.0f}{2022/03/18}{Remove \cs{ProcessKeyPackageOptions}}
629 % We need to deal with the older interface from \pkg{l3keys2e} here: it had
630 % a mandatory argument. We can mop that up using a look-ahead, and then
631 % exploit that information to determine whether the package option handling
632 % is set up for the new approach for clash handling.
633 % \begin{macrocode}
634 \NewDocumentCommand \ProcessKeyOptions { O { \@currname } }
635 { \@@_options:n {#1} }
636 \@onlypreamble \ProcessKeyOptions
637 % \end{macrocode}
638 % \end{macro}
639 %
640 % \subsection{Option usage scope}
641 %
642 % \begin{macro}{\@@_options_loaded:n}
643 % \begin{macro}{\@@_options_loaded:nn}
644 % \changes{v1.0l}{2022/10/20}{Correct an argument for a message}
645 % Indicates that the load-time options for a package have been processed:
646 % once this has happened, make them unavailable either with a warning or
647 % an error.
648 % \begin{macrocode}
649 \cs_new_protected:Npn \@@_options_loaded:n #1
650 {
651 \prop_get:NnNT \l_keys_usage_load_prop {#1} \l_@@_tmpa_tl
652 {
653 \clist_map_inline:Nn \l_@@_tmpa_tl
654 {
655 \keys_define:nn {#1}
656 {
657 ##1 .code:n =
658 \@@_options_loaded:nn {#1} {##1}
659 }
660 }
661 }
662 }
663 \cs_new_protected:Npn \@@_options_loaded:nn #1#2
664 {
665 \bool_if:NTF \l_@@_options_loading_bool
666 { \msg_warning:nnnn { keys } { load-option-ignored } }
667 { \msg_error:nnnn { keys } { load-only } }
668 {#1} {#2}
669 }
670 % \end{macrocode}
671 % \changes{v1.0j}{2022/07/23}
672 % {Output `public' package name in messages}
673 % \begin{macrocode}
674 \msg_new:nnn { keys } { load-option-ignored }
675 {
676 Package~"\msg_module_name:n {#1}"~has~already~been~loaded:~
677 ignoring~load-time~option~"#2".
678 }
679 % \end{macrocode}
680 % \changes{v1.0j}{2022/07/23}
681 % {Output `public' package name in messages}
682 % \changes{v1.0k}{2022/08/21}
683 % {Correct error message}
684 % \begin{macrocode}
685 \msg_new:nnnn { keys } { load-only }
686 {
687 Key~"#2"~may~only~be~used~during~loading~of~package~
688 "\msg_module_name:n {#1}".
689 }
690 {
691 LaTeX~was~asked~to~set~a~key~called~"#2",~but~this~is~only~allowed~
692 in~the~optional~argument~when~loading~package~"\msg_module_name:n{#1}".
693 }
694 % \end{macrocode}
695 % \end{macro}
696 % \end{macro}
697 %
698 % Disable all preamble options in one shot.
699 % \begin{macrocode}
700 \tl_gput_left:Nn \@kernel@after@begindocument
701 {
702 \prop_map_inline:Nn \l_keys_usage_preamble_prop
703 {
704 \clist_map_inline:nn {#2}
705 {
706 \keys_define:nn {#1}
707 {
708 ##1 .code:n =
709 \msg_error:nnn { keys } { preamble-only } {##1}
710 }
711 }
712 }
713 }
714 \msg_new:nnnn { keys } { preamble-only }
715 { Key~"#1"~may~only~be~used~in~the~preamble. }
716 {
717 LaTeX~was~asked~to~set~a~key~called~"#1",~but~this~is~only~allowed~
718 before~\begin{document}.~You~will~need~to~set~the~key~earlier.
719 }
720 % \end{macrocode}
721 %
722 % \subsection{General key setting}
723 %
724 % \begin{macro}{\SetKeys}
725 % \changes{v1.0c}{2022/02/15}{Expand module argument}
726 % \changes{v1.0d}{2022/02/16}{Allow for active characters in module argument}
727 % A simple wrapper.
728 % \begin{macrocode}
729 \NewDocumentCommand \SetKeys { O { \@currname } +m }
730 { \@@_options_expand_module:Nn \keys_set:nn {#1} {#2} }
731 % \end{macrocode}
732 % \end{macro}
733 %
734 % \begin{macrocode}
735 \ExplSyntaxOff
736 % \end{macrocode}
737 %
738 % \begin{macrocode}
739 %</2ekernel>
740 % \end{macrocode}