%\iffalse -*- doctex -*- \fi
%
%% \RCS$Id: pmn-prsp.sty,v 1.2 2004/10/12 00:14:35 turtle Exp $
%% \RCS$Revision: 1.2 $
%% \RCS$Date: 2004/10/12 00:14:35 $
%
%\iffalse metacomment
% -*- latex-mode -*-
% % $Id: pmn-prsp.sty,v 1.2 2004/10/12 00:14:35 turtle Exp $
% % (C) 2003 Peter M�ller Neergaard
%%  
%%   This program may be distributed and/or modified under the
%%   conditions of the LaTeX Project Public License, either version 1.2
%%   of this license or (at your option) any later version.
%%   The latest version of this license is in
%%     http://www.latex-project.org/lppl.txt
%%   and version 1.2 or later is part of all distributions of LaTeX 
%%   version 1999/12/01 or later.
%
% This program consists of the file pmn-prsp.sty.
% 
% To print the documentation (which for the moment is uninteresting)
% remove (or comment out) the line
%
%   \endinput
%
% occurring immediately after
%
%   %<*documentation>
% 
%\fi
%
% \CheckSum{11}
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \MakeShortVerb{\"}
%
% \title{The \package{pmn-prsp} package\thanks
%   {This file has CVS revision \RCSRevision, dated \RCSDate.}}
% \author{Peter M�ller Neergaard}
% \maketitle
%
% \begin{abstract}
%   Extends \package{prosper}-document class with some extra
%   convenient commands.
% \end{abstract}
%
% \section{Package identification}
% 
% We identify ourselves.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pmn-prsp}[2004/10/04  PMN prosper extensions]
%    \end{macrocode}
\newcommand{\prsp@ifDVItoPS}{%
 \ifDVItoPS
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}	
\newcommand{\prsp@putonslide}{\let\prsp@if@onslide\iftrue}
\newcommand{\overlay@one}{\overlay{1}}%
\newcommand{\OnSlides}{%
  \prsp@ifDVItoPS{\@gobble}{\prsp@onslides\relax\overlay@one}}
\newcommand{\onSlides}{%
  \prsp@ifDVItoPS
    {\prsp@slide@ps}%
    {\@ifstar
        {\prsp@onslides\@iden\@gobble}%
      {\prsp@onslides\@iden\@on@overlay@one}}}
\newcommand{\prsp@slide@ps}{%
  \@ifstar\prsp@slide@ps@i\prsp@slide@ps@i}
\newcommand{\prsp@slide@ps@i}[1]{%
  \ifAccumulate
    \expandafter\@iden
  \else
    \expandafter\@gobble
  \fi} 
	
\newcommand{\prsp@onslides}[3]{%
  \let\prsp@if@onslide\iffalse
  \@for\interval:=#3\do{\expandafter\pmn@tst@intv\interval-\relax}%
  \prsp@if@onslide\expandafter#1\else\expandafter#2\fi}	
  
\def\pmn@tst@intv#1-{%
  \@ifnextchar-{\pmn@tst@intv@mbopend{#1}}{%
    \@ifnextchar\relax{%
      \ifnum\value{overlaysCount}=#1\relax\prsp@putonslide\fi
      \@gobble}%
    {\pmn@tst@intv@clsend{#1}}}}
\def\pmn@tst@intv@mbopend#1-\relax{%
  \def\reserved@a{#1}%
    \ifx\reserved@a\empty 
      \prsp@putonslide
    \else
      \ifnum\value{overlaysCount}<#1\else\prsp@putonslide\fi
    \fi}
\def\pmn@tst@intv@clsend#1#2-\relax{%
  \ifnum\value{overlaysCount}>#2\else
    \def\reserved@a{#1}%
    \ifx\reserved@a\empty 
      \prsp@putonslide
    \else
      \ifnum\value{overlaysCount}<#1\else\prsp@putonslide\fi
    \fi
  \fi}

\makeatletter
\newbox\prsp@boxA
\newbox\prsp@boxB
\newcommand{\untilAfterSlide}[4][c]{%
  \ifmmode 
    \let\next\prsp@uas@math
  \else 
    \let\next\prsp@uas@text
  \fi
  \ifnum\value{overlaysCount}>#2
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi  
  {\next{#4}{#3}{#1}}{\next{#3}{#4}{#1}}}
\newcommand{\prsp@uas@text}[3]{%
  \bgroup
  \setbox\prsp@boxA\hbox{\mbox{#1}}% 
  \setbox\prsp@boxB\hbox{\mbox{#2}}%
  \ifdim\wd\prsp@boxB>\wd\prsp@boxA
    \setbox\prsp@boxA\hbox{\makebox[\wd\prsp@boxB][#3]{#1}}%
  \fi
  \prsp@uas@fin}
\newcommand{\prsp@uas@math}[3]{%
  \mathpalette\prsp@uas@math@i{{#1}{#2}{#3}}}
\newcommand{\prsp@uas@math@i}[2]{\prsp@uas@math@ii{#1}#2}
\newcommand{\prsp@uas@math@ii}[4]{%
  \bgroup
  \setbox\prsp@boxA\hbox{$\m@th#1{#2}$}%
  \setbox\prsp@boxB\hbox{$\m@th#1{#3}$}%
  \ifdim\wd\prsp@boxB>\wd\prsp@boxA
    \setbox\prsp@boxA\hbox{\makebox[\wd\prsp@boxB][#4]{$\m@th#1{#2}$}}%
  \fi
  \prsp@uas@fin}
\newcommand{\prsp@uas@fin}{%
  \ifdim \dp\prsp@boxB>\dp\prsp@boxA\relax
    \dp\prsp@boxA\dp\prsp@boxB\relax
  \fi
  \ifdim \ht\prsp@boxB>\ht\prsp@boxA\relax
    \ht\prsp@boxA\ht\prsp@boxB\relax
  \fi
  \box\prsp@boxA\egroup}
