-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforest-animate.sty
87 lines (84 loc) · 3.46 KB
/
forest-animate.sty
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
\ProvidesPackage{forest-animate}[2013/01/20]
\RequirePackage{forest}[2013/01/20]
\RequirePackage{animate}
%%% cumulative animation
%%% - must be done by producing all the frame-boxes in advance, since
%%% animate's \newframe command introduces a TeX group
%%% - frames are controlled "node-wise"
%%% - after changing node's properties between frames, the node
%%% usually needs to be re-typeset; this is done automatically, but
%%% (i) doesn't cover all the cases (e.g. if a propagator is used to
%%% modify some other node) and (ii) can be turned off using
%%% "animate don't autotypeset".
\forestset{
animate/.style 2 args={%
declare keylist={frames}{},
draw tree stage/.style={%
TeX={\def\nframes{0}},
for root'={if n children=0{frames=draw frame}{for last leaf={frames=draw frame}}},
process keylist=frames,
TeX={%
\def\framen{0}%
\def\animateminx{16000pt}%
\def\animateminy{16000pt}%
\def\animatemaxx{-16000pt}%
\def\animatemaxy{-16000pt}%
\loop
\ifnum\framen<\nframes\relax
\pgfmathsetlengthmacro{\animateminx}{min(\animateminx,\csname animateminx\framen\endcsname)}%
\pgfmathsetlengthmacro{\animateminy}{min(\animateminy,\csname animateminy\framen\endcsname)}%
\pgfmathsetlengthmacro{\animatemaxx}{max(\animatemaxx,\csname animatemaxx\framen\endcsname)}%
\pgfmathsetlengthmacro{\animatemaxy}{max(\animatemaxy,\csname animatemaxy\framen\endcsname)}%
\edef\framen{\number\numexpr\framen+1}%
\repeat
\begin{animateinline}[#1]{#2}
\multiframe{\nframes}{iframen=0+1}{%
\edef\animatemarshal{%
\noexpand\begin{minipage}{\the\dimexpr\animatemaxx-\animateminx\relax}%
\noexpand\vspace*{\the\dimexpr\animatemaxy-\csname animatemaxy\iframen\endcsname\relax}%
\noexpand\hspace*{\the\dimexpr\csname animateminx\iframen\endcsname-\animateminx}%
\noexpand\expandafter\box\noexpand\csname framebox\iframen\endcsname
\noexpand\vspace*{\the\dimexpr\csname animateminy\iframen\endcsname-\animateminy}%
\noexpand\end{minipage}%
}\animatemarshal
}%
\end{animateinline}
},
},
},
animate typeset node/.style={typeset node},
animate don't autotypeset/.style={animate typeset node/.style={}},
frame/.style 2 args={
frames={delay n={#1}{#2,animate typeset node}},
},
draw frame/.style={
TeX={\expandafter\locbox\csname framebox\nframes\endcsname},
draw tree box/.expanded=\csname framebox\nframes\endcsname,
tikz+={%
\csxdef{animateminx\nframes}{\the\pgf@picminx}%
\csxdef{animateminy\nframes}{\the\pgf@picminy}%
\csxdef{animatemaxx\nframes}{\the\pgf@picmaxx}%
\csxdef{animatemaxy\nframes}{\the\pgf@picmaxy}%
},
for root'=draw tree',
TeX={\edef\nframes{\number\numexpr\nframes+1}},
if have delayed={delay=draw frame}{}
},
}
%%% non-cumulative animation
%%% - easier on memory (no boxes)
%%% - controlled centrally, not node-wise (but this could be reworked)
%%% - the real question is: should this mechanism be included in the
%%% style as well? Will anybody ever need it?
\forestset{
new frame/.style={draw tree',TeX={\newframe}},
animate non-cumulative/.style n args=3{
draw tree stage/.style={%
TeX={\begin{animateinline}[#1]{#2}},%
for root'=new frame,%
#3,%
for root'=draw tree,
TeX={\end{animateinline}}%
},
},
}