summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/pgfplots/tex/pgfplotsoldpgfsupp_tikzlibraryexternal.code.tex
blob: e4ef015455fe8dcd10b9c739eca20364e8909d8c (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% This file is a copy of some part of PGF/Tikz.
%%% It has been copied here to provide :
%%%  - compatibility with older PGF versions
%%%  - availability of PGF contributions by Christian Feuersaenger
%%%    which are necessary or helpful for pgfplots.
%%%
%%% For reasons of simplicity, I have copied the whole file, including own contributions AND
%%% PGF parts. The copyrights are as they appear in PGF.
%%%
%%% Note that pgfplots has compatible licenses.
%%% 
%%% This copy has been modified in the following ways:
%%%  - nested \input commands have been updated
%%%  
%
% Support for the contents of this file will NOT be done by the PGF/TikZ team. 
% Please contact the author and/or maintainer of pgfplots (Christian Feuersaenger) if you need assistance in conjunction
% with the deployment of this patch or partial content of PGF. Note that the author and/or maintainer of pgfplots has no obligation to fix anything:
% This file comes without any warranty as the rest of pgfplots; there is no obligation for help.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Date of this copy: Do 31. Dez 19:01:21 CET 2015 %%%



% Copyright 2008 by Christian Feuersaenger
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
%
% 
% This file provides a high-level automatic export feature for tikz pictures.
% It allows to export EACH SINGLE FIGURE into a separate PDF.
%
% The simplest way is to use 
%
% \tikzexternalize{myarticle}
%
% it simply converts every figure using the write18 method. If that is not possible,
% you need to reconfigure \tikzexternalize: it can generate a list of figure file names 
% and you need to generate these figures manually (or with a script).
%
% It replaces \tikzpicture/ \endtikzpicture and \tikz and invokes \beginpgfgraphicnamed ... \endpgfgraphicnamed
% commands if necessary.

% load this package in order to get \pdf@mdfivesum .
% \pdf@mdfivesum is available for pdftex and lualatex and computes the
% md5 sum. Note that pdftex has \pdfmdfivesum, but lualatex does not
% have it.
%
% ... also used for \pdf@shellescape.
\usepackage{pdftexcmds}
\pgfutil@IfFileExists{atveryend.sty}{%
	\usepackage{atveryend}%
}{%
	\message{! Package tikz Warning: \string\usepackage{atveryend} impossible. Automatic resolving of references within external files impossible.}%
}%

% source generic implementation:
\input pgfplotsoldpgfsupp_tikzexternalshared.code.tex

\pgfutil@IfUndefined{pdf@mdfivesum}{}{%
	\let\tikzexternal@mdfivesum=\pdf@mdfivesum
}%

\def\tikzexternal@TEXDIALECT@begpicture{\begin{tikzpicture}}
\def\tikzexternal@TEXDIALECT@endpicture{\end{tikzpicture}}%

% this latex specific this assumes it starts at the beginning of an
% environment. The environment is named
% '\tikzexternal@laTeX@collect@until@end@tikzpicturetikzpicturestring'.
%
% Everything up to \end{<name>} will be collected and passed as
% argument to the macro '#1'.
%
% This does also work if <name> is NOT tikzpicture!
\def\tikzexternal@TEXDIALECT@collectpicture#1{%
	\begingroup
	\t@tikzexternal@tmpa={}%
	\tikzexternal@laTeX@collect@until@end@tikzpicture{#1}%
}

% Loop until we find '\end{tikzpicture}'.  We have to make sure that
% even strings like '#1' are allowed inside of the collected argument.
\long\def\tikzexternal@laTeX@collect@until@end@tikzpicture#1#2\end#3{%
	\def\tikzexternal@laTeX@collect@until@end@tikzpicture@{#3}%
	\ifx\tikzexternal@laTeX@collect@until@end@tikzpicture@\tikzexternal@laTeX@collect@until@end@tikzpicturetikzpicturestring
		\t@tikzexternal@tmpa=\expandafter{\the\t@tikzexternal@tmpa #2}%
		\edef\tikzexternal@TEXDIALECT@collectpicture@next{%
			\noexpand\endgroup
			\noexpand#1{\the\t@tikzexternal@tmpa}%
		}%
		\t@tikzexternal@tmpa={}% release memory.
	\else
		\t@tikzexternal@tmpa=\expandafter{\the\t@tikzexternal@tmpa #2\end{#3}}%
		\def\tikzexternal@TEXDIALECT@collectpicture@next{%
			\tikzexternal@laTeX@collect@until@end@tikzpicture{#1}}%
	\fi
	\tikzexternal@TEXDIALECT@collectpicture@next
}%
\def\tikzexternal@laTeX@collect@until@end@tikzpicturetikzpicturestring{tikzpicture}%

\def\tikzexternal@handle@landscape{%
	\ltx@ifpackageloaded{pdflscape}{%
		% Work around a bug in conjunction with pdflscape and
		% external: without this optimize-away-instruction, the
		% externalized image would be rotated - and it will be rotated
		% once more again when it is included.
		%
		% if we "optimize it away", the landscape stuff will be
		% omitted. I hope this is enough... might not be entirely
		% fool-proof; perhaps we need to set it to \relax. For now, it
		% will probably do the job
		\tikzset{
			external/.cd,
			optimize command away=\landscape,
			optimize command away=\endlandscape
		}%
	}{%
	}%
}%

\AtBeginDocument{%
	\pgfutil@ifundefined{tikzexternalrealjob}{%
		\global\let\tikzexternalrealjob=\jobname
	}{}%
	\tikzexternal@handle@landscape
}%