% -----------------------------------------------------------------------------
% My document style file, for use with LaTeX
% -----------------------------------------------------------------------------
% REVISION HISTORY
% v3.00 2002-05-06  Adrian F. Clark <alien@essex.ac.uk>
%       Revised layout a little.
% v3.01 2002-06-18  Adrian F. Clark <alien@essex.ac.uk>
%       Added \email{} definition.
% v3.02 2002-08-27  Adrian F. Clark <alien@essex.ac.uk>
%       Changed test for foiltex to be for seminar class; added definitions
%       and set-up code for presentations displayed via data projector.
% v3.03 2002-09-20  Adrian F. Clark <alien@essex.ac.uk>
%       Moved definitions around a bit to handle some weird cases and did some
%       general tidying up.
% v3.04 2003-09-23  Adrian F. Clark <alien@essex.ac.uk>
%       Fixed bug in \alienmaketitlenodate with used in two-column mode.
%       v3.05 2005-07-27
%       Added \Secref etc.
% v3.06 2005-09-07  Adrian F. Clark <alien@essex.ac.uk>
%       Added support for lagraphic.
% v3.07 2005-12-19  Adrian F. Clark <alien@essex.ac.uk>
%       Improved definition of \|...|.
% v3.08 2006-11-08  Adrian F. Clark <alien@essex.ac.uk>
%       Included colordvi all the time, not optionally.
% v3.09 2007-09-25  Adrian F. Clark <alien@essex.ac.uk>
%       ESE letterhead -> CES letterhead.
%       Make \alienletterhead etc., i.e. all-lowercase versions of commands.
% -----------------------------------------------------------------------------
% Copyright 1997-2005 Adrian F. Clark <alien@essex.ac.uk>
% -----------------------------------------------------------------------------

% Preliminary boilerplate.

\def\fileversion{3.06}
\def\filedate{2005/09/07}

\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{alien}%
[\filedate\space Adrian F Clark's personal package. v\fileversion]


% Other style files.

\RequirePackage{dates}
\RequirePackage{xspace}
\RequirePackage{xcomment}
\RequirePackage{colordvi}
\newxcomment{lagraphic}


% -----------------------------------------------------------------------------
% The University of Essex logo
% -----------------------------------------------------------------------------

\def\@gap#1{\vrule height 0pt width #1 depth 0pt\relax}
\def\@slug#1{\vrule height #1 width #1 depth 0pt\relax}

\def\Essex@Logo#1{{\vbox{\baselineskip=#1
    \hbox{\@gap{#1}\@slug{#1}}
    \hbox{\@slug{#1}}
    \hbox{\@gap{#1}\@slug{#1}}
    \hbox{\@slug{#1}}
    \hbox{\@gap{#1}\@slug{#1}}}}}

\def\Essexlogo{\Essex@Logo{7mm}}


% -----------------------------------------------------------------------------
% Letterheads for use with my own letter definitions
% -----------------------------------------------------------------------------

% Letterheads for use at home (three variants).

\def\homeletterhead{%
  \gdef\LETTERgap{0in}
  \gdef\LETTERauthor{}
  \gdef\letterhead{%
    \begin{center}
      \Green{Christine and Adrian Clark\\
        2 Orchard Close $\bullet$ Elmstead Market $\bullet$ Essex
        $\bullet$ CO7 7AS $\bullet$ UK\\
        Tel: +44 1206 823400 $\bullet$ Email: \texttt{\{cc,alien\}@essex.ac.uk}
      \end{center}
      \vspace{5pt}
      \hrule}
    \vspace{5pt}
    \begin{flushright}
      \@date
    \end{flushright}\vspace{15pt}
    \noindent\thispagestyle{empty}\ignorespaces}}

\def\Alienhomeletterhead{%
  \gdef\LETTERgap{-0.5in}
  \gdef\LETTERauthor{Dr.~Adrian F. Clark}
  \gdef\letterhead{\vspace*{-\topskip}
    \vspace{-\headheight}
    \vspace{-\headsep}
    \begin{center}
      \Green{Adrian F. Clark\\
        2 Orchard Close $\bullet$ Elmstead Market $\bullet$ Essex
        $\bullet$ CO7 7AS $\bullet$ UK\\
        Tel: +44 1206 823400 $\bullet$ Email: \texttt{alien@essex.ac.uk}
      \end{center}
      \vspace{5pt}
      \hrule}
    \vspace{5pt}
    \begin{flushright}
      \@date
    \end{flushright}\vspace{15pt}
    \noindent\thispagestyle{empty}\ignorespaces}}

\def\Chrishomeletterhead{%
  \gdef\LETTERgap{-0.5in}
  \gdef\LETTERauthor{Dr.~Christine Clark}
  \gdef\letterhead{\vspace*{-\topskip}
  \vspace{-\headheight}
  \vspace{-\headsep}
  \begin{center}
    \Green{Christine Clark\\
    2 Orchard Close $\bullet$ Elmstead Market $\bullet$ Essex
    $\bullet$ CO7 7AS $\bullet$ UK\\
    Tel: +44 1206 823400 $\bullet$ Email: \texttt{cc@essex.ac.uk}
  \end{center}
  \vspace{5pt}
  \hrule}
  \vspace{5pt}
  \begin{flushright}
    \@date
  \end{flushright}
  \noindent\thispagestyle{empty}\ignorespaces}}


% A letterhead for work and a variation on it for using pukka stationery.

\def\AlienCESletterhead{%
  \gdef\LETTERgap{-0.5in}
  \gdef\LETTERauthor{Dr.~Adrian F.~Clark}
  \gdef\letterhead{\hbox to \textwidth{\Essexlogo\hss\small
      \tabcolsep=0pt
      \textsf{\begin{tabular}[b]{lr}
        \multicolumn2l{\Huge\textbf{University of Essex}}\\*[10pt]
        \multicolumn2l{\textbf{Department of Computing and Electronic Systems}}\\
        Wivenhoe Park\quad Colchester & CO4 3SQ\quad United Kingdom\\*[10pt]
        Dr.~Adrian F. Clark & Email \texttt{alien@essex.ac.uk}\\
        Telephone +44 1206 872432 & Facsimile +44 1206 872900\\
        \multicolumn2l{World-Wide Web\quad \texttt{http://esewww.essex.ac.uk/\~{}alien/}}\\
      \end{tabular}}}\par
  \vspace{5pt}
  \begin{flushright}
    \@date
  \end{flushright}
  \noindent\thispagestyle{empty}\ignorespaces}}


\def\noESEletterhead{\gdef\LETTERgap{-0.5in}
  \gdef\LETTERauthor{Dr.~Adrian F.~Clark}
  \gdef\letterhead{\vglue 2.5in}}


% A BMVA letterhead.

\def\AlienBMVAletterhead{%
  \gdef\LETTERgap{-0.5in}
  \gdef\LETTERauthor{Dr.~Adrian F.~Clark}
  \gdef\letterhead{\noindent\Blue{\BMVAlogo}\\*[10pt]
    \begin{flushright}
      \tabcolsep=0pt\small
      \textsf{\begin{tabular}[b]{lr}
        \multicolumn2l{\Huge\textbf{University of Essex}}\\*[5pt]
        \multicolumn2l{\textbf{Department of Computing and Electronic Systems}}\\
        Wivenhoe Park\quad Colchester & CO4 3SQ\quad United Kingdom\\*[5pt]
        Dr.~Adrian F. Clark & Email \texttt{alien@essex.ac.uk}\\
        Telephone +44 1206 872432 & Facsimile +44 1206 872900\\
        \multicolumn2l{World-Wide Web\quad \texttt{http://esewww.essex.ac.uk/\~{}alien/}}\\
      \end{tabular}}
  \end{flushright}\par
  \vspace{5pt}
  \begin{flushright}
    \@date
  \end{flushright}
  \noindent\thispagestyle{empty}\ignorespaces}}

% Use a work letterhead by default.

\AlienCESletterhead

% Define all-lowercase alternatives to the letterheads

\def\alienbmvaletterhead{\AlienBMVAletterhead}
\def\aliencesletterhead{\AlienCESletterhead}
\def\alienhomeletterhead{\Alienhomeletterhead}
\def\chrishomeletterhead{\Chrishomeletterhead}
\def\noeseletterhead{\noESEletterhead}

% -----------------------------------------------------------------------------
% A letter environment, emulating some features of the standard LaTeX one
% -----------------------------------------------------------------------------
% This is invoked in a slightly different way to the standard LaTeX one as the
% name and address of the recipient are given in separate arguments:
%
%   \begin{letter}{name}{address}
%   \opening{Dear Fred,}
%   \closing{Yours hatefully,}
%   \end{letter}

\def\letter#1#2{\newpage
  \gdef\@toname{#1}
  \setcounter{page}{1}
  \vglue \LETTERgap\relax
  \vglue -\headsep  \vglue -\headheight
  \vglue -\topmargin  \vglue -\parskip
  \letterhead
  \vspace{30pt}
  \noindent\begingroup \tabcolsep=0pt\relax
  \begin{tabular}{l}
    \textbf{#1}\\
    #2
  \end{tabular}\endgroup\par
  \thispagestyle{empty}
  \par\bigskip}

\def\endletter{}

\def\opening#1{\noindent#1\par\smallskip}

\def\closing#1{\par\vspace{0.5in}\leavevmode\hskip3in
  \begin{tabular}{l}
    #1\\*[0.5in]
    \LETTERauthor
  \end{tabular}}


% -----------------------------------------------------------------------------
% A memo environment
% -----------------------------------------------------------------------------
% This mirrors the letter environment and is used as follows:
%   \begin{memo}
%     \from{Your master}
%     \to{His slaves}
%     \cc{Other people}
%     \subject{Your work...}
%   \end{memo}
%   ...is not hard enough.

\newenvironment{memo}{\newpage
  \vspace*{-\topskip} \vspace{-\headheight} \vspace{-\headsep}
  \setcounter{page}{1}
  \def\to##1{\bf To:& ##1\\}
  \def\from##1{\bf From:& ##1\\}
  \def\cc##1{\bf Cc:& ##1\\}
  \def\subject##1{\bf Subject:& ##1\\}
  \hrule
  \noindent \begin{tabular}{|lp{\the\textwidth}}
    \begin{tabular}[c]{l}
      \tabcolsep=0pt \Essex@Logo{4mm}
    \end{tabular}
      & \huge\textsf{University of Essex}\\*[12pt]
    \multicolumn2{|c}{\Large MEMORANDUM}\\*[12pt]}
  {\bf Date:& \@date\\*[5pt]
  \end{tabular}
  \hrule\bigskip}

% -----------------------------------------------------------------------------
% Modifications to specific kinds of documents.  Alas, TeX makes it easy to
% test for something being undefined, but difficult to test for something
% being defined.  Hence the rather convoluted logic.
% -----------------------------------------------------------------------------

\ifx \undefined \chapter
\ifx \undefined \slide

% -----------------------------------------------------------------------------
% Unknown style, so assume `article'
% -----------------------------------------------------------------------------

% Alternatives to \maketitle, which sets in ragged-right sans.
% First, the title and author with date.

\def\alienmaketitle{\par
 \begingroup
   \def\thefootnote{\fnsymbol{footnote}}%
   \def\@makefnmark{\hbox
       to\z@{$\m@th^{\@thefnmark}$\hss}}%
   \if@twocolumn
     \twocolumn[\alien@maketitle]%
     \else \newpage
     \global\@topnum\z@
     \alien@maketitle \fi\thispagestyle{plain}\@thanks
 \endgroup
 \setcounter{footnote}{0}%
 \let\maketitle\relax
 \let\alien@maketitle\relax
 \gdef\@thanks{}\gdef\@author{}\gdef\@title{}\let\thanks\relax}

\def\alien@maketitle{\newpage
 \begin{raggedright}%
  {\LARGE\bf\sf \@title \par}%
  \vskip 1.5em
  {\large\sf \lineskip .5em
   \@author\par}%
  \vskip 1em
  {\large\sf \@date}
 \end{raggedright}%
 \vskip 1.5em}


% Next, the title and author without date.

\def\alienmaketitlenodate{\par
 \begingroup
   \def\thefootnote{\fnsymbol{footnote}}%
   \def\@makefnmark{\hbox
       to\z@{$\m@th^{\@thefnmark}$\hss}}%
   \if@twocolumn
     \twocolumn[\alien@maketitlenodate]%
     \else \newpage
     \global\@topnum\z@
     \alien@maketitlenodate \fi\thispagestyle{plain}\@thanks
 \endgroup
 \setcounter{footnote}{0}%
 \let\maketitle\relax
 \let\alien@maketitlenodate\relax
 \gdef\@thanks{}\gdef\@author{}\gdef\@title{}\let\thanks\relax}

\def\alien@maketitlenodate{\newpage
 \begin{raggedright}%
  {\LARGE\bf\sf \@title \par}%
  \vskip 1.5em
  {\large\sf \lineskip .5em
   \@author\par}%
 \end{raggedright}%
 \vskip 1.5em}


% Set section headings ragged-right.

\def\section{\@startsection {section}{1}{\z@}{-3.5ex plus-1ex minus
    -.2ex}{2.3ex plus.2ex}{\reset@font\Large\bf\raggedright}}
\def\subsection{\@startsection{subsection}{2}{\z@}{-3.25ex plus-1ex
     minus-.2ex}{1.5ex plus.2ex}{\reset@font\large\bf\raggedright}}
\def\subsubsection{\@startsection{subsubsection}{3}{\z@}{-3.25ex plus
     -1ex minus-.2ex}{1.5ex plus.2ex}{\reset@font\normalsize\bf\raggedright}}


% Modify \section's table-of-contents macro to insert leaders.

\def\dotfil{\cleaders\hbox{$\m@th \mkern4.5mu.\mkern4.5mu$}\hfil\kern\z@}

\def\l@section#1#2{\addpenalty{\@secpenalty}  % good place for page break
   \addvspace{1.0em plus 1pt}                 % space above toc entry
   \@tempdima 1.5em                           % width of section no. box
   \begingroup
     \parindent \z@ \rightskip \@pnumwidth
     \parfillskip -\@pnumwidth
     \bf \leavevmode                          %  to enter horizontal mode
     #1\dotfil \hbox to\@pnumwidth{\hss #2}\par
   \endgroup}

\else
% -----------------------------------------------------------------------------
% 'slide' is defined, so assume we're using the seminar style for pdfLaTeX
% ----------------------------------------------------------------------------

\RequirePackage{hyperref}
\RequirePackage{graphicx}
\RequirePackage{fixseminar}
\RequirePackage{pdfscreen}

\newenvironment{Slide}{\begin{slide}[10in,7in]}{\end{slide}}

\newcommand{\heading}[1]{\noindent\textcolor{red}{\begin{LARGE}%
        \textbf{#1}\end{LARGE}\\*[-7pt]\hrule}\par\bigskip}
\def\sliderunninghead#1{\gdef\alien@sliderunninghead{#1}}
\def\alien@sliderunninghead{}

\newpagestyle{vasesem}{}{%
  \begin{minipage}[c]{0.15\textwidth}
    ~\includegraphics[height=3\baselineskip]{/home/alien/environment/tex/uofe-logo}
  \end{minipage}
  \hfil
  \begin{minipage}[c]{0.6\textwidth}
    \begin{center}
      \emph{\alien@sliderunninghead}\\
      \thepage
    \end{center}
  \end{minipage}
  \hfil
  \begin{minipage}[c]{0.15\textwidth}
    \hfill
    \includegraphics[height=3\baselineskip]{/home/alien/environment/tex/vase-logo}~
  \end{minipage}}

\hypersetup{colorlinks=false,pdfborder=0 0 0,pdfpagemode=none}

\centerslidesfalse
\slideframe{none}
\slidepagestyle{vasesem}

\renewcommand{\slidetopmargin}{0pt}
\renewcommand{\slidebottommargin}{4\baselineskip}
\renewcommand{\slideleftmargin}{0pt}
\renewcommand{\sliderightmargin}{0pt}

\fi
\else
% -----------------------------------------------------------------------------
% Report or book style -- probably the former
% -----------------------------------------------------------------------------

% Set section headings ragged-right.

\def\section{\@startsection {section}{1}{\z@}{-3.5ex plus -1ex minus 
 -.2ex}{2.3ex plus .2ex}{\Large\bf\raggedright}}
\def\subsection{\@startsection{subsection}{2}{\z@}{-3.25ex plus -1ex minus 
 -.2ex}{1.5ex plus .2ex}{\large\bf\raggedright}}
\def\subsubsection{\@startsection{subsubsection}{3}{\z@}{-3.25ex plus
 -1ex minus -.2ex}{1.5ex plus .2ex}{\normalsize\bf\raggedright}}

\fi

% -----------------------------------------------------------------------------
% Simple command and environment definitions
% -----------------------------------------------------------------------------

% Commands for cross-referencing other parts of the document.  Those
% with a lower-case initial letter are intended for use in the middle
% of a sentence while those with an upper-case initial letter are when
% a cross-reference starts a sentence.

\def\appref#1{Appendix~\ref{#1}}
\def\chapref#1{Chapter~\ref{#1}}
\def\eqnref#1{(\ref{#1})}
\def\figref#1{Figure~\ref{#1}}
\def\pageref#1{p\ref{#1}}
\def\secref#1{Section~\ref{#1}}
\def\tabref#1{Table~\ref{#1}}

\def\Appref#1{Appendix~\ref{#1}}
\def\Chapref#1{Chapter~\ref{#1}}
\def\Eqnref#1{(\ref{#1})}
\def\Figref#1{Figure~\ref{#1}}
\def\Pageref#1{Page~\ref{#1}}
\def\Secref#1{Section~\ref{#1}}
\def\Tabref#1{Table~\ref{#1}}

% Macros for foreign words and abbreviations.

\def\foreign{\emph}
\def\etc{\foreign{etc.}}                        % etc.
\def\eg{\foreign{e.g.~}\ignorespaces}           % e.g.
\def\egc{\foreign{e.g.,~}\ignorespaces}         % e.g.,
\def\ie{\foreign{i.e.~}\ignorespaces}           % i.e.
\def\iec{\foreign{i.e.,~}\ignorespaces}         % i.e.,

% Useful mnemonics.

\def\order{\sim}
\def\role{r\^ole}

% A simple environment for setting off detail or remarks.

\newenvironment{aside}{\begin{quote}\small}{\end{quote}}


% -----------------------------------------------------------------------------
% More complex commands, involving non-standard delimiters.
% -----------------------------------------------------------------------------

% Set the argument in teletype font.

\def\|#1|{\texttt{#1}}

% Set the argument in angle brackets.

\def\<#1>{$\langle$#1$\rangle$}

% Definition of an acronym that gives full expansion when first invoked:
%   \acronym{\tla}{TLA}{three-letter acronym}

\def\acronym#1#2#3{\def#1{#3 (#2)\gdef#1{#2}}}

% Output a marginal note, usually to remind the author to do something.

\def\NB#1{\marginpar{\it\raggedright#1}}

% A command for including RCS or CVS information; invoke as
%   \rcs$Revision:$    in the preamble to define \rcsRevision, etc.

\def\rcs$#1: #2 ${\expandafter\gdef\csname rcs#1\endcsname{\mbox{#2}}}

% Macros for inserting links into documents, for use with pdfLaTeX or
% for conversion to HTML.  The fundamental macro is \href, which is
% defined if the hyperref style is loaded.  So if that macro isn't
% defined, substitute something that does nothing.  The other macros
% are then defined in terms of \href.

\ifx\undefined\href
\def\href#1#2{#2}
\fi

\def\email#1{\<\href{mailto:#1}{\texttt{#1}}>}
\def\file#1{\href{file:#1}{\texttt{#1}}}
\ifx\undefined\url
\def\url#1{\href{#1}{\texttt{#1}}}
\fi

% -----------------------------------------------------------------------------
% Most things I write include computer stuff somewhere, and I use lots
% of underscores in my variable names.  So change the definition of `_'
% to act as text outside maths mode.
% -----------------------------------------------------------------------------

\catcode`\_=\active
\def_{\ifmmode \sb \else \leavevmode \kern.06em \vbox{\hrule width.3em}\fi}

% -----------------------------------------------------------------------------
% Likewise, a pair of macros for producing verbatim listings of files:
% \listing (with numbered lines) and \verbatimfile (unnumbered lines),
% with the listings produced in \verbatimfont.
% -----------------------------------------------------------------------------

%  Note that the precise layout of line breaks in the following is vital!

\def\verbatimfont{\tt}

\def\verbatimfile#1{\begingroup \@verbatim \frenchspacing \@vobeyspaces
   \verbatimfont \input#1 \endgroup}

\newcounter{a@lineno}

\def\listing#1{\setcounter{a@lineno}{0}%
   \begingroup \@verbatim \frenchspacing \@vobeyspaces \parindent=20pt
   \everypar{\stepcounter{a@lineno}\llap{\thea@lineno:\ \ }}%
   \verbatimfont \input#1
   \endgroup}

% -----------------------------------------------------------------------------
% End of alien.sty
% -----------------------------------------------------------------------------
\endinput
