Debian Codegraph @

texmf-dist/tex/latex/tikz-dependency/pgfmanual.pdflinks.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 file provides an interface to the
28 % pgfmanual.prettyprint.code.tex thing -- it allows to
29 % *generate pdf crossrefs inside of codeexamples automatically*
30 % without any user input.
31 %
32 % Thus, you write
33 % \begin{codeexample}[]
34 % \begin{tikzpicture}[options]
35 % \end{tikzpicture}
36 % \end{codeexample}
37 % and pdf cross references to the definitions of 'tikzpicture'
38 % and any options will be generated automatically.
39 %
40 % Furthermore, pdf cross references will be generated for everything
41 % within vertical bars, |....|.
42 %
43 %
44 %
45 %
46 %
47 % The only necessary thing is that \pgfmanualpdflabel has been called
48 % for every (fully qualified) key, control sequence, environment or
49 % whatever.
50
51 \newif\ifpgfmanualpdfwarnings
52 \pgfmanualpdfwarningstrue
53
54 \newif\ifpgfmanualshowlabels
55
56 \pgfkeys{%
57 /codeexample/prettyprint/cs arguments/pgfkeys/.initial=1,
58 /codeexample/prettyprint/cs/pgfkeys/.code 2 args={\pgfmanualpdfref{#1}{#1}\{\pgfmanualprettyprintpgfkeys{#2}\pgfmanualclosebrace},
59 %
60 /codeexample/prettyprint/autolinks/.style={%
61 /codeexample/prettyprint/key name/.code={\pgfmanualpdfref{##1}{##1}},
62 /codeexample/prettyprint/key name with handler/.code 2 args={\pgfmanualpdfref{##1}{##1}/\pgfmanualpdfref{/handlers/##2}{##2}},
63 /codeexample/prettyprint/key value display only/.code={\pgfmanualprettyprintcode{##1}},
64 /codeexample/prettyprint/cs/.code={\pgfmanualpdfref{##1}{##1}},
65 /codeexample/prettyprint/cs with args/.code 2 args={\pgfmanualpdfref{##1}{##1}\{\pgfmanualprettyprintcode{##2}\pgfmanualclosebrace},
66 /codeexample/prettyprint/cs arguments/pgfkeys/.initial=1,
67 /codeexample/prettyprint/cs/pgfkeys/.code 2 args={\pgfmanualpdfref{##1}{##1}\{\pgfmanualprettyprintpgfkeys{##2}\pgfmanualclosebrace},
68 /codeexample/prettyprint/cs arguments/begin/.initial=1,
69 /codeexample/prettyprint/cs/begin/.code 2 args={##1\{\pgfmanualpdfref{##2}{##2}\pgfmanualclosebrace},
70 /codeexample/prettyprint/cs arguments/end/.initial=1,
71 /codeexample/prettyprint/cs/end/.code 2 args={##1\{\pgfmanualpdfref{##2}{##2}\pgfmanualclosebrace},
72 /codeexample/prettyprint/word/.code={\begingroup\pgfkeyssetvalue{/pdflinks/search key prefixes in}{}\pgfmanualpdfref{##1}{##1}\endgroup},
73 /codeexample/prettyprint/point/.code={##1},%
74 /codeexample/prettyprint/point with cs/.code 2 args={(\pgfmanualpdfref{##1}{##1}:##2},%
75 },%
76 /codeexample/prettyprint/autolinks,
77 }%
78
79 \pgfkeys{
80 %
81 % Enables or disables the parsing of codeexamples.
82 /pdflinks/codeexample links/.is if=pgfmanualprettyenabled,
83 /pdflinks/codeexample links/.default=true,
84 %
85 % whenever an unqualified key is found, the following key prefix
86 % list is tried to find a match.
87 /pdflinks/search key prefixes in/.initial={/tikz/,/pgf/},
88 %
89 % Enables or disables warnings for failed auto links:
90 /pdflinks/warnings/.is if=pgfmanualpdfwarnings,
91 /pdflinks/warnings/.default=true,
92 %
93 % Shows the autogenerated labels. This is useful to check if the
94 % 'search key prefixes in' worked as it ought to.
95 /pdflinks/show labels/.is if=pgfmanualshowlabels,
96 /pdflinks/show labels/.default=true,
97 /pdflinks/show labels=false,
98 % will be invoked with '#1' set to the generated label.
99 /pdflinks/show labels code/.code={
100 \hbox to 0pt{%
101 \vbox to 0pt{\hsize=0pt
102 \vskip-\baselineskip
103 \hbox to \hsize{%
104 \hss
105 {\footnotesize\ttfamily\textcolor{red}{#1}}%
106 \hss
107 }%
108 \vss
109 }%
110 \vbox to 0pt{\hsize=0pt
111 \vss
112 \hbox to \hsize{%
113 \hss
114 {\footnotesize\ttfamily\textcolor{red}{$\vert$}}%
115 \hss
116 }%
117 }%
118 \vsize=0pt
119 }%
120 },
121 %
122 % the link prefix written to the pdf file:
123 /pdflinks/internal link prefix/.initial=pgf,
124 }
125
126 \gdef\pgfmanualpdf@installreplacements{%
127 \def\marg##1{{##1}}%
128 \def\oarg##1{[##1]}%
129 \def\meta##1{<##1>}%
130 \def\x{x}%
131 \def\textbackslash{<CS>}%
132 \def\\{\textbackslash}%
133 \def\space{:}%
134 \edef\ {\space}%
135 \edef\#{}%
136 \def\printanat{@}%
137 \def\protect{}%
138 \def\textasciicircum{o}%
139 \expandafter\edef\pgfmanual@verb@activebar{\pgfmanual@verb@bar}%
140 }%
141
142 % Defines a new pdf cross ref label for use with \pgfmanualpdfref.
143 %
144 % Usage:
145 % \pgfmanualpdflabel{<label>}{<text>}
146 % #1: the label.
147 % The text #2 will be shown in the resulting pdf (if it is not empty).
148 %
149 % There is also support for catcode changes if <label> contains
150 % something which shouldn't be written as-is into .aux files:
151 % \pgfmanualpdflabel[\catcode`\|=12 ]{|-}{}
152 % -> this will write
153 % \begingroup \catcode `\|=12
154 % <code to deal with the label |- >
155 % \endgroup
156 % into the .aux file.
157 %
158 \def\pgfmanualpdflabel{\pgfutil@ifnextchar[{\pgfmanualpdflabel@opt}{\pgfmanualpdflabel@opt[]}}%
159 \def\pgfmanualpdflabel@opt[#1]#2#3{%
160 \begingroup
161 %
162 \def\pgfmanualpdf@catcode{#1}%
163 \pgfmanualpdf@catcode
164 %
165 \pgfmanualpdflabel@generate{#2}{#3}%
166 %
167 % this is pgfplots-specific: pgfplots supports generic styles which
168 % contain '\x' where '\x' iterates through 'x,y,z'.
169 \pgfutil@in@\x{#2}%
170 \ifpgfutil@in@
171 \def\x{y}%
172 \pgfmanualpdflabel@generate{#2}{#3}%
173 \def\x{z}%
174 \pgfmanualpdflabel@generate{#2}{#3}%
175 \fi
176 \endgroup
177 }%
178 \def\pgfmanualpdflabel@generate#1#2{%
179 \pgfmanual@handlespeciallabeltokens@in{#1}%
180 %
181 \def\pgfmanualpdflabel@generateone{0}%
182 \pgfutil@ifundefined{pgfd@lbl@\pgfmanualpdflabel@@}{%
183 % ok, no such label is known.
184 \def\pgfmanualpdflabel@generateone{1}%
185 }{%
186 \if\csname pgfd@lbl@\pgfmanualpdflabel@@\endcsname a% "a"ux
187 % ah, it is "just" known from a previous run, but there is
188 % no code in the pdf! Write it!
189 \def\pgfmanualpdflabel@generateone{1}%
190 \else
191 % ok, we already wrote one before. Skip.
192 \fi
193 }%
194 \if\pgfmanualpdflabel@generateone1%
195 \ifpgfmanualshowlabels
196 \pgfkeysvalueof{/pdflinks/show labels code/.@cmd}{\pgfmanualpdflabel@@}\pgfeov
197 \fi
198 %
199 \if@filesw
200 \ifx\pgfmanualpdf@catcode\pgfutil@empty
201 \else
202 \toks0=\expandafter{\pgfmanualpdf@catcode}%
203 \immediate\write\@auxout{%
204 \noexpand\begingroup
205 \the\toks0
206 }%
207 \fi
208 \immediate\write\@auxout{%
209 \noexpand\expandafter\noexpand\gdef
210 \noexpand\csname pgfd@lbl@\pgfmanualpdflabel@@\noexpand\endcsname{a}% a = known in "a"ux file
211 }%
212 \ifx\pgfmanualpdf@catcode\pgfutil@empty
213 \else
214 \immediate\write\@auxout{\noexpand\endgroup}%
215 \fi
216 \fi
217 \expandafter\gdef\csname pgfd@lbl@\pgfmanualpdflabel@@\endcsname{w}% 1. remember the label AND remember that we "w"rote it into the pdf.
218 \edef\pgfmanualpdflabel@@{\pgfkeysvalueof{/pdflinks/internal link prefix}.\pgfmanualpdflabel@@}%
219 \expandafter\hypertarget\expandafter{\pgfmanualpdflabel@@}{#2}%
220 \else
221 #2%
222 \fi
223 }%
224
225 % A pdf reference to label `#1' with (TeX) text `#2'.
226 % @see also \verbpdfref.
227 \def\pgfmanualpdfref#1#2{%
228 \begingroup
229 \pgfmanual@handlespeciallabeltokens@in{#1}%
230 %
231 \ifcsname pgfd@lbl@\pgfmanualpdflabel@@\endcsname
232 \else
233 \global\let\pgfmanual@glob=\pgfmanualpdflabel@@
234 \def\pgfmanual@tempa{\foreach \prefix in }%
235 \pgfkeysgetvalue{/pdflinks/search key prefixes in}\pgfmanual@tempb
236 \expandafter\pgfmanual@tempa\expandafter{\pgfmanual@tempb}{%
237 \edef\pgfmanualpdflabel@@{\prefix\pgfmanualpdflabel@@}%
238 \expandafter\pgfmanual@handlespeciallabeltokens@in\expandafter{\pgfmanualpdflabel@@}%
239 \ifcsname pgfd@lbl@\pgfmanualpdflabel@@\endcsname
240 \xdef\pgfmanual@glob{\pgfmanualpdflabel@@}%
241 \breakforeach
242 \fi
243 }%
244 \let\pgfmanualpdflabel@@=\pgfmanual@glob
245 \ifcsname pgfd@lbl@\pgfmanualpdflabel@@\endcsname
246 \else
247 \ifpgfmanualpdfwarnings
248 \begingroup
249 \toks0={#1}%
250 \pgfmanual@warning{pgfmanualpdfref{\the\toks0 }: target label does not exist.}%
251 \endgroup
252 \fi
253 #2%
254 \let\pgfmanualpdflabel@@=\pgfutil@empty
255 \fi
256 \fi
257 \ifx\pgfmanualpdflabel@@\pgfutil@empty
258 \else
259 \expandafter\pgfmanualpdfref@\expandafter{\pgfmanualpdflabel@@}{#2}%
260 \fi
261 \endgroup
262 }%
263 \def\pgfmanualpdfref@#1#2{%
264 \pgfkeysgetvalue{/pdflinks/internal link prefix}\pgfmanual@temp
265 \expandafter\hyperlink\expandafter{\pgfmanual@temp.#1}{#2}%
266 \ifpgfmanualshowlabels
267 \pgfkeysvalueof{/pdflinks/show labels code/.@cmd}{#1}\pgfeov
268 \fi
269 }%
270
271 % Handles special tokens in a pdf label which should be treated with
272 % care.
273 %
274 % For example, backslashes might produce problems.
275 % This occurs quite frequently with automatically generated hyperrefs
276 % inside of codeexamples where \pgfmanualpdfref will be invoked -
277 % there, we get the catcode 12 backslashes.
278 % Check for them!
279 %
280 % #1: a token list which shall be used either as cross ref or as
281 % label.
282 %
283 % On output, the macro \pgfmanualpdflabel@@ will be '\edef'ed to the
284 % new, possibly modified value.
285 \def\pgfmanual@handlespeciallabeltokens@in#1{%
286 \begingroup
287 \pgfmanualpdf@installreplacements
288 \expandafter\pgfutil@in@\pgfmanual@pretty@backslash{#1}%
289 \ifpgfutil@in@
290 % assume the backslash is the first char and substitute it:
291 \pgfmanualpdfref@substitute@backslash#1\relax
292 \else
293 \edef\pgfmanualpdflabel@@{#1}%
294 \fi
295 \def\pgfmanual@tmp{\pgfutilstrreplace{ }{\space}}%
296 \expandafter\pgfmanual@tmp\expandafter{\pgfmanualpdflabel@@}%
297 \edef\pgfmanualpdflabel@@{\pgfretval}%
298 \pgfmath@smuggleone\pgfmanualpdflabel@@
299 \endgroup
300 }%
301
302 \expandafter\def\expandafter\pgfmanualpdfref@substitute@backslash\expandafter#\expandafter1\pgfmanual@pretty@backslash#2\relax{%
303 \edef\pgfmanualpdflabel@@{#1\textbackslash #2}%
304 }%
305
306 % Typesets '#1' in red,\texttt like every declaration. It will also
307 % generate a pdf cross ref anchor for #1.
308 %
309 % WARNING: this changes catcodes! In case this is not acceptable in
310 % your context, you will need to generate a \pgfmanualpdflabel
311 % manually.
312 %
313 % \declareandlabel{\controlsequence} can be used as |\controlsequence|
314 \def\declareandlabel{%
315 \begingroup
316 \pgfmanual@verb@preparecatcodes@
317 \def\pgfmanualprettyprinterhandlecollectedargs##1{%
318 \pgfmanualpdflabel##1{\texttt{\declare##1}}% mark: '##1' contains already braces.
319 \endgroup
320 }%
321 \pgfmanualprettyprintercollectargcount1{\relax}%
322 }
323
324 %
325 % \verbpdfref{\controlsequence more stuff}
326 % is the same as writing |\controlsequence more stuff|, but the
327 % *complete* argument is supposed to be one label.
328 %
329 % The difference to \pgfmanualpdfref{...}{} is that the argument is
330 % supposed to be verbatim text.
331 \def\verbpdfref{%
332 \begingroup
333 \pgfmanual@verb@preparecatcodes@
334 \def\pgfmanualprettyprinterhandlecollectedargs##1{%
335 \pgfmanualpdfref##1{\texttt{##1}}% mark: '##1' contains already braces.
336 \endgroup
337 }%
338 \pgfmanualprettyprintercollectargcount1{\relax}%
339 }
340
341 % Prepare active vertical bars, |....| for auto-pretty cross
342 % referencing.
343 %
344 % Example:
345 % |\pgfkeys| -> will generate a hyperref!
346 {
347 \catcode`\|=12
348 \gdef\pgfmanual@verb@bar{|}%
349 % \gdef\pgfmanual@verb@collect#1|{%
350 % % this command will also handle control sequences.
351 % \texttt{\pgfmanualprettyprintpgfkeys{#1}}%
352 % \endgroup
353 % }%
354 \catcode`\|=13
355 \gdef\pgfmanual@verb@activebar{|}%
356 }
357 \def\pgfmanual@verb{%
358 \begingroup
359 \pgfmanual@verb@preparecatcodes@
360 \toksdef\t@pgfmanual@verb=0
361 \t@pgfmanual@verb={}%
362 \pgfmanual@verb@collect
363 }
364 % this version of \pgfmanual@verb@collect is less efficient than the
365 % one uncommented above. BUT: it can auto-detect the case when
366 % |...| has been provided somewhere where I can't change catcodes!
367 % The other one would simply fail to compile.
368 \def\pgfmanual@verb@collect#1{%
369 \def\pgfmanual@temp{#1}%
370 \ifx\pgfmanual@temp\pgfmanual@verb@bar
371 % ok, finish:
372 \edef\pgfmanual@verb@collect@next{%
373 % this command will also handle control sequences.
374 \noexpand\endgroup
375 \noexpand\texttt{\noexpand\pgfmanualprettyprintpgfkeys{\the\t@pgfmanual@verb}}%
376 }%
377 \else
378 \ifx\pgfmanual@temp\pgfmanual@verb@activebar
379 % ohoh... that should not happen! It means someone invoked
380 % |...| within an argument; I couln't change catcodes.
381 % Ok, resort to a simple fallback solution.
382 % FIXME : I have just realized that THIS DOESN'T PRESERVE SPACES
383 \edef\pgfmanual@verb@collect@next{%
384 \noexpand\endgroup
385 \noexpand\texttt{\the\t@pgfmanual@verb}%
386 }%
387 \else
388 \t@pgfmanual@verb=\expandafter{\the\t@pgfmanual@verb #1}%
389 \let\pgfmanual@verb@collect@next=\pgfmanual@verb@collect
390 \fi
391 \fi
392 \pgfmanual@verb@collect@next
393 }%
394
395 \AtBeginDocument{%
396 \ifpgfmanualprettyenabled
397 \catcode`\|=13
398 \expandafter\let\pgfmanual@verb@activebar=\pgfmanual@verb
399 \fi
400 }%
401
402 \def\pgfmanual@verb@preparecatcodes@{%
403 \let\do\@makeother%
404 \dospecials%
405 \catcode`\%=12 % THATS IMPORTANT! Do *not* handle comments!
406 % these catcodes are expected by the pretty printer...
407 %\catcode`\^^M=13
408 \catcode`\ =13
409 \catcode`\^^I=13
410 \expandafter\def\pgfmanual@pretty@activespace{\space}%
411 \expandafter\def\pgfmanual@pretty@activetab{\space\space\space\space}%
412 }%
413 \endinput
414 % vi: ts=4 sw=4