Debian Codegraph @

texmf-dist/source/latex/expkv-bundle/expkv-opt-2020-10-10.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: expkv-opt.dtx Copyright (C) 2020-2024 Jonathan P. Spratte
4 %
5 % This work may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License (LPPL), either version 1.3c of this license or
7 % (at your option) any later version. The latest version of this license is in
8 % the file:
9 %
10 % http://www.latex-project.org/lppl.txt
11 %
12 % ------------------------------------------------------------------------------
13 %
14 %<*driver>^^A>>=
15 \def\nameofplainTeX{plain}
16 \ifx\fmtname\nameofplainTeX\else
17 \expandafter\begingroup
18 \fi
19 \input l3docstrip.tex
20 \askforoverwritefalse
21 \preamble
22
23 --------------------------------------------------------------
24 expkv-opt -- parse class and package options with expkv
25 E-mail: [email protected]
26 Released under the LaTeX Project Public License v1.3c or later
27 See http://www.latex-project.org/lppl.txt
28 --------------------------------------------------------------
29
30 Copyright (C) 2020-2024 Jonathan P. Spratte
31
32 This work may be distributed and/or modified under the conditions of the
33 LaTeX Project Public License (LPPL), either version 1.3c of this license or
34 (at your option) any later version. The latest version of this license is in
35 the file:
36
37 http://www.latex-project.org/lppl.txt
38
39 This work is "maintained" (as per LPPL maintenance status) by
40 Jonathan P. Spratte.
41
42 This work consists of the file expkv-opt.dtx
43 and the derived files expkv-opt.pdf
44 expkv-opt.sty
45 and the file expkv-opt-2020-10-10.dtx
46 and the derived file expkv-opt-2020-10-10.sty
47
48 \endpreamble
49 % stop docstrip adding \endinput
50 \postamble
51 \endpostamble
52 \generate{\file{expkv-opt-2020-10-10.sty}{\from{expkv-opt-2020-10-10.dtx}{pkg}}}
53 \ifx\fmtname\nameofplainTeX
54 \expandafter\endbatchfile
55 \else
56 \expandafter\endgroup\expandafter\stop
57 \fi
58 %
59 \IfFileExists{expkv-opt.sty}{\RequirePackage{expkv-opt}}{}
60 \ProvidesFile{expkv-opt.dtx}
61 [\csname ekvoDate\endcsname\ parse class and package options with expkv]
62 \PassOptionsToPackage{full}{textcomp}
63 \documentclass{l3doc}
64 \RequirePackage[oldstylenums,nott]{kpfonts}
65 \input{glyphtounicode}
66 \pdfgentounicode=1
67 \RequirePackage{listings}
68 \RequirePackage{booktabs}
69 \RequirePackage{array}
70 \RequirePackage{collcell}
71 \RequirePackage{siunitx}
72 \RequirePackage{xcolor}
73 \RequirePackage{caption}
74 \RequirePackage{microtype}
75 \RequirePackage{accsupp}
76 \lstset
77 {
78 ,flexiblecolumns=false
79 ,basewidth=.53em
80 ,gobble=2
81 ,basicstyle=\fontfamily{jkp}\itshape
82 ,morekeywords=^^A
83 {^^A
84 \ekvoProcessLocalOptions,
85 \ekvoProcessGlobalOptions,
86 \ekvoProcessUnusedGlobalOptions,
87 \ekvoProcessOptionsList,
88 \ekvoUseUnknownHandlers
89 }
90 ,morecomment=[l]\%
91 ,commentstyle=\color[gray]{0.4}
92 ,literate={\{}{{\CodeSymbol\{}}{1}
93 {\}}{{\CodeSymbol\}}}{1}
94 ^^A,literate=*{<key>}{\key}{4}{<set>}{\set}{4}
95 }
96 \newcommand*\CodeSymbol[1]{\textbf{#1}}
97 \RequirePackage{randtext}
98 \let\metaORIG\meta
99 \protected\def\meta #1{\texttt{\metaORIG{#1}}}
100 \renewcommand*\thefootnote{\fnsymbol{footnote}}
101 \definecolor{expkvred}{HTML}{9F393D}
102 \colorlet{expkvgrey}{black!75}
103 \makeatletter
104 \newcommand*\expkv
105 {^^A
106 \texorpdfstring
107 {^^A
108 \mbox
109 {^^A
110 \BeginAccSupp{ActualText=expkv}^^A
111 \href{https://github.com/Skillmon/tex_expkv}
112 {^^A
113 \rmfamily
114 \bfseries
115 {\color{expkvgrey}e\kern-.05em x\kern-.05em}^^A
116 \lower.493ex
117 \hbox{{\color{expkvgrey}P}\kern-.1em{\color{expkvred}k}}^^A
118 \kern-.18em{\color{expkvred}v}^^A
119 }^^A
120 \EndAccSupp{}^^A
121 }^^A
122 }
123 {expkv}^^A
124 }
125 \newcommand*\expkvpkg[1]
126 {^^A
127 \texorpdfstring
128 {^^A
129 \mbox
130 {^^A
131 \BeginAccSupp{ActualText=expkv-#1}^^A
132 \href{https://github.com/Skillmon/tex_expkv-#1}
133 {^^A
134 \rmfamily
135 \bfseries
136 {\color{expkvgrey}e\kern-.05em x\kern-.05em}^^A
137 \lower.493ex
138 \hbox{{\color{expkvgrey}P}\kern-.1em{\color{expkvred}k}}^^A
139 \kern-.18em{\color{expkvred}v}^^A
140 {\color{expkvgrey}^^A
141 \kern.05em\rule[-.1ex]{.08em}{1.2ex}\kern.05em\textsc{#1}^^A
142 }^^A
143 }^^A
144 \EndAccSupp{}^^A
145 }^^A
146 }
147 {expkv-#1}^^A
148 }
149 \newcommand*\expkvd{\expkvpkg{def}}
150 \newcommand*\expkvc{\expkvpkg{cs}}
151 \newcommand*\expkvo{\expkvpkg{opt}}
152 \newcommand\kv{\meta{key}=\meta{value}}
153 \newcommand\key{\meta{key}}
154 \newcommand\val{\meta{value}}
155 \newcommand\set{\meta{set}}
156 \newcommand\enfprot{\textcolor{black}{protected}}
157 \newcommand\allprot{\textcolor{gray}{protected}}
158 \newcommand\notprot{\textcolor{red!80!black}{protected}}
159 \newcommand\enflong{\textcolor{black}{long}}
160 \newcommand\alllong{\textcolor{gray}{long}}
161 \newcommand\notlong{\textcolor{red!80!black}{long}}
162 \newcommand\prefixes[2]
163 {^^A
164 \hfill
165 \ifcase\numexpr#1\relax\or
166 \enfprot\or
167 \allprot\or
168 \notprot\fi\space
169 \ifcase\numexpr#2\relax\or
170 \enflong\or
171 \alllong\or
172 \notlong\fi
173 }
174 \hypersetup{linkcolor=red!80!black,urlcolor=purple!80!black}
175 \DoNotIndex{\def,\edef,\,,\=,\begingroup,\catcode,\chardef,\csname,\endcsname}
176 \DoNotIndex{\endgroup,\endinput,\errmessage,\expandafter,\input,\let,\long}
177 \DoNotIndex{\protected,\ProvidesFile,\ProvidesPackage,\relax,\space}
178 \DoNotIndex{\@,\unexpanded,\string,\expanded,\dimexpr,\global,\glueexpr,\hbox}
179 \DoNotIndex{\numexpr,\RequirePackage,\setbox,\the,\unless,\xdef,\@firstofone}
180 \DoNotIndex{\@firstoftwo,\@gobble,\@secondoftwo,\AtEndOfPackage,\newcommand}
181 \DoNotIndex{\PackageError,\@classoptionslist,\@clsextension,\@currext}
182 \DoNotIndex{\@currname,\@empty,\@gobbletwo,\@onlypreamble,\@unprocessedoptions}
183 \DoNotIndex{\@unusedoptionlist}
184 \DoNotIndex{\ifcsname}
185 \DoNotIndex{\ifx}
186 \DoNotIndex{\ifdefined}
187 \DoNotIndex{\iffalse}
188 \DoNotIndex{\iftrue}
189 \DoNotIndex{\else}
190 \DoNotIndex{\fi}
191 \@gobble\fi ^^A ignoring \ifx, \ifcsname, etc., but only one \fi
192 \@gobble\fi ^^A ignoring \ifx, \ifcsname, etc., but only one \fi
193 \@gobble\fi ^^A ignoring \ifx, \ifcsname, etc., but only one \fi
194 \@gobble\fi ^^A ignoring \ifx, \ifcsname, etc., but only one \fi
195 \@ifdefinable\gobbledocstriptag{\def\gobbledocstriptag#1>{}}
196 \makeatother
197 \begin{document}
198 \title
199 {^^A
200 \texorpdfstring
201 {^^A
202 \huge\expkvo
203 \\[\medskipamount]
204 \Large parse class and package options with \expkv
205 }{expkv-opt - parse class and package options with expkv}^^A
206 }
207 \date{\ekvoDate\space v\ekvoVersion}
208 \author{Jonathan P. Spratte\thanks{\protect\randomize{[email protected]}}}
209 \DocInput{expkv-opt.dtx}
210 \end{document}
211 %</driver>^^A=<<
212 % \fi
213 %
214 % \maketitle
215 % \renewcommand*\thefootnote{\arabic{footnote}}
216 %
217 % \begin{abstract}
218 % \noindent\parfillskip=0pt
219 % \expkvo\ provides option parsing for classes and packages in \LaTeXe\ based on
220 % \expkv. Global and local options are parsed individually by different
221 % commands. The stylised name is \expkvo\ but the files use \file{expkv-opt},
222 % this is due to CTAN-rules which don't allow \string| in package names since
223 % that is the pipe symbol in *nix shells.
224 % \end{abstract}
225 %
226 % \tableofcontents
227 %
228 % \begin{documentation}^^A>>=
229 %
230 % \section{Documentation}
231 %
232 % The \expkv\ family provides at its core a \kv\ parser and additionally
233 % packages, one to conveniently define new keys (\expkvd) and another to build
234 % expandable \kv\ taking control sequences (\expkvc). Still missing from the mix
235 % was a solution to parse \LaTeXe\ class and package options, a gap that's
236 % hereby filled with \expkvo.
237 %
238 % \expkvo\ shouldn't place any restrictions on the keys, but note that parts of
239 % \LaTeXe\ can break if the \kv\ list contains braces. This includes the global
240 % options list depending on which class you're using. Also keep in mind that
241 % every value provided should be save from an |\edef| expansion, as the space
242 % stripping code of \LaTeXe\ options (which is applied before \expkvo\ takes
243 % control) uses such an expansion.
244 %
245 % The package can be loaded with
246 % \begin{lstlisting}
247 % \usepackage{expkv-opt}
248 % \end{lstlisting}
249 % Unlike the other packages in the \expkv\ family, \expkvo\ is only provided as
250 % a \LaTeX\ package.
251 %
252 % Before reading this documentation you should read \expkv's documentation and
253 % might want to also read the documentation of \expkvd.
254 %
255 %
256 % \subsection{Macros}
257 %
258 % \expkvo's behaviour if it encounters a defined or an undefined \key\ depends
259 % on which list is being parsed and whether the current file is a class or not.
260 % Of course in every case a defined \key's callback will be invoked but an
261 % additional action might be executed. For this reason the rule set of every
262 % macro will be given below the short description which list it will parse.
263 %
264 % During each of the processing macros the current list element (not separated
265 % in \key\ and \val\ but as a whole) is stored within the macro
266 % \cs{CurrentOption}.
267 %
268 % \begin{function}{\ekvoProcessLocalOptions}
269 % \begin{syntax}
270 % \cs{ekvoProcessLocalOptions}\marg{set}
271 % \end{syntax}
272 % This parses the options which are directly passed to the current class or
273 % package for an \expkv\ \set.
274 % \end{function}
275 % \begin{description}
276 % \item[Class:]
277 % \begin{description}
278 % \item[defined] \emph{nothing}
279 % \item[undefined]
280 % add the key to the list of unused global options (if the local option
281 % list matches the option list of the main class)
282 % \end{description}
283 % \item[Package:]
284 % \begin{description}
285 % \item[defined] \emph{nothing}
286 % \item[undefined] throw an error
287 % \end{description}
288 % \end{description}
289 %
290 % \begin{function}{\ekvoProcessGlobalOptions}
291 % \begin{syntax}
292 % \cs{ekvoProcessGlobalOptions}\marg{set}
293 % \end{syntax}
294 % In \LaTeXe\ the options given to |\documentclass| are global options. This
295 % macro processes the global options for an \expkv\ \set.
296 % \end{function}
297 % \begin{description}
298 % \item[Class:]
299 % \begin{description}
300 % \item[defined] remove the option from the list of unused global options
301 % \item[undefined] \emph{nothing}
302 % \end{description}
303 % \item[Package:]
304 % \begin{description}
305 % \item[defined] remove the option from the list of unused global options
306 % \item[undefined] \emph{nothing}
307 % \end{description}
308 % \end{description}
309 %
310 % \begin{function}{\ekvoProcessUnusedGlobalOptions}
311 % \begin{syntax}
312 % \cs{ekvoProcessUnusedGlobalOptions}\marg{set}
313 % \end{syntax}
314 % If you want to, instead of parsing all global options, you can parse only
315 % those global options which weren't yet used by another package or class.
316 % \end{function}
317 % \begin{description}
318 % \item[Class:]
319 % \begin{description}
320 % \item[defined] remove the option from the list of unused global options
321 % \item[undefined] \emph{nothing}
322 % \end{description}
323 % \item[Package:]
324 % \begin{description}
325 % \item[defined] remove the option from the list of unused global options
326 % \item[undefined] \emph{nothing}
327 % \end{description}
328 % \end{description}
329 %
330 % \begin{function}{\ekvoProcessOptionsList}
331 % \begin{syntax}
332 % \cs{ekvoProcessOptionsList}\meta{list}\marg{set}
333 % \end{syntax}
334 % Process the \kv\ list stored in the macro \meta{list}.
335 % \end{function}
336 % \begin{description}
337 % \item[Class:]
338 % \begin{description}
339 % \item[defined] \emph{nothing}
340 % \item[undefined] \emph{nothing}
341 % \end{description}
342 % \item[Package:]
343 % \begin{description}
344 % \item[defined] \emph{nothing}
345 % \item[undefined] \emph{nothing}
346 % \end{description}
347 % \end{description}
348 %
349 % \begin{function}{\ekvoUseUnknownHandlers}
350 % \begin{syntax}
351 % \cs{ekvoUseUnknownHandlers}\meta{cs_1}\meta{cs_2}
352 % \end{syntax}
353 % With this macro you can change the action \expkvo\ executes if it encounters
354 % an undefined \key\ for the next (and only the next) list processing macro.
355 % The macro \meta{cs_1} will be called if an undefined \key\ without a \val\
356 % is encountered and get one argument, being the \key. Analogous the macro
357 % \meta{cs_2} will be called if an undefined \key\ with a \val\ was specified.
358 % It will get two arguments, the first being the \key\ and the second the
359 % \val.
360 % \end{function}
361 %
362 % \begin{function}{\ekvoVersion,\ekvoDate}
363 % These two macros store the version and date of the package.
364 % \end{function}
365 %
366 %
367 % \subsection{Example}
368 %
369 % Let's say we want to create a package that changes the way footnotes are
370 % displayed in \LaTeX. For this it will essentially just redefine
371 % \cs[no-index]{thefootnote} and we'll call this package \pkg{ex-footnote}.
372 % First we report back which package we are:
373 % \begin{lstlisting}
374 % \ProvidesPackage{ex-footnote}[2020-02-02 v1 change footnotes]
375 % \end{lstlisting}
376 % Next we'll need to provide the options we want the package to have.
377 % \begin{lstlisting}
378 % \RequirePackage{color}
379 % \RequirePackage{expkv-opt} % also loads expkv
380 % \ekvdef{ex-footnote}{color}{\def\exfn@color{#1}}
381 % \ekvdef{ex-footnote}{format}{\def\exfn@format{#1}}
382 % \end{lstlisting}
383 % We can provide initial values just by defining the two macros storing the
384 % value.
385 % \begin{lstlisting}
386 % \newcommand*\exfn@color{}
387 % \newcommand*\exfn@format{arabic}
388 % \end{lstlisting}
389 % Next we need to process the options given to the package. The package should
390 % only obey options directly passed to it, so we're only using
391 % |\ekvoProcessLocalOptions|:
392 % \begin{lstlisting}
393 % \ekvoProcessLocalOptions{ex-footnote}
394 % \end{lstlisting}
395 % Now everything that's still missing is actually changing the way footnotes
396 % appear:
397 % \begin{lstlisting}
398 % \renewcommand*\thefootnote
399 % {%
400 % \ifx\exfn@color\@empty
401 % \csname\exfn@format\endcsname{footnote}%
402 % \else
403 % \textcolor{\exfn@color}{\csname\exfn@format\endcsname{footnote}}%
404 % \fi
405 % }
406 % \end{lstlisting}
407 % \bigskip
408 %
409 % \noindent
410 % So the complete code of the package would look like this:
411 % \begin{lstlisting}
412 % \ProvidesPackage{ex-footnote}[2020-02-02 v1 change footnotes]
413 %
414 % \RequirePackage{color}
415 % \RequirePackage{expkv-opt} % also loads expkv
416 %
417 % \ekvdef{ex-footnote}{color}{\def\exfn@color{#1}}
418 % \ekvdef{ex-footnote}{format}{\def\exfn@format{#1}}
419 % \newcommand*\exfn@color{}
420 % \newcommand*\exfn@format{arabic}
421 %
422 % \ekvoProcessLocalOptions{ex-footnote}
423 %
424 % \renewcommand*\thefootnote
425 % {%
426 % \ifx\exfn@color\@empty
427 % \csname\exfn@format\endcsname{footnote}%
428 % \else
429 % \textcolor{\exfn@color}{\csname\exfn@format\endcsname{footnote}}%
430 % \fi
431 % }
432 % \end{lstlisting}
433 % \bigskip
434 %
435 % \noindent
436 % And it could be used with one of the following lines:
437 % \begin{lstlisting}
438 % \usepackage{ex-footnote}
439 % \usepackage[format=fnsymbol]{ex-footnote}
440 % \usepackage[color=green]{ex-footnote}
441 % \usepackage[color=red,format=roman]{ex-footnote}
442 % \end{lstlisting}
443 %
444 %
445 % \subsection{Bugs}
446 %
447 % If you happen to find bugs, it'd be great if you let me know. Just write me an
448 % email (see the front page) or submit a bug report on GitHub:
449 % \url{https://github.com/Skillmon/tex_expkv-opt}
450 %
451 %
452 % \subsection{License}
453 %
454 % Copyright \textcopyright\ 2020\unless\ifnum\year=2020--\the\year\fi\
455 % Jonathan P. Spratte
456 %
457 % \medskip\noindent
458 % This work may be distributed and/or modified under the conditions of the
459 % \LaTeX\ Project Public License (LPPL), either version 1.3c of this license or
460 % (at your option) any later version. The latest version of this license is in
461 % the file:
462 %
463 % \url{http://www.latex-project.org/lppl.txt}
464 %
465 % \noindent
466 % This work is ``maintained'' (as per LPPL maintenance status) by
467 %
468 % \mbox{Jonathan P. Spratte}.
469 %
470 % \end{documentation}^^A=<<
471 %
472 % \begin{implementation}^^A>>=
473 %
474 % \clearpage
475 %
476 %
477 % \section{Implementation}
478 %
479 % \gobbledocstriptag
480 %<*pkg>
481 % Start the package with the typical \LaTeX\ standards.
482 %
483 % \begin{macro}{\ekvoVersion,\ekvoDate}
484 % Store the packages version and date in two macros.
485 % \begin{macrocode}
486 \newcommand*\ekvoVersion{0.1c}
487 \newcommand*\ekvoDate{2020-10-10}
488 % \end{macrocode}
489 % \end{macro}
490 % And we report who we are and what we need.
491 % \begin{macrocode}
492 \ProvidesPackage{expkv-opt}
493 [%
494 \ekvoDate\space v\ekvoVersion\space
495 parse class and package options with expkv%
496 ]
497 \RequirePackage{expkv}
498 % \end{macrocode}
499 %
500 %
501 % \subsection{Loop}
502 %
503 % \begin{macro}[internal]
504 % {\ekvo@CurrentOption@loop,\ekvo@CurrentOption@loop@,\ekvo@end@loop}
505 % We'll need some loop which can iterate over a comma separated list. The loop
506 % is very basic and only works for commas of category~12. First we insert the
507 % delimiters for the actual loop. The |\ekv@set@other| is necessary to get a
508 % functional |\ekvmorekv| in this loop.
509 % \begin{macrocode}
510 \protected\long\def\ekvo@CurrentOption@loop#1#2%
511 {%
512 \ekvo@CurrentOption@loop@#2\ekv@set@other\ekv@mark#1,\ekv@stop,\ekvo@tail
513 }
514 % \end{macrocode}
515 % The actual loop checks whether the final element has been read and if so
516 % ends the loop. Else blank elements are ignored, |\CurrentOption| is set and
517 % the macro which parses the list elements called. Then call the next
518 % iteration.
519 % \begin{macrocode}
520 \long\def\ekvo@CurrentOption@loop@#1\ekv@set@other#2,%
521 {%
522 \ekv@gobble@from@mark@to@stop#2\ekvo@end@loop\ekv@stop
523 \ekv@ifblank{#2}%
524 {}%
525 {%
526 \edef\CurrentOption{\unexpanded\expandafter{\ekv@gobble@mark#2}}%
527 #1{#2}%
528 }%
529 \ekvo@CurrentOption@loop@#1\ekv@set@other\ekv@mark
530 }
531 \long\def\ekvo@end@loop#1\ekvo@tail{}
532 % \end{macrocode}
533 % \end{macro}
534 %
535 %
536 % \subsection{Tests}
537 %
538 % \begin{macro}[internal]{\ekvo@ifx@TF,\ekvo@ifx@F}
539 % We'll need branching |\ifx| tests so that user input containing unbalanced
540 % \TeX\ ifs doesn't break (at least not because of us, everything else is the
541 % fault of \LaTeXe).
542 % \begin{macrocode}
543 \def\ekvo@ifx@TF#1#2{\ifx#1#2\ekv@fi@firstoftwo\fi\@secondoftwo}
544 \def\ekvo@ifx@F#1#2{\ifx#1#2\ekv@fi@gobble\fi\@firstofone}
545 % \end{macrocode}
546 % \end{macro}
547 %
548 % \begin{macro}[internal]{\ekvo@do@with@set,\ekvo@name,\ekvo@setname}
549 % This test checks whether the \set\ is defined. If it is we store it in
550 % |\ekvo@setname| and set |\ekvo@name| to a short cut to get the \key's
551 % callback name. Next we execute the code in |#2|, if the \set\ isn't defined
552 % |#2| is gobbled.
553 % \begin{macrocode}
554 \protected\def\ekvo@do@with@set#1#2%
555 {%
556 \ekvifdefinedset{#1}%
557 {%
558 \expandafter
559 \let\expandafter\ekvo@name\csname\ekv@undefined@set{#1}\endcsname
560 \def\ekvo@setname{#1}%
561 #2%
562 }%
563 {\ekvo@err@undefined@set{#1}}%
564 }
565 % \end{macrocode}
566 % \end{macro}
567 %
568 %
569 % \subsection{Key handlers}
570 %
571 % \expkvo\ uses handlers specifying what happens if a parsed \key\ is defined or
572 % undefined.
573 %
574 % \begin{macro}[internal]
575 % {\ekvo@handle@undefined@k@pkg,\ekvo@handle@undefined@kv@pkg}
576 % The case for undefined keys in a local list of a package is easy, just throw
577 % appropriate errors.
578 % \begin{macrocode}
579 \protected\long\def\ekvo@handle@undefined@k@pkg#1%
580 {%
581 \ekv@ifdefined{\ekvo@name{#1}}%
582 {\ekvo@err@value@required{#1}}%
583 {\ekvo@err@undefined@key{#1}}%
584 }
585 \def\ekvo@handle@undefined@kv@pkg#1#2%
586 {%
587 \ekv@ifdefined{\ekvo@name{#1}N}%
588 {\ekvo@err@value@forbidden{#1}}%
589 {\ekvo@err@undefined@key{#1}}%
590 }
591 % \end{macrocode}
592 % \end{macro}
593 %
594 % \begin{macro}[internal]
595 % {
596 % \ekvo@addto@unused@one,\ekvo@addto@unused@two,
597 % \ekvo@rmfrom@unused@one,\ekvo@rmfrom@unused@two
598 % }
599 % These macros will add or remove the |\CurrentOption| to or from the list of
600 % unused global options.
601 % \begin{macrocode}
602 \long\def\ekvo@addto@unused@one#1{\ekvo@addto@list\@unusedoptionlist}
603 \long\def\ekvo@addto@unused@two#1#2{\ekvo@addto@list\@unusedoptionlist}
604 \long\def\ekvo@rmfrom@unused@one#1{\ekvo@rmfrom@list\@unusedoptionlist}
605 \long\def\ekvo@rmfrom@unused@two#1#2{\ekvo@rmfrom@list\@unusedoptionlist}
606 % \end{macrocode}
607 % \end{macro}
608 % \begin{macro}[internal]
609 % {
610 % \ekvo@set@handlers@local,\ekvo@set@handlers@global,
611 % \ekvo@set@handlers@unusedglobal,\ekvo@set@handlers@list
612 % }
613 % These macros are boring. They just set up the handlers to respect the rules
614 % documented earlier.
615 % \begin{macrocode}
616 \protected\def\ekvo@set@handlers@local
617 {%
618 \ekvo@if@need@handlers
619 {%
620 \ifx\@currext\@clsextension
621 \ifx\@classoptionslist\relax
622 \let\ekvo@handle@undefined@k\@gobble
623 \let\ekvo@handle@undefined@kv\@gobbletwo
624 \else
625 \expandafter
626 \ifx\csname opt@\@currname.\@currext\endcsname\@classoptionslist
627 \let\ekvo@handle@undefined@k\ekvo@addto@unused@one
628 \let\ekvo@handle@undefined@kv\ekvo@addto@unused@two
629 \else
630 \let\ekvo@handle@undefined@k\@gobble
631 \let\ekvo@handle@undefined@kv\@gobbletwo
632 \fi
633 \fi
634 \else
635 \let\ekvo@handle@undefined@k\ekvo@handle@undefined@k@pkg
636 \let\ekvo@handle@undefined@kv\ekvo@handle@undefined@kv@pkg
637 \fi
638 }%
639 }
640 \protected\def\ekvo@set@handlers@global
641 {%
642 \unless\ifx\@unusedoptionlist\@empty
643 \let\ekvo@handle@defined@k\ekvo@rmfrom@unused@one
644 \let\ekvo@handle@defined@kv\ekvo@rmfrom@unused@two
645 \fi
646 \ekvo@if@need@handlers
647 {%
648 \let\ekvo@handle@undefined@k\@gobble
649 \let\ekvo@handle@undefined@kv\@gobbletwo
650 }%
651 }
652 \protected\def\ekvo@set@handlers@unusedglobal
653 {%
654 \ekvo@if@need@handlers
655 {%
656 \let\ekvo@handle@undefined@k\ekvo@addto@unused@one
657 \let\ekvo@handle@undefined@kv\ekvo@addto@unused@two
658 \let\@unusedoptionlist\@empty
659 \@gobbletwo
660 }%
661 \@firstofone
662 {%
663 \let\ekvo@handle@defined@k\ekvo@rmfrom@unused@one
664 \let\ekvo@handle@defined@kv\ekvo@rmfrom@unused@two
665 }%
666 }
667 \protected\def\ekvo@set@handlers@list
668 {%
669 \ekvo@if@need@handlers
670 {%
671 \let\ekvo@handle@undefined@k\@gobble
672 \let\ekvo@handle@undefined@kv\@gobbletwo
673 }%
674 }
675 % \end{macrocode}
676 % \end{macro}
677 %
678 % \begin{macro}[internal]{\ekvo@if@need@handlers,\ekvo@dont@need@handlers}
679 % If the user specifies handlers this macro will be let to
680 % |\ekvo@dont@need@handlers|, which will act like |\@gobble| and also let it
681 % to |\@firstofone| afterwards.
682 % \begin{macrocode}
683 \let\ekvo@if@need@handlers\@firstofone
684 \protected\long\def\ekvo@dont@need@handlers#1%
685 {%
686 \let\ekvo@if@need@handlers\@firstofone
687 }%
688 % \end{macrocode}
689 % \end{macro}
690 %
691 % We have to set the default for the handlers of defined keys, because they
692 % don't necessarily get defined before a list is parsed.
693 % \begin{macrocode}
694 \let\ekvo@handle@defined@k\@gobble
695 \let\ekvo@handle@defined@kv\@gobbletwo
696 % \end{macrocode}
697 %
698 %
699 % \subsection{Processing list elements}
700 %
701 % \begin{macro}[internal]{\ekvo@process@common}
702 % All the key processing frontend macros use the same basic structure. |#1|
703 % will be a simple test, deciding whether the list will really be parsed or
704 % not, |#3| will be the \set, and |#2| will be the individual code of the
705 % frontend macro which should be executed if both the test in |#1| is true and
706 % the \set\ is defined.
707 % \begin{macrocode}
708 \protected\def\ekvo@process@common#1#2#3%
709 {%
710 #1{\ekvo@do@with@set{#3}{#2}}%
711 }
712 % \end{macrocode}
713 % \end{macro}
714 %
715 % \begin{macro}[internal]{\ekvo@process@list}
716 % This macro only expands the list holding macro and forwards it to the
717 % loop macro.
718 % \begin{macrocode}
719 \protected\def\ekvo@process@list#1%
720 {%
721 \expandafter\ekvo@CurrentOption@loop\expandafter{#1}\ekvo@parse
722 }
723 % \end{macrocode}
724 % \end{macro}
725 %
726 % \begin{macro}[internal]{\ekvo@parse}
727 % This macro calls internals of |\ekvparse| such that the code splitting at
728 % commas isn't executed, else this is equivalent to
729 % |\ekvparse\ekvo@set@k\ekvo@set@kv{#1}|.
730 % \begin{macrocode}
731 \protected\long\def\ekvo@parse#1%
732 {%
733 \ekv@expanded
734 {\ekv@unexpanded{\ekvparse\ekvo@set@k\ekvo@set@kv}\expandafter}%
735 \expandafter{\ekv@gobble@mark#1}\ekvo@tail
736 }
737 % \end{macrocode}
738 % \end{macro}
739 %
740 % \begin{macro}[internal]{\ekvo@set@k,\ekvo@set@kv}
741 % These two macros check whether the key is defined and if so call the handler
742 % for defined keys and execute the key, else the handler for undefined keys is
743 % called. They have to clean up a bit of code which is left by |\ekvo@parse|.
744 % \begin{macrocode}
745 \protected\def\ekvo@set@k#1#2\ekvo@tail
746 {%
747 \ekv@ifdefined{\ekvo@name{#1}N}%
748 {%
749 \ekvo@handle@defined@k{#1}%
750 \csname\ekvo@name{#1}N\endcsname
751 }%
752 {\ekvo@handle@undefined@k{#1}}%
753 }
754 \protected\def\ekvo@set@kv#1#2#3\ekvo@tail
755 {%
756 \ekv@ifdefined{\ekvo@name{#1}}%
757 {%
758 \ekvo@handle@defined@kv{#1}{#2}%
759 \csname\ekvo@name{#1}\endcsname{#2}%
760 }%
761 {\ekvo@handle@undefined@kv{#1}{#2}}%
762 }
763 % \end{macrocode}
764 % \end{macro}
765 %
766 %
767 % \subsection{List variable helpers}
768 %
769 % \begin{macro}[internal]{\ekvo@addto@list}
770 % This macro is rather simple. If the list to which the |\CurrentOption|
771 % should be added is empty we can just let the list to the |\CurrentOption|.
772 % Else we have to expand the list once and the |\CurrentOption| once.
773 % \begin{macrocode}
774 \protected\def\ekvo@addto@list#1%
775 {%
776 \ekvo@ifx@TF#1\@empty
777 {\let#1\CurrentOption}%
778 {%
779 \edef#1%
780 {%
781 \unexpanded\expandafter{#1},%
782 \unexpanded\expandafter{\CurrentOption}%
783 }%
784 }%
785 }
786 % \end{macrocode}
787 % \end{macro}
788 %
789 % \begin{macro}[internal]{\ekvo@rmfrom@list,\ekvo@rmfrom@list@}
790 % This works by looping over every list item and comparing it to
791 % |\ekvo@curropt| which stores the real |\CurrentOption|. This is
792 % comparatively slow, but works for items containing braces unlike what
793 % \LaTeXe\ does. We could be faster for items not containing braces, though.
794 % \begin{macrocode}
795 \protected\def\ekvo@rmfrom@list#1%
796 {%
797 \ekvo@ifx@F#1\@empty
798 {%
799 \let\ekvo@tmp@list\@empty
800 \let\ekvo@curropt\CurrentOption
801 \expandafter\ekvo@CurrentOption@loop\expandafter{#1}\ekvo@rmfrom@list@
802 \let\CurrentOption\ekvo@curropt
803 \let#1\ekvo@tmp@list
804 }%
805 }
806 \protected\long\def\ekvo@rmfrom@list@#1%
807 {%
808 \ekvo@ifx@F\CurrentOption\ekvo@curropt
809 {\ekvo@addto@list\ekvo@tmp@list}%
810 }
811 % \end{macrocode}
812 % \end{macro}
813 %
814 %
815 % \subsection{Errors}
816 %
817 % \begin{macro}[internal]
818 % {
819 % \ekvo@err@undefined@key,\ekvo@err@value@required,
820 % \ekvo@err@value@forbidden,\ekvo@err@undefined@set
821 % }
822 % Just some macros to throw errors in the few cases an error has to be thrown.
823 % \begin{macrocode}
824 \protected\def\ekvo@err@undefined@key#1%
825 {%
826 \PackageError{expkv-opt}{Undefined key `#1' in set `\ekvo@setname'}{}%
827 }
828 \protected\def\ekvo@err@value@required#1%
829 {%
830 \PackageError{expkv-opt}%
831 {Value required for key `#1' in set `\ekvo@setname'}%
832 {}%
833 }
834 \protected\def\ekvo@err@value@forbidden#1%
835 {%
836 \PackageError{expkv-opt}%
837 {Value forbidden for key `#1' in set `\ekvo@setname'}%
838 {}%
839 }
840 \protected\def\ekvo@err@undefined@set#1%
841 {%
842 \PackageError{expkv-opt}%
843 {Undefined set `#1'}%
844 {The set for which you try to parse options isn't defined in expkv.}%
845 }
846 % \end{macrocode}
847 % \end{macro}
848 %
849 %
850 % \subsection{User Interface}
851 %
852 % The user interface macros just put together the bits and pieces.
853 % \begin{macro}{\ekvoProcessLocalOptions}
854 % \begin{macrocode}
855 \protected\def\ekvoProcessLocalOptions
856 {%
857 \ekvo@process@common
858 {\ekv@ifdefined{opt@\@currname.\@currext}\@firstofone\@gobble}%
859 {%
860 \ekvo@set@handlers@local
861 \expandafter
862 \ekvo@process@list\csname opt@\@currname.\@currext\endcsname
863 \AtEndOfPackage{\let\@unprocessedoptions\relax}%
864 }%
865 }
866 % \end{macrocode}
867 % \end{macro}
868 % \begin{macro}{\ekvoProcessGlobalOptions}
869 % \begin{macrocode}
870 \protected\def\ekvoProcessGlobalOptions
871 {%
872 \ekvo@process@common{\ekvo@ifx@F\@classoptionslist\relax}%
873 {%
874 \ekvo@set@handlers@global
875 \ekvo@process@list\@classoptionslist
876 \let\ekvo@handle@defined@k\@gobble
877 \let\ekvo@handle@defined@kv\@gobbletwo
878 }%
879 }
880 % \end{macrocode}
881 % \end{macro}
882 % \begin{macro}{\ekvoProcessUnusedGlobalOptions}
883 % \begin{macrocode}
884 \protected\def\ekvoProcessUnusedGlobalOptions
885 {%
886 \ekvo@process@common{\ekvo@ifx@F\@unusedoptionlist\@empty}%
887 {%
888 \let\ekvo@tmp@list\@unusedoptionlist
889 \ekvo@set@handlers@unusedglobal
890 \ekvo@process@list\ekvo@tmp@list
891 \let\ekvo@handle@defined@k\@gobble
892 \let\ekvo@handle@defined@kv\@gobbletwo
893 }%
894 }
895 % \end{macrocode}
896 % \end{macro}
897 % \begin{macro}{\ekvoProcessOptionsList}
898 % \begin{macrocode}
899 \protected\def\ekvoProcessOptionsList#1%
900 {%
901 \ekvo@process@common{\ekvo@ifx@F#1\@empty}%
902 {%
903 \ekvo@set@handlers@list
904 \ekvo@process@list#1%
905 }%
906 }
907 % \end{macrocode}
908 % \end{macro}
909 % \begin{macro}{\ekvoUseUnknownHandlers}
910 % \begin{macrocode}
911 \protected\def\ekvoUseUnknownHandlers#1#2%
912 {%
913 \let\ekvo@handle@undefined@k#1\relax
914 \let\ekvo@handle@undefined@kv#2\relax
915 \let\ekvo@if@need@handlers\ekvo@dont@need@handlers
916 }
917 % \end{macrocode}
918 % \end{macro}
919 %
920 % All user interface macros should be only used in the preamble.
921 % \begin{macrocode}
922 \@onlypreamble\ekvoProcessLocalOptions
923 \@onlypreamble\ekvoProcessGlobalOptions
924 \@onlypreamble\ekvoProcessUnusedGlobalOptions
925 \@onlypreamble\ekvoProcessOptionsList
926 \@onlypreamble\ekvoUseUnknownHandlers
927 % \end{macrocode}
928 %
929 % \gobbledocstriptag
930 %</pkg>
931 %
932 % \end{implementation}^^A=<<
933 %
934 % \clearpage
935 % \PrintIndex
936 %
937 % \Finale
938 \endinput
939 %
940 ^^A vim: ft=tex fdm=marker fmr=>>=,=<<