%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                        ntds2012.cls                            %
% Class file to be used for the abstracts of ntds2012            %
% Version for standalone abstracts                               %
% Lluís Alsedà (Universitat Autònoma de Barcelona)               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{ntds2012} [2012/01/07 v1.0 for standalone abstracts]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass[12pt]{article}

%%%%%%%%%%%%%%%%%%%%
% Default Packages %
%%%%%%%%%%%%%%%%%%%%
%\RequirePackage{amsmath,amsfonts,amssymb,amsthm,enumerate}
\RequirePackage{amsmath,amssymb,amsthm,enumerate}
\RequirePackage{url}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Margins, textwidths, indentations etc %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setlength\textwidth {150mm}
\setlength\textheight{200mm}
\setlength{\topmargin}{0pt}
\setlength{\headheight}{0pt}
\setlength{\parindent}{0pt}
\setlength{\parskip}{5pt plus 2pt minus 1 pt}
%
\setlength\oddsidemargin  {\paperwidth}
\addtolength\oddsidemargin{-\textwidth}
\divide\oddsidemargin by 2
\addtolength\oddsidemargin{-1in}
\addtolength\oddsidemargin{-\hoffset}
\setlength\evensidemargin {\oddsidemargin}

%%%%%%%%%%%%%%%%%%%%%
% Basic environment %
%%%%%%%%%%%%%%%%%%%%%

\renewenvironment{abstract}{\document\maketitle\thispagestyle{empty}}{\enddocument}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Title, authors, address et al. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\speaker#1#2{\@author@base@command[\underline]{#1 #2}}
\def\author#1#2{\@author@base@command[\relax]{#1 #2}}
\def\@collaborators{}
\def\collaborators#1{\ifx\@collaborators\empty\gdef\@collaborators{\par\par\smallskip\par\par{(in collaboration with #1)}}\fi}

\newcounter{author@number}
\def\@author@base@command[#1]#2{
  \ifcase\c@author@number\xdef\@author{#1{#2}}
  \or\xdef\@author{\@author$^\arabic{author@number}$}
  \fi
  \addtocounter{author@number}{1}
  \expandafter\gdef\csname @address\romannumeral\the\c@author@number\endcsname{\@latex@warning@no@line{No \noexpand\address given}}
  \expandafter\gdef\csname @email\romannumeral\the\c@author@number\endcsname{}
  \expandafter\gdef\csname @urladdr\romannumeral\the\c@author@number\endcsname{}
  \ifnum\c@author@number>1
    \xdef\@author{\@author, #1{#2}$^\arabic{author@number}$}
  \fi
}

\def\address#1{\expandafter\gdef\csname @address\romannumeral\the\c@author@number\endcsname{#1}}
\def\email#1{\expandafter\gdef\csname @email\romannumeral\the\c@author@number\endcsname{E-mail address: {\upshape \url{#1}}}}
\def\urladdr#1{\expandafter\gdef\csname @urladdr\romannumeral\the\c@author@number\endcsname{URL: {\upshape \url{http://#1}}}}

\def\@write@url@line#1{\vskip -1ex\par\par{\small#1}\par\par}
\def\@maketitle{\begin{center}\let \footnote \thanks
    {\Large \textbf{\@title}\par}
    \vskip 1.5em
    {\large \textsc{\@author}\ifnum\c@author@number=1\@collaborators\fi}
  \end{center}\par\par
  \begingroup \itshape
  \ifnum\c@author@number>1\bigskip\par\par
    \count@\@ne
    \loop $^\the\count@$ \csname @address\romannumeral\the\count@\endcsname.
       \par\par
       \expandafter\ifx\csname @email\romannumeral\the\count@\endcsname\empty
           \expandafter\ifx\csname @urladdr\romannumeral\the\count@\endcsname\empty\else
               \@write@url@line{\csname @urladdr\romannumeral\the\count@\endcsname}
           \fi
       \else
           \@write@url@line{\csname @email\romannumeral\the\count@\endcsname\quad\csname @urladdr\romannumeral\the\count@\endcsname}
       \fi
    \ifnum\count@<\c@author@number\advance\count@ by 1\repeat
  \else
    \setbox\z@\hbox{\itshape\@emaili}\setlength\@tempdima{\wd\z@}%
    \setbox\z@\hbox{\itshape\@urladdri}\ifdim\wd\z@>\@tempdima\setlength\@tempdima{\wd\z@}\fi
    \begin{center}
      \@addressi\par\par\parbox{\@tempdima}{\raggedright \@emaili\\ \@urladdri}
    \end{center}
  \fi
  \endgroup
  \par\par\vskip 1.5em
}

%%%%%%%%%%%%%%%%%%%%%%%%
% Initial declarations %
%%%%%%%%%%%%%%%%%%%%%%%%
\sloppy
\flushbottom
\frenchspacing
\endinput
