Debian Codegraph @

texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.verb.code.tex

raw
1 %--------------------------------------------
2 %
3 % Package pgfplots
4 %
5 % Copyright 2007-2011 by Christian Feuersänger.
6 %
7 % This program is free software: you can redistribute it and/or modify
8 % it under the terms of the GNU General Public License as published by
9 % the Free Software Foundation, either version 3 of the License, or
10 % (at your option) any later version.
11 %
12 % This program is distributed in the hope that it will be useful,
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 % GNU General Public License for more details.
16 %
17 % You should have received a copy of the GNU General Public License
18 % along with this program. If not, see <http://www.gnu.org/licenses/>.
19 %
20 %--------------------------------------------
21 %
22 % This source file contains helper utilities for verbatim character
23 % processing.
24
25
26 %
27 % USAGE:
28 % \beginpgfplotsverbatim[result/.code={\message{I read #1}}]
29 % <verbatim code>
30 % \endpgfplotsverbatim
31 %
32 % The verbatim code MUST start at the line after the ']' (or after
33 % \beginpgfplotsverbatim if there is no ']')
34 \def\beginpgfplotsverbatim{\pgfutil@ifnextchar[{\beginpgfplotsverbatim@}{\beginpgfplotsverbatim@[]}}
35 \def\beginpgfplotsverbatim@[#1]{%
36 \begingroup
37 \pgfqkeys{/pgfplots/verb}{#1}%
38 \pgfplots@verbatim@prepare@collect
39 \beginpgfplotsverbatim@gobbleuntileol
40 }
41
42 \begingroup
43 \catcode`\|=0
44 \catcode`\\=12
45 |gdef|endpgfplotsverbatim{\endpgfplotsverbatim}%
46 |endgroup
47
48 \expandafter\long\expandafter\def\expandafter\pgfplots@verbatim@collect@until\expandafter#\expandafter1\endpgfplotsverbatim{%
49 \begingroup
50 \pgfplots@verbatim@newline@handler
51 \xdef\pgfplots@glob@TMPa{#1}%
52 \endgroup
53 \pgfkeysgetvalue{/pgfplots/verb/result/.@cmd}\pgfplots@loc@TMPb
54 \global\let\pgfplots@glob@TMPb=\pgfplots@loc@TMPb
55 \endgroup% restore old catcodes etc.
56 \expandafter\pgfplots@glob@TMPb\expandafter{\pgfplots@glob@TMPa}\pgfeov%
57 }%
58
59 \begingroup
60 \long\def\pgfplots@loc@TMPa{
61 }%^^M}%
62 \catcode`\^^M=13 %
63 \gdef\beginpgfplotsverbatim@gobbleuntileol^^M{\pgfplots@verbatim@collect@until}%
64 \gdef\pgfplots@verbatim@newline@toHATHATJ{\def^^M{^^J}}%
65 \xdef\pgfplots@verbatim@newline@IDENTITY{\noexpand\long\noexpand\def\noexpand^^M{\pgfplots@loc@TMPa}}%
66 \endgroup
67
68 \pgfkeys{
69 /pgfplots/verb/result/.code={%
70 \pgfplots@error{Please use \string\beginpgfplotsverbatim[result/.code=....] to configure what to do with the content of \string\beginpgfplotsverbatim...\endpgfplotsverbatim\space (or use \string\pgfplotsset{verb/.cd,result/.code=....} in your preamble)}%
71 },
72 /pgfplots/verb/newline handler/.is choice,
73 /pgfplots/verb/newline handler/to outfile/.code=
74 {\let\pgfplots@verbatim@newline@handler=\pgfplots@verbatim@newline@toHATHATJ},
75 /pgfplots/verb/newline handler/identity/.code=
76 {\let\pgfplots@verbatim@newline@handler=\pgfplots@verbatim@newline@IDENTITY},
77 /pgfplots/verb/newline handler/identity,
78 }
79
80 \def\pgfplots@verbatim@prepare@collect{%
81 \def\do##1{\catcode`##1=12 }\dospecials
82 \catcode`\^^M=13
83 \catcode`\^^J=12
84 \catcode`\^^I=12
85 }%
86
87 \def\pgfplots@verbatim@restore@catcodes{%
88 \catcode`\^^M=5
89 \catcode`\^^J=10
90 \catcode`\^^I=10
91 % this is important to get \scantokens to work: otherwise, it will
92 % eat up the ^^M chars:
93 \endlinechar=`\^^M
94 \newlinechar=\endlinechar
95 }%
96
97 \endinput