Debian Codegraph @

texmf-dist/tex/latex/tikz-dependency/pgfmanual.prettyprinter.code.tex

raw
1 %--------------------------------------------
2 %
3 % Package pgfplots
4 %
5 % Provides a user-friendly interface to create function plots (normal
6 % plots, semi-logplots and double-logplots).
7 %
8 % It is based on Till Tantau's PGF package.
9 %
10 % Copyright 2007/2008/2009 by Christian Feuersänger.
11 %
12 % This program is free software: you can redistribute it and/or modify
13 % it under the terms of the GNU General Public License as published by
14 % the Free Software Foundation, either version 3 of the License, or
15 % (at your option) any later version.
16 %
17 % This program is distributed in the hope that it will be useful,
18 % but WITHOUT ANY WARRANTY; without even the implied warranty of
19 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 % GNU General Public License for more details.
21 %
22 % You should have received a copy of the GNU General Public License
23 % along with this program. If not, see <http://www.gnu.org/licenses/>.
24 %
25 %--------------------------------------------
26
27 % this is some kind of "plug-in" for pgfmanual-en-macros.tex which
28 % provides pretty printing of the code lines in 'codeexample'.
29 %
30 % It requires to be invoked with \pgfmanualprettyprintcode{#1} at the
31 % right place.
32 %
33 % ATTENTION:
34 % this is NOT a sophisticated syntax highlighter like lstlistings!
35 % It has rather strict assumptions about how to use it (the input must
36 % have been read verbatim, for example).
37
38 % Special code for syntax highlighting:
39 %
40 %
41 % USER INTERFACE
42 \pgfkeys{%
43 % this is the public hook into
44 % \begin{codeexample}...\end{codeexample} which triggers pretty
45 % printing:
46 /codeexample/typeset listing/.code= {\pgfmanualprettyprintcode{#1}},
47 %
48 % this key will be invoked whenever a key in key-value context has been identified.
49 %
50 % It won't be invoked for handled keys like |my style/.style=....|, see below.
51 %
52 % #1 will be the keys name.
53 /codeexample/prettyprint/key name/.code={#1},
54 %
55 % A variant which will be used instead of |key name| if the key
56 % has a key handler. For example, when the pretty printer finds
57 % |my style/.style|, it will call
58 % |key name with handler={my style}{.style}.
59 /codeexample/prettyprint/key name with handler/.code 2 args={#1/#2},
60 %
61 % Will be invoked whenever the value of a key has been found.
62 % It will be invoked AFTER 'key name' and not at all if there was
63 % no value.
64 %
65 % #1: the key's name
66 % #2: the key's value.
67 %
68 % The default implementation checks if there is a special handler
69 % for the key name '#1', in
70 % /codeexample/prettyprint/key value/#1.
71 % For example:
72 % /codeexample/prettyprint/key value/my key/.code 2 args={name=#1, value =#2}
73 % If such a key exists, it will be invoked with {#1}{#2} as
74 % arguments. Otherwise, the generic method
75 % /codeexample/prettyprint/key value with style detection={#1}{#2}
76 % will be invoked.
77 /codeexample/prettyprint/key value/.code 2 args={%
78 \pgfkeysifdefined{/codeexample/prettyprint/key value/#1}{%
79 \pgfkeysalso{/codeexample/prettyprint/key value/#1={#1}{#2}}%
80 }{%
81 \pgfkeysalso{/codeexample/prettyprint/key value with style detection={#1}{#2}}%
82 }%
83 },
84 % A helper macro for the default 'key value' implementation.
85 /codeexample/prettyprint/key value with style detection/.code 2 args={%
86 \pgfutil@in@{style}{#1}%
87 \ifpgfutil@in@
88 \pgfmanualprettyprintpgfkeys{#2}%
89 \else
90 \pgfkeysalso{/codeexample/prettyprint/key value display only={#2}}%
91 \fi
92 },%
93 %
94 % Will be invoked by the default 'key value' implementation to
95 % typeset the value as such.
96 /codeexample/prettyprint/key value display only/.code={#1},
97 %
98 % Used to typeset a single word. A word is something which has not
99 % been identified in any other context; a maximal sequence of
100 % non-white-space tokens.
101 /codeexample/prettyprint/word/.code={#1},
102 %
103 % A two-argument code key which invokes '#1' if spaces shall
104 % delimit words and '#2' if not.
105 % This may be useless. Handle with care!
106 /codeexample/prettyprint/if space is word delim/.code 2 args={%
107 #1%
108 },%
109 %
110 % A three-argument code key which should invoke '#2' if the single
111 % token '#1' is a word delimiter and '#3' if that is not the case.
112 % Note that '#1' doesn't have the usual catcodes (see the
113 % \pgfmanual@pretty@** macros)!
114 % Furthermore, white spaces are treated separately.
115 /codeexample/prettyprint/if is word delim/.code args={#1#2#3}{%
116 \edef\pgfmanual@check{,;().;\pgfmanual@pretty@lbrace\pgfmanual@pretty@rbrace}%
117 \def\pgfmanual@check@{\pgfutil@in@{#1}}%
118 \expandafter\pgfmanual@check@\expandafter{\pgfmanual@check}%
119 \ifpgfutil@in@ #2\else #3\fi
120 },%
121 %
122 % Used to typeset a single control sequence.
123 % #1 is the control sequence's name as a sequence of catcode 12
124 % tokens.
125 /codeexample/prettyprint/cs/.code={#1},
126 %
127 % Used to typeset a single control sequence together with one or
128 % more arguments.
129 %
130 % #1 is the control sequence's name (including the backslash as
131 % literal string) and
132 % #2,#3,...,#9 are the arguments. The number of arguments depends
133 % on the 'cs arguments/<CS NAME>' key; it contains the integer
134 % number.
135 %
136 % For example, if
137 % |cs arguments/pgfkeys/.initial=1|,
138 % the pretty printer invokes
139 % |cs with args={\pgfkeys}{<argument>}.
140 %
141 % If
142 % |cs arguments/mycommand/.initial=2|,
143 % the pretty printer invokes
144 % |cs with args={\pgfkeys}{<argument1>}{<argument2>}.
145 % In this case, 'cs with args' needs to be defined in a way which
146 % allows to deal with 3 arguments.
147 %
148 % Please note that the value do not contain braces! The braces
149 % need to be inserted manually.
150 %
151 % Special cases:
152 % 1. If end-of-input is encountered BEFORE the expected number of
153 % arguments has been found, the following happens:
154 % - if not even one (partial) argument has been found, the
155 % /codeexample/prettyprint/cs/.@cmd key will be used instead.
156 % - the \ifpgfmanualprettyprinterarghasunmatchedbraces boolean
157 % indicates if the trailing brace is missing.
158 /codeexample/prettyprint/cs with args/.code 2 args={#1\{#2\pgfmanualclosebrace},
159 %
160 % For every identified control sequence, the key
161 % /codeexample/prettyprint/cs arguments/<CSNAME>
162 % will be checked. If it exists, it contains an integer with the
163 % number of arguments it takes.
164 % The <CSNAME> must not contain the '\'.
165 /codeexample/prettyprint/cs arguments/pgfkeys/.initial=1,
166 %
167 % For every identified control sequence, the key
168 % /codeexample/prettyprint/cs/<CSNAME>/.@cmd
169 % will be checked. If it exists, it will be used instead of
170 % 'cs with args' (with the same special case restrictions for
171 % early end-of-input).
172 %
173 % The <CSNAME> must not contain the '\'.
174 %
175 % This allows special treatment for special
176 % commands like \pgfkeys:
177 /codeexample/prettyprint/cs/pgfkeys/.code 2 args={#1\{\pgfmanualprettyprintpgfkeys{#2}\pgfmanualclosebrace},
178 %
179 % recognise environments:
180 /codeexample/prettyprint/cs arguments/begin/.initial=1,
181 /codeexample/prettyprint/cs/begin/.code 2 args={#1\{#2\pgfmanualclosebrace},
182 /codeexample/prettyprint/cs arguments/end/.initial=1,
183 /codeexample/prettyprint/cs/end/.code 2 args={#1\{#2\pgfmanualclosebrace},
184 %
185 % a point coordinate (#1)
186 % Note that '#1' will contain the braces (if there was one),
187 /codeexample/prettyprint/point/.code={#1},%
188 %
189 % a point coordinate with explicit coordinate system: (#1:#2)
190 % Note that '#2' will contain the terminating brace (if there was one)
191 % #1: the coordinate system name (*without* the leading brace).
192 % The leading brace must be re-inserted by this style.
193 /codeexample/prettyprint/point with cs/.code 2 args={(#1:#2},%
194 % the same with specialised code:
195 %/codeexample/prettyprint/point with cs/<CS NAME>/.code 2 args={(#1:#2},%
196 %
197 %
198 % A predefined style which colors every identified token. It's
199 % purpose is only debugging.
200 /codeexample/prettyprint/colored/.style={%
201 /codeexample/prettyprint/key name/.code={\textcolor{red!75!black}{##1}},
202 /codeexample/prettyprint/key name with handler/.code 2 args={\textcolor{red!75!black}{##1}/\textcolor{red!90!black}{##2}},
203 /codeexample/prettyprint/key value display only/.code={\textcolor{yellow}{##1}},
204 /codeexample/prettyprint/cs/.code={\textcolor{green}{##1}},
205 /codeexample/prettyprint/cs with args/.code 2 args={\textcolor{green}{##1}\{\textcolor{orange}{##2}\pgfmanualclosebrace},
206 /codeexample/prettyprint/cs arguments/pgfkeys/.initial=1,
207 /codeexample/prettyprint/cs/pgfkeys/.code 2 args={\textcolor{green}{##1}\{\pgfmanualprettyprintpgfkeys{##2}\pgfmanualclosebrace},
208 /codeexample/prettyprint/cs arguments/begin/.initial=1,
209 /codeexample/prettyprint/cs/begin/.code 2 args={\textcolor{green}{##1}\{\textcolor{orange}{##2}\pgfmanualclosebrace},
210 /codeexample/prettyprint/cs arguments/end/.initial=1,
211 /codeexample/prettyprint/cs/end/.code 2 args={\textcolor{green}{##1}\{\textcolor{orange}{##2}\pgfmanualclosebrace},
212 /codeexample/prettyprint/word/.code={\textcolor{brown}{##1}},
213 /codeexample/prettyprint/point/.code={\textcolor{red}{##1}},%
214 /codeexample/prettyprint/point with cs/.code 2 args={(\textcolor{green}{##1}:\textcolor{red}{##2}},%
215 },%
216 % A further debuggin helper.
217 /codeexample/prettyprint/colored and verbose/.style={%
218 /codeexample/prettyprint/colored,
219 /codeexample/prettyprint/key name/.code={\message{[key name=##1]}\textcolor{red!75!black}{##1}},
220 /codeexample/prettyprint/key name with handler/.code 2 args={\message{[key name with handler=##1/##2]}\textcolor{red!75!black}{##1}/\textcolor{red!90!black}{##2}},
221 /codeexample/prettyprint/key value display only/.code={\def\temp{##1}\message{[key value=\meaning\temp]}\textcolor{yellow}{##1}},
222 /codeexample/prettyprint/cs/.code={\message{[cs=##1]}\textcolor{green}{##1}},
223 /codeexample/prettyprint/cs with args/.code 2 args={\def\temp{##2}\message{[cs with args={##1}{\meaning\temp}]}\textcolor{green}{##1}\{\textcolor{orange}{##2}\pgfmanualclosebrace},
224 /codeexample/prettyprint/word/.code={\message{[word=##1]}\textcolor{brown}{##1}},
225 /codeexample/prettyprint/point/.code={\message{[point=##1]}\textcolor{red}{##1}},%
226 /codeexample/prettyprint/point with cs/.code 2 args={\message{[point with cs={##1}{##2}]}(\textcolor{green}{##1}:\textcolor{red}{##2}},%
227 },%
228 %/codeexample/prettyprint/colored,
229 %/codeexample/prettyprint/colored and verbose,
230 }%
231
232 \newif\ifpgfmanualprettyenabled
233 \pgfmanualprettyenabledtrue
234
235 % User interface command to handle unmatched braces:
236 %
237 % It expands to '\}' unless the preceding argument had unmatched braces.
238 \def\pgfmanualclosebrace{%
239 \ifpgfmanualprettyprinterarghasunmatchedbraces
240 \else
241 \}%
242 \fi
243 }%
244
245
246 % Typesets '#1', possibly using some sort of pretty printer.
247 %
248 % The argument '#1' is expected to be a long token list in which
249 % 1. all characters have catcode 11 or 12 (normal letters),
250 % 2. white spaces, tabs and newlines have catcode 13 (are active).
251 %
252 % @see \pgfmanualprettyprintpgfkeys
253 \long\def\pgfmanualprettyprintcode#1{%
254 %\def\temp{#1}\message{STARTING PRETTY PRINTING for \meaning\temp}%
255 \ifpgfmanualprettyenabled
256 \begingroup
257 \pgfmanualprettyprintstyles
258 \pgfmanual@pretty@mainloop#1\pgfmanual@EOI
259 \endgroup
260 \else
261 #1%
262 \fi
263 }%
264 % DISABLE:
265 %\long\def\pgfmanualprettyprintcode#1{#1}%
266
267 \def\pgfmanualprettyprintstyles{%
268 %\tracingmacros=2 \tracingcommands=2 \message{PRETTYPRINT INIT}%
269 \def\{{\pgfmanual@pretty@lbrace}%
270 \def\}{\pgfmanual@pretty@rbrace}%
271 \pgfmanual@pretty@installcommenthandler
272 \let\pgfmanualprettyprintstyles=\relax
273 }%
274
275
276 \newif\ifpgfmanualprettycommentactive
277
278 % we can't use the \@typeset@till@return method for comments because
279 % the pretty printer needs full control over the token list.
280 %
281 % We try a replacement here.
282 %
283 % FIXME
284 % THIS INTRODUCES A NEW GROUP! Does that hurt the pretty printer??
285 %
286 \def\pgfmanual@pretty@installcommenthandler{%
287 \expandafter\def\pgfmanual@pretty@activepercent{%
288 \begingroup
289 \pgfmanualprettycommentactivetrue
290 \expandafter\let\pgfmanual@pretty@activenl=\pgfmanual@pretty@recoveraftercomment
291 \expandafter\def\pgfmanual@pretty@activepercent{\%}%
292 %\tt
293 \% %
294 }%
295 }%
296 \def\pgfmanual@pretty@recoveraftercomment{%
297 \endgroup
298 \pgfmanual@pretty@activenl
299 }%
300
301 \def\pgfmanual@EOI{\pgfmanual@EOI}%
302
303 {
304 \catcode`\[=0
305 \catcode`\\=12
306 [gdef[pgfmanual@pretty@backslash{\}%
307 }
308 \begingroup
309 \catcode`\:=12
310 \catcode`\(=12
311 \catcode`\)=12
312 \gdef\pgfmanual@pretty@colon{:}%
313 \gdef\pgfmanual@pretty@lroundbrace{(}%
314 \gdef\pgfmanual@pretty@rroundbrace{)}%
315 \catcode`\[=1
316 \catcode`\]=2
317 \catcode`\{=12
318 \catcode`\}=12
319 \gdef\pgfmanual@pretty@lbrace[{]%
320 \gdef\pgfmanual@pretty@rbrace[}]%
321 \catcode`\{=1
322 \catcode`\}=2
323 \catcode`\[=12
324 \catcode`\]=12
325 \catcode`\,=12
326 \catcode`\ =10\relax\gdef\pgfmanual@pretty@space{ }%
327 \gdef\pgfmanual@pretty@lbracket{[}%
328 \gdef\pgfmanual@pretty@rbracket{]}%
329 \gdef\pgfmanual@pretty@comma{,}%
330 \catcode`\==12
331 \gdef\pgfmanual@pretty@eq{=}%
332 \endgroup
333 \begingroup
334 \catcode`\%=12
335 \gdef\pgfmanual@pretty@percent{%}
336 \catcode`\%=13
337 \gdef\pgfmanual@pretty@activepercent{%}
338 \catcode`\^^M=13
339 \gdef\pgfmanual@pretty@activenl{^^M}\endgroup
340 \begingroup
341 \catcode`\^^I=13\relax\gdef\pgfmanual@pretty@activetab{^^I}%
342 \catcode`\ =13\relax\gdef\pgfmanual@pretty@activespace{ }\endgroup
343
344 % loops through all tokens.
345 % #1 is a single token.
346 \def\pgfmanual@pretty@mainloop{%
347 \def\pgfmanual@pretty@mainloop@currentword{}%
348 \pgfmanual@pretty@mainloop@
349 }%
350 \long\def\pgfmanual@pretty@mainloop@#1{%
351 \def\pgfmanual@loc@TMPa{#1}%
352 \let\pgfmanual@pretty@mainloop@NEXT=\pgfmanual@pretty@mainloop@
353 \ifx\pgfmanual@loc@TMPa\pgfmanual@EOI
354 % stop iteration.
355 \pgfmanual@pretty@mainloop@finishword
356 \let\pgfmanual@pretty@mainloop@NEXT=\relax
357 \else
358 \ifpgfmanualprettycommentactive
359 #1%
360 \else
361 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@lbracket%
362 % we found the start of OPTIONS '[ ... ]'.
363 \pgfmanual@pretty@mainloop@finishword
364 % Attempt syntax highlighting for pgfkeys:
365 \let\pgfmanual@pretty@mainloop@NEXT=\pgfmanual@pretty@pgfkeys
366 \else
367 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@backslash
368 % we found the start of a control sequence '\command'
369 \pgfmanual@pretty@mainloop@finishword
370 %
371 % collect the control sequence name into
372 % \pgfmanual@loc@TMPa, but without the backslash:
373 \let\pgfmanual@loc@TMPa=\pgfutil@empty
374 \let\pgfmanual@pretty@mainloop@NEXT=\pgfmanual@pretty@collectcs@loop
375 \else
376 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@lroundbrace%
377 \pgfmanual@pretty@mainloop@finishword
378 \let\pgfmanual@pretty@mainloop@NEXT=\pgfmanual@pretty@collectpoint
379 \else
380 \def\pgfmanual@isspace{0}%
381 \ifnum13=\catcode`#1
382 % we found a white space (space, TAB or NL) or comment
383 \def\pgfmanual@isspace{1}%
384 \else
385 \ifnum10=\catcode`#1
386 \def\pgfmanual@isspace{1}%
387 \fi
388 \fi
389 \if\pgfmanual@isspace1%
390 \pgfkeysvalueof{/codeexample/prettyprint/if space is word delim/.@cmd}{%
391 \pgfmanual@pretty@mainloop@finishword
392 #1% ok, show it.
393 }{%
394 % collect the word.
395 \expandafter\def\expandafter\pgfmanual@pretty@mainloop@currentword\expandafter{\pgfmanual@pretty@mainloop@currentword #1}%
396 }%
397 \else
398 \pgfkeysvalueof{/codeexample/prettyprint/if is word delim/.@cmd}{#1}{%
399 \pgfmanual@pretty@mainloop@finishword
400 #1% ok, show the delimiter.
401 }{%
402 % collect the word.
403 \expandafter\def\expandafter\pgfmanual@pretty@mainloop@currentword\expandafter{\pgfmanual@pretty@mainloop@currentword #1}%
404 }\pgfeov%
405 \fi
406 \fi
407 \fi
408 \fi
409 \fi
410 \fi
411 \pgfmanual@pretty@mainloop@NEXT
412 }%
413
414 \def\pgfmanual@pretty@mainloop@finishword{%
415 \ifx\pgfmanual@pretty@mainloop@currentword\pgfutil@empty
416 \else
417 \def\pgfmanual@loc@TMPa{\pgfkeysvalueof{/codeexample/prettyprint/word/.@cmd}}%
418 \expandafter\pgfmanual@loc@TMPa\pgfmanual@pretty@mainloop@currentword\pgfeov
419 \let\pgfmanual@pretty@mainloop@currentword=\pgfutil@empty
420 \fi
421 }%
422
423 \def\pgfmanual@pretty@collectpoint{%
424 \let\pgfmanualprettyprinterhandlecollectedargs=\pgfmanual@pretty@collectargs@finish@collectpoint
425 \expandafter\pgfmanualprettyprintercollectupto\pgfmanual@pretty@rroundbrace
426 {\afterpgfmanual@pretty@collectpoint}%
427 }
428
429 {
430 \catcode`\:=12
431 \gdef\pgfmanual@pretty@collectargs@finish@collectpoint#1{%
432 \expandafter\pgfutil@in@\pgfmanual@pretty@colon{#1}%
433 \ifpgfutil@in@
434 \def\pgfmanual@pretty@collectpoint@getcoordsystem##1:##2\relax{%
435 \begingroup
436 \pgfmanual@pretty@restorespaces
437 % remove active spaces from ##1:
438 \xdef\pgfmanual@pretty@glob@TMPa{##1}%
439 \endgroup
440 \pgfkeysifdefined{/codeexample/prettyprint/point with cs/\pgfmanual@pretty@glob@TMPa/.@cmd}{%
441 \def\pgfmanual@loc@TMPb{\pgfkeysvalueof{/codeexample/prettyprint/point with cs/\pgfmanual@pretty@glob@TMPa/.@cmd}}%
442 }{%
443 \def\pgfmanual@loc@TMPb{\pgfkeysvalueof{/codeexample/prettyprint/point with cs/.@cmd}}%
444 }%
445 \expandafter\def\expandafter\pgfmanual@loc@TMPa\expandafter{\expandafter{\pgfmanual@pretty@glob@TMPa}{##2}}%
446 \expandafter\pgfmanual@loc@TMPb\pgfmanual@loc@TMPa\pgfeov
447 }%
448 \ifpgfmanualprettyprinterfoundterminator
449 \pgfmanual@pretty@collectpoint@getcoordsystem#1)\relax
450 \else
451 \pgfmanual@pretty@collectpoint@getcoordsystem#1\relax
452 \fi
453 \else
454 \def\pgfmanual@loc@TMPb{\pgfkeysvalueof{/codeexample/prettyprint/point/.@cmd}}%
455 \ifpgfmanualprettyprinterfoundterminator
456 \pgfmanual@loc@TMPb(#1)\pgfeov
457 \else
458 \pgfmanual@loc@TMPb(#1\pgfeov
459 \fi
460 \fi
461 }%
462 }
463 \def\afterpgfmanual@pretty@collectpoint{\pgfmanual@pretty@mainloop}%
464
465 % loops through all tokens, assembling the cs name as it goes.
466 % #1 is a single token.
467 \def\pgfmanual@pretty@collectcs@loop#1{%
468 \let\pgfmanual@pretty@collectcs@loop@NEXT=\pgfmanual@pretty@collectcs@loop
469 \def\pgfmanual@loc@TMPb{#1}%
470 \ifx\pgfmanual@loc@TMPb\pgfmanual@EOI
471 \def\pgfmanual@pretty@collectcs@loop@NEXT{\pgfmanual@pretty@collectcs@loop@END #1}%
472 \else
473 % a csname may only use letters. And: only letters have a
474 % positive lcccode!
475 \ifnum\lccode`#1=0
476 \ifx\pgfmanual@loc@TMPb @%
477 % ok, we may also accept an `@':
478 \edef\pgfmanual@loc@TMPa{\pgfmanual@loc@TMPa #1}%
479 \else
480 % This here is the first non-letter.
481 \def\pgfmanual@pretty@collectcs@loop@NEXT{\pgfmanual@pretty@collectcs@loop@END #1}%
482 \fi
483 \else
484 % continue iterating and assemble the csname...
485 \edef\pgfmanual@loc@TMPa{\pgfmanual@loc@TMPa #1}%
486 \fi
487 \fi
488 \pgfmanual@pretty@collectcs@loop@NEXT
489 }%
490 \def\afterpgfmanual@pretty@cs{\pgfmanual@pretty@mainloop}%
491
492 \def\pgfmanual@pretty@collectcs@loop@END{%
493 \pgfkeysifdefined{/codeexample/prettyprint/cs arguments/\pgfmanual@loc@TMPa}{%
494 % oh. The collected control sequence expects arguments. That
495 % means a lot of work since there are no nestable braces in
496 % the token list! All of them have catcode 12... we need to do
497 % that manually.
498 \let\pgfmanualprettyprinterhandlecollectedargs=\pgfmanual@pretty@collectargs@finish@cs
499 \def\pgfmanual@pretty@collectcs@loop@END@next{%
500 \pgfmanualprettyprintercollectargcount
501 {\pgfkeysvalueof{/codeexample/prettyprint/cs arguments/\pgfmanual@loc@TMPa}}%
502 {\afterpgfmanual@pretty@cs}%
503 }%
504 }{%
505 % re-insert the backslash:
506 \edef\pgfmanual@loc@TMPa{\pgfmanual@pretty@backslash \pgfmanual@loc@TMPa}%
507 % ok, report the macro and continue with the main loop.
508 \def\pgfmanual@loc@TMPb{\pgfkeysvalueof{/codeexample/prettyprint/cs/.@cmd}}%
509 \expandafter\pgfmanual@loc@TMPb\pgfmanual@loc@TMPa\pgfeov
510 \let\pgfmanual@pretty@collectcs@loop@END@next=\afterpgfmanual@pretty@cs
511 }%
512 \pgfmanual@pretty@collectcs@loop@END@next
513 }%
514
515 \newif\ifpgfmanualprettyprinterarghasunmatchedbraces
516
517 % Collects arguments inside of a token list, dealing with nested
518 % catcode-12-braces.
519 %
520 % #1: is the NUMBER of arguments to collect.
521 % #2: is TeX code which shall be invoked after
522 % \pgfmanualprettyprinterhandlecollectedargs has been invoked (see
523 % below).
524 %
525 % PRECONDITION:
526 % there is a large token list following
527 % \pgfmanualprettyprintercollectargcount with balanced braces. The braces
528 % have \catcode 12.
529 % POSTCONDITION:
530 % 1. the arguments will be collected as
531 % '<result> := {<first arg>}{<second arg>}',
532 % 2.1 the macro \pgfmanualprettyprinternumcollectedargs will contain
533 % the *actual* number of *completely* collected arguments,
534 % 2.2 the if \ifpgfmanualprettyprinterarghasunmatchedbraces will be
535 % set to \c true if the last found argument had an unmatched brace,
536 % 3. then, \pgfmanualprettyprinterhandlecollectedargs{<result>} will be
537 % invoked. Just define \pgfmanualprettyprinterhandlecollectedargs
538 % properly.
539 % Afterwards, #2 will be invoked to recover from the argument
540 % collection.
541 %
542 %
543 % Example:
544 % \pgfmanualprettyprintercollectargcount{2}{\donnextstep}
545 % {_12 first argument }_12 {_12 second argument }_12 next tokens%
546 %
547 % will result in the expansion
548 % \pgfmanualprettyprinterhandlecollectedargs{{_1 first argument }_2 {_1 second argument }_2 }
549 % \donnextstep
550 % next tokens
551 %
552 %
553 %
554 % ATTENTION:
555 % \pgfmanualprettyprinterhandlecollectedargs will be invoked with a SINGLE
556 % argument. The argument as such will contain extra braces, one pair
557 % of braces for each of the #1 arguments. These braces will have
558 % catcode 1 and 2, i.e. they can *really* be used in TeX. Thus, the
559 % finish routine will be invoked with
560 % \pgfmanualprettyprinterhandlecollectedargs{{<arg>}}
561 % for one argument and with
562 % \pgfmanualprettyprinterhandlecollectedargs{{<first arg>}{<second arg>}}
563 % for two and more arguments. Note the extra set of braces for one
564 % arg.
565 % It might happen that not all arguments have been found if
566 % end-of-input occured before. The
567 % \pgfmanualprettyprinterhandlecollectedargs routine has to check
568 % this using the macro \pgfmanualprettyprinternumcollectedargs which
569 % contains the actual number of collected args.
570 %
571 % @remark This macro checks for the end-of-input indicator, \pgfmanual@EOI. In case it encounters
572 % \pgfmanual@EOI, it
573 % 1. stops collecting, leaving the \pgfmanual@EOI as next token to be read,
574 % 2. sets \ifpgfmanualprettyprinterarghasunmatchedbraces to \iftrue if necessary,
575 % 3. assigns \pgfmanualprettyprinternumcollectedargs
576 % 4. invokes the finish routine.
577 % The \pgfmanual@EOI needs to be collected by following routines in
578 % this case. You can also use \pgfutil@ifnextchar\pgfmanual@EOI{}{} in
579 % following routines to check for \pgfmanual@EOI.
580 \def\pgfmanualprettyprintercollectargcount#1#2{%
581 \pgfmanualprettyprinterarghasunmatchedbracesfalse
582 \begingroup
583 \edef\pgfmanual@loc@csargcount{#1}%
584 \toksdef\t@afterpgfmanualprettyprinterhandlecollected=10
585 \t@afterpgfmanualprettyprinterhandlecollected={#2}%
586 \let\c@pgfmanual@pretty@openbracecount=\c@pgf@counta
587 \let\c@pgfmanual@pretty@curargcount=\c@pgf@countb
588 % I will track open braces and the number of completely
589 % collected arguments here:
590 \c@pgfmanual@pretty@openbracecount=0
591 \c@pgfmanual@pretty@curargcount=0
592 %
593 % and I will accumulate the argument token lists as such here:
594 \toksdef\t@pgfmanual@currentarg=0
595 \toksdef\t@pgfmanual@allargs=1
596 \t@pgfmanual@currentarg={}%
597 \t@pgfmanual@allargs={}%
598 %
599 \pgfmanual@pretty@collectargs@loop
600 }%
601
602 % loops through all tokens, collecting the required number of
603 % arguments. This involves to track nested braces manually.
604 % #1 is a single token.
605 \def\pgfmanual@pretty@collectargs@loop#1{%
606 \let\pgfmanual@pretty@collectargs@loop@NEXT=\pgfmanual@pretty@collectargs@loop
607 \def\pgfmanual@loc@TMPc{#1}%
608 \ifx\pgfmanual@loc@TMPc\pgfmanual@EOI
609 \ifnum\c@pgfmanual@pretty@openbracecount>0
610 \ifpgfmanualpdfwarnings
611 \pgfplots@warning{The pretty printer did not found the closing curly brace!? This will potentially lead to display errors}%
612 \fi
613 \fi
614 \edef\pgfmanual@pretty@collectargs@loop@NEXT{%
615 \noexpand\endgroup
616 \ifnum\c@pgfmanual@pretty@openbracecount>0
617 \noexpand\pgfmanualprettyprinterarghasunmatchedbracestrue
618 \fi
619 \noexpand\def\noexpand\pgfmanualprettyprinternumcollectedargs{\the\c@pgfmanual@pretty@curargcount}%
620 \noexpand\pgfmanualprettyprinterhandlecollectedargs{\the\t@pgfmanual@allargs\the\t@pgfmanual@currentarg}%
621 \the\t@afterpgfmanualprettyprinterhandlecollected
622 \noexpand\pgfmanual@EOI% <- put this token back into token list!
623 }%
624 \else
625 \ifpgfmanualprettycommentactive
626 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
627 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@activenl
628 \pgfmanualprettycommentactivefalse
629 \fi
630 \else
631 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@activepercent
632 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
633 \pgfmanualprettycommentactivetrue
634 \else
635 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@lbrace
636 \advance\c@pgfmanual@pretty@openbracecount by1
637 \ifnum\c@pgfmanual@pretty@openbracecount>1
638 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
639 \fi
640 \else
641 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@rbrace
642 \advance\c@pgfmanual@pretty@openbracecount by-1
643 \ifnum\c@pgfmanual@pretty@openbracecount=0
644 % we have one complete argument ready!
645 % append it -- with REAL braces if needed:
646 \edef\pgfmanual@loc@TMPc{\the\t@pgfmanual@allargs{\the\t@pgfmanual@currentarg}}%
647 \t@pgfmanual@allargs=\expandafter{\pgfmanual@loc@TMPc}%
648 \t@pgfmanual@currentarg={}%
649 %
650 % check it we need more arguments:
651 \advance\c@pgfmanual@pretty@curargcount by1
652 \ifnum\c@pgfmanual@pretty@curargcount=\pgfmanual@loc@csargcount\relax
653 \edef\pgfmanual@pretty@collectargs@loop@NEXT{%
654 \noexpand\endgroup
655 \noexpand\def\noexpand\pgfmanualprettyprinternumcollectedargs{\the\c@pgfmanual@pretty@curargcount}%
656 \noexpand\pgfmanualprettyprinterhandlecollectedargs{\the\t@pgfmanual@allargs}%
657 \the\t@afterpgfmanualprettyprinterhandlecollected
658 }%
659 \fi
660 \else
661 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
662 \fi
663 \else
664 \ifnum13=\catcode`#1
665 % we found a white space (space, TAB or NL) or comment
666 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
667 \else
668 \ifnum10=\catcode`#1
669 % we found a white space (space, TAB
670 % or NL) with unexpected catcode
671 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
672 \else
673 \ifnum\c@pgfmanual@pretty@openbracecount=0
674 \ifpgfmanualpdfwarnings
675 \begingroup
676 \toks4{#1}%
677 \pgfplots@warning{The pretty printer did not find the expected \pgfmanual@loc@csargcount\space arguments (only token \the\toks4 )}%
678 \endgroup
679 \fi
680 \edef\pgfmanual@pretty@collectargs@loop@NEXT{%
681 \noexpand\endgroup
682 \noexpand\def\noexpand\pgfmanualprettyprinternumcollectedargs{\the\c@pgfmanual@pretty@curargcount}%
683 \noexpand\pgfmanualprettyprinterhandlecollectedargs{\the\t@pgfmanual@allargs\the\t@pgfmanual@currentarg}%
684 \the\t@afterpgfmanualprettyprinterhandlecollected
685 \noexpand#1% <- put this token back into token list!
686 }%
687 \else
688 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
689 \fi
690 \fi
691 \fi
692 \fi
693 \fi
694 \fi
695 \fi
696 \fi
697 \pgfmanual@pretty@collectargs@loop@NEXT
698 }%
699
700 \newif\ifpgfmanualprettyprinterfoundterminator
701
702 % Collects tokens inside of a token list up to a single delimiting token, dealing with nested
703 % catcode-12-braces.
704 %
705 % #1: is the end token, the delimiter. It won't be collected.
706 % #2: is code to invoke after
707 % \pgfmanualprettyprinterhandlecollectedargs has been invoked.
708 %
709 % PRECONDITION:
710 % there is a large token list following
711 % \pgfmanualprettyprintercollectargcount with balanced braces. The braces
712 % have \catcode 12.
713 % POSTCONDITION:
714 % - the arguments will be collected as
715 % '<result> := <token list>'
716 % and then, \pgfmanualprettyprinterhandlecollectedargs{<result>} will be
717 % invoked. Just define \pgfmanualprettyprinterhandlecollectedargs
718 % properly.
719 % Then, #2 will be invoked.
720 % - The boolean \ifpgfmanualprettyprinterfoundterminator will be set to true if and only if '#1' has been found.
721 %
722 % @see \pgfmanualprettyprintercollectargcount for more details.
723 %
724 \def\pgfmanualprettyprintercollectupto#1#2{%
725 \pgfmanualprettyprinterarghasunmatchedbracesfalse
726 \pgfmanualprettyprinterfoundterminatortrue
727 \begingroup
728 \def\pgfmanual@loc@delimittoken{#1}%
729 \toksdef\t@afterpgfmanualprettyprinterhandlecollected=10
730 \t@afterpgfmanualprettyprinterhandlecollected={#2}%
731 %
732 \let\c@pgfmanual@pretty@openbracecount=\c@pgf@counta
733 % I will track open braces here:
734 \c@pgfmanual@pretty@openbracecount=0
735 %
736 % and I will accumulate the argument token lists as such here:
737 \toksdef\t@pgfmanual@currentarg=0
738 \t@pgfmanual@currentarg={}%
739 %
740 \pgfmanual@pretty@collectupto@loop
741 }%
742
743 % loops through all tokens, collecting the required number of
744 % arguments. This involves to track nested braces manually.
745 % #1 is a single token.
746 \def\pgfmanual@pretty@collectupto@loop#1{%
747 \let\pgfmanual@pretty@collectupto@loop@NEXT=\pgfmanual@pretty@collectupto@loop
748 \def\pgfmanual@loc@TMPc{#1}%
749 \ifx\pgfmanual@loc@TMPc\pgfmanual@EOI
750 \edef\pgfmanual@pretty@collectupto@loop@NEXT{%
751 \noexpand\endgroup
752 \ifnum\c@pgfmanual@pretty@openbracecount>0
753 \noexpand\pgfmanualprettyprinterarghasunmatchedbracestrue
754 \fi
755 \noexpand\pgfmanualprettyprinterfoundterminatorfalse
756 \noexpand\pgfmanualprettyprinterhandlecollectedargs{\the\t@pgfmanual@currentarg}%
757 \the\t@afterpgfmanualprettyprinterhandlecollected
758 \noexpand\pgfmanual@EOI% <- put this token back into token list!
759 }%
760 \else
761 \ifpgfmanualprettycommentactive
762 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
763 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@activenl
764 \pgfmanualprettycommentactivefalse
765 \fi
766 \else
767 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@activepercent
768 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
769 \pgfmanualprettycommentactivetrue
770 \else
771 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@lbrace
772 \advance\c@pgfmanual@pretty@openbracecount by1
773 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
774 \else
775 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@rbrace
776 \advance\c@pgfmanual@pretty@openbracecount by-1
777 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
778 \else
779 \ifx\pgfmanual@loc@TMPc\pgfmanual@loc@delimittoken
780 \ifnum\c@pgfmanual@pretty@openbracecount=0
781 % do NOT include the delimit token.
782 \edef\pgfmanual@pretty@collectupto@loop@NEXT{%
783 \noexpand\endgroup
784 \noexpand\pgfmanualprettyprinterhandlecollectedargs{\the\t@pgfmanual@currentarg}%
785 \the\t@afterpgfmanualprettyprinterhandlecollected
786 }%
787 \else
788 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
789 \fi
790 \else
791 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
792 \fi
793 \fi
794 \fi
795 \fi
796 \fi
797 \fi
798 \pgfmanual@pretty@collectupto@loop@NEXT
799 }%
800
801 \def\pgfmanual@pretty@collectargs@finish@cs#1{%
802 \def\pgfmanual@pretty@collectargs@finish@cs@hasargs{1}%
803 \ifnum\pgfmanualprettyprinternumcollectedargs=0
804 \ifpgfmanualprettyprinterarghasunmatchedbraces
805 \else
806 \def\pgfmanual@pretty@collectargs@finish@cs@hasargs{0}%
807 \fi
808 \fi
809 \if\pgfmanual@pretty@collectargs@finish@cs@hasargs1%
810 % report the macro and its arguments:
811 \pgfkeysifdefined{/codeexample/prettyprint/cs/\pgfmanual@loc@TMPa/.@cmd}{%
812 % oh, we have a separate routine for this macro! Ok, use it:
813 \edef\pgfmanual@loc@TMPb{\noexpand\pgfkeysvalueof{/codeexample/prettyprint/cs/\pgfmanual@loc@TMPa/.@cmd}}%
814 }{%
815 % use the generic routine:
816 \edef\pgfmanual@loc@TMPb{\noexpand\pgfkeysvalueof{/codeexample/prettyprint/cs with args/.@cmd}}%
817 }%
818 % re-insert the backslash:
819 \edef\pgfmanual@loc@TMPa{{\pgfmanual@pretty@backslash\pgfmanual@loc@TMPa}}%
820 \expandafter\pgfmanual@loc@TMPb\pgfmanual@loc@TMPa #1\pgfeov
821 \else
822 % Oh. We probably got |\pgfkeys| instead of |\pgfkeys{arg}|
823 % re-insert the backslash:
824 \edef\pgfmanual@loc@TMPa{{\pgfmanual@pretty@backslash\pgfmanual@loc@TMPa}}%
825 \edef\pgfmanual@loc@TMPb{\noexpand\pgfkeysvalueof{/codeexample/prettyprint/cs/.@cmd}}%
826 \expandafter\pgfmanual@loc@TMPb\pgfmanual@loc@TMPa\pgfeov
827 #1\relax% simply typeset any encountered tokens after the control sequence.
828 \fi
829 }%
830
831 % A user macro which pretty prints a set of keys.
832 %
833 % If '#1' is NOT an argument for \pgfkeys,
834 % \pgfmanualprettyprintpgfkeys will try to recognise at least control
835 % sequences (in the same way as usual). Thus, you can even use this
836 % method if there *could* be pgfkeys arguments in an automated pretty
837 % printing environment.
838 %
839 % However, '#1' should only have catcode 12 characters with the
840 % exception of catcode 13 for newlines, spaces and comments.
841 \long\def\pgfmanualprettyprintpgfkeys#1{%
842 \ifpgfmanualprettyenabled
843 \begingroup
844 \pgfmanualprettyprintstyles
845 \pgfmanual@pretty@pgfkeys@loop#1\pgfmanual@EOI
846 \endgroup
847 \else
848 #1%
849 \fi
850 }
851
852 \def\pgfmanual@pretty@pgfkeys{%
853 \let\pgfmanualprettyprinterhandlecollectedargs=\pgfmanual@pretty@pgfkeys@start
854 \pgfmanualprettyprintercollectupto]{\pgfmanual@pretty@mainloop}%%
855 }%
856 \long\def\pgfmanual@pretty@pgfkeys@start#1{%
857 [%
858 \pgfmanual@pretty@pgfkeys@loop#1\pgfmanual@EOI
859 ]%
860 }%
861 % iterates through single tokens, detecting key names and values while
862 % it goes.
863 \long\def\pgfmanual@pretty@pgfkeys@loop#1{%
864 \def\pgfmanual@loc@TMPa{#1}%
865 \ifx\pgfmanual@loc@TMPa\pgfmanual@EOI
866 \def\pgfmanual@pretty@pgfkeys@loop@NEXT{\relax}%
867 \else
868 \def\pgfmanual@pretty@pgfkeys@loop@NEXT{\pgfmanual@pretty@pgfkeys@loop}%
869 \ifpgfmanualprettycommentactive
870 #1%
871 \else
872 \ifnum13=\catcode`#1
873 % we found a white space (space, TAB or NL) or comment
874 #1%
875 \else
876 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@comma%
877 %\let\pgfmanual@pretty@pgfkeys@loop@NEXT=\pgfmanual@pretty@pgfkeys@checkforEOI
878 ,%
879 \else
880 \ifnum10=\catcode`#1
881 % another white space... I thought they'd have
882 % catcode 13. doesn't matter.
883 #1%
884 \else
885 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@lbrace
886 % braces may not occur in the first place -
887 % but there are circumstances where it is
888 % convenient to deal with them here (when
889 % processing arguments of styles)
890 % Do it.
891 #1%
892 \else
893 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@rbrace
894 #1%
895 \else
896 % found the beginning of a key!
897 % We will collect the key name into
898 % \toks0.
899 \toks0={}%
900 %
901 % Handle it:
902 % FIXME what if we found an opening brace!?
903 \def\pgfmanual@pretty@pgfkeys@loop@NEXT{\pgfmanual@pretty@pgfkeys@collectkey #1}%
904 \fi
905 \fi
906 \fi
907 \fi
908 \fi
909 \fi
910 \fi
911 \pgfmanual@pretty@pgfkeys@loop@NEXT
912 }%
913 \def\pgfmanual@pretty@pgfkeys@collectkey#1{%
914 \def\pgfmanual@loc@TMPb{#1}%
915 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@pgfkeys@collectkey}%
916 \ifx\pgfmanual@loc@TMPb\pgfmanual@EOI
917 % finish key name.
918 \edef\pgfmanual@loc@TMPb{\the\toks0 }%
919 \ifx\pgfmanual@loc@TMPb\pgfutil@empty
920 \else
921 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
922 \fi
923 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\relax}%
924 \else
925 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@eq
926 % finish key name.
927 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
928 #1%
929 % now, we do the same with the value - we collect it into
930 % \toks0.
931 \toks0={}%
932 \def\pgfmanual@pretty@pgfkeys@collectvalue@hasconsumedspaces{0}%
933 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@pgfkeys@collectvalue}%
934 \else
935 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@comma
936 % finish key name.
937 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
938 #1%
939 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@pgfkeys@loop}%
940 \else
941 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@activenl
942 % finish key name before newline. This is not
943 % necessarily as in TeX, but its simpler here
944 % because we don't need special cases for comments
945 % and we don't need to gobble following white
946 % spaces.
947 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
948 #1%
949 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@pgfkeys@loop}%
950 \else
951 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@backslash
952 % This is confusing. I simply try to invoke
953 % the control sequence code and recover as
954 % good as possible. Let's see if that's
955 % useful.
956 \edef\pgfmanual@loc@TMPb{\the\toks0 }%
957 \ifx\pgfmanual@loc@TMPb\pgfutil@empty
958 \else
959 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
960 \fi
961 %
962 % we found the start of a control sequence '\command':
963 %
964 % collect the control sequence name into
965 % \pgfmanual@loc@TMPa, but without the backslash:
966 \begingroup
967 \let\pgfmanual@loc@TMPa=\pgfutil@empty
968 \def\afterpgfmanual@pretty@cs{%
969 \endgroup
970 \pgfmanual@pretty@pgfkeys@loop
971 }%
972 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@collectcs@loop}%
973 \else
974 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@lbrace
975 % Braces in key names are allowed (if they
976 % are not the first character of a key
977 % name)
978 \def\pgfmanualprettyprinterhandlecollectedargs##1{%
979 \toks1={##1}%
980 \edef\pgfmanual@loc@TMPc{%
981 \the\toks0 \pgfmanual@pretty@lbrace \the\toks1
982 \ifpgfmanualprettyprinterarghasunmatchedbraces
983 \else
984 \pgfmanual@pretty@rbrace
985 \fi
986 }%
987 \toks0=\expandafter{\pgfmanual@loc@TMPc}%
988 }%
989 \def\pgfmanual@pretty@pgfkeys@collectkey@next{%
990 \pgfmanualprettyprintercollectargcount{1}{\pgfmanual@pretty@pgfkeys@collectkey}%
991 #1%
992 }%
993 \else
994 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@rbrace
995 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
996 #1%
997 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@pgfkeys@loop}%
998 \else
999 \toks0=\expandafter{\the\toks0 #1}%
1000 \fi
1001 \fi
1002 \fi
1003 \fi
1004 \fi
1005 \fi
1006 \fi
1007 \pgfmanual@pretty@pgfkeys@collectkey@next
1008 }%
1009 \def\pgfmanual@pretty@pgfkeys@collectvalue#1{%
1010 \def\pgfmanual@loc@TMPb{#1}%
1011 \let\pgfmanual@pretty@pgfkeys@collectvalue@next=\pgfmanual@pretty@pgfkeys@collectvalue
1012 \ifx\pgfmanual@loc@TMPb\pgfmanual@EOI
1013 % the key value is empty.
1014 %\expandafter\pgfmanual@pretty@pgfkeys@processvalue\expandafter{\the\toks0 }%
1015 \let\pgfmanual@pretty@pgfkeys@collectvalue@next=\relax
1016 \else
1017 \def\pgfmanual@pretty@isconsumed{0}%
1018 \if\pgfmanual@pretty@pgfkeys@collectvalue@hasconsumedspaces0%
1019 \ifnum13=\catcode`#1
1020 % we found a white space (space, TAB or NL)
1021 #1%
1022 \def\pgfmanual@pretty@isconsumed{1}%
1023 \else
1024 \ifnum10=\catcode`#1
1025 % another white space... I thought they'd have
1026 % catcode 13. doesn't matter.
1027 \def\pgfmanual@pretty@isconsumed{1}%
1028 #1%
1029 \fi
1030 \fi
1031 \fi
1032 \if\pgfmanual@pretty@isconsumed0%
1033 \def\pgfmanualprettyprinterhandlecollectedargs##1{\pgfmanual@pretty@pgfkeys@processvalue{##1}}% the braces will be handled separately.
1034 \def\pgfmanual@pretty@pgfkeys@collectvalue@next{%
1035 \pgfmanualprettyprintercollectupto,{\afterpgfmanual@pretty@collectargs@finish@value}#1%
1036 }%
1037 \fi
1038 \fi
1039 \pgfmanual@pretty@pgfkeys@collectvalue@next
1040 }%
1041 \def\afterpgfmanual@pretty@collectargs@finish@value{%
1042 \pgfutil@ifnextchar\pgfmanual@EOI{%
1043 \pgfmanual@pretty@pgfkeys@loop
1044 }{%
1045 \pgfmanual@pretty@pgfkeys@loop,% re-insert the gobbled comma here!
1046 }%
1047 }%
1048
1049 {\catcode`\^^M=13 \catcode`\ =13\relax\catcode`\%=13\relax\gdef\pgfmanual@pretty@restorespaces{\def%{\pgfmanual@pretty@percent}\def^^M{\pgfmanual@pretty@space}\def {\pgfmanual@pretty@space}}}
1050
1051 % #1: the key's name
1052 \def\pgfmanual@pretty@pgfkeys@processkey#1{%
1053 \begingroup
1054 \pgfmanual@pretty@restorespaces
1055 % remember this key name! It is used when we are dealing with
1056 % its value later... (if it has a value)
1057 \xdef\pgfmanual@pretty@pgfkeys@collectkey@keyname{#1}%
1058 \endgroup
1059 %
1060 % check if it is a handled key. FIXME: this could be done in a
1061 % rigorous way! This here assumes that all key handlers start with
1062 % '.' and the '.' occurs never right after a '/' otherwise:
1063 \def\pgfmanual@loc@TMPa{\pgfutil@in@{/.}}%
1064 \expandafter\pgfmanual@loc@TMPa\expandafter{\pgfmanual@pretty@pgfkeys@collectkey@keyname}%
1065 \ifpgfutil@in@
1066 % split into key name and handler name...
1067 \def\pgfmanual@pretty@splitit##1/.##2\relax{%
1068 \def\pgfmanual@loc@TMPb{{##1}{.##2}}%
1069 }%
1070 \expandafter\pgfmanual@pretty@splitit\pgfmanual@pretty@pgfkeys@collectkey@keyname\relax
1071 %
1072 % report key name AND handler:
1073 \def\pgfmanual@loc@TMPa{\pgfkeysvalueof{/codeexample/prettyprint/key name with handler/.@cmd}}%
1074 \expandafter\pgfmanual@loc@TMPa\pgfmanual@loc@TMPb\pgfeov
1075 \else
1076 % report key name ...
1077 \def\pgfmanual@loc@TMPa{\pgfkeysvalueof{/codeexample/prettyprint/key name/.@cmd}}%
1078 \expandafter\pgfmanual@loc@TMPa\pgfmanual@pretty@pgfkeys@collectkey@keyname\pgfeov
1079 \fi
1080 }
1081 \def\pgfmanual@pretty@pgfkeys@processvalue#1{%
1082 % report or process the value, depending on the keyname.
1083 % After all, it *may* be a style which needs to be pretty printed
1084 % as well.
1085 \pgfkeysifdefined{/codeexample/prettyprint/key value/\pgfmanual@pretty@pgfkeys@collectkey@keyname/.@cmd}{%
1086 % oh, we have a separate routine for this macro! Ok, use it:
1087 \edef\pgfmanual@loc@TMPb{\noexpand\pgfkeysvalueof{/codeexample/prettyprint/key value/\pgfmanual@pretty@pgfkeys@collectkey@keyname/.@cmd}}%
1088 }{%
1089 % use the generic routine:
1090 \edef\pgfmanual@loc@TMPb{\noexpand\pgfkeysvalueof{/codeexample/prettyprint/key value/.@cmd}}%
1091 }%
1092 \edef\pgfmanual@loc@TMPa{{\pgfmanual@pretty@pgfkeys@collectkey@keyname}}%
1093 \expandafter\pgfmanual@loc@TMPb\pgfmanual@loc@TMPa{#1}\pgfeov
1094 }
1095