%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LaTeX class for Working Papers of University of Tartu, Faculty of Economics and 
% Business Administration (in English).
% 
% Ver. 1.0: 02.04.2007: Ott Toomet improved the formatting of captions of the 
% tables. 
% 
% Ver. 0.95:Toomas & Marit Hinnosaar, 06.01.2005: Finished version. As the first
% two pages are done in printing house anyway, these are empty now. Which
% means that without this complex formatting class works much better.
% 
% Ver. 0.9: Toomas & Marit Hinnosaar, 04.04.2004: More or less working version, 
% gives two strange error messages (but still works).
%
% Usage:		Described in the file mtk_wp.tex, mtk_wp.pdf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \NeedsTeXFormat{LaTeX2e}
	\ProvidesClass{mtk_wp}[2004/12/16 Working Paper of Dept of Econ and BA at Tartu University.]
	\ProvidesFile{mtk_wp.cls}
  \PassOptionsToClass{twoside,a5paper,fleqn,11pt}{article}
	\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
	\ProcessOptions
	\LoadClass{article}
  \RequirePackage[labelsep=period, font=small, labelfont=bf]{caption} % Make captions more like common mtk captions
  \RequirePackage[a5paper,includeheadfoot,lmargin=24mm,rmargin=24mm,tmargin=15mm,bmargin=20mm]%
	  {geometry}
  \RequirePackage{times}
  \RequirePackage{titlesec} % used mostly for section numbering
  \RequirePackage[ansinew]{inputenc}
  \RequirePackage[T1]{fontenc}

% Page and text formatting
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{\baselineskip}
    \renewcommand{\normalsize}{\fontsize{11pt}{12pt}\selectfont}

%%%%% Formatting of first pages
\renewcommand\maketitle{\par
  \begingroup
    \begin{titlepage}%
  	  \let\footnotesize\small
  		\let\footnoterule\relax
  		\let \footnote \thanks
  		\null\vfil
  		\begin{center}
	  	    {\fontfamily{verdana}\fontseries{b}\large\selectfont University of Tartu}\\[2mm]
	  			{\fontfamily{phv}\large\selectfont Faculty of Economics and Business\\ 	
	  				 Administration}\\[2mm]
  		\end{center}
  		\vskip 40\p@
  		\begin{center}%
    		{\fontfamily{phv}\bfseries\LARGE\selectfont \@title \par}%
    		\vskip 3em%
    		{\large
     		\lineskip .75em%
        {\fontfamily{phv}\large\selectfont 
      	\begin{tabular}[t]{c}%
          \@author
      	\end{tabular}\par}%
      	}
    		{\fontfamily{phv}\large\selectfont \@date \par}%       % Set date in \large size.
      	\vskip 5em%
      	{\fontfamily{phv} \small NB! This is a preprint version of the
          working paper,\\
          see \href{http://www.mtk.ut.ee/}{http://www.mtk.ut.ee/} for final version.}
  		\end{center}\par
  		\global\let\@thanks\@empty
  		\setcounter{footnote}{0}%
	\gdef\thefootnote{\arabic{footnote}}\gdef\@@savethanks{}%
  		\vfil\null
    \end{titlepage}
    \mbox{ }
    \thispagestyle{empty}
    \newpage
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \newpage
    \global\@topnum\z@   % Prevents figures from going at top of page.
    \@maketitle
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\@maketitle{%
  \newpage
  \let \footnote \thanks
    {\fontfamily{phv}\bfseries\selectfont \@title \par}%
    \vskip -0.8em%
    {\fontfamily{phv}\selectfont \@author \par}%
  \par
  \vskip 1em}
   
%%%%% Header and Footer
% Usage: \short{Lastname}{Short title tells ...}
\newcommand{\short}[2]{%
  \RequirePackage{fancyhdr}
  \pagestyle{fancy}
  \fancyhead{}
  \fancyhead[LE]{\itshape #1}
  \fancyhead[RO]{\itshape #2}
  \fancyhead[LO,RE]{\thepage}
  \fancyfoot{}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
}

%%%%% Command definition and formatting of Summary 
% Usage: \summary{Title in Estonian}
\newcommand{\summary}[1]{
  \newpage
  \phantomsection
  \addcontentsline{toc}{section}{Sisukokkuvõte} 
  {\fontfamily{phv}\bfseries\fontsize{11pt}{12pt}\selectfont SISUKOKKUVÕTE}\\[6mm]%
  % Summary=Sisukokkuvõte; Conclusions=Kokkuvõte
  {\fontfamily{phv}\bfseries\fontsize{11pt}{12pt}\selectfont #1}%
}    

%---- Section, Subsection, Subsubsection -------
% We use 'titlesec' package here because we need a dot after the
% section number.  However, we also need to refer the section numbers
% without the dot.
\titleformat{\section}%
{\fontfamily{phv}\bfseries\fontsize{16pt}{18pt}\selectfont}%
{\arabic{section}.\quad}%
{0pt}{}{}
\titlespacing{\section}{0pt}
{2.5\baselineskip plus 0.3\baselineskip minus 0.3\baselineskip}
{0.8\baselineskip plus 0.1\baselineskip}

\titleformat{\subsection}%
{\fontfamily{phv}\bfseries\fontsize{12pt}{13pt}\selectfont}%
{\arabic{section}.\arabic{subsection}.\quad}%
{0pt}{}{}
\titlespacing{\section}{0pt}
{1.5\baselineskip plus 0.2\baselineskip minus 0.1\baselineskip}
{0.1\baselineskip}

\titleformat{\subsubsection}%
{\flushleft\fontsize{12pt}{13pt}\bfseries}%
{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}.\quad}%
{0pt}{}{}
\titlespacing{\section}{0pt}
{0.1\baselineskip}
{0.1\baselineskip}

    %%%%% Abstract
    \renewenvironment{abstract}{%
      {\fontfamily{phv}\fontseries{b}\selectfont \abstractname \par}%
      \selectfont
    }{}

    %%%%% Table of Contents, section numbering
    \RequirePackage{tocloft}
    \renewcommand\cftsecfont{\normalsize}			
    \renewcommand\cftsecpagefont{\normalsize}			
    \renewcommand\cftsecleader{\cftdotfill{\cftsecdotsep}}
    \renewcommand\cftsecdotsep{\cftdotsep}%
    \renewcommand{\cfttoctitlefont}{\fontfamily{phv}\bfseries\fontsize{16pt}{18pt}\selectfont}
    \renewcommand{\contentsname}{CONTENTS} % The easiest way to get it in uppercase.
    \setcounter{tocdepth}{2}    % Depth of table of contents (no subsubsections).
    \setcounter{secnumdepth}{2} % No numbers for subsubsections.

    %%%%% References
    \renewcommand{\refname}{REFERENCES}

    %%%%% Simple additions
    \sloppy 											   		
    \clubpenalty=9999
    \widowpenalty=9999																
    \normalsfcodes


% The following is borrowed from size11pt.clo
\def\@listi{\leftmargin\leftmargini
            \parsep 4.5\p@ \@plus2\p@ \@minus\p@
            \topsep 0pt \@plus 0.3pt
            \itemsep 0pt \@plus 0.3pt}
\let\@listI\@listi
\@listi
\def\@listii {\leftmargin\leftmarginii
              \labelwidth\leftmarginii
              \advance\labelwidth-\labelsep
              \topsep    4.5\p@ \@plus2\p@ \@minus\p@
              \parsep    2\p@   \@plus\p@  \@minus\p@
              \itemsep   \parsep}
\def\@listiii{\leftmargin\leftmarginiii
              \labelwidth\leftmarginiii
              \advance\labelwidth-\labelsep
              \topsep    2\p@ \@plus\p@\@minus\p@
              \parsep    \z@
              \partopsep \p@ \@plus\z@ \@minus\p@
              \itemsep   \topsep}
\def\@listiv {\leftmargin\leftmarginiv
              \labelwidth\leftmarginiv
              \advance\labelwidth-\labelsep}
\def\@listv  {\leftmargin\leftmarginv
              \labelwidth\leftmarginv
              \advance\labelwidth-\labelsep}
\def\@listvi {\leftmargin\leftmarginvi
              \labelwidth\leftmarginvi
              \advance\labelwidth-\labelsep}

%%%%% Environments
%%end of the file "mtk_wp.cls"
