summaryrefslogtreecommitdiff
path: root/support/ppower4/mpmulti.sty
blob: d8502e21118e399a2a28a5c2d0ef5d950c765dd5 (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
%% mpmulti.sty                                     09 Sep 2002
%%------------------------------------------------------------
%% History:
%%   Initial version                               14 Apr 2000
%%   Introduced keyword parameters                 12 Jun 2000
%%   Introduced new parameters (start,format), changed the
%%     global code to take several file counting strings (eg
%%     bla-*.mps, foo-*.jpg, etc.), added compatibility with
%%     \graphicspath (Jean-Christophe Dubacq)      06 Dec 2001
%%   Generalized the format option, added the end
%%   handling and documented extended features in here
%%                                                 09 Sep 2002
%%
%% Purpose:
%%     include multiple metapost pictures and overlay them,
%%     inserting a transition effect between them
%%
%% Synopsis:
%%
%% \multiinclude[pause=transitioncommand,
%%               graphics={option for includegraphics},
%%               format=filenameformat,
%%               start=number,
%%               end=number]{basefilename}
%%
%%     Include all metapost generated graphics found in
%%     files with the basename "filename", which
%%     have a number attached or in the extension.
%%     Insert the transitioncommand between the files (defaults
%%     to \pause).
%%     Further options allow to specify additional specifications
%%     for includegraphics, can change the number to start with
%%     (default 0) or the number to end with (default 1000000).
%%     By default the filenames are as created by mpost in the format
%%     "filename.n", where "n" represents the number.
%%     The option format with the values like "mps", "png" or "jpg" this
%%     can be changed to "filename-n.format", e.g. "example-0.mps"
%%     instead of "example.0".
%%     Complaints are only written, if the first file is not found.
%%     Otherwise including will silently stop.
%%
%% Requires:
%%     pause.sty for definitions of transition commands.
%%     The keyval package for options processing.
%%
%%
\RequirePackage{pause}
\RequirePackage{keyval}
%%
%% The command should process the optional arguments.
%%
\def\multiinclude{%
  \@ifnextchar [\@mpmulti{\@mpmulti[]}}
%%
\newif\if@mpm@groptions\@mpm@groptionsfalse
%% We describe the keys and their default values
\define@key{mpm}{format}[\@mpm@defaultformat]{%
  \global\def\@mpm@format##1{##1-\the\@mpm@count.#1}}
\define@key{mpm}{start}[0]{\global\def\@mpm@start{#1}\relax}
\define@key{mpm}{end}[1000000]{\global\def\@mpm@end{#1}\relax}
\define@key{mpm}{pause}[\pause]{\global\def\@mpm@pause{#1}\relax}
\define@key{mpm}{graphics}{\@mpm@groptionstrue
  \global\def\@mpm@graphics{\string#1}}
\def\@mpm@defaultformat#1{#1.\the\@mpm@count}
\let\@mpm@format=\@mpm@defaultformat
%%
%% We need a local counter
%%
\newcount\@mpm@count
%%
%% Implement the basic functionality.
%% Try to include the first file unconditionally.
%% This will produce an error message, if no such file can be found.
%% Afterwards we are going to check for more files and stop, when we
%% do not find another file. As long as we find files, these are
%% overlapped to the previous parts.
%%
\def\@mpmulti[#1]#2{%
  %% reset the options 
  \def\@mpm@pause{\pause}%
  \global\def\@mpm@graphics{}%
  \global\def\@mpm@start{0}%
  \global\def\@mpm@end{1000000}%
  %% get the arguments
  \setkeys{mpm}{#1}%
  %% Insert the first part of the figure
  %% and make sure we look also in other places according to path.
  \let\@mpm@oldinp@th\input@path\let\input@path\Ginput@path
  \@mpm@count=\@mpm@start
  \if@mpm@groptions
  \edef\@mpm@do@include{\noexpand\includegraphics[\@mpm@graphics]{\@mpm@format{#2}}}%
  \@mpm@do@include
  \else
  \includegraphics{\@mpm@format{#2}}%
  \fi
  \def\@mpmdoit{% Do it by conditional tail recursion.
  %% Select the next filename and advance counter
  \edef\@mpmfilename{\@mpm@format{#2}}%
  %% If the file exists,
  \IfFileExists{\@mpmfilename}{%
    %% insert the user defined transition (or the default),
    \@mpm@pause
    %% then process the next part and set up to try again.
    \llap{\if@mpm@groptions
      \edef\@mpm@do@include{\noexpand
        \includegraphics[\@mpm@graphics]{\@mpmfilename}}%
      \@mpm@do@include
      \else
      \includegraphics{\@mpmfilename}%
      \fi}%
    \ifnum\@mpm@count<\@mpm@end\relax    
      \advance\@mpm@count by 1\relax
      \let\@mpmnext\@mpmdoit
    \else
      \let\@mpmnext\relax
    \fi
  }{%
    %% If no more files exist, set up to stop.
    \let\@mpmnext\relax
  }%
  %% Whatever we had to do (without nesting all the IfFileExists)
  \@mpmnext
  }%
  %% Finally we must start it once, if there is more than one file
  %% supposed to be available.
  \ifnum\@mpm@count<\@mpm@end\relax
    \advance\@mpm@count by 1\relax   % start counting
    \@mpmdoit % and run the show
  \fi
  %% and reset the input path after all
  \let\input@path\@mpm@oldinp@th
}%