%% Class file for the Proceedings of DDs
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{procDD08}[2007/16/06 Days on Diffraction Proceedings Class]
\newif\ifHyperRefs \HyperRefsfalse
\DeclareOption{HyperRefs}{\HyperRefstrue}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass[10pt,twocolumn,twoside,a4paper]{article}
% Load styles
\usepackage{amssymb}
\usepackage{amsfonts, latexsym}
%%

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

\newcommand{\confpath}{http://math.nw.ru/DD}% <<<-------------------------------

\ifpdf
  \usepackage[pdftex]{graphicx}
  \ifHyperRefs
    \usepackage[pdftex,colorlinks=true,citecolor=blue,linkcolor=blue,%
            pagecolor=black,urlcolor=blue,pdfstartview=FitH]{hyperref}
    \hypersetup{%
      pdftitle={Days on Diffraction Instructions for paper preparation and submission},
      pdfsubject={DDs submission},
      pdfauthor={\textcopyright I. Andronov},
      pdfcreator={\LaTeX with hyperref},
      pdfproducer={pdfLaTeX},
      pdfkeywords={DDs, submission},
      bookmarksopen=true,
      bookmarksopenlevel=1}
  \else
    \def\href#1#2{#2}
  \fi
\else
  \usepackage[dvips]{graphicx}
  \def\href#1#2{#2}
\fi
% end of PDFLATEX PART




%% Reset margins and text grid (Добавил headers)
\textwidth=\paperwidth
\advance\textwidth -2in
\columnwidth \textwidth \advance\columnwidth -\columnsep
\divide\columnwidth \tw@
\oddsidemargin \z@
\evensidemargin \z@
\advance \textheight \footskip \footskip \z@
\topmargin \paperheight \advance\topmargin -\textheight
\divide\topmargin \tw@ \advance\topmargin -1in

%% Заголовки и авторы
\global\let\@author\@empty
\global\let\@authora\@empty
\global\let\@authorb\@empty

\newlength{\TMPauthor}% Вспомогательная длина для определения пуста ли команда

% Определение \author с 3 аргументами
\global\def\author#1#2#3{\settowidth{\TMPauthor}{\@author}%
                         \ifdim\TMPauthor<1mm%
                              \gdef\@author{#1}\gdef\@affil{#2}\gdef\@email{#3}
                         \else\settowidth{\TMPauthor}{\@authora}%
                         \ifdim\TMPauthor<1mm%
                              \gdef\@authora{#1}\gdef\@affila{#2}\gdef\@emaila{#3}
                         \else
                              \gdef\@authorb{#1}\gdef\@affilb{#2}\gdef\@emailb{#3}
                         \fi\fi}

% Переопределили \maketitle, чтобы было можно использовать много раз
\renewcommand\maketitle{\par
  \begingroup
    \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}%
        \twocolumn[\@maketitle]%
  \endgroup
%%% Отменили переносы строки
\let\NEWLINE=\\
\let\\=\@empty
\settowidth{\TMPauthor}{\@authora}\ifdim\TMPauthor>1mm%
        \toks2=\expandafter{\@author}\xdef\@author{\the\toks2, \@authora}\fi
\settowidth{\TMPauthor}{\@authorb}\ifdim\TMPauthor>1mm%
        \toks2=\expandafter{\@author}\xdef\@author{\the\toks2, \@authorb}\fi
%%% написали ссылку в toc 
\addcontentsline{toc}{report}{\@author\protect\\ \@title}
%%% Вернули \\
\let\\=\NEWLINE
%%% Обнулили счетчики
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty  \global\let\@affil\@empty  \global\let\@email\@empty
  \global\let\@authora\@empty  \global\let\@affila\@empty  \global\let\@emaila\@empty
  \global\let\@authorb\@empty  \global\let\@affilb\@empty  \global\let\@emailb\@empty
  \global\let\@title\@empty
}

% Формат заголовка
\long\def\@maketitle{%
  \newpage
  \null
  {\centering
  \let \footnote \thanks
    {\LARGE\bfseries \@title \par}%
    \vskip 14pt%
    {\lineskip .5em%
       {\large\underline{\@author}}\\[1mm] \@affil
       \settowidth{\TMPauthor}{\@email}\ifdim\TMPauthor > 1mm
           ; \mbox{e-mail: \texttt{\@email}}\fi
\settowidth{\TMPauthor}{\@authora}
\ifdim\TMPauthor > 1mm
       \\[2mm] {\large\underline{\@authora}}\\[1mm] \@affila
       \settowidth{\TMPauthor}{\@emaila}\ifdim\TMPauthor > 1mm
           ; \mbox{e-mail: \texttt{\@emaila}}\fi
\settowidth{\TMPauthor}{\@authorb}
\ifdim\TMPauthor > 1mm
       \\[2mm] {\large\underline{\@authorb}}\\[1mm] \@affilb
       \settowidth{\TMPauthor}{\@emailb}\ifdim\TMPauthor > 1mm
           \\ e-mail:\texttt{\@emailb}\fi
\fi
\fi
}%
  \par}
  \vskip 14pt
}

%% Section headings
\renewcommand{\contentsname}{\centerline{\textbf{\sc CONTENTS}}}

\renewcommand\section{%
                                   \@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\scshape}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\large\itshape}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                     {-3ex\@plus -1ex \@minus -.2ex}%
                                     {1ex \@plus .2ex}%
                                     {\normalfont\itshape}}

%%% Redefinition of \@makecaption
%\long\def\@makecaption#1#2{\def\@capref{table}
%  \vskip\abovecaptionskip
%  \sbox\@tempboxa{#1: #2}%
%  \ifdim \wd\@tempboxa >\hsize
%    #1: #2\par
%  \else
%    \global \@minipagefalse
%    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
%  \fi
%  \vskip\belowcaptionskip
%  }

% Abstract 
\renewenvironment{abstract}{%
    \footnotesize\bfseries\parindent=0pt%
%    {\noindent\bf\textit{\abstractname{}} --- $\!$}
}%
    {\mdseries\par}

%% Roman subscripts
%\newcommand*{\ped}[1]{\ensuremath{_\mathrm{#1}}}

%% Reduce warning messages
\hbadness 5000 \vbadness 5000

%% DDs style
% the file name as the prefix
\newcommand{\labelprefix}{>>}
\let\LABEL\label
\let\LABELINDISPLAY\label@in@display
\renewcommand{\label}[1]{\LABEL{\labelprefix:#1}}
\providecommand{\label@in@display}[1]{\LABELINDISPLAY{\labelprefix:#1}}
\let\REF\ref
\renewcommand{\ref}[1]{\REF{\labelprefix:#1}}
\let\PAGEREF\pageref
\renewcommand{\pageref}[1]{\PAGEREF{\labelprefix:#1}}
\let\BIBITEM\bibitem
\renewcommand{\bibitem}[1]{\BIBITEM{\labelprefix::#1}}
\def\@citex[#1]#2{%
  \let\@citea\@empty
  \@cite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb}%
     \if@filesw\immediate\write\@auxout{\string\citation{\labelprefix::\@citeb}}\fi
     \@ifundefined{b@\labelprefix::\@citeb}{\mbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\labelprefix::\@citeb' on page \thepage \space undefined}}%
       {\hbox{\csname b@\labelprefix::\@citeb\endcsname}}}}{#1}}

% This is to count the number of talks automatically
\newcounter{NumberOfTalks}
\newcommand{\NumberOfTalksWrite}{%
 \immediate\write\@mainaux{\noexpand\newlabel{>>:N-O-T}{{\theNumberOfTalks}{0}}}}

\newcommand{\report}[1]{\global\def\@author{\@empty}
\renewcommand{\labelprefix}{#1}%
\stepcounter{NumberOfTalks}%
\typeout{(\theNumberOfTalks) =========================== #1 =====================}%
\begingroup
\setcounter{section}{0}%
\setcounter{figure}{0}%
\setcounter{table}{0}%
\setcounter{equation}{0}%
\input{#1.prc}
\endgroup}

% Headings
\pagestyle{myheadings}
\markboth{DAYS on DIFFRACTION' \noexpand\number\year}{DAYS on DIFFRACTION' \noexpand\number\year}

% Table of contents
\setcounter{tocdepth}{-2}
\newlength{\TOCspace}\setlength{\TOCspace}{2.5mm}
\newcommand{\l@report}[2]{\noindent\hspace*{0.05\textwidth}%
     \parbox[b]{0.9\textwidth}{\hspace*{-0.05\textwidth}#1
            \dotfill #2\hspace*{-0.05\textwidth}}\\[\TOCspace]}

% INDEX
\newcounter{INDEXcolumns}\setcounter{INDEXcolumns}{2}
\renewenvironment{theindex}{%
\addcontentsline{toc}{report}{\textsc{Author index}}%
\centerline{\sc Author index}%
\begin{multicols}{\theINDEXcolumns}%
\renewcommand{\item}{\par\noindent}}{\end{multicols}}

% CAPTIONS
\newcommand{\captionwidth}{0.9}
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1: #2}%
  \ifdim \wd\@tempboxa >\captionwidth\hsize
   \centerline{\parbox{\captionwidth\hsize}{#1: #2}}
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}


% Old commands
\newcommand{\speaker}[1]{\textbf{#1}}
\newcommand{\coauthor}[3]{\author{#1}{#2}{#3}}

\endinput


