%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This file `slideprint.sty'
%
%
% Error Reports should be sent to
%
%   Georg Martius <mai99dgf@studserv.uni-leipzig.de>
%   M. Lindemeyer <battlechess@web.de>
%
% options: (first 2 are mutual exclusive)
%   - slides -> Slide version will be created
%   - print  -> Print version as normal Tex-Paper 
%
%   - lecture-> option for print version with included 
%               comments and breakmarkers
%   - pdf    -> options for pdflatex 
%   - nopictures -> all pictures and tables will be omitted 
%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{slideprint}[2001/12/20 v0.1 Slides with Print option]
\def\showpictures{Yes}
\def\lecture{No}
\def\pdf{No}
\DeclareOption{slides}{
  \def\Output{Slides}
}
\DeclareOption{print}{
  \def\Output{Print}
}
\DeclareOption{lecture}{
  \def\lecture{Yes}
}

\DeclareOption{nopictures}{
  \def\showpictures{No}  
}
\DeclareOption{pdf}{
  \def\pdf{Yes}  
}

\ProcessOptions

\RequirePackage{ifthen}
\RequirePackage{exscale}
\RequirePackage{calc}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  to distinguish the output types
\newcommand{\Printonly}[1]{\ifthenelse{\equal{\Output}{Print}}
  {#1}
  {}}

\newcommand{\Slidesonly}[1]{\ifthenelse{\equal{\Output}{Slides}}
  {#1}
  {}}

\newcommand{\ForLecture}[1]{\ifthenelse{\equal{\lecture}{Yes}}
  {#1}
  {}}


\newcommand{\ifPDFelse}[2]{\ifthenelse{\equal{\pdf}{Yes}}
  {#1}
  {#2}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Packages
\Slidesonly{
  \ifthenelse{\equal{\pdf}{Yes}}{
     \RequirePackage[pdftex,usenames]{color}
  }{
     \RequirePackage[dvips]{color}
     \def\printlandscape{\special{landscape}}    % Works with dvips.
  }
  
  \RequirePackage{fancybox}  
  \newcounter{chapter}
}

\Printonly{  
  \RequirePackage{a4wide}
  \RequirePackage{fancyhdr}
  \RequirePackage[twoside, top=2cm, bottom=1cm, right=3cm, left=2cm]{geometry} 
}

\ifPDFelse{
  \RequirePackage[pdftex,bookmarks=true,
  		 bookmarksopen=true,
		 bookmarksnumbered=true,
		 colorlinks=true,
		 linkcolor=blue, 
		 citecolor=green,
		 pagecolor=magenta]{hyperref}
}{
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  general Values
\def\project{}
\def\name{}
\def\organisation{}
\newcommand{\Project}[1]{\def\project{#1}}
\newcommand{\Name}[1]{\def\name{#1}}
\newcommand{\Organisation}[1]{\def\organisation{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%               Bilder, Abbildungen und Tabellen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\Picture}[3]{ % 1: beschreibung 2:label 3: graphics befehl
  \ifthenelse{\equal{\showpictures}{Yes}}
  { \Slidesonly{
      \begin{figure}[htbp]
        \begin{center}
          #3
          % for manja \caption{#1}\ifthenelse{\equal{#2}{}}{}{\label{#2}}
        \end{center}
      \end{figure}      
    \slidebreak
    }
    \Printonly{
      %\clearpage
      \begin{figure}
        \begin{center}
          #3
          \caption{\scriptsize #1}
  \ifthenelse{\equal{#2}{}}{}{\label{#2}}
         \end{center}
      \end{figure}
    }
  }
  {% do nothing
  }
}

\renewcommand{\tablename}{\scriptsize Tabelle}
\newcommand{\Table}[3]{ % 1: beschreibung 2:label 3: graphics befehl
  \ifthenelse{\equal{\showpictures}{Yes}}
  { \Slidesonly{
      \begin{table}[htbp]
        \begin{center}
          #3
          % for manja \caption{#1}\ifthenelse{\equal{#2}{}}{}{\label{#2}}
        \end{center}
      \end{table}
    \slidebreak
    }
    \Printonly{
      \begin{table}
        \begin{center}
          #3
          \caption{\scriptsize #1}
          \ifthenelse{\equal{#2}{}}{}{\label{#2}}
         \end{center}
      \end{table}
    }
  }
  {% do nothing
  }
}


\newcommand{\PicturePrintShrink}{ 2/3}
%% 1: direction: ,w,e,s rotate to the point of the compass  (north, east ..)
%% 2: scale: default 0.5
%% 3: filename
\newcommand{\LoadPicture}[3][n]{ %% n,w,e,s rotate to the point of the compass  (north, east ..)
  \ifthenelse{\equal{#1}{n}}{
    \def\LoadPicRotate{0}
  }{
    \ifthenelse{\equal{#1}{e}}{
     \def\LoadPicRotate{90}
    }{
      \ifthenelse{\equal{#1}{w}}{
        \def\LoadPicRotate{-90}
      }{
        \ifthenelse{\equal{#1}{s}}{
          \def\LoadPicRotate{180}
        }{
            \errmessage{Unsupported rotate direction #1 (only n,e,w,s: north, east ..)}\stop
        }
      }
    }
  } 
  \def\LoadPicsize{0.5}
  \ifthenelse{\equal{#2}{}}{}{ \def\LoadPicsize{#2}}
  \Printonly{  
    \resizebox*{\LoadPicsize\columnwidth * \PicturePrintShrink }{!}{\rotatebox{\LoadPicRotate}{\includegraphics{#3}}}
  }
  \Slidesonly{  
    \resizebox*{\LoadPicsize\columnwidth}{!}{\rotatebox{\LoadPicRotate}{\includegraphics{#3}}}  
  }
}
%% 1: direction: ,w,e,s rotate to the point of the compass  (north, east ..)
%% 2: width ratio to the whole page width. default 0.5
%% 3: \includegraphics{filename} # just for the makefile to get it!
\newcommand{\RotScale}[3][n]{ %% n,w,e,s rotate to the point of the compass  (north, east ..)
  \ifthenelse{\equal{#1}{n}}{
    \def\LoadPicRotate{0}
  }{
    \ifthenelse{\equal{#1}{e}}{
     \def\LoadPicRotate{90}
    }{
      \ifthenelse{\equal{#1}{w}}{
        \def\LoadPicRotate{-90}
      }{
        \ifthenelse{\equal{#1}{s}}{
          \def\LoadPicRotate{180}
        }{
            \errmessage{Unsupported rotate direction #1 (only n,e,w,s: north, east ..)}\stop
        }
      }
    }
  } 
  \def\LoadPicsize{0.5}
  \ifthenelse{\equal{#2}{}}{}{ \def\LoadPicsize{#2}}
  \Printonly{  
    \resizebox*{\LoadPicsize\columnwidth * \PicturePrintShrink }{!}{\rotatebox{\LoadPicRotate}{#3}}
  }
  \Slidesonly{  
    \resizebox*{\LoadPicsize\columnwidth}{!}{\rotatebox{\LoadPicRotate}{#3}}
  }
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%               Headings and Sections
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\ChapterToLastheading}{No}
\newcounter{lastheadingcnt}
\def\lastheading{}
\newcommand{\setlastheading}[1]{
  \ifthenelse{\equal{#1}{}}{ }{
    \setcounter{lastheadingcnt}{1} \def\lastheading{#1}
  }
}
\newcommand{\getlastheading}{
  \ifthenelse{\equal{\lastheading}{}}{}{
  \ifthenelse{\arabic{lastheadingcnt}<2}
    {}
    {\lastheading\ (\arabic{lastheadingcnt})}
  }
  \addtocounter{lastheadingcnt}{1}
}

\newlength{\tabwid}
\newsavebox{\headbox}
\def\headingcol{\color{black}}
\newcommand{\Headingcol}[1]{\def\headingcol{\color{#1}}}

\def\increaseHeadingLevel{0}
\newcounter{headinglevel}
\ifx\chapter\def\increaseHeadingLevel{1}
\else\def\increaseHeadingLevel{0}
\fi

\newcommand{\heading}[2][2]{
  \internheading[#1]{n}{#2}
}
\newcommand{\headingnn}[2][2]{
  \internheading[#1]{*}{#2}
}


\newcommand{\internheading}[3][2]{% 
  %optional 1. param:  1 chapter
  %                   ,2 section
  %                   ,3 subsection
  %                   ,4 subsubsection
  %                   ,5 subsubsubsection
  % 2. param: n with numbers
  %                  * without numbers
\Slidesonly{                                         
  \pagebreak[3]
  \vspace{1ex}
  
  \def\headingbox{shadow}
  
  \ifthenelse{\equal{#1}{1}}
  {
    \pagebreak[4]
    \def\headingFont{\LARGE \bf}
    \def\headingbox{shadow}
    \ifPDFelse{\pdfbookmark[0]{#3}{\roman{chapter}}}{}
    \addtocounter{chapter}{1}
    \ifthenelse{\equal{\ChapterToLastheading}{Yes}}{\setlastheading{#3}}{}
    \addtocontents{toc}{\bf\large#3\\}
  }{
   \ifthenelse{\equal{#1}{2}}
   {
     \pagebreak[4]
     \def\headingFont{\Large \bf}
     \def\headingbox{shadow}
     \setlastheading{#3}
     \ifPDFelse{\pdfbookmark[1]{#3}{\roman{section}}}{}
     \addtocontents{toc}{\rm\normalsize\tab#3\\}
     \addtocounter{section}{1}
   }{
     \ifthenelse{\equal{#1}{3}}
     { %subsection
        \pagebreak[4]
        \def\headingFont{\large}
        \def\headingbox{frame}
        \ifPDFelse{\pdfbookmark[2]{#3}{\roman{subsection}}}{}
      	\addtocounter{subsection}{1}	
     }
     { \ifthenelse{\equal{#1}{4}}
       { %subsubsection
         \def\headingFont{\normalsize}
         \def\headingbox{frame}
       }
       { \ifthenelse{\equal{#1}{5}}
         { %subsubsection
           \def\headingFont{\normalsize}
           \def\headingbox{none}
         }
         {  %\if#1n 
              %nothing
              \def\headingFont{\normalsize}
              \def\headingbox{none}
            %\else
            %  \errmessage{Unsupported heading type #1 (only 1,2,3,4,n)}\stop
            %\fi
         }
       }
     }
   }
  }
  
  \begin{center}%
    \setslidelength{\tabwid}{\slidewidth}%
    \headingFont%
    \savebox{\headbox}{#3}%
    \ifdim\wd\headbox>\tabwid% 
    
      \ifthenelse{\equal{\headingbox}{shadow}}
       {\shadowbox{\headingcol \parbox{.9\tabwid}{\begin{center}#3\end{center}}}}%
       {\framebox{\headingcol \parbox{.9\tabwid}{\begin{center}#3\end{center}}}}
       
    \else% 
      \ifthenelse{\equal{\headingbox}{shadow}}
       {\shadowbox{\headingcol {#3}}}%
       {\framebox{\headingcol {#3}}}
    \fi%
  \end{center}%
  \vspace{1ex}
}%
\Printonly{
\setcounter{headinglevel}{#1}
\addtocounter{headinglevel}{\increaseHeadingLevel}
  \ifthenelse{\equal{\arabic{headinglevel}}{1}}
    {
     \ifthenelse{\equal{#2}{n}}{\chapter{#3}}{\chapter*{#3}}
      \def\currentchapter{#3}
    }{
     \ifthenelse{\equal{\arabic{headinglevel}}{2}}
     {
       \ifthenelse{\equal{#2}{n}}{\section{#3}}{\section*{#3}}
     }{
       \ifthenelse{\equal{\arabic{headinglevel}}{3}}
       { %subsection
         \ifthenelse{\equal{#2}{n}}{\subsection{#3}}{\subsection*{#3}}
       }
       { \ifthenelse{\equal{\arabic{headinglevel}}{4}}
         { %subsubsection
           \ifthenelse{\equal{#2}{n}}{\subsubsection{#3}}{\subsubsection*{#3}}
         }
         { \ifthenelse{\equal{\arabic{headinglevel}}{5}}
           { %subsection
              \ifthenelse{\equal{#2}{n}}{\subsubsection{#3}}{\subsubsection*{#3}}
           }
           {%  \if#1n 
                 %nothing
                 \subsubsection*{#3}    
  %            \else
  %              \errmessage{Unsupported heading type #1 (only 1,2,3,4,n)}\stop
  %            \fi
          }
        }
       }
     }
    }
}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%               Headline Footline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\currentchapter{}
\def\headlineleft{\currentchapter}
\def\headlinecenter{\getlastheading}
\def\headlineright{\organisation}
\def\headlinerule{\headlinecol\rule{\textwidth}{1mm}}
\def\headlinecol{}
\newcommand{\Headlineleft}[1]{\def\headlineleft{#1}}
\newcommand{\Headlinecenter}[1]{\def\headlinecenter{#1}}
\newcommand{\Headlineright}[1]{\def\headlineright{#1}}
\newcommand{\Headlinerule}[1]{\def\headlinerule{#1}}
\newcommand{\Headlinercolor}[1]{\def\headlinecol{ \color{#1}}}
\newcommand{\Logo}{}
\newcommand{\LogoForHeadline}{}


\def\footlineleft{\name}
\def\footlinecenter{\thechapter\ --\ \thepage}
\def\footlineright{\project}
\def\footlinerule{\footlinecol \rule{\textwidth}{1mm}}
\def\footlinecol{}
\newcommand{\Footlineleft}[1]{\def\footlineleft{#1}}
\newcommand{\Footlinecenter}[1]{\def\footlinecenter{#1}}
\newcommand{\Footlineright}[1]{\def\footlineright{#1}}
\newcommand{\Footlinerule}[1]{\def\footlinerule{#1}}
\newcommand{\Footlinercolor}[1]{\def\footlinecol{ \color{#1}}}


%               Headline,Footline for SLIDES
\Slidesonly{
    %%% Headline with or without a Logo
    \newcommand{\Headline}{\headline}
    \newcommand{\Footline}{\footline}

    \def\headline{%
    \hbox{\vbox{%
	       \hbox to \textwidth{%
	        \ \makebox[0cm][l]{\headlinecol\headlineleft}\hfill%
	        \makebox[0cm]{\headlinecol\headlinecenter}\hfill%           
	        \makebox[0cm][r]{\headlinecol\headlineright}\ %
	       }%
 	       \hbox{\headlinerule}%
         }
    }}

    \def\footline{%
     \hbox{\vbox{%
       \hbox{\footlinerule}%
       \hbox to \textwidth{%
       \ \makebox[0cm][l]{\footlinecol\footlineleft}\hfill%
       \makebox[0cm]{\footlinecol\footlinecenter}\hfill%           
       \makebox[0cm][r]{\footlinecol\footlineright}\ %
      }%
     }}
    }

    \newpagestyle{slideframestyle}{\Headline}{\Footline}
    \slidepagestyle{slideframestyle}
}
\Printonly{ %               Headline,Footline for print output
  \pagestyle{fancy}
  \fancyhf{}
  \setlength{\headheight}{33pt}

  \fancyhead[LE,RO]{\name\\ \thepage}
  \fancyhead[C]{\organisation\\ \project}
  \fancyhead[LO,RE]{\LogoForHeadline}
  \fancypagestyle{plain}{%
    \fancyhead{} % get rid of headers
    \renewcommand{\headrulewidth}{0pt} % and the line
  }

}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% P D F
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ifthenelse{\equal{\pdf}{Yes}}{

  \pdfcompresslevel=9     % compression level for text and image;
                          % 0 = no compression (default)
                          % 1 = fastest compression
                          % 9 = best compression
                          % 2..8 = something between
}{}

\newcommand{\setPageSize}[1]{  % Querformat
  %(eigentlich 11.69in x 8.26in aber faktoren durch magnification) (formel: für z>3: faktor=log_2(z+0.3)
  \ifthenelse{\equal{\pdf}{Yes}}{
     \ifthenelse{#1=1}
     {
       %mag 1 -> 1.20
       \pdfpagewidth=9.74in    % page width of PDF output 
       \pdfpageheight=6.88in   % page height of PDF output
     }{
     \ifthenelse{#1=2}
     {%mag 2 -> 1.44
       \pdfpagewidth=8.12in    % page width of PDF output 
       \pdfpageheight=5.73in   % page height of PDF output
     }{
     \ifthenelse{#1=3}
     {%mag 3 -> 1.73
       \pdfpagewidth=6.76in    % page width of PDF output 
       \pdfpageheight=4.78in   % page height of PDF output
     }{
     \ifthenelse{#1=4}
     {%mag 4 -> 2.07
       \pdfpagewidth=5.64in    % page width of PDF output 
       \pdfpageheight=3.98in   % page height of PDF output
     }{
     \ifthenelse{#1=5}
     {%mag 5 -> 2.49
       \pdfpagewidth=4.70in    % page width of PDF output 
       \pdfpageheight=3.32in   % page height of PDF output
     }{
     }}}}}
  }
  { % nopdf (ps)
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Frames and Boxes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newlength{\storefboxrule}{}
\newlength{\storefboxsep}{}
\newcommand{\ColorBox}[2]{
 \Slidesonly{
   \setslidelength{\tabwid}{\slidewidth}
   \definecolor{bkcolor}{rgb}{#1}
   \setlength{\storefboxrule}{\fboxrule}
   \setlength{\storefboxsep}{\fboxsep}
   \setlength{\fboxrule}{1pt}
   \setlength{\fboxsep}{10pt}
    \hspace{-.5cm}
    \fcolorbox{black}{bkcolor}{
     \begin{minipage}{\tabwid}
      #2
     \end{minipage}
    }
    \setlength{\fboxrule}{\storefboxrule}
    \setlength{\fboxsep}{\storefboxsep}   
 
 }
 \Printonly{
  \ \\{\bf#2}\\
 }
}

\def\bkcolorA{0.8,0.8,1}
\def\bkcolorB{0.5,1,0.5}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Environments and Macros
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\Start}{\begin{document}\begin{slideex}}
\newcommand{\End}{\end{slideex}\end{document}}

\Slidesonly{
  \newcommand{\zoom}[1]{\slidesmag{#1} \setPageSize{#1}}
  \newenvironment{slideex}{\begin{slide}}{\end{slide}}
  \newcommand{\slidebreak}[1][4]{\pagebreak[#1]}
  \newcommand{\refa}[1]{}
  \newcommand{\reft}[1]{}
}
\Printonly{
  \newenvironment{slideex}{}{}
  \newcommand{\slidebreak}[1][4]{\ForLecture{\rule{\textwidth}{0.5mm}}
  
  }
  \newcommand{\refa}[1]{(Abb. \ref{#1})}
  \newcommand{\reft}[1]{(Tab. \ref{#1})}
}

\newcommand{\pv}[1]{\Printonly{#1}}
\newcommand{\sv}[1]{\Slidesonly{#1}}
\newcommand{\comment}[1]{\ForLecture{{\em \textbf{Comment:} #1}}}
\newcommand{\Comment}[1]{\ForLecture{{\em \textbf{Comment:} #1}}}


%%%%%%%% Format things
\newcommand{\tab}[1][0.5cm]{\makebox[#1][l]{}}
\newcommand{\bold}[1]{{\bf #1}}
\newcommand{\Bold}[1]{{\bf #1}}
\newcommand{\kurs}[1]{{\em #1}}

\newcommand{\entrylabel}[1]{\mbox{\textsf{#1:}}\hfil}

\newenvironment{entry}[1]
{ \begin{list}{}%
  { \renewcommand{\makelabel}{\entrylabel}%
     \setlength{\labelwidth}{#1}%
     \setlength{\leftmargin}{\labelwidth+\labelsep}%
  }%
}%
{\end{list}}

\newcommand{\Mentrylabel}[1]%
 {\raisebox{0pt}[1ex][0pt]{\makebox[\labelwidth][l]%
  {\parbox[t]{\labelwidth}{\hspace{0pt}\textsf{#1:}}}}}

\newenvironment{Mentry}[1]%
 {\renewcommand{\entrylabel}{\Mentrylabel}\begin{entry}{#1}}%
  {\end{entry}}

%%%%%  CHEMIE
\newcommand{\reactionarrow}[2]{\ensuremath{\overset{_{#1}}{\underset{#2}{\Longrightarrow}}}}

