%\def\filedate{12 Sept 2006}
%\def\fileversion{1.02}
%\def\filename{uealettr.dtx}
%\def\docdate{12th September 2006}
%\iffalse
% Doc-Source file to use with LaTeX2e
% Copyright (C) 2000 Nicola Talbot, all rights reserved.
%\fi
%
%\iffalse
% Kopka & Daly 7.5.9
%\fi
%\newenvironment{ttscript}[1]{%
%  \begin{list}{}{%
%  \settowidth{\labelwidth}{\texttt{#1}}
%  \setlength{\leftmargin}{\labelwidth}
%  \addtolength{\leftmargin}{\labelsep}
%  \setlength{\parsep}{0.5ex plus0.2ex minus0.2ex}
%  \setlength{\itemsep}{0.3ex}
%  \renewcommand{\makelabel}[1]{\texttt{##1\hfill}}}}%
%{\end{list}}
%
% \title{uealettr v \fileversion : UEA Letter Class File}
% \author{N.L.C. Talbot}
% \date{\docdate}
%\maketitle
%\tableofcontents
%
%\setlength{\parindent}{0pt}
%\setlength{\parskip}{10pt}
%
% \section{Introduction}
%The class file |uealettr.cls| is provided for writing letters
%with or without headed paper.  It is based on the |letter| class file, and 
%on the example given in ``A Guide to LaTeX'' Helmut Kopka and Patrick W. Daly.
%It is recommended that the Times (Roman), Helvetica or Avant Garde (Sans Serif) 
%and Courier (Typewriter) fonts
%are used instead of the Computer Modern fonts, as they look a bit
%better.  These fonts can be obtained by using the |times|,
% |helvet| or |avant| and |courier| packages.
%
%
% \section{Class File Options}
%All options that can be passed to the |letter| class file, can also
%be passed to |uealettr| (except for the paper size which is fixed at A4).  
%In addition, the following options can also be passed to |uealettr|:
%
%
%\begin{ttscript}{notconfidential}
%\item[headed]
%This option assumes the letter will be printed on headed
%paper, and so the sender details are omitted. (Default)
%
%\item[notheaded]
%This option assumes the letter will be printed on blank
%paper, and so the sender details are placed at the top of the letter.
%
%\item[personal]
% This option indicates that the letter is personal, 
%and the word \textbf{PERSONAL} is typeset above the recipients address.
%
%\item[notpersonal]
% This option indicates that the letter is not personal. (Default)
%
%\item[confidential]
% This option indicates that the letter is confidential,
%and the word \textbf{CONFIDENTIAL} is typeset above the recipients address.
%
%\item[notconfidential]
% This option indicates that the letter is not confidential. (Default)
%
%\item[datetime]
% Use the \textsf{datetime}
%package to display the date in full
%on the first page, and abbrieviated in the header of subsequent pages.
%
%\item[nodatetime]
% Don't use \textsf{datetime} package. (Default)
%\end{ttscript}
%
%\section{\texttt{letter} environment}
%
%As with the |letter| class file, each letter should be enclosed in a |letter| environment.  Multiple letters may be
%enclosed in one document using multiple |letter| environments.  
%The |letter| environment takes one argument that should
%be the recipient's name and address.  The |\\| command may be used to provide line 
%breaks within the recipient's address.  The first line is taken to be the recipient's name.
%For example:
%\begin{verbatim}
%\begin{letter}{Prof. Some One\\1 The Street\\
%               The Town\\
%               The County\\
%               AB1 2XY}
%\end{verbatim}
%``Prof. Some One'' is the recipient, the remainder is the address.
%
%Within the |letter| environment, the following commands may be used:
%
%\DescribeMacro{\opening}
%The command |\opening{|\meta{text}|}| indicates opening salutation.\\ (e.g.\ |\opening{Dear Sir}|)
%
%\DescribeMacro{\closing}
%The command |\closing{|\meta{text}|}| indicates closing text.\\ (e.g.\ |\closing{Yours Faithfully}|)
%
%\DescribeMacro{\cc}
%The command |\cc{|\meta{text}|}| indicates who the letter
%should be copied to. (e.g.\ |\cc{Dr A. Person\\Dr A.N. Other}|).  
%This command should come after the |\closing| command.
%
%\DescribeMacro{\encl}
% The command |\encl{|\meta{text}|}| indicates 
%any enclosures with the letter. (e.g.\ |\encl{Application Form\\Map}|).  
%This command should come after the |\closing| command.
%
%\DescribeMacro{\ps}
%This command |\ps| indicates that all text from this point until the
%end of the |letter| environment is treated as a postscript.
%
%\section{Available Commands}
%
%The following commands may be used in the preamble:
%
%\DescribeMacro{\signature}\noindent
%The command |\signature{|\meta{text}|}| indicates who
%the letter is from.
%
%\DescribeMacro{\location}
% The command |\location{|\meta{text}|}| indicates the
%school.\\  (e.g.\ |\location{School of Computing Sciences}|)
%
%\DescribeMacro{\institute}
% The command |\institute{|\meta{text}|}| indicates the
%institute (the default is University of East Anglia).\\
%(e.g.\ |\institute{University of East Anglia}|)
%
%\DescribeMacro{\instituteAddress}
% The command |\instituteAddress{|\meta{text}|}| indicates the
%institute's address. (the default is UEA's address)\\
%(e.g.\ |\instituteAddress{Norwich. NR4 7TJ. England}|)
%
%\DescribeMacro{\division}
% The command |\division{|\meta{text}|}| indicates the group
%within the school that the letter is from. (e.g. |\division{Kernel Support Vector Group}|)
%
%\DescribeMacro{\telephone}
% The command |\telephone{|\meta{text}|}| indicates the main 
%telephone number.
%
%\DescribeMacro{\directdial}
% The command |\directdial{|\meta{text}|}| indicates the direct
%dial number of the sender.
%
%\DescribeMacro{\fax}
% The command |\fax{|\meta{text}|}| indicates the fax number.
%
%\DescribeMacro{\email}
% The command |\email{|\meta{text}|}| indicates the e-mail
%address of the sender if required.
%
%\DescribeMacro{\myref}
% The command |\myref{|\meta{text}|}| indicates the sender's reference
%if required.
%
%\DescribeMacro{\yourref}
% The command |\yourref{|\meta{text}|}| indicates the recipient's
%reference if required.
%
%\DescribeMacro{\subject}
% The command |\subject{|\meta{text}|}| indicates the subject of
%the correspondence if required. (e.g. |\subject{Interview}|)
%
%\DescribeMacro{\logo}
% The command |\logo{|\meta{object}|}| is the logo to appear
%at the top right corner of the first page, if the \texttt{notheaded} option is specified.  For example
%\begin{verbatim}
%\logo{\includegraphics[height=3.3cm]{uealogo.ps}}
%\end{verbatim}
%By default, this is an empty box of width 4cm and height 3.3cm.
%The UEA logo is not supplied with this class file.
%
%\section{Additional Information}
%
%The default page styles are |firstpage| for the first page of the letter and
%|uealettr| for subsequent pages.  If the letter is more than one page long,
%the text \textsf{\itshape Continued / \ldots} appears at the foot of all but the last page.
%The |uealettr| page style places the recipient's name, the date and the
%page number out of total page number in the header.  Other available page
%styles are: |empty|, |plain| and |headings|.  The latter is
%similar to |uealettr| but does not give the total number of pages.
%Since LaTeX needs to know the total number of pages in the letter for the |uealettr|
%page style, the document will need to be re-run to get it up-to-date.
%
%The date is taken to be the current date given by |\today|.  By default, the
%date is formatted in the US style, but can be changed using packages such as
%|ukdate| or |datetime|.  Alternatively the date can be specified
%explicitly using the |\date| command (e.g.\ |\date{17th December, 2003}|).
%The |\date| command has an optional argument that specifies an abbreviated version
%to put at the head of subsequent pages (e.g.\ |\date[17th Dec, 2003]{17th December, 2003}|).  
%For example, using the |datetime| package, the command
%\begin{verbatim}
%\date[\shortdate\today]{\longdate\today}
%\end{verbatim}
%will result in the full date
%appearing at the start of the letter, but a short date at the head of page 2 onwards.
%(Passing the option |datetime| to |uealettr| achieves the same effect.)
%
%The package \textsf{csvtools} 
%is available for mail merging.  See the |csvtools|
%documentation on how to do this.
%
%\section{Contact Details}
%
%Dr Nicola Talbot\\
%School of Computing Sciences\\
%University of East Anglia\\
%Norwich.  NR4 7TJ\\
%\url{http://theoval.cmp.uea.ac.uk/~nlct}
%
%
% \StopEventually{}
% \section{The Code}
% \iffalse
% First we have the driver to get the documentation
%    \begin{macrocode}
%<*driver>
\documentclass{ltxdoc}
\usepackage[colorlinks,
            bookmarks,
            pdfauthor=Nicola Talbot,
            pdftitle={uealettr : UEA Letter Class File}]{hyperref}
\begin{document}
\OnlyDescription
\DocInput{uealettr.dtx}
\end{document}
%</driver>
%    \end{macrocode}
% \fi
%    \begin{macrocode}
% based on example in "A Guide to LaTeX" Helmut Kopka and Patrick W. Daly
\NeedsTeXFormat{LaTeX2e}

\ProvidesClass{uealettr}[2006/09/12 v1.02 (N.L.C. Talbot)]

\RequirePackage{ifthen}

\newif\ifpersonal
\newif\ifconfidential
\newif\ifnotheaded
\newif\if@d@tetime
\@d@tetimefalse

\DeclareOption{personal}{\personaltrue}
\DeclareOption{confidential}{\confidentialtrue}
\DeclareOption{headed}{\notheadedfalse}
\DeclareOption{notpersonal}{\personalfalse}
\DeclareOption{notconfidential}{\confidentialfalse}
\DeclareOption{notheaded}{\notheadedtrue}
\DeclareOption{datetime}{\@d@tetimetrue}
\DeclareOption{nodatetime}{\@d@tetimefalse}

\ExecuteOptions{notpersonal,notconfidential,headed,nodatetime}

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

\ProcessOptions
\LoadClass[a4paper]{letter}

\gdef\@shortd@te{\today}
\renewcommand{\date}[2][\relax]{\gdef\@date{#2}
\ifx#1\relax 
 \gdef\@shortd@te{#2}
\else
 \gdef\@shortd@te{#1}
\fi}

\if@d@tetime
\IfFileExists{datetime.sty}{%
\RequirePackage{datetime}
\date[\shortdate\today]{\today}}{%
\ClassError{uealettr}{Can't find datetime package, defaulting to standard date}{%
If you don't have datetime.sty installed, omit the datetime option to \protect\documentclass}\date{\today}}
\fi

\newcommand{\@yref}{}
\newcommand{\@myref}{}
\newcommand{\@subject}{}
\newcommand{\@division}{}
\newcommand{\@directnum}{}
\newcommand{\@faxnum}{}
\newcommand{\@email}{}

\newcommand{\yourref}[1]{\renewcommand{\@yref}{#1}}
\newcommand{\myref}[1]{\renewcommand{\@myref}{#1}}
\newcommand{\subject}[1]{\renewcommand{\@subject}{#1}}
\newcommand{\division}[1]{\renewcommand{\@division}{#1}}
\newcommand{\directdial}[1]{\renewcommand{\@directnum}{#1}}
\newcommand{\fax}[1]{\renewcommand{\@faxnum}{#1}}
\newcommand{\email}[1]{\renewcommand{\@email}{#1}}

\newcommand{\thelogo}{\raisebox{-1.65cm}{\parbox[c][3.3cm]{4cm}{\mbox{}}}}
\newcommand{\logo}[1]{\ifnotheaded\renewcommand{\thelogo}{\raisebox{-1.65cm}{\parbox[c][3.3cm]{4cm}{#1}}}\else
\PackageError{uealettr}{Headed paper - Ignoring logo}{You can't specify a logo if you are using the headed option.  Your command
has been ignored}\fi}

\newcommand{\hideifheaded}[1]{\ifnotheaded#1\else\phantom{#1}\fi}

\newlength{\leftfield}
\newlength{\rightfield}

\setlength{\leftfield}{80mm}
\setlength{\rightfield}{43mm}

\newcommand{\leftbox}{%
\parbox[t]{\leftfield}{\sffamily\begin{tabular}[t]{@{}l}\relax
{\bfseries\fromlocation}\ifthenelse{\equal{\@division}{}}{}{\\\@division}\relax
\end{tabular}}}

\newcommand*{\@institute}{University of East Anglia}
\newcommand*{\@fromaddress}{Norwich NR4 7TJ England}
\newcommand*{\institute}[1]{\renewcommand*{\@institute}{#1}}
\newcommand*{\instituteAddress}[1]{\renewcommand*{\@fromaddress}{#1}}

\newcommand{\rightbox}{%
\parbox[t]{\rightfield}{%
\begin{sffamily}
\begin{tabular}[t]{c}
\hideifheaded{\thelogo}\\
\\
\hideifheaded{\textbf{\@institute}}\\
\hideifheaded{\@fromaddress}\\[10pt]
\ifthenelse{\equal{\telephonenum}{}}{\\\\}{\slshape Telephone\\\telephonenum\\} 
\ifthenelse{\equal{\@directnum}{}}{\\}{Direct Dial \@directnum\\} 
\ifthenelse{\equal{\@faxnum}{}}{\\}{\slshape Fax\\\@faxnum\\} 
\ifthenelse{\equal{\@email}{}}{\\}{\slshape E-mail\\\@email} 
\end{tabular}
\end{sffamily}}}

\setlength{\voffset}{-60pt}
\setlength{\hoffset}{-30pt}
\addtolength{\textwidth}{1in}
\addtolength{\textheight}{0.5in}
\setlength{\oddsidemargin}{46.48393pt}

\def\putit(#1,#2)#3{\@killglue
\raise #2\relax \hb@xt@ \z@ {\kern #1\relax #3\hss}\ignorespaces}

%one inch + \voffset  + \topmargin
% one inch + \hoffset + \oddsidemargin
\newlength\originX
\newlength\originY
\newcommand{\window}{%
\originY = 1in\relax
\advance\originY by \voffset
\advance\originY by \topmargin
\advance\originY by \headheight
\originX = 1in\relax
\advance\originX by \hoffset
\advance\originX by \oddsidemargin
\begin{picture}(0,0)
\setlength{\unitlength}{1cm}
\putit(-\originX,\originY){
\begin{picture}(0,0)
\put(2.55,-5.2){.}
\put(2.55,-7.7){.}
\put(10.25,-5.2){.}
\put(10.25,-7.7){.}
\put(0,-9.9){\line(1,0){0.5}}
\end{picture}}
\end{picture}}

\renewcommand{\ps@firstpage}{%
\renewcommand{\@oddhead}{\hideifheaded{\window}\hspace{-5mm}\footnotesize\leftbox\hfill\rightbox}
\renewcommand{\@oddfoot}{{\footnotesize \@myref}\hfill
\ifnum\@lastpage>1 \itshape Continued / \ldots\fi}
\renewcommand{\@evenhead}{}
\renewcommand{\@evenfoot}{}}

\newcommand{\ps@uealettr}{%
\renewcommand{\@oddhead}{\itshape To \toname\hfill\@shortd@te\hfill Page \thepage\ of \the\@lastpage}
\renewcommand{\@oddfoot}{\hfill\ifnum\@lastpage>\c@page \itshape Continued / \ldots\fi}
\renewcommand{\@evenhead}{}
\renewcommand{\@evenfoot}{}}

\pagestyle{uealettr}

\providecommand{\@evenhead}{}
\providecommand{\@evenfoot}{}
\providecommand{\@oddhead}{}
\providecommand{\@oddfoot}{}

\renewcommand{\opening}[1]{\thispagestyle{firstpage}%
\vspace*{8pt}
\parbox[t]{\leftfield}{%
\ifpersonal
\ifconfidential
\textbf{PERSONAL AND CONFIDENTIAL}
\else
\textbf{PERSONAL}
\fi
\else
\ifconfidential
\textbf{CONFIDENTIAL}
\else
\phantom{\textbf{PERSONAL AND CONFIDENTIAL}}
\fi
\fi
\par
\vspace{10pt}
\noindent\toname\par
\noindent\toaddress\par
\vspace{\baselineskip}
\@date\par
\ifthenelse{\equal{\@yref}{} \and \equal{\@subject}{}}{}{%
\vspace{\baselineskip}
\begin{small}
\begin{tabular}{@{}l@{ : }l}
\ifthenelse{\equal{\@yref}{}}{}{\bfseries Your Ref &  \@yref}\relax
\ifthenelse{\not\equal{\@yref}{} \and \not\equal{\@subject}{}}{\\}{}\relax
\ifthenelse{\equal{\@subject}{}}{}{\bfseries Subject &  \@subject}
\end{tabular}
\end{small}}
\par
\vspace{\baselineskip} #1\par\nobreak
\vspace{\baselineskip}
}}

\newcount\c@letter

\def\@getlastpage#1#2{\@lastpage=#2}
\newcount\@lastpage
\@lastpage=1

\renewenvironment{letter}[1]
  {\newpage
    \global\advance\c@letter by 1\relax
\edef\@lstpgref{\csname r@pg@lastpage@\romannumeral\c@letter \endcsname}
\expandafter\ifx\@lstpgref\relax
\@lastpage=1
\typeout{Last Page Unknown.}
\else
\expandafter\@getlastpage\@lstpgref
\fi
    \if@twoside \ifodd\c@page
                \else\thispagestyle{empty}\null\newpage\fi
    \fi
    \c@page \@ne
    \c@footnote \z@
    \interlinepenalty=200 % smaller than the TeXbook value
    \@processto{\leavevmode\ignorespaces #1}}
  {\vfill
    \edef\@l@stp@ge{pg@lastpage@\romannumeral\c@letter}
    \label{\@l@stp@ge}
    \stopletter\@@par\pagebreak\@@par
    \if@filesw
      \begingroup
        \let\\=\relax
        \let\protect\@unexpandable@protect
        \immediate\write\@auxout{%
          \string\@mlabel{\returnaddress}{\toname\\\toaddress}}%
      \endgroup
    \fi}

%    \end{macrocode}
%\Finale
\endinput
