%%%   warwickletter.sty - warwick letterhead style
%%  Adapted from Leedsletter.sty  
%% December 2012 by Ding Yuan (Ding.Yuan@warwick.ac.uk)
%% you are welcome to edit the style files, please notify Ding Yuan with the
%% inprovement and the source for downloading




\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{warwickletter}
\RequirePackage{color,fancybox,fancyhdr,graphicx}
 \definecolor{logo}{rgb}{0.00,0.00,0.00}   % color of the address font 
\def\logo{      
     \thisfancyput(-20pt,0pt){
      \includegraphics[height=50pt]{the_warwick_uni_black}
      \hspace{300pt}
     \includegraphics[height=50pt]{warwick_logo}}
}

\longindentation=0pt

\newcommand*{\department}[1]{\def\deptname{#1}}

\DeclareOption{color}
{\def\logo{     
     \thisfancyput(-20pt,0pt){
      \includegraphics[height=50pt]{the_warwick_uni_blue}
      \hspace{300pt}
     \includegraphics[height=50pt]{warwick_logoc}}
           }
\renewcommand*{\department}[1]{\def\deptname{{{\color{logo}#1}}}}
}
% 0.6
\def\completeaddress{\hbox{\vtop{\hsize=\textwidth\small\rm%
                   \fromaddress}}\hfill
                   }
%%% next section is to get "fancy" UK style dates

\def\@cent{\count0 }                       % century number (1979 == 20)
\def\@diy{\count1 }                        % day in the year
\def\@dow{\count2 }                        % gets day of the week
\def\@epact{\count3 }                      % age of the moon on Jan. 1
\def\@golden{\count4 }                     % Moon's golden number
\def\@leap{\count5 }                       % leap year fingaler
\def\@x{\count6 }                          % temp register

\def\@y{\count7 }                          % another temp register

\def\@up#1{\hbox{%
  #1}}
\def\st{\@up{st}}
\def\nd{\@up{nd}}
\def\rd{\@up{rd}}
\def\th{\@up{th}}

% --- Macros to save and restore the font family.

\def\@savestyle{\count0=\the\fam}
\def\@setstyle{\ifcase\count0\rm\or\mit\or\cal\or\rm% what's family 3?
  \or\it\or\sl\or\bf\or\tt\fi}



\DeclareOption{ukdate}
{\renewcommand*{\today}{\dayofweek,\space \number\day\ifcase\day
  \or\st\or\nd\or\rd\or\th\or\th\or\th\or\th\or\th\or\th\or\th
  \or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\th
  \or\st\or\nd\or\rd\or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\st\fi
  \space\ifcase\month\or January\or February\or March\or April\or May\or
  June\or July\or August\or September\or October\or November\or December\fi
  \space\number\year}}
\def\dayofweek{{%
%               leap = year + (month - 14)/12;
  \@leap=\month \advance\@leap by -14 \divide\@leap by 12
  \advance\@leap by \year
%               dow = (13 * (month + 10 - (month + 10)/13*12) - 1)/5
  \@dow=\month \advance\@dow by 10
  \@y=\@dow \divide\@y by 13 \multiply\@y by 12
  \advance\@dow by -\@y \multiply\@dow by 13
  \advance\@dow by -1 \divide\@dow by 5
%               dow += day + 77 + 5 * (leap % 100)/4
  \advance\@dow by \day \advance\@dow by 77
  \@x=\@leap \@y=\@x \divide\@y by 100 \multiply\@y by 100 \advance\@x by -\@y
  \multiply\@x by 5 \divide\@x by 4 \advance\@dow by \@x
%               dow += leap / 400
  \@x=\@leap \divide\@x by 400 \advance\@dow by \@x
%               dow -= leap / 100 * 2;
%               dow = (dow % 7)
  \@x=\@leap \divide\@x by 100 \multiply\@x by 2 \advance\@dow by -\@x
  \@x=\@dow \divide\@x by 7 \multiply\@x by 7 \advance\@dow by -\@x
  \ifcase\@dow Sunday\or Monday\or Tuesday\or Wednesday\or
        Thursday\or Friday\or Saturday\fi}}

%%% end of section is to get "fancy" UK style dates



\ProcessOptions
\raggedright  % apparently recommended

%customization for letter format
\usepackage{helvet}
\usepackage[latin1]{inputenc}
\setlength{\textwidth}{16.57truecm}
\setlength{\textheight}{25truecm}
\setlength{\oddsidemargin}{0mm}
\setlength{\evensidemargin}{-0mm}
\setlength{\topmargin}{-41truemm}


\newcommand*{\skipit}[1]{\def\skipamount{#1}}
%\newcommand*{\department}[1]{\def\deptname{#1}}
\newcommand*{\university}[1]{\def\universityname{#1}}
\newcommand*{\postcode}[1]{\def\postcodenum{#1}}
\newcommand*{\alignit}[1]{\def\alignnum{#1}}

\newcommand*{\tel}[1]{\def\telnum{#1}}
\newcommand*{\fax}[1]{\def\faxnum{#1}}
\newcommand*{\email}[1]{\def\emailnum{#1}}

\ifx\fromaddress\@empty         %create default address
                \def\fromaddress{
                  \ifx\deptname\@empty     \else  \deptname \fi \\[\alignnum]
                  }
\fi




\def\ps@headings{\def\@oddhead{\rm To \ignorespaces\toname \hfil \today
    \hfil Page \thepage}\def\@oddfoot{}}

\def\@texttop{\vskip 0pt}

\def\opening#1{{\color{logo}\logo}            %Create all up to start of
                                        % text
   \vspace{12pt}
   {\raggedleft \completeaddress \par}
  \thispagestyle{empty} 
  \vspace{\parskip}
   {\raggedright \toname \\ \toaddress \par}
   \vspace{\ifx\skipamount\parskip\@empty \else \skipamount\parskip \fi}
\@date\par%
  \vspace{\ifx\skipamount\parskip\@empty \else \skipamount\parskip \fi}%
  #1\par\nobreak}

