%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                  %
%  This is alpha.sty, to be used with \documentclass{article}      %
%  of Latex2e. It is to be included with the command               %
%                                                                  %
%         \usepackage[<OPTIONS>]{alpha}                            %
%                                                                  %
%  It modifies the size of the section, subsection and appendix    %
%  titles and of figure and table captions. We include some        %
%  packages such as cite, graphicx, booktabs and hyperref.         %
%                                                                  %
%  [ To avoid clashes with hyperref, some packages need to be  ]   %
%  [ loaded after the present one in the main tex file, others ]   %
%  [ before.                                                   ]   %
%                                                                  %
%  OPTIONS = 'draft' will produce labels for references            %
%          = 'nohyper' does not load hyperref package              %
%                                                                  %
%  DEFAULTS = 'JHEP.bst' as bibtex style file if available,        %
%             standard public Latex 'ieeetr.bst' otherwise         %
%  _________________                                               %
%  PROVIDED COMMANDS                                               %
%                                                                  %
%   * \usebiblio{} to include *.bib files (w/o this command no     %
%                  reference section is included automatically)    %
%   * \maketitle   produces common ALPHA collab. title page using  %
%                                                                  %
%      + \title{}                                                  %
%      + \preprintno{}                                             %
%      + \collaboration{}                                          %
%      + \author[affil1,affil2]{Author1} ...                       %
%      + \address[affil1]{Affiliation1}  ...                       %
%      + \begin{abstract} ... \end{abstract}                       %
%      + \begin{keyword}  ... \PACS{...} \end{keyword}             %
%                                                                  %
%   * \begin{acknowledgement} ... \end{acknowledgement} produces   %
%     an acknowledgements section at current position              %
%                                                                  %
%   * \usechangever[vX.Y]{<text>}  if in draft mode outputs <text> %
%                                  on new pages at end of docum.   %
%                                                                  %
% --------------------------------- ALPHA collaboration, 2016 ---- %
%  v0.5, 27 Sep 2017, PF changed appearance of abstract            %
%  v0.4, 23 May 2016, PF, sidecap breaks caption style -> replaced %
%                     by caption package                           %
%  v0.3, 18 Jan 2014, PF added \usechangever[]{} for draft mode    %
%  v0.2, 18 Nov 2013, PF                                           %
%  v0.1, 11 Nov 2013, PF                                           %
%                                                                  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{alpha}
  [2016/05/23 v0.4 paper style file of ALPHA collaboration]
%---------------------------------------------------
% package option handling 
%
\newif\iflabelshow\labelshowfalse
\DeclareOption{draft}{%
  \typeout{[draft] mode set in alpha.sty}%
  \newif\iflabelshow\labelshowtrue
}
\newif\ifXbibkeys\Xbibkeysfalse
\DeclareOption{bibkeys}{%
  \typeout{[bibkeys] mode set in alpha.sty}%
  \newif\iflabelshow\labelshowfalse
  \newif\ifXbibkeys\Xbibkeystrue
}
\newif\ifnohyper\nohyperfalse
\DeclareOption{nohyper}{%
  \typeout{[nohyper] mode set in alpha.sty}%
  \newif\ifnohyperhow\nohypertrue
}
\ProcessOptions\relax
%---------------------------------------------------
% page layout
%
\RequirePackage[a4paper,top=3.35cm,bottom=3.35cm,left=3cm,right=3cm,nohead]{geometry}
\RequirePackage[T1]{fontenc} 
\renewcommand{\baselinestretch}{1.05}
\parindent=2em

%---------------------------------------------------
% minimal package list (to be loaded before hyperref)
%
\RequirePackage{cite}
\RequirePackage{amsmath,amsfonts,amssymb,amsbsy}
\RequirePackage{mathrsfs,latexsym}
\RequirePackage[rgb]{xcolor}
\RequirePackage{graphicx}
\RequirePackage{booktabs}
\RequirePackage{caption}

%---------------------------------------------------
% define colors for hyperref
%
\definecolor{darkred}{rgb}{0.4,0.0,0.0}
\definecolor{darkgreen}{rgb}{0.0,0.4,0.0}
\definecolor{darkblue}{rgb}{0.0,0.0,0.4}

%---------------------------------------------------
% hyperref
\ifnohyper
\else
\usepackage[bookmarks,linktocpage,colorlinks,
    linkcolor = darkred,
    urlcolor  = darkblue,
    citecolor = darkgreen
    ]{hyperref}
\fi
%---------------------------------------------------
% packages to be loaded after hyperref call
%
\iflabelshow
  \usepackage{showlabels}%
  \renewcommand{\showlabelfont}{\scriptsize\ttfamily}%
\fi
\ifXbibkeys
  \usepackage[notref]{showkeys}%
  \renewcommand{\showkeyslabelformat}[1]{{\normalfont\scriptsize\ttfamily\{#1\}}}%
\fi

%---------------------------------------------------
% modify figure and table captions
\usepackage[font={small},
            format=plain,
            labelfont={bf,footnotesize},
            textfont={rm},
]{caption}
%\captionsetup[SC-figure]{margin=10pt}

%---------------------------------------------------
% modification of section, subsection etc.
\renewcommand{\section}{\setcounter{equation}{0}
                                  \@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\reset@font\large\bfseries}}
\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\reset@font\normalsize\bfseries}}
\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\reset@font\normalsize\itshape}}
\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
                                    {3.25ex \@plus1ex \@minus.2ex}%
                                    {-1em}%
                                    {\reset@font\normalsize\bfseries}}
\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
                                       {3.25ex \@plus1ex \@minus .2ex}%
                                       {-1em}%
                                      {\reset@font\normalsize\bfseries}}

%---------------------------------------------------
% modify equation labelling

\renewcommand{\theequation}{\thesection.\arabic{equation}}
   
  \newcommand{\TABLE}[1]{\begin{table}
    \small
    \begin{center} {#1} \end{center}
    \end{table}}
  \newcommand{\FIGURE}[1]{\begin{figure}[tb]
    \begin{center} {#1} \end{center}
    \end{figure}}
  \newcommand{\FIGUREB}[1]{\begin{figure}[b]
    \begin{center} {#1} \end{center}
    \end{figure}}
  \newcommand{\FIGURET}[1]{\begin{figure}[t!]
    \begin{center} {#1} \end{center}
    \end{figure}}
  \newcommand{\FIGUREP}[1]{\begin{figure}[p!]
    \begin{center} {#1} \end{center}
    \end{figure}}
  \newcommand{\TABLEP}[1]{\begin{table}[p!]
    \footnotesize
    \begin{center} {#1} \end{center}
    \end{table}}
  \newcommand{\TABLET}[1]{\begin{table}[t!]
    \footnotesize
    \begin{center} {#1} \end{center}
    \end{table}}
  \newcommand{\TABLEH}[1]{\begin{table}[h!]
    \footnotesize
    \begin{center} {#1} \end{center}
    \end{table}}

%---------------------------------------------------
% special command(s)
%

\newcommand{\usebiblio}[1]{\def\@usebiblio{#1}}
\usebiblio{}
\newcommand{\preprintno}[1]{\def\@preprintno{#1}}
\preprintno{}
\newcommand{\collaboration}[1]{\def\@collaboration{#1}}
\collaboration{}
\newcommand{\usechangever}[2][vX.Y]{%
\def\@usechangever{%
\begin{flushright}
  \begin{tabular}{rl}
     \bf current version: & #1         \\  %     \bf started:         & Month Year \\
     \bf compile date:    & \today     \\
  \end{tabular}
\end{flushright}
\hrule
#2}
}
\usechangever{}


%---------------------------------------------------
% new environment(s)
%

\newenvironment{acknowledgement}{%
\vskip2em
\noindent{\normalsize\bf Acknowledgements.}~\small
}{%
\par}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% The following section uses and modifies some of the definition from    %%
%% `elsarticle.cls', to have a proper author-affiliation environment.     %%
%%                                                                        %%
%%  It was part of the 'Elsarticle Bundle' with the following License :   %%
%% ----                                                                   %%
%% It may be distributed under the conditions of the LaTeX Project Public %%
%% License, either version 1.2 of this license or (at your option) any    %%
%% later version.  The latest version of this license is in               %%
%%    http://www.latex-project.org/lppl.txt                               %%
%% and version 1.2 or later is part of all distributions of LaTeX         %%
%% version 1999/12/01 or later.                                           %%
%% ----                                                                   %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

\def\elsLabel#1{\@bsphack\protected@write\@auxout{}%
         {\string\Newlabel{#1}{\@currentlabel}}\@esphack}
\def\Newlabel#1#2{\expandafter\xdef\csname X@#1\endcsname{#2}}

\def\elsRef#1{\@ifundefined{X@#1}{0}{\csname X@#1\endcsname}%
}

\newcounter{fnote}
\def\fnmark[#1]{\let\comma\@empty
    \def\@fnmark{\@for\@@fnmark:=#1\do{%
    \edef\fnotenum{\@ifundefined{X@\@@fnmark}{1}{\elsRef{\@@fnmark}}}%
  \unskip\comma\fnotenum\let\comma,}}%
}

\let\@fnotes\@empty\let\@fnmark\@empty
\def\fntext[#1]#2{\g@addto@macro\@fnotes{%
     \refstepcounter{fnote}\elsLabel{#1}%
   \def\thefootnote{\thefnote}%
   \global\setcounter{footnote}{\thefnote}%
   \footnotetext{#2}}}

\def\cormark[#1]{\edef\cnotenum{\elsRef{#1}}%
    \unskip\textsuperscript{\sep\ifcase\cnotenum\or
       $\ast$\or$\ast\ast$\fi\hspace{-1pt}}\let\sep=,}

\let\@cormark\@empty
\let\@cornotes\@empty
\newcounter{cnote}
\def\cortext[#1]#2{\g@addto@macro\@cornotes{%
    \refstepcounter{cnote}\elsLabel{#1}%
    \def\thefootnote{\ifcase\thecnote\or$\ast$\or
    $\ast\ast$\fi}%
    \footnotetext{#2}}}

\let\@corref\@empty
\def\corref#1{\edef\cnotenum{\elsRef{#1}}%
    \edef\@corref{\ifcase\cnotenum\or
         $\ast$\or$\ast\ast$\fi\hskip-1pt}}

\def\fnref#1{\fnmark[#1]}
\def\tnoteref#1{\tnotemark[#1]}

\def\resetTitleCounters{\c@cnote=0
   \c@fnote=0 \c@tnote=0 \c@footnote=0}


\let\eadsep\@empty
\let\@elseads\@empty
\let\@elsuads\@empty
\let\@cormark\@empty
\def\hashchar{\expandafter\@gobble\string\~}
\def\underscorechar{\expandafter\@gobble\string\_}
\def\lbracechar{\expandafter\@gobble\string\{}
\def\rbracechar{\expandafter\@gobble\string\}}

\def\ead{\@ifnextchar[{\@uad}{\@ead}}
\gdef\@ead#1{\bgroup\def\_{\string\underscorechar\space}%
  \def\{{\string\lbracechar\space}%
   \def~{\hashchar\space}%
   \def\}{\string\rbracechar\space}%
   \edef\tmp{\the\@eadauthor}
   \immediate\write\@auxout{\string\emailauthor
     {#1}{\expandafter\strip@prefix\meaning\tmp}}%
  \egroup
}
\newcounter{ead}
\gdef\emailauthor#1#2{\stepcounter{ead}%
     \g@addto@macro\@elseads{\raggedright%
      \let\corref\@gobble
      \eadsep\texttt{#1} (#2)\def\eadsep{\unskip,\space}}%
}
\gdef\@uad[#1]#2{\bgroup
  \def~{\string\hashchar\space}%
  \def\_{\string\underscorechar\space}%
   \edef\tmp{\the\@eadauthor}
   \immediate\write\@auxout{\string\urlauthor
     {#2}{\expandafter\strip@prefix\meaning\tmp}}%
  \egroup
}
\def\urlauthor#1#2{\g@addto@macro\@elsuads{\let\corref\@gobble%
     \raggedright\eadsep\texttt{#1}\space(#2)%
     \def\eadsep{\unskip,\space}}%
}

\def\elsauthors{}
\def\pprinttitle{}
\let\authorsep\@empty
\let\sep\@empty
\newcounter{author}
\def\author{\@ifnextchar[{\@@author}{\@author}}

\newtoks\@eadauthor
\def\@@author[#1]#2{\g@addto@macro\elsauthors{%
    \def\baselinestretch{1}%
    \authorsep#2\unskip\textsuperscript{%#1%
      \@for\@@affmark:=#1\do{%
       \edef\affnum{\@ifundefined{X@\@@affmark}{1}{\elsRef{\@@affmark}}}%
     \unskip\sep\affnum\let\sep=,}%
      \ifx\@fnmark\@empty\else\unskip\sep\@fnmark\let\sep=,\fi
      \ifx\@corref\@empty\else\unskip\sep\@corref\let\sep=,\fi
      }%
    \def\authorsep{\unskip,\space}%
    \global\let\sep\@empty\global\let\@corref\@empty
    \global\let\@fnmark\@empty}%
    \@eadauthor={#2}
}

\def\@author#1{\g@addto@macro\elsauthors{\normalsize%
    \def\baselinestretch{1}%
    \upshape\authorsep#1\unskip\textsuperscript{%
      \ifx\@fnmark\@empty\else\unskip\sep\@fnmark\let\sep=,\fi
      \ifx\@corref\@empty\else\unskip\sep\@corref\let\sep=,\fi
      }%
    \def\authorsep{\unskip,\space}%
    \global\let\@fnmark\@empty
    \global\let\@corref\@empty
    \global\let\sep\@empty}%
    \@eadauthor={#1}
}

\def\elsaddress{}
\def\addsep{\par\vskip6pt}
\def\address{\@ifnextchar[{\@@address}{\@address}}

\def\@alph#1{%
  \ifcase#1\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or k\or
  l\or m\or n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or
  y\or z%
  \else\@ctrerr\fi}

\newcounter{affn}
\renewcommand\theaffn{\alph{affn}}

\long\def\@@address[#1]#2{\g@addto@macro\elsaddress{%
     \vskip0.3em
     \def\baselinestretch{1}%
     \refstepcounter{affn}
     \xdef\@currentlabel{$\theaffn$}
     \elsLabel{#1}%
     \textsuperscript{$\theaffn$}{\,#2}\par}}

\long\def\@address#1{\g@addto@macro\elsauthors{%
    \def\baselinestretch{1}%
    \addsep\vskip8pt
    \footnotesize\itshape#1
    \def\addsep{\par\vskip6pt}%
    \def\authorsep{\par\vskip8pt}
    }}

\newbox\absbox
\renewenvironment{abstract}{\global\setbox\absbox=\vbox\bgroup
  \hsize=\textwidth\def\baselinestretch{1}%
  \noindent\unskip\centerline{{\color{gray}\rule[0.3em]{0.4\textwidth}{0.4pt}\hfill}\textbf{Abstract}{\color{gray}\hfill\rule[0.3em]{0.4\textwidth}{0.4pt}}}
 \par\medskip\noindent\unskip\ignorespaces}
 {{\color{gray}\rule[0em]{\textwidth}{0.4pt}}\egroup}

\newbox\keybox
\def\keyword{%
  \def\sep{\unskip, }%
  \def\PACS{\par\leavevmode\hbox {\it PACS:\space}}%
  \global\setbox\keybox=\vbox\bgroup\hsize=\textwidth
  \small\normalfont\def\baselinestretch{1}
  \parskip\z@
  \noindent\textit{Keywords: }
  \raggedright                         % Keywords are not justified.
  \ignorespaces}
\def\endkeyword{\par \egroup}


%---------------------------------------------------
% composing ALPHA title page
%
\long\def\pprintMaketitle{
  {%\clearpage
  \thispagestyle{empty}%
  \ifx\@preprintno\@empty\relax
    \hspace*{1cm}\vskip50pt
  \else
    %\vskip-35pt
    \vspace*{-4em}
    {\footnotesize
    \begin{flushright}
       %\vskip-35pt
       \@preprintno
       \vskip25pt
    \end{flushright}
    }
  \fi
  \begin{center}%
   \enlargethispage{4ex}
   \def\baselinestretch{1}%
    \Large\bfseries\@title\par\vskip20pt\rm
    \ifx\@collaboration\@empty\relax
      \hspace*{1cm}\vskip5pt
    \else
      \vskip10pt
      \vbox{\makeatletter\@collaboration\makeatother}
      \vskip20pt
    \fi
    \normalsize\rm\elsauthors\par\vskip20pt
    %\footnotesize\itshape\elsaddress\par\vskip36pt
    \footnotesize\elsaddress\par\vskip36pt
    \vfill
    \ifvoid\absbox\else\unvbox\absbox\par\vskip20pt\fi
    \vfill
  \end{center}%
  \ifvoid\keybox\else\unvbox\keybox\par\vskip0pt\fi
  \gdef\thefootnote{\arabic{footnote} }%
  \clearpage%
  }%
  }

\def\maketitle{\pprintMaketitle\pagebreak}

%---------------------------------------------------
% last but not least
%

\AtBeginDocument{%
}

\AtEndDocument{%
%
% add bibliography
%
\ifx\@usebiblio\@empty\relax
\else
\small
\IfFileExists{alpha.bst}{\bibliographystyle{alpha}}{%
 \IfFileExists{JHEP.bst}{\bibliographystyle{JHEP}}{%
                         \bibliographystyle{ieeetr}
 }
}
\bibliography{\@usebiblio}
\fi
%
% add version/changes description page
%
\ifx\@usechangever\@empty\relax
\else
  \iflabelshow
  \clearpage
  \footnotesize
  \@usechangever
  \fi
\fi
}

\endinput