%% tpmultiinc.sty
%%
%% This package provides the command \tpmultiinc{foo} to include 
%% incremental graphics using Stephan Lehmke's texpower package.
%%
%% 
%% Copyright (C) 2002 Holger Wenzel
%%
%% 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 2
%% 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, write to the Free Software
%% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
%%
%% Contact Holger Wenzel               Email: Holger.Wenzel@engineous.com
%%                        
%%         Engineous Software GmbH
%%         Landsberger Str. 398
%%         81241 Munich, Germany
%%
%% Call tmpultiiinc like: \tpmultiinc[options to includegraphics]{foo}
%% 
%% It requires that you have the graphic files in a certain order.
%%  foo.0 is the first file to be included. It appears at once.
%% The graphic files
%%  foo.n with n >=1 are included step by step using the step command
%%                   from texpower.
%% The files foo.* are eps-Files, as produced by metapost. They must 
%% all have the same bounding box.
%% 
%% The most convenient way to generate them is to use xfig with the
%% patches provided by Klaus Guntermann to generate multiple metapost
%% output. See:
%% 
%% http://www-sp.iti.informatik.tu-darmstadt.de/software/xfig/
%%
%% The [options to includegraphics] are optional. You can use them to
%% scale your graphics to the proper size.
%%
%% Beware, no error handling is attempted. 
%% Beware, this is my first attempt to write something other than
%% local hacks.
%% Beware, this has only been tested via the latex, dvips, ps2pdf
%% route. I don't know how it behaves if you use pdflatex.
%%
%% Author: Holger Wenzel H.Wenzel@itm.rwth-aachen.de
%% Version: 0.1b  July 7, 2000
%%          0.1c  Nov. 11, 2002 license added 
%%
\RequirePackage{texpower}
\RequirePackage{graphicx}
\RequirePackage{ifthen}
%% 
%% The width and the height of the included graphics
\newlength{\layerwidth}
\newlength{\layerheight}
%% Boolean value to decide wether we have to include another 
%% file
\newboolean{morelayers}
%%
%% Counter for the actual layer
%%
\newcounter{layer}
%%
%%
%%
\newcommand*{\tpmultiinc}[2][{}]{%
%%
%% First (optional) argument are the options passed to
%% includegraphics. 
%% Second (requried) argument is the base-name of the files to be
%% included.
%%
%% Determine the dimensions of the picture
\settowidth{\layerwidth}{\includegraphics[#1]{#2.0}}
\settoheight{\layerheight}{\includegraphics[#1]{#2.0}}
%% initialise 
\setboolean{morelayers}{true}
\setcounter{layer}{1}
%%
%% use parstepwise instead of stepwise to avoid glitches in 
%% the output
\parstepwise{%
%%
%% Make room for the picture
\parbox[t][\layerheight][b]{\layerwidth}{%
%%
%% Be sure that the files are nicely overlaid
%% by anchoring them at (0,0) in a picture environment
\begin{picture}(0,0)
%% Include at least one file (this is foo.0)
\put(0,0) {\includegraphics[#1]{#2.0}}
%%
%% This is the loop to include all the foo.n files
%% like in the mpmulti.sty of ppower.
%%
\whiledo{\boolean{morelayers}}
{\IfFileExists{#2.\thelayer}%
  {\setboolean{morelayers}{true}%
    \step{\put(0,0) {{\includegraphics[#1]{#2.\thelayer}}}}
    \stepcounter{layer}}%
  {\setboolean{morelayers}{false}}}
\end{picture}}}%
\\}%

