Debian Codegraph @

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