% Class file for Le Matematiche
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{lematema}[2007/01/01 v0.1
Class for articles in ``Le Matematiche'']

\DeclareOption{english}{\PassOptionsToPackage{\CurrentOption}{babel}}
\DeclareOption{french}{\PassOptionsToPackage{\CurrentOption}{babel}}
\DeclareOption{italian}{\PassOptionsToPackage{\CurrentOption}{babel}}

\DeclareOption{draft}{\PassOptionsToClass{\CurrentOption}{article}}

\ProcessOptions\relax

\LoadClass[10pt,twoside]{article}
\RequirePackage[italian]{babel}
\RequirePackage{url}
\RequirePackage{amsmath}
\RequirePackage{amssymb}

\DeclareUrlCommand\email{\urlstyle{tt}}

% %\magnification\magstephalf
\RequirePackage[paperwidth=17cm,%
		paperheight=24cm,%
		footskip=0pt,%
		headsep=0.5cm,%
		headheight=0.5cm,%
		width=12.2cm,%
		height=18.5cm,%
		left=2cm,%
		top=2cm,%
		bottom=2.5cm]{geometry}

\renewcommand{\ps@plain}{%
  \renewcommand{\@oddhead}{\hfill\@htitle\hfill\thepage}%
  \renewcommand{\@evenhead}{\thepage\hfill\@hauthor\hfill}%
  \renewcommand{\@oddfoot}{}%
  \renewcommand{\@evenfoot}{}%
}
\pagestyle{plain}

% TODO bibliografia
% TODO font

% TODO
\def\@htitle{titolo}
\def\@hauthor{autore}

\def\MSC#1{\gdef\@MSC{#1}}
\def\@MSC{}
\def\keywords#1{\gdef\@keywords{#1}}
\def\@keywords{}

\edef\LM@Year{????}
\def\LM@Vol{???}
\def\LM@Num{??}
\def\LM@FirstPg{??}
\def\LM@LastPg{??}

%% Redefine \date to parse a string yyyy/mm/dd, which will be used
%% submission date
\newcount\LM@year
\newcount\LM@month
\newcount\LM@day
\def\date#1{\LM@parsedate#1\LM@enddate}
\def\LM@parsedate#1/#2/#3\LM@enddate{%
\LM@year#1\relax
\LM@month#2\relax
\LM@day#3\relax
}

\def\@articleinfo{%
\noindent\footnotesize LE MATEMATICHE\\
Vol.~\LM@Vol~(\LM@Year)~--~Fasc.~\LM@Num,~pp.~\LM@FirstPg--\LM@LastPg
}
\renewcommand{\maketitle}{%
  \begingroup
    \renewcommand\thefootnote{}%
    \def\@makefnmark{}%
    \long\def\@makefntext##1{\parindent 1em\noindent##1}%
    \newpage
    \global\@topnum\z@   % Prevents figures from going at top of page.
    \@maketitle
    \thispagestyle{empty}\@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
  \global\let\MSC\relax
  \global\let\@MSC\relax
  \global\let\keywords\relax
  \global\let\@keywords\relax
}

\def\@maketitle{%
  \newpage
  \@articleinfo
  \vskip 4.5truecm%
  \begin{center}%
  \let \footnote \thanks
    {\Large\bfseries \@title \par}%
    \vskip 0.5truecm%
    {\Large
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
  \end{center}%
  \par
  \vskip 0.5truecm}

\renewenvironment{abstract}{%
\small\quotation
}{%
\endquotation
}

% In case the author forgets it:
\AtBeginDocument{\maketitle}

