Debian Codegraph @

texmf-dist/tex/generic/pgf/utilities/pgfkeyslibraryfiltered.code.tex

raw
1 % Copyright 2019 by Christian Feuersaenger
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9 %
10 % This file contains additions to pgfkeys.code.tex (loaded
11 % automatically at the end of pgfkeys.code.tex)
12 %
13 % Improvements:
14 %
15 % - option filtering
16 % you provide
17 % - a boolean predicate
18 % - a "filter handler" which will be invoked for non-matching options,
19 % - a key=value list as usual.
20 % The filter sets only matching options and invokes the handler for
21 % unmatching ones.
22 %
23 % - Fast family support as in xkeyval.
24 % - A key like /my tree/my option can be associated with /my family
25 % - You can efficiently set keys which belong to a set of "active"
26 % families.
27 % Remaining options can be collected into a macro.
28
29 % WARNING:
30 % this file overwrites
31 % \pgfkeys@addpath
32 % \pgfkeys@nevermind
33 %
34 % all other features are 'additive'
35
36
37 % these implementations will be switched dynamically with their
38 % filtered versions (in \pgfkeys@install@filter@and@invoke)
39 \let\pgfkeys@orig@case@one=\pgfkeys@case@one
40 \let\pgfkeys@orig@@set=\pgfkeys@@set
41 \let\pgfkeys@orig@@qset=\pgfkeys@@qset
42 \let\pgfkeys@orig@try=\pgfkeys@try
43 \let\pgfkeys@orig@unknown=\pgfkeys@unknown
44
45 \newif\ifpgfkeysfilteringisactive
46 \newif\ifpgfkeysfiltercontinue
47 \let\pgfkeys@key@predicate=\pgfkeys@empty
48 \let\pgfkeys@filtered@handler=\pgfkeys@empty
49 \newtoks\pgfkeys@tmptoks
50
51 % Performs 'filtered' key settings.
52 %
53 % For every option for which the path prefixing has already been done,
54 % the current key filter predicate will be invoked. If the predicate
55 % returns true, pgfkeys will process this key in the normal manner.
56 % If not, a key filter handler will be invoked.
57 %
58 % The *predicate* and *handler* semantics are as follows:
59 % PRECONDITION:
60 % 1. The variables
61 % \pgfkeyscurrentkey (full path including name)
62 % \pgfkeyscurrentkeyRAW (the current key as it has been
63 % found in the key=value list
64 % without path modification)
65 % \pgfkeyscurrentvalue
66 % are all set. If the current key is a handler variable,
67 % \pgfkeyscurrentname
68 % and
69 % \pgfkeyscurrentpath
70 % are also set.
71 % 2. The type of option has already been checked, that means
72 % case (1) whether '.@cmd' exists
73 % case (2) whether the key as such has its value
74 % case (3) it is a handler like '.code', '.cd' or whatever.
75 % case (0) it is unknown.
76 % The actual case number (0-3) will be provided as contents
77 % of the macro
78 % \pgfkeyscasenumber.
79 % It is always a one-character token, so it may be compared
80 % with both, \ifnum or \if.
81 % Please note that unknown options will be processed with
82 % the usual '.unknown' handlers unless the key filter takes
83 % control over unknown options as well.
84 %
85 % POSTCONDITION:
86 % the predicate sets
87 % \pgfkeysfiltercontinuetrue
88 % or
89 % \pgfkeysfiltercontinuefalse
90 % (the boolean \ifpgfkeysfiltercontinue).
91 % Depending on this 'if', option processing will be continued or
92 % skipped.
93 %
94 % The handler can do anything with the option, for example collect
95 % unmatched ones.
96 %
97 % ATTENTION: \pgfkeysfiltered can't be nested (yet). Use the
98 % \pgfkeyspredicateAND if you need multiple predicates at once.
99 % Nesting would produce unexpected results because the current filter
100 % state can't be stored/restored without TeX-groups, therefore it is
101 % disabled.
102 %
103 % ATTENTION: you can't filter error messages.
104 %
105 % REMARK: In case (3), the macros \pgfkeyscurrentpath and
106 % \pgfkeyscurrentname have already been computed, you do not need to
107 % invoke \pgfkeyssplitpath. In any other case, neither path nor name
108 % are required for the options processing - if you need them for
109 % predicates/handlers, you need to compute them by hand.
110 %
111 %
112 % Example:
113 % \def\unmatched{}
114 % \pgfkeys{/pgf/key filters/is descendant of/.install key filter=/my group}
115 % \pgfkeys{/pgf/key filter handlers/append filtered to/.install key filter handler=\unmatched}
116 % \pgfkeysfiltered%
117 % {/my group/option 1=value 1,/tikz/option 2=value 2}
118 % ->
119 % will set '/my group/option 1' as usual, but '/tikz/option 2' will not
120 % be set. Instead, it will be appended to '\unmatched' such that
121 % \unmatched = {/tikz/option 2=value2}
122 % after the operation.
123 %
124 % Arguments:
125 % #1: key-value list.
126 \def\pgfkeysfiltered{%
127 % produce
128 % '{<default path>}'
129 % each expanded exactly one time into the register:
130 \expandafter\pgfkeysfiltered@@install\expandafter{\pgfkeysdefaultpath}%
131 }
132
133 % #1: old value of default path.
134 % #2: key-value-list.
135 \long\def\pgfkeysfiltered@@install#1#2{%
136 \pgfkeys@install@filter@and@invoke{%
137 \let\pgfkeysdefaultpath\pgfkeys@root%
138 \pgfkeys@parse#2,\pgfkeys@mainstop%
139 \def\pgfkeysdefaultpath{#1}%
140 }%
141 }
142
143 % Assuming that macro #1 contains a key=value list, this command
144 % performs an \pgfkeysalso command for the content of macro #1.
145 %
146 % It can be used in conjunction with
147 % - \pgfkeysfiltered and
148 % - \pgfkeysappendfilterednamestomacro:
149 % the first pass fill only process options matching the filter, then,
150 % a \pgfkeysalsofrom can be used at a later time to set the remaining
151 % options.
152 %
153 % Example:
154 % \pgfkeys{/my group/.cd,/utils/exec=\pgfkeysalsofrom\filtered}
155 \long\def\pgfkeysalsofrom#1{%
156 \expandafter\pgfkeysalso\expandafter{#1}%
157 }
158
159 % The same as \pgfkeysalsofrom, but it invokes \pgfkeysalsofiltered.
160 \long\def\pgfkeysalsofilteredfrom#1{%
161 \expandafter\pgfkeysalsofiltered\expandafter{#1}%
162 }
163
164 % #1 = options
165 \long\def\pgfkeysalsofiltered#1{%
166 \pgfkeys@install@filter@and@invoke{\pgfkeysalso{#1}}%
167 }%
168
169 % The same like \pgfkeysfiltered, but with quick search path setting.
170 %
171 % #1: default path
172 % #2: key-value-pairs
173 \long\def\pgfqkeysfiltered#1{%
174 \expandafter\pgfqkeysfiltered@@install\expandafter{\pgfkeysdefaultpath}{#1}%
175 }
176
177 % #1: old value of default path.
178 % #2: default path
179 % #3: key-value-list.
180 \long\def\pgfqkeysfiltered@@install#1#2#3{%
181 \pgfkeys@install@filter@and@invoke{%
182 \def\pgfkeysdefaultpath{#2/}\pgfkeys@parse#3,\pgfkeys@mainstop\def\pgfkeysdefaultpath{#1}%
183 }%
184 }
185
186 % Family management
187 %
188 % The family code provides the following features:
189 % 1. every key can be associated with 0 or 1 'family'.
190 % 2. Families are a loose association which are independent of the key
191 % hierarchy.
192 % For example, /my tree/key1 can belong to family /tikz.
193 %
194 % 3. It is possible to "activate" or "deactivate" single families.
195 % Furthermore, it is possible to set only keys which belong to
196 % active families (using \pgfkeysfiltered).
197 % 4. Runtime complexities:
198 % If you have N options and you only want to process K active
199 % families, the runtime is O( N + K ):
200 % - activate every family O(K)
201 % - use \pgfkeyshasactivefamily as filter predicate O(N)
202 % - deactivate every family O(K)
203
204
205 % Activates family #1.
206 %
207 % #1 maybe a macro.
208 \def\pgfkeysactivatefamily#1{%
209 \pgfkeysiffamilydefined
210 {#1}%
211 {\csname pgfk@#1/familyactivetrue\endcsname}%
212 {\pgfkeysvalueof{/errors/family unknown/.@cmd}{#1}\pgfeov}%
213 %\message{[ACTIVATING FAMILY #1]}%
214 }
215
216 % Deactivates family #1.
217 %
218 % #1 maybe a macro.
219 \def\pgfkeysdeactivatefamily#1{%
220 \pgfkeysiffamilydefined
221 {#1}%
222 {\csname pgfk@#1/familyactivefalse\endcsname}%
223 {\pgfkeysvalueof{/errors/family unknown/.@cmd}{#1}\pgfeov}%
224 %\message{[DEACTIVATING FAMILY #1]}%
225 }
226
227 % Activates all families in the comma separated list #1.
228 %
229 % It will also generate code for deactivation of all those families
230 % into the command #2.
231 %
232 % #1: a comma-separated list of fully qualified family names.
233 % #2: a command which will be filled with a deactivate-all command.
234 \def\pgfkeysactivatefamilies#1#2{%
235 \pgfkeyssavekeyfilterstateto\pgfkeys@cur@state
236 \expandafter\pgfkeysactivatefamilies@impl\expandafter{\pgfkeys@cur@state}{#1}{#2}%
237 }
238 % #1: commands needed to restore the old filtering state
239 % #2: family name list
240 % #3: macro name for de-activate command
241 \def\pgfkeysactivatefamilies@impl#1#2#3{%
242 \pgfkeysinstallkeyfilter{/pgf/key filters/false}{}%
243 \let#3=\pgfkeys@empty%
244 \def\pgfkeys@filtered@handler{\pgfkeys@family@activate@handler{#3}}%
245 \pgfkeysalsofiltered{#2}%
246 #1%
247 }
248
249 \def\pgfkeys@family@activate@handler#1{%
250 \pgfkeysactivatefamily{\pgfkeyscurrentkey}%
251 % produce
252 % <old list> '\pgfkeysdeactivatefamily{' <current key> '}'
253 \pgfkeys@tmptoks=\expandafter\expandafter\expandafter{\expandafter#1\expandafter\pgfkeysdeactivatefamily\expandafter{\pgfkeyscurrentkey}}%
254 \edef#1{\the\pgfkeys@tmptoks}%
255 }
256
257 % If for testing whether a family exists.
258 %
259 % #1 = fully qualified family name
260 % #2 = if-case
261 % #3 = else-case
262 %
263 % Description:
264 %
265 % If the family exists, #2 will be executed. Otherwise, #3 will be
266 % called.
267 \long\def\pgfkeysiffamilydefined#1#2#3{\ifcsname ifpgfk@#1/familyactive\endcsname#2\else#3\fi}
268
269 % Sets the TeX boolean
270 % \ifpgfkeysfiltercontinue := ( family #1 is active )
271 %
272 % Argument:
273 % #1 the family name. Maybe a macro.
274 \def\pgfkeysisfamilyactive#1{%
275 \pgfkeysiffamilydefined{#1}{%
276 \expandafter\let\expandafter\ifpgfkeysfiltercontinue\csname ifpgfk@#1/familyactive\endcsname
277 }{%
278 \pgfkeysvalueof{/errors/family unknown/.@cmd}{#1}\pgfeov%
279 \expandafter\expandafter\expandafter\let\csname ifpgfkeysfiltercontinue\endcsname\csname iffalse\endcsname
280 }%
281 }%
282
283 % Retrieve the family of full key #1 into macro #2.
284 %
285 % Will set the TeX boolean \ifpgfkeyssuccess to whether the full key
286 % really has a family.
287 %
288 % The family for any key is stored in the sub-key #1/family.
289 %
290 % Parameters:
291 % #1: the full key name for which the family is requested. Maybe a
292 % macro.
293 % #2: a macro name which will be filled with the result.
294 \def\pgfkeysgetfamily#1#2{%
295 \pgfkeysifdefined{#1/family}{\pgfkeysgetvalue{#1/family}{#2}\pgfkeyssuccesstrue}{\pgfkeyssuccessfalse}%
296 }
297
298 % Equivalent to \pgfkeys{#1/.belongs to family=#2}
299 \def\pgfkeyssetfamily#1#2{%
300 \pgfkeysiffamilydefined{#2}{%
301 \pgfkeyssetvalue{#1/family}{#2}%
302 }{%
303 \pgfkeysalso{/errors/family unknown={#2}}%
304 }%
305 }%
306
307
308 % Sets \ifpgfkeysfiltercontinue to true iff the current key belongs to
309 % the /errors tree.
310 \long\def\pgfkeys@cur@is@descendant@of@errors{%
311 \expandafter\pgfkeys@cur@is@descendant@of@errors@impl\pgfkeyscurrentkey/errors\pgf@@eov
312 }%
313 \long\def\pgfkeys@cur@is@descendant@of@errors@impl#1/errors#2\pgf@@eov{%
314 \def\pgfkeyspred@TMP{#1}%
315 \ifx\pgfkeyspred@TMP\pgfkeys@empty
316 %\message{[SPECIAL CHECK] '\pgfkeyscurrentkey' is descendant of '/errors': TRUE.}%
317 \pgfkeysfiltercontinuetrue
318 \else
319 %\message{[SPECIAL CHECK] '\pgfkeyscurrentkey' is descendant of '/errors': FALSE.}%
320 \pgfkeysfiltercontinuefalse
321 \fi
322 }%
323
324 % \pgfkeysinterruptkeyfilter
325 % ...
326 % \endpgfkeysinterruptkeyfilter
327 % temporarily interrupts key filtering and enables it in
328 % \endpgfkeysinterruptkeyfilter.
329 %
330 % If key filtering it not active, this has no effect at all.
331 %
332 % REMARK:
333 % \pgfkeysinterruptkeyfilter...\endpgfkeysinterruptkeyfilter does NOT
334 % introduce a \TeX-group.
335 \def\pgfkeysinterruptkeyfilter{%
336 \ifpgfkeysfilteringisactive
337 \let\pgfkeys@case@one=\pgfkeys@orig@case@one
338 \let\pgfkeys@try=\pgfkeys@orig@try
339 \let\pgfkeys@unknown=\pgfkeys@orig@unknown
340 \fi
341 }
342
343 \def\endpgfkeysinterruptkeyfilter{%
344 \ifpgfkeysfilteringisactive
345 \let\pgfkeys@case@one=\pgfkeys@case@one@filtered
346 \let\pgfkeys@try=\pgfkeys@try@filtered
347 \let\pgfkeys@unknown=\pgfkeys@unknown@filtered
348 \fi
349 }
350
351 % Activates families #1, calls \pgfkeysfiltered and deactivates the
352 % families afterwards.
353 %
354 % REMARK: you need to install a family-based key filter predicate
355 % manually to benefit from the activated families!
356 %
357 % #1: comma separated family list
358 % #2: key-value pairs
359 %
360 % @see \pgfkeysactivatefamiliesandfilteroptions
361 \def\pgfkeysactivatefamiliesandfilteroptions#1#2{%
362 \pgfkeysactivatefamilies{#1}{\pgfkeys@family@deactivation}%
363 \pgfkeysfiltered{#2}%
364 \pgfkeys@family@deactivation
365 }
366
367 % The "quick" variant of \pgfkeysactivatefamiliesandfilteroptions: it
368 % also assigns a default path.
369 %
370 % #1: comma separated family list
371 % #2: default path
372 % #3: key-value pairs
373 \def\pgfqkeysactivatefamiliesandfilteroptions#1#2#3{%
374 \pgfkeysactivatefamilies{#1}{\pgfkeys@family@deactivation}%
375 \pgfqkeysfiltered{#2}{#3}%
376 \pgfkeys@family@deactivation
377 }
378
379 % Public version of split path:
380 \def\pgfkeyssplitpath{\pgfkeys@split@path}%
381
382
383 % The same as \pgfkeysactivatefamiliesandfilteroptions but just for
384 % ONE family.
385 %
386 % #1: family (maybe a macro)
387 % #2: key-value pairs
388 \def\pgfkeysactivatesinglefamilyandfilteroptions#1#2{%
389 \pgfkeysactivatefamily{#1}%
390 \pgfkeysfiltered{#2}%
391 \pgfkeysdeactivatefamily{#1}%
392 }
393
394 % The "quick" variant of \pgfkeysactivatesinglefamilyandfilteroptions
395 %
396 % #1: family (maybe a macro)
397 % #2: default path
398 % #3: key-value pairs
399 \def\pgfqkeysactivatesinglefamilyandfilteroptions#1#2#3{%
400 \pgfkeysactivatefamily{#1}%
401 \pgfqkeysfiltered{#2}{#3}%
402 \pgfkeysdeactivatefamily{#1}%
403 }
404
405 % Installs the key filter '#1' with argument '#2'.
406 % This is equivalent to
407 % \pgfkeys{#1/.install key filter=#2}
408 %
409 % The current values of the key filter handler is stored into the public
410 % macros
411 % \pgfkeyscurrentkeyfilter
412 % and
413 % \pgfkeyscurrentkeyfilterargs
414 %
415 % #1: a full key name; may be a macro
416 % #2: optional arguments for the key. If the key expects more than one
417 % argument, supply '{{first}{second}}'
418 \def\pgfkeysinstallkeyfilter#1#2{%
419 \pgfkeysifdefined{#1/.@cmd}{%
420 \edef\pgfkeyscurrentkeyfilter{#1}%
421 \def\pgfkeyscurrentkeyfilterargs{#2}%
422 \pgfkeysgetvalue{#1/.@cmd}{\pgfkeys@key@predicate@}%
423 \def\pgfkeys@key@predicate{\pgfkeys@key@predicate@#2\pgfeov}%
424 }{%
425 \pgfkeysvalueof{/errors/no such key filter/.@cmd}{#1}{#2}\pgfeov%
426 }%
427 }
428
429 % Installs the key filter handler '#1' with argument '#2'.
430 % This is equivalent to
431 % \pgfkeys{#1/.install key filter handler=#2}
432 %
433 % The current values of the key filter handler is stored into the public
434 % macros
435 % \pgfkeyscurrentkeyfilterhandler
436 % and
437 % \pgfkeyscurrentkeyfilterhandlerargs
438 %
439 % #1: a full key name; may be a macro
440 % #2: optional arguments for the handler. If the handler expects more than one
441 % argument, supply '{{first}{second}}'
442 \def\pgfkeysinstallkeyfilterhandler#1#2{%
443 \pgfkeysifdefined{#1/.@cmd}{%
444 \edef\pgfkeyscurrentkeyfilterhandler{#1}%
445 \def\pgfkeyscurrentkeyfilterhandlerargs{#2}%
446 \pgfkeysgetvalue{#1/.@cmd}{\pgfkeys@filtered@handler@}%
447 \def\pgfkeys@filtered@handler{\pgfkeys@filtered@handler@#2\pgfeov}%
448 }{%
449 \pgfkeysvalueof{/errors/no such key filter handler/.@cmd}{#1}{#2}\pgfeov%
450 }%
451 }
452
453 % Creates a macro which contains commands to re-activate the current
454 % key filter and key filter handler. It can be used to temporarily
455 % switch the key filter.
456 \def\pgfkeyssavekeyfilterstateto#1{%
457 % produce the string
458 % \pgfkeysinstallkeyfilter{...}{...}
459 % \pgfkeysinstallkeyfilterhandler{...}{...}
460 % where each argument is expanded once
461 % FIXME: Do the same with less overhead!
462 \pgfkeys@tmptoks={\pgfkeysinstallkeyfilter}%
463 \pgfkeys@tmptoks=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfkeys@tmptoks\expandafter{\pgfkeyscurrentkeyfilter}}%
464 \pgfkeys@tmptoks=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfkeys@tmptoks\expandafter{\pgfkeyscurrentkeyfilterargs}\pgfkeysinstallkeyfilterhandler}%
465 \pgfkeys@tmptoks=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfkeys@tmptoks\expandafter{\pgfkeyscurrentkeyfilterhandler}}%
466 \pgfkeys@tmptoks=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfkeys@tmptoks\expandafter{\pgfkeyscurrentkeyfilterhandlerargs}}%
467 \edef#1{%
468 \the\pgfkeys@tmptoks
469 }%
470 }
471
472
473 \pgfkeys{%
474 /errors/family unknown/.code=\pgfkeys@error{%
475 Sorry, I do not know family '#1' and can't work with any associated family handling. Perhaps you misspelled it?},
476 /errors/no such key filter/.code 2 args=\pgfkeys@error{Sorry, there is no such key filter '#1'.},
477 /errors/no such key filter handler/.code 2 args=\pgfkeys@error{Sorry, there is no such key filter handler '#1'.},
478 % HANDLERS:
479 %
480 % .is family should
481 % 1. '.cd' into the families' path,
482 % 2. define booleans to activate/deactivate the family
483 % (see \pgfkeysisfamilyactive)
484 % 3. make sure that \pgfkeyshasactivefamily returns true for
485 % the family itself.
486 /handlers/.is family/.append code={%
487 %\newif is an \outer macro in plain tex, so this here is not portable:
488 %\expandafter\newif\csname if\pgfkeyscurrentpath/familyactive\endcsname
489 \edef\pgfkeyspred@TMP{pgfk@\pgfkeyscurrentpath/familyactive}%
490 \expandafter\pgfkeys@non@outer@newif\expandafter{\pgfkeyspred@TMP}%
491 \edef\pgfkeyspred@TMP{\pgfkeyscurrentpath/.belongs to family=\pgfkeyscurrentpath}%
492 \expandafter\pgfkeysalso\expandafter{\pgfkeyspred@TMP}%
493 },%
494 /handlers/.activate family/.code=\pgfkeysactivatefamily{\pgfkeyscurrentpath},
495 /handlers/.deactivate family/.code=\pgfkeysdeactivatefamily{\pgfkeyscurrentpath},
496 /handlers/.belongs to family/.code={\pgfkeyssetfamily{\pgfkeyscurrentpath}{#1}},%
497 %
498 %
499 % An addition to the '.try' and '.retry' handlers:
500 %
501 % It is the same as '.retry', but if the option is still unknown, the
502 % usual handlers for unknown keys will be invoked.
503 /handlers/.lastretry/.code={%
504 \ifpgfkeyssuccess\else
505 \pgfkeys@try
506 \ifpgfkeyssuccess\else
507 \pgfkeys@split@path%
508 \pgfkeys@unknown
509 \fi
510 \fi
511 },
512 %
513 %
514 /handlers/.install key filter/.code={%
515 \pgfkeysinstallkeyfilter{\pgfkeyscurrentpath}{#1}%
516 },%
517 /handlers/.install key filter handler/.code={%
518 \pgfkeysinstallkeyfilterhandler{\pgfkeyscurrentpath}{#1}%
519 },%
520 %
521 %
522 % KEY FILTER HANDLERS:
523 %
524 /pgf/key filter handlers/append filtered to/.code={%
525 % Produce
526 % <orig key> '={' <value> '}'
527 % where both, the key and the value are expanded just ONCE:
528 \pgfkeys@tmptoks=\expandafter\expandafter\expandafter{\expandafter\pgfkeyscurrentkeyRAW\expandafter=\expandafter{\pgfkeyscurrentvalue}}%
529 \ifx#1\pgfkeys@empty
530 \else
531 % Produce <old list> ',' <orig key> '={' <value> '}'
532 \pgfkeys@tmptoks=\expandafter\expandafter\expandafter{\expandafter#1\expandafter,\the\pgfkeys@tmptoks}%
533 \fi
534 \edef#1{\the\pgfkeys@tmptoks}%
535 },%
536 /pgf/key filter handlers/ignore/.code={},
537 /pgf/key filter handlers/ignore/.install key filter handler,
538 /pgf/key filter handlers/log/.code={%
539 \pgf@typeout{LOG: the option '\pgfkeyscurrentkey' (was originally '\pgfkeyscurrentkeyRAW') (case \pgfkeyscasenumber) has not been processed due to pgfkeysfiltered.}%
540 },
541 %
542 %
543 % KEY FILTER PREDICATES:
544 %
545 % Returns true if the currently processed key belongs to an active family.
546 % A family is active if it has been activated before.
547 /pgf/key filters/active families/.code={%
548 \if\pgfkeyscasenumber0%
549 % unknown options shall be processed with the
550 % unknown-handlers.
551 \pgfkeysfiltercontinuetrue
552 \else
553 \if\pgfkeyscasenumber3%
554 \pgfkeysgetfamily\pgfkeyscurrentpath\pgfkeyspred@TMP
555 \else
556 \pgfkeysgetfamily\pgfkeyscurrentkey\pgfkeyspred@TMP
557 \fi
558 \ifpgfkeyssuccess
559 \pgfkeysisfamilyactive{\pgfkeyspred@TMP}%
560 \else% Ok, it does not belong to any family.
561 \pgfkeysfiltercontinuefalse
562 \fi
563 \fi
564 },%
565 %
566 %
567 %
568 % This filter works as follows:
569 % 1. if the current key belongs to a family:
570 % return whether its family is active,
571 % 2. if the current key does NOT belong to a family:
572 % return the result of criterion '#1',
573 % 3. the current key is unknown:
574 % return the result of criterion '#2'.
575 %
576 % Arguments:
577 % #1: the predicate which will be invoked in case 2.
578 % It will be invoked with the current case number as argument.
579 % #2: the predicate which will be invoked in case 3 with
580 % the current case number as argument.
581 /pgf/key filters/active families or no family/.code 2 args={%
582 \if\pgfkeyscasenumber0%
583 \pgfkeysevalkeyfilterwith{#2}%
584 \else
585 \if\pgfkeyscasenumber3%
586 \pgfkeysgetfamily\pgfkeyscurrentpath\pgfkeyspred@TMP
587 \else
588 \pgfkeysgetfamily\pgfkeyscurrentkey\pgfkeyspred@TMP
589 \fi
590 \ifpgfkeyssuccess
591 \pgfkeysisfamilyactive{\pgfkeyspred@TMP}%
592 \else% Ok, it does not belong to any family.
593 \pgfkeysevalkeyfilterwith{#1}%
594 \fi
595 \fi
596 },
597 /pgf/key filters/active families or no family DEBUG/.code 2 args={%
598 \if\pgfkeyscasenumber0%
599 \pgf@typeout{[pgfkeyshasactivefamilyornofamily(\pgfkeyscurrentkey, \pgfkeyscasenumber) invoking unknown handler '#2']}%
600 \pgfkeysevalkeyfilterwith{#2}%
601 \else
602 \if\pgfkeyscasenumber3%
603 \pgfkeysgetfamily\pgfkeyscurrentpath\pgfkeyspred@TMP
604 \else
605 \pgfkeysgetfamily\pgfkeyscurrentkey\pgfkeyspred@TMP
606 \fi
607 \ifpgfkeyssuccess
608 \pgfkeysisfamilyactive{\pgfkeyspred@TMP}%
609 \ifpgfkeysfiltercontinue
610 \pgf@typeout{[pgfkeyshasactivefamilyornofamily(\pgfkeyscurrentkey, \pgfkeyscasenumber) family is ACTIVE]}%
611 \else
612 \pgf@typeout{[pgfkeyshasactivefamilyornofamily(\pgfkeyscurrentkey, \pgfkeyscasenumber) family is NOT active.]}%
613 \fi
614 \else% Ok, it does not belong to any family.
615 \pgf@typeout{[pgfkeyshasactivefamilyornofamily(\pgfkeyscurrentkey, \pgfkeyscasenumber) invoking has-no-family-handler '#1']}%
616 \pgfkeysevalkeyfilterwith{#1}%
617 \fi
618 \fi
619 },
620 %
621 % A (faster) shortcut for
622 % /pgf/key filters/active families or no family=
623 % {/pgf/keys filters/false}
624 % {/pgf/keys filters/false}
625 /pgf/key filters/active families and known/.code={%
626 \if\pgfkeyscasenumber0%
627 \pgfkeysfiltercontinuefalse
628 \else
629 \if\pgfkeyscasenumber3%
630 \pgfkeysgetfamily\pgfkeyscurrentpath\pgfkeyspred@TMP
631 \else
632 \pgfkeysgetfamily\pgfkeyscurrentkey\pgfkeyspred@TMP
633 \fi
634 \ifpgfkeyssuccess
635 \pgfkeysisfamilyactive{\pgfkeyspred@TMP}%
636 \else% Ok, it does not belong to any family.
637 \pgfkeysfiltercontinuefalse
638 \fi
639 \fi
640 },
641 % A (faster) shortcut for
642 % /pgf/key filters/active families or no family=
643 % {/pgf/key filters/is descendant of=#1}% for keys without family
644 % {/pgf/keys filters/false}
645 /pgf/key filters/active families or descendants of/.code={%
646 \if\pgfkeyscasenumber0%
647 \pgfkeysfiltercontinuefalse
648 \else
649 \if\pgfkeyscasenumber3%
650 \pgfkeysgetfamily\pgfkeyscurrentpath\pgfkeyspred@TMP
651 \else
652 \pgfkeysgetfamily\pgfkeyscurrentkey\pgfkeyspred@TMP
653 \fi
654 \ifpgfkeyssuccess
655 \pgfkeysisfamilyactive{\pgfkeyspred@TMP}%
656 \else% Ok, it does not belong to any family.
657 % the 'is descendant of' implementation has been
658 % COPY PASTED here:
659 %
660 % string prefix comparison:
661 \def\pgfkeysisdescendantof@impl##1#1##2\pgf@@eov{%
662 \def\pgfkeyspred@TMP{##1}%
663 \ifx\pgfkeyspred@TMP\pgfkeys@empty
664 \pgfkeysfiltercontinuetrue
665 \else
666 \pgfkeysfiltercontinuefalse
667 \fi
668 }%
669 \expandafter\pgfkeysisdescendantof@impl\pgfkeyscurrentkey#1\pgf@@eov
670 \fi
671 \fi
672 },
673 %
674 % Processes only options which are children of #1.
675 % Example:
676 % is descendant of/.install key filter=/foo
677 % will be true for
678 % /foo/bar/x=y
679 % /foo/.cd
680 % /foo/bar/.style=...
681 % but not for
682 % /bar/foo/...
683 /pgf/key filters/is descendant of/.code={%
684 \if\pgfkeyscasenumber0%
685 %\message{'\pgfkeyscurrentkey' (case \pgfkeyscasenumber) is UNKNOWN. Calling unknown handler.}%
686 % unknown options shall be processed with the
687 % unknown-handlers.
688 \pgfkeysfiltercontinuetrue
689 \else
690 % string prefix comparison:
691 % [ note : this has been COPY-PASTED to
692 % |active families or descendants of| ]
693 \def\pgfkeysisdescendantof@impl##1#1##2\pgf@@eov{%
694 \def\pgfkeyspred@TMP{##1}%
695 \ifx\pgfkeyspred@TMP\pgfkeys@empty
696 %\message{'\pgfkeyscurrentkey' (case \pgfkeyscasenumber) is descendant of '#1': TRUE.}%
697 \pgfkeysfiltercontinuetrue
698 \else
699 %\message{'\pgfkeyscurrentkey' (case \pgfkeyscasenumber) is descendant of '#1': FALSE.}%
700 \pgfkeysfiltercontinuefalse
701 \fi
702 }%
703 \expandafter\pgfkeysisdescendantof@impl\pgfkeyscurrentkey#1\pgf@@eov
704 \fi
705 },%
706 %
707 %
708 %
709 % Returns true if the currently processed full key equals #2.
710 /pgf/key filters/equals/.code={%
711 \if\pgfkeyscasenumber0%
712 % Unknown option:
713 \pgfkeysfiltercontinuetrue
714 \else
715 \def\pgfkeyspred@TMP{#1}%
716 \ifx\pgfkeyscurrentkey\pgfkeyspred@TMP
717 \pgfkeysfiltercontinuetrue
718 \else
719 \pgfkeysfiltercontinuefalse
720 \fi
721 \fi
722 },%
723 %
724 %
725 % Argument #1 can be any other (evaluated) filter predicate, its logical return
726 % value will be inverted.
727 % Example:
728 % not/.install key filter={is descendant of=/tikz}
729 % will install a key filter which evaluates 'is descendant of' with argument
730 % '/tikz' and returns the logical negation of the result.
731 %
732 /pgf/key filters/not/.code={%
733 \pgfkeysevalkeyfilterwith{#1}%
734 \ifpgfkeysfiltercontinue
735 \pgfkeysfiltercontinuefalse
736 \else
737 \pgfkeysfiltercontinuetrue
738 \fi
739 },%
740 /pgf/key filters/and/.code 2 args={%
741 \pgfkeysevalkeyfilterwith{#1}%
742 \ifpgfkeysfiltercontinue
743 \pgfkeysevalkeyfilterwith{#2}%
744 \fi
745 },%
746 /pgf/key filters/or/.code 2 args={%
747 \pgfkeysevalkeyfilterwith{#1}%
748 \ifpgfkeysfiltercontinue
749 \else
750 \pgfkeysevalkeyfilterwith{#2}%
751 \fi
752 },%
753 /pgf/key filters/true/.code={\pgfkeysfiltercontinuetrue},%
754 /pgf/key filters/true/.install key filter,
755 /pgf/key filters/false/.code={%
756 \pgfkeysfiltercontinuefalse
757 },%
758 %
759 % Returns false if the current key is unknown, which avoids calling
760 % the unknown handlers.
761 /pgf/key filters/defined/.code={%
762 \if\pgfkeyscasenumber0%
763 \pgfkeysfiltercontinuefalse
764 \else
765 \pgfkeysfiltercontinuetrue
766 \fi
767 },
768 }%
769
770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
771 %
772 % Private IMPLEMENTATION
773 %
774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
775
776
777 % This command does THE SAME work as \pgfkeys@case@one,
778 % but it applies filtering whenever it identified the type of an
779 % option.
780 \def\pgfkeys@case@one@filtered{%
781 \pgfkeys@cur@is@descendant@of@errors
782 \ifpgfkeysfiltercontinue
783 \pgfkeys@orig@case@one
784 \else
785 \pgfkeysfiltercontinuetrue
786 \pgfkeysifdefined{\pgfkeyscurrentkey/.@cmd}{%
787 % CASE ONE: a command option
788 \def\pgfkeyscasenumber{1}%
789 \pgfkeys@key@predicate%
790 \ifpgfkeysfiltercontinue
791 %\message{PROCESSING KEY \pgfkeyscurrentkey!}%
792 \pgfkeysgetvalue{\pgfkeyscurrentkey/.@cmd}{\pgfkeys@code}%
793 \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov
794 \else
795 %\message{FILTERED OUT KEY \pgfkeyscurrentkey!}%
796 \pgfkeys@filtered@handler%
797 \fi
798 }{%
799 % CASE TWO: a normal value option
800 \pgfkeysifdefined{\pgfkeyscurrentkey}{%
801 \def\pgfkeyscasenumber{2}%
802 \pgfkeys@key@predicate%
803 \ifpgfkeysfiltercontinue
804 %\message{PROCESSING KEY \pgfkeyscurrentkey!}%
805 \pgfkeys@case@two@extern
806 \else
807 %\message{FILTERED OUT KEY \pgfkeyscurrentkey!}%
808 \pgfkeys@filtered@handler%
809 \fi
810 }{%
811 \pgfkeys@split@path
812 % CASE THREE: a handler
813 \pgfkeysifdefined{/handlers/\pgfkeyscurrentname/.@cmd}{%
814 \pgfkeys@ifexecutehandler{%
815 \def\pgfkeyscasenumber{3}%
816 \pgfkeys@key@predicate%
817 \ifpgfkeysfiltercontinue
818 %\message{PROCESSING KEY \pgfkeyscurrentkey!}%
819 \pgfkeysgetvalue{/handlers/\pgfkeyscurrentname/.@cmd}{\pgfkeys@code}%
820 \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov
821 \else
822 %\message{FILTERED OUT KEY \pgfkeyscurrentkey!}%
823 \pgfkeys@filtered@handler%
824 \fi
825 }{%
826 \pgfkeys@unknown
827 }%
828 }{%
829 \pgfkeys@unknown
830 }%
831 }%
832 }%
833 \fi
834 }%
835
836 \def\pgfkeys@unknown@filtered{%
837 % CASE ZERO: an unknown option.
838 \def\pgfkeyscasenumber{0}%
839 \pgfkeys@key@predicate%
840 \ifpgfkeysfiltercontinue
841 %\message{PROCESSING KEY \pgfkeyscurrentkey!}%
842 % start normal 'unknown' handlers:
843 \pgfkeys@orig@unknown
844 \else
845 %\message{FILTERED OUT KEY \pgfkeyscurrentkey!}%
846 \pgfkeys@filtered@handler%
847 \fi
848 }
849
850 % Does the same as \pgfkeys@try, but it also invokes the key filters.
851 \def\pgfkeys@try@filtered{%
852 \ifpgfkeysfiltercontinue
853 \pgfkeys@orig@try
854 \else
855 \pgfkeysfiltercontinuetrue
856 \edef\pgfkeyscurrentkey{\pgfkeyscurrentpath}% make sure that \pgfkeys@code doesn't know about 'try'. Important for .is choice
857 \ifx\pgfkeyscurrentvalue\pgfkeysnovalue@text% Hmm... no value
858 \pgfkeysifdefined{\pgfkeyscurrentpath/.@def}%
859 {\pgfkeysgetvalue{\pgfkeyscurrentpath/.@def}{\pgfkeyscurrentvalue}}
860 {}% no default, so leave it
861 \fi%
862 \pgfkeysifdefined{\pgfkeyscurrentpath/.@cmd}%
863 {%
864 % CASE ONE: a command option
865 \def\pgfkeyscasenumber{1}%
866 \pgfkeys@key@predicate%
867 \ifpgfkeysfiltercontinue
868 \pgfkeysgetvalue{\pgfkeyscurrentkey/.@cmd}{\pgfkeys@code}%
869 \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov%
870 \else
871 \pgfkeys@filtered@handler%
872 \fi
873 \pgfkeyssuccesstrue%
874 }%
875 {%
876 \pgfkeysifdefined{\pgfkeyscurrentpath}%
877 {% CASE TWO: a normal value option
878 \def\pgfkeyscasenumber{2}%
879 \pgfkeys@key@predicate%
880 \ifpgfkeysfiltercontinue
881 \ifx\pgfkeyscurrentvalue\pgfkeysnovalue@text%
882 \pgfkeysvalueof{\pgfkeyscurrentpath}%
883 \else%
884 \pgfkeyslet{\pgfkeyscurrentpath}\pgfkeyscurrentvalue%
885 \fi%
886 \else
887 \pgfkeys@filtered@handler%
888 \fi
889 \pgfkeyssuccesstrue%
890 }%
891 {%
892 \pgfkeys@split@path%
893 \pgfkeysifdefined{/handlers/\pgfkeyscurrentname/.@cmd}{%
894 % CASE THREE: a handled key
895 %
896 % in the standard configuration, this check here is redundant
897 % because pgfkeys@ifexecutehandler === true.
898 % It is only interesting for 'handle only existing'.
899 \pgfkeys@ifexecutehandler{%
900 \def\pgfkeyscasenumber{3}%
901 \pgfkeys@key@predicate%
902 \ifpgfkeysfiltercontinue
903 %\message{PROCESSING KEY \pgfkeyscurrentkey!}%
904 \pgfkeysgetvalue{/handlers/\pgfkeyscurrentname/.@cmd}{\pgfkeys@code}%
905 \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov
906 \else
907 %\message{FILTERED OUT KEY \pgfkeyscurrentkey!}%
908 \pgfkeys@filtered@handler%
909 \fi
910 \pgfkeyssuccesstrue%
911 }{%
912 \pgfkeyssuccessfalse
913 }%
914 }{%
915 \pgfkeyssuccessfalse
916 }%
917 }%
918 }%
919 \fi
920 }
921
922
923 % #1 the code to invoke after init and before cleanup
924 \long\def\pgfkeys@install@filter@and@invoke#1{%
925 \ifpgfkeysfilteringisactive
926 \pgfkeys@error{Sorry, nested calls to key filtering routines are not allowed. (reason: It is not possible to properly restore the previous filtering state after returning from the nested call)}%
927 \fi
928 \pgfkeysfilteringisactivetrue
929 \let\pgfkeys@case@one=\pgfkeys@case@one@filtered
930 \let\pgfkeys@try=\pgfkeys@try@filtered
931 \let\pgfkeys@unknown=\pgfkeys@unknown@filtered
932 #1%
933 \let\pgfkeys@case@one=\pgfkeys@orig@case@one
934 \let\pgfkeys@try=\pgfkeys@orig@try
935 \let\pgfkeys@unknown=\pgfkeys@orig@unknown
936 \pgfkeysfilteringisactivefalse
937 }
938
939
940 %--------------------------------------------------
941 % \def\pgfkeys@eval@key@filter@subroutine@case@one{%
942 % \pgfkeysifdefined{\pgfkeyscurrentkey/.@cmd}{%
943 % \pgfkeysgetvalue{\pgfkeyscurrentkey/.@cmd}{\pgfkeys@code}%
944 % \let\pgfkeyspred@TMP=\pgfkeyscurrentvalue
945 % \pgfkeys@eval@key@filter@subroutine@restorestate
946 % \expandafter\pgfkeys@code\pgfkeyspred@TMP\pgfeov
947 % }{%
948 % \pgfkeysvalueof{/errors/no such key filter/.@cmd}\pgfkeyscurrentkey\pgfkeyscurrentvalue\pgfeov%
949 % }%
950 % }
951 % % THIS VERSION IS TOO SLOW. See below.
952 % \def\pgfkeysevalkeyfilterwith#1{%
953 % \edef\pgfkeys@eval@key@filter@subroutine@restorestate{%
954 % \noexpand\def\noexpand\pgfkeyscurrentkey{\pgfkeyscurrentkey}%
955 % \noexpand\def\noexpand\pgfkeyscurrentkeyRAW{\pgfkeyscurrentkeyRAW}%
956 % \noexpand\def\noexpand\pgfkeyscurrentname{\pgfkeyscurrentname}%
957 % \noexpand\def\noexpand\pgfkeyscurrentvalue{\pgfkeyscurrentvalue}%
958 % \noexpand\pgfkeys@pathtoks={\pgfkeyscurrentpath}%
959 % }%
960 % \pgfkeysinterruptkeyfilter
961 % \let\pgfkeys@case@one=\pgfkeys@eval@key@filter@subroutine@case@one
962 % \pgfkeysalso{#1}%
963 % \endpgfkeysinterruptkeyfilter% this here also restored \pgfkeys@case@one.
964 % \pgfkeys@eval@key@filter@subroutine@restorestate
965 % }%
966 %--------------------------------------------------
967
968
969 % Evaluates a key filter '#1'. Example:
970 % \pgfkeysevalkeyfilterwith{/pgf/key filters/equals=/tikz}
971 %
972 % \pgfkeysevalkeyfilterwith works only if key filtering is
973 % active.
974 %
975 % The argument '#1' MUST be a FULL KEY.
976 %
977 % The implementation employs a subset of the \pgfkeysalso code.
978 \long\def\pgfkeysevalkeyfilterwith#1{%
979 \pgfkeys@eval@key@filter@subroutine@unpack#1=\pgfkeysnovalue=\pgfkeys@stop
980 }%
981 \long\def\pgfkeys@eval@key@filter@subroutine@unpack#1=#2=#3\pgfkeys@stop{%
982 \pgfkeys@spdef\pgfkeyspred@TMP{#1}%
983 \edef\pgfkeyspred@TMP{\pgfkeyspred@TMP}%
984 \pgfkeys@spdef\pgfkeyspred@TMPB{#2}% TMPB=value
985 \ifx\pgfkeyspred@TMPB\pgfkeysnovalue@text% Hmm... no value
986 \pgfkeysifdefined{\pgfkeyspred@TMP/.@def}%
987 {\pgfkeysgetvalue{\pgfkeyspred@TMP/.@def}{\pgfkeyspred@TMPB}}
988 {}% no default, so leave it
989 \fi%
990 \ifx\pgfkeyspred@TMPB\pgfkeysvaluerequired%
991 \pgfkeysvalueof{/errors/value required/.@cmd}\pgfkeyspred@TMP\pgfkeyspred@TMPB\pgfeov%
992 \else%
993 \pgfkeysifdefined{\pgfkeyspred@TMP/.@cmd}{%
994 \pgfkeysgetvalue{\pgfkeyspred@TMP/.@cmd}{\pgfkeys@code}%
995 \expandafter\pgfkeys@code\pgfkeyspred@TMPB\pgfeov
996 }{%
997 \pgfkeysvalueof{/errors/no such key filter/.@cmd}\pgfkeyspred@TMP\pgfkeyspred@TMPB\pgfeov%
998 }%
999 \fi%
1000 }
1001
1002
1003 \def\pgfkeys@non@outer@newif@#1#2{%
1004 \expandafter\edef\csname #2true\endcsname{\noexpand\let\noexpand#1=\noexpand\iftrue}%
1005 \expandafter\edef\csname #2false\endcsname{\noexpand\let\noexpand#1=\noexpand\iffalse}%
1006 \csname #2false\endcsname
1007 }%
1008
1009 % For latex and context, this here has the same effect as a \newif
1010 % applied to 'if#1'. For plain tex, it has also the same effect, but
1011 % it is not an \outer macro as the plain-tex \newif.
1012 \def\pgfkeys@non@outer@newif#1{%
1013 \expandafter\pgfkeys@non@outer@newif@\csname if#1\endcsname{#1}%
1014 }
1015 \endinput