% --------------------------------------%--------------------------------------
% ---------------------------- Identification part ----------------------------
% --------------------------------------%--------------------------------------

\RequirePackage{rcs}

\RCS$Date: 2000/10/10 12:34:33 $
\RCS$RCSfile: aapres.cls,v $
\RCS$Revision: 1.1 $
\RCS$State: Exp $
\RCS$Author: aa $

\input{aausercs}


% --------------------------------------%--------------------------------------
% -------------------------------- Start code ---------------------------------
% --------------------------------------%--------------------------------------


% --------------------------------------%--------------------------------------
% -------------------------- Declaration of options ---------------------------
% --------------------------------------%--------------------------------------

% Paper type
\DeclareOption{a4paper}{\def\aaslide@paper{A4}}

% Fonts
\DeclareOption{lcmss}{%
  % Font faimily for bout encodings
  \DeclareFontFamily{OT1}{lcmss}{}
  \DeclareFontFamily{T1}{lcmss}{}
  % Font shapes: italic = slant, and OT1 doesn't have bold oblique
  \DeclareFontShape{OT1}{lcmss}{m}{n}{<->lcmss8}{}
  \DeclareFontShape{OT1}{lcmss}{m}{it}{<->lcmssi8}{}
  \DeclareFontShape{OT1}{lcmss}{m}{sl}{<->ssub*lcmss/m/it}{}
  \DeclareFontShape{OT1}{lcmss}{bx}{n}{<->lcmssb8}{}
  \DeclareFontShape{OT1}{lcmss}{bx}{it}{<->sub*lcmss/bx/n}{}
  \DeclareFontShape{OT1}{lcmss}{bx}{sl}{<->sub*lcmss/bx/n}{}
  \DeclareFontShape{T1}{lcmss}{m}{n}{<->dclq8}{}
  \DeclareFontShape{T1}{lcmss}{m}{it}{<->dcli8}{}
  \DeclareFontShape{T1}{lcmss}{m}{sl}{<->ssub*lcmss/m/it}{}
  \DeclareFontShape{T1}{lcmss}{bx}{n}{<->dclb8}{}
  \DeclareFontShape{T1}{lcmss}{bx}{it}{<->dclo8}{}
  \DeclareFontShape{T1}{lcmss}{bx}{sl}{<->ssub*lcmss/bx/it}{}
  % Defaults
  \def\rmdefault{lcmss}
  \def\sfdefault{lcmss}}

% Type of output
\newif\ifslides
\newif\ifhandout
\DeclareOption{slides}{%
  \slidestrue
  \handoutfalse
  \def\aaslide@scale{2.074}%
  \def\aaslide@po{landscape}%
  \def\aaslide@col{onecolumn}%
  \def\aaslide@box#1{#1}%
  \AtEndOfClass{\pagestyle{aaslide}}}
\DeclareOption{slide}{\ExecuteOptions{slides}}
\DeclareOption{note}{%
  \slidesfalse
  \handoutfalse
  \def\aaslide@scale{1}%
  \def\aaslide@po{portrait}%
  \def\aaslide@col{onecolumn}%
  \def\aaslide@box#1{\fbox{#1}}%
  \AtEndOfClass{%
    \includeversion{comment}%
    \pagestyle{aahandout}}}
\DeclareOption{handout}{%
  \slidesfalse
  \handouttrue
  \def\aaslide@scale{.9}%
  \def\aaslide@po{landscape}%
  \def\aaslide@col{twocolumn}%
  \def\aaslide@box#1{\fbox{#1}}%
  \AtEndOfClass{\pagestyle{aahandout}}}


% --------------------------------------%--------------------------------------
% --------------------------- Execution of options ----------------------------
% --------------------------------------%--------------------------------------

\ExecuteOptions{a4paper,lcmss,slides}
\ProcessOptions


% --------------------------------------%--------------------------------------
% ------------------------------ Package loading ------------------------------
% --------------------------------------%--------------------------------------

\LoadClass[\aaslide@col]{article}
\RequirePackage{vmargin}
\RequirePackage{calc}
\RequirePackage{version}
\RequirePackage{aapagestruct}


% --------------------------------------%--------------------------------------
% --------------------------------- Main code ---------------------------------
% --------------------------------------%--------------------------------------


%
% Slide environment
%

% A counter for slides
\newcounter{slide}
\newcounter{subslide}[slide]
\renewcommand{\thesubslide}{\theslide.\arabic{subslide}}

% A slide
\newlength{\aaslide@wslide}
\newlength{\aaslide@hslide}
\newlength{\aaslide@pw}
\newlength{\aaslide@ph}
\newsavebox{\aslide}
\def\aaslide@sec{}
\newenvironment{slide}[1][\@empty]{%
  \setlength{\aaslide@pw}{\PaperWidth}%
  \setlength{\aaslide@ph}{\PaperHeight}%
  \setlength{\aaslide@wslide}{(\aaslide@pw-\aaslidehmarg*2)*\real{0.434}}%
  \setlength{\aaslide@hslide}{%
    (\aaslide@ph-\aaslidevmarg*2-\aaslidehheight-\aaslidesep-
     \aaslide@fsep)*\real{0.434}}%
  \gdef\aaslide@tmpsec{#1}%
  \begin{lrbox}{\aslide}%
    \parbox[c]{0mm}{\rule{0mm}{\aaslide@hslide}}%
    \begin{minipage}[c]{\aaslide@wslide}}{%
    \end{minipage}
  \end{lrbox}%
  \ifslides\clearpage\vspace*{\fill}\else\vspace{\fill}\fi
  \refstepcounter{slide}%
  \markboth{\aaslide@sec{{\large\aaslide@tmpsec}}}{\theslide}%
  \noindent%
  \ifslides\else\section*{\theslide~\aaslide@tmpsec}\fi
  \hspace*{\fill}%
  \aaslide@box{\scalebox{\aaslide@scale}{\usebox{\aslide}}}%
  \hspace*{\fill}%
  \ifslides\vspace*{2mm}\vspace*{\fill}\fi%
  }
\newenvironment{subslide}[1][\@empty]{%
  \ifslides
  \setlength{\aaslide@pw}{\PaperWidth}%
  \setlength{\aaslide@ph}{\PaperHeight}%
  \else\ifhandout
  \setlength{\aaslide@pw}{\PaperWidth}%
  \setlength{\aaslide@ph}{\PaperHeight}%
  \else
  \setlength{\aaslide@ph}{\PaperWidth}%
  \setlength{\aaslide@pw}{\PaperHeight}%
  \fi\fi
  \setlength{\aaslide@wslide}{(\aaslide@pw-\aaslidehmarg*2)*\real{0.434}}%
  \setlength{\aaslide@hslide}{%
    (\aaslide@ph-\aaslidevmarg*2-\aaslidehheight-\aaslidesep-
     \aaslide@fsep)*\real{0.434}}%
  \gdef\aaslide@tmpsec{#1}%
  \begin{lrbox}{\aslide}%
    \parbox[c]{0mm}{\rule{0mm}{\aaslide@hslide}}%
    \begin{minipage}[c]{\aaslide@wslide}}{%
    \end{minipage}
  \end{lrbox}%
  \ifslides\clearpage\vspace*{\fill}\else\vspace{\fill}\fi
  \refstepcounter{subslide}%
  \markboth{\aaslide@sec{\aaslide@tmpsec}}{\thesubslide}%
  \noindent%
  \ifslides\else\subsection*{\thesubslide~\aaslide@tmpsec}\fi
  \hspace*{\fill}%
  \aaslide@box{\scalebox{\aaslide@scale}{\usebox{\aslide}}}%
  \hspace*{\fill}%
  \ifslides\vspace*{2mm}\vspace*{\fill}\fi%
  }

% Some new document identifiers (these + author, title and date)
\newcommand{\organization}[1]{\def\aaslide@org{#1}}
\newcommand{\presentation}[1]{\def\aaslide@pres{#1}}

% title and author have a new optional argument for the footer
\let\au@thor\author
\renewcommand{\author}[2][]{%
  \au@thor{#2}%
  \def\@arg{#1}%
  \ifx\@empty\@arg\def\aaslide@author{#2}\else\def\aaslide@author{#1}\fi}
\let\ti@tle\title
\renewcommand{\title}[2][]{%
  \ti@tle{#2}%
  \def\@arg{#1}%
  \ifx\@empty\@arg\def\aaslide@title{#2}\else\def\aaslide@title{#1}\fi}

% date have an additional * form to remove the date from the foot
\let\da@te\date
\def\date{\@ifnextchar*{\aada@te}{\aa@date}}
\def\aada@te*#1{\da@te{#1}}
\newcommand{\aa@date}[2][]{%
  \da@te{#2}%
  \def\@arg{#1}%
  \ifx\@empty\@arg\def\aaslide@date{#2}\else\def\aaslide@date{#1}\fi}

% maketitle is just a slide with the title
\let\mk@title\maketitle
\def\maketitle{%
  \ifslides
  \begin{slide}
    \setcounter{slide}{-1}%
    \let\aaslide@title\@title
    \let\aaslide@author\@author
    \let\aaslide@date\@date
    \vspace*{-29pt}
    \mk@title
    \global\let\@title\aaslide@title
    \global\let\@author\aaslide@author
    \global\let\@date\aaslide@date
    \thispagestyle{aaslide}%
  \end{slide}%
%  \else\ifhandout
%  \begin{slide}
%    \setcounter{slide}{-1}%
%    \let\aaslide@title\@title
%    \let\aaslide@author\@author
%    \let\aaslide@date\@date
%    \let\tmp@aasbox\aaslide@box
%    \def\aaslide@box##1{##1}%
%    \vspace*{-29pt}
%    \mk@title
%    \global\let\@title\aaslide@title
%    \global\let\@author\aaslide@author
%    \global\let\@date\aaslide@date
%    \global\aaslide@box\tmp@aasbox
%    \thispagestyle{plain}
%  \end{slide}
  \else
  \mk@title\thispagestyle{plain}
%  \fi
  \fi}

%
% Decoration frames and page layout
%

% Set paper size (a4 and landscape default).
\setpapersize[\aaslide@po]{\aaslide@paper}

% Ok, lets calculate some lengths (we use counters, but the unit is mm)

% hmarg and vmarg is for horizontal and vertical margins
\newlength{\aaslidehmarg}\setlength{\aaslidehmarg}{20mm}
\newlength{\aaslidevmarg}\setlength{\aaslidevmarg}{\aaslidehmarg}

% hheight and fheight is the height of the head and foot
\newlength{\aaslidehheight}\setlength{\aaslidehheight}{12mm}
\newlength{\aaslidefheight}\setlength{\aaslidefheight}{3mm}

% sep is the space between the text and the head and the foot
\newlength{\aaslidesep}\setlength{\aaslidesep}{5mm}

% @fsep is the space between the text and the end of the foot
\newlength{\aaslide@fsep}
\setlength{\aaslide@fsep}{\aaslidesep+\aaslidefheight}

% The rounded corner of frames (size)
\newlength{\aaslidecorner}
\setlength{\aaslidecorner}{3mm}

% Fine tune x position of frames
\newlength{\aaslide@xcor}
\setlength{\aaslide@xcor}{-0.8mm}

% Fine tune y position of header and footer
\newlength{\aaslide@hycor}
\setlength{\aaslide@hycor}{0mm}
\newlength{\aaslide@fycor}
\setlength{\aaslide@fycor}{-0.1mm}

% Set margins
\setmarginsrb{\aaslidehmarg}{\aaslidevmarg}{\aaslidehmarg}{\aaslidevmarg}{%
  \aaslidehheight}{\aaslidesep}{\aaslidefheight}{\aaslide@fsep}

% Goto zero position
\newlength{\aaslide@gtb}
\newcommand{\aaslide@zeropos}[1]{%
  \makebox[0pt][l]{%
    % Calculate space down to lower left corner
    \setlength{\aaslide@gtb}{\PaperHeight-\aaslidehheight-\aaslidevmarg}
    % Goto lower left corner (from lower left corner of header)
    \hspace{-\aaslidehmarg}%
    \raisebox{-\aaslide@gtb}[0pt][0pt]{%
      #1%
      }%
    }%
  }

% Draw a frame
\newcounter{aaslide@olen}\newcounter{aaslide@osz}
\newcounter{aaslide@hlen}\newcounter{aaslide@vlen}
\newcounter{aaslide@xa}\newcounter{aaslide@xb}
\newcounter{aaslide@ya}\newcounter{aaslide@yb}
\newcommand{\aaslide@frame}[2]{%
  \setcounter{aaslide@olen}{\aaslidecorner/\unitlength}%
  \setcounter{aaslide@osz}{\value{aaslide@olen}*2}%
  \setcounter{aaslide@hlen}{#1-\value{aaslide@olen}*2}%
  \setcounter{aaslide@vlen}{#2-\value{aaslide@olen}*2}%
  \setcounter{aaslide@xa}{\value{aaslide@olen}+\value{aaslide@hlen}}%
  \setcounter{aaslide@xb}{\value{aaslide@olen}+\value{aaslide@xa}}%
  \setcounter{aaslide@ya}{\value{aaslide@olen}+\value{aaslide@vlen}}%
  \setcounter{aaslide@yb}{\value{aaslide@olen}+\value{aaslide@ya}}%
  \begin{picture}(#1,#2)
    \thicklines
    \put(\value{aaslide@olen},0){%
      \line(1,0){\value{aaslide@hlen}}}%
    \put(\value{aaslide@olen},\value{aaslide@yb}){%
      \line(1,0){\value{aaslide@hlen}}}%
    \put(0,\value{aaslide@olen}){%
      \line(0,1){\value{aaslide@vlen}}}%
    \put(\value{aaslide@xb},\value{aaslide@olen}){%
      \line(0,1){\value{aaslide@vlen}}}%
    \put(\value{aaslide@olen},\value{aaslide@olen}){%
      \oval(\value{aaslide@osz},\value{aaslide@osz})[bl]}%
    \put(\value{aaslide@olen},\value{aaslide@ya}){%
      \oval(\value{aaslide@osz},\value{aaslide@osz})[tl]}%
    \put(\value{aaslide@xa},\value{aaslide@olen}){%
      \oval(\value{aaslide@osz},\value{aaslide@osz})[br]}%
    \put(\value{aaslide@xa},\value{aaslide@ya}){%
      \oval(\value{aaslide@osz},\value{aaslide@osz})[tr]}%
  \end{picture}%
  }

% Positions and sizes of frames

% Same x position for all frames (fxpos)
\newcounter{aaslide@fxpos}

% Same width for all frames (fwidth)
\newcounter{aaslide@fwidth}

% Y position for header frame (hypos)
\newcounter{aaslide@hypos}

% Y position for text frame (typos)
\newcounter{aaslide@typos}

% Y position for foot frame (fypos)
\newcounter{aaslide@fypos}

% Height for header frame (hheight)
\newcounter{aaslide@hheight}

% Height for text frame (theight)
\newcounter{aaslide@theight}

% Height for foot frame (fheight)
\newcounter{aaslide@fheight}

% Counters for paper height and paper width
\newcounter{paperwidth}
\newcounter{paperheight}

% Make the pagestyle for this paper
\def\ps@aaslide{%
  % Calculate counters from lengths
  \setcounter{paperwidth}{\PaperWidth/\unitlength}%
  \setcounter{paperheight}{\PaperHeight/\unitlength}%
  \setcounter{aaslide@fxpos}{%
    (\aaslidehmarg-\aaslidesep/2+\aaslide@xcor)/\unitlength}%
  \setcounter{aaslide@fwidth}{%
    (\PaperWidth-(\aaslidehmarg*2-\aaslidesep))/\unitlength}%
  \setcounter{aaslide@hypos}{%
    (\PaperHeight-\aaslidevmarg-\aaslidehheight-\aaslide@hycor-\aaslidesep/2)/\unitlength}%
  \setcounter{aaslide@typos}{%
    (\aaslidevmarg+\aaslide@fsep-\aaslidesep/2)/\unitlength}%
  \setcounter{aaslide@fypos}{%
    (\aaslidevmarg-\aaslide@fycor-\aaslidesep/2)/\unitlength}%
  \setcounter{aaslide@hheight}{%
    (\aaslidehheight+\aaslidesep)/\unitlength}%
  \setcounter{aaslide@theight}{%
    (\PaperHeight-\aaslidevmarg*2-\aaslidehheight-\aaslide@fsep)/\unitlength}%
  \setcounter{aaslide@fheight}{%
    (\aaslidefheight+\aaslidesep)/\unitlength}%
  % The head for odd pages
  \def\@oddhead{%
    % Draw frames
    \aaslide@zeropos{%
      \begin{picture}(\value{paperwidth},\value{paperheight})
        \put(\value{aaslide@fxpos},\value{aaslide@hypos}){%
          \aaslide@frame{\value{aaslide@fwidth}}{\value{aaslide@hheight}}}
        \put(\value{aaslide@fxpos},\value{aaslide@typos}){%
          \aaslide@frame{\value{aaslide@fwidth}}{\value{aaslide@theight}}}
        \put(\value{aaslide@fxpos},\value{aaslide@fypos}){%
          \aaslide@frame{\value{aaslide@fwidth}}{\value{aaslide@fheight}}}
      \end{picture}%
      }%
    \parbox[b]{0.3\PaperWidth}{%
      \raggedright
      \aaslide@org
      }%
    \hfill%
    \makebox[0pt]{\scalebox{\aaslide@scale}{\textbf{\leftmark}}}%
    \hfill%
    \parbox[b]{0.3\PaperWidth}{%
      \raggedleft
      \aaslide@pres
      }%
    \hfil}%
  \def\@oddfoot{%
    \makebox[0.3\PaperWidth][l]{\aaslide@title}%
    \hfill%
    -~\rightmark~-%
    \hfill%
    \makebox[0.3\PaperWidth][r]{\aaslide@author\@ifundefined{aaslide@date}{}{%
        ,~\aaslide@date}}%
    }%
  }

% The pagestyle for handout
\def\ps@aahandout{%
  \def\@oddhead{%
    \parbox[b]{0.3\PaperWidth}{%
      \raggedright
      \aaslide@org
      }%
    \hfill%
    \parbox[b]{0.3\PaperWidth}{%
      \raggedleft \aaslide@pres \hfil}}
  \def\@oddfoot{\hfill\thepage\hfill}}

