%------------------------------------------------------------------------------
% B M V A a n n a l s . c l s   --   LaTeX2e class for "Annals of the BMVA"
%------------------------------------------------------------------------------
% REVISION HISTORY
% 0.00 2007-03-29  Adrian F. Clark <alien/at/essex.ac.uk>
%      Original version.
% 0.01 2007-05-01  Adrian F. Clark <alien/at/essex.ac.uk>
%      Increase \headsep and tweak headline following comments from Roy Davies.
%------------------------------------------------------------------------------
% Copyright 2007 Adrian F. Clark <alien/at/essex.ac.uk>.  All rights reserved.
%------------------------------------------------------------------------------

% Boilerplate.

\def\fileversion{0.01}
\def\filedate{2007/05/01}

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{bmvaannals}[\filedate\space Annals of the BMVA. v\fileversion]

% We're based on the article class.

\LoadClass[a4paper,11pt,twoside]{article}

% Things we need or expect the author to use.  The hyperref package takes care
% of most of the live cross-referencing within the document, and the vast
% majority of vision papers have included diagrams or images.  The hyperref
% package also makes it possible for the headline to contain a link to the
% master versions of papers on the Annals website.

\RequirePackage{hyperref}
\RequirePackage{graphicx,subfigure}

% Set up the fonts.

\RequirePackage[T1]{fontenc}
\RequirePackage{mathpazo,helvet,courier}

% The page layout is designed for printing onto A4 paper.

\advance\headsep 5pt
\RequirePackage{a4wide}

% The following user-callable macro requires as arguments:
%   -- the volume number (the year of publication)
%   -- the paper number within that year
%   -- the paper's filename relative to the top of the Annals hierarchy
%      and without an extension (filetype)
% e.g. \papernumber{2007}{2}{2007/2007-0002}.  This probably has to be
% done by the editor, or by the author in discussion with the editor.

\def\papernumber#1#2#3{\gdef\BMVA@year{#1}\gdef\BMVA@number{#2}%
  \gdef\BMVA@url{http://www.bmva.ac.uk/annals/#1/#3.pdf}}

% Email addresses are enclosed in angle brackets.  (The \<...> macro
% can also be used independently, though it works only outside maths mode.)

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

% A macro for producing the title, which also puts the copyright notice
% in an unnumbered footnote on the first page.  The \maketitle macro
% was derived from a (probably very old) version of the article class
% and is probably not as elegant as it could be.

\def\maketitle{\newpage \global\@topnum\z@%
  \vglue 5pt%
  \begin{raggedright}%
    {\Huge\bfseries\sffamily \@title\par}%
    \vskip 1.5em%
    {\large\sffamily \lineskip .5em%
      \@author\par}%
  \end{raggedright}%
  \vskip\baselineskip\hrule\vskip2\baselineskip
  \def\BMVA@blfootnote{\xdef\@thefnmark{}\@footnotetext}%
  \BMVA@blfootnote{\null\hspace{-1.9em}\copyright{} \BMVA@year.
    The copyright of this document resides with its authors.\\
    It may be distributed unchanged freely in print or electronic forms.}%
  \setcounter{footnote}{0}%
  \thispagestyle{bmvaannals}\pagestyle{bmvaannals}%
  \let\maketitle\relax}

% The running head contains the author(s) and paper title, perhaps
% abbreviated so that the overall length of the headline is not too long.

\def\runninghead#1#2{\gdef\BMVA@author{\MakeUppercase{#1}}%
  \gdef\BMVA@title{\MakeUppercase{#2}}}

% A macro that saves out the number of the last page of the document
% in the macro \BMVA@LastPage, for use in the headline.

\AtEndDocument{\immediate\write\@auxout{\gdef\string\BMVA@LastPage{\thepage}}}
\def\BMVA@LastPage{??}

% The headline itself, which comprises two lines of text:
%   -- The first contains the paper's authors and title and is a
%      hypertext reference to the master version on the Annals website.
%   -- The second gives citation information, with the journal name
%      being a hypertext reference to the Annals website.
% This has to be set explicitly by the author (or editor) via the \papernumber
% macro (see above).

\newcommand*{\ps@bmvaannals}{%
  \renewcommand*{\@oddhead}{\begin{minipage}{\textwidth}\small
      \begin{tabular*}{\textwidth}{@{}l@{\extracolsep{\fill}}r@{}}
        \textsl{\href{\BMVA@url}{\BMVA@author: \BMVA@title}}
          & \bfseries\thepage\\
            \href{http://www.bmva.ac.uk/annals/}{Annals of the BMVA}
        Vol.~\BMVA@year, No.~\BMVA@number, pp\,1--\BMVA@LastPage{}
          (\BMVA@year) &\\
      \end{tabular*}\par\smallskip\hrule
    \end{minipage}} 
  \renewcommand*{\@evenhead}{%
    \begin{minipage}{\textwidth}\small
      \begin{tabular*}{\textwidth}{@{}l@{\extracolsep{\fill}}r@{}}
        \thepage &\textsl{\href{\BMVA@url}{\BMVA@author:
            \BMVA@title}} \\
        & \href{http://www.bmva.ac.uk/annals/}{Annals of the BMVA}
        Vol.~\BMVA@year, No.~\BMVA@number, pp\,1--\BMVA@LastPage{}
        (\BMVA@year) \\
      \end{tabular*}\par\smallskip\hrule
    \end{minipage}}
  \renewcommand*{\@oddfoot}{}%
  \renewcommand*{\@evenfoot}{}%
}

% Ensure section titles are set ragged-right.   These definitions are
% adapted from those in article.cls v1.4f of 2004/02/16.

\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries\flushleft}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\large\bfseries\flushleft}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\normalsize\bfseries\flushleft}}

% Footnote rules go right across the page (definition adapted from
% article.cls v1.4f of 2004/02/16).

\renewcommand\footnoterule{\kern-3\p@
  \hrule\@width\columnwidth
  \kern2.6\p@}

% Bibliography stuff.

\bibliographystyle{plainnat}
\RequirePackage[square,comma]{natbib}

%------------------------------------------------------------------------------
% End of BMVAannals.cls
%------------------------------------------------------------------------------
