%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% `kthletter.sty'
%
% Modified version of ``brevmall.sty'' by Rickard Norström.
% Written by Anders Forsgren.
% This version dated October 23, 2003.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Beginning of sample letter
%
% \documentclass[11pt,a4paper]{letter}
%
% \def\mydata{
%    \english
% %   \swedish\usepackage[swedish]{babel}
%    \def\myname{Anders Forsgren} 
%    \def\myphone{790 71 27}
%    \def\myfax{22 53 20}
%    \def\myemail{andersf@math.kth.se}
%    \def\mydivision{
%      \ifthenelse{\boolean{english}}
%      {Optimization and Systems Theory}
%      {Optimeringslära och systemteori}}
%    \def\myadress{Lindstedtsvägen 25}
% %   \extrainitspace 2cm   % will give extra space above the main letter
% %   \extrapsspace 0cm     % will give extra space after the signature
%    \makelabels
% }
%
% \usepackage{kthletter}
%
% \begin{document}
%
% \begin{letter}{Addressee \\
% Address}
%
% \opening{Dear Addressee:}
%
% This is the body of the letter.
%
% \closing{Yours sincerely,}            
%
% %\encl{Enclosure}
% %\cc{Copy}
% %\ps PS
%
% \end{letter}
%
% \end{document}
%
% End of sample letter

%%%% Begin added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcounter{letter}
\def\fromname{\myname}

\let\letterorig\letter
\let\endletterorig\endletter

\renewcommand*{\letter}{\addtocounter{letter}{1}\letterorig}
\renewcommand*{\endletter}{\message{\theletter}\vfill\label{lastpage\theletter}\endletterorig}

\newdimen\extrainitspace
\extrainitspace=0mm

\newdimen\psspace
\psspace=10mm

\newdimen\extrapsspace
\extrapsspace=0mm

%%%% End added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\RequirePackage{fancyheadings}
\usepackage[T1]{fontenc}
\usepackage{extramarks}
%%%% Begin added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\usepackage{graphicx}
%%%% End added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[latin1]{inputenc}
\pagestyle{fancy}
\usepackage{float, times}
\usepackage{helvetic}
%%%% Begin added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\usepackage{lastpage}
%%%% End added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\topmargin = 20mm %var 8mm
\textheight = 24.7cm %21.9 om header
\columnsep = 0pt
\hoffset = -1in
\voffset = -1in
\headsep = 0mm %8mm om header
\headheight = 0mm %30mm om header
\oddsidemargin = 30mm
\evensidemargin = 30mm
\textwidth = 15cm
\footskip = 5mm
\marginparsep = 0pt
\marginparwidth = 0pt
\headrulewidth = 0pt
\paperwidth = 20.8cm

\RequirePackage{ifthen}

%%%% Begin added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newif\ifpdf
\ifx\pdfoutput\undefined
   \pdffalse
\else
   \pdfoutput=1
   \pdftrue
\fi

\ifpdf
   \usepackage[pdftex]{color} %%% black,white, red,green,blue,
                              %%% cyan,magenta,yellow
   \usepackage[pdftex]{graphicx}
   \usepackage{thumbpdf}
\else
   \usepackage{color} %%% black,white, red,green,blue, cyan,magenta,yellow
   \usepackage{graphicx}   
\fi

% Style file with KTH macros appropriate for Mathematics
% Written by Anders Forsgren on October 23 2003.

\def\mathematics#1{%
  \begin{center}
    \ifpdf
    \colorbox{white}{\includegraphics[width=#1]{kth_mathematics_rgb}}
    \else
    \colorbox{white}{\includegraphics[width=#1]{kth_mathematics_pms}}
    \fi
  \end{center}}

\def\matematik#1{%
  \begin{center}
    \ifpdf\
    \colorbox{white}{\includegraphics[width=#1]{kth_matematik_rgb}}
    \else
    \colorbox{white}{\includegraphics[width=#1]{kth_matematik_pms}}
    \fi
  \end{center}}

% \KTH gives KTH logo

\def\kth#1{%
  \begin{center}
    \ifpdf
    \colorbox{white}{\includegraphics[width=#1]{kth_cmyk}}
    \else
    \colorbox{white}{\includegraphics[width=#1]{kth_pms}}
    \fi
  \end{center}}


% \kthtoplogo given at first line on a page gives selected logo in the upper
%  center of the page.
%     #1 is the vertical distance from the top edge of the paper
%     #2 is either of the logos defined above
%     #3 is the width of the logo (preferrably 25 true mm or 32 true mm)
%  Example:
%     \kthtoplogo{12 true mm}{\matematik}{25 true mm}

\def\kthtoplogo#1#2#3{%
     \newdimen\xlogoskip
     \newdimen\ylogoskip
     \xlogoskip 0mm
     \advance\xlogoskip -\oddsidemargin
     \advance\xlogoskip -1 true in
     \advance\xlogoskip -0.5 true mm
     \advance\xlogoskip #1
     \ylogoskip 0mm
     \advance\ylogoskip -\topmargin
%     \advance\ylogoskip -1 true in
     \advance\ylogoskip -6 true mm
     \advance\ylogoskip #1
     \
     \vskip \ylogoskip
     \noindent #2{#3}}


%   \newcommand{\placelogo}{\vbox to 30 mm{\kthtoplogo{13mm}{\kth}}}
   \newcommand{\placelogo}{{\vbox to 30 mm{%
         \ifthenelse{\boolean{english}}
         {\kthtoplogo{10 mm}{\mathematics}{25 mm}}
         {\kthtoplogo{10 mm}{\matematik}{25 mm}}
       }}}

%%%% End added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newboolean{english}
\newcommand{\english}[0]{
\setboolean{english}{true}
}

\newcommand{\swedish}[0]{
\setboolean{english}{false}
}

\mydata

%%%% Begin added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newdimen\initspace
\initspace=10mm
\advance\initspace\extrainitspace
\def\opening#1{%
  \typeout{(Unofficial) KTH style file for LaTeX `letter' document
                   class <23 Oct 03>.}
  \placelogo
   {\begin{minipage}[t]{70mm}
      \toname \\ \toaddress 
   \end{minipage} \hfill \today} 
   \par\vspace{\initspace}
   \parbox[t]{\textwidth}{#1}}

\let\closingorig\closing
\renewcommand*{\closing}[1]{\closingorig{#1}
 \advance\psspace \extrapsspace \vspace{\psspace}}

\renewcommand*{\startlabels}{\labelcount\z@
  \pagestyle{empty}%
  \let\@texttop\relax
%  \topmargin -50\p@
  \topmargin 7mm
  \headsep \z@
%  \oddsidemargin -35\p@
%  \evensidemargin -35\p@
  \oddsidemargin 5mm
  \evensidemargin 5mm
  \textheight 10in
  \@colht\textheight  \@colroom\textheight \vsize\textheight
  \textwidth 190mm
  \columnsep 10mm
  \ifcase \@ptsize\relax
    \normalsize
  \or
%    \small
    \normalsize
  \or
    \footnotesize
  \fi
  \baselineskip \z@
  \lineskip \z@
  \boxmaxdepth \z@
  \parindent \z@
%  \twocolumn\relax}
  \relax}
\let\@startlabels=\relax
\renewcommand*{\mlabel}[2]{%
\begin{minipage}[h]{68mm}
\vbox to 36 mm{#2\vfil}
\end{minipage}
%  \parbox[b][2in][c]{262\p@}{\strut\ignorespaces x #2}%
  }

%%%% End added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\lhead[]{}
\chead[]{}
\rhead[]{}
\lfoot[]{}
\rfoot[]{}
\ifthenelse{\boolean{english}}{
\cfoot[]{
\begin{tabular*}{\textwidth}{r c r}
\hspace{1.4cm} & \hspace{11cm} & \hspace{3cm}\\
 & \fontfamily{pag}\selectfont
\fontsize{6.5}{6}\selectfont{\hspace{0mm} Royal Institute of
  Technology \quad \emph{\mydivision}} &
%%%% Begin added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{\hspace{7mm}\vspace{-8mm}\small \thepage(\pageref{LastPage})}\\[2ex]
%{\hspace{7mm}\vspace{-8mm}\small \thepage(\pageref{lastpage\theletter})}\\[2ex]
%%%% End added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{tabular*}  
\begin{center}\vspace{-5mm}
\vspace{0.7mm}\rule{\textwidth}{0.25pt}\\[0.6534679845ex]
\renewcommand{\arraystretch}{0.8}
\begin{tabular}{c}
\hspace{0mm} \fontfamily{pag}\selectfont{\hspace{9mm}
  {\fontsize{5.5}{5}\selectfont{\textbf{KTH}}} 
  {\fontsize{6.5}{5}\selectfont{\myadress, SE-\fontsize{6}{5}\selectfont{100 44 }\fontsize{6.5}{5}\selectfont{Stockholm. Phone:}
  \fontsize{6}{5}\selectfont{+46 8 \myphone}\fontsize{6.5}{5}\selectfont{.
  Fax:
  }\fontsize{6}{5}\selectfont{+46 8 \myfax}\fontsize{6.5}{5}\selectfont{.
  E-mail: \myemail}}}}\\
%  \vspace{-1mm}\fontfamily{pag}\selectfont{\hspace{11mm}{\fontsize{6.5}{5}\selectfont{Postal
%  giro No:\fontsize{6}{5}\selectfont{ 1 56
%  53-9}. \fontsize{6.5}{5}\selectfont{Bank giro No:
%  }\fontsize{6}{5}\selectfont{895-9223}\fontsize{6.5}{5}\selectfont{.
%  VAT registration No:
%  SE}\fontsize{6}{5}\selectfont{202100305401.}\fontsize{6.5}{5}\selectfont{
%  www.kth.se}}}}
\end{tabular}
\end{center}
}}
{\cfoot[]{
\begin{tabular*}{\textwidth}{r c r}
\hspace{1.4cm} & \hspace{11cm} & \hspace{3cm}\\
 & \fontfamily{pag}\selectfont
\fontsize{6.5}{6}\selectfont{\hspace{0mm} Kungliga Tekniska högskolan \quad \emph{\mydivision}} &
%%%% Begin added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{\hspace{7mm}\vspace{-8mm}\small \thepage(\pageref{LastPage})}\\[2ex]
%{\hspace{7mm}\vspace{-8mm}\small \thepage(\pageref{lastpage\theletter})}\\[2ex]
%%%% End added by AF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{tabular*}  
\begin{center}\vspace{-5mm}
\vspace{0.7mm}\rule{\textwidth}{0.25pt}\\[0.6534679845ex]
\renewcommand{\arraystretch}{0.8}
\begin{tabular}{c}
\hspace{0mm} \fontfamily{pag}\selectfont{\hspace{9mm}
  {\fontsize{5.5}{5}\selectfont{\textbf{KTH}}} 
  {\fontsize{6.5}{5}\selectfont{\myadress,
  %SE-
\fontsize{6}{5}\selectfont{100 44 }
\fontsize{6.5}{5}\selectfont{Stockholm. Tel:}
  \fontsize{6}{5}\selectfont{\myphone}\fontsize{6.5}{5}\selectfont{.
  Fax:
  }\fontsize{6}{5}\selectfont{\myfax}\fontsize{6.5}{5}\selectfont{.
  E-post: \myemail}}}}\\
%\vspace{-1mm}\fontfamily{pag}\selectfont{\hspace{11mm}{\fontsize{6.5}{5}\selectfont{Pg:\fontsize{6}{5}\selectfont{
%  1 56 53-9}. \fontsize{6.5}{5}\selectfont{Bg:
%  }\fontsize{6}{5}\selectfont{895-9223}\fontsize{6.5}{5}\selectfont{.
%  Momsreg.nr/VAT: }\fontsize{6}{5}\selectfont{202100305401.}\fontsize{6.5}{5}\selectfont{
%  www.kth.se}}}}
\end{tabular}
\end{center}
}}
