%%% euletr.cls
%%%
%%% Generic style for Edinburgh University letters, following visual
%%% identity style guidelines. This file should be used by an
%%% appropriate departmental style file which defines the addresses,
%%% professors, etc.
%%%
%%% Authors/Maintainers : {ajcd,jtb,mxr}@dcs.ed.ac.uk
%%%
%%% This is a modification of the standard LaTeX ``letter'' style for
%%% the University of Edinburgh's corporate visual identity (sic).  It
%%% should be customised for the department by the installer, to take
%%% into account the departmental information, the method of including
%%% the logo, and the header font selection.  The best way to do this
%%% is to create another class which loads this `standard' one.
%%%
%%% Usage:
%%% Do NOT use the \address macro to set the address; it will be ignored.
%%% There are several macros for user-level customisation. These are:
%%%     \email{address}      Sets the user's email address
%%%     \extn{number}        Sets the new phone extension
%%%     \telex{number}       Sets the telex address
%%%     \href{number}        Sets the department's/user's WWW page URL
%%% If any of these are given an empty argument, the corresponding address
%%% line will be omitted. There is also the macro:
%%%     \code{number} Sets the phone prefix (useful for international
%%%     style)
%%% The macro \crestversion{num} selects the crest version:
%%%   0  -  normal monochrome
%%%   1  -  no lines
%%%   2  -  reversed
%%%   3  -  2 colour
%%%   4  -  full colour
%%%
%%% The commands \ourref{num} and \yourref{num} can be used in the
%%% recipient's address to set up reference numbers for the letter.
%%%
%%% The command \newcc{\name}{intro:} creates a new \cc-like command,
%%% with the text "intro:" at the start.
%%%
%%% The class option [headedpaper] will omit most of the address, and
%%% just fill in the gaps for pre-printed letter paper.
%%%
%%% The class option [onepage] will alter the margins to fit as much
%%% as possible onto the first page. This is useful for letters in
%%% which the signature would otherwise go on the second page on its
%%% own.
%%%
%%% The class option [cm] will use Computer Modern for the appropriate
%%% parts of the address (perpetua is the default).
%%%
%%% AJCD 17/2/93
%%% JTB 06/02/95 - modified for LaTeX2e
%%% MXR 09/09/96 - minor bug fix
%%% MXR 22/01/96 - added \href facility
%%%
%%% $Log: euletr.cls,v $
%%% Revision 1.9  1996/01/22  15:18:30  mxr
%%% Added \href facility
%%%
%%% Revision 1.8  1996/09/09  12:12:12  mxr
%%% Fixed onepage bug.
%%%
%%% Revision 1.7  1996/08/07  16:19:14  jtb
%%% Fixed italic bug.
%%%
%%% Revision 1.6  1996/05/08  12:24:10  jtb
%%% Combined the Mac and Unix versions.
%%%
%%% Revision 1.5  1996/05/07  11:39:08  jtb
%%% Fixed \tt in Email: header (plus other bugs).
%%%
%%% Revision 1.4  1995/11/14  16:00:34  jtb
%%% Layout of address adjusted for new pre-printed paper.
%%%
%%% Revision 1.3  1995/10/02  16:05:57  jtb
%%% Hacked address bit to handle planning units.
%%%
%%% Revision 1.2  1995/09/28  10:49:07  jtb
%%% Renamed to euletr.cls
%%%
%%% Revision 1.1  1995/05/19  13:10:15  da
%%% Initial revision
%%%

% ----------------------------------
%    Identification   
% ----------------------------------

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesClass{euletr}[1996/05/08 Edinburgh University letter style - JTB]

% ----------------------------------
%    Initial code   
% ----------------------------------

\newif\ifheadedpaper
\headedpaperfalse
\newcommand{\euletter@font}{}

\newcommand{\@tenpt}{\euletter@font\fontsize{10}{13pt}\selectfont}
\newcommand{\@ninept}{\euletter@font\fontsize{9}{12.5pt}\selectfont}
\newcommand{\@eightpt}{\euletter@font\fontsize{8}{9pt}\selectfont}
\newcommand{\@sevenpt}{\euletter@font\fontsize{7}{8pt}\selectfont}

\newcommand{\@cmtt}{\fontfamily{cmtt}\selectfont}

\newcommand{\optionwarn}{\ClassWarningNoLine{euletr}{%
        class option '\CurrentOption' ignored}}

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

\DeclareOption{a5paper}{\optionwarn}
\DeclareOption{b5paper}{\optionwarn}
\DeclareOption{letterpaper}{\optionwarn}
\DeclareOption{legalpaper}{\optionwarn}
\DeclareOption{executivepaper}{\optionwarn}
\DeclareOption{landscape}{\optionwarn}

\DeclareOption{parskip}{\input{parskip.clo}}
\DeclareOption{headedpaper}{\headedpapertrue}
\DeclareOption{cm}{\def\euletter@font{\fontfamily{cmr}}}
\DeclareOption{perpetua}{\def\euletter@font{\fontfamily{mpp}}}
\DeclareOption{onepage}{\AtEndOfClass{\addtolength{\textheight}{30mm}%
                                      \addtolength{\footskip}{-30mm}}}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{letter}}

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

% default options
\ExecuteOptions{perpetua,10pt}

% user selected options
\ProcessOptions

% ----------------------------------
%    Package Loading   
% ----------------------------------

\LoadClass[a4paper]{letter}
\RequirePackage{graphics}

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

% JTB - I tried to get rid of this and use the standard a4.sty package
% but the shield kept moving about.  So it seems that we are stuck
% with this junk until someone braver than me looks at it.

% copied and modified from a4.sty
% set up LaTeX parameters for A4 paper (21 x 29.7 cm).

\setlength{\textheight}{29.7 true cm}           % A4 paper length
\addtolength{\textheight}{-86mm}                % margins at top and bottom
\setlength{\textwidth}{21 true cm}              % A4 paper width
\addtolength{\textwidth}{-46 true mm}           % allow for margins

\setlength{\oddsidemargin}{-2.4mm}
\setlength{\evensidemargin}{-2.4mm}

\setlength{\headheight}{0mm}                    % height of heading
\setlength{\headsep}{23mm}                      % space betw heading and text
\addtolength{\headsep}{-\topskip}               % space at top
\setlength{\topmargin}{-2.4mm}                  % space at top
\setlength{\footskip}{35mm}                     % space betw footing and text

%\setlength{\marginparsep}{0mm}                 % 
%\setlength{\marginparwidth}{0mm}                % margin width

% pick up point size of current font - can't use \normalsize?  JTB 

\newlength{\mainsize}
\setlength{\mainsize}{\topskip}

% I don't see why this was done like this because I thought \topskip
% was set to the right thing in the first place - JTB
%\setlength{\mainsize}{1\@ptsize pt}
%\setlength{\topskip}{\mainsize}                        % plain has 10pt

% I haven't set these because I don't know what they are and they seem
% to make no difference - JTB
%\setlength{\maxdepth}{.4\mainsize}             % plain has 4pt
%\setlength{\@maxdepth}{\maxdepth}              % this has to be set as well


\pagestyle{empty}

\let\@texttop\relax

% space between prof's names
\newcommand{\@emspc}{\hspace{.7em}}

\renewcommand{\opening}[1]{%
  \thispagestyle{firstpage}
  {\begin{tabular}[t]{@{}l}
    \ignorespaces\@date\\*[2\normalbaselineskip]
    \ignorespaces\toname \\[0pt]
    \toaddress
    \ifx\@empty\@ourref
    \else
      \\*[\normalbaselineskip] \@ourref\\ 
    \fi
    \ifx\@empty\@yourref
    \else
      \ifx\@empty\@ourref
        \\*[\normalbaselineskip]
      \fi
      \@yourref\\
    \fi
  \end{tabular}\hfill
  \vtop{\vspace{13\normalbaselineskip}}%
  \@ninept
  \begin{tabular}[t]{r@{}}
    \ignorespaces
    \ifheadedpaper \@headedaddress \else \fromaddress \fi
  \end{tabular}
  }%
  \par \vspace{-\parskip}#1 \par
  \vspace{-\parskip} \vspace{\normalbaselineskip} \nobreak
}%

\long\def\closing#1{%
 \par\nobreak\vspace{\normalbaselineskip}
 \stopbreaks
 \noindent
 \parbox{\indentedwidth}{%
   \raggedright
   \ignorespaces #1\\[6\medskipamount]
   \ifx\@empty\fromsig
     \fromname
   \else
     \fromsig
   \fi
   \strut
 }%
 \def\yourref##1{}%
 \def\ourref##1{}%
 \par
}%

\renewcommand{\ps@firstpage}{%
  \renewcommand{\@oddhead}{%
    \ifheadedpaper
    \else
      \hfill
      \vbox to 0mm {\vss
        \hbox to 0pt {\hss \@eushield \hss} \vss}%
    \fi}%
  \renewcommand{\@oddfoot}{%
    \@eightpt
    \vbox to \mainsize {\vss
    \begin{center}%
      \leavevmode 
      \ifheadedpaper
      \else
        \ifx \@empty \@hod 
        \else
          {\@sevenpt HEAD OF DEPARTMENT} \@emspc \@hod
        \fi
      \fi
      \ifheadedpaper
      \else
        \ifx \@empty \@profs 
        \else
          \let\@pspc=\\
          \@for\@prof:=\@profs\do{%
            \@pspc \@prof \let\@pspc\@emspc}
        \fi
      \fi
    \end{center}
    \vss
    }%
  }%   
  \let\@evenhead=\@empty
  \let\@evenfoot=\@empty
}%

%%% Positioning for pre-printed letter paper. Add fields as required.
\newcommand\@headedaddress{%
  \\
  [-\arraystretch\dp\strutbox]
%  \@eightpt\vrule \@width\z@ \@depth\z@ \@height39mm
%  adjustment for new DCS letterhead - 14 November 1995
  \@eightpt\vrule \@width\z@ \@depth\z@ \@height43mm
  \hbox to 28mm{\hfill \@email}
  \\
  [-\arraystretch\dp\strutbox]
  \@eightpt\vrule \@width\z@ \@depth\z@ \@height10mm
  \@extn
}%

% address pattern
\address{%
  \ifx\@empty\@planningunit \@tenpt \@deptname\\*[7.5pt]
  \else\@tenpt \@deptname\\ \@tenpt \@planningunit\\*[7.5pt] \fi
  \@deptaddress\\*[3.5pt]
  \ifx\@empty\@fax \else\@eightpt Fax \@code\ \@fax\\ \fi
  \ifx\@empty\@telex \else\@eightpt Telex \@telex\\ \fi
  \ifx\@empty\@email \else\@eightpt Email \@cmtt \@email\\ \fi
  \ifx\@empty\@phone \else\@eightpt Telephone \@code\ \@phone\\ \fi
  \ifx\@empty\@extn \else\@eightpt or direct dial \@code\ 650 \@extn\\ \fi
  \ifx\@empty\@href \else\@eightpt \@href\\ \fi
}

\renewcommand{\address}[1]{}            % ignore future addresses
\newcommand{\email}[1]{\gdef\@email{#1}}
\newcommand{\extn}[1]{\gdef\@extn{#1}}
\newcommand{\telex}[1]{\gdef\@telex{#1}}
\newcommand{\code}[1]{\gdef\@code{#1}}
\newcommand{\phone}[1]{\gdef\@phone{#1}}
\newcommand{\fax}[1]{\gdef\@fax{#1}}
\newcommand{\href}[1]{\gdef\@href{#1}}

\newcommand{\ourref}[1]{\gdef\@ourref{Our ref #1}}
\newcommand{\yourref}[1]{\gdef\@yourref{Your ref #1}}
\def\@ourref{}                                          % own reference number
\def\@yourref{}                                         % other reference #

\renewcommand{\cc}[1]{%
  \def\@cc{#1}
  \ifx\@empty\@cc
  \else{%
  \par\noindent
  \parbox[t]{\textwidth}{%
    \@hangfrom{\reset@font\rm \ccname: }%
    \ignorespaces #1\strut}\par}
  \fi}
    
\renewcommand{\encl}[1]{%
  \def\@encl{#1}
  \ifx\@empty\@encl
  \else{%
  \par\noindent
  \parbox[t]{\textwidth}{%
    \@hangfrom{\reset@font\rm \enclname: }%
    \ignorespaces #1\strut}\par}
  \fi}

% CC: like lists on enclosures/people/etc.
\newcommand{\newcc}[2]{%
  \newcommand{#1}[1]{%
  \par
  \noindent
  \parbox[t]{\textwidth}{\@hangfrom{\rm #2 }
  \ignorespaces ##1\strut}\par
  }%
}%

%%% Typeset a 30mm diameter shield; we use Rokicki's dvips, with the PS file in
%%% the TEXINPUTS directory.
%\newcommand{\@eushield}{%
%  \vbox to 45mm{%
%    \vfill
%    \hbox to 45mm{%
%      \special{psfile=eushield.ps hoffset=-4.664 voffset=-65.99
%               hscale=23.32 vscale=23.32}%
%      \hss
%    }%
%  }%
%}%

\def\@dvips{dvips.def}
\def\@oztex{oztex.def}
\ifx\Gin@driver\@dvips
        %%% Place a scaled shield in the top right hand corner.  Isn't this
        %%% neat?
        \newcommand{\@eushield}{%
          \scalebox{0.2332}{\includegraphics{eushield.ps}}
        }%
\else
\ifx\Gin@driver\@oztex
        %%% Neat maybe, but it doesn't work in OzTeX. Try this instead
        %%% ... (paul)
        \newcommand{\@eushield}{%
           \includegraphics[30mm,30mm]{eushield.ps}
        }%
\fi
\fi

\def\crestversion#1{\special{!/crestversion #1 def }}% select version


%%% Customisations follow; these should be overridden in the
%%% department-specific letter style.

%%% Departmental information. Override these defaults in department-specific
%%% style file.
\newcommand{\@deptname}{%
  \textit{The\/} UNIVERSITY \textit{of\/} EDINBURGH
}%

\newcommand{\@planningunit}{}

\newcommand{\@deptaddress}{%
  The Old College\\
  South Bridge\\
  Edinburgh EH8 9YL}
\newcommand{\@hod}{}            % head of department
\newcommand{\@profs}{}          % comma separated list of (footer, professors)

%%% Set up variables defined above
\email{}                        % electronic mail
\extn{}                         % internal phone
\telex{727442 (UNIVED G)}       % telex number
\code{(0131)}                   % could use +44 131
\fax{}                          % fax number
\phone{650 1000}                % main phone number
\href{}                         % web page URL

%%%
%%% Label stuff - does anyone use this?
%%%
\renewcommand{\startlabels}{%
  \baselineskip=0pt
  \lineskip=0pt
  \labelcount\z@
  \pagestyle{empty}
  \let\@texttop=\relax
  \topskip 0pt
  \topmargin -10.4 true mm
  \headsep 0pt
  \headheight 0pt
  \footskip 0pt
%  \footheight 0pt
  \textheight 267 true mm
  \@colht\textheight
  \@colroom\textheight
  \vsize\textheight
  \textwidth 185 true mm
  \oddsidemargin -10.4 true mm
  \evensidemargin -10.4 true mm
  \marginparwidth 0pt
  \marginparsep 0pt
  \columnsep 25 true mm
  \@tenpt
%  \baselineskip=0pt
%  \lineskip=0pt
  \boxmaxdepth=0pt
  \parindent=0pt
  \twocolumn\relax
  \@whilenum\labelcount >\z@\do {\mlabel{}{}\advance\labelcount\m@ne}
}%

\renewcommand{\mlabel}[2]{%
  \setbox0
  \vbox{%
    \parbox[b]{80 true mm}{\strut\ignorespaces #2}}
  \vbox to 38 true mm{\vss \box0 \vss}
}%

% Now make \makelabels take an optional argument, which is the first
% label position to use.

\def\makelabels{%
  \AtBeginDocument{%
    \@ifnextchar[{\@makelabels}{\@makelabels[1]}
  }%
}%

\def\@makelabels[#1]{%
  \labelcount#1 
  \advance\labelcount\m@ne 
  \@fileswtrue
}%

%%% Stuff that I don't think we need any more

%\def\stopletter{\global\setlength{\textheight}{\eutextheight}%
%  \global\setlength{\headsep}{\euheadsep}}

%\newlength{\eutextheight}\newlength{\euheadsep}
%\setlength{\eutextheight}{\textheight}
%\setlength{\euheadsep}{\headsep}

