summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.verb.code.tex
blob: 8590ba908d6dca644b0eb7e9d5bd179d7ddd3c2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
%--------------------------------------------
%
% Package pgfplots
%
% Copyright 2007-2011 by Christian Feuersänger.
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.
%
%--------------------------------------------
%
% This source file contains helper utilities for verbatim character
% processing.


%
% USAGE: 
% \beginpgfplotsverbatim[result/.code={\message{I read #1}}]
% <verbatim code>
% \endpgfplotsverbatim
%
% The verbatim code MUST start at the line after the ']' (or after
% \beginpgfplotsverbatim if there is no ']')
\def\beginpgfplotsverbatim{\pgfutil@ifnextchar[{\beginpgfplotsverbatim@}{\beginpgfplotsverbatim@[]}}
\def\beginpgfplotsverbatim@[#1]{%
	\begingroup
	\pgfqkeys{/pgfplots/verb}{#1}%
	\pgfplots@verbatim@prepare@collect
	\beginpgfplotsverbatim@gobbleuntileol
}

\begingroup
\catcode`\|=0
\catcode`\\=12
|gdef|endpgfplotsverbatim{\endpgfplotsverbatim}%
|endgroup

\expandafter\long\expandafter\def\expandafter\pgfplots@verbatim@collect@until\expandafter#\expandafter1\endpgfplotsverbatim{%
	\begingroup
	\pgfplots@verbatim@newline@handler
	\xdef\pgfplots@glob@TMPa{#1}%
	\endgroup
	\pgfkeysgetvalue{/pgfplots/verb/result/.@cmd}\pgfplots@loc@TMPb
	\global\let\pgfplots@glob@TMPb=\pgfplots@loc@TMPb
	\endgroup% restore old catcodes etc.
	\expandafter\pgfplots@glob@TMPb\expandafter{\pgfplots@glob@TMPa}\pgfeov%
}%

\begingroup
\long\def\pgfplots@loc@TMPa{
}%^^M}%
\catcode`\^^M=13 %
\gdef\beginpgfplotsverbatim@gobbleuntileol^^M{\pgfplots@verbatim@collect@until}%
\gdef\pgfplots@verbatim@newline@toHATHATJ{\def^^M{^^J}}%
\xdef\pgfplots@verbatim@newline@IDENTITY{\noexpand\long\noexpand\def\noexpand^^M{\pgfplots@loc@TMPa}}%
\endgroup

\pgfkeys{
	/pgfplots/verb/result/.code={%
		\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)}%
	},
	/pgfplots/verb/newline handler/.is choice,
	/pgfplots/verb/newline handler/to outfile/.code=
		{\let\pgfplots@verbatim@newline@handler=\pgfplots@verbatim@newline@toHATHATJ},
	/pgfplots/verb/newline handler/identity/.code=
		{\let\pgfplots@verbatim@newline@handler=\pgfplots@verbatim@newline@IDENTITY},
	/pgfplots/verb/newline handler/identity,
}

\def\pgfplots@verbatim@prepare@collect{%
	\def\do##1{\catcode`##1=12 }\dospecials
	\catcode`\^^M=13
	\catcode`\^^J=12
	\catcode`\^^I=12
}%

\def\pgfplots@verbatim@restore@catcodes{%
	\catcode`\^^M=5
	\catcode`\^^J=10
	\catcode`\^^I=10
	% this is important to get \scantokens to work: otherwise, it will
	% eat up the ^^M chars:
	\endlinechar=`\^^M
	\newlinechar=\endlinechar
}%

\endinput