\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sep2ebrad}[1996/12/01 v0.1 sepreport rewritten in LaTeX2e]
\RequirePackage{ifthen}

\RequirePackage[wavy]{vector}% for \st
\RequirePackage{comment}

\newboolean{@report}
\newcommand{\@class}{}

\DeclareOption{alone}{%
\renewcommand{\@class}{article}\setboolean{@report}{true}}

\DeclareOption{report}{%
\renewcommand{\@class}{book}\setboolean{@report}{true}}

\DeclareOption{book}{%
\renewcommand{\@class}{book}\setboolean{@report}{false}}

\DeclareOption{thesis}{%
\renewcommand{\@class}{report}\setboolean{@report}{false}}
\DeclareOption{thesistwoside}{%
\renewcommand{\@class}{report}\setboolean{@report}{false}%
\PassOptionsToClass{twoside}{report}}

\DeclareOption{thesis-report}{%
\renewcommand{\@class}{report}\setboolean{@report}{true}%
\PassOptionsToClass{twoside}{report}}

\newboolean{@psfonts}
\DeclareOption{psfonts}{\setboolean{@psfonts}{true}}
\DeclareOption{cmfonts}{\setboolean{@psfonts}{false}}

\newboolean{@minimal}
\DeclareOption{minimal}{\setboolean{@minimal}{true}}
\DeclareOption{maximal}{\setboolean{@minimal}{false}}

\newboolean{@web}
\DeclareOption{web}{\setboolean{@web}{true}}
\DeclareOption{noweb}{\setboolean{@web}{false}}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\@class}}

\ExecuteOptions{alone,maximal,psfonts,noweb}
\ProcessOptions*

\LoadClass{\@class}

\ifthenelse{\equal{\@class}{report}}{}{%
\ifthenelse{\equal{\@class}{book}}
{\RequirePackage{chapterbib}}
{\RequirePackage[rootbib]{chapterbib}}}

\ifthenelse{\boolean{@psfonts}}{%
%\RequirePackage[LY1]{fontenc}
%\RequirePackage[LY1,mtbold]{mathtime}
%\RequirePackage{times}
\RequirePackage{pslatex}% TimesRoman fonts
\RequirePackage{mt11p}
%\RequirePackage{pslatex}
}{}

\ifthenelse{\boolean{@web}}{%
\RequirePackage[pdftex,tight]{web}
\setlength{\textwidth}{4.6in}
\hypersetup{pdfpagescrop=53 436 421 704}
\def\web@chapter{Chapter}
%
% Routines for typesetting toc entries - copied from web.sty and hacked
%
\def\webtableofcontents{\begingroup
%
% Sample line from .aux
%   \contentsline {section}{\numberline {1}Introduction}{4}{section.1}
%   \contentsline {section}{\numberline {}References}{56}{section*.1}
%                                   #1                 #2   #3
\parindent20pt
\def\par{\endgraf\leftskip=0pt}%
%\def\contentsname{Table of Contents}
\def\numberline##1{\llap{##1\enspace}}%
\def\contentsline##1##2##3##4{\csname web@##1\endcsname{##2}{##3}{##4}}%
\def\web@parse##1##2##3\\{\def\web@title{##3}\def\numberline{##2}}%
\def\web@chapter##1##2##3{\web@parse##1\\\par\mbox{}\textbf{%
  \ifx\numberline\empty
    \hyperlink{##3}{\web@title}%
  \else
    \llap{\hyperlink{##3}{\numberline.}\space}\web@title
  \fi}%
  \endgraf
  }
\def\web@section##1##2##3{\web@parse##1\\\par\penalty-50 \hspace{20pt}\mbox{}%
    \textbf{\llap{\hbox to20pt{\hyperlink{##3}{\numberline.}\space\hfil}}\web@title}\endgraf}%
\def\web@subsection##1##2##3{\web@parse##1\\\def\numberline{\strut$\bullet$}%
   \leftskip40pt\noindent\unskip\mbox{}\penalty-50\hyperlink{##3}{\ \numberline}~\web@title\ }%
\def\web@subsubsection##1##2##3{}%
\@starttoc{toc}
\leftskip40pt
\par\endgroup}
\excludecomment{notforlecture}
}{\includecomment{notforlecture}}

\newcommand{\newslide}{\ifthenelse{\boolean{@web}}{\clearpage}{}}

\ifthenelse{\equal{\@class}{article}}{}{%
\newlength{\toc@width}%
\newcommand{\TOCentry}[3][.]{%
\ifthenelse{\boolean{@report}}
{\setlength{\toc@width}{\textwidth}%
\addtolength{\toc@width}{-6em}%
\noindent\hspace*{4em}%
{\begin{minipage}[b]{\toc@width}
\setlength{\parindent}{-5em}%
\ifthenelse{\equal{#1}{.}}%
{}{\textit {#1}, }%
#2\dotfill\ 
\end{minipage}\hfill#3}\par}{}}{}}

\newboolean{@article}
\newcommand{\sepreport}{\setboolean{@article}{true}}
\newcommand{\shortnote}{\setboolean{@article}{false}}
\ifthenelse{\equal{\@class}{report}}%
{\setboolean{@article}{false}}%
{\setboolean{@article}{true}}

\renewcommand{\baselinestretch}{1.0}

\ifthenelse{\boolean{@minimal}}{}{%
\newcommand{\morespace}{\renewcommand{\baselinestretch}{1.5}}
%\providecommand{\doublespace}{\renewcommand{\baselinestretch}{2.0}}
\newcommand{\nopagenumbers}{\renewcommand{\thepage}{}}}

\ifthenelse{\boolean{@web}}{}{%
\setlength{\textheight}{9in}
\setlength{\textwidth}{6in}
\setlength{\parskip}{1.5ex plus0.1ex minus0.1ex} % should be a *rubber* length
\setlength{\oddsidemargin}{.26in}
\setlength{\evensidemargin}{.26in}
\setlength{\topmargin}{-.51in}
\setlength{\textfloatsep}{30pt plus 3pt minus 6pt}
\setlength{\headsep}{0.5in}

\newcommand{\bold}[1]{\ensuremath{\mathbf{#1}}}

\let\sv\bold
\let\realbold\bold
\newcommand{\st}[1]{\uvec{\realbold{#1}}}}

\ifthenelse{\boolean{@minimal}}{}{%
\newcommand{\ital}[1]{\textit{#1}}}

\newcommand{\@mskip}{\vspace{.3in}}
\newcommand{\@sskip}{\vspace{.2in}}

\newcommand{\sep@rhead}{}
\newcommand{\sep@lhead}{}
\newcommand{\sep@foot}{}
\newcommand{\sep@head}{}
\newcommand{\sep@header}{}

\newcommand{\righthead}[1]{\renewcommand{\sep@rhead}{#1}}
\newcommand{\lefthead}[1]{\renewcommand{\sep@lhead}{#1}}
\newcommand{\footer}[1]{\renewcommand{\sep@foot}{#1}}
\newcommand{\header}[1]{\renewcommand{\sep@head}{#1}}
\newcommand{\SEPheader}[1]{\renewcommand{\sep@header}{#1}}
\newcommand{\REPORT}{}

\ifthenelse{\boolean{@web}}{}{%
\newcommand{\ps@sepreport}{%
\renewcommand{\@oddhead}{%
\sep@foot\hfill\textit{\sep@rhead}\hfill\thepage}
\renewcommand{\@evenhead}{%
\thepage\hfill\textit{\sep@lhead}\hfill\sep@foot}
\renewcommand{\@oddfoot}{}\renewcommand{\@evenfoot}{}}

\newcommand{\ps@sep}{%
\renewcommand{\@oddhead}{%
\makebox[2.5in][l]{\textit{\sep@rhead}}\hfill\thepage\hfill%
\makebox[2.5in][r]{\textit{\sep@lhead}}}%
\renewcommand{\@evenhead}{\@oddhead}%
\renewcommand{\@oddfoot}{\hfill\textit{\sep@foot}\hfill}%
\renewcommand{\@evenfoot}{\@oddfoot}}

\newcommand{\ps@sepone}{%
\renewcommand{\@oddhead}{}%
\renewcommand{\@evenhead}{}%
\renewcommand{\@oddfoot}{\hfill\textit{\sep@foot}\hfill}%
\renewcommand{\@evenfoot}{\@oddfoot}}

\newcommand{\ps@sepbook}{%
\renewcommand{\@oddfoot}{\hfill\textit{\sep@foot}\hfill}%
\renewcommand{\@evenfoot}{\@oddfoot}}
}

\ifthenelse{\boolean{@report}}{%
\newcommand{\ps@septwo}{%
\renewcommand{\@oddfoot}{\hfill\thepage\hfill}%
\renewcommand{\@evenfoot}{\@oddfoot}
\renewcommand{\@oddhead}{%
\footnotesize\textit{\sep@header\sep@head}\hfill\normalsize}%
\renewcommand{\@evenhead}{\@oddhead}}}{%
\newcommand{\ps@septwo}{\ps@sepbook}}

\newcommand{\@emailaddress}{Author has no known email address}
\newcommand{\noemailaddress}{\renewcommand{\@emailaddress}{.}}

%\newcommand{\@keywords}{not available}
\newcommand{\nokeywords}{}%\renewcommand{\@keywords}{.}}

\ifthenelse{\boolean{@web}}{%
\setlength{\headsep}{0pt}%
\pagestyle{empty}\thispagestyle{empty}}{%
\ifthenelse{\boolean{@report}}{%
\pagestyle{sepreport}}{\pagestyle{sepbook}}
\ifthenelse{\equal{\@class}{article}}{%
\pagestyle{sep}\thispagestyle{sepone}}{}

% to make section headings smaller
\let\sep@Large\Large
\let\sep@large\large
\ifthenelse{\boolean{@report}}
{\renewcommand{\Large}{\protect\normalsize\centering}%
 \renewcommand{\large}{\protect\normalsize}}
{\renewcommand{\Large}{\protect\sep@large}}

\newcommand{\email}[1]{\renewcommand{\@emailaddress}{#1}}
\newcommand{\keywords}[1]{}%\renewcommand{\@keywords}{#1}}

\newenvironment{SEP@title}
{\@mskip\begin{minipage}{\textwidth}\bfseries\sep@Large%
\ifthenelse{\boolean{@article}}{\centering}{}}
{\end{minipage}\@sskip}

\ifthenelse{\boolean{@report}}{%
\ifthenelse{\equal{\@class}{report}}{}{%
\renewcommand{\title}[1]{%
\noindent\begin{SEP@title}\setlength{\parindent}{0em}\par%
\ifthenelse{\boolean{@article}}%
{\smallskip #1}{Short Note\@mskip\newline~#1}%
\end{SEP@title}}}}{}

\ifthenelse{\equal{\@class}{article}}
{\newcommand{\chapter}[2][]{\title{#2}}\newcounter{chapter}}{}

\newenvironment{SEP@author}
{\@mskip\begin{minipage}{\textwidth}\itshape\large%
\ifthenelse{\boolean{@article}}{\centering}{}}
{\end{minipage}\@sskip}
%{\ifthenelse{\equal{\@keywords}{.}}%
%{}{\par\@sskip\normalsize\textbf{keywords: }\@keywords}%

%\ifthenelse{\boolean{@report}}{%        
%\ifthenelse{\equal{\@class}{report}}{}{%
%\renewcommand{\author}[1]{%
%\ifthenelse{\equal{\@emailaddress}{.}}%
%{\noindent\begin{SEP@author}#1\end{SEP@author}}
%{\noindent\begin{SEP@author}#1\footnotemark\end{SEP@author}%
%\footnotetext{\textbf{email: }\@emailaddress}}}}}{}


\ifthenelse{\boolean{@report}}{%
\ifthenelse{\equal{\@class}{report}}{}{%
\renewcommand{\author}[1]{%
\ifthenelse{\equal{\@emailaddress}{.}}%
{\noindent\begin{SEP@author}#1\end{SEP@author}}
{\noindent\begin{SEP@author}#1\end{SEP@author}}}}}{}
%\footnotetext{\textbf{email: }\@emailaddress}}}}}{}


% remove numbers from section headings
\let\sep@section\section
\let\sep@subsection\subsection
\let\sep@subsubsection\subsubsection
\ifthenelse{\boolean{@report}}{%
\newcommand{\sepsection}[1]{\sep@section*{#1}}
\renewcommand{\section}[2][]{\sepsection{\MakeUppercase{#2}}}%
\def\subsection{\sep@subsection*}%
\def\subsubsection{\sep@subsubsection*}}{%
\newcommand{\sepsection}[1]{\sep@section{#1}}}
\newcommand{\sephead}[1]{\sepsection{#1}}}

\ifthenelse{\boolean{@minimal}}{}{%
\newcommand{\mhead}[1]{\section{#1}}
\newcommand{\shead}[1]{\subsection{#1}}
\newcommand{\sshead}[1]{\subsubsection{#1}}}

\newcommand{\ssshead}[1]{\smallskip\begin{flushleft}%
\footnotesize\textbf{#1}\end{flushleft}}
\newcommand{\sssshead}[1]{\smallskip\begin{flushleft}%
\scriptsize\textbf{#1}\end{flushleft}}

\newlength{\box@width}
\setlength{\box@width}{\textwidth}
\addtolength{\box@width}{-20pt} 
\setlength{\fboxsep}{10pt}

\newcommand{\boxit}[1]{%
\ifthenelse{\boolean{@web}}{%
\noindent\fcolorbox{blue}{webyellow}{\parbox{\box@width}{#1}}}{%
\noindent\fbox{\parbox{\box@width}{#1}}}}

\newcommand{\ABS}[1]{%
\ifthenelse{\boolean{@web}}{%
\thispagestyle{empty}
\begin{center}
\ifeqforpaper\vspace{\stretch{1}}\fi
\noindent\makebox[\linewidth]{\parbox{\box@width}%
   {\bfseries\ifeqforpaper\Large\else\large\fi\centering\webtitle}}%
\par\ifeqforpaper\vspace{2\baselineskip}\else\bigskip\fi
\noindent\makebox[\linewidth]{\parbox{\box@width}%
   {\bfseries\ifeqforpaper\large\fi\centering\webauthor}}
\optionalpagematter
\par\ifeqforpaper\vspace{\stretch{1}}\else\bigskip\fi
\href{mailto:\webemail}{\webemail}\vfill
\noindent\protect\boxit{%
\noindent\textcolor{blue}{\centerline{\textbf{ABSTRACT}}}%
\medskip#1\medskip}\end{center}\newpage}{%
\ifthenelse{\boolean{@report}\and\boolean{@article}}
{\noindent\protect\boxit{\centerline{\textbf{ABSTRACT}}%
\medskip#1\medskip}}{}}}

%\ifthenelse{\equal{\@class}{report}}{%
%\sepsection{\@title}\bigskip\begin{center}
%\@author, Ph.D.
%\end{center}}{}}} 

\ifthenelse{\boolean{@minimal}}{}{%
\newcommand{\parab}{\par}
\newcommand{\INT}{\section{INTRODUCTION}}
\newcommand{\DIS}{\section{DISCUSSION}}
\newcommand{\CON}{\section{CONCLUSIONS}}
\newcommand{\ACK}{\section{ACKNOWLEDGMENTS}}
\ifthenelse{\boolean{@report}}
{\newcommand{\REF}{\section{REFERENCES}}}
{\newcommand{\REF}{\section*{REFERENCES}}}}

\newcounter{@append}
\newcommand{\append@name}{A}
\newcommand{\appendname}[1]{\renewcommand{\append@name}{#1}}

\ifthenelse{\equal{\@class}{report}}{}{%
\renewcommand{\appendix}{%
\ifthenelse{\equal{\append@name}{A}}{\renewcommand{\append@name}{\Alph{@append}}}{}
\setcounter{equation}{0}\setcounter{figure}{0}%%
\renewcommand{\theequation}{\mbox{\append@name-\arabic{equation}}}%
\renewcommand{\thefigure}{\append@name-\arabic{figure}}\stepcounter{@append}}}

\ifthenelse{\boolean{@minimal}}{}{%
\newcommand{\APPENDIX}[1]{\appendname{#1}\appendix\sepsection{APPENDIX\ #1}}
\newcommand{\APP}{\appendix\sepsection{APPENDIX A}}
\newcommand{\booktoreport}{}
\newcommand{\reporttobook}{}}

\newcommand{\chapter@name}{}
\ifthenelse{\equal{\@class}{book}}
{\newcommand{\@separator}{/}}
{\newcommand{\@separator}{}}

\ifthenelse{\equal{\@class}{article}}{}{%
\newcommand{\SEPpaper}[1]{%
\ifthenelse{\boolean{@report}}{%
\ifthenelse{\equal{\@class}{report}}{}{%
\renewcommand{\@emailaddress}{not available}\sepreport%
%\renewcommand{\@keywords}{not available}%
\setcounter{equation}{0}\setcounter{figure}{0}\setcounter{table}{0}%
\renewcommand{\theequation}{\arabic{equation}}%
\renewcommand{\thefigure}{\arabic{figure}}%
\renewcommand{\thetable}{\arabic{table}}%
\setcounter{@append}{0}\setcounter{table}{0}\setcounter{footnote}{0}}}{}%
\header{, pages \pageref{#1.start}--\pageref{#1.end}}%
\renewcommand{\chapter@name}{#1}}}

%obsolete, backward compatibility
\ifthenelse{\boolean{@minimal}}{}{%
\newfont{\bigbf}{cmbx10 scaled\magstep 3}
\newfont{\bigit}{cmti10 scaled\magstep 2}
\newfont{\bigrm}{cmr10 scaled\magstep 2}}

\newcommand{\SEPcopyr}[1]{\ifthenelse{\boolean{@report}}{
\ \vfill
\author{Copyright \copyright\ #1}
\author{by the Board of Trustees of the Leland Stanford Junior University} 
\author{Stanford, California 94305}
\vfill
\author{Copying permitted for all internal purposes of the Sponsors of \\
Stanford Exploration Project}
\newpage
}{\let\title\chapter}}

\input{seplabel}
\input{sepinput}
\input{sepcite}
\input{sepplot}

\ifthenelse{\equal{\@class}{report}}{
\RequirePackage{suthesis-2e}%
\ifthenelse{\boolean{@report}}{%
\setlength{\oddsidemargin}{0.5in}%
\setlength{\evensidemargin}{0in}}{}
\renewcommand{\copyrightpage}{%
        \null\vfill
        \begin{center}
                \large
                \copyright\ Copyright \@copyrightyear\ by \@author\\
                All Rights Reserved
                \ifthenelse{\boolean{@report}}{
        \vfill
                printed as  Stanford Exploration Project No. \REPORT\\
                by permission of the author
        \vfill
                Copying for all internal purposes of the sponsors \\
                of the Stanford Exploration Project is permitted
                }{}
        \end{center}
        \vfill
\newpage}}{}




