Debian Codegraph @

texmf-dist/tex/latex/pgf/doc/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/2019 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 %
195 % The font / color command to use for comments. Will be set at
196 % the beginning of a comment
197 /codeexample/prettyprint/comment font/.initial=,%
198 % the same with specialised code:
199 %/codeexample/prettyprint/point with cs/<CS NAME>/.code 2 args={(#1:#2},%
200 %
201 %
202 % A predefined style which colors every identified token. It's
203 % purpose is only debugging.
204 /codeexample/prettyprint/colored/.style={%
205 /codeexample/prettyprint/key name/.code={\textcolor{red!75!black}{##1}},
206 /codeexample/prettyprint/key name with handler/.code 2 args={\textcolor{red!75!black}{##1}/\textcolor{red!90!black}{##2}},
207 /codeexample/prettyprint/key value display only/.code={\textcolor{yellow}{##1}},
208 /codeexample/prettyprint/cs/.code={\textcolor{green}{##1}},
209 /codeexample/prettyprint/cs with args/.code 2 args={\textcolor{green}{##1}\{\textcolor{orange}{##2}\pgfmanualclosebrace},
210 /codeexample/prettyprint/cs arguments/pgfkeys/.initial=1,
211 /codeexample/prettyprint/cs/pgfkeys/.code 2 args={\textcolor{green}{##1}\{\pgfmanualprettyprintpgfkeys{##2}\pgfmanualclosebrace},
212 /codeexample/prettyprint/cs arguments/begin/.initial=1,
213 /codeexample/prettyprint/cs/begin/.code 2 args={\textcolor{green}{##1}\{\textcolor{orange}{##2}\pgfmanualclosebrace},
214 /codeexample/prettyprint/cs arguments/end/.initial=1,
215 /codeexample/prettyprint/cs/end/.code 2 args={\textcolor{green}{##1}\{\textcolor{orange}{##2}\pgfmanualclosebrace},
216 /codeexample/prettyprint/word/.code={\textcolor{brown}{##1}},
217 /codeexample/prettyprint/point/.code={\textcolor{red}{##1}},%
218 /codeexample/prettyprint/point with cs/.code 2 args={(\textcolor{green}{##1}:\textcolor{red}{##2}},%
219 },%
220 % A further debugging helper.
221 /codeexample/prettyprint/colored and verbose/.style={%
222 /codeexample/prettyprint/colored,
223 /codeexample/prettyprint/key name/.code={\message{[key name=##1]}\textcolor{red!75!black}{##1}},
224 /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}},
225 /codeexample/prettyprint/key value display only/.code={\def\temp{##1}\message{[key value=\meaning\temp]}\textcolor{yellow}{##1}},
226 /codeexample/prettyprint/cs/.code={\message{[cs=##1]}\textcolor{green}{##1}},
227 /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},
228 /codeexample/prettyprint/word/.code={\message{[word=##1]}\textcolor{brown}{##1}},
229 /codeexample/prettyprint/point/.code={\message{[point=##1]}\textcolor{red}{##1}},%
230 /codeexample/prettyprint/point with cs/.code 2 args={\message{[point with cs={##1}{##2}]}(\textcolor{green}{##1}:\textcolor{red}{##2}},%
231 },%
232 %/codeexample/prettyprint/colored,
233 %/codeexample/prettyprint/colored and verbose,
234 }%
235
236 \newif\ifpgfmanualprettyenabled
237 \pgfmanualprettyenabledtrue
238
239 % User interface command to handle unmatched braces:
240 %
241 % It expands to '\}' unless the preceding argument had unmatched braces.
242 \def\pgfmanualclosebrace{%
243 \ifpgfmanualprettyprinterarghasunmatchedbraces
244 \else
245 \}%
246 \fi
247 }%
248
249
250 % Typesets '#1', possibly using some sort of pretty printer.
251 %
252 % The argument '#1' is expected to be a long token list in which
253 % 1. all characters have catcode 11 or 12 (normal letters),
254 % 2. white spaces, tabs and newlines have catcode 13 (are active).
255 %
256 % @see \pgfmanualprettyprintpgfkeys
257 \long\def\pgfmanualprettyprintcode#1{%
258 %\def\temp{#1}\message{STARTING PRETTY PRINTING for \meaning\temp}%
259 \ifpgfmanualprettyenabled
260 \begingroup
261 \pgfmanualprettyprintstyles
262 \pgfmanual@pretty@mainloop#1\pgfmanual@EOI
263 \endgroup
264 \else
265 #1%
266 \fi
267 }%
268 % DISABLE:
269 %\long\def\pgfmanualprettyprintcode#1{#1}%
270
271 \def\pgfmanualprettyprintstyles{%
272 %\tracingmacros=2 \tracingcommands=2 \message{PRETTYPRINT INIT}%
273 \def\{{\pgfmanual@pretty@lbrace}%
274 \def\}{\pgfmanual@pretty@rbrace}%
275 \pgfmanual@pretty@installcommenthandler
276 \let\pgfmanualprettyprintstyles=\relax
277 }%
278
279
280 \newif\ifpgfmanualprettycommentactive
281
282 % we can't use the \@typeset@till@return method for comments because
283 % the pretty printer needs full control over the token list.
284 %
285 % We try a replacement here.
286 %
287 % FIXME
288 % THIS INTRODUCES A NEW GROUP! Does that hurt the pretty printer??
289 %
290 \def\pgfmanual@pretty@installcommenthandler{%
291 \expandafter\def\pgfmanual@pretty@activepercent{%
292 \begingroup%
293 \pgfmanualprettycommentactivetrue
294 \expandafter\let\pgfmanual@pretty@activenl=\pgfmanual@pretty@recoveraftercomment
295 \expandafter\def\pgfmanual@pretty@activepercent{\%}%
296 \pgfkeysvalueof{/codeexample/prettyprint/comment font}%\tt
297 \%%
298 }%
299 }%
300 \def\pgfmanual@pretty@recoveraftercomment{%
301 \endgroup
302 \pgfmanual@pretty@activenl
303 }%
304
305 \def\pgfmanual@EOI{\pgfmanual@EOI}%
306
307 {
308 \catcode`\[=0
309 \catcode`\\=12
310 [gdef[pgfmanual@pretty@backslash{\}%
311 }
312 \begingroup
313 \catcode`\:=12
314 \catcode`\(=12
315 \catcode`\)=12
316 \gdef\pgfmanual@pretty@colon{:}%
317 \gdef\pgfmanual@pretty@lroundbrace{(}%
318 \gdef\pgfmanual@pretty@rroundbrace{)}%
319 \catcode`\[=1
320 \catcode`\]=2
321 \catcode`\{=12
322 \catcode`\}=12
323 \gdef\pgfmanual@pretty@lbrace[{]%
324 \gdef\pgfmanual@pretty@rbrace[}]%
325 \catcode`\{=1
326 \catcode`\}=2
327 \catcode`\[=12
328 \catcode`\]=12
329 \catcode`\,=12
330 \catcode`\ =10\relax\gdef\pgfmanual@pretty@space{ }%
331 \gdef\pgfmanual@pretty@lbracket{[}%
332 \gdef\pgfmanual@pretty@rbracket{]}%
333 \gdef\pgfmanual@pretty@comma{,}%
334 \catcode`\==12
335 \gdef\pgfmanual@pretty@eq{=}%
336 \endgroup
337 \begingroup
338 \catcode`\%=12
339 \gdef\pgfmanual@pretty@percent{%}
340 \catcode`\%=13
341 \gdef\pgfmanual@pretty@activepercent{%}
342 \catcode`\^^M=13
343 \gdef\pgfmanual@pretty@activenl{^^M}\endgroup
344 \begingroup
345 \catcode`\^^I=13\relax\gdef\pgfmanual@pretty@activetab{^^I}%
346 \catcode`\ =13\relax\gdef\pgfmanual@pretty@activespace{ }\endgroup
347
348 % loops through all tokens.
349 % #1 is a single token.
350 \def\pgfmanual@pretty@mainloop{%
351 \def\pgfmanual@pretty@mainloop@currentword{}%
352 \pgfmanual@pretty@mainloop@
353 }%
354 \long\def\pgfmanual@pretty@mainloop@#1{%
355 \def\pgfmanual@loc@TMPa{#1}%
356 \let\pgfmanual@pretty@mainloop@NEXT=\pgfmanual@pretty@mainloop@
357 \ifx\pgfmanual@loc@TMPa\pgfmanual@EOI
358 % stop iteration.
359 \pgfmanual@pretty@mainloop@finishword
360 \let\pgfmanual@pretty@mainloop@NEXT=\relax
361 \else
362 \ifpgfmanualprettycommentactive
363 #1\kern0pt%
364 \else
365 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@lbracket%
366 % we found the start of OPTIONS '[ ... ]'.
367 \pgfmanual@pretty@mainloop@finishword
368 % Attempt syntax highlighting for pgfkeys:
369 \let\pgfmanual@pretty@mainloop@NEXT=\pgfmanual@pretty@pgfkeys
370 \else
371 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@backslash
372 % we found the start of a control sequence '\command'
373 \pgfmanual@pretty@mainloop@finishword
374 %
375 % collect the control sequence name into
376 % \pgfmanual@loc@TMPa, but without the backslash:
377 \let\pgfmanual@loc@TMPa=\pgfutil@empty
378 \let\pgfmanual@pretty@mainloop@NEXT=\pgfmanual@pretty@collectcs@loop
379 \else
380 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@lroundbrace%
381 \pgfmanual@pretty@mainloop@finishword
382 \let\pgfmanual@pretty@mainloop@NEXT=\pgfmanual@pretty@collectpoint
383 \else
384 \def\pgfmanual@isspace{0}%
385 \ifnum13=\catcode`#1
386 % we found a white space (space, TAB or NL) or comment
387 \def\pgfmanual@isspace{1}%
388 \else
389 \ifnum10=\catcode`#1
390 \def\pgfmanual@isspace{1}%
391 \fi
392 \fi
393 \if\pgfmanual@isspace1%
394 \pgfkeysvalueof{/codeexample/prettyprint/if space is word delim/.@cmd}{%
395 \pgfmanual@pretty@mainloop@finishword
396 #1% ok, show it.
397 }{%
398 % collect the word.
399 \expandafter\def\expandafter\pgfmanual@pretty@mainloop@currentword\expandafter{\pgfmanual@pretty@mainloop@currentword #1}%
400 }%
401 \else
402 \pgfkeysvalueof{/codeexample/prettyprint/if is word delim/.@cmd}{#1}{%
403 \pgfmanual@pretty@mainloop@finishword
404 #1% ok, show the delimiter.
405 }{%
406 % collect the word.
407 \expandafter\def\expandafter\pgfmanual@pretty@mainloop@currentword\expandafter{\pgfmanual@pretty@mainloop@currentword #1}%
408 }\pgfeov%
409 \fi
410 \fi
411 \fi
412 \fi
413 \fi
414 \fi
415 \pgfmanual@pretty@mainloop@NEXT
416 }%
417
418 \def\pgfmanual@pretty@mainloop@finishword{%
419 \ifx\pgfmanual@pretty@mainloop@currentword\pgfutil@empty
420 \else
421 \def\pgfmanual@loc@TMPa{\pgfkeysvalueof{/codeexample/prettyprint/word/.@cmd}}%
422 \expandafter\pgfmanual@loc@TMPa\pgfmanual@pretty@mainloop@currentword\pgfeov
423 \let\pgfmanual@pretty@mainloop@currentword=\pgfutil@empty
424 \fi
425 }%
426
427 \def\pgfmanual@pretty@collectpoint{%
428 \let\pgfmanualprettyprinterhandlecollectedargsVtwo=\pgfmanual@pretty@collectargs@finish@collectpoint
429 \expandafter\pgfmanualprettyprintercollectupto\pgfmanual@pretty@rroundbrace
430 {\afterpgfmanual@pretty@collectpoint}%
431 }
432
433 {
434 \catcode`\:=12
435 \gdef\pgfmanual@pretty@collectargs@finish@collectpoint#1#2{%
436 \expandafter\pgfutil@in@\pgfmanual@pretty@colon{#1}%
437 \ifpgfutil@in@
438 \def\pgfmanual@pretty@collectpoint@getcoordsystem##1:##2\relax{%
439 \begingroup
440 \pgfmanual@pretty@restorespaces
441 % remove active spaces from ##1:
442 \xdef\pgfmanual@pretty@glob@TMPa{##1}%
443 \endgroup
444 \pgfkeysifdefined{/codeexample/prettyprint/point with cs/\pgfmanual@pretty@glob@TMPa/.@cmd}{%
445 \def\pgfmanual@loc@TMPb{\pgfkeysvalueof{/codeexample/prettyprint/point with cs/\pgfmanual@pretty@glob@TMPa/.@cmd}}%
446 }{%
447 \def\pgfmanual@loc@TMPb{\pgfkeysvalueof{/codeexample/prettyprint/point with cs/.@cmd}}%
448 }%
449 \expandafter\def\expandafter\pgfmanual@loc@TMPa\expandafter{\expandafter{\pgfmanual@pretty@glob@TMPa}{##2}}%
450 \expandafter\pgfmanual@loc@TMPb\pgfmanual@loc@TMPa\pgfeov
451 }%
452 \if1#2%
453 \pgfmanual@pretty@collectpoint@getcoordsystem#1)\relax
454 \else
455 \pgfmanual@pretty@collectpoint@getcoordsystem#1\relax
456 \fi
457 \else
458 \def\pgfmanual@loc@TMPb{\pgfkeysvalueof{/codeexample/prettyprint/point/.@cmd}}%
459 \if1#2%
460 \pgfmanual@loc@TMPb(#1)\pgfeov
461 \else
462 \pgfmanual@loc@TMPb(#1\pgfeov
463 \fi
464 \fi
465 }%
466 }
467 \def\afterpgfmanual@pretty@collectpoint{\pgfmanual@pretty@mainloop}%
468
469 % loops through all tokens, assembling the cs name as it goes.
470 % #1 is a single token.
471 \def\pgfmanual@pretty@collectcs@loop#1{%
472 \let\pgfmanual@pretty@collectcs@loop@NEXT=\pgfmanual@pretty@collectcs@loop
473 \def\pgfmanual@loc@TMPb{#1}%
474 \ifx\pgfmanual@loc@TMPb\pgfmanual@EOI
475 \def\pgfmanual@pretty@collectcs@loop@NEXT{\pgfmanual@pretty@collectcs@loop@END #1}%
476 \else
477 % a csname may only use letters. And: only letters have a
478 % positive lcccode!
479 \ifnum\lccode`#1=0
480 \ifx\pgfmanual@loc@TMPb\pgfmanual@attext%
481 % ok, we may also accept an `@':
482 \edef\pgfmanual@loc@TMPa{\pgfmanual@loc@TMPa #1}%
483 \else
484 % This here is the first non-letter.
485 \def\pgfmanual@pretty@collectcs@loop@NEXT{\pgfmanual@pretty@collectcs@loop@END #1}%
486 \fi
487 \else
488 % continue iterating and assemble the csname...
489 \edef\pgfmanual@loc@TMPa{\pgfmanual@loc@TMPa #1}%
490 \fi
491 \fi
492 \pgfmanual@pretty@collectcs@loop@NEXT
493 }%
494 \def\afterpgfmanual@pretty@cs{\pgfmanual@pretty@mainloop}%
495 \def\pgfmanual@attext{@}
496
497 \def\pgfmanual@pretty@collectcs@loop@END{%
498 \pgfkeysifdefined{/codeexample/prettyprint/cs arguments/\pgfmanual@loc@TMPa}{%
499 % oh. The collected control sequence expects arguments. That
500 % means a lot of work since there are no nestable braces in
501 % the token list! All of them have catcode 12... we need to do
502 % that manually.
503 \let\pgfmanualprettyprinterhandlecollectedargs=\pgfmanual@pretty@collectargs@finish@cs
504 \def\pgfmanual@pretty@collectcs@loop@END@next{%
505 \pgfmanualprettyprintercollectargcount
506 {\pgfkeysvalueof{/codeexample/prettyprint/cs arguments/\pgfmanual@loc@TMPa}}%
507 {\afterpgfmanual@pretty@cs}%
508 }%
509 }{%
510 % re-insert the backslash:
511 \edef\pgfmanual@loc@TMPa{\pgfmanual@pretty@backslash \pgfmanual@loc@TMPa}%
512 % ok, report the macro and continue with the main loop.
513 \def\pgfmanual@loc@TMPb{\pgfkeysvalueof{/codeexample/prettyprint/cs/.@cmd}}%
514 \expandafter\pgfmanual@loc@TMPb\pgfmanual@loc@TMPa\pgfeov
515 \let\pgfmanual@pretty@collectcs@loop@END@next=\afterpgfmanual@pretty@cs
516 }%
517 \pgfmanual@pretty@collectcs@loop@END@next
518 }%
519
520 \newif\ifpgfmanualprettyprinterarghasunmatchedbraces
521
522 % Collects arguments inside of a token list, dealing with nested
523 % catcode-12-braces.
524 %
525 % #1: is the NUMBER of arguments to collect.
526 % #2: is TeX code which shall be invoked after
527 % \pgfmanualprettyprinterhandlecollectedargs has been invoked (see
528 % below).
529 %
530 % PRECONDITION:
531 % there is a large token list following
532 % \pgfmanualprettyprintercollectargcount with balanced braces. The braces
533 % have \catcode 12.
534 % POSTCONDITION:
535 % 1. the arguments will be collected as
536 % '<result> := {<first arg>}{<second arg>}',
537 % 2.1 the macro \pgfmanualprettyprinternumcollectedargs will contain
538 % the *actual* number of *completely* collected arguments,
539 % 2.2 the if \ifpgfmanualprettyprinterarghasunmatchedbraces will be
540 % set to \c true if the last found argument had an unmatched brace,
541 % 3. then, \pgfmanualprettyprinterhandlecollectedargs{<result>} will be
542 % invoked. Just define \pgfmanualprettyprinterhandlecollectedargs
543 % properly.
544 % Afterwards, #2 will be invoked to recover from the argument
545 % collection.
546 %
547 %
548 % Example:
549 % \pgfmanualprettyprintercollectargcount{2}{\donnextstep}
550 % {_12 first argument }_12 {_12 second argument }_12 next tokens%
551 %
552 % will result in the expansion
553 % \pgfmanualprettyprinterhandlecollectedargs{{_1 first argument }_2 {_1 second argument }_2 }
554 % \donnextstep
555 % next tokens
556 %
557 %
558 %
559 % ATTENTION:
560 % \pgfmanualprettyprinterhandlecollectedargs will be invoked with a SINGLE
561 % argument. The argument as such will contain extra braces, one pair
562 % of braces for each of the #1 arguments. These braces will have
563 % catcode 1 and 2, i.e. they can *really* be used in TeX. Thus, the
564 % finish routine will be invoked with
565 % \pgfmanualprettyprinterhandlecollectedargs{{<arg>}}
566 % for one argument and with
567 % \pgfmanualprettyprinterhandlecollectedargs{{<first arg>}{<second arg>}}
568 % for two and more arguments. Note the extra set of braces for one
569 % arg.
570 % It might happen that not all arguments have been found if
571 % end-of-input occurred before. The
572 % \pgfmanualprettyprinterhandlecollectedargs routine has to check
573 % this using the macro \pgfmanualprettyprinternumcollectedargs which
574 % contains the actual number of collected args.
575 %
576 % @remark This macro checks for the end-of-input indicator, \pgfmanual@EOI. In case it encounters
577 % \pgfmanual@EOI, it
578 % 1. stops collecting, leaving the \pgfmanual@EOI as next token to be read,
579 % 2. sets \ifpgfmanualprettyprinterarghasunmatchedbraces to \iftrue if necessary,
580 % 3. assigns \pgfmanualprettyprinternumcollectedargs
581 % 4. invokes the finish routine.
582 % The \pgfmanual@EOI needs to be collected by following routines in
583 % this case. You can also use \pgfutil@ifnextchar\pgfmanual@EOI{}{} in
584 % following routines to check for \pgfmanual@EOI.
585 \def\pgfmanualprettyprintercollectargcount#1#2{%
586 \pgfmanualprettyprinterarghasunmatchedbracesfalse
587 \begingroup
588 \edef\pgfmanual@loc@csargcount{#1}%
589 \toksdef\t@afterpgfmanualprettyprinterhandlecollected=10
590 \t@afterpgfmanualprettyprinterhandlecollected={#2}%
591 \let\c@pgfmanual@pretty@openbracecount=\c@pgf@counta
592 \let\c@pgfmanual@pretty@curargcount=\c@pgf@countb
593 % I will track open braces and the number of completely
594 % collected arguments here:
595 \c@pgfmanual@pretty@openbracecount=0
596 \c@pgfmanual@pretty@curargcount=0
597 %
598 % and I will accumulate the argument token lists as such here:
599 \toksdef\t@pgfmanual@currentarg=0
600 \toksdef\t@pgfmanual@allargs=1
601 \t@pgfmanual@currentarg={}%
602 \t@pgfmanual@allargs={}%
603 %
604 \pgfmanual@pretty@collectargs@loop
605 }%
606
607 % loops through all tokens, collecting the required number of
608 % arguments. This involves to track nested braces manually.
609 % #1 is a single token.
610 \def\pgfmanual@pretty@collectargs@loop#1{%
611 \let\pgfmanual@pretty@collectargs@loop@NEXT=\pgfmanual@pretty@collectargs@loop
612 \def\pgfmanual@loc@TMPc{#1}%
613 \ifx\pgfmanual@loc@TMPc\pgfmanual@EOI
614 \ifnum\c@pgfmanual@pretty@openbracecount>0
615 \ifpgfmanualpdfwarnings
616 \pgfplots@warning{The pretty printer did not found the closing curly brace!? This will potentially lead to display errors}%
617 \fi
618 \fi
619 \edef\pgfmanual@pretty@collectargs@loop@NEXT{%
620 \noexpand\endgroup
621 \ifnum\c@pgfmanual@pretty@openbracecount>0
622 \noexpand\pgfmanualprettyprinterarghasunmatchedbracestrue
623 \fi
624 \noexpand\def\noexpand\pgfmanualprettyprinternumcollectedargs{\the\c@pgfmanual@pretty@curargcount}%
625 \noexpand\pgfmanualprettyprinterhandlecollectedargs{\the\t@pgfmanual@allargs\the\t@pgfmanual@currentarg}%
626 \the\t@afterpgfmanualprettyprinterhandlecollected
627 \noexpand\pgfmanual@EOI% <- put this token back into token list!
628 }%
629 \else
630 \ifpgfmanualprettycommentactive
631 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
632 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@activenl
633 \pgfmanualprettycommentactivefalse
634 \fi
635 \else
636 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@activepercent
637 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
638 \pgfmanualprettycommentactivetrue
639 \else
640 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@lbrace
641 \advance\c@pgfmanual@pretty@openbracecount by1
642 \ifnum\c@pgfmanual@pretty@openbracecount>1
643 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
644 \fi
645 \else
646 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@rbrace
647 \advance\c@pgfmanual@pretty@openbracecount by-1
648 \ifnum\c@pgfmanual@pretty@openbracecount=0
649 % we have one complete argument ready!
650 % append it -- with REAL braces if needed:
651 \edef\pgfmanual@loc@TMPc{\the\t@pgfmanual@allargs{\the\t@pgfmanual@currentarg}}%
652 \t@pgfmanual@allargs=\expandafter{\pgfmanual@loc@TMPc}%
653 \t@pgfmanual@currentarg={}%
654 %
655 % check it we need more arguments:
656 \advance\c@pgfmanual@pretty@curargcount by1
657 \ifnum\c@pgfmanual@pretty@curargcount=\pgfmanual@loc@csargcount\relax
658 \edef\pgfmanual@pretty@collectargs@loop@NEXT{%
659 \noexpand\endgroup
660 \noexpand\def\noexpand\pgfmanualprettyprinternumcollectedargs{\the\c@pgfmanual@pretty@curargcount}%
661 \noexpand\pgfmanualprettyprinterhandlecollectedargs{\the\t@pgfmanual@allargs}%
662 \the\t@afterpgfmanualprettyprinterhandlecollected
663 }%
664 \fi
665 \else
666 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
667 \fi
668 \else
669 \ifnum13=\catcode`#1
670 % we found a white space (space, TAB or NL) or comment
671 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
672 \else
673 \ifnum10=\catcode`#1
674 % we found a white space (space, TAB
675 % or NL) with unexpected catcode
676 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
677 \else
678 \ifnum\c@pgfmanual@pretty@openbracecount=0
679 \ifpgfmanualpdfwarnings
680 \begingroup
681 \toks4{#1}%
682 \pgfplots@warning{The pretty printer did not find the expected \pgfmanual@loc@csargcount\space arguments (only token \the\toks4 )}%
683 \endgroup
684 \fi
685 \edef\pgfmanual@pretty@collectargs@loop@NEXT{%
686 \noexpand\endgroup
687 \noexpand\def\noexpand\pgfmanualprettyprinternumcollectedargs{\the\c@pgfmanual@pretty@curargcount}%
688 \noexpand\pgfmanualprettyprinterhandlecollectedargs{\the\t@pgfmanual@allargs\the\t@pgfmanual@currentarg}%
689 \the\t@afterpgfmanualprettyprinterhandlecollected
690 \noexpand#1% <- put this token back into token list!
691 }%
692 \else
693 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
694 \fi
695 \fi
696 \fi
697 \fi
698 \fi
699 \fi
700 \fi
701 \fi
702 \pgfmanual@pretty@collectargs@loop@NEXT
703 }%
704
705 \newif\ifpgfmanualprettyprinterfoundterminator
706
707 \def\pgfmanualprettyprinterhandlecollectedargsVtwo@default#1#2{%
708 \if1#2%
709 \pgfmanualprettyprinterfoundterminatortrue
710 \else
711 \pgfmanualprettyprinterfoundterminatorfalse
712 \fi
713 \pgfmanualprettyprinterhandlecollectedargs{#1}%
714 }%
715 \def\pgfmanualprettyprintercollectupto@restore@callback{%
716 \let\pgfmanualprettyprinterhandlecollectedargsVtwo=\pgfmanualprettyprinterhandlecollectedargsVtwo@default
717 }%
718 \pgfmanualprettyprintercollectupto@restore@callback
719
720 % Collects tokens inside of a token list up to a single delimiting token, dealing with nested
721 % catcode-12-braces.
722 %
723 % #1: list of tokens, each of which is marking the end. It won't be collected.
724 % #2: is code to invoke after
725 % \pgfmanualprettyprinterhandlecollectedargsVtwo has been invoked.
726 %
727 % PRECONDITION:
728 % there is a large token list following
729 % \pgfmanualprettyprintercollectargcount with balanced braces. The braces
730 % have \catcode 12.
731 % POSTCONDITION:
732 % - the arguments will be collected as
733 % '<result> := <token list>'
734 % and then,
735 % \pgfmanualprettyprinterhandlecollectedargsVtwo{<result>}{<found terminator>? 1 : 0} will be
736 % invoked. Just define
737 % \pgfmanualprettyprinterhandlecollectedargsVtwo
738 % properly.
739 % Then, #2 will be invoked.
740 %
741 % @see \pgfmanualprettyprintercollectargcount for more details.
742 %
743 \def\pgfmanualprettyprintercollectupto#1#2{%
744 \pgfmanualprettyprinterarghasunmatchedbracesfalse
745 \def\pgfmanualprettyprinterterminator{}%
746 \begingroup
747 \def\pgfmanual@loc@delimittokens{#1}%
748 \toksdef\t@afterpgfmanualprettyprinterhandlecollected=10
749 \t@afterpgfmanualprettyprinterhandlecollected={#2}%
750 %
751 \let\c@pgfmanual@pretty@openbracecount=\c@pgf@counta
752 % I will track open braces here:
753 \c@pgfmanual@pretty@openbracecount=0
754 %
755 % and I will accumulate the argument token lists as such here:
756 \toksdef\t@pgfmanual@currentarg=0
757 \t@pgfmanual@currentarg={}%
758 %
759 \pgfmanual@pretty@collectupto@loop
760 }%
761
762 % Stores the token that marks the end in the first argument of
763 % \pgfmanualprettyprintercollectupto. For example if the token list was {,]}
764 % and ] was encountered first, then \pgfmanualprettyprinterterminator will
765 % be ].
766 \def\pgfmanualprettyprinterterminator{}
767
768 % loops through all tokens, collecting the required number of
769 % arguments. This involves to track nested braces manually.
770 % #1 is a single token.
771 \def\pgfmanual@pretty@collectupto@loop#1{%
772 \let\pgfmanual@pretty@collectupto@loop@NEXT=\pgfmanual@pretty@collectupto@loop
773 \def\pgfmanual@loc@TMPc{#1}%
774 \ifx\pgfmanual@loc@TMPc\pgfmanual@EOI
775 \edef\pgfmanual@pretty@collectupto@loop@NEXT{%
776 \noexpand\endgroup
777 \ifnum\c@pgfmanual@pretty@openbracecount>0
778 \noexpand\pgfmanualprettyprinterarghasunmatchedbracestrue
779 \fi
780 \noexpand\pgfmanualprettyprinterhandlecollectedargsVtwo{\the\t@pgfmanual@currentarg}{0}%
781 \noexpand\pgfmanualprettyprintercollectupto@restore@callback
782 \the\t@afterpgfmanualprettyprinterhandlecollected
783 \noexpand\pgfmanual@EOI% <- put this token back into token list!
784 }%
785 \else
786 \ifpgfmanualprettycommentactive
787 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
788 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@activenl
789 \pgfmanualprettycommentactivefalse
790 \fi
791 \else
792 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@activepercent
793 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
794 \pgfmanualprettycommentactivetrue
795 \else
796 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@lbrace
797 \advance\c@pgfmanual@pretty@openbracecount by1
798 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
799 \else
800 \ifx\pgfmanual@loc@TMPc\pgfmanual@pretty@rbrace
801 \advance\c@pgfmanual@pretty@openbracecount by-1
802 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
803 \else
804 \expandafter\expandafter\expandafter\pgfutil@in@\expandafter\pgfmanual@loc@TMPc\expandafter{\pgfmanual@loc@delimittokens}%
805 \ifpgfutil@in@
806 \ifnum\c@pgfmanual@pretty@openbracecount=0
807 % do NOT include the delimit token.
808 \edef\pgfmanual@pretty@collectupto@loop@NEXT{%
809 \noexpand\endgroup
810 \noexpand\def\noexpand\pgfmanualprettyprinterterminator{\pgfmanual@loc@TMPc}%
811 \noexpand\pgfmanualprettyprinterhandlecollectedargsVtwo{\the\t@pgfmanual@currentarg}{1}%
812 \noexpand\pgfmanualprettyprintercollectupto@restore@callback
813 \the\t@afterpgfmanualprettyprinterhandlecollected
814 }%
815 \else
816 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
817 \fi
818 \else
819 \t@pgfmanual@currentarg=\expandafter{\the\t@pgfmanual@currentarg#1}%
820 \fi
821 \fi
822 \fi
823 \fi
824 \fi
825 \fi
826 \pgfmanual@pretty@collectupto@loop@NEXT
827 }%
828
829 \def\pgfmanual@pretty@collectargs@finish@cs#1{%
830 \def\pgfmanual@pretty@collectargs@finish@cs@hasargs{1}%
831 \ifnum\pgfmanualprettyprinternumcollectedargs=0
832 \ifpgfmanualprettyprinterarghasunmatchedbraces
833 \else
834 \def\pgfmanual@pretty@collectargs@finish@cs@hasargs{0}%
835 \fi
836 \fi
837 \if\pgfmanual@pretty@collectargs@finish@cs@hasargs1%
838 % report the macro and its arguments:
839 \pgfkeysifdefined{/codeexample/prettyprint/cs/\pgfmanual@loc@TMPa/.@cmd}{%
840 % oh, we have a separate routine for this macro! Ok, use it:
841 \edef\pgfmanual@loc@TMPb{\noexpand\pgfkeysvalueof{/codeexample/prettyprint/cs/\pgfmanual@loc@TMPa/.@cmd}}%
842 }{%
843 % use the generic routine:
844 \edef\pgfmanual@loc@TMPb{\noexpand\pgfkeysvalueof{/codeexample/prettyprint/cs with args/.@cmd}}%
845 }%
846 % re-insert the backslash:
847 \edef\pgfmanual@loc@TMPa{{\pgfmanual@pretty@backslash\pgfmanual@loc@TMPa}}%
848 \expandafter\pgfmanual@loc@TMPb\pgfmanual@loc@TMPa #1\pgfeov
849 \else
850 % Oh. We probably got |\pgfkeys| instead of |\pgfkeys{arg}|
851 % re-insert the backslash:
852 \edef\pgfmanual@loc@TMPa{{\pgfmanual@pretty@backslash\pgfmanual@loc@TMPa}}%
853 \edef\pgfmanual@loc@TMPb{\noexpand\pgfkeysvalueof{/codeexample/prettyprint/cs/.@cmd}}%
854 \expandafter\pgfmanual@loc@TMPb\pgfmanual@loc@TMPa\pgfeov
855 #1\relax% simply typeset any encountered tokens after the control sequence.
856 \fi
857 }%
858
859 % A user macro which pretty prints a set of keys.
860 %
861 % If '#1' is NOT an argument for \pgfkeys,
862 % \pgfmanualprettyprintpgfkeys will try to recognise at least control
863 % sequences (in the same way as usual). Thus, you can even use this
864 % method if there *could* be pgfkeys arguments in an automated pretty
865 % printing environment.
866 %
867 % However, '#1' should only have catcode 12 characters with the
868 % exception of catcode 13 for newlines, spaces and comments.
869 \long\def\pgfmanualprettyprintpgfkeys#1{%
870 \ifpgfmanualprettyenabled
871 \begingroup
872 \pgfmanualprettyprintstyles
873 \pgfmanual@pretty@pgfkeys@loop#1\pgfmanual@EOI
874 \endgroup
875 \else
876 #1%
877 \fi
878 }
879
880 \def\pgfmanual@pretty@pgfkeys{%
881 \let\pgfmanualprettyprinterhandlecollectedargsVtwo=\pgfmanual@pretty@pgfkeys@start
882 \pgfmanualprettyprintercollectupto]{\pgfmanual@pretty@mainloop}%%
883 }%
884 \long\def\pgfmanual@pretty@pgfkeys@start#1#2{%
885 [%
886 \pgfmanual@pretty@pgfkeys@loop#1\pgfmanual@EOI
887 \if1#2%
888 ]%
889 \fi
890 }%
891 % iterates through single tokens, detecting key names and values while
892 % it goes.
893 \long\def\pgfmanual@pretty@pgfkeys@loop#1{%
894 \def\pgfmanual@loc@TMPa{#1}%
895 \ifx\pgfmanual@loc@TMPa\pgfmanual@EOI
896 \def\pgfmanual@pretty@pgfkeys@loop@NEXT{\relax}%
897 \else
898 \def\pgfmanual@pretty@pgfkeys@loop@NEXT{\pgfmanual@pretty@pgfkeys@loop}%
899 \ifpgfmanualprettycommentactive
900 #1\kern0pt%
901 \else
902 \ifnum13=\catcode`#1
903 % we found a white space (space, TAB or NL) or comment
904 #1%
905 \else
906 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@comma%
907 %\let\pgfmanual@pretty@pgfkeys@loop@NEXT=\pgfmanual@pretty@pgfkeys@checkforEOI
908 ,%
909 \else
910 \ifnum10=\catcode`#1
911 % another white space... I thought they'd have
912 % catcode 13. doesn't matter.
913 #1%
914 \else
915 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@lbrace
916 % braces may not occur in the first place -
917 % but there are circumstances where it is
918 % convenient to deal with them here (when
919 % processing arguments of styles)
920 % Do it.
921 #1%
922 \else
923 \ifx\pgfmanual@loc@TMPa\pgfmanual@pretty@rbrace
924 #1%
925 \else
926 % found the beginning of a key!
927 % We will collect the key name into
928 % \toks0.
929 \toks0={}%
930 %
931 % Handle it:
932 % FIXME what if we found an opening brace!?
933 \def\pgfmanual@pretty@pgfkeys@loop@NEXT{\pgfmanual@pretty@pgfkeys@collectkey #1}%
934 \fi
935 \fi
936 \fi
937 \fi
938 \fi
939 \fi
940 \fi
941 \pgfmanual@pretty@pgfkeys@loop@NEXT
942 }%
943 \def\pgfmanual@pretty@pgfkeys@collectkey#1{%
944 \def\pgfmanual@loc@TMPb{#1}%
945 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@pgfkeys@collectkey}%
946 \ifx\pgfmanual@loc@TMPb\pgfmanual@EOI
947 % finish key name.
948 \edef\pgfmanual@loc@TMPb{\the\toks0 }%
949 \ifx\pgfmanual@loc@TMPb\pgfutil@empty
950 \else
951 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
952 \fi
953 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\relax}%
954 \else
955 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@eq
956 % finish key name.
957 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
958 #1%
959 % now, we do the same with the value - we collect it into
960 % \toks0.
961 \toks0={}%
962 \def\pgfmanual@pretty@pgfkeys@collectvalue@hasconsumedspaces{0}%
963 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@pgfkeys@collectvalue}%
964 \else
965 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@comma
966 % finish key name.
967 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
968 #1%
969 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@pgfkeys@loop}%
970 \else
971 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@activenl
972 % finish key name before newline. This is not
973 % necessarily as in TeX, but its simpler here
974 % because we don't need special cases for comments
975 % and we don't need to gobble following white
976 % spaces.
977 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
978 #1%
979 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@pgfkeys@loop}%
980 \else
981 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@backslash
982 % This is confusing. I simply try to invoke
983 % the control sequence code and recover as
984 % good as possible. Let's see if that's
985 % useful.
986 \edef\pgfmanual@loc@TMPb{\the\toks0 }%
987 \ifx\pgfmanual@loc@TMPb\pgfutil@empty
988 \else
989 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
990 \fi
991 %
992 % we found the start of a control sequence '\command':
993 %
994 % collect the control sequence name into
995 % \pgfmanual@loc@TMPa, but without the backslash:
996 \begingroup
997 \let\pgfmanual@loc@TMPa=\pgfutil@empty
998 \def\afterpgfmanual@pretty@cs{%
999 \endgroup
1000 \pgfmanual@pretty@pgfkeys@loop
1001 }%
1002 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@collectcs@loop}%
1003 \else
1004 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@lbrace
1005 % Braces in key names are allowed (if they
1006 % are not the first character of a key
1007 % name)
1008 \def\pgfmanualprettyprinterhandlecollectedargs##1{%
1009 \toks1={##1}%
1010 \edef\pgfmanual@loc@TMPc{%
1011 \the\toks0 \pgfmanual@pretty@lbrace \the\toks1
1012 \ifpgfmanualprettyprinterarghasunmatchedbraces
1013 \else
1014 \pgfmanual@pretty@rbrace
1015 \fi
1016 }%
1017 \toks0=\expandafter{\pgfmanual@loc@TMPc}%
1018 }%
1019 \def\pgfmanual@pretty@pgfkeys@collectkey@next{%
1020 \pgfmanualprettyprintercollectargcount{1}{\pgfmanual@pretty@pgfkeys@collectkey}%
1021 #1%
1022 }%
1023 \else
1024 \ifx\pgfmanual@loc@TMPb\pgfmanual@pretty@rbrace
1025 \expandafter\pgfmanual@pretty@pgfkeys@processkey\expandafter{\the\toks0 }%
1026 #1%
1027 \def\pgfmanual@pretty@pgfkeys@collectkey@next{\pgfmanual@pretty@pgfkeys@loop}%
1028 \else
1029 \toks0=\expandafter{\the\toks0 #1}%
1030 \fi
1031 \fi
1032 \fi
1033 \fi
1034 \fi
1035 \fi
1036 \fi
1037 \pgfmanual@pretty@pgfkeys@collectkey@next
1038 }%
1039 \def\pgfmanual@pretty@pgfkeys@collectvalue#1{%
1040 \def\pgfmanual@loc@TMPb{#1}%
1041 \let\pgfmanual@pretty@pgfkeys@collectvalue@next=\pgfmanual@pretty@pgfkeys@collectvalue
1042 \ifx\pgfmanual@loc@TMPb\pgfmanual@EOI
1043 % the key value is empty.
1044 %\expandafter\pgfmanual@pretty@pgfkeys@processvalue\expandafter{\the\toks0 }%
1045 \let\pgfmanual@pretty@pgfkeys@collectvalue@next=\relax
1046 \else
1047 \def\pgfmanual@pretty@isconsumed{0}%
1048 \if\pgfmanual@pretty@pgfkeys@collectvalue@hasconsumedspaces0%
1049 \ifnum13=\catcode`#1
1050 % we found a white space (space, TAB or NL)
1051 #1%
1052 \def\pgfmanual@pretty@isconsumed{1}%
1053 \else
1054 \ifnum10=\catcode`#1
1055 % another white space... I thought they'd have
1056 % catcode 13. doesn't matter.
1057 \def\pgfmanual@pretty@isconsumed{1}%
1058 #1%
1059 \fi
1060 \fi
1061 \fi
1062 \if\pgfmanual@pretty@isconsumed0%
1063 \def\pgfmanualprettyprinterhandlecollectedargsVtwo##1##2{\pgfmanual@pretty@pgfkeys@processvalue{##1}}% the braces will be handled separately.
1064 \def\pgfmanual@pretty@pgfkeys@collectvalue@next{%
1065 \pgfmanualprettyprintercollectupto{,]}{\afterpgfmanual@pretty@collectargs@finish@value}#1%
1066 }%
1067 \fi
1068 \fi
1069 \pgfmanual@pretty@pgfkeys@collectvalue@next
1070 }%
1071 \def\afterpgfmanual@pretty@collectargs@finish@value{%
1072 \expandafter\pgfmanual@pretty@pgfkeys@loop\pgfmanualprettyprinterterminator% re-insert the gobbled comma here!
1073 }%
1074
1075 {\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}}}
1076
1077 % #1: the key's name
1078 \def\pgfmanual@pretty@pgfkeys@processkey#1{%
1079 \begingroup
1080 \pgfmanual@pretty@restorespaces
1081 % remember this key name! It is used when we are dealing with
1082 % its value later... (if it has a value)
1083 \xdef\pgfmanual@pretty@pgfkeys@collectkey@keyname{#1}%
1084 \endgroup
1085 %
1086 % check if it is a handled key. FIXME: this could be done in a
1087 % rigorous way! This here assumes that all key handlers start with
1088 % '.' and the '.' occurs never right after a '/' otherwise:
1089 \def\pgfmanual@loc@TMPa{\pgfutil@in@{/.}}%
1090 \expandafter\pgfmanual@loc@TMPa\expandafter{\pgfmanual@pretty@pgfkeys@collectkey@keyname}%
1091 \ifpgfutil@in@
1092 % split into key name and handler name...
1093 \def\pgfmanual@pretty@splitit##1/.##2\relax{%
1094 \def\pgfmanual@loc@TMPb{{##1}{.##2}}%
1095 }%
1096 \expandafter\pgfmanual@pretty@splitit\pgfmanual@pretty@pgfkeys@collectkey@keyname\relax
1097 %
1098 % report key name AND handler:
1099 \def\pgfmanual@loc@TMPa{\pgfkeysvalueof{/codeexample/prettyprint/key name with handler/.@cmd}}%
1100 \expandafter\pgfmanual@loc@TMPa\pgfmanual@loc@TMPb\pgfeov
1101 \else
1102 % report key name ...
1103 \def\pgfmanual@loc@TMPa{\pgfkeysvalueof{/codeexample/prettyprint/key name/.@cmd}}%
1104 \expandafter\pgfmanual@loc@TMPa\pgfmanual@pretty@pgfkeys@collectkey@keyname\pgfeov
1105 \fi
1106 }
1107 \def\pgfmanual@pretty@pgfkeys@processvalue#1{%
1108 % report or process the value, depending on the keyname.
1109 % After all, it *may* be a style which needs to be pretty printed
1110 % as well.
1111 \pgfkeysifdefined{/codeexample/prettyprint/key value/\pgfmanual@pretty@pgfkeys@collectkey@keyname/.@cmd}{%
1112 % oh, we have a separate routine for this macro! Ok, use it:
1113 \edef\pgfmanual@loc@TMPb{\noexpand\pgfkeysvalueof{/codeexample/prettyprint/key value/\pgfmanual@pretty@pgfkeys@collectkey@keyname/.@cmd}}%
1114 }{%
1115 % use the generic routine:
1116 \edef\pgfmanual@loc@TMPb{\noexpand\pgfkeysvalueof{/codeexample/prettyprint/key value/.@cmd}}%
1117 }%
1118 \edef\pgfmanual@loc@TMPa{{\pgfmanual@pretty@pgfkeys@collectkey@keyname}}%
1119 \expandafter\pgfmanual@loc@TMPb\pgfmanual@loc@TMPa{#1}\pgfeov
1120 }