Debian Codegraph @

texmf-dist/source/latex/kvsetkeys/kvsetkeys.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: kvsetkeys.dtx
4 % Version: 2022-10-05 v1.19
5 % Info: Key value parser
6 %
7 % Copyright (C)
8 % 2006, 2007, 2009-2012 Heiko Oberdiek
9 % 2016-2022 Oberdiek Package Support Group
10 % https://github.com/ho-tex/kvsetkeys/issues
11 %
12 % This work may be distributed and/or modified under the
13 % conditions of the LaTeX Project Public License, either
14 % version 1.3c of this license or (at your option) any later
15 % version. This version of this license is in
16 % https://www.latex-project.org/lppl/lppl-1-3c.txt
17 % and the latest version of this license is in
18 % https://www.latex-project.org/lppl.txt
19 % and version 1.3 or later is part of all distributions of
20 % LaTeX version 2005/12/01 or later.
21 %
22 % This work has the LPPL maintenance status "maintained".
23 %
24 % The Current Maintainers of this work are
25 % Heiko Oberdiek and the Oberdiek Package Support Group
26 % https://github.com/ho-tex/kvsetkeys/issues
27 %
28 % The Base Interpreter refers to any `TeX-Format',
29 % because some files are installed in TDS:tex/generic//.
30 %
31 % This work consists of the main source file kvsetkeys.dtx
32 % and the derived files
33 % kvsetkeys.sty, kvsetkeys.pdf, kvsetkeys.ins, kvsetkeys.drv,
34 % kvsetkeys-example.tex, kvsetkeys-test1.tex,
35 % kvsetkeys-test2.tex, kvsetkeys-test3.tex,
36 % kvsetkeys-test4.tex.
37 %
38 % Distribution:
39 % CTAN:macros/latex/contrib/kvsetkeys/kvsetkeys.dtx
40 % CTAN:macros/latex/contrib/kvsetkeys/kvsetkeys.pdf
41 %
42 % Unpacking:
43 % (a) If kvsetkeys.ins is present:
44 % tex kvsetkeys.ins
45 % (b) Without kvsetkeys.ins:
46 % tex kvsetkeys.dtx
47 % (c) If you insist on using LaTeX
48 % latex \let\install=y\input{kvsetkeys.dtx}
49 % (quote the arguments according to the demands of your shell)
50 %
51 % Documentation:
52 % (a) If kvsetkeys.drv is present:
53 % latex kvsetkeys.drv
54 % (b) Without kvsetkeys.drv:
55 % latex kvsetkeys.dtx; ...
56 % The class ltxdoc loads the configuration file ltxdoc.cfg
57 % if available. Here you can specify further options, e.g.
58 % use A4 as paper format:
59 % \PassOptionsToClass{a4paper}{article}
60 %
61 % Programm calls to get the documentation (example):
62 % pdflatex kvsetkeys.dtx
63 % makeindex -s gind.ist kvsetkeys.idx
64 % pdflatex kvsetkeys.dtx
65 % makeindex -s gind.ist kvsetkeys.idx
66 % pdflatex kvsetkeys.dtx
67 %
68 % Installation:
69 % TDS:tex/generic/kvsetkeys/kvsetkeys.sty
70 % TDS:doc/latex/kvsetkeys/kvsetkeys.pdf
71 % TDS:doc/latex/kvsetkeys/kvsetkeys-example.tex
72 % TDS:source/latex/kvsetkeys/kvsetkeys.dtx
73 %
74 %<*ignore>
75 \begingroup
76 \catcode123=1 %
77 \catcode125=2 %
78 \def\x{LaTeX2e}%
79 \expandafter\endgroup
80 \ifcase 0\ifx\install y1\fi\expandafter
81 \ifx\csname processbatchFile\endcsname\relax\else1\fi
82 \ifx\fmtname\x\else 1\fi\relax
83 \else\csname fi\endcsname
84 %</ignore>
85 %<*install>
86 \input docstrip.tex
87 \Msg{************************************************************************}
88 \Msg{* Installation}
89 \Msg{* Package: kvsetkeys 2022-10-05 v1.19 Key value parser (HO)}
90 \Msg{************************************************************************}
91
92 \keepsilent
93 \askforoverwritefalse
94
95 \let\MetaPrefix\relax
96 \preamble
97
98 This is a generated file.
99
100 Project: kvsetkeys
101 Version: 2022-10-05 v1.19
102
103 Copyright (C)
104 2006, 2007, 2009-2012 Heiko Oberdiek
105 2016-2022 Oberdiek Package Support Group
106
107 This work may be distributed and/or modified under the
108 conditions of the LaTeX Project Public License, either
109 version 1.3c of this license or (at your option) any later
110 version. This version of this license is in
111 https://www.latex-project.org/lppl/lppl-1-3c.txt
112 and the latest version of this license is in
113 https://www.latex-project.org/lppl.txt
114 and version 1.3 or later is part of all distributions of
115 LaTeX version 2005/12/01 or later.
116
117 This work has the LPPL maintenance status "maintained".
118
119 The Current Maintainers of this work are
120 Heiko Oberdiek and the Oberdiek Package Support Group
121 https://github.com/ho-tex/kvsetkeys/issues
122
123
124 The Base Interpreter refers to any `TeX-Format',
125 because some files are installed in TDS:tex/generic//.
126
127 This work consists of the main source file kvsetkeys.dtx
128 and the derived files
129 kvsetkeys.sty, kvsetkeys.pdf, kvsetkeys.ins, kvsetkeys.drv,
130 kvsetkeys-example.tex, kvsetkeys-test1.tex,
131 kvsetkeys-test2.tex, kvsetkeys-test3.tex,
132 kvsetkeys-test4.tex.
133
134 \endpreamble
135 \let\MetaPrefix\DoubleperCent
136
137 \generate{%
138 \file{kvsetkeys.ins}{\from{kvsetkeys.dtx}{install}}%
139 \file{kvsetkeys.drv}{\from{kvsetkeys.dtx}{driver}}%
140 \usedir{tex/generic/kvsetkeys}%
141 \file{kvsetkeys.sty}{\from{kvsetkeys.dtx}{package}}%
142 \usedir{doc/latex/kvsetkeys}%
143 \file{kvsetkeys-example.tex}{\from{kvsetkeys.dtx}{example}}%
144 }
145
146 \catcode32=13\relax% active space
147 \let =\space%
148 \Msg{************************************************************************}
149 \Msg{*}
150 \Msg{* To finish the installation you have to move the following}
151 \Msg{* file into a directory searched by TeX:}
152 \Msg{*}
153 \Msg{* kvsetkeys.sty}
154 \Msg{*}
155 \Msg{* To produce the documentation run the file `kvsetkeys.drv'}
156 \Msg{* through LaTeX.}
157 \Msg{*}
158 \Msg{* Happy TeXing!}
159 \Msg{*}
160 \Msg{************************************************************************}
161
162 \endbatchfile
163 %</install>
164 %<*ignore>
165 \fi
166 %</ignore>
167 %<*driver>
168 \NeedsTeXFormat{LaTeX2e}
169 \ProvidesFile{kvsetkeys.drv}%
170 [2022-10-05 v1.19 Key value parser (HO)]%
171 \documentclass{ltxdoc}
172 \usepackage{holtxdoc}[2011/11/22]
173 \begin{document}
174 \DocInput{kvsetkeys.dtx}%
175 \end{document}
176 %</driver>
177 % \fi
178 %
179 %
180 %
181 % \GetFileInfo{kvsetkeys.drv}
182 %
183 % \title{The \xpackage{kvsetkeys} package}
184 % \date{2022-10-05 v1.19}
185 % \author{Heiko Oberdiek\thanks
186 % {Please report any issues at \url{https://github.com/ho-tex/kvsetkeys/issues}}}
187 %
188 % \maketitle
189 %
190 % \begin{abstract}
191 % Package \xpackage{kvsetkeys} provides \cs{kvsetkeys}, a variant
192 % of package \xpackage{keyval}'s \cs{setkeys}. It allows to specify
193 % a handler that deals with unknown options. Active commas and equal
194 % signs may be used (e.g. see \xpackage{babel}'s shorthands) and
195 % only one level of curly braces is removed from the values.
196 % \end{abstract}
197 %
198 % \tableofcontents
199 %
200 % \def\M#1{\texttt{\{}\meta{#1}\texttt{\}}}
201 %
202 % \section{Documentation}
203 %
204 % First I want to recommend the very good review article
205 % ``A guide to key-value methods'' by Joseph Wright \cite{tb94wright}.
206 % It introduces the different key-value packages and compares them.
207 %
208 % \subsection{Motivation}
209 %
210 % \cs{kvsetkeys} serves as replacement for \xpackage{keyval}'s
211 % \cs{setkeys}. It basically uses the same syntax. But the
212 % implementation is more robust and predictable:
213 % \begin{description}
214 % \item[Active syntax characters:]
215 % Comma `|,|' and the equals sign `|=|' are used inside
216 % key value lists as syntax characters. Package \xpackage{keyval}
217 % uses the catcode of the characters that is active during
218 % package loading, usually this is catcode 12 (other).
219 % But it can happen that the catcode setting of the syntax characters
220 % changes. Especially active characters are of interest, because
221 % some language adaptations uses them. For example, option \xoption{turkish}
222 % of package \xpackage{babel} uses the equals sign as active shorthand
223 % character. Therefore package \xpackage{kvsetkeys} deals with
224 % both catcode settings 12 (other) and 13 (active).
225 % \item[Brace removal:]
226 % Package \xpackage{keyval}'s \cs{setkeys} removes up to two
227 % levels of curly braces around the value in some unpredictable way:
228 %\begin{quote}
229 %|\setkeys{fam}{key={{value}}} || || | $\rightarrow$ |value|\\
230 %|\setkeys{fam}{key={{{value}}}} | $\rightarrow$ |{value}|\\
231 %|\setkeys{fam}{key= {{{value}}}}| $\rightarrow$ |{{value}}|
232 %\end{quote}
233 % This package \xpackage{kvsetkeys} follows a much stronger rule:
234 % Exactly one level of braces are removed from an item, if the
235 % item is surrounded by curly braces. An item can be a
236 % the key value pair, the key or the value.
237 %\begin{quote}
238 %|\kvsetkeys{fam}{key={value}} || | $\rightarrow$ |value|\\
239 %|\kvsetkeys{fam}{key={{value}} | $\rightarrow$ |{value}|\\
240 %|\kvsetkeys{fam}{key= {{value}}| $\rightarrow$ |{value}|
241 %\end{quote}
242 % \item[Arbitrary values:] Unmatched conditionals are supported.
243 % \end{description}
244 %
245 % Before I describe
246 % \cs{kvsetkeys} in more detail, first I want to explain, how
247 % this package deals with key value lists. For the package also
248 % provides low level interfaces that can be used by package authors.
249 %
250 % \subsection{Normalizing key value lists}
251 %
252 % \begin{declcs}{kv@normalize}\,\M{key value list}
253 % \end{declcs}
254 % If the user specifies key value lists, he usually prefers
255 % nice formatted source code, e.g.:
256 % \begin{quote}
257 %\begin{verbatim}
258 %\hypersetup{
259 % pdftitle = {...},
260 % pdfsubject = {...},
261 % pdfauthor = {...},
262 % pdfkeywords = {...},
263 % ...
264 %}
265 %\end{verbatim}
266 % \end{quote}
267 % Thus there can be spaces around keys, around |=| or around the value.
268 % Also empty entries are possible by too many commas. Therefore these
269 % spaces and empty entries are silently removed by package \xpackage{keyval}
270 % and this package. Whereas the contents of the value can be protected
271 % by curly braces, especially if spaces or commas are used inside,
272 % a key name must not use spaces or other syntax characters.
273 %
274 % \cs{kv@normalize} takes a key value list and performs the cleanup:
275 % \begin{itemize}
276 % \item Spaces are removed.
277 % \item Syntax characters (comma and equal sign) that are active
278 % are replaced by the same characters with standard catcode.
279 % (Example: \xpackage{babel}'s language option \xoption{turkish}
280 % uses the equal sign as active shorthand character.)
281 % \end{itemize}
282 % The result is stored in \cs{kv@list}, e.g.:
283 % \begin{quote}
284 % |\kv@list| $\rightarrow$ |,pdftitle={...},pdfsubject={...},...,|
285 % \end{quote}
286 % Curly braces around values (or keys) remain untouched.
287 % \begin{description}
288 % \item[v1.3+:]
289 % One comma is added in front of the list and each pair ends with
290 % a comma. Thus an empty list consists of one comma, otherwise
291 % two commas encloses the list. Empty entries other than the first
292 % are removed.
293 % \item[v1.0 -- v1.2:]
294 % Empty entries are removed later. In fact it adds a comma at the begin
295 % and end to protect the last value and an easier implementation.
296 % \end{description}
297 %
298 % \subsection{Parsing key value lists}
299 %
300 % \begin{declcs}{kv@parse}\,\M{key value list}\,\M{processor}
301 % \end{declcs}
302 % It is easier to parse a normalized list, thus \cs{kv@parse}
303 % normalizes the list and calls \cs{kv@parse@normalized}.
304 %
305 % \begin{declcs}{kv@parse@normalized}\,\M{key value list}%
306 % \,\M{processor}
307 % \end{declcs}
308 % Now the key value list is split into single key value pairs.
309 % For further processing the key and value are given as arguments
310 % for the \meta{processor}:
311 % \begin{quote}
312 % \meta{processor}\,\M{key}\,\M{value}
313 % \end{quote}
314 % Also key and value are stored in macro names:
315 % \begin{itemize}
316 % \item \cs{kv@key} stores the key.
317 % \item \cs{kv@value} stores the value or if the value was not
318 % specified it has the meaning \cs{relax}.
319 % \end{itemize}
320 % The behaviour in pseudo code:
321 % \begin{quote}
322 % foreach (\meta{key}, \meta{value}) in (\meta{key value list})\\
323 % \hspace*{1.5em}\cs{kv@key} := \meta{key}\\
324 % \hspace*{1.5em}\cs{kv@value} := \meta{value}\\
325 % \hspace*{1.5em}\meta{processor}\,\M{key}\,\M{value}
326 % \end{quote}
327 %
328 % \begin{declcs}{kv@break}
329 % \end{declcs}
330 % Since version 2011/03/03 v1.11 \cs{kv@break} can be
331 % called inside the \meta{processor}
332 % of \cs{kv@parse} or \cs{kv@parse@normalized}, then
333 % the processing is stopped and the following entries discarded.
334 %
335 % \subsection{Processing key value pairs}
336 %
337 % Key value pairs can be processed in many different ways.
338 % For example, the processor for \cs{kvsetkeys} works similar
339 % to \cs{setkeys} of package \xpackage{keyval}. There unknown
340 % keys raise an error.
341 %
342 % Package \xpackage{xkeyval} also knows a star form of \cs{setkeys}
343 % that stores unknown keys in an internal macro for further processing
344 % with \cs{setrmkeys} and similar macros. This feature is covered
345 % by processor \cs{kv@processor@known}.
346 %
347 % \subsubsection{Processing similar to \xpackage{keyval}}
348 %
349 % \begin{declcs}{kv@processor@default}\,\M{family}\,\M{key}\,\M{value}
350 % \end{declcs}
351 % There are many possiblities to process key value pairs.
352 % \cs{kv@processor@default} is the processor used in \cs{kvsetkeys}.
353 % It reimplements and extends the behaviour of
354 % \xpackage{keyval}'s \cs{setkeys}.
355 % In case of unknown keys \cs{setkeys} raise an error.
356 % This processer, however, calls a handler instead, if it
357 % is provided by the family. Both \meta{family} and \meta{key}
358 % may contain package \xpackage{babel}'s shorthands
359 % (since 2011/04/07 v1.13).
360 %
361 % Since 2011/10/18 v1.15 the family handler can reject the
362 % successful handling of a key by calling \cs{kv@handled@false}.
363 %
364 % Since 2012/04/25 v1.16 \cs{kv@processor@default} also defines
365 % macro \cs{kv@fam} with meaning \meta{family} for convenience.
366 %
367 % \subsubsection{Processing similar to \cs{setkeys*} of package \xpackage{xkeyval}}
368 %
369 % \begin{declcs}{kv@processor@known}\,\M{family}\,^^A
370 % \M{cmd}\,\M{key}\,\M{value}
371 % \end{declcs}
372 % The key value processor \cs{kv@processor@known} behaves similar
373 % to \cs{kv@processor@default}. If the \meta{key} exists in the
374 % \meta{family} its code is called, otherwise the family handler
375 % is tried. If the family handler is not set or cannot handle the
376 % key, the unknown key value pair is added to the macro \meta{cmd}.
377 % Since 2011/10/18 v1.15.
378 %
379 % The behaviour in pseudo code:
380 % \begin{quote}
381 % if \meta{key} exists\\
382 % \hspace*{1.5em}call the keyval code of \meta{key}\\
383 % else\\
384 % \hspace*{1.5em}if \meta{handler} for \meta{family} exists\\
385 % \hspace*{3em}handled = true\\
386 % \hspace*{3em}\meta{handler}\,\M{key}\,\M{value}\\
387 % \hspace*{3em}if handled\\
388 % \hspace*{3em}else\\
389 % \hspace*{4.5em}add \texttt{"}\M{key}\texttt{=}\M{value}\texttt{"}
390 % to \M{cmd}\\
391 % \hspace*{3em}fi\\
392 % \hspace*{1.5em}else\\
393 % \hspace*{3em}add \texttt{"}\M{key}\texttt{=}\M{value}\texttt{"}
394 % to \M{cmd}\\
395 % \hspace*{3em}raise unknown key error\\
396 % \hspace*{1.5em}fi\\
397 % fi
398 % \end{quote}
399 %
400 % Since 2012/04/25 v1.16 \cs{kv@processor@known} also defines
401 % macro \cs{kv@fam} with meaning \meta{family} for convenience.
402 %
403 % \subsection{Default family handler}
404 %
405 % \cs{kv@processor@default} calls \meta{handler}, the default
406 % handler for the family, if the key does not exist in the family.
407 % The handler is called with two arguments, the key and the value.
408 % It can be defined with \cs{kv@set@family@hander}:
409 %
410 % \begin{declcs}{kv@set@family@handler}\,\M{family}\,\M{handler definition}
411 % \end{declcs}
412 % This sets the default family handler for the keyval family
413 % \meta{family}. Inside \meta{handler definition} |#1| stands for
414 % the key and |#2| is the value. Also \cs{kv@key} and \cs{kv@value}
415 % can be used for the key and the value. If the value is not given,
416 % \cs{kv@value} has the meaning \cs{relax}.
417 %
418 % \begin{declcs}{kv@unset@family@handler}\,\M{family}
419 % \end{declcs}
420 % It removes the family handler for \meta{family}.
421 % Since 2011/10/18 v1.15.
422 %
423 % \subsection{Put it all together}
424 %
425 % \begin{declcs}{kvsetkeys}\,\M{family}\,\M{key value list}
426 % \end{declcs}
427 % Macro \cs{kvsetkeys} processes the \meta{key value list} with
428 % the standard processor \cs{kv@processor@default}:
429 % \begin{quote}
430 % \cs{kv@parse}\,\M{key value list}^^A
431 % \texttt{\{}\cs{kv@processor@default}\,\M{family}\texttt{\}}
432 % \end{quote}
433 %
434 % \begin{declcs}{kvsetknownkeys}\,\M{family}\,\M{cmd}\,\M{key value list}
435 % \end{declcs}
436 % Macro \cs{kvsetknownkeys} processes the \meta{key value list}
437 % with processor \cs{kv@processor@known}. All key value pairs
438 % with keys that are not known in \meta{family} are stored
439 % in macro \meta{cmd}. A previous contents of macro \meta{cmd}
440 % will be overwritten. If all keys can be handled, \meta{cmd}
441 % will be empty, otherwise it contains a key value list of
442 % unhandled key value pairs.
443 % Since 2011/10/18 v1.15.
444 %
445 % Pseudo code:
446 % \begin{quote}
447 % create macro \meta{cmdaux} with unique name (inside the current group)\\
448 % \cs{def}\meta{cmdaux}\{\}\\
449 % \cs{kv@parse}\,\M{key value list}^^A
450 % \texttt{\{}\cs{kv@processor@known}\,\M{family}\,\M{cmdaux}\texttt{\}}\\
451 % \cs{let}\meta{cmd}=\meta{cmdaux}
452 % \end{quote}
453 %
454 % \begin{declcs}{kvsetkeys@expandafter}\,\M{family}\,\M{list cmd}\\
455 % \cs{kvsetknownkeys@expandafter}\,\M{family}\,%
456 % \M{cmd}\,\M{list cmd}
457 % \end{declcs}
458 % Both macros behave like the counterparts without suffix
459 % |@expandafter|. The difference is that the key value list is
460 % given as macro that is expanded once.
461 % Since 2011/10/18 v1.15.
462 %
463 % Thus you can replace \cs{setkeys} of package \xpackage{keyval}
464 % by the key value parser of this package:
465 % \begin{quote}
466 % |\renewcommand*{\setkeys}{\kvsetkeys}|\\
467 % or\\
468 % |\let\setkeys\kvsetkeys|
469 % \end{quote}
470 %
471 % \subsection{Comma separated lists}
472 %
473 % Since version 2007/09/29 v1.3 this package also supports the normalizing
474 % and parsing of general comma separated lists.
475 %
476 % \begin{declcs}{comma@normalize}\,\M{comma list}
477 % \end{declcs}
478 % Macro \cs{comma@normalize} normalizes the comma separated list,
479 % removes spaces around commas. The result is put in macro \cs{comma@list}.
480 %
481 % \begin{declcs}{comma@parse}\,\M{comma list}\,\M{processor}
482 % \end{declcs}
483 % Macro \cs{comma@parse} first normalizes the comma separated list
484 % and then parses the list by calling \cs{comma@parse@normalized}.
485 %
486 % \begin{declcs}{comma@parse@normalized}\,\M{normalized comma list}^^A
487 % \,\M{processor}
488 % \end{declcs}
489 % The list is parsed. Empty entries are ignored. \meta{processor}
490 % is called for each non-empty entry with the entry as argument:
491 % \begin{quote}
492 % \meta{processor}|{|\meta{entry}|}|
493 % \end{quote}
494 % Also the entry is stored in the macro \cs{comma@entry}.
495 %
496 % \begin{declcs}{comma@break}
497 % \end{declcs}
498 % Since version 2011/03/03 v1.11 \cs{comma@break} can be
499 % called inside the \meta{processor}
500 % of \cs{comma@parse} or \cs{comma@parse@normalized}, then
501 % the processing is stopped and the following entries discarded.
502 %
503 % \section{Example}
504 %
505 % The following example prints a short piece of HTML code using
506 % the tabbing environment for indenting purpose and a key value
507 % syntax for specifying the attributes of an HTML tag.
508 % The example illustrates the use of a default family handler.
509 % \begin{macrocode}
510 %<*example>
511 \documentclass{article}
512 \usepackage[T1]{fontenc}
513 \usepackage{kvsetkeys}
514 \usepackage{keyval}
515
516 \makeatletter
517 \newcommand*{\tag}[2][]{%
518 % #1: attributes
519 % #2: tag name
520 \begingroup
521 \toks@={}%
522 \let\@endslash\@empty
523 \kvsetkeys{tag}{#1}%
524 \texttt{%
525 \textless #2\the\toks@\@endslash\textgreater
526 }%
527 \endgroup
528 }
529 \kv@set@family@handler{tag}{%
530 % #1: key
531 % #2: value
532 \toks@\expandafter{%
533 \the\toks@
534 \space
535 #1=\string"#2\string"%
536 }%
537 }
538 \define@key{tag}{/}[]{%
539 \def\@endslash{/}%
540 }
541 \makeatother
542
543 \begin{document}
544 \begin{tabbing}
545 \mbox{}\qquad\=\qquad\=\kill
546 \tag{html}\\
547 \>\dots\\
548 \>\tag[border=1]{table}\\
549 \>\>\tag[width=200, span=3, /]{colgroup}\\
550 \>\>\dots\\
551 \>\tag{/table}\\
552 \>\dots\\
553 \tag{/html}\\
554 \end{tabbing}
555 \end{document}
556 %</example>
557 % \end{macrocode}
558 %
559 % \StopEventually{
560 % }
561 %
562 % \section{Implementation}
563 %
564 % \subsection{Identification}
565 %
566 % \begin{macrocode}
567 %<*package>
568 % \end{macrocode}
569 % Reload check, especially if the package is not used with \LaTeX.
570 % \begin{macrocode}
571 \begingroup\catcode61\catcode48\catcode32=10\relax%
572 \catcode13=5 % ^^M
573 \endlinechar=13 %
574 \catcode35=6 % #
575 \catcode39=12 % '
576 \catcode44=12 % ,
577 \catcode45=12 % -
578 \catcode46=12 % .
579 \catcode58=12 % :
580 \catcode64=11 % @
581 \catcode123=1 % {
582 \catcode125=2 % }
583 \expandafter\let\expandafter\x\csname [email protected]\endcsname
584 \ifx\x\relax % plain-TeX, first loading
585 \else
586 \def\empty{}%
587 \ifx\x\empty % LaTeX, first loading,
588 % variable is initialized, but \ProvidesPackage not yet seen
589 \else
590 \expandafter\ifx\csname PackageInfo\endcsname\relax
591 \def\x#1#2{%
592 \immediate\write-1{Package #1 Info: #2.}%
593 }%
594 \else
595 \def\x#1#2{\PackageInfo{#1}{#2, stopped}}%
596 \fi
597 \x{kvsetkeys}{The package is already loaded}%
598 \aftergroup\endinput
599 \fi
600 \fi
601 \endgroup%
602 % \end{macrocode}
603 % Package identification:
604 % \begin{macrocode}
605 \begingroup\catcode61\catcode48\catcode32=10\relax%
606 \catcode13=5 % ^^M
607 \endlinechar=13 %
608 \catcode35=6 % #
609 \catcode39=12 % '
610 \catcode40=12 % (
611 \catcode41=12 % )
612 \catcode44=12 % ,
613 \catcode45=12 % -
614 \catcode46=12 % .
615 \catcode47=12 % /
616 \catcode58=12 % :
617 \catcode64=11 % @
618 \catcode91=12 % [
619 \catcode93=12 % ]
620 \catcode123=1 % {
621 \catcode125=2 % }
622 \expandafter\ifx\csname ProvidesPackage\endcsname\relax
623 \def\x#1#2#3[#4]{\endgroup
624 \immediate\write-1{Package: #3 #4}%
625 \xdef#1{#4}%
626 }%
627 \else
628 \def\x#1#2[#3]{\endgroup
629 #2[{#3}]%
630 \ifx#1\@undefined
631 \xdef#1{#3}%
632 \fi
633 \ifx#1\relax
634 \xdef#1{#3}%
635 \fi
636 }%
637 \fi
638 \expandafter\x\csname [email protected]\endcsname
639 \ProvidesPackage{kvsetkeys}%
640 [2022-10-05 v1.19 Key value parser (HO)]%
641 % \end{macrocode}
642 %
643 % \begin{macrocode}
644 \begingroup\catcode61\catcode48\catcode32=10\relax%
645 \catcode13=5 % ^^M
646 \endlinechar=13 %
647 \catcode123=1 % {
648 \catcode125=2 % }
649 \catcode64=11 % @
650 \def\x{\endgroup
651 \expandafter\edef\csname KVS@AtEnd\endcsname{%
652 \endlinechar=\the\endlinechar\relax
653 \catcode13=\the\catcode13\relax
654 \catcode32=\the\catcode32\relax
655 \catcode35=\the\catcode35\relax
656 \catcode61=\the\catcode61\relax
657 \catcode64=\the\catcode64\relax
658 \catcode123=\the\catcode123\relax
659 \catcode125=\the\catcode125\relax
660 }%
661 }%
662 \x\catcode61\catcode48\catcode32=10\relax%
663 \catcode13=5 % ^^M
664 \endlinechar=13 %
665 \catcode35=6 % #
666 \catcode64=11 % @
667 \catcode123=1 % {
668 \catcode125=2 % }
669 \def\TMP@EnsureCode#1#2{%
670 \edef\KVS@AtEnd{%
671 \KVS@AtEnd
672 \catcode#1=\the\catcode#1\relax
673 }%
674 \catcode#1=#2\relax
675 }
676 \TMP@EnsureCode{36}{3}% $
677 \TMP@EnsureCode{38}{4}% &
678 \TMP@EnsureCode{39}{12}% '
679 \TMP@EnsureCode{43}{12}% +
680 \TMP@EnsureCode{44}{12}% ,
681 \TMP@EnsureCode{45}{12}% -
682 \TMP@EnsureCode{46}{12}% .
683 \TMP@EnsureCode{47}{12}% /
684 \TMP@EnsureCode{91}{12}% [
685 \TMP@EnsureCode{93}{12}% ]
686 \TMP@EnsureCode{94}{7}% ^ (superscript)
687 \TMP@EnsureCode{96}{12}% `
688 \TMP@EnsureCode{126}{13}% ~ (active)
689 \edef\KVS@AtEnd{\KVS@AtEnd\noexpand\endinput}
690 % \end{macrocode}
691 %
692 % \subsection{Package loading}
693 %
694 % \begin{macrocode}
695 \begingroup\expandafter\expandafter\expandafter\endgroup
696 \expandafter\ifx\csname RequirePackage\endcsname\relax
697 \def\TMP@RequirePackage#1[#2]{%
698 \begingroup\expandafter\expandafter\expandafter\endgroup
699 \expandafter\ifx\csname ver@#1.sty\endcsname\relax
700 \input #1.sty\relax
701 \fi
702 }%
703 \TMP@RequirePackage{infwarerr}[2007/09/09]%
704 \let\PackageError\@PackageError
705 \else
706 \fi
707 % \end{macrocode}
708 %
709 % \begin{macrocode}
710 \expandafter\ifx\csname toks@\endcsname\relax
711 \toksdef\toks@=0 %
712 \fi
713 % \end{macrocode}
714 %
715 % \subsection{Check for \eTeX}
716 %
717 % \cs{unexpanded}, \cs{ifcsname}, and \cs{unless} are used if found.
718 % \begin{macrocode}
719 \ifx\numexpr\@undefined
720 \catcode`\$=9 % ignore
721 \catcode`\&=14 % comment
722 \else % e-TeX
723 \catcode`\$=14 % comment
724 \catcode`\&=9 % ignore
725 \fi
726 % \end{macrocode}
727 %
728 % \subsection{Generic help macros}
729 %
730 % \begin{macro}{\KVS@Empty}
731 % \begin{macrocode}
732 \def\KVS@Empty{}
733 % \end{macrocode}
734 % \end{macro}
735 % \begin{macro}{\KVS@FirstOfTwo}
736 % \begin{macrocode}
737 \long\def\KVS@FirstOfTwo#1#2{#1}
738 % \end{macrocode}
739 % \end{macro}
740 % \begin{macro}{\KVS@SecondOfTwo}
741 % \begin{macrocode}
742 \long\def\KVS@SecondOfTwo#1#2{#2}
743 % \end{macrocode}
744 % \end{macro}
745 %
746 % \begin{macro}{\KVS@IfEmpty}
747 % \begin{macrocode}
748 \long\def\KVS@IfEmpty#1{%
749 & \edef\KVS@Temp{\unexpanded{#1}}%
750 $ \begingroup
751 $ \toks@{#1}%
752 $ \edef\KVS@Temp{\the\toks@}%
753 $ \expandafter\endgroup
754 \ifx\KVS@Temp\KVS@Empty
755 \expandafter\KVS@FirstOfTwo
756 \else
757 \expandafter\KVS@SecondOfTwo
758 \fi
759 }
760 % \end{macrocode}
761 % \end{macro}
762 %
763 % \subsection{Normalizing}
764 %
765 % \begin{macro}{\kv@normalize}
766 % \begin{macrocode}
767 \long\def\kv@normalize#1{%
768 \begingroup
769 \toks@{,#1,}%
770 \KVS@Comma
771 \KVS@SpaceComma
772 \KVS@CommaSpace
773 \KVS@CommaComma
774 \KVS@Equals
775 \KVS@SpaceEquals
776 \KVS@EqualsSpace
777 \xdef\KVS@Global{\the\toks@}%
778 \endgroup
779 \let\kv@list\KVS@Global
780 }
781 % \end{macrocode}
782 % \end{macro}
783 % \begin{macro}{\comma@normalize}
784 % \begin{macrocode}
785 \def\comma@normalize#1{%
786 \begingroup
787 \toks@{,#1,}%
788 \KVS@Comma
789 \KVS@SpaceComma
790 \KVS@CommaSpace
791 \KVS@CommaComma
792 \xdef\KVS@Global{\the\toks@}%
793 \endgroup
794 \let\comma@list\KVS@Global
795 }
796 % \end{macrocode}
797 % \end{macro}
798 % \begin{macro}{\KVS@Comma}
799 % Converts active commas into comma with catcode other.
800 % Also adds a comma at the end to protect the last value
801 % for next cleanup steps.
802 % \begin{macrocode}
803 \begingroup
804 \lccode`\,=`\,%
805 \lccode`\~=`\,%
806 \lowercase{\endgroup
807 \def\KVS@Comma{%
808 \toks@\expandafter{\expandafter}\expandafter
809 \KVS@@Comma\the\toks@~\KVS@Nil
810 }%
811 \long\def\KVS@@Comma#1~#2\KVS@Nil{%
812 \toks@\expandafter{\the\toks@#1}%
813 \KVS@IfEmpty{#2}{%
814 }{%
815 \KVS@@Comma,#2\KVS@Nil
816 }%
817 }%
818 }
819 % \end{macrocode}
820 % \end{macro}
821 % \begin{macro}{\KVS@SpaceComma}
822 % Removes spaces before the comma, may add commas at the end.
823 % \begin{macrocode}
824 \def\KVS@SpaceComma#1{%
825 \def\KVS@SpaceComma{%
826 \expandafter\KVS@@SpaceComma\the\toks@#1,\KVS@Nil
827 }%
828 }
829 \KVS@SpaceComma{ }
830 % \end{macrocode}
831 % \end{macro}
832 % \begin{macro}{\KVS@@SpaceComma}
833 % \begin{macrocode}
834 \long\def\KVS@@SpaceComma#1 ,#2\KVS@Nil{%
835 \KVS@IfEmpty{#2}{%
836 \toks@{#1}%
837 }{%
838 \KVS@@SpaceComma#1,#2\KVS@Nil
839 }%
840 }
841 % \end{macrocode}
842 % \end{macro}
843 % \begin{macro}{\KVS@CommaSpace}
844 % Removes spaces after the comma, may add commas at the end.
845 % \begin{macrocode}
846 \def\KVS@CommaSpace{%
847 \expandafter\KVS@@CommaSpace\the\toks@, \KVS@Nil
848 }
849 % \end{macrocode}
850 % \end{macro}
851 % \begin{macro}{\KVS@@CommaSpace}
852 % \begin{macrocode}
853 \long\def\KVS@@CommaSpace#1, #2\KVS@Nil{%
854 \KVS@IfEmpty{#2}{%
855 \toks@{#1}%
856 }{%
857 \KVS@@CommaSpace#1,#2\KVS@Nil
858 }%
859 }
860 % \end{macrocode}
861 % \end{macro}
862 % \begin{macro}{\KVS@CommaComma}
863 % Replaces multiple commas by one comma.
864 % \begin{macrocode}
865 \def\KVS@CommaComma{%
866 \expandafter\KVS@@CommaComma\the\toks@,\KVS@Nil
867 }
868 % \end{macrocode}
869 % \end{macro}
870 % \begin{macro}{\KVS@@CommaComma}
871 % \begin{macrocode}
872 \long\def\KVS@@CommaComma#1,,#2\KVS@Nil{%
873 \KVS@IfEmpty{#2}{%
874 \toks@{#1,}% (!)
875 }{%
876 \KVS@@CommaComma#1,#2\KVS@Nil
877 }%
878 }
879 % \end{macrocode}
880 % \end{macro}
881 %
882 % \begin{macro}{\KVS@Equals}
883 % Converts active equals signs into catcode other characters.
884 % \begin{macrocode}
885 \begingroup
886 \lccode`\==`\=%
887 \lccode`\~=`\=%
888 \lowercase{\endgroup
889 \def\KVS@Equals{%
890 \toks@\expandafter{\expandafter}\expandafter
891 \KVS@@Equals\the\toks@~\KVS@Nil
892 }%
893 \long\def\KVS@@Equals#1~#2\KVS@Nil{%
894 \edef\KVS@Temp{\the\toks@}%
895 \ifx\KVS@Temp\KVS@Empty
896 \expandafter\KVS@FirstOfTwo
897 \else
898 \expandafter\KVS@SecondOfTwo
899 \fi
900 {%
901 \toks@{#1}%
902 }{%
903 \toks@\expandafter{\the\toks@=#1}%
904 }%
905 \KVS@IfEmpty{#2}{%
906 }{%
907 \KVS@@Equals#2\KVS@Nil
908 }%
909 }%
910 }
911 % \end{macrocode}
912 % \end{macro}
913 % \begin{macro}{\KVS@SpaceEquals}
914 % Removes spaces before the equals sign.
915 % \begin{macrocode}
916 \def\KVS@SpaceEquals#1{%
917 \def\KVS@SpaceEquals{%
918 \expandafter\KVS@@SpaceEquals\the\toks@#1=\KVS@Nil
919 }%
920 }
921 \KVS@SpaceEquals{ }
922 % \end{macrocode}
923 % \end{macro}
924 % \begin{macro}{\KVS@@SpaceEquals}
925 % \begin{macrocode}
926 \long\def\KVS@@SpaceEquals#1 =#2\KVS@Nil{%
927 \KVS@IfEmpty{#2}{%
928 \toks@{#1}%
929 }{%
930 \KVS@@SpaceEquals#1=#2\KVS@Nil
931 }%
932 }
933 % \end{macrocode}
934 % \end{macro}
935 % \begin{macro}{\KVS@EqualsSpace}
936 % Removes spaces after the equals sign.
937 % \begin{macrocode}
938 \def\KVS@EqualsSpace{%
939 \expandafter\KVS@@EqualsSpace\the\toks@= \KVS@Nil
940 }
941 % \end{macrocode}
942 % \end{macro}
943 % \begin{macro}{\KVS@@EqualsSpace}
944 % \begin{macrocode}
945 \long\def\KVS@@EqualsSpace#1= #2\KVS@Nil{%
946 \KVS@IfEmpty{#2}{%
947 \toks@{#1}%
948 }{%
949 \KVS@@EqualsSpace#1=#2\KVS@Nil
950 }%
951 }
952 % \end{macrocode}
953 % \end{macro}
954 %
955 % \subsection{Parsing key value lists}
956 %
957 % \begin{macro}{\kv@parse}
958 % Normalizes and parses the key value list. Also sets \cs{kv@list}.
959 % \begin{macrocode}
960 \long\def\kv@parse#1{%
961 \kv@normalize{#1}%
962 \expandafter\kv@parse@normalized\expandafter{\kv@list}%
963 }
964 % \end{macrocode}
965 % \end{macro}
966 % \begin{macro}{\kv@parse@normalized}
967 % |#1|: key value list\\
968 % |#2|: processor
969 % \begin{macrocode}
970 \long\def\kv@parse@normalized#1#2{%
971 \KVS@Parse#1,\KVS@Nil{#2}%
972 }
973 % \end{macrocode}
974 % \end{macro}
975 % \begin{macro}{\KVS@Parse}
976 % |#1,#2|: key value list\\
977 % |#3|: processor
978 % \begin{macrocode}
979 \long\def\KVS@Parse#1,#2\KVS@Nil#3{%
980 \KVS@IfEmpty{#1}{%
981 }{%
982 \KVS@Process#1=\KVS@Nil{#3}%
983 }%
984 \KVS@MaybeBreak
985 \KVS@IfEmpty{#2}{%
986 }{%
987 \KVS@Parse#2\KVS@Nil{#3}%
988 }%
989 }
990 % \end{macrocode}
991 % \end{macro}
992 % \begin{macro}{\KVS@Process}
993 % |#1|: key\\
994 % |#2|: value, |=|\\
995 % |#3|: processor
996 % \begin{macrocode}
997 \long\def\KVS@Process#1=#2\KVS@Nil#3{%
998 \let\KVS@MaybeBreak\relax
999 \def\kv@key{#1}%
1000 \KVS@IfEmpty{#2}{%
1001 \let\kv@value\relax
1002 #3{#1}{}%
1003 }{%
1004 \KVS@@Process{#1}#2\KVS@Nil{#3}%
1005 }%
1006 }
1007 % \end{macrocode}
1008 % \end{macro}
1009 % \begin{macro}{\KVS@@Process}
1010 % |#1|: key\\
1011 % |#2|: value\\
1012 % |#3|: processor
1013 % \begin{macrocode}
1014 \long\def\KVS@@Process#1#2=\KVS@Nil#3{%
1015 & \edef\kv@value{\unexpanded{#2}}%
1016 $ \begingroup
1017 $ \toks@{#2}%
1018 $ \xdef\KVS@Global{\the\toks@}%
1019 $ \endgroup
1020 $ \let\kv@value\KVS@Global
1021 #3{#1}{#2}%
1022 }
1023 % \end{macrocode}
1024 % \end{macro}
1025 % \begin{macro}{\KVS@MaybeBreak}
1026 % \begin{macrocode}
1027 \let\KVS@MaybeBreak\relax
1028 % \end{macrocode}
1029 % \end{macro}
1030 % \begin{macro}{\KVS@break}
1031 % \begin{macrocode}
1032 \def\KVS@break#1#2#3#4{%
1033 \let\KVS@MaybeBreak\relax
1034 }
1035 % \end{macrocode}
1036 % \end{macro}
1037 % \begin{macro}{\kv@break}
1038 % \begin{macrocode}
1039 \def\kv@break{%
1040 \let\KVS@MaybeBreak\KVS@break
1041 }
1042 % \end{macrocode}
1043 % \end{macro}
1044 %
1045 % \subsection{Parsing comma lists}
1046 %
1047 % \begin{macro}{\comma@parse}
1048 % Normalizes and parses the key value list. Also sets \cs{comma@list}.
1049 % \begin{macrocode}
1050 \def\comma@parse#1{%
1051 \comma@normalize{#1}%
1052 \expandafter\comma@parse@normalized\expandafter{\comma@list}%
1053 }
1054 % \end{macrocode}
1055 % \end{macro}
1056 %
1057 % \begin{macro}{\comma@parse@normalized}
1058 % |#1|: comma list\\
1059 % |#2|: processor
1060 % \begin{macrocode}
1061 \def\comma@parse@normalized#1#2{%
1062 \KVS@CommaParse#1,\KVS@Nil{#2}%
1063 }
1064 % \end{macrocode}
1065 % \end{macro}
1066 % \begin{macro}{\KVS@CommaParse}
1067 % |#1,#2|: comma list\\
1068 % |#3|: processor
1069 % \begin{macrocode}
1070 \def\KVS@CommaParse#1,#2\KVS@Nil#3{%
1071 \KVS@IfEmpty{#1}{%
1072 }{%
1073 \def\comma@entry{#1}%
1074 #3{#1}%
1075 }%
1076 \KVS@MaybeBreak
1077 \KVS@IfEmpty{#2}{%
1078 }{%
1079 \KVS@CommaParse#2\KVS@Nil{#3}%
1080 }%
1081 }
1082 % \end{macrocode}
1083 % \end{macro}
1084 % \begin{macro}{\comma@break}
1085 % \begin{macrocode}
1086 \def\comma@break{%
1087 \let\KVS@MaybeBreak\KVS@break
1088 }
1089 % \end{macrocode}
1090 % \end{macro}
1091 %
1092 % \subsection{Processing key value pairs}
1093 %
1094 % \begin{macro}{\kv@handled@false}
1095 % The handler can call \cs{kv@handled@false} or
1096 % \cs{kv@handled@true} so report failure or success.
1097 % The default is success (compatibility for versions
1098 % before 2011/10/18 v1.15).
1099 % \begin{macrocode}
1100 \def\kv@handled@false{%
1101 \let\ifkv@handled@\iffalse
1102 }
1103 % \end{macrocode}
1104 % \end{macro}
1105 % \begin{macro}{\kv@handled@true}
1106 % \begin{macrocode}
1107 \def\kv@handled@true{%
1108 \let\ifkv@handled@\iftrue
1109 }
1110 % \end{macrocode}
1111 % \end{macro}
1112 % \begin{macro}{\ifkv@handled@}
1113 % \begin{macrocode}
1114 \kv@handled@true
1115 % \end{macrocode}
1116 % \end{macro}
1117 %
1118 % \begin{macro}{\kv@processor@default}
1119 % \begin{macrocode}
1120 \def\kv@processor@default#1#2{%
1121 \begingroup
1122 \csname @safe@activestrue\endcsname
1123 \let\ifincsname\iftrue
1124 \edef\KVS@temp{\endgroup
1125 \noexpand\KVS@ProcessorDefault{#1}{#2}%
1126 }%
1127 \KVS@temp
1128 }
1129 % \end{macrocode}
1130 % \end{macro}
1131 % \begin{macro}{\KVS@ProcessorDefault}
1132 % \begin{macrocode}
1133 \long\def\KVS@ProcessorDefault#1#2#3{%
1134 \def\kv@fam{#1}%
1135 & \unless\ifcsname KV@#1@#2\endcsname
1136 $ \begingroup\expandafter\expandafter\expandafter\endgroup
1137 $ \expandafter\ifx\csname KV@#1@#2\endcsname\relax
1138 & \unless\ifcsname KVS@#1@handler\endcsname
1139 $ \begingroup\expandafter\expandafter\expandafter\endgroup
1140 $ \expandafter\ifx\csname KVS@#1@handler\endcsname\relax
1141 \kv@error@unknownkey{#1}{#2}%
1142 \else
1143 \kv@handled@true
1144 \csname KVS@#1@handler\endcsname{#2}{#3}%
1145 \relax
1146 \ifkv@handled@
1147 \else
1148 \kv@error@unknownkey{#1}{#2}%
1149 \fi
1150 \fi
1151 \else
1152 \ifx\kv@value\relax
1153 & \unless\ifcsname KV@#1@#2@default\endcsname
1154 $ \begingroup\expandafter\expandafter\expandafter\endgroup
1155 $ \expandafter\ifx\csname KV@#1@#2@default\endcsname\relax
1156 \kv@error@novalue{#1}{#2}%
1157 \else
1158 \csname KV@#1@#2@default\endcsname
1159 \relax
1160 \fi
1161 \else
1162 \csname KV@#1@#2\endcsname{#3}%
1163 \fi
1164 \fi
1165 }
1166 % \end{macrocode}
1167 % \end{macro}
1168 %
1169 % \begin{macro}{\kv@processor@known}
1170 % \begin{macrocode}
1171 \def\kv@processor@known#1#2#3{%
1172 \begingroup
1173 \csname @safe@activestrue\endcsname
1174 \let\ifincsname\iftrue
1175 \edef\KVS@temp{\endgroup
1176 \noexpand\KVS@ProcessorKnown{#1}\noexpand#2{#3}%
1177 }%
1178 \KVS@temp
1179 }
1180 % \end{macrocode}
1181 % \end{macro}
1182 % \begin{macro}{\KVS@ProcessorKnown}
1183 % \begin{macrocode}
1184 \long\def\KVS@ProcessorKnown#1#2#3#4{%
1185 \def\kv@fam{#1}%
1186 & \unless\ifcsname KV@#1@#3\endcsname
1187 $ \begingroup\expandafter\expandafter\expandafter\endgroup
1188 $ \expandafter\ifx\csname KV@#1@#3\endcsname\relax
1189 & \unless\ifcsname KVS@#1@handler\endcsname
1190 $ \begingroup\expandafter\expandafter\expandafter\endgroup
1191 $ \expandafter\ifx\csname KVS@#1@handler\endcsname\relax
1192 \KVS@AddUnhandled#2{#3}{#4}%
1193 \else
1194 \kv@handled@true
1195 \csname KVS@#1@handler\endcsname{#3}{#4}%
1196 \relax
1197 \ifkv@handled@
1198 \else
1199 \KVS@AddUnhandled#2{#3}{#4}%
1200 \fi
1201 \fi
1202 \else
1203 \ifx\kv@value\relax
1204 & \unless\ifcsname KV@#1@#2@default\endcsname
1205 $ \begingroup\expandafter\expandafter\expandafter\endgroup
1206 $ \expandafter\ifx\csname KV@#1@#3@default\endcsname\relax
1207 \kv@error@novalue{#1}{#3}%
1208 \else
1209 \csname KV@#1@#3@default\endcsname
1210 \relax
1211 \fi
1212 \else
1213 \csname KV@#1@#3\endcsname{#4}%
1214 \fi
1215 \fi
1216 }
1217 % \end{macrocode}
1218 % \end{macro}
1219 % \begin{macro}{\KVS@AddUnhandled}
1220 % \begin{macrocode}
1221 \long\def\KVS@AddUnhandled#1#2#3{%
1222 & \edef#1{%
1223 & \ifx#1\KVS@empty
1224 & \else
1225 & \unexpanded\expandafter{#1},%
1226 & \fi
1227 & \unexpanded{{#2}={#3}}%
1228 & }%
1229 $ \begingroup
1230 $ \ifx#1\KVS@empty
1231 $ \toks@{{#2}={#3}}%
1232 $ \else
1233 $ \toks@\expandafter{#1,{#2}={#3}}%
1234 $ \fi
1235 $ \xdef\KVS@Global{\the\toks@}%
1236 $ \endgroup
1237 $ \let#1\KVS@Global
1238 }
1239 % \end{macrocode}
1240 % \end{macro}
1241 %
1242 % \begin{macro}{\kv@set@family@handler}
1243 % \begin{macrocode}
1244 \long\def\kv@set@family@handler#1#2{%
1245 \begingroup
1246 \csname @safe@activestrue\endcsname
1247 \let\ifincsname\iftrue
1248 \expandafter\endgroup
1249 \expandafter\def\csname KVS@#1@handler\endcsname##1##2{#2}%
1250 }
1251 % \end{macrocode}
1252 % \end{macro}
1253 %
1254 % \begin{macro}{\kv@unset@family@handler}
1255 % \begin{macrocode}
1256 \long\def\kv@unset@family@handler#1#2{%
1257 \begingroup
1258 \csname @safe@activestrue\endcsname
1259 \let\ifincsname\iftrue
1260 \expandafter\endgroup
1261 \expandafter\let\csname KVS@#1@handler\endcsname\@UnDeFiNeD
1262 }
1263 % \end{macrocode}
1264 % \end{macro}
1265 %
1266 % \subsection{Error handling}
1267 %
1268 % \begin{macro}{\kv@error@novalue}
1269 % \begin{macrocode}
1270 \def\kv@error@novalue{%
1271 \kv@error@generic{No value specified for}%
1272 }
1273 % \end{macrocode}
1274 % \end{macro}
1275 % \begin{macro}{\kv@error@unknownkey}
1276 % \begin{macrocode}
1277 \def\kv@error@unknownkey{%
1278 \kv@error@generic{Undefined}%
1279 }
1280 % \end{macrocode}
1281 % \end{macro}
1282 % \begin{macro}{\kv@error@generic}
1283 % \begin{macrocode}
1284 \def\kv@error@generic#1#2#3{%
1285 \PackageError{kvsetkeys}{%
1286 #1 key `#3'%
1287 }{%
1288 The keyval family of the key `#3' is `#2'.\MessageBreak
1289 The setting of the key is ignored because of the error.\MessageBreak
1290 \MessageBreak
1291 \@ehc
1292 }%
1293 }
1294 % \end{macrocode}
1295 % \end{macro}
1296 %
1297 % \subsection{Do it all}
1298 %
1299 % \begin{macro}{\kvsetkeys}
1300 % \begin{macrocode}
1301 \long\def\kvsetkeys#1#2{%
1302 \kv@parse{#2}{\kv@processor@default{#1}}%
1303 }
1304 % \end{macrocode}
1305 % \end{macro}
1306 %
1307 % \begin{macro}{\kvsetkeys@expandafter}
1308 % \begin{macrocode}
1309 \def\kvsetkeys@expandafter#1#2{%
1310 \expandafter\kv@parse\expandafter{#2}{%
1311 \kv@processor@default{#1}%
1312 }%
1313 }
1314 % \end{macrocode}
1315 % \end{macro}
1316 %
1317 % \begin{macro}{\KVS@cmd}
1318 % \begin{macrocode}
1319 \def\KVS@cmd{0}%
1320 % \end{macrocode}
1321 % \end{macro}
1322 % \begin{macro}{\KVS@cmd@inc}
1323 % \begin{macrocode}
1324 \def\KVS@cmd@inc{%
1325 & \edef\KVS@cmd{\the\numexpr\KVS@cmd+1}%
1326 $ \begingroup
1327 $ \count255=\KVS@cmd\relax
1328 $ \advance\count255 by 1\relax
1329 $ \edef\x{\endgroup
1330 $ \noexpand\def\noexpand\KVS@cmd{\number\count255}%
1331 $ }%
1332 $ \x
1333 }
1334 % \end{macrocode}
1335 % \end{macro}
1336 % \begin{macro}{\KVS@cmd@dec}
1337 % \begin{macrocode}
1338 \def\KVS@cmd@dec{%
1339 & \edef\KVS@cmd{\the\numexpr\KVS@cmd-1}%
1340 $ \begingroup
1341 $ \count255=\KVS@cmd\relax
1342 $ \advance\count255 by -1\relax
1343 $ \edef\x{\endgroup
1344 $ \noexpand\def\noexpand\KVS@cmd{\number\count255}%
1345 $ }%
1346 $ \x
1347 }
1348 % \end{macrocode}
1349 % \end{macro}
1350 % \begin{macro}{\KVS@empty}
1351 % \begin{macrocode}
1352 \def\KVS@empty{}
1353 % \end{macrocode}
1354 % \end{macro}
1355 %
1356 % \begin{macro}{\kvsetknownkeys}
1357 % \begin{macrocode}
1358 \def\kvsetknownkeys{%
1359 \expandafter
1360 \KVS@setknownkeys\csname KVS@cmd\KVS@cmd\endcsname{}%
1361 }
1362 % \end{macrocode}
1363 % \end{macro}
1364 % \begin{macro}{\KVS@setknownkeys}
1365 % \begin{macrocode}
1366 \long\def\KVS@setknownkeys#1#2#3#4#5{%
1367 \let#1\KVS@empty
1368 \KVS@cmd@inc
1369 #2\kv@parse#2{#5}{\kv@processor@known{#3}#1}%
1370 \KVS@cmd@dec
1371 \let#4=#1%
1372 }
1373 % \end{macrocode}
1374 % \end{macro}
1375 %
1376 % \begin{macro}{\kvsetknownkeys@expandafter}
1377 % \begin{macrocode}
1378 \def\kvsetknownkeys@expandafter{%
1379 \expandafter
1380 \KVS@setknownkeys
1381 \csname KVS@cmd\KVS@cmd\endcsname\expandafter
1382 }
1383 % \end{macrocode}
1384 % \end{macro}
1385 %
1386 % \begin{macrocode}
1387 \KVS@AtEnd%
1388 %</package>
1389 % \end{macrocode}
1390 %% \section{Installation}
1391 %
1392 % \subsection{Download}
1393 %
1394 % \paragraph{Package.} This package is available on
1395 % CTAN\footnote{\CTANpkg{kvsetkeys}}:
1396 % \begin{description}
1397 % \item[\CTAN{macros/latex/contrib/kvsetkeys/kvsetkeys.dtx}] The source file.
1398 % \item[\CTAN{macros/latex/contrib/kvsetkeys/kvsetkeys.pdf}] Documentation.
1399 % \end{description}
1400 %
1401 %
1402 % \subsection{Package installation}
1403 %
1404 % \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
1405 % \docstrip\ archive. The files are extracted by running the
1406 % \xfile{.dtx} through \plainTeX:
1407 % \begin{quote}
1408 % \verb|tex kvsetkeys.dtx|
1409 % \end{quote}
1410 %
1411 % \paragraph{TDS.} Now the different files must be moved into
1412 % the different directories in your installation TDS tree
1413 % (also known as \xfile{texmf} tree):
1414 % \begin{quote}
1415 % \def\t{^^A
1416 % \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
1417 % kvsetkeys.sty & tex/generic/kvsetkeys/kvsetkeys.sty\\
1418 % kvsetkeys.pdf & doc/latex/kvsetkeys/kvsetkeys.pdf\\
1419 % kvsetkeys-example.tex & doc/latex/kvsetkeys/kvsetkeys-example.tex\\
1420 % kvsetkeys.dtx & source/latex/kvsetkeys/kvsetkeys.dtx\\
1421 % \end{tabular}^^A
1422 % }^^A
1423 % \sbox0{\t}^^A
1424 % \ifdim\wd0>\linewidth
1425 % \begingroup
1426 % \advance\linewidth by\leftmargin
1427 % \advance\linewidth by\rightmargin
1428 % \edef\x{\endgroup
1429 % \def\noexpand\lw{\the\linewidth}^^A
1430 % }\x
1431 % \def\lwbox{^^A
1432 % \leavevmode
1433 % \hbox to \linewidth{^^A
1434 % \kern-\leftmargin\relax
1435 % \hss
1436 % \usebox0
1437 % \hss
1438 % \kern-\rightmargin\relax
1439 % }^^A
1440 % }^^A
1441 % \ifdim\wd0>\lw
1442 % \sbox0{\small\t}^^A
1443 % \ifdim\wd0>\linewidth
1444 % \ifdim\wd0>\lw
1445 % \sbox0{\footnotesize\t}^^A
1446 % \ifdim\wd0>\linewidth
1447 % \ifdim\wd0>\lw
1448 % \sbox0{\scriptsize\t}^^A
1449 % \ifdim\wd0>\linewidth
1450 % \ifdim\wd0>\lw
1451 % \sbox0{\tiny\t}^^A
1452 % \ifdim\wd0>\linewidth
1453 % \lwbox
1454 % \else
1455 % \usebox0
1456 % \fi
1457 % \else
1458 % \lwbox
1459 % \fi
1460 % \else
1461 % \usebox0
1462 % \fi
1463 % \else
1464 % \lwbox
1465 % \fi
1466 % \else
1467 % \usebox0
1468 % \fi
1469 % \else
1470 % \lwbox
1471 % \fi
1472 % \else
1473 % \usebox0
1474 % \fi
1475 % \else
1476 % \lwbox
1477 % \fi
1478 % \else
1479 % \usebox0
1480 % \fi
1481 % \end{quote}
1482 % If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
1483 % TDS installing feature, then some files can already be in the right
1484 % place, see the documentation of \docstrip.
1485 %
1486 % \subsection{Refresh file name databases}
1487 %
1488 % If your \TeX~distribution
1489 % (\TeX\,Live, \mikTeX, \dots) relies on file name databases, you must refresh
1490 % these. For example, \TeX\,Live\ users run \verb|texhash| or
1491 % \verb|mktexlsr|.
1492 %
1493 % \subsection{Some details for the interested}
1494 %
1495 % \paragraph{Unpacking with \LaTeX.}
1496 % The \xfile{.dtx} chooses its action depending on the format:
1497 % \begin{description}
1498 % \item[\plainTeX:] Run \docstrip\ and extract the files.
1499 % \item[\LaTeX:] Generate the documentation.
1500 % \end{description}
1501 % If you insist on using \LaTeX\ for \docstrip\ (really,
1502 % \docstrip\ does not need \LaTeX), then inform the autodetect routine
1503 % about your intention:
1504 % \begin{quote}
1505 % \verb|latex \let\install=y\input{kvsetkeys.dtx}|
1506 % \end{quote}
1507 % Do not forget to quote the argument according to the demands
1508 % of your shell.
1509 %
1510 % \paragraph{Generating the documentation.}
1511 % You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
1512 % the documentation. The process can be configured by the
1513 % configuration file \xfile{ltxdoc.cfg}. For instance, put this
1514 % line into this file, if you want to have A4 as paper format:
1515 % \begin{quote}
1516 % \verb|\PassOptionsToClass{a4paper}{article}|
1517 % \end{quote}
1518 % An example follows how to generate the
1519 % documentation with pdf\LaTeX:
1520 % \begin{quote}
1521 %\begin{verbatim}
1522 %pdflatex kvsetkeys.dtx
1523 %makeindex -s gind.ist kvsetkeys.idx
1524 %pdflatex kvsetkeys.dtx
1525 %makeindex -s gind.ist kvsetkeys.idx
1526 %pdflatex kvsetkeys.dtx
1527 %\end{verbatim}
1528 % \end{quote}
1529 %
1530 % \begin{thebibliography}{9}
1531 % \bibitem{tb94wright}
1532 % A guide to key-value methods, Joseph Wright, second draft for
1533 % \href{https://www.tug.org/tugboat}{TUGBoat}, 2009-03-17.
1534 % \url{https://www.texdev.net/uploads/2009/03/keyval.pdf}
1535 %
1536 % \bibitem{keyval}
1537 % David Carlisle:
1538 % \textit{The \xpackage{keyval} package};
1539 % 1999/03/16 v1.13;
1540 % \CTANpkg{keyval}.
1541 %
1542 % \end{thebibliography}
1543 %
1544 % \begin{History}
1545 % \begin{Version}{2006/03/06 v1.0}
1546 % \item
1547 % First version.
1548 % \end{Version}
1549 % \begin{Version}{2006/10/19 v1.1}
1550 % \item
1551 % Fix of \cs{kv@set@family@handler}.
1552 % \item
1553 % Example added.
1554 % \end{Version}
1555 % \begin{Version}{2007/09/09 v1.2}
1556 % \item
1557 % Using package \xpackage{infwarerr} for error messages.
1558 % \item
1559 % Catcode section rewritten.
1560 % \end{Version}
1561 % \begin{Version}{2007/09/29 v1.3}
1562 % \item
1563 % Normalizing and parsing of comma separated lists added.
1564 % \item
1565 % \cs{kv@normalize} rewritten.
1566 % \item
1567 % Robustness increased for normalizing and parsing,
1568 % e.g. for values with unmatched conditionals.
1569 % \item
1570 % \eTeX\ is used if available.
1571 % \item
1572 % Tests added for normalizing and parsing.
1573 % \end{Version}
1574 % \begin{Version}{2009/07/19 v1.4}
1575 % \item
1576 % Bug fix for \cs{kv@normalize}: unwanted space removed (Florent Chervet).
1577 % \end{Version}
1578 % \begin{Version}{2009/07/30 v1.5}
1579 % \item
1580 % Documentation addition: recommendation for Joseph Wright's
1581 % review article.
1582 % \end{Version}
1583 % \begin{Version}{2009/12/12 v1.6}
1584 % \item
1585 % Short info shortened.
1586 % \end{Version}
1587 % \begin{Version}{2009/12/22 v1.7}
1588 % \item
1589 % Internal optimization (\cs{KVS@CommaSpace}, \dots, \cs{KVS@EqualsSpace}).
1590 % \end{Version}
1591 % \begin{Version}{2010/01/28 v1.8}
1592 % \item
1593 % Compatibility to ini\TeX\ added.
1594 % \end{Version}
1595 % \begin{Version}{2010/03/01 v1.9}
1596 % \item
1597 % Support of \cs{par} inside values.
1598 % \end{Version}
1599 % \begin{Version}{2011/01/30 v1.10}
1600 % \item
1601 % Already loaded package files are not input in \hologo{plainTeX}.
1602 % \end{Version}
1603 % \begin{Version}{2011/03/03 v1.11}
1604 % \item
1605 % \cs{kv@break} and \cs{comma@break} added.
1606 % \end{Version}
1607 % \begin{Version}{2011/04/05 v1.12}
1608 % \item
1609 % Error message with recovery action in help message
1610 % (request by GL).
1611 % \end{Version}
1612 % \begin{Version}{2011/04/07 v1.13}
1613 % \item
1614 % \cs{kv@processor@default} supports package \xpackage{babel}'s
1615 % shorthands.
1616 % \item
1617 % \cs{kv@set@family@handler} with shorthand support.
1618 % \end{Version}
1619 % \begin{Version}{2011/06/15 v1.14}
1620 % \item
1621 % Some optimizations in token register uses (GL, HO).
1622 % \end{Version}
1623 % \begin{Version}{2011/10/18 v1.15}
1624 % \item
1625 % \cs{kv@processor@known} and \cs{kvsetknownkeys} added.
1626 % \item
1627 % \cs{kvsetkeys@expandafter} and \cs{kvsetknownkeys@expandafter} added.
1628 % \item
1629 % Family handler can report success or failure by \cs{kv@handled@true}
1630 % or \cs{kv@handled@false}.
1631 % \item
1632 % \cs{kv@unset@family@handler} added.
1633 % \end{Version}
1634 % \begin{Version}{2012/04/25 v1.16}
1635 % \item
1636 % \cs{kv@processor@default} and \cs{kv@processor@known} define
1637 % macro \cs{kv@fam} for convenience.
1638 % \item
1639 % Catcode section: Catcode setting for \texttt{+} added for \hologo{eTeX}.
1640 % \end{Version}
1641 % \begin{Version}{2016/05/16 v1.17}
1642 % \item
1643 % Documentation updates.
1644 % \end{Version}
1645 % \begin{Version}{2019/12/15 v1.18}
1646 % \item
1647 % Documentation updates.
1648 % \item
1649 % Avoid \xpackage{etexcmds} and \xpackage{infwarwerr} in \LaTeX.
1650 % \end{Version}
1651 % \begin{Version}{2022-10-05 v1.19}
1652 % \item Corrected storing of unknown keys, issue \#1
1653 % \end{Version}
1654 % \end{History}
1655 %
1656 % \PrintIndex
1657 %
1658 % \Finale
1659 \endinput