Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2021-2026
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 [2026-03-13 v1.0r LaTeX Kernel (Keyval options)]
37 % \iffalse
38 \documentclass{l3in2edoc}
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 % \changes{v1.0r}{2026-03-12}{Switch from \texttt{x}- to \texttt{e}-type
166 % expansion in expl3 code}
167 %
168 % \subsection{Key properties}
169 %
170 % \begin{macro}{.code, .if, .ifnot, .store, .usage}
171 % \changes{v1.0b}{2022/02/05}
172 % {Create properties in \texttt{ltkeys}}
173 % \changes{v1.0c}{2022/02/07}
174 % {Correct \texttt.{.code} property}
175 % \changes{v1.0i}{2022/06/22}
176 % {Add \texttt.{.notif} property}
177 % \begin{macrocode}
178 \group_begin:
179 \cs_set_protected:Npn \@@_tmp:nn #1#2
180 {
181 \quark_if_recursion_tail_stop:n {#1}
182 \cs_new_eq:cc
183 { \c_@@_props_root_str . #2 }
184 { \c_@@_props_root_str . #1 }
185 \@@_tmp:nn
186 }
187 \@@_tmp:nn
188 { code:n } { code }
189 { legacy_if_set:n } { if }
190 { legacy_if_set_inverse:n } { ifnot }
191 { tl_set:N } { store }
192 { usage:n } { usage }
193 { \q_recursion_tail } { }
194 \q_recursion_stop
195 \group_end:
196 % \end{macrocode}
197 % \end{macro}
198 %
199 % \begin{macro}{.pass-to-packages}
200 % \changes{v1.0n}{2024/06/19}{New key property}
201 % \begin{macro}{\@@_scope:n}
202 % \changes{v1.0n}{2024/06/19}{New function}
203 % \begin{macro}{\@@_scope:N}
204 % \changes{v1.0n}{2024/06/19}{New function}
205 % \changes{v1.0o}{2024/06/20}{Ensure only key name is stored}
206 % Used to force options to be global: as this property (uniquely) has
207 % an \emph{optional} value, there is a bit of work to do.
208 % \begin{macrocode}
209 \cs_new_protected:cpn { \c_@@_props_root_str .pass-to-packages }
210 {
211 \bool_if:NTF \l_@@_no_value_bool
212 { \@@_scope:n { true } }
213 { \@@_scope:n }
214 }
215 \cs_new_protected:Npn \@@_scope:n #1
216 {
217 \str_case:nnF {#1}
218 {
219 { true }
220 { \@@_scope:N \clist_put_right:NV }
221 { false }
222 { \@@_scope:N \clist_remove_all:NV }
223 }
224 {
225 \msg_error:nnnn { keys }
226 { choice-unknown }
227 { .pass-to-packages }
228 {#1}
229 }
230 }
231 \cs_new_protected:Npn \@@_scope:N #1
232 {
233 \exp_after:wN \@@_find_key_module:wNN
234 \l_keys_path_str \s_@@_stop
235 \l_keys_key_tl \l_keys_key_str
236 #1 \l_@@_forced_global_clist \l_keys_key_str
237 }
238 % \end{macrocode}
239 % \end{macro}
240 % \end{macro}
241 % \end{macro}
242 %
243 % \subsection{Main mechanism}
244 %
245 % \changes{v1.0r}{2026-03-13}{Tidy up variants}
246 %
247 % \begin{macrocode}
248 \cs_generate_variant:Nn \clist_if_in:NnT { Ne }
249 \cs_generate_variant:Nn \clist_if_in:NnTF { Ne }
250 % \end{macrocode}
251 %
252 % \begin{macro}{\l_@@_class_only_clist}
253 % \changes{v1.0n}{2024/06/19}{New variable}
254 % Used to track class-only options.
255 % \begin{macrocode}
256 \clist_new:N \l_@@_class_only_clist
257 % \end{macrocode}
258 % \end{macro}
259 %
260 % \begin{macro}{\l_@@_forced_global_clist}
261 % \changes{v1.0n}{2024/06/19}{New variable}
262 % Used to force options to be global.
263 % \begin{macrocode}
264 \clist_new:N \l_@@_forced_global_clist
265 % \end{macrocode}
266 % \end{macro}
267 %
268 % \begin{macro}{\l_@@_options_clist}
269 % A single list is used for all options, into which they are collected
270 % before processing.
271 % \begin{macrocode}
272 \clist_new:N \l_@@_options_clist
273 % \end{macrocode}
274 % \end{macro}
275 %
276 % \begin{macro}{\l_@@_local_clist}
277 % \changes{v1.0q}{2025/06/25}{New variable}
278 % Holds the local options when appropriate: otherwise empty. Needed as
279 % the \LaTeXe{} setup here can be equal to \cs{scan_stop:}, which is not
280 % generally supported.
281 % \begin{macrocode}
282 \clist_new:N \l_@@_local_clist
283 % \end{macrocode}
284 % \end{macro}
285 %
286 % \begin{variable}{\l_@@_options_loading_bool}
287 % Used to indicate we are in the loading phase: controls the outcome
288 % of warnings.
289 % \begin{macrocode}
290 \bool_new:N \l_@@_options_loading_bool
291 % \end{macrocode}
292 % \end{variable}
293 %
294 % \begin{macro}{\@@_options:n}
295 % \changes{v1.0f}{2022/03/18}{Simplify to always cover global options}
296 % \begin{macro}{\@@_options_aux:n}
297 % \changes{v1.0b}{2022/01/15}
298 % {Clear option list in end-of-package hook}
299 % \changes{v1.0l}{2022/10/20}
300 % {Define key option handler in \pkg{ltkeys}}
301 % \changes{v1.0i}{2022/07/05}{Support \cs{CurrentOption}}
302 % \changes{v1.0p}{2025/01/15}{Only process global options on first pass}
303 % \changes{v1.0q}{2025/06/25}{Revise for multiple family support}
304 % The main function calls functions to collect up the global and local
305 % options into \cs{l_@@_options_clist} before calling the
306 % underlying functions to actually do the processing. So that a suitable
307 % message is produced if the option is unknown, the special
308 % \texttt{unknown} key is set if it does not already exist for the
309 % current family, and is cleaned up afterwards if required. To allow
310 % the \LaTeXe{} layer to know this mechanism is active, and to deal
311 % with the key family not matching the file name, we store the family
312 % in all cases. Global options are only considered the first time a
313 % package is loaded: this is tracked using
314 % |opt@handler@\@currname.\@currext|, as this is defined once keyval
315 % processing has been applied for the first time.
316 % \begin{macrocode}
317 \cs_new_protected:Npn \@@_options:n #1
318 { \@@_options_expand_module:Nn \@@_options_aux:n {#1} }
319 \cs_new_protected:Npn \@@_options_aux:n #1
320 {
321 \@@_options_local:
322 \clist_map_inline:nn {#1}
323 {
324 \clist_clear:N \l_@@_options_clist
325 \cs_if_exist:cF { opt@handler@ \@currname . \@currext }
326 { \@@_options_global:n {##1} }
327 \@@_options_local:n {##1}
328 \bool_set_true:N \l_@@_options_loading_bool
329 \clist_map_variable:NNn \l_@@_options_clist \CurrentOption
330 { \keys_set:nV {##1} \CurrentOption }
331 \bool_set_false:N \l_@@_options_loading_bool
332 \@@_options_loaded:n {##1}
333 }
334 \clist_if_empty:NF \l_@@_unused_clist
335 {
336 \clist_map_inline:Nn \l_@@_unused_clist
337 {
338 \msg_error:nnee { keys } { option-unknown }
339 {##1} { \@currname }
340 }
341 }
342 \cs_if_exist:cF { opt@handler@ \@currname . \@currext }
343 {
344 \cs_gset_protected:cpn { opt@handler@ \@currname . \@currext }
345 { \ProcessKeyOptions [ {#1} ] }
346 }
347 \AtEndOfPackage { \cs_set_eq:NN \@unprocessedoptions \scan_stop: }
348 }
349 % \end{macrocode}
350 % \changes{v1.0j}{2022/07/23}
351 % {Output `public' package name in messages}
352 % \begin{macrocode}
353 \msg_new:nnnn { keys } { option-unknown }
354 { Unknown~option~'#1'~for~package~#2. }
355 {
356 LaTeX~has~been~asked~to~set~an~option~called~'#1'~
357 but~the~package~"\msg_module_name:n {#2}"~has~not~created~an~option~with~this~name.
358 }
359 % \end{macrocode}
360 % \end{macro}
361 % \end{macro}
362 %
363 % \begin{macro}{\@@_options_global:n}
364 % \changes{v1.0f}{2022/03/18}{Simplify to always cover global options}
365 % \changes{v1.0h}{2022/06/20}{Use raw options data}
366 % Global (class) options are handled differently for \LaTeXe{} packages
367 % and classes. Hence this function is essentially a check on the current
368 % file type. The initial test is needed as \LaTeXe{} allows variables to
369 % be equal to \cs{scan_stop:}, which is usually forbidden in \pkg{expl3}
370 % code.
371 % \begin{macrocode}
372 \cs_new_protected:Npn \@@_options_global:n #1
373 {
374 \cs_if_eq:NNF \@raw@classoptionslist \scan_stop:
375 {
376 \cs_if_eq:NNTF \@currext \@clsextension
377 { \@@_options_class:n {#1} }
378 { \@@_options_package:n {#1} }
379 }
380 }
381 % \end{macrocode}
382 % \end{macro}
383 %
384 % \begin{macro}{\@@_options_class:n}
385 % \changes{v1.0g}{2022/06/16}{Better handling of option removal}
386 % \changes{v1.0h}{2022/06/19}{Further work on handling of option removal}
387 % \changes{v1.0h}{2022/06/20}{Use raw options data}
388 % \changes{v1.0m}{2024/01/13}{Trim spaces off key names}
389 % \changes{v1.0n}{2024/06/19}{Refactor function}
390 % \begin{macro}{\@@_options_class:nnn}
391 % \changes{v1.0h}{2022/06/20}{New function}
392 % \changes{v1.0i}{2022/07/05}{Correct naming of raw class options storage}
393 % \changes{v1.0l}{2022/10/22}{Correct handling of unused option list}
394 % \changes{v1.0n}{2024/06/19}{Refactor function}
395 % \changes{v1.0n}{2024/06/19}{Track options used by classes}
396 % \begin{macro}{\@@_options_class:nn}
397 % \changes{v1.0n}{2024/06/19}{New function}
398 % For classes, each option (stripped of any content after |=|)
399 % is checked for existence as a key. If found, the option is added to
400 % the combined list for processing. On the other hand, unused options
401 % are stored up in \cs{@unusedoptionlist}. An earlier version of
402 % this code checked for the \texttt{unknown} key just once and
403 % if found short-cutted the loop: that though makes handling more
404 % complex situations harder, so we take the performance hit instead.
405 % Options used by classes are tracked but the catch-all \texttt{unknown}
406 % is excluded (hence not using a lazy evaluation for the key testing).
407 % \begin{macrocode}
408 \cs_new_protected:Npn \@@_options_class:n #1
409 {
410 \cs_if_free:cF { @raw@opt@ \@currname . \@currext }
411 {
412 \clist_map_inline:cn { @raw@opt@ \@currname . \@currext }
413 {
414 \exp_args:Ne \@@_options_class:nnn
415 { \tl_trim_spaces:e { \@@_remove_equals:n {##1} } }
416 {##1} {#1}
417 }
418 }
419 }
420 \cs_new_protected:Npn \@@_options_class:nnn #1#2#3
421 {
422 \keys_if_exist:nnTF {#3} {#1}
423 {
424 \@@_options_class:nn {#1} {#2}
425 \clist_put_right:Ne \l_@@_class_only_clist { \tl_to_str:n {#1} }
426 }
427 {
428 \keys_if_exist:nnTF {#3} { unknown }
429 { \@@_options_class:nn {#1} {#2} }
430 {
431 \clist_if_in:NnF \@unusedoptionlist {#1}
432 { \clist_put_right:Nn \@unusedoptionlist {#1} }
433 }
434 }
435 }
436 \cs_new_protected:Npn \@@_options_class:nn #1#2
437 {
438 \clist_remove_all:Nn \@unusedoptionlist {#1}
439 \clist_put_right:Nn \l_@@_options_clist {#2}
440 }
441 % \end{macrocode}
442 % \end{macro}
443 % \end{macro}
444 % \end{macro}
445 %
446 % \begin{macro}{\@@_options_package:n}
447 % \changes{v1.0g}{2022/06/16}{Better handling of option removal}
448 % \changes{v1.0h}{2022/06/19}{Further work on handling of option removal}
449 % \changes{v1.0h}{2022/06/20}{Use raw options data}
450 % \changes{v1.0m}{2024/01/13}{Trim spaces off key names}
451 % \begin{macro}{\@@_options_package:nnn}
452 % \changes{v1.0h}{2022/06/19}{New function}
453 % \changes{v1.0n}{2024/06/19}{Skip options given to packages}
454 % \begin{macro}{\@@_options_package:nn}
455 % \changes{v1.0n}{2024/06/19}{New functions}
456 % For global options when processing a package, the tasks are slightly
457 % different from those for a class. The check is the same, but here
458 % there is nothing to do if the option is not applicable. Each valid
459 % option also needs to be removed from \cs{@unusedoptionlist}.
460 % \begin{macrocode}
461 \cs_new_protected:Npn \@@_options_package:n #1
462 {
463 \clist_map_inline:Nn \@raw@classoptionslist
464 {
465 \exp_args:Ne \@@_options_package:nnn
466 { \tl_trim_spaces:e { \@@_remove_equals:n {##1} } }
467 {##1} {#1}
468 }
469 }
470 % \end{macrocode}
471 % The forced-global test here needs to use \cs{tl_to_str:n} as the data come
472 % from a key name, which is always a string.
473 % \begin{macrocode}
474 \cs_new_protected:Npn \@@_options_package:nnn #1#2#3
475 {
476 \keys_if_exist:nnT {#3} {#1}
477 {
478 \clist_if_in:NeTF \l_@@_class_only_clist { \tl_to_str:n {#1} }
479 {
480 \clist_if_in:NeT \l_@@_forced_global_clist { \tl_to_str:n {#1} }
481 { \@@_options_package:nn {#1} {#2} }
482 }
483 { \@@_options_package:nn {#1} {#2} }
484 }
485 }
486 \cs_new_protected:Npn \@@_options_package:nn #1#2
487 {
488 \clist_put_right:Nn \l_@@_options_clist {#2}
489 \clist_remove_all:Nn \@unusedoptionlist {#1}
490 }
491 % \end{macrocode}
492 % \end{macro}
493 % \end{macro}
494 % \end{macro}
495 %
496 % \begin{macro}{\@@_options_local:}
497 % \changes{v1.0h}{2022/06/20}{Use raw options data}
498 % \changes{v1.0q}{2025/06/25}{Revise for multiple family support}
499 % If local options are found, they are added to the processing list.
500 % \LaTeXe{} stores options for each file in a macro which may or may not
501 % exist, hence the need to use \cs{cs_if_exist:c}. For tracking the unused
502 % options, we need to hold only the option name, hence needing a mapping.
503 % \begin{macrocode}
504 \cs_new_protected:Npn \@@_options_local:
505 {
506 \clist_clear:N \l_@@_local_clist
507 \cs_if_eq:NNF \@currext \@clsextension
508 {
509 \cs_if_exist:cT { @raw@opt@ \@currname . \@currext }
510 {
511 \clist_set_eq:Nc \l_@@_local_clist
512 { @raw@opt@ \@currname . \@currext }
513 }
514 }
515 \clist_map_inline:Nn \l_@@_local_clist
516 {
517 \clist_put_right:Ne \l_@@_unused_clist
518 { \tl_trim_spaces:e { \@@_remove_equals:n {##1} } }
519 }
520 }
521 % \end{macrocode}
522 % \end{macro}
523 %
524 % \begin{macro}{\@@_options_local:n}
525 % \changes{v1.0q}{2025/06/25}{New function}
526 % \begin{macro}{\@@_options_local:nnn}
527 % \changes{v1.0q}{2025/06/25}{New function}
528 % A simpler version of the code used for package options: we stack up those
529 % that are known, unless the family supports unknown keys in which case we hover
530 % up everything.
531 % \begin{macrocode}
532 \cs_new_protected:Npn \@@_options_local:n #1
533 {
534 \keys_if_exist:nnTF {#1} { unknown }
535 {
536 \clist_put_right:NV \l_@@_options_clist \l_@@_local_clist
537 \clist_clear:N \l_@@_unused_clist
538 }
539 {
540 \clist_map_inline:Nn \l_@@_local_clist
541 {
542 \exp_args:Ne \@@_options_local:nnn
543 { \tl_trim_spaces:e { \@@_remove_equals:n {##1} } }
544 {##1} {#1}
545 }
546 }
547 }
548 \cs_new_protected:Npn \@@_options_local:nnn #1#2#3
549 {
550 \keys_if_exist:nnT {#3} {#1}
551 {
552 \clist_put_right:Nn \l_@@_options_clist {#2}
553 \clist_remove_all:Nn \l_@@_unused_clist {#1}
554 }
555 }
556 % \end{macrocode}
557 % \end{macro}
558 % \end{macro}
559 %
560 % \begin{macro}[EXP]{\@@_remove_equals:n}
561 % \begin{macro}[EXP]{\@@_remove_equals:w}
562 % As the name suggests, this is a simple function to remove an equals
563 % sign from the input. This is all wrapped up in an \texttt{n} function
564 % so that there will always be a sign available.
565 % \begin{macrocode}
566 \cs_new:Npn \@@_remove_equals:n #1
567 { \@@_remove_equals:w #1 = \s_@@_stop }
568 \cs_new:Npn \@@_remove_equals:w #1 = #2 \s_@@_stop { \exp_not:n {#1} }
569 % \end{macrocode}
570 % \end{macro}
571 % \end{macro}
572 %
573 % \subsection{The document interfaces}
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:ne {#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}