%%
%% This is file `tplists.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tplists.dtx  (with options: `tplists')
%% 
%% --------------------------------------------------------------
%% TeXPower bundle - dynamic online presentations with LaTeX
%% Copyright (C) 1999-2004 Stephan Lehmke
%% Copyright (C) 2003-2005 Hans Fredrik Nordhaug
%% 
%% 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.
%% --------------------------------------------------------------
%% 
%% The list of all files belonging to the TeXPower bundle is
%% given in the file `00readme.txt'.
%% 
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{tplists}
  [2005/04/07 v0.2 Easy Dynamic Lists using TeXPower]
\RequirePackage{texpower}
\newboolean{tpl@paralist}
\@ifpackageloaded{paralist}{\setboolean{tpl@paralist}{true}}{}
\newboolean{tpl@eqlist}
\@ifpackageloaded{eqlist}{\setboolean{tpl@eqlist}{true}}{}
\newboolean{tpl@pausestep}
\DeclareOption{pausestep}{\setboolean{tpl@pausestep}{true}}
\newboolean{tpl@noflipendstep}
\DeclareOption{noflipendstep}{\setboolean{tpl@noflipendstep}{true}}

\ProcessOptions
\define@key{tpl}{pausestep}[true]{%
  \setboolean{tpl@pausestep}{#1}
}
\define@key{tpl}{noflipendstep}[true]{%
  \setboolean{tpl@noflipendstep}{#1}
}
\newcommand*{\tplsetup}{\setkeys{tpl}}
\newif\iftpl@instepenv \tpl@instepenvfalse
\newif\iftpl@inpausestepenv \tpl@inpausestepenvfalse
\newif\iftpl@indimenv  \tpl@indimenvfalse
\newif\iftpl@inflipenv \tpl@inflipenvfalse
\let\oldenumerate=\enumerate
\let\olditemize=\itemize
\let\olddescription=\description
\let\endoldenumerate=\endenumerate
\let\endolditemize=\enditemize
\let\endolddescription=\enddescription
\ifthenelse{\boolean{tpl@eqlist}}{%
\let\oldeqlist=\eqlist
\let\endoldeqlist=\endeqlist
}{}
\ifthenelse{\boolean{tpl@paralist}}{%
\let\oldcompactenum=\compactenum
\let\oldcompactitem=\compactitem
\let\endoldcompactenum=\endcompactenum
\let\endoldcompactitem=\endcompactitem
}{}
\let\tpl@nx\noexpand
\let\tpl@xp\expandafter
\newtoks\tpl@emptytoks
\newtoks\tpl@envbody
\long\def\tpl@addto@envbody#1{\global\tpl@envbody\tpl@xp{\the\tpl@envbody#1}}
\def\tpl@collect@body#1{%
  \tpl@envbody{\tpl@xp#1\tpl@xp{\the\tpl@envbody}}%
  \edef\tpl@process@envbody{\the\tpl@envbody\tpl@nx\end{\@currenvir}}%
  \tpl@envbody\tpl@emptytoks \def\begin@stack{b}%
  \begingroup
  \tpl@xp\let\csname\@currenvir\endcsname\tpl@collect@@body
  \edef\tpl@process@envbody{\tpl@xp\tpl@nx\csname\@currenvir\endcsname}%
  \tpl@process@envbody
}
\long\def\tpl@push@begins#1\begin#2{%
  \ifx\end#2\else b\tpl@xp\tpl@push@begins\fi
}
\long\def\tpl@collect@@body#1\end#2{%
  \edef\begin@stack{\tpl@push@begins#1\begin\end \tpl@xp\@gobble\begin@stack}%
  \ifx\@empty\begin@stack
    \endgroup
    \@checkend{#2}%
    \tpl@addto@envbody{#1}%
  \else
    \tpl@addto@envbody{#1\end{#2}}%
  \fi
  \tpl@process@envbody
}
\def\tpl@addmargin#1{%
  \advance\@listdepth 1
  \addtolength{\csname leftmargin\romannumeral\@listdepth\endcsname}{#1}
  \advance\@listdepth -1
}

\ifthenelse{\boolean{display}}{%
\ifthenelse{\boolean{TPcolor}}% Can we use colors?
{% Yes. In this case highlighting is implemented by switching color.
  \def\tpl@flipstep{%
    \step{\ifthenelse{\boolean{firstactivation}}%
      {\color{textcolor}}%
      {\color{inactivecolor}}%
    }%
  }%
}
{% No. In this case highlighting is implemented by putting the item in boldface.
  \def\tpl@flipstep{%
    \step{\ifthenelse{\boolean{firstactivation}}{\bfseries}{\mdseries}}
  }%
}
\ifthenelse{\boolean{TPcolor}}% Can we use colors?
{% Yes. In this case highlighting is implemented by using \dstep
  \def\tpl@dimstep{\dstep}%
}
{% No. In this case highlighting is implemented by putting the item in boldface.
  \def\tpl@dimstep{%
    \step{\bfseries}%
    \ifthenelse{\boolean{active}}{}{\mdseries}%
  }%
}
\ifthenelse{\boolean{TPcolor}}% Can we use colors?
{% Yes. In this case stepping is implemented by using \vstep
  \def\tpl@step{\vstep}%
}
{% No. In this case stepping is implemented using \pause
  \def\tpl@step{\pause}%
}
}{% \boolean{display} is false
\def\tpl@flipstep{\relax}%
\def\tpl@dimstep{\relax}%
\def\tpl@step{\relax}%
}
\newenvironment{flipitem}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@flipitem}%
 {\global\@ignoretrue}
\newenvironment{flipdesc}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@flipdesc}%
 {\global\@ignoretrue}
\newenvironment{flipenum}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@flipenum}%
 {\global\@ignoretrue}
\ifthenelse{\boolean{tpl@eqlist}}{%
\newenvironment{flipeqlist}[1][0cm]{%
  \tpl@collect@body\@flipeqlist}%
 {\global\@ignoretrue}
\newenvironment{flipcompacteqlist}[1][0cm]{%
  \tpl@collect@body\@flipcompacteqlist}%
 {\global\@ignoretrue}
}{}
\ifthenelse{\boolean{tpl@paralist}}{%
\newenvironment{flipcompactitem}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@flipcompactitem}%
 {\global\@ignoretrue}
\newenvironment{flipcompactenum}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@flipcompactenum}%
 {\global\@ignoretrue}
}{}

\newcommand\@fliplist[2]{%
  \iftpl@indimenv
    \PackageError{tplists}{%
      dim* and flip* environments do NOT nest}{%
      Do not continue! Type 'q' to stop and fix the nested list.
    }
  \else\iftpl@instepenv
    \begin{#1}
    \let\hidestepcontents=\displaystepcontents
    \renewcommand{\item}{\tpl@flipstep\tpl@origitem}%
    #2
    \end{#1}%
  \else
    \iftpl@inpausestepenv\let\liststepwise=\stepwise\fi
    \liststepwise[\let\hidestepcontents=\displaystepcontents]{%
      \begin{#1}
      \iftpl@inpausestepenv\else
        \iftpl@instepenv\else\let\tpl@origitem=\item\fi
      \fi
      \tpl@instepenvtrue
      \tpl@inflipenvtrue
      \renewcommand{\item}{\tpl@flipstep\tpl@origitem}%
      #2
      \ifthenelse{\boolean{tpl@noflipendstep}}{}{\step{}}%
      \end{#1}}
  \fi\fi
}

\newcommand\@flipitem[1]{%
 \@fliplist{olditemize}{#1}}
\newcommand\@flipdesc[1]{%
 \@fliplist{olddescription}{#1}}
\newcommand\@flipenum[1]{%
 \@fliplist{oldenumerate}{#1}}
\ifthenelse{\boolean{tpl@eqlist}}{%
\newcommand\@flipeqlist[1]{%
 \@fliplist{oldeqlist}{#1}}
\newcommand\@flipcompacteqlist[1]{%
 \@fliplist{compacteqlist}{#1}}
}{}
\ifthenelse{\boolean{tpl@paralist}}{%
\newcommand\@flipcompactitem[1]{%
 \@fliplist{oldcompactitem}{#1}}
\newcommand\@flipcompactenum[1]{%
 \@fliplist{oldcompactenum}{#1}}
}{}
\newenvironment{dimitem}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@dimitem}%
 {\global\@ignoretrue}
\newenvironment{dimdesc}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@dimdesc}%
 {\global\@ignoretrue}
\newenvironment{dimenum}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@dimenum}%
 {\global\@ignoretrue}
\ifthenelse{\boolean{tpl@eqlist}}{%
\newenvironment{dimeqlist}[1][0cm]{%
  \tpl@collect@body\@dimeqlist}%
 {\global\@ignoretrue}
\newenvironment{dimcompacteqlist}[1][0cm]{%
  \tpl@collect@body\@dimcompacteqlist}%
 {\global\@ignoretrue}
}{}
\ifthenelse{\boolean{tpl@paralist}}{%
\newenvironment{dimcompactitem}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@dimcompactitem}%
 {\global\@ignoretrue}
\newenvironment{dimcompactenum}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@dimcompactenum}%
 {\global\@ignoretrue}
}{}

\newcommand\@dimlist[2]{%
  \iftpl@inflipenv
    \PackageError{tplists}{%
      dim* and flip* environments do NOT nest}{%
      Do not continue! Type <q> to stop and fix the nested list.
    }
  \else\iftpl@instepenv
    \begin{#1}
    \renewcommand{\item}{\tpl@dimstep\tpl@origitem}%
    #2
    \end{#1}%
  \else
    \iftpl@inpausestepenv\let\liststepwise=\stepwise\fi
    \liststepwise{%
      \begin{#1}
      \iftpl@inpausestepenv\else
        \iftpl@instepenv\else\let\tpl@origitem=\item\fi
      \fi
      \tpl@instepenvtrue
      \tpl@indimenvtrue
      \renewcommand{\item}{\tpl@dimstep\tpl@origitem}%
      #2
      \end{#1}}
  \fi\fi
}

\newcommand\@dimitem[1]{%
 \@dimlist{olditemize}{#1}}
\newcommand\@dimdesc[1]{%
 \@dimlist{olddescription}{#1}}
\newcommand\@dimenum[1]{%
 \@dimlist{oldenumerate}{#1}}
\ifthenelse{\boolean{tpl@eqlist}}{%
\newcommand\@dimeqlist[1]{%
 \@dimlist{oldeqlist}{#1}}
\newcommand\@dimcompacteqlist[1]{%
 \@dimlist{compacteqlist}{#1}}
}{}
\ifthenelse{\boolean{tpl@paralist}}{%
\newcommand\@dimcompactitem[1]{%
 \@dimlist{oldcompactitem}{#1}}
\newcommand\@dimcompactenum[1]{%
 \@dimlist{oldcompactenum}{#1}}
}{}
\newenvironment{stepitem}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@stepitem}%
 {\global\@ignoretrue}
\newenvironment{stepdesc}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@stepdesc}%
 {\global\@ignoretrue}
\newenvironment{stepenum}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@stepenum}%
 {\global\@ignoretrue}
\ifthenelse{\boolean{tpl@eqlist}}{%
\newenvironment{stepeqlist}[1][0cm]{%
  \tpl@collect@body\@stepeqlist}%
 {\global\@ignoretrue}
\newenvironment{stepcompacteqlist}[1][0cm]{%
  \tpl@collect@body\@stepcompacteqlist}%
 {\global\@ignoretrue}
}{}
\ifthenelse{\boolean{tpl@paralist}}{%
\newenvironment{stepcompactitem}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@stepcompactitem}%
 {\global\@ignoretrue}
\newenvironment{stepcompactenum}[1][0cm]{%
  \tpl@addmargin{#1}
  \tpl@collect@body\@stepcompactenum}%
 {\global\@ignoretrue}
}{}
\newcommand\@steplist[2]{%
\ifthenelse{\boolean{tpl@pausestep}}{%
  \iftpl@inflipenv
    \PackageError{tplists}{%
      flip* followed by step* environment does NOT work \MessageBreak
      when the pausestep option is used}{%
      Do not continue! Type <q> to stop and fix the nested list.
    }
  \else\iftpl@indimenv
    \PackageError{tplists}{%
      dim* followed by step* environment does NOT work \MessageBreak
      when the pausestep option is used}{%
      Do not continue! Type <q> to stop and fix the nested list.
    }
  \else
    \begin{#1}
      \iftpl@inpausestepenv\else\let\tpl@origitem=\item\fi
      \tpl@inpausestepenvtrue
      \renewcommand{\item}{\pause\tpl@origitem}%
      #2
    \end{#1}
  \fi\fi
}{
  \iftpl@inflipenv
    \begin{#1}
    \renewcommand{\item}{\tpl@flipstep\tpl@origitem}
    #2
    \end{#1}%
  \else\iftpl@indimenv
    \begin{#1}
    \renewcommand{\item}{\dstep\tpl@origitem}%
    #2
    \end{#1}%
  \else\iftpl@instepenv
    \begin{#1}
    \renewcommand{\item}{\tpl@step\tpl@origitem}%
    #2
    \end{#1}%
  \else
    \liststepwise{%
      \begin{#1}
      \iftpl@instepenv\else\let\tpl@origitem=\item\fi
      \tpl@instepenvtrue
      \renewcommand{\item}{\tpl@step\tpl@origitem}%
      #2
      \end{#1}}
  \fi\fi\fi
}
}

\newcommand\@stepitem[1]{%
 \@steplist{olditemize}{#1}}
\newcommand\@stepdesc[1]{%
 \@steplist{olddescription}{#1}}
\newcommand\@stepenum[1]{%
 \@steplist{oldenumerate}{#1}}
\ifthenelse{\boolean{tpl@eqlist}}{%
\newcommand\@stepeqlist[1]{%
 \@steplist{oldeqlist}{#1}}
\newcommand\@stepcompacteqlist[1]{%
 \@steplist{compacteqlist}{#1}}
}{}
\ifthenelse{\boolean{tpl@paralist}}{%
\newcommand\@stepcompactitem[1]{%
 \@steplist{oldcompactitem}{#1}}
\newcommand\@stepcompactenum[1]{%
 \@steplist{oldcompactenum}{#1}}
}{}
\newenvironment{compacteqlist}[1][0cm]{%
  % \tpl@addmargin{#1}
  \begin{eqlist}[\parsep0pt\itemsep0pt]}%
 {\end{eqlist}}
\renewenvironment{enumerate}[1][0cm]{%
  \tpl@addmargin{#1}
  \begin{oldenumerate}
    \iftpl@instepenv
      \renewcommand{\item}{\tpl@origitem}%
    \fi
 }%
 {\end{oldenumerate}}

\renewenvironment{itemize}[1][0cm]{%
  \tpl@addmargin{#1}
  \begin{olditemize}
    \iftpl@instepenv
      \renewcommand{\item}{\tpl@origitem}%
    \fi
 }%
 {\end{olditemize}}

\renewenvironment{description}[1][0cm]{%
  % \tpl@addmargin{#1} % Has no effect - FIXME
  \begin{olddescription}
    \iftpl@instepenv
      \renewcommand{\item}{\tpl@origitem}%
    \fi
 }%
 {\end{olddescription}}
\ifthenelse{\boolean{tpl@paralist}}{%
\renewenvironment{compactenum}[1][0cm]{%
  \tpl@addmargin{#1}
  \begin{oldcompactenum}
    \iftpl@instepenv
      \renewcommand{\item}{\tpl@origitem}%
    \fi
 }%
 {\end{oldcompactenum}}

\renewenvironment{compactitem}[1][0cm]{%
  \tpl@addmargin{#1}
  \begin{oldcompactitem}
    \iftpl@instepenv
      \renewcommand{\item}{\tpl@origitem}%
    \fi
 }%
 {\end{oldcompactitem}}
}{}

\endinput
%%
%% End of file `tplists.sty'.
