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

\RequirePackage{rcs}
\RequirePackage{ifthen}

\RCS$Date: 1997/04/24 14:21:06 $
\RCS$RCSfile: aateo.sty,v $
\RCS$Revision: 1.0 $
\RCS$State: Exp $
\RCS$Author: anders $

\def\aabasenamex#1.#2,#3{#1}
\def\aafiletypex#1.#2,#3{#2}
\def\aabasename{\expandafter\aabasenamex\RCSRCSfile}
\ifthenelse{\equal{\@clsextension}{\expandafter\aafiletypex\RCSRCSfile}}{%
  \def\aafiletype{Class}}{%
  \def\aafiletype{Package}}
\ifthenelse{\equal{OK}{\RCSState}}{%
  \def\aastate{ }}{%
  \def\aastate{ (\RCSState) }}
\typeout{\aafiletype: `\aabasename' v\RCSRevision\aastate
  <\RCSRawDate> (\RCSAuthor)}

\NeedsTeXFormat{LaTeX2e}
\ifthenelse{\equal{\aafiletype}{Class}}{%
  \ProvidesClass{\aabasename}[\RCSRawDate]}{%
  \ProvidesPackage{\aabasename}[\RCSRawDate]}


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

\newboolean{boxed}


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

\DeclareOption{norsk}{%
  \def\codename{Kode}
  \def\listcodename{Kode}
  \def\algorithmname{Algoritme}
  \def\theoremname{Teorem}
  \def\examplename{Eksempel}
  \def\definitionname{Definisjon}
  \def\proofname{Bevis}
  \def\commentname{Kommentar}}
\DeclareOption{english}{%
  \def\codename{Code}
  \def\listcodename{Code}
  \def\algorithmname{Algorithm}
  \def\theoremname{Theorem}
  \def\examplename{Example}
  \def\definitionname{Definition}
  \def\proofname{Proof}
  \def\commentname{Comment}}

\DeclareOption{ruled}{%
  \setboolean{boxed}{false}}
\DeclareOption{boxed}{%
  \setboolean{boxed}{true}}


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

\ExecuteOptions{norsk,ruled}
\ProcessOptions


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

\RequirePackage{graphics}
\RequirePackage{latexsym}


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

% Modify theorem (see aaruled float style, and latex.ltx)
\newlength{\the@linewidth}
\newlength{\the@removing}
\newlength{\the@adding}
\def\newtheorem#1{\@ifnextchar[{\@othm{#1}}{\@nthm{#1}}}
\def\@begintheorem#1#2{%
  \setlength{\the@linewidth}{\linewidth}%
  \setlength{\the@removing}{\linewidth}%
  \addtolength{\the@removing}{\marginparsep}%
  \setlength{\the@adding}{\marginparwidth}%
  \addtolength{\the@adding}{\marginparsep}%
  \par
  \vspace{1ex}
  \trivlist
  \item[\hskip \labelsep{\sffamily \bfseries #1\ #2}]\ 
    \marginpar[{%
      \makebox[0pt][l]{\hspace*{\the@adding}\raisebox{2.2ex}{%
          \rule{\the@linewidth}{0.4pt}}}%
      }]{%
      \makebox[0pt][l]{\hspace*{-\the@removing}\raisebox{2.2ex}{%
          \rule{\the@linewidth}{0.4pt}}}%
      }}
\def\@opargbegintheorem#1#2#3{%
  \setlength{\the@linewidth}{\linewidth}%
  \setlength{\the@removing}{\linewidth}%
  \addtolength{\the@removing}{\marginparsep}%
  \setlength{\the@adding}{\marginparwidth}%
  \addtolength{\the@adding}{\marginparsep}%
  \par
  \vspace{1ex}
  \trivlist
  \item[\hskip \labelsep{\sffamily \bfseries #1\ #2\ (#3)}]\ 
    \marginpar[{%
      \makebox[0pt][l]{\hspace*{\the@adding}\raisebox{2.2ex}{%
          \rule{\the@linewidth}{0.4pt}}}%
      }]{%
      \makebox[0pt][l]{\hspace*{-\the@removing}\raisebox{2.2ex}{%
          \rule{\the@linewidth}{0.4pt}}}%
      }}
\def\@endtheorem{%
%  \makebox[0pt]{\phantom{g}}%
  \vspace{2pt}\hrule\endtrivlist\vspace{1ex}\par}
\def\endtheo{\hspace*{\fill}\raisebox{-1pt}{\(\Box\)}}


% Some new theorems (and such)
\@ifundefined{thechapter}{%
  \newtheorem{theorem}{\theoremname}}{%
  \newtheorem{theorem}{\theoremname}[chapter]}
\@ifundefined{thechapter}{%
  \newtheorem{algorithm}{\algorithmname}}{%
  \newtheorem{algorithm}{\algorithmname}[chapter]}
\@ifundefined{thechapter}{%
  \newtheorem{example}{\examplename}}{%
  \newtheorem{example}{\examplename}[chapter]}
\@ifundefined{thechapter}{%
  \newtheorem{definition}{\definitionname}}{%
  \newtheorem{definition}{\definitionname}[chapter]}


% Proofs (and such)
\newcommand{\newproof}[2]{\newenvironment{#1}{\trivlist
  \item[\hskip \labelsep{\sffamily \bfseries #2}]\ }{%
    \endtheo\endtrivlist}}

\newcommand{\newnproof}[2]{%
  \@ifundefined{thechapter}{%
    \newcounter{#1}}{%
    \newcounter{#1}[chapter]}%
  \newenvironment{#1}{%
    \refstepcounter{#1}%
    \trivlist
    \item[\hskip \labelsep{\sffamily \bfseries #2\ \arabic{#1}}]\ }{%
      \endtheo\endtrivlist}}

% A generic proof-like environment, with the name as an argument
\newenvironment{genproof}[1]{\trivlist
  \item[\hskip \labelsep{\sffamily \bfseries #1}]\ }{%
  \endtheo\endtrivlist}
  
% Some new proofs
\newproof{proof}{\proofname}
\newproof{comment}{\commentname}
