Debian Codegraph @

texmf-dist/source/latex/expkv-bundle/expkv-cs.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: expkv-cs.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\expkvDocNoGenerate{}
16 \input expkv-bundle.ins
17 \generate{\file{expkv-cs.sty}{\from{expkv-cs.dtx}{pkg}}}
18 \generate{\file{expkv-cs.tex}{\from{expkv-cs.dtx}{tex}}}
19 \generate{\file{t-expkv-cs.tex}{\from{expkv-cs.dtx}{ctx}}}
20 \endbatchfile
21 %</driver>^^A=<<
22 % \fi
23 %
24 % \section{\expkvc}
25 %^^A the LaTeX package >>=
26 % \subsection{The \LaTeX\ Package}
27 % Just like for \expkv\ we provide a small \LaTeX\ package that sets up things
28 % such that we behave nicely on \LaTeX\ packages and files system. It'll
29 % |\input| the generic code which implements the functionality.
30 % \gobbledocstriptag
31 %<*pkg>
32 % \begin{macrocode}
33 \RequirePackage{expkv-pop}
34 \def\ekvc@tmp
35 {%
36 \ProvidesFile{expkv-cs.tex}%
37 [%
38 \ekvcDate\space v\ekvcVersion\space
39 define expandable key=val macros using expkv%
40 ]%
41 }
42 \input{expkv-cs.tex}
43 \ProvidesPackage{expkv-cs}%
44 [%
45 \ekvcDate\space v\ekvcVersion\space
46 define expandable key=val macros using expkv%
47 ]
48 % \end{macrocode}
49 % \gobbledocstriptag
50 %</pkg>
51 %^^A=<<
52 %^^A the ConTeXt module >>=
53 % \subsection{The \ConTeXt\ module}
54 % \gobbledocstriptag
55 %<*ctx>
56 % \begin{macrocode}
57 \writestatus{loading}{ConTeXt User Module / expkv-cs}
58 \usemodule[expkv-pop]
59 \unprotect
60 \input expkv-cs.tex
61 \writestatus{loading}
62 {ConTeXt User Module / expkv-cs / Version \ekvcVersion\space loaded}
63 \protect\endinput
64 % \end{macrocode}
65 % \gobbledocstriptag
66 %</ctx>
67 %^^A=<<
68 %^^A main file >>=
69 % \subsection{The Generic Code}
70 % The rest of this implementation will be the generic code.
71 % \gobbledocstriptag
72 %<*tex>
73 %
74 % Load \expkv\ if the package didn't already do so -- since \expkv\ has
75 % safeguards against being loaded twice this does no harm and the overhead
76 % isn't that big. Also we reuse some of the internals of \expkv\ to save us from
77 % retyping them.
78 % \begin{macrocode}
79 \input expkv-pop
80 % \end{macrocode}
81 %
82 % We make sure that \file{expkv-cs.tex} is only input once:
83 % \begin{macrocode}
84 \expandafter\ifx\csname ekvcVersion\endcsname\relax
85 \else
86 \expandafter\endinput
87 \fi
88 % \end{macrocode}
89 %
90 % \begin{macro}{\ekvcVersion,\ekvcDate}
91 % We're on our first input, so lets store the version and date in a macro.
92 % \begin{macrocode}
93 \def\ekvcVersion{1.4}
94 \def\ekvcDate{2024-12-16}
95 % \end{macrocode}
96 % \end{macro}
97 %
98 % If the \LaTeX\ format is loaded we want to be a good file and report back who
99 % we are, for this the package will have defined |\ekvc@tmp| to use
100 % |\ProvidesFile|, else this will expand to a |\relax| and do no harm.
101 % \begin{macrocode}
102 \csname ekvc@tmp\endcsname
103 % \end{macrocode}
104 %
105 % Store the category code of |@| to later be able to reset it and change it to
106 % 11 for now.
107 % \begin{macrocode}
108 \expandafter\chardef\csname ekvc@tmp\endcsname=\catcode`\@
109 \catcode`\@=11
110 % \end{macrocode}
111 % |\ekvc@tmp| will be reused later, but we don't need it to ever store
112 % information long-term after \expkvc\ was initialized.
113 %
114 % \begin{macro}[internal]{\ekvc@tripledots}
115 % This macro just serves as a marker for a comparison to allow the syntax
116 % for the unknown key handlers.
117 % \begin{macrocode}
118 \edef\ekvc@tripledots{\detokenize{...}}
119 % \end{macrocode}
120 % \end{macro}
121 %
122 % \begin{macro}[internal]{\ekvc@keycount}
123 % We'll need to keep count how many keys must be defined for each macro in the
124 % |split| variants.
125 % \begin{macrocode}
126 \newcount\ekvc@keycount
127 % \end{macrocode}
128 % \end{macro}
129 %
130 % \begin{macro}[internal]{\ekvc@long,\ekvc@any@long}
131 % Some macros will have to be defined long. These two will be let to |\long|
132 % when this should be the case.
133 % \begin{macrocode}
134 \let\ekvc@long\ekv@empty
135 \let\ekvc@any@long\ekv@empty
136 % \end{macrocode}
137 % \end{macro}
138 %
139 % \begin{macro}[internal]{\ekvc@ifdefined}
140 % We want to test whether a macro is already defined. This test checks for a
141 % defined macro that isn't |\relax|.
142 % \begin{macrocode}
143 \long\def\ekvc@ifdefined#1%
144 {%
145 \ifdefined#1%
146 \ifx\relax#1%
147 \ekv@fi@gobble
148 \fi
149 \@firstofone
150 \ekv@fi@firstoftwo
151 \fi
152 \@secondoftwo
153 }
154 % \end{macrocode}
155 % \end{macro}
156 %
157 % \begin{macro}[internal]
158 % {
159 % \ekvc@ekvset@pre@expander,
160 % \ekvc@ekvset@pre@expander@a,
161 % \ekvc@ekvset@pre@expander@b
162 % }
163 % This macro expands |\ekvset| twice so that the first two steps of expansion
164 % don't have to be made every time the \expkvc\ macros are used. We have to do
165 % a little magic trick to get the macro parameter |#1| for the macro
166 % definition this is used in, even though we're calling |\unexpanded|. We do
167 % that by splitting the expanded |\ekvset| at some marks and place |##1| in
168 % between. At this spot we also add |\ekv@alignsafe| and |\ekv@endalignsafe|
169 % to ensure that macros created with \expkvc\ are alignment safe.
170 % \begin{macrocode}
171 \def\ekvc@ekvset@pre@expander#1%
172 {%
173 \expandafter\ekvc@ekvset@pre@expander@a\ekvset{#1}\ekvc@stop\ekvc@stop
174 }
175 \def\ekvc@ekvset@pre@expander@a
176 {%
177 \expandafter\ekvc@ekvset@pre@expander@b
178 }
179 \def\ekvc@ekvset@pre@expander@b#1\ekvc@stop#2\ekvc@stop
180 {%
181 \ekv@unexpanded\expandafter{\ekv@alignsafe}%
182 \ekv@unexpanded{#1}##1\ekv@unexpanded{#2}%
183 \ekv@unexpanded\expandafter{\ekv@endalignsafe}%
184 }
185 % \end{macrocode}
186 % \end{macro}
187 %
188 % \begin{macro}{\ekvcSplitAndUse}
189 % The first user macro we want to set up can be reused for
190 % \cs[no-index]{ekvcSplitAndForward} and \cs[no-index]{ekvcSplit}. We'll split
191 % this one up so that the test whether the macro is already defined doesn't
192 % run twice.
193 % \begin{macrocode}
194 \protected\long\def\ekvcSplitAndUse#1#2%
195 {%
196 \let\ekvc@helpers@needed\@firstoftwo
197 \ekvc@ifdefined#1%
198 {\ekvc@err@already@defined#1}%
199 {\ekvcSplitAndUse@#1{}{#2}}%
200 }
201 % \end{macrocode}
202 % \end{macro}
203 %
204 % \begin{macro}[internal]{\ekvcSplitAndUse@}
205 % The actual macro setting up things. We need to set some variables, forward
206 % the key list to |\ekvc@SetupSplitKeys|, and afterwards define the front
207 % facing macro to call |\ekvset| and put the initials and the argument sorting
208 % macro behind it. The internals |\ekvc@any@long|, |\ekvc@initials| and
209 % |\ekvc@keycount| will be set correctly by |\ekvc@SetupSplitKeys|.
210 % \begin{macrocode}
211 \protected\long\def\ekvcSplitAndUse@#1#2#3%
212 {%
213 \edef\ekvc@set{\string#1}%
214 \ekvc@SetupSplitKeys{#3}%
215 \ekvc@helpers@needed
216 {%
217 \ekvc@any@long\edef#1##1%
218 {%
219 \expandafter\ekvc@ekvset@pre@expander\expandafter{\ekvc@set}%
220 \ekv@unexpanded\expandafter
221 {\csname ekvc@split@\the\ekvc@keycount\endcsname}%
222 \ekv@unexpanded\expandafter{\ekvc@initials{}#2}%
223 }%
224 }%
225 {%
226 \ekvc@any@long\edef#1##1%
227 {%
228 \expandafter\ekvc@ekvset@pre@expander\expandafter{\ekvc@set}%
229 \ekv@unexpanded{#2}%
230 \ekv@unexpanded\expandafter{\ekvc@initials}%
231 }%
232 }%
233 }
234 % \end{macrocode}
235 % \end{macro}
236 %
237 %
238 % \begin{macro}{\ekvcSplitAndForward}
239 % This just reuses |\ekvcSplitAndUse@| with a non-empty second argument,
240 % resulting in that argument to be called after the splitting.
241 % \begin{macrocode}
242 \protected\long\def\ekvcSplitAndForward#1#2#3%
243 {%
244 \let\ekvc@helpers@needed\@firstoftwo
245 \ekvc@ifdefined#1%
246 {\ekvc@err@already@defined#1}%
247 {\ekvcSplitAndUse@#1{{#2}}{#3}}%
248 }
249 % \end{macrocode}
250 % \end{macro}
251 %
252 % \begin{macro}{\ekvcSplit}
253 % The first half is just |\ekvcSplitAndForward| then we define the macro to
254 % which the parsed key list is forwarded. There we need to allow for up to
255 % nine arguments.
256 % \begin{macrocode}
257 \protected\long\def\ekvcSplit#1#2#3%
258 {%
259 \let\ekvc@helpers@needed\@secondoftwo
260 \ekvc@ifdefined#1%
261 {\ekvc@err@already@defined#1}%
262 {%
263 \expandafter
264 \ekvcSplitAndUse@\expandafter#1\csname ekvc@\string#1\endcsname{#2}%
265 \ifnum\ekvc@keycount<1
266 \ekvc@any@long\expandafter\def\csname ekvc@\string#1\endcsname{#3}%
267 \else
268 \ifnum\ekvc@keycount>9
269 \ekvc@err@toomany{#1}%
270 \let#1\ekvc@undefined
271 \else
272 \ekvcSplit@build@argspec
273 \ekvc@any@long\expandafter
274 \def\csname ekvc@\string#1\expandafter\endcsname\ekvc@tmp{#3}%
275 \fi
276 \fi
277 }%
278 }
279 % \end{macrocode}
280 % \end{macro}
281 %
282 % \begin{macro}[internal]{\ekvcSplit@build@argspec,\ekvcSplit@build@argspec@}
283 % \begin{macrocode}
284 \protected\def\ekvcSplit@build@argspec
285 {%
286 \begingroup
287 \edef\ekvc@tmp
288 {\endgroup\def\ekv@unexpanded{\ekvc@tmp}{\ekvcSplit@build@argspec@{1}}}%
289 \ekvc@tmp
290 }
291 \def\ekvcSplit@build@argspec@#1%
292 {%
293 \ifnum#1>\ekvc@keycount
294 \ekv@fi@gobble
295 \fi
296 \@firstofone
297 {%
298 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@#1\endcsname####}#1%
299 \expandafter\ekvcSplit@build@argspec@\expandafter{\the\numexpr#1+1}%
300 }%
301 }
302 % \end{macrocode}
303 % \end{macro}
304 %
305 % \begin{macro}[internal]
306 % {
307 % \ekvc@SetupSplitKeys, \ekvc@SetupSplitKeys@a, \ekvc@SetupSplitKeys@b,
308 % \ekvc@SetupSplitKeys@unknown
309 % }
310 % These macros parse the list of keys and set up the key macros. First we need
311 % to initialise some macros and start an \expkvp\ parser.
312 % \begin{macrocode}
313 \protected\long\def\ekvc@SetupSplitKeys
314 {%
315 \ekvc@keycount=\ekv@zero
316 \let\ekvc@any@long\ekv@empty
317 \let\ekvc@initials\ekv@empty
318 \ekvpParse@unsafe\ekvp@@p@ekvc@setup@splitkeys
319 }
320 % \end{macrocode}
321 % We're calling a parser here without the safety nets testing for parser
322 % existence, so better define it now.
323 % \begin{macrocode}
324 \ekvpNewParser{ekvc@setup@splitkeys}
325 \ekvpDefType{ekvc@setup@splitkeys}{short}
326 {%
327 \let\ekvc@long\ekv@empty
328 \expandafter\ekvc@SetupSplitKeys@a\detokenize{#1}\ekv@stop{#3}%
329 }
330 \ekvpDefType{ekvc@setup@splitkeys}{long}
331 {%
332 \let\ekvc@long\long
333 \let\ekvc@any@long\long
334 \expandafter\ekvc@SetupSplitKeys@a\detokenize{#1}\ekv@stop{#3}%
335 }
336 \ekvpDefNoType{ekvc@setup@splitkeys}
337 {%
338 \let\ekvc@long\ekv@empty
339 \expandafter\ekvc@SetupSplitKeys@a\detokenize{#1}\ekv@stop{#3}%
340 }
341 % \end{macrocode}
342 % If no value was provided this could either be an error, or the unknown key
343 % forwarding. We have to check this (comparing against |...| inside
344 % |\ekvc@tripledots|) and if this is the unknown key list type, set it up
345 % accordingly (advancing the key count and setting up the unknown handlers of
346 % \expkv). Else we simply throw an error and ignore the incident.
347 % \begin{macrocode}
348 \ekvpDefNoValue{ekvc@setup@splitkeys}
349 {%
350 \begingroup
351 \edef\ekvc@tmp{\detokenize{#1}}%
352 \expandafter
353 \endgroup
354 \ifx\ekvc@tripledots\ekvc@tmp
355 \advance\ekvc@keycount1
356 % \end{macrocode}
357 % The |\begingroup\expandafter\endgroup| ensures that the split mark isn't
358 % actually defined (even if it just were with meaning |\relax|).
359 % \begin{macrocode}
360 \begingroup\expandafter\endgroup
361 \expandafter\ekvc@SetupSplitKeys@unknown
362 \csname ekvc@splitmark@\the\ekvc@keycount\endcsname
363 \let\ekvc@any@long\long
364 \else
365 \ekvc@err@value@required{#1}%
366 \fi
367 }
368 % \end{macrocode}
369 %
370 % Now everything is parsed down to the point that we got the key name and its
371 % value. We step the key counter and build the mark within a group to not
372 % accidentally define the |\csname|.
373 % \begin{macrocode}
374 \protected\long\def\ekvc@SetupSplitKeys@a
375 {%
376 \advance\ekvc@keycount1
377 \begingroup\expandafter\endgroup
378 \expandafter\ekvc@SetupSplitKeys@b
379 \csname ekvc@splitmark@\the\ekvc@keycount\endcsname
380 }
381 \protected\long\def\ekvc@SetupSplitKeys@b#1#2\ekv@stop#3%
382 {%
383 \long\def\ekvc@tmp##1##2#1##3{##2#1{##1}}%
384 % \end{macrocode}
385 % The short variant needs a bit of special treatment. The key macro will be
386 % short to throw the correct error, but since there might be long macros
387 % somewhere the reordering of arguments needs to be long, so for short keys we
388 % use a two step approach, first grabbing only the short argument, then
389 % reordering.
390 % \begin{macrocode}
391 \ifx\ekvc@long\long
392 \else
393 \expandafter\let\csname ekvc@\ekvc@set(#2)\endcsname\ekvc@tmp
394 \edef\ekvc@tmp##1%
395 {%
396 \ekv@unexpanded\expandafter{\csname ekvc@\ekvc@set(#2)\endcsname}%
397 {##1}%
398 }%
399 \fi
400 \ekvlet\ekvc@set{#2}\ekvc@tmp
401 \edef\ekvc@initials{\ekv@unexpanded\expandafter{\ekvc@initials#1{#3}}}%
402 \ekvc@helpers@needed
403 {\expandafter\ekvc@setup@splitmacro\expandafter{\the\ekvc@keycount}}%
404 {}%
405 }
406 % \end{macrocode}
407 %
408 % Here we get everything readily set up, |#1| contains the mark for unknown
409 % keys and they only have to do some reordering.
410 % \begin{macrocode}
411 \protected\long\def\ekvc@SetupSplitKeys@unknown#1%
412 {%
413 \long\def\ekvc@tmp##1##2##3##4#1##5{##4#1{##5, {##3} = {##1} }}%
414 \ekvletunknown\ekvc@set\ekvc@tmp
415 \long\def\ekvc@tmp##1##2##3#1##4{##3#1{##4, {##2} }}%
416 \ekvletunknownNoVal\ekvc@set\ekvc@tmp
417 \edef\ekvc@initials{\ekv@unexpanded\expandafter{\ekvc@initials#1{}}}%
418 \ekvc@helpers@needed
419 {\expandafter\ekvc@setup@splitmacro\expandafter{\the\ekvc@keycount}}%
420 {}%
421 }
422 % \end{macrocode}
423 % \end{macro}
424 %
425 % \begin{macro}[internal]{\ekvc@defarggobbler}
426 % This is needed to define a macro with 1-9 parameters programmatically.
427 % \LaTeX's \cs[no-index]{newcommand} does something similar for example.
428 % \begin{macrocode}
429 \protected\def\ekvc@defarggobbler#1{\def\ekvc@tmp##1#1##2##{##1#1}}
430 % \end{macrocode}
431 % \end{macro}
432 %
433 % \begin{macro}[internal]
434 % {
435 % \ekvc@setup@splitmacro,
436 % \ekvc@split@1, \ekvc@split@2, \ekvc@split@3,
437 % \ekvc@split@4, \ekvc@split@5, \ekvc@split@6,
438 % \ekvc@split@7
439 % }
440 % Since the first few split macros are different from the others we manually
441 % set those up now. All the others will be defined as needed (always
442 % globally). The split macros just read up until the correct split mark, move
443 % that argument into a list and reinsert the rest, calling the next split
444 % macro afterwards.
445 % \begin{macrocode}
446 \begingroup
447 \edef\ekvc@tmp
448 {%
449 \long\gdef\ekv@unexpanded\expandafter{\csname ekvc@split@1\endcsname}%
450 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@1\endcsname}##1%
451 ##2##3%
452 {##3{##1}##2}%
453 \long\gdef\ekv@unexpanded\expandafter{\csname ekvc@split@2\endcsname}%
454 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@1\endcsname}##1%
455 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@2\endcsname}##2%
456 ##3##4%
457 {##4{##1}{##2}##3}%
458 \long\gdef\ekv@unexpanded\expandafter{\csname ekvc@split@3\endcsname}%
459 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@1\endcsname}##1%
460 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@2\endcsname}##2%
461 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@3\endcsname}##3%
462 ##4##5%
463 {##5{##1}{##2}{##3}##4}%
464 \long\gdef\ekv@unexpanded\expandafter{\csname ekvc@split@4\endcsname}%
465 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@1\endcsname}##1%
466 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@2\endcsname}##2%
467 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@3\endcsname}##3%
468 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@4\endcsname}##4%
469 ##5##6%
470 {##6{##1}{##2}{##3}{##4}##5}%
471 \long\gdef\ekv@unexpanded\expandafter{\csname ekvc@split@5\endcsname}%
472 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@1\endcsname}##1%
473 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@2\endcsname}##2%
474 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@3\endcsname}##3%
475 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@4\endcsname}##4%
476 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@5\endcsname}##5%
477 ##6##7%
478 {##7{##1}{##2}{##3}{##4}{##5}##6}%
479 \long\gdef\ekv@unexpanded\expandafter{\csname ekvc@split@6\endcsname}%
480 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@1\endcsname}##1%
481 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@2\endcsname}##2%
482 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@3\endcsname}##3%
483 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@4\endcsname}##4%
484 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@5\endcsname}##5%
485 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@6\endcsname}##6%
486 ##7##8%
487 {##8{##1}{##2}{##3}{##4}{##5}{##6}##7}%
488 \long\gdef\ekv@unexpanded\expandafter{\csname ekvc@split@7\endcsname}%
489 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@1\endcsname}##1%
490 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@2\endcsname}##2%
491 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@3\endcsname}##3%
492 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@4\endcsname}##4%
493 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@5\endcsname}##5%
494 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@6\endcsname}##6%
495 \ekv@unexpanded\expandafter{\csname ekvc@splitmark@7\endcsname}##7%
496 ##8##9%
497 {##9{##1}{##2}{##3}{##4}{##5}{##6}{##7}##8}%
498 }
499 \ekvc@tmp
500 \endgroup
501 \protected\def\ekvc@setup@splitmacro#1%
502 {%
503 \ekv@ifdefined{ekvc@split@#1}{}%
504 {%
505 \begingroup
506 \def\ekvc@tmp##1%
507 {%
508 \ekv@unexpanded\expandafter
509 {\csname ekvc@splitmark@\the\numexpr#1-##1\relax\endcsname}%
510 }%
511 \edef\ekvc@tmp
512 {%
513 \long\gdef
514 \ekv@unexpanded\expandafter{\csname ekvc@split@#1\endcsname}%
515 ####1%
516 \ekvc@tmp{6}####2%
517 \ekvc@tmp{5}####3%
518 \ekvc@tmp{4}####4%
519 \ekvc@tmp{3}####5%
520 \ekvc@tmp{2}####6%
521 \ekvc@tmp{1}####7%
522 \ekvc@tmp{0}####8%
523 ####9%
524 {%
525 \ekv@unexpanded\expandafter
526 {\csname ekvc@split@\the\numexpr#1-7\relax\endcsname}%
527 ####1{{####2}{####3}{####4}{####5}{####6}{####7}{####8}####9}%
528 }%
529 }%
530 \ekvc@tmp
531 \endgroup
532 }%
533 }
534 % \end{macrocode}
535 % \end{macro}
536 %
537 % \begin{macro}{\ekvcHashAndUse}
538 % |\ekvcHashAndUse| works just like |\ekvcSplitAndUse|.
539 % \begin{macrocode}
540 \protected\long\def\ekvcHashAndUse#1#2%
541 {%
542 \let\ekvc@helpers@needed\@firstoftwo
543 \ekvc@ifdefined#1%
544 {\ekvc@err@already@defined#1}%
545 {\ekvcHashAndUse@#1{}{#2}}%
546 }
547 % \end{macrocode}
548 % \end{macro}
549 %
550 % \begin{macro}[internal]{\ekvcHashAndUse@}
551 % This is more or less the same as |\ekvcSplitAndUse@|. Instead of an empty
552 % group we place a marker after the initials, we don't use the sorting macros
553 % of |split|, but instead pack all the values in one argument.
554 % \begin{macrocode}
555 \protected\long\def\ekvcHashAndUse@#1#2#3%
556 {%
557 \edef\ekvc@set{\string#1}%
558 \ekvc@SetupHashKeys{#3}%
559 \ekvc@helpers@needed
560 {%
561 \ekvc@any@long\edef#1##1%
562 {%
563 \expandafter\ekvc@ekvset@pre@expander\expandafter{\ekvc@set}%
564 \ekv@unexpanded{\ekvc@hash@pack@argument}%
565 \ekv@unexpanded\expandafter{\ekvc@initials\ekvc@stop#2}%
566 }%
567 }%
568 {%
569 \ekvc@any@long\edef#1##1%
570 {%
571 \expandafter\ekvc@ekvset@pre@expander\expandafter{\ekvc@set}%
572 \ekv@unexpanded{#2}%
573 \ekv@unexpanded\expandafter{\ekvc@initials\ekvc@stop}%
574 }%
575 }%
576 }
577 % \end{macrocode}
578 % \end{macro}
579 %
580 % \begin{macro}{\ekvcHashAndForward}
581 % |\ekvcHashAndForward| works just like |\ekvcSplitAndForward|.
582 % \begin{macrocode}
583 \protected\long\def\ekvcHashAndForward#1#2#3%
584 {%
585 \let\ekvc@helpers@needed\@firstoftwo
586 \ekvc@ifdefined#1%
587 {\ekvc@err@already@defined#1}%
588 {\ekvcHashAndUse@#1{{#2}}{#3}}%
589 }
590 % \end{macrocode}
591 % \end{macro}
592 %
593 % \begin{macro}{\ekvcHash}
594 % |\ekvcHash| does the same as |\ekvcSplit|, but has the advantage of not
595 % needing to count arguments, so the definition of the internal macro is a bit
596 % more straight forward.
597 % \begin{macrocode}
598 \protected\long\def\ekvcHash#1#2#3%
599 {%
600 \let\ekvc@helpers@needed\@secondoftwo
601 \ekvc@ifdefined#1%
602 {\ekvc@err@already@defined#1}%
603 {%
604 \expandafter
605 \ekvcHashAndUse@\expandafter#1\csname ekvc@\string#1\endcsname{#2}%
606 \ekvc@any@long\expandafter\def\csname ekvc@\string#1\endcsname
607 ##1\ekvc@stop
608 {#3}%
609 }%
610 }
611 % \end{macrocode}
612 % \end{macro}
613 %
614 % \begin{macro}[internal]{\ekvc@hash@pack@argument}
615 % All this macro does is pack the values into one argument and forward that to
616 % the next macro.
617 % \begin{macrocode}
618 \long\def\ekvc@hash@pack@argument#1\ekvc@stop#2{#2{#1}}
619 % \end{macrocode}
620 % \end{macro}
621 %
622 % \begin{macro}[internal]
623 % {
624 % \ekvc@SetupHashKeys,\ekvc@SetupHashKeys@a,\ekvc@SetupHashKeys@b,
625 % \ekvc@SetupHashKeys@unknown
626 % }
627 % This should look awfully familiar as well, since it's just the same as for
628 % the split keys with a few other names here and there.
629 % \begin{macrocode}
630 \protected\long\def\ekvc@SetupHashKeys
631 {%
632 \let\ekvc@any@long\ekv@empty
633 \let\ekvc@initials\ekv@empty
634 \ekvpParse@unsafe\ekvp@@p@ekvc@setup@hashkeys
635 }
636 \ekvpNewParser{ekvc@setup@hashkeys}
637 \ekvpDefType{ekvc@setup@hashkeys}{short}
638 {%
639 \let\ekvc@long\ekv@empty
640 \expandafter\ekvc@SetupHashKeys@a\detokenize{#1}\ekv@stop{#3}%
641 }
642 \ekvpDefType{ekvc@setup@hashkeys}{long}
643 {%
644 \let\ekvc@long\long
645 \let\ekvc@any@long\long
646 \expandafter\ekvc@SetupHashKeys@a\detokenize{#1}\ekv@stop{#3}%
647 }
648 \ekvpDefNoType{ekvc@setup@hashkeys}
649 {%
650 \let\ekvc@long\ekv@empty
651 \expandafter\ekvc@SetupHashKeys@a\detokenize{#1}\ekv@stop{#3}%
652 }
653 \ekvpDefNoValue{ekvc@setup@hashkeys}
654 {%
655 \begingroup
656 \edef\ekvc@tmp{\detokenize{#1}}%
657 \expandafter
658 \endgroup
659 \ifx\ekvc@tripledots\ekvc@tmp
660 \ekvc@SetupHashKeys@unknown
661 \let\ekvc@any@long\long
662 \else
663 \ekvc@err@value@required{#1}%
664 \fi
665 }
666 % \end{macrocode}
667 % Again we build the marker, this time instead of a numbered one a named
668 % hashmark, inside a group to not actually define the macro used as a marker.
669 % \begin{macrocode}
670 \protected\long\def\ekvc@SetupHashKeys@a#1\ekv@stop
671 {%
672 \begingroup\expandafter\endgroup
673 \expandafter\ekvc@SetupHashKeys@b\csname ekvc@hashmark@#1\endcsname{#1}%
674 }
675 % \end{macrocode}
676 % Yes, even the defining macro looks awfully familiar. Instead of numbered we
677 % have named marks. Still the key macros grab everything up to their
678 % respective mark and reorder the arguments. The same quirk is applied for
679 % short keys. And instead of the |\ekvc@setup@splitmacro| we use
680 % |\ekvc@setup@hashmacro|.
681 % \begin{macrocode}
682 \protected\long\def\ekvc@SetupHashKeys@b#1#2#3%
683 {%
684 \long\def\ekvc@tmp##1##2#1##3{##2#1{##1}}%
685 \ifx\ekvc@long\long
686 \else
687 \expandafter\let\csname ekvc@\ekvc@set(#2)\endcsname\ekvc@tmp
688 \edef\ekvc@tmp##1%
689 {%
690 \ekv@unexpanded\expandafter{\csname ekvc@\ekvc@set(#2)\endcsname}%
691 {##1}%
692 }%
693 \fi
694 \ekvlet\ekvc@set{#2}\ekvc@tmp
695 \edef\ekvc@initials{\ekv@unexpanded\expandafter{\ekvc@initials#1{#3}}}%
696 \ekvc@setup@hashmacro{#2}%
697 }
698 % \end{macrocode}
699 % Another temporary definition, this time to get the hashmarks for the unknown
700 % handler without defining them.
701 % \begin{macrocode}
702 \def\ekvc@SetupHashKeys@unknown#1%
703 {%
704 \protected\def\ekvc@SetupHashKeys@unknown
705 {%
706 \ekvletunknown\ekvc@set\ekvc@hash@unknown@kv
707 \ekvletunknownNoVal\ekvc@set\ekvc@hash@unknown@k
708 \edef\ekvc@initials{\ekv@unexpanded\expandafter{\ekvc@initials#1{}}}%
709 \ekvc@setup@hashmacro{...}%
710 }%
711 \long\def\ekvc@hash@unknown@kv##1##2##3##4#1##5{##4#1{##5, {##3} = {##1} }}%
712 \long\def\ekvc@hash@unknown@k##1##2##3#1##4{##3#1{##4, {##2} }}%
713 }
714 \begingroup\expandafter\endgroup
715 \expandafter\ekvc@SetupHashKeys@unknown
716 \csname ekvc@hashmark@\ekvc@tripledots\endcsname
717 % \end{macrocode}
718 % \end{macro}
719 %
720 % \begin{macro}[internal]{\ekvc@setup@hashmacro}
721 % The safe hash macros will be executed inside of an |\unexpanded| expansion
722 % context, so they have to insert braces for that once they are done.
723 % Most of the tests which have to be executed will already be done, but we
724 % have to play safe if the hash doesn't show up in the hash list. Therefore we
725 % use some |\ekvc@mark|s and |\ekvc@stop| to throw errors if the hash isn't
726 % found in the right place. The fast variants have an easier life and just
727 % return the correct value.
728 % \begin{macrocode}
729 \protected\def\ekvc@setup@hashmacro#1%
730 {%
731 \ekv@ifdefined{ekvc@fasthash@#1}{}%
732 {%
733 \begingroup
734 \edef\ekvc@tmp
735 {%
736 \long\gdef
737 \ekv@unexpanded\expandafter{\csname ekvc@fasthash@#1\endcsname}%
738 ####1%
739 \ekv@unexpanded\expandafter
740 {\csname ekvc@hashmark@#1\endcsname}%
741 ####2####3\ekv@unexpanded{\ekvc@stop}%
742 {####2}%
743 \long\gdef
744 \ekv@unexpanded\expandafter{\csname ekvc@safehash@#1\endcsname}%
745 ####1%
746 {%
747 \ekv@unexpanded\expandafter
748 {\csname ekvc@@safehash@#1\endcsname}%
749 ####1\ekv@unexpanded{\ekvc@mark}{}%
750 \ekv@unexpanded\expandafter
751 {%
752 \csname ekvc@hashmark@#1\endcsname{}%
753 \ekvc@mark{\ekvc@err@missing@hash{#1}}\ekvc@stop
754 }%
755 }%
756 \long\gdef
757 \ekv@unexpanded\expandafter
758 {\csname ekvc@@safehash@#1\endcsname}%
759 ####1%
760 \ekv@unexpanded\expandafter
761 {\csname ekvc@hashmark@#1\endcsname}%
762 ####2####3\ekv@unexpanded{\ekvc@mark}####4####5%
763 \ekv@unexpanded{\ekvc@stop}%
764 {%
765 ####4{####2}%
766 }%
767 \long\gdef\ekv@unexpanded\expandafter
768 {\csname ekvc@fastsplithash@#1\endcsname}%
769 ####1%
770 \ekv@unexpanded\expandafter
771 {\csname ekvc@hashmark@#1\endcsname}%
772 ####2####3\ekv@unexpanded{\ekvc@stop}####4%
773 {%
774 ####4{####2}%
775 }%
776 \long\gdef\ekv@unexpanded\expandafter
777 {\csname ekvc@safesplithash@#1\endcsname}####1%
778 {%
779 \ekv@unexpanded\expandafter
780 {\csname ekvc@@safesplithash@#1\endcsname}%
781 ####1\ekv@unexpanded{\ekvc@mark\ekvc@safe@after@hash}%
782 \ekv@unexpanded\expandafter
783 {%
784 \csname ekvc@hashmark@#1\endcsname{}%
785 \ekvc@mark
786 {\ekvc@err@missing@hash{#1}\ekvc@safe@after@hash}%
787 \ekvc@stop
788 }%
789 }%
790 \long\gdef\ekv@unexpanded\expandafter
791 {\csname ekvc@@safesplithash@#1\endcsname}%
792 ####1%
793 \ekv@unexpanded\expandafter
794 {\csname ekvc@hashmark@#1\endcsname}%
795 ####2####3\ekv@unexpanded{\ekvc@mark}####4####5%
796 \ekv@unexpanded{\ekvc@stop}%
797 {%
798 ####4{####2}%
799 }%
800 }%
801 \ekvc@tmp
802 \endgroup
803 }%
804 }
805 % \end{macrocode}
806 % \end{macro}
807 %
808 % \begin{macro}{\ekvcValue}
809 % \begin{macro}[internal]{\ekvcValue@}
810 % All this does is a few consistency checks on the first argument (not empty,
811 % hash macro exists) and then call that hash-grabbing macro that will also
812 % test whether the hash is inside of |#2| or not.
813 % \begin{macrocode}
814 \long\def\ekvcValue#1%
815 {%
816 \ekv@unexpanded
817 \expandafter\ekvcValue@\detokenize{#1}\ekvc@stop
818 }
819 \def\ekvcValue@#1\ekvc@stop
820 {%
821 \ekv@ifdefined{ekvc@safehash@#1}%
822 {\csname ekvc@safehash@#1\endcsname}%
823 {\ekvc@err@unknown@hash{#1}\@firstoftwo{{}}}%
824 }
825 % \end{macrocode}
826 % \end{macro}
827 % \end{macro}
828 %
829 % \begin{macro}{\ekvcValueFast}
830 % To be as fast as possible, this doesn't test for anything, assuming the user
831 % knows best.
832 % \begin{macrocode}
833 \long\def\ekvcValueFast#1#2%
834 {\csname ekvc@fasthash@\detokenize{#1}\endcsname#2\ekvc@stop}
835 % \end{macrocode}
836 % \end{macro}
837 %
838 % \begin{macro}{\ekvcValueSplit}
839 % \begin{macro}[internal]{\ekvcValueSplit@,\ekvcValueSplit@recover}
840 % This splits off a single value.
841 % \begin{macrocode}
842 \long\def\ekvcValueSplit#1%
843 {\expandafter\ekvcValueSplit@\detokenize{#1}\ekvc@stop}
844 \def\ekvcValueSplit@#1\ekvc@stop
845 {%
846 \ekv@ifdefined{ekvc@safesplithash@#1}%
847 {\csname ekvc@safesplithash@#1\endcsname}%
848 {\ekvc@err@unknown@hash{#1}\ekvcValueSplit@recover}%
849 }
850 \long\def\ekvcValueSplit@recover#1#2{#2{}}
851 % \end{macrocode}
852 % \end{macro}
853 % \end{macro}
854 %
855 % \begin{macro}[internal]{\ekvc@safe@after@hash}
856 % \begin{macrocode}
857 \long\def\ekvc@safe@after@hash#1#2%
858 {%
859 #2{#1}%
860 }
861 % \end{macrocode}
862 % \end{macro}
863 %
864 % \begin{macro}{\ekvcValueSplitFast}
865 % Again a fast approach which doesn't provide too many safety measurements.
866 % This needs to build the hash function and expand it before passing the
867 % results to the next control sequence. The first step only builds the control
868 % sequence.
869 % \begin{macrocode}
870 \long\def\ekvcValueSplitFast#1#2%
871 {\csname ekvc@fastsplithash@\detokenize{#1}\endcsname#2\ekvc@stop}
872 % \end{macrocode}
873 % \end{macro}
874 %
875 % \begin{macro}[internal]
876 % {
877 % \ekvc@safehash@,\ekvc@fasthash@,
878 % \ekvc@safesplithash@,\ekvc@fastsplithash@
879 % }
880 % At least in the empty hash case we can provide a meaningful error message
881 % without affecting performance by just defining the macro that would be build
882 % in that case. There is of course a downside to this, the error will not be
883 % thrown by |\ekvcValueFast| in three expansion steps. The safe hash variant
884 % has to also stop the |\unexpanded| expansion.
885 % \begin{macrocode}
886 \long\def\ekvc@safehash@#1{\ekvc@err@empty@hash{}}
887 \long\def\ekvc@fasthash@#1\ekvc@stop{\ekvc@err@empty@hash}
888 \long\def\ekvc@safesplithash@#1#2{\ekvc@err@empty@hash#2{}}
889 \long\def\ekvc@fastsplithash@#1\ekvc@stop#2{\ekvc@err@empty@hash#2{}}
890 % \end{macrocode}
891 % \end{macro}
892 %
893 % \begin{macro}{\ekvcSecondaryKeys}
894 % \begin{macro}[internal]
895 % {\ekvcSecondaryKeys@a,\ekvcSecondaryKeys@b,\ekvcSecondaryKeys@c}
896 % Secondary keys use yet another \expkvp\ parser, keys will be set up further
897 % down in their own subsection.
898 % \begin{macrocode}
899 \ekvpNewParser{ekvc@setup@secondary}
900 \ekvpValueAlwaysRequired{ekvc@setup@secondary}
901 \protected\long\def\ekvcSecondaryKeys#1%
902 {%
903 \edef\ekvc@set{\string#1}%
904 \let\ekvc@long\ekv@empty
905 \ekvpParse@unsafe\ekvp@@p@ekvc@setup@secondary
906 }
907 % \end{macrocode}
908 % \end{macro}
909 % \end{macro}
910 %
911 % \begin{macro}{\ekvcChange}
912 % This can be used to change the defaults of an \expkvc\ defined macro. It
913 % checks whether there is a set with the correct name and that the macro is
914 % defined. If both is true the real work is done by |\ekvc@change|.
915 % \begin{macrocode}
916 \protected\long\def\ekvcChange#1%
917 {%
918 \ekvifdefinedset{\string#1}%
919 {%
920 \ekvc@ifdefined#1%
921 {\ekvc@change#1}%
922 {\ekvc@err@no@key@macro#1\@gobble}%
923 }%
924 {\ekvc@err@no@key@macro#1\@gobble}%
925 }
926 % \end{macrocode}
927 % \end{macro}
928 %
929 % \begin{macro}[internal]
930 % {
931 % \ekvc@change ,\ekvc@change@a,\ekvc@change@b,
932 % \ekvc@change@c,\ekvc@change@d,\ekvc@change@e
933 % }
934 % First we need to see whether the macro is currently |\long|. For this we get
935 % the meaning and will parse it. |#1| is the macro name in which we want to
936 % change the defaults.
937 % \begin{macrocode}
938 \protected\def\ekvc@change#1%
939 {\expandafter\ekvc@change@a\meaning#1\ekv@stop#1}
940 % \end{macrocode}
941 % A temporary definition to get the stringified |macro:|. |##1| will be the
942 % list of prefixes, we don't care for the exact contents of |##2| and |##3|.
943 % \begin{macrocode}
944 \def\ekvc@change@a#1%
945 {%
946 \protected\def\ekvc@change@a##1#1##2->##3\ekv@stop
947 {%
948 \ekvc@change@iflong{##1}%
949 {\ekvc@change@b{}}%
950 {\ekvc@change@b{\long}}%
951 }%
952 }
953 \expandafter\ekvc@change@a\expandafter{\detokenize{macro:}}
954 % \end{macrocode}
955 % Next we expand the macro once to get its contents (including the current
956 % default values with their markers) and place |\ekvc@stop| instead of an
957 % argument as a marker for the last step. |#1| is either |\long| or empty,
958 % |#2| is the macro.
959 % \begin{macrocode}
960 \protected\def\ekvc@change@b#1#2%
961 {\expandafter\ekvc@change@c\expandafter{#2\ekvc@stop}{#1}#2}
962 % \end{macrocode}
963 % Here we place an unbalanced closing brace after the expansion of the macro.
964 % Then we just parse the \kv-list with |\ekvset|, that will exchange the
965 % values behind the markers. Once those are changed we give control to
966 % |\ekvc@change@d|. The |\ekvset| step might horribly fail if the user defined
967 % some keys that don't behave nice. |#1| is the expansion of the macro, |#2|
968 % is either |\long| or empty, |#3| is the macro, and |#4| is the \kv-list
969 % containing the new defaults.
970 % \begin{macrocode}
971 \ekv@exparg{\protected\long\def\ekvc@change@c#1#2#3#4}%
972 {%
973 \expandafter\iffalse\expandafter{\expandafter{\expandafter\fi
974 \ekvset{\string#3}{#4}%
975 \ekvc@change@d{#2}{#3}%
976 #1%
977 }}%
978 }
979 % \end{macrocode}
980 % The final step needs to put an unbalanced opening brace after |\edef|. Also
981 % we have to protect everything from further expanding with the exception of
982 % the redefined macro's argument, which is why we placed the |\ekvc@stop|
983 % earlier. Then we need to also protect the rest of the contents from further
984 % expanding using |\unexpanded| with another unbalanced opening brace.
985 % |#1| will be either empty or |\long| and |#2| is the macro.
986 % \begin{macrocode}
987 \protected\def\ekvc@change@d#1#2%
988 {#1\edef#2##1{\expandafter\ekvc@change@e\iffalse}\fi}
989 \long\def\ekvc@change@e#1\ekvc@stop
990 {\ekv@unexpanded{#1}##1\ekv@unexpanded\expandafter{\iffalse}\fi}
991 % \end{macrocode}
992 % \end{macro}
993 %
994 % \begin{macro}[internal]{\ekvc@change@iflong,\ekvc@change@iflong@}
995 % Checking whether a string contains the string representation of |\long| can
996 % be done by gobbling everything up to the first |\long| and checking whether
997 % the result is completely empty. We need a temporary macro to get the result
998 % of |\string\long| inside the definitions.
999 % \begin{macrocode}
1000 \def\ekvc@change@iflong#1%
1001 {%
1002 \protected\def\ekvc@change@iflong##1%
1003 {\expandafter\ekv@ifempty\expandafter{\ekvc@change@iflong@##1#1}}%
1004 \def\ekvc@change@iflong@##1#1{}
1005 }
1006 \expandafter\ekvc@change@iflong\expandafter{\string\long}
1007 % \end{macrocode}
1008 % \end{macro}
1009 %
1010 % \begin{macro}{\ekvcPass}
1011 % This macro can be used to pass a value to a key of some macro (this way
1012 % more complicated key codes are possible that in the end pass processed
1013 % values on to some macro). The implemantation is pretty straight forward.
1014 % \begin{macrocode}
1015 \long\def\ekvcPass#1#2%
1016 {%
1017 \ekvifdefined{\string#1}{#2}%
1018 {\csname\ekv@name{\string#1}{#2}\endcsname}%
1019 {\ekvc@err@unknown@key@or@macro{#1}{#2}\@gobble}%
1020 }
1021 % \end{macrocode}
1022 % \end{macro}
1023 %
1024 %
1025 % \subsubsection{Secondary Key Types}
1026 %
1027 % There is a single prefix named |long| and set up pretty simple.
1028 % \begin{macrocode}
1029 \ekvpDefPrefixLet{ekvc@setup@secondary}{long}\ekvc@long\long\ekv@empty
1030 % \end{macrocode}
1031 %
1032 % \begin{macro}[internal]
1033 % {
1034 % meta, nmeta,
1035 % \ekvc@type@meta, \ekvc@type@meta@
1036 % }
1037 % The |meta| and |nmeta| key types use |\ekvmorekv| to set other keys in
1038 % the same macro's \set. If the \kv\ list ist fixed (|nmeta|) we can expand
1039 % |\ekvmorekv| as far as possible (twice), else we expand it only once. This
1040 % makes a difference only if the \val\ of the |meta| key isn't forwarded in
1041 % braces and commas are active at the time of usage, in which case expanding
1042 % |\ekvmorekv| twice would result in wrong behaviour.
1043 % \begin{macrocode}
1044 \ekvpDefType{ekvc@setup@secondary}{meta}
1045 {\ekvc@type@meta\ekv@exparg\ekvc@long{##1}\ekvlet{#1}{#3}}
1046 \ekvpDefType{ekvc@setup@secondary}{nmeta}
1047 {\ekvc@assert@not@long\ekvc@type@meta\ekv@expargtwice{}{}\ekvletNoVal{#1}{#3}}
1048 \protected\long\def\ekvc@type@meta#1#2#3#4#5#6%
1049 {%
1050 #1\ekvc@type@meta@{\ekvmorekv{#6}}{#2}{#3}%
1051 #4\ekvc@set{#5}\ekvc@tmp
1052 }
1053 \protected\long\def\ekvc@type@meta@#1#2#3{#2\def\ekvc@tmp#3{#1}}
1054 % \end{macrocode}
1055 % \end{macro}
1056 %
1057 % \begin{macro}{alias}
1058 % |alias| just checks whether there is a key and/or |NoVal| key defined with
1059 % the target name and |\let| the key to those.
1060 % \begin{macrocode}
1061 \ekvpDefType{ekvc@setup@secondary}{alias}
1062 {%
1063 \ekvc@assert@not@long
1064 \ekvc@assert@k@or@p@defined{#3}%
1065 \ekvifdefined\ekvc@set{#3}{\ekvletkv\ekvc@set{#1}\ekvc@set{#3}}{}%
1066 \ekvifdefinedNoVal\ekvc@set{#3}{\ekvletkvNoVal\ekvc@set{#1}\ekvc@set{#3}}{}%
1067 }
1068 % \end{macrocode}
1069 % \end{macro}
1070 %
1071 % \begin{macro}{default}
1072 % The |default| key can be used to set a \Nkey\ for an existing \Vkey. It
1073 % will just pass the \val\ to the key macro of that other key.
1074 % \begin{macrocode}
1075 \ekvpDefType{ekvc@setup@secondary}{default}
1076 {%
1077 \ekvc@assert@defined{#1}%
1078 \ekvc@assert@not@long
1079 \edef\ekvc@tmp
1080 {%
1081 \ekv@unexpanded\expandafter
1082 {\csname\ekv@name\ekvc@set{#1}\endcsname{#3}}%
1083 }%
1084 \ekvletNoVal\ekvc@set{#1}\ekvc@tmp
1085 }
1086 % \end{macrocode}
1087 % \end{macro}
1088 %
1089 % \begin{macro}{enum,choice}
1090 % \begin{macro}[internal]
1091 % {
1092 % \ekvc@type@enum,\ekvc@h@enum,\ekvc@h@enum@,\ekvc@enum@name,
1093 % \ekvc@type@choice,\ekvc@type@choice@k,\ekvc@type@choice@p
1094 % }
1095 % Enums don't need to apply special trickery to make the parts of the names
1096 % retrievable, so unlike in \expkvd\ we don't need catcode juggling.
1097 % The setup of an |enum| requires unpacking the value in two different
1098 % arguments so we need an auxiliary here. A |choice| is basically the same,
1099 % but a bit more flexible (it allows to specify a value to be forwarded
1100 % instead of just a positional number), hence we need a slightly different
1101 % second step.
1102 % \begin{macrocode}
1103 \def\ekvc@enum@name#1#2#3{ekvc#1(#2)#3}
1104 \ekvpDefType{ekvc@setup@secondary}{enum}
1105 {\ekvpAssertTwoValues{#3}\ekvc@type@enum{#1}#3}
1106 \ekvpDefType{ekvc@setup@secondary}{choice}
1107 {\ekvpAssertTwoValues{#3}\ekvc@type@choice{#1}#3}
1108 \protected\long\def\ekvc@type@enum@or@choice#1#2%
1109 {%
1110 \ekvc@assert@defined{#2}%
1111 % \end{macrocode}
1112 % At run time we need another helper and we need to expand the current
1113 % |\ekvc@set| now. The helper will check whether the given value is defined
1114 % and call the underlying macro (defined below).
1115 % \begin{macrocode}
1116 \ekvc@long\edef\ekvc@tmp##1%
1117 {%
1118 \ekv@unexpanded{\expandafter\ekvc@h@enum\detokenize}{##1}%
1119 \ekv@unexpanded{\ekvc@stop}%
1120 {\ekvc@set}{#1}%
1121 }%
1122 \ekvlet\ekvc@set{#1}\ekvc@tmp
1123 }
1124 \protected\long\def\ekvc@type@enum#1#2%
1125 {%
1126 \ekvc@type@enum@or@choice{#1}{#2}%
1127 % \end{macrocode}
1128 % |\ekvc@type@enum@| will build a control sequence from each given value,
1129 % those will be set up in the |\ekvcsvloop|.
1130 % \begin{macrocode}
1131 \def\ekvc@tmp{0}%
1132 \expandafter\ekvcsvloop\expandafter
1133 {\expandafter\ekvc@type@enum@\csname\ekv@name\ekvc@set{#2}\endcsname{#1}}%
1134 }
1135 % \end{macrocode}
1136 % Here |#1| will be the key-macro of the underlying primary or secondary key,
1137 % |#2| is the |enum| key's name, and |#3| will be the choice. The rest is
1138 % pretty obvious.
1139 % \begin{macrocode}
1140 \ekv@exparg{\protected\long\def\ekvc@type@enum@#1#2#3}%
1141 {%
1142 \expandafter\expandafter\expandafter\edef\expandafter
1143 \csname\ekvc@enum@name\ekvc@set{#2}{\detokenize{#3}}\endcsname
1144 {\ekv@unexpanded{#1}{\ekvc@tmp}}%
1145 \edef\ekvc@tmp{\the\numexpr\ekvc@tmp+1\relax}%
1146 }
1147 % \end{macrocode}
1148 % Similar code for the |choice| type.
1149 % \begin{macrocode}
1150 \protected\long\def\ekvc@type@choice#1#2%
1151 {%
1152 \ekvc@type@enum@or@choice{#1}{#2}%
1153 \ekv@exparg
1154 {%
1155 \expandafter\ekvparse\expandafter
1156 {%
1157 \expandafter\ekvc@type@choice@k
1158 \csname\ekv@name\ekvc@set{#2}\endcsname{#1}%
1159 }%
1160 }%
1161 {%
1162 \expandafter\ekvc@type@choice@p
1163 \csname\ekv@name\ekvc@set{#2}\endcsname{#1}%
1164 }%
1165 }
1166 \ekv@exparg{\protected\long\def\ekvc@type@choice@p#1#2#3#4}%
1167 {%
1168 \expandafter\expandafter\expandafter\edef\expandafter
1169 \csname\ekvc@enum@name\ekvc@set{#2}{\detokenize{#3}}\endcsname
1170 {\ekv@unexpanded{#1{#4}}}%
1171 }
1172 \protected\long\def\ekvc@type@choice@k#1#2#3{\ekvc@type@choice@p#1{#2}{#3}{#3}}
1173 % \end{macrocode}
1174 % The use-time helper will check if the macro for the passed in choice exists,
1175 % if it doesn't throws an error, else calls that macro which will set the
1176 % correct value.
1177 % \begin{macrocode}
1178 \ekv@if@lastnamedcs
1179 {%
1180 \ekv@exparg{\def\ekvc@h@enum#1\ekvc@stop#2#3}%
1181 {%
1182 \expandafter\ifcsname\ekvc@enum@name{#2}{#3}{#1}\endcsname
1183 \expandafter\ekvc@h@enum@\lastnamedcs
1184 \fi
1185 \ekvc@err@unknown@enum{#2}{#3}{#1}%
1186 }
1187 \def\ekvc@h@enum@#1\fi\ekvc@err@unknown@enum#2#3#4%
1188 {%
1189 \fi
1190 \ifx#1\relax
1191 \ekvc@err@unknown@enum{#2}{#3}{#4}%
1192 \expandafter\@gobble
1193 \fi
1194 #1%
1195 }
1196 }
1197 {%
1198 \def\ekvc@h@enum#1%
1199 {%
1200 \def\ekvc@h@enum##1\ekvc@stop##2##3%
1201 {%
1202 \expandafter\ekvc@h@enum@
1203 \csname\ifcsname#1\endcsname#1\else relax\fi\endcsname
1204 {##2}{##3}{##1}%
1205 }%
1206 }
1207 \expandafter\ekvc@h@enum\expandafter{\ekvc@enum@name{#2}{#3}{#1}}
1208 \def\ekvc@h@enum@#1#2#3#4%
1209 {%
1210 \ifx#1\relax
1211 \ekvc@err@unknown@enum{#2}{#3}{#4}%
1212 \expandafter\@gobble
1213 \fi
1214 #1%
1215 }
1216 }
1217 % \end{macrocode}
1218 % We don't need |\ekvc@enum@name| anymore, so let's undefine it.
1219 % \begin{macrocode}
1220 \let\ekvc@enum@name\ekvc@undefined
1221 % \end{macrocode}
1222 % \end{macro}
1223 % \end{macro}
1224 %
1225 % \begin{macro}{aggregate,e-aggregate}
1226 % Aggregating isn't easy to define. We'll have to extract the correct mark for
1227 % the specified key, branch correctly for short and long keys, and use a small
1228 % hack to have the correct arguments on the user interface (|#1| as the
1229 % current contents, |#2| as the new value). This is split into a few steps
1230 % here.
1231 %
1232 % First, assert that the user input is well-behaved.
1233 % \begin{macrocode}
1234 \ekvpDefType{ekvc@setup@secondary}{aggregate}
1235 {%
1236 \let\ekvc@type@aggregate@ifexpanded\@secondoftwo
1237 \ekvc@type@aggregate{#1}{#3}%
1238 }
1239 \ekvpDefType{ekvc@setup@secondary}{e-aggregate}
1240 {%
1241 \let\ekvc@type@aggregate@ifexpanded\@firstoftwo
1242 \ekvc@type@aggregate{#1}{#3}%
1243 }
1244 % \end{macrocode}
1245 % \end{macro}
1246 %
1247 % \begin{macro}[internal]
1248 % {\ekvc@type@aggregate,\ekvc@type@aggregate@a,\ekvc@type@aggregate@b}
1249 % The next step stores the user defined processing in a temporary macro that's
1250 % used to do the parameter number swapping later. It also builds the names of
1251 % the key macro and the helper which would be used for processing a short key.
1252 % \begin{macrocode}
1253 \protected\long\def\ekvc@type@aggregate#1#2%
1254 {%
1255 \ekvc@assert@not@long
1256 \ekvpAssertTwoValues{#2}%
1257 \ekvc@type@aggregate@a
1258 \ekvc@type@aggregate@long\ekvc@type@aggregate@short
1259 {#1}#2%
1260 }
1261 \protected\long\def\ekvc@type@aggregate@a#1#2#3#4#5%
1262 {%
1263 \ekvc@assert@defined{#4}%
1264 \def\ekvc@type@aggregate@tmp##1##2{#5}%
1265 \begingroup\expandafter\endgroup
1266 \expandafter\ekvc@type@aggregate@b
1267 \csname\ekv@name\ekvc@set{#4}\expandafter\endcsname
1268 \csname ekvc@\ekvc@set(#4)\endcsname
1269 #1#2%
1270 {#3}%
1271 }
1272 \protected\long\def\ekvc@type@aggregate@b#1#2#3#4%
1273 {%
1274 \ekvc@type@aggregate@check@long#1#2%
1275 {#3#1}%
1276 {#4#2}%
1277 }
1278 % \end{macrocode}
1279 % \end{macro}
1280 %
1281 % \begin{macro}[internal]
1282 % {
1283 % \ekvc@type@aggregate@check@long,
1284 % \ekvc@type@aggregate@check@long@a,\ekvc@type@aggregate@check@long@b
1285 % }
1286 % To check whether the primary key is long we see whether its |\meaning|
1287 % contains the helper which would only be there for short keys. For this we
1288 % have to get the stringified name of the internal (using |\detokenize|),
1289 % and afterwards get the |\meaning| of the macro. A temporary helper does the
1290 % real test by gobbling and forwarding the result to |\ekv@ifempty|.
1291 % \begin{macrocode}
1292 \protected\long\def\ekvc@type@aggregate@check@long#1#2%
1293 {\expandafter\ekvc@type@aggregate@check@long@a\detokenize{#2}\ekv@stop#1}
1294 \protected\long\def\ekvc@type@aggregate@check@long@a#1\ekv@stop#2%
1295 {%
1296 \def\ekvc@type@aggregate@check@long@@##1#1{}%
1297 \expandafter\ekvc@type@aggregate@check@long@b\meaning#2\ekv@stop{#1}%
1298 }
1299 \protected\def\ekvc@type@aggregate@check@long@b#1\ekv@stop#2%
1300 {\expandafter\ekv@ifempty\expandafter{\ekvc@type@aggregate@check@long@@#1#2}}
1301 % \end{macrocode}
1302 % \end{macro}
1303 %
1304 % \begin{macro}[internal]{\ekvc@type@aggregate@long,\ekvc@type@aggregate@long@}
1305 % The long variant just builds the split mark we extract, uses the hack to
1306 % swap argument order, and then does the definition via |\ekvlet| and a
1307 % temporary macro.
1308 % \begin{macrocode}
1309 \protected\long\def\ekvc@type@aggregate@long#1%
1310 {%
1311 \begingroup\expandafter\endgroup\expandafter
1312 \ekvc@type@aggregate@long@
1313 \csname\ekvc@extract@mark#1\expandafter\endcsname
1314 \expandafter{\ekvc@type@aggregate@tmp{##3}{##1}}%
1315 }
1316 \protected\long\def\ekvc@type@aggregate@long@#1#2#3%
1317 {%
1318 \ekvc@type@aggregate@ifexpanded
1319 {%
1320 \long\def\ekvc@type@aggregate@tmp##1##2#1##3%
1321 {\ekv@expanded{\ekv@unexpanded{##2#1}{#2}}}%
1322 }%
1323 {\long\def\ekvc@type@aggregate@tmp##1##2#1##3{##2#1{#2}}}%
1324 \ekvlet\ekvc@set{#3}\ekvc@type@aggregate@tmp
1325 }
1326 % \end{macrocode}
1327 % \end{macro}
1328 %
1329 % \begin{macro}[internal]
1330 % {\ekvc@type@aggregate@short,\ekvc@type@aggregate@short@}
1331 % The short variant will have to build the marker and the name of the helper
1332 % function, and swap the user argument order. Hence here are a few more
1333 % |\expandafter|s involved. But afterwards we can do the definition of the key
1334 % and the helper macro directly.
1335 % \begin{macrocode}
1336 \protected\long\def\ekvc@type@aggregate@short#1#2%
1337 {%
1338 \begingroup\expandafter\endgroup\expandafter
1339 \ekvc@type@aggregate@short@
1340 \csname\ekvc@extract@mark#1\expandafter\endcsname
1341 \csname ekvc@\ekvc@set(#2)\expandafter\endcsname
1342 \expandafter{\ekvc@type@aggregate@tmp{##3}{##1}}%
1343 {#2}%
1344 }
1345 \protected\long\def\ekvc@type@aggregate@short@#1#2#3#4%
1346 {%
1347 \ekvdef\ekvc@set{#4}{#2{##1}}%
1348 \ekvc@type@aggregate@ifexpanded
1349 {\long\def#2##1##2#1##3{\ekv@expanded{\ekv@unexpanded{##2#1}{#3}}}}%
1350 {\long\def#2##1##2#1##3{##2#1{#3}}}%
1351 }
1352 % \end{macrocode}
1353 % \end{macro}
1354 %
1355 % \begin{macro}{process}
1356 % The |process| type can reuse much of |aggregate|, just the last step of
1357 % definition differ.
1358 % \begin{macrocode}
1359 \ekvpDefType{ekvc@setup@secondary}{process}
1360 {%
1361 \ekvpAssertTwoValues{#3}%
1362 \ifx\ekvc@long\long
1363 \ekv@fi@firstoftwo
1364 \fi
1365 \@secondoftwo
1366 {%
1367 \ekvc@type@aggregate@a
1368 \ekvc@type@process@long\ekvc@type@process@long
1369 }%
1370 {%
1371 \ekvc@type@aggregate@a
1372 \ekvc@type@process@short\ekvc@type@process@short
1373 }%
1374 {#1}#3%
1375 }
1376 % \end{macrocode}
1377 % \end{macro}
1378 %
1379 % \begin{macro}[internal]{\ekvc@type@process@long,\ekvc@type@process@long@}
1380 % This defines a temporary macro to grab the current value (found after the
1381 % marker |#1|), executes the user code and puts everything back to where it
1382 % belongs. Then |\ekvlet| is used to assign that meaning to the key macro.
1383 % \begin{macrocode}
1384 \protected\long\def\ekvc@type@process@long#1%
1385 {%
1386 \begingroup\expandafter\endgroup\expandafter
1387 \ekvc@type@process@long@
1388 \csname\ekvc@extract@mark#1\expandafter\endcsname
1389 \expandafter{\ekvc@type@aggregate@tmp{##3}{##1}}%
1390 }
1391 \protected\long\def\ekvc@type@process@long@#1#2#3%
1392 {%
1393 \long\def\ekvc@type@aggregate@tmp##1##2#1##3{#2##2#1{##3}}%
1394 \ekvlet\ekvc@set{#3}\ekvc@type@aggregate@tmp
1395 }
1396 % \end{macrocode}
1397 % \end{macro}
1398 %
1399 % \begin{macro}[internal]{\ekvc@type@process@short,\ekvc@type@process@short@}
1400 % We define the key macro directly to just grab the argument once and forward
1401 % it to the auxiliary. That one does essentially the same as the long variant.
1402 % \begin{macrocode}
1403 \protected\long\def\ekvc@type@process@short#1#2%
1404 {%
1405 \begingroup\expandafter\endgroup\expandafter
1406 \ekvc@type@process@short@
1407 \csname\ekvc@extract@mark#1\expandafter\endcsname
1408 \csname ekvc@\ekvc@set(#2)\expandafter\endcsname
1409 \expandafter{\ekvc@type@aggregate@tmp{##3}{##1}}%
1410 {#2}%
1411 }
1412 \protected\long\def\ekvc@type@process@short@#1#2#3#4%
1413 {%
1414 \ekvdef\ekvc@set{#4}{#2{##1}}%
1415 \long\def#2##1##2#1##3{#3##2#1{##3}}%
1416 }
1417 % \end{macrocode}
1418 % \end{macro}
1419 %
1420 % \begin{macro}{flag-bool}
1421 % \begin{macrocode}
1422 \ekvpDefType{ekvc@setup@secondary}{flag-bool}
1423 {%
1424 \ekvc@assert@not@long
1425 \ekvpAssertOneValue{#3}%
1426 \ifdefined#3\else\ekvcFlagNew#3\fi
1427 \ekvdef\ekvc@set{#1}%
1428 {%
1429 \ekv@ifdefined{ekvc@flag@set@##1}%
1430 {%
1431 \csname ekvc@flag@set@##1\expandafter\endcsname
1432 \ekvcFlagHeight#3\ekv@stop#3%
1433 }%
1434 {\ekvc@err@invalid@bool{##1}}%
1435 }%
1436 }
1437 % \end{macrocode}
1438 % \end{macro}
1439 %
1440 % \begin{macro}{flag-true,flag-false,flag-raise}
1441 % \begin{macro}[internal]{\ekvc@type@flag}
1442 % \begin{macrocode}
1443 \protected\def\ekvc@type@flag#1#2#3%
1444 {%
1445 \ekvc@assert@not@long
1446 \ekvpAssertOneValue{#3}%
1447 \ifdefined#3\else\ekvcFlagNew#3\fi
1448 \ekv@exparg{\ekvdefNoVal\ekvc@set{#2}}{#1#3}%
1449 }
1450 \ekvpDefType{ekvc@setup@secondary}{flag-true}
1451 {\ekvc@type@flag\ekvcFlagSetTrue{#1}{#3}}
1452 \ekvpDefType{ekvc@setup@secondary}{flag-false}
1453 {\ekvc@type@flag\ekvcFlagSetFalse{#1}{#3}}
1454 \ekvpDefType{ekvc@setup@secondary}{flag-raise}
1455 {\ekvc@type@flag\ekvcFlagRaise{#1}{#3}}
1456 % \end{macrocode}
1457 % \end{macro}
1458 % \end{macro}
1459 %
1460 %
1461 % \subsubsection{Flags}
1462 %
1463 % The basic idea of flags is to store information by the fact that \TeX\
1464 % expandably assigns the meaning |\relax| to undefined control sequences which
1465 % were built with |\csname|. This mechanism is borrowed from \pkg{expl3}.
1466 %
1467 % \begin{macro}[internal]{\ekvc@flag@name,\ekvc@flag@namescheme}
1468 % Flags follow a simple naming scheme which we define here. |\ekvc@flag@name|
1469 % will store the name of an internal function that is used to build names of
1470 % the second naming scheme defined by |\ekvc@flag@namescheme|.
1471 % \begin{macrocode}
1472 \def\ekvc@flag@name{ekvcf\string}
1473 \def\ekvc@flag@namescheme#1#2{ekvch#2#1}
1474 % \end{macrocode}
1475 % \end{macro}
1476 %
1477 % \begin{macro}{\ekvcFlagHeight}
1478 % For semantic reasons we use |\number| with another name.
1479 % \begin{macrocode}
1480 \let\ekvcFlagHeight\number
1481 % \end{macrocode}
1482 % \end{macro}
1483 %
1484 % \begin{macro}{\ekvcFlagNew}
1485 % This macro defines a new flag. It stores the function build with the
1486 % |\ekvc@flag@name| naming scheme after the internal function
1487 % |\ekvc@flag@height| that'll determine the current flag height. It'll also
1488 % define the macro named via |\ekvc@flag@name| to build names according to
1489 % |\ekvc@flag@namescheme|.
1490 % \begin{macrocode}
1491 \protected\def\ekvcFlagNew#1%
1492 {%
1493 \edef#1%
1494 {%
1495 \ekv@unexpanded{\ekvc@flag@height}%
1496 \ekv@unexpanded\expandafter{\csname\ekvc@flag@name#1\endcsname}%
1497 }%
1498 \ekv@expargtwice
1499 {\expandafter\def\csname\ekvc@flag@name#1\endcsname##1}%
1500 {\expandafter\ekvc@flag@namescheme\expandafter{\string#1}{##1}}%
1501 }
1502 % \end{macrocode}
1503 % \end{macro}
1504 %
1505 % \begin{macro}[internal]{\ekvc@flag@height,\ekvc@flag@height@}
1506 % This macro gets the height of a flag by a simple loop. The first loop
1507 % iteration differs a bit from the following in that it doesn't have to get
1508 % the current iteration count. The space at the end of |\ekvc@flag@height|
1509 % ends the |\number| evaluation.
1510 % \begin{macrocode}
1511 \def\ekvc@flag@height#1%
1512 {%
1513 \ifcsname#10\endcsname
1514 \ekvc@flag@height@1\ekv@stop#1%
1515 \fi
1516 \@firstofone{0} % leave this space
1517 }
1518 \def\ekvc@flag@height@#1\ekv@stop#2\fi\@firstofone#3%
1519 {%
1520 \fi
1521 \ifcsname#2{#1}\endcsname
1522 \expandafter\ekvc@flag@height@\the\numexpr#1+1\relax\ekv@stop#2%
1523 \fi
1524 \@firstofone{#1}%
1525 }
1526 % \end{macrocode}
1527 % \end{macro}
1528 %
1529 % \begin{macro}{\ekvcFlagRaise}
1530 % Raising a flag simply means letting the |\ekvc@flag@namescheme| macro for
1531 % the current height to relax. The result of raising a flag is that its height
1532 % is bigger by $1$.
1533 % \begin{macrocode}
1534 \ekv@exparg{\def\ekvcFlagRaise#1}%
1535 {%
1536 \expandafter\expandafter\expandafter\@gobble\expandafter
1537 \csname\ekvc@flag@namescheme{\string#1}{\ekvcFlagHeight#1}\endcsname
1538 }
1539 % \end{macrocode}
1540 % \end{macro}
1541 %
1542 % \begin{macro}{\ekvcFlagSetTrue,\ekvcFlagSetFalse}
1543 % \begin{macro}[internal]{\ekvc@flag@set@true,\ekvc@flag@set@false}
1544 % A flag is considered true if its current height is odd, and as false if it
1545 % is even. Therefore |\ekvcFlagSetTrue| and |\ekvcFlagSetFalse| only need to
1546 % raise the flag if the opposing boolean value is the current one.
1547 % \begin{macrocode}
1548 \def\ekvcFlagSetTrue#1%
1549 {\expandafter\ekvc@flag@set@true\ekvcFlagHeight#1\ekv@stop#1}
1550 \def\ekvcFlagSetFalse#1%
1551 {\expandafter\ekvc@flag@set@false\ekvcFlagHeight#1\ekv@stop#1}
1552 % \end{macrocode}
1553 % We can expand |\ekvc@flag@namescheme| at definition time here, which is why
1554 % we're using a temporary definition to set up |\ekvc@flag@set@true| and
1555 % |\ekvc@flag@set@false|.
1556 % \begin{macrocode}
1557 \def\ekvc@flag@set@true#1%
1558 {%
1559 \def\ekvc@flag@set@true##1\ekv@stop##2%
1560 {%
1561 \ifodd##1
1562 \ekv@fi@gobble
1563 \fi
1564 \@firstofone{\expandafter\@gobble\csname#1\endcsname}%
1565 }%
1566 \def\ekvc@flag@set@false##1\ekv@stop##2%
1567 {%
1568 \ifodd##1
1569 \ekv@fi@firstofone
1570 \fi
1571 \@gobble{\expandafter\@gobble\csname#1\endcsname}%
1572 }%
1573 }
1574 \expandafter\ekvc@flag@set@true\expandafter
1575 {\ekvc@flag@namescheme{\string#2}{#1}}
1576 % \end{macrocode}
1577 % \end{macro}
1578 % \end{macro}
1579 %
1580 % \begin{macro}{\ekvcFlagIf}
1581 % As already explained, truthiness is defined as a flag's height being odd, so
1582 % we just branch accordingly here.
1583 % \begin{macrocode}
1584 \def\ekvcFlagIf#1%
1585 {%
1586 \ifodd#1%
1587 \ekv@fi@firstoftwo
1588 \fi
1589 \@secondoftwo
1590 }
1591 % \end{macrocode}
1592 % \end{macro}
1593 %
1594 % \begin{macro}{\ekvcFlagIfRaised}
1595 % This macro uses flags as a switch, if a flag's current height is bigger than
1596 % $0$ this test yields true.
1597 % \begin{macrocode}
1598 \ekv@exparg{\def\ekvcFlagIfRaised#1}%
1599 {%
1600 \expandafter\ifcsname\ekvc@flag@namescheme{\string#1}0\endcsname
1601 \ekv@fi@firstoftwo
1602 \fi
1603 \@secondoftwo
1604 }
1605 % \end{macrocode}
1606 % \end{macro}
1607 %
1608 % \begin{macro}{\ekvcFlagReset,\ekvcFlagResetGlobal}
1609 % \begin{macro}[internal]{\ekvc@flag@reset,\ekvc@flag@reset@}
1610 % Resetting works by locally letting all the defined internal macros named
1611 % after |\ekvc@flag@namescheme| to undefined.
1612 % \begin{macrocode}
1613 \protected\def\ekvcFlagReset#1%
1614 {\expandafter\ekvc@flag@reset\csname\ekvc@flag@name#1\endcsname{}}
1615 \protected\def\ekvcFlagResetGlobal#1%
1616 {\expandafter\ekvc@flag@reset\csname\ekvc@flag@name#1\endcsname\global}
1617 \protected\def\ekvc@flag@reset#1#2%
1618 {%
1619 \ifcsname#10\endcsname
1620 #2\expandafter\let\csname#10\endcsname\ekvc@undefined
1621 \ekvc@flag@reset@1\ekv@stop#1{#2}%
1622 \fi
1623 }
1624 \protected\def\ekvc@flag@reset@#1\ekv@stop#2#3\fi
1625 {%
1626 \fi
1627 \ifcsname#2{#1}\endcsname
1628 #3\expandafter\let\csname#2{#1}\endcsname\ekvc@undefined
1629 \expandafter\ekvc@flag@reset@\the\numexpr#1+1\relax\ekv@stop#2{#3}%
1630 \fi
1631 }
1632 % \end{macrocode}
1633 % \end{macro}
1634 % \end{macro}
1635 %
1636 % \begin{macro}{\ekvcFlagGetHeight}
1637 % \begin{macro}[internal]{\ekvc@flag@get@height@single}
1638 % These are just small helpers, first getting the height of the flag and then
1639 % passing it on to the user supplied code.
1640 % \begin{macrocode}
1641 \def\ekvcFlagGetHeight#1%
1642 {\expandafter\ekvc@flag@get@height@single\ekvcFlagHeight#1\ekv@stop}
1643 \long\def\ekvc@flag@get@height@single#1\ekv@stop#2{#2{#1}}
1644 % \end{macrocode}
1645 % \end{macro}
1646 % \end{macro}
1647 %
1648 % \begin{macro}{\ekvcFlagGetHeights}
1649 % \begin{macro}[internal]
1650 % {\ekvc@flag@get@heights,\ekvc@flag@get@heights@,\ekvc@flag@get@heights@done}
1651 % This works by a simple loop that stops at |\ekv@stop|. As long as that
1652 % marker isn't hit, get the next flags height and put it into a list after
1653 % |\ekv@stop|. |\ekvc@flag@get@heights@| uses the same marker name for the
1654 % end of the height, which shouldn't clash in any case. Once we're done we
1655 % remove the remainder of the current iteration and leave the user supplied
1656 % code in the input stream with all the flags' heights as a single argument.
1657 % \begin{macrocode}
1658 \def\ekvcFlagGetHeights#1%
1659 {%
1660 \ekvc@flag@get@heights#1\ekv@stop{}%
1661 }
1662 \def\ekvc@flag@get@heights#1%
1663 {%
1664 \ekv@gobbleto@stop#1\ekvc@flag@get@heights@done\ekv@stop
1665 \expandafter\ekvc@flag@get@heights@\ekvcFlagHeight#1\ekv@stop
1666 }
1667 \def\ekvc@flag@get@heights@#1\ekv@stop#2\ekv@stop#3%
1668 {\ekvc@flag@get@heights#2\ekv@stop{#3{#1}}}
1669 \long\def\ekvc@flag@get@heights@done
1670 \ekv@stop
1671 \expandafter\ekvc@flag@get@heights@\ekvcFlagHeight\ekv@stop\ekv@stop#1#2%
1672 {#2{#1}}
1673 % \end{macrocode}
1674 % \end{macro}
1675 % \end{macro}
1676 %
1677 %
1678 % \subsubsection{Helper Macros}
1679 %
1680 % \begin{macro}[internal]{\ekvc@extract@mark,\ekvc@extract@mark@}
1681 % This is used to extract the mark of a split or hash key from its definition.
1682 % This is kind of fragile, it assumes |#1| is always a macro used for hashing
1683 % or splitting. Also it assumes that the escape character is a backslash.
1684 % \begin{macrocode}
1685 \def\ekvc@extract@mark#1{\expandafter\ekvc@extract@mark@\meaning#1\ekv@stop}
1686 \begingroup
1687 \lccode`;=`#
1688 \lccode`/=`\\
1689 \lowercase{\endgroup
1690 \def\ekvc@extract@mark@#1:#2/#3 ;#4\ekv@stop{#3}%
1691 }
1692 % \end{macrocode}
1693 % \end{macro}
1694 %
1695 %
1696 % \subsubsection{Assertions}
1697 %
1698 % \begin{macro}[internal]{\ekvc@assert@not@long}
1699 % Some keys don't want to be |long| and we have to educate the user, so let's
1700 % throw an error if someone wanted these to be long.
1701 % \begin{macrocode}
1702 \ekv@exparg{\def\ekvc@assert@not@long}%
1703 {\ekvpAssertIfNot{\ifx\ekvc@long\long}{`long' not accepted}}
1704 % \end{macrocode}
1705 % \end{macro}
1706 %
1707 % \begin{macro}[internal]{\ekvc@assert@defined,\ekvc@assert@k@or@p@defined}
1708 % Since some keys interact with existing other keys we need to assert those
1709 % exist.
1710 % \begin{macrocode}
1711 \long\def\ekvc@assert@defined#1%
1712 {\ekvpAssertTF{\ekvifdefined\ekvc@set{#1}}{undefined key `#1'}}
1713 \long\def\ekvc@assert@k@or@p@defined#1%
1714 {%
1715 \ekvpAssertTF
1716 {\ekvifdefined\ekvc@set{#1}\@firstoftwo{\ekvifdefinedNoVal\ekvc@set{#1}}}%
1717 {undefined key `#1'}%
1718 }
1719 % \end{macrocode}
1720 % \end{macro}
1721 %
1722 %
1723 % \subsubsection{Messages}
1724 %
1725 % \begin{macro}[internal]
1726 % {
1727 % \ekvc@errm,
1728 % \ekvc@err@toomany,\ekvc@err@value@required,
1729 % \ekvc@err@already@defined,\ekvc@err@no@key@macro,
1730 % }
1731 % Boring unexpandable error messages.
1732 % \begin{macrocode}
1733 \protected\long\def\ekvc@errm#1{\errmessage{expkv-cs Error: #1}}
1734 \protected\long\def\ekvc@err@toomany#1%
1735 {\ekvc@errm{Too many keys for macro `\string#1'}}
1736 \protected\long\def\ekvc@err@value@required#1%
1737 {\ekvc@errm{Missing value for key `\ekv@unexpanded{#1}'}}
1738 \protected\long\def\ekvc@err@already@defined#1%
1739 {\ekvc@errm{Macro `\string#1' already defined}}
1740 \protected\long\def\ekvc@err@no@key@macro#1%
1741 {\ekvc@errm{\string#1 is no key=val macro}}
1742 % \end{macrocode}
1743 % \end{macro}
1744 %
1745 % \begin{macro}[internal]{\ekvc@err}
1746 % We need a way to throw error messages expandably in some contexts.
1747 % \begin{macrocode}
1748 \ekv@exparg{\long\def\ekvc@err#1}{\ekverr{expkv-cs}{#1}}
1749 % \end{macrocode}
1750 % \end{macro}
1751 %
1752 % \begin{macro}[internal]
1753 % {
1754 % \ekvc@err@unknown@hash,\ekvc@err@empty@hash,\ekvc@err@missing@hash,
1755 % \ekvc@err@invalid@bool,\ekvc@err@unknown@key@or@macro,
1756 % \ekvc@err@unknown@enum
1757 % }
1758 % And here are the expandable error messages.
1759 % \begin{macrocode}
1760 \long\def\ekvc@err@unknown@hash#1{\ekvc@err{unknown hash `#1'}}
1761 \long\def\ekvc@err@missing@hash#1{\ekvc@err{hash `#1' not found}}
1762 \long\def\ekvc@err@empty@hash{\ekvc@err{empty hash}}
1763 \def\ekvc@err@invalid@bool#1{\ekvc@err{invalid boolean value `#1'}}
1764 \long\def\ekvc@err@unknown@key@or@macro#1#2%
1765 {\ekvc@err{unknown key `#2' for #1}}
1766 \def\ekvc@err@unknown@enum#1#2#3%
1767 {\ekvc@err{unknown choice `#3' for `#2' in #1}}
1768 % \end{macrocode}
1769 % \end{macro}
1770 %
1771 %
1772 % Now everything that's left is to reset the category code of |@|.
1773 % \begin{macrocode}
1774 \catcode`\@=\ekvc@tmp
1775 % \end{macrocode}
1776 %
1777 % \gobbledocstriptag
1778 %</tex>
1779 %^^A=<<