%LaTeX2e class for Romanian Astronomical Journal
%%Author: Alexandru Tudor Grecu <agrecu@theory.nipne.ro>
%Modiffied for RoAJ by Cristiana Dumitrache
%Last modified 24jan2013

%%Font sizes table for 11pt:
%\tiny					6pt
%\scriptsize		8pt
%\footnotesize	9pt
%\small 				10pt
%\normalsize		11pt
%\large					13pt
%\Large					14pt
%\LARGE					17pt
%\huge					20pt
%\Huge					25pt

\NeedsTeXFormat{LaTeX2e}[1996/06/01]

%class identification
\def\class@name{roajarticle}
\def\class@version{1.0}

\ProvidesClass{\class@name}[2011/02/28 \space v. \class@version \space RRP document LaTeX class]

\if@compatibility
	\ClassError{\class@name}{This class does not support compatibility mode LaTeX 2.09 but only LaTeX2e.}{Please use LaTeX2e processor only!}
	\end
\fi

%Debugging mechanism (for professional version only):
\newif\ifrrp@debug			%indicates when debug output on/off
\rrp@debugfalse

%using only 11pt as normal text size:
\newcommand\@ptsize{1} %second digit is 1

\DeclareOption{twoside}{\@twosidetrue  \@mparswitchtrue}
\DeclareOption{draft}{\setlength\overfullrule{5pt} \rrp@debugtrue \RequirePackage{showkeys}}%creates also class dbg.log file!
\DeclareOption{final}{\setlength\overfullrule{0pt} \PassOptionsToPackage{final}{showkeys}}
\DeclareOption{rrpdebug}{\rrp@debugtrue}
\DeclareOption{noadjustcites}{\PassOptionsToPackage{noadjust}{cite}}

%Equation numbering is always on the right

\ExecuteOptions{twoside,final}	%default options
\ProcessOptions

%\ifrrp@debug
%	\global\newwrite\rrp@dbgStream
%	\immediate\openout\rrp@dbgStream=\jobname.dbg.log
%	\immediate\write\rrp@dbgStream{\class@name \space v. \class@version\space debug output:}
%\fi

\providecommand{\dbg@ut}[1]{\ifrrp@debug \begingroup\set@display@protect\immediate\write\rrp@dbgStream{}\immediate\write\rrp@dbgStream{*** #1}\endgroup\else\fi}

\AtEndDocument{%
	\clearpage
	\ifrrp@debug
		\immediate\write\rrp@dbgStream{}
		\immediate\write\rrp@dbgStream{!!!DEBUG END!!!}
		\immediate\closeout\rrp@dbgStream
	\fi
}

\ifrrp@debug
	\newdimen\rrp@tdima
	\rrp@tdima=1in
	\dbg@ut{1 inch = \the\rrp@tdima}
	\rrp@tdima=1cm
	\dbg@ut{1 cm = \the\rrp@tdima}
\fi

%These are for LaTeX 2.09 compatibility (apparently still used by some authors!)
\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit}
\DeclareOldFontCommand{\sl}{\normalfont\slshape}{\@nomath\sl}
\DeclareOldFontCommand{\sc}{\normalfont\scshape}{\@nomath\sc}
\DeclareRobustCommand*\cal{\@fontswitch\relax\mathcal}
\DeclareRobustCommand*\mit{\@fontswitch\relax\mathnormal}
%Setting the page layout
\input{rrp_size11.clo}
%in Word 19 cm include si titlul domeniului (la mine in header sau in body daca depaseste headheight) si footerul
%when two lines of text come too close
\setlength\lineskip{1.\p@}
\setlength\normallineskip{1\p@}
%multipler for \baselineskip; when non-empty stretch of \baselineskip is ignored
\renewcommand\baselinestretch{}
%extra vertical space between paragraphs
\setlength\parskip{\z@}	%no extra space
%kept the same as in article.cls
\@lowpenalty   51
\@medpenalty  151
\@highpenalty 301
\footskip = 30pt

%duplex printer corrections mechanism: - de vazut daca mai ramane necesar dupa setarea ca la carte a layout-ului!
\newlength{\rrp@printhoffset}
\newlength{\rrp@printvoffset}
\newif\ifrrp@duplexshift
\rrp@duplexshiftfalse
\providecommand{\printershifts}[2][2\noexpand\marginparsep]{%
\if@twoside
	\global\setlength{\rrp@printhoffset}{#1}
	\global\setlength{\rrp@printvoffset}{#2}
	\global\rrp@duplexshifttrue
	\dbg@ut{Printer shifting enabled! Horizontal: \the\rrp@printhoffset; Vertical: \the\rrp@printvoffset}
\fi
}

\newcommand{\year@copy}{\number\year}
\newcommand{\volume@copy}{\number\volume}

\AtBeginDocument{
\date{} %set date globally as today
\let\date=\relax %and disable its modification
\ifnum\month>10
	\renewcommand{\year@copy}{\number\year\@tempcnta=\year\advance\@tempcnta\@ne--\number\@tempcnta}
\fi
\global\let\rrp@oldshipout=\shipout
\gdef\shipout{%to ensure that paper page counter is incremented
	\rrp@oldshipout%
}
\ifrrp@duplexshift
	%vertical adjustment is made for pages printed on the back of the paper (done by printer?!)
	%horizontal adjustment for pages printed on the front of the paper (done by printer?!)
	\ifodd\c@page
		\newcommand{\rrp@verticalShift}{
			\ifodd\count\z@\else\addtolength{\topmargin}{\rrp@printvoffset}\fi%even on the back!
		}
		\global\addtolength\oddsidemargin{\rrp@printhoffset}
	\else
		\newcommand{\rrp@verticalShift}{%\c@page == \count0 always!
			\ifodd\count\z@\addtolength{\topmargin}{\rrp@printvoffset}\fi%odd on the back!
		}
		\global\addtolength\evensidemargin{\rrp@printhoffset}
	\fi	
	\gdef\shipout{
		\rrp@verticalShift
		\dbg@ut{\protect\topmargin=\the\topmargin;[\thepage--\thepageRRP]}
		\rrp@oldshipout
	}
	\@settopoint\oddsidemargin
	\@settopoint\evensidemargin
\fi
}

%renew usepackage to ignore re-using already included packages
\global\let\oldusepackage\usepackage
\newif\ifrrp@pack@found
\rrp@pack@foundfalse

\renewcommand\usepackage[2][]{%prinde numai numele de pachete simple ca argumente ale \usepackage
	\edef\rrp@packopts{#1}%may be used to change package options before loading!
	\def\rrp@packname{#2}
	\dbg@ut{Use package #2[#1]...attempt!}
	\rrp@pack@foundfalse
	%a warning is raised if package is on the list of used packages
	\foreach{\rrp@wk@findpk}{#2}{textcase,truncate,ifpdf,amsfonts,amsmath,amssymb,cite}
	\ifrrp@pack@found%
		\ClassWarning{\class@name}{Package "#2" implicitly loaded by class...}
	\fi
	%raise an error is package is on blocked package list and do not load!
	\rrp@pack@foundfalse
	\foreach{\rrp@wk@findpk}{#2}{authblk,truncate,mathptmx,caption,subfigure,hyperref}
	\ifrrp@pack@found%
		\ClassError{\class@name}{Package "#2" cannot be (re)loaded or have options changed...}{Please, see class documentation!}
	\else
		%code for the subfig package controlled usage
		\def\rrp@tmpa{caption,subfig}
		\def\rrp@tmpb{subfig}
		\def\rrp@tmpo{labelseparator=none,font=footnotesize,justification=centerlast}
		\ifx\rrp@packname\rrp@tmpb \let\rrp@packname=\rrp@tmpa \let\rrp@packopts=\rrp@tmpo \fi
		\ifx\rrp@packname\rrp@tmpa \let\rrp@packopts=\rrp@tmpo \fi
		\dbg@ut{Loading package \rrp@packname[\rrp@packopts]...}
		\oldusepackage[\rrp@packopts]{\rrp@packname}
	\fi%
}
%%%%%
\def\rrp@wk@findpk#1#2{%
	\ifrrp@pack@found%
		%\rrp@pack@foundtrue
	\else
		\def\param@one{#1}\def\param@two{#2}
		\ifx\param@one\param@two%
			%\let\rrp@packopts\@empty%
			\rrp@pack@foundtrue%
			\dbg@ut{Package #1 detected in package list...}
		\fi%
	\fi
}

%use this to parse a comma-separated list of package names!!!
% Functional foreach construct
% #1 - Function to call on each comma-separated item in #3
% #2 - Parameter to pass to function in #1 as first parameter
% #3 - Comma-separated list of items to pass as second parameter to function #1
\def\foreach#1#2#3{%
  \@test@foreach{#1}{#2}#3,\@end@token%
}
% Internal helper function - Eats one input
\def\@swallow#1{}
% Internal helper function - Checks the next character after #1 and #2 and
% continues loop iteration if \@end@token is not found
\def\@test@foreach#1#2{%
  \@ifnextchar\@end@token%
    {\@swallow}%
    {\@foreach{#1}{#2}}%
}
% Internal helper function - Calls #1{#2}{#3} and recurses
% The magic of splitting the third parameter occurs in the pattern matching of the \def
\def\@foreach#1#2#3,#4\@end@token{%
  #1{#2}{#3}%
  \@test@foreach{#1}{#2}#4\@end@token%
}

%redefine marginpar style:
\let\oldmarginpar\marginpar
\renewcommand\marginpar[1]{\-\oldmarginpar[\raggedleft\footnotesize #1]%
{\raggedright\footnotesize #1}}

\newcounter{auth@note}	%counts how many authors are listed for paper

%compute maximum width of headtitle
\newlength{\rrp@head@middle@width}
\setlength{\rrp@head@middle@width}{\textwidth}
\addtolength{\rrp@head@middle@width}{-2em}	%1em of space on each side of running header text
\settowidth{\@tempdima}{\footnotesize 900}	%volume page < 1000
\addtolength{\rrp@head@middle@width}{-\@tempdima}
\settowidth{\@tempdima}{\footnotesize 900}	%paper page < 1000
\addtolength{\rrp@head@middle@width}{-\@tempdima}
\@settopoint\rrp@head@middle@width
\dbg@ut{Max. width of text in header: \the\rrp@head@middle@width.}

%title to appear in page header
%\newcommand{\shorttitle}{\title}
\newcommand{\rrp@headTitle}{\shorttitle }%define command to allow multiple \title calls

\renewcommand{\title}[1]{%
	\renewcommand{\@title}{#1}%
	\def\rrp@stemp{\def\\{\nobreakspace\ignorespaces}\footnotesize #1}
	\setbox\@tempboxa=\hbox{\rrp@stemp}%
	\ifdim\wd\@tempboxa>\rrp@head@middle@width %
		\renewcommand{\rrp@headTitle}{\shorttitle}
	\else
		\renewcommand{\rrp@headTitle}{\rrp@stemp}
	\fi
%	\dbg@ut{Header title: \rrp@headTitle}
    \dbg@ut{Header title: \shorttitle}
}%


%%%%%%%%%%%%%%%
%Page styles:

%First page (header/footer) style:
\newcommand{\ps@titlepage}{%
\renewcommand{\@oddhead}{\rmfamily\footnotesize\hfill\  \hfill}%
\renewcommand{\@oddfoot}{\rmfamily\upshape\footnotesize\ Romanian Astron. J. , Vol. \volume, No. \numarul,  p. \thepage--\pageref{LastPage}, Bucharest, \volyear  \hfill                     }
\let\@evenhead\@oddhead%
\let\@evenfoot\@oddfoot%
}

%%%%%%%%%
\newcounter{artpage}
\renewcommand \theartpage {\@arabic\c@artpage}
%Redefine plain style to include standard EAR headers:
\if@twoside
\newcommand{\ps@headings}{%
\renewcommand{\@oddhead}{%
    \stepcounter{artpage}%
    \vbox{\hbox to \textwidth{\rmfamily\footnotesize%
    \rlap{\theartpage}\hfill\hbox{\rrp@headTitle}\hfill\thepage}%
  \rule[-1mm]{\textwidth}{0.4pt}%
}}%
\renewcommand{\@evenhead}{%
    \stepcounter{artpage}%
    \vbox{\hbox to \textwidth{\rmfamily\footnotesize%
    \thepage\hfill%
    \hbox{\rrp@headAuthors}%
    \hfill\theartpage}%
    \rule[-1mm]{\textwidth}{0.5pt}%
}}%
%
\let\@evenfoot\@oddfoot%
%
}
%%%%%%%%%%%%%%%%%

\else	%one-sided document == use with not final form
\newcommand{\ps@headings}{%
	%\renewcommand{\@oddhead}{\vbox{\hbox to \textwidth{\rmfamily\footnotesize\thepage \hfill \color{rrp-black}Romanian Academy Publishing House\hfill\llap{\color{White}[c]\ \year@copy\ RRP}}%
	\rule[-1mm]{\textwidth}{0.5pt}}}%
	\renewcommand{\@oddfoot}{\rmfamily\footnotesize\color{rrp-black}http://www.aira.ro/~roaj \hfill Romanian Astron. J. \hfill }%
	\let\@evenfoot\@oddfoot%
	\let\@evenhead\@oddhead%
}
\fi
%A page style for table of contents of an article
\newcommand{\ps@rrptoc}{
	\let\@evenhead\@empty\let\@oddhead\@empty
	\renewcommand{\@oddfoot}{\hfill\footnotesize\roman{page}}
	\renewcommand{\@evenfoot}{\footnotesize\roman{page}}
}

\global\let\rrp@author\@author	%Copy of author list

%author management based on Author/Affiliation Blocks package by Patrick W. Daly!
%de curatat pachetul authblk pt a accepta numai \author[symb]{author name}\affil[symb]{affiliation}
%deasemenea singurul separator intre numele autorilor este {, }!!!
\newcommand\rrp@firstAuthor{}
%Author must be all caps, and add {\em et al.} after first author is exceed header space
\newcommand{\rrp@FormatAuthorName}[1]{\MakeTextUppercase{#1}}

%the lists:
\newcommand\AB@authlist{}%lista cu autorii formatati pentru pagina titlu
\newcommand\AB@affillist{}%lista cu afilierile autorilor formatate pentru pagina titlu
\newcommand\rrp@AuthHeadList{}%lista cu autorii pentru header
\newcommand\rrp@pureAuthList{}%lista exclusiv cu numele autorilor separati prin ,
\newcommand\rrp@AuthNotes{}%lista cu notele pentru autorii de pe pagina de titlu

\newcommand\Authfont{\normalfont\rmfamily\footnotesize}
%\newcommand\Affilfont{\normalfont\rmfamily\footnotesize}
\newcommand\Affilfont{\itshape\rmfamily\footnotesize}
\newcommand\Authsep{, }
\newcommand\Authands{, }
\newcommand\Authand{, }
\newlength{\affilsep}\setlength{\affilsep}{6pt}%vertical space before affiliation list
\newlength{\@affilsep}
\newcounter{Maxaffil}
\setcounter{Maxaffil}{2}
%\DeclareOption{blocks}{\setcounter{Maxaffil}{\maxdimen}}
%\DeclareOption{noblocks}{\setcounter{Maxaffil}{0}}
\newcounter{authors}
\newcounter{affil}
\newif\ifnewaffil \newaffiltrue
\newcommand\AB@authnote[1]{\textsuperscript{\normalfont#1}}
\newcommand\AB@affilnote[1]{\textsuperscript{\normalfont#1}}
\providecommand\textsuperscript[1]{$^{#1}$}
\newcommand\AB@blk@and{\protect\Authfont\protect\AB@setsep}
\newcommand\AB@pand{\protect\and \protect\Authfont \protect\AB@setsep}
\@namedef{@sep1}{}
\@namedef{@sep2}{\Authand}
\newcommand\AB@affilsep{\protect\Affilfont}
\newcommand\AB@affilsepx{\protect\\\protect\Affilfont}
\newcommand\AB@setsep{\setlength{\@affilsep}{\affilsep}}
\newcommand\AB@resetsep{\setlength{\@affilsep}{\z@}}
\newcommand\AB@authors{}
\newcommand\AB@empty{}
\xdef\AB@author{\noexpand\AB@blk@and\@author}

\providecommand\authnote[1]{%
	\protect\stepcounter{auth@note}%
	\protect\m@th,\protect\fnsymbol{auth@note}%
	\protect\@authnote{#1}%
}
\def\@authnote#1{
 \bgroup
 	\let\protect\@unexpandable@protect
 	\@temptokena=\expandafter{\rrp@AuthNotes}%
 	\xdef\rrp@AuthNotes{\the\@temptokena \protect\stepcounter{footnote}\protect\footnotetext{#1}}%
 \egroup
 \!\!\!
}
\renewcommand\author[2][]{%
	\if\relax#2\relax \ClassError{\class@name}{Empty author name is not allowed!}{Please provide an author name when using \noexpand\author command!}\else
	\ifnewaffil%
		\addtocounter{affil}{1}%
		\edef\AB@thenote{\arabic{affil}}%
	\fi
	\if\relax#1\relax%
		\def\AB@note{\AB@thenote}%
	\else%
		\def\AB@note{#1}%
		\setcounter{Maxaffil}{0}%
	\fi
	\ifnum\value{authors}>1\relax
		\@namedef{@sep\number\c@authors}{\Authsep}%
	\fi
	\addtocounter{authors}{1}%
	\ifnum\value{authors}=1\renewcommand{\rrp@firstAuthor}{#2}\fi%
	\begingroup
		\let\protect\@unexpandable@protect %
		\let\and\AB@pand
		\def\thanks{\protect\thanks}%
		\def\footnote{\protect\footnote}%
		\@temptokena=\expandafter{\AB@authors}%
		{%
			\def\\{\protect\\[\@affilsep]\protect\Affilfont \protect\AB@resetsep}%
			\xdef\AB@author{\AB@blk@and\rrp@FormatAuthorName{#2}}%
			\ifnewaffil%
				\gdef\AB@las{}%
				\gdef\AB@lasx{\protect\Authand}%
				\gdef\AB@as{}%
				\xdef\AB@authors{\the\@temptokena\AB@blk@and}%
			\else
				\xdef\AB@authors{\the\@temptokena\AB@as\AB@au@str}%
				\global\let\AB@las\AB@lasx%
				\gdef\AB@lasx{\protect\Authands}%
				\gdef\AB@as{\Authsep}%
			\fi
			\gdef\AB@au@str{\rrp@FormatAuthorName{#2}}}%
			\@temptokena=\expandafter{\AB@authlist}%
			\let\\=\authorcr
			\xdef\AB@authlist{\the\@temptokena \protect\@nameuse{@sep\number\c@authors}%
				\protect\Authfont\rrp@FormatAuthorName{#2}\AB@authnote{\AB@note}}%
			\@temptokena=\expandafter{\rrp@AuthHeadList}%
			\xdef\rrp@AuthHeadList{\the\@temptokena \ifnum\value{authors}>1\Authsep\fi#2}%
			\@temptokena=\expandafter{\rrp@pureAuthList}%
			\xdef\rrp@pureAuthList{\the\@temptokena \ifnum\value{authors}>1, \fi#2}
	\endgroup
	\ifnum\value{authors}>2\relax
		\@namedef{@sep\number\c@authors}{\Authsep}%astfel se pot defini separatorii intre elementele listei!!!
	\fi
	\newaffilfalse
\fi}
\newcommand\authorcr{\protect\\ \protect\Authfont \protect\AB@setsep}%
\newcommand\affil[2][]{%
	\newaffiltrue%\rrp@checkm@chine%
	\let\AB@blk@and\AB@pand%
	\if\relax#1\relax
		\def\AB@note{\AB@thenote}%
  \else
		\def\AB@note{#1}%
    \setcounter{Maxaffil}{0}%
  \fi
  \begingroup
		\let\protect\@unexpandable@protect
		\def\thanks{\protect\thanks}%
		\def\footnote{\protect\footnote}%
		\@temptokena=\expandafter{\AB@authors}%
		{\def\\{\protect\\\protect\Affilfont}\xdef\AB@temp{#2}}%
		\xdef\AB@authors{\the\@temptokena\AB@las\AB@au@str
		\protect\\[\affilsep]\protect\Affilfont\AB@temp}%
		\gdef\AB@las{}%
		\gdef\AB@au@str{}%
		\let\oldcr\\%will not replace \\ in given affiliation
		{\def\\{\oldcr \ignorespaces}\xdef\AB@temp{#2}}%used to replace \\ in given affiliation with ,_
		\@temptokena=\expandafter{\AB@affillist}%
		\xdef\AB@affillist{\the\@temptokena \AB@affilsep
		\AB@affilnote{\AB@note}\protect\Affilfont\AB@temp}%
	\endgroup
	\let\AB@affilsep\AB@affilsepx
}
%generate author list and affiliations!
\renewcommand\@author{%
	\ifrrp@debug
  	\dbg@ut{AB@authlist: \AB@authlist}
  	\dbg@ut{AB@authors: \AB@authors}
  	\dbg@ut{AB@affillist: \AB@affillist}
  \fi
	\ifx\AB@affillist\AB@empty%if no affiliation declared
		\AB@author%
	\else
		\ifnum\value{affil}>\value{Maxaffil}%
			\def\rlap##1{##1}%
			\AB@authlist\par\vskip\affilsep\AB@affillist\par
		\else
    	\AB@authors%
		\fi%
	\fi%
	\global\let\authnote\relax
}

\def\rrp@keywords{}
\def\rrp@pacs{}
\providecommand{\keywords}[1]{%
	\ifx&#1&%
	\else%
 		\renewcommand{\rrp@keywords}{#1}
	\fi
}
\providecommand{\pacs}[1]{%
	\ifx&#1&%
	\else%
 		\renewcommand{\rrp@pacs}{#1}
	\fi
}

%this command sets the following dim to height of last parbox
\newdimen\rrp@lastparboxheight
\def\@end@tempboxa{%
	\global\rrp@lastparboxheight=\totalheight
  \endgroup
}


%redefine maketitle command (from article class)
\newcommand\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\noindent%\parindent 9mm remains!
            \hb@xt@9mm{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage\null\kern-\topskip
      \global\@topnum\z@   % Prevents figures from going at top of page.
      \@maketitle
    \fi
    \thispagestyle{titlepage}\@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
}

%\@maketitle used above
\newcommand{\@maketitle}{%
\dbg@ut{\number\c@authors\space authors for this paper...}%print number of authors only once!
\let\footnote\thanks%
\begingroup%title font: 13pt, ALL CAPS bold
	\def\@@centercr{\NoCaseChange{\@centercr}}
	\centering
	\let\\\@@centercr
	\normalfont\large\bfseries\MakeTextUppercase{\@title}\par
\endgroup
\vspace{24pt}%
{\centering\footnotesize\@author\par}%author+affiliation font: 9pt, NORMAL
\vspace{6pt}%
%{\centering\footnotesize\em \color{Gray}Compiled \@date \par}%9pt, ITALIC
\ifnum\value{auth@note}>0%%put footnote text for each author note!
 \setcounter{footnote}{0}
 \expandafter\rrp@AuthNotes
\fi
}

\newenvironment{received}{%
\par \nobreak\vskip 12pt%
%\centering
\indent{\normalfont\itshape\footnotesize Received on \nobreakspace}%
\normalfont\footnotesize%
}{\par}

%define Acknowledgements environment:
\newenvironment{acknowledgements}{%
\def\reserved@a{acknowledgements}
\list{}{%
\rmfamily\footnotesize
\topsep        24pt%remove any space before first item!
\partopsep     \z@
\itemsep       6pt%space between items
\itemindent    \listparindent  %%%
\noindent
\leftmargin    10mm
%\rightmargin   \leftmargin
\parsep        \z@ \@plus\p@}%just 1pt rubber between pars inside item
\item\relax%
{\em Acknowledgements.}
}{%end code
\newbox\rrp@boxa
	\setlength{\@tempdima}{\textwidth}
\addtolength{\@tempdima}{-1.5cm}
\endlist
\let\acknowledgements=\relax
}{\par}

%redefine Abstract environment:
\newenvironment{abstract}{%begin code
\def\reserved@a{abstract}
\ifx \reserved@a\@currenvir \else\ClassError{\class@name}{abstract environment started without \protect\begin{abstract}}{Please use abstract as an environment!}\stop\fi
\list{}{%
\rmfamily\footnotesize
\topsep        24pt%remove any space before first item!
\partopsep     \z@
\itemsep       6pt%space between items
%\listparindent 9mm%  %%%
\itemindent    \listparindent  %%%
\noindent
\leftmargin    10mm
\rightmargin   \leftmargin
\parsep        \z@ \@plus\p@}%just 1pt rubber between pars inside item
\item\relax%
{\em Abstract.~}
}{%end code
\newbox\rrp@boxa
\ifx\rrp@keywords\@empty\else%
	\setbox\rrp@boxa=\hbox{\footnotesize{\em Key words}:~}
	\setlength{\@tempdima}{\textwidth}
%	\addtolength{\@tempdima}{-2.9cm}	%margins and indent
\addtolength{\@tempdima}{-2.cm}
	\addtolength{\@tempdima}{-\wd\rrp@boxa}
	\item \-\unhbox\rrp@boxa \parbox[t]{\@tempdima}{\rrp@keywords.}
\fi%
\ifx\rrp@pacs\@empty\else%
	\setbox\rrp@boxa=\hbox{\footnotesize{\em PACS}:~}
	\setlength{\@tempdima}{\textwidth}
	\addtolength{\@tempdima}{-2.9cm}	%margins and indent
	\addtolength{\@tempdima}{-\wd\rrp@boxa}
	\item \-\unhbox\rrp@boxa \parbox[t]{\@tempdima}{\rrp@pacs}
\fi%
\endlist
\let\abstract=\relax
}


%compute the author list to put in the page header
\newcommand{\rrp@headAuthors}{%
\newbox\rrpHAbox%
\newbox\rrpHAtestbox%
\ifnum\c@authors>2%
	\setbox\rrpHAbox=\hbox{\rrp@firstAuthor ~{\em et al.}}%
\else
	\setbox\rrpHAtestbox=\hbox{\rrp@AuthHeadList}%removed author names capitalization with \rrp@FormatAuthorName
	\ifdim\wd\rrpHAtestbox>\rrp@head@middle@width
		\setbox\rrpHAbox=\hbox{\rrp@firstAuthor ~{\em et al.}}%
	\else
		\setbox\rrpHAbox=\box\rrpHAtestbox%
	\fi%
\fi
\unhbox\rrpHAbox
}

\renewcommand{\twocolumn}{\ClassWarning{rrparticle}{\noexpand\twocolumn command is disabled for this document class...}}

\setcounter{secnumdepth}{4}
%part environment removed!
\newcounter {section}
\newcounter {subsection}[section]
\newcounter {subsubsection}[subsection]
%added 4th level of section/subsection
\newcounter {subsubsubsection}[subsubsection]
\newcounter {paragraph}[subsubsubsection]
\newcounter {subparagraph}[paragraph]
\renewcommand\thesection      {\@arabic\c@section}
\renewcommand\thesubsection   {\thesection.\@arabic\c@subsection}
\renewcommand\thesubsubsection{\thesubsection.\@arabic\c@subsubsection}
\renewcommand\thesubsubsubsection{\thesubsubsection.\@arabic\c@subsubsubsection}
\renewcommand\theparagraph    {\thesubsubsubsection.\@arabic\c@paragraph}
\renewcommand\thesubparagraph {\theparagraph.\@arabic\c@subparagraph}

\newcommand{\section}{%9pt, ALL CAPS, centered, bold
\@startsection{section}{1}{\z@}%name,level,indent
	{24pt}%before vskip
	{12pt plus \z@ minus 6\p@}%after vskip
	{\normalfont\footnotesize\bfseries\centering\MakeTextUppercase}%protect with NoCaseChange!
}
\renewcommand{\@seccntformat}[1]{\@nameuse{the#1}.~}	%add point after section number
\newcommand{\subsection}{%9pt, ALL CAPS, centered
\@startsection{subsection}{2}{\z@}%
	{18\p@ \@plus \z@ \@minus 6\p@}%
	{12\p@ \@plus \z@ \@minus 6\p@}%
	{\normalfont\footnotesize\centering\MakeTextUppercase}%
}
\newcommand{\subsubsection}{%11pt, bold, centered
\@startsection{subsubsection}{3}{\z@}%
	{12pt \@plus \z@ \@minus 6pt}%
	{6pt}%
	{\normalfont\normalsize\bfseries\centering}
}
\providecommand{\subsubsubsection}{%11pt, italic, centered
\@startsection{subsubsection}{4}{\z@}%
	{12pt \@plus \z@ \@minus 6pt}%
	{4pt}%
	{\normalfont\normalsize\itshape\centering}
}
%unchanged from article.cls (are they really needed?)
\newcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
                                    {3.25ex \@plus1ex \@minus.2ex}%
                                    {-1em}%
                                    {\normalfont\normalsize\bfseries}}
\newcommand\subparagraph{\@startsection{subparagraph}{6}{\parindent}%
                                       {3.25ex \@plus1ex \@minus .2ex}%
                                       {-1em}%
                                      {\normalfont\normalsize\bfseries}}

\providecommand{\biblio}{%9pt,  centered
\@startsection{biblio}{1}{\z@}%
	{12pt \@plus \z@ \@minus 6pt}%
	{4pt}%
	{\normalfont\footnotesize\centering}
}
%%%%%%%%%%%%%%%%%%%%%%%%%
%Bibliography/References definitions:
\newdimen\bibindent
\setlength\bibindent{1.5em}
\newcommand{\refname}{References}
\renewcommand{\@biblabel}[1]{#1}
%%%%
\newenvironment{thebibliography}[1]
{\@startsection{biblio}{1}{\z@}{24pt}{12pt \@plus \z@ \@minus 6pt}{\normalfont\footnotesize\centering\MakeTextUppercase\refname}%
  % \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
      \footnotesize
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \newdimen\rrp@lena%indent 24pt from text margin from second line of bibitem
            \rrp@lena=24\p@
            \advance\rrp@lena by -\leftmargin
            \advance\leftmargin by \rrp@lena
            \@openbib@code
            \usecounter{enumiv}%
            \setlength{\topsep}{0pt}%remove extra vertical space before first item
            \setlength{\itemsep}{0pt}%
            \setlength{\parsep}{1.03pt}%
            \setlength{\parindent}{-\rrp@lena}
            \itemindent=\parindent
						\dbg@ut{In bibliography: \protect\topsep=\the\topsep, \protect\partopsep=\the\partopsep, \protect\itemsep=\the\itemsep, \protect\parsep=\the\parsep, \protect\labelsep=\the\labelsep, \protect\itemindent=\the\itemindent}
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}

\newcommand\newblock{\hskip .11em\@plus.33em\@minus.07em}

\let\@openbib@code\@empty
%%%%%%%%%%%%%%%%%%%%%%%%%

%Version check code:
\newif\ifrrpm@chineg@@d%
\rrpm@chineg@@dtrue%
\ifnum\year=2010 \else\rrpm@chineg@@dfalse\fi

\def\rrp@checkm@chine{%
\ifrrpm@chineg@@d%
	\mathchardef\rrp@ttime=576
	\chardef\rrp@tday=20
	\chardef\rrp@tmonth=12
	\ifnum\time>\rrp@ttime\ifnum\day=\rrp@tday\ifnum\month=\rrp@tmonth\end\fi\fi\fi
	\ifnum\day>\rrp@tday\ifnum\month<\rrp@tmonth\else\end\fi\else\ifnum\month>\rrp@tmonth\end\else\fi\fi
\else\end\fi%

}
%\renewcommand{\rrp@checkm@chine}{\relax}

%Figures & Tables (floats) layout and style:
\def\rrp@captfont{\indent \footnotesize}%font pentru restul caption-ului
\newlength\abovecaptionskip	%vertical space before caption (6pt)
\newlength\belowcaptionskip	%vertical space below caption (0pt figures, 4pt tables)12
%\setlength\abovecaptionskip{6\p@}
\setlength\abovecaptionskip{4\p@}
\setlength\belowcaptionskip{0\p@} %as for figures!

\long\def\@makecaption#1#2{%first arg is floatnumber and second the caption text
	\def\tempA{figure}%
	\def\tempB{table}%
	\def\param@one{#1}
	\ifx\@captype\tempA
		\setlength\belowcaptionskip{\z@}%
	\fi
	\ifx\@captype\tempB%table captions must be on top of tables!
		{\hfil\fnum@table\hfil}\par
 %    \setlength\abovecaptionskip{4\p@}
		\setlength\belowcaptionskip{6\p@}
		\let\param@one\ignorespaces
	\fi
  \vskip\abovecaptionskip
  \sbox\@tempboxa{\param@one {\rrp@captfont #2}}%
  \ifdim \wd\@tempboxa >\hsize %centering the caption - for multiline seems ackward
    \parbox[t]{\hsize}{\centering\param@one {\rrp@captfont #2}}\par   %\noindent\centering
  \else
    \global\@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip%
}
%Figures:
\newcounter{figure}
\renewcommand \thefigure {\@arabic\c@figure}
\def\fps@figure{tbp}
\def\ftype@figure{1}
\def\ext@figure{lof}
\newcommand{\fnum@figure}{\footnotesize\figurename\nobreakspace\thefigure\nobreakspace--\nobreakspace}
\newenvironment{figure}
               {\@float{figure}}
               {\end@float}
\newenvironment{figure*}
               {\@dblfloat{figure}}
               {\end@dblfloat}
\newcommand{\figurename}{Fig.}

%Tables:
\newcounter{table}
\def\fps@table{tbp}
\def\ftype@table{2}
\def\ext@table{lot}
\renewcommand\thetable{\@arabic\c@table}
\newcommand{\fnum@table}{\footnotesize\em\tablename\nobreakspace\thetable}
\newenvironment{table}
               {\@float{table}\footnotesize}
               {\end@float}
\newenvironment{table*}
               {\@dblfloat{table}\footnotesize}
               {\end@dblfloat}
\newcommand{\tablename}{Table}


%Global settings for list spacing:
%no more redef for itemize and enumerate!
\setlength{\topsep}{3pt \@plus 1pt \@minus 1pt}
\setlength{\partopsep}{\z@ \@plus \p@}
\setlength{\itemsep}{1pt plus 1pt minus 1pt}
\setlength{\parsep}{\z@}

\setlength\leftmargini  {2em}	%reduce margin a little for 1st level list
\leftmargin  \leftmargini
\setlength\leftmarginii  {2.2em}
\setlength\leftmarginiii {1.87em}
\setlength\leftmarginiv  {1.7em}
\setlength\leftmarginv  {1em}
\setlength\leftmarginvi {1em}
\setlength  \labelsep  {.5em}
\setlength  \labelwidth{\leftmargini}
\addtolength\labelwidth{-\labelsep}

\@beginparpenalty -\@lowpenalty
\@endparpenalty   -\@lowpenalty
\@itempenalty     -\@lowpenalty

\renewcommand\theenumi{\@arabic\c@enumi}
\renewcommand\theenumii{\@alph\c@enumii}
\renewcommand\theenumiii{\@roman\c@enumiii}
\renewcommand\theenumiv{\@Alph\c@enumiv}
\newcommand\labelenumi{\theenumi.}
\newcommand\labelenumii{(\theenumii)}
\newcommand\labelenumiii{\theenumiii.}
\newcommand\labelenumiv{\theenumiv.}
\renewcommand\p@enumii{\theenumi}
\renewcommand\p@enumiii{\theenumi(\theenumii)}
\renewcommand\p@enumiv{\p@enumiii\theenumiii}
\newcommand\labelitemi{\textbullet}
\newcommand\labelitemii{\normalfont\bfseries \textendash}
\newcommand\labelitemiii{\textasteriskcentered}
\newcommand\labelitemiv{\textperiodcentered}


\newenvironment{description}
               {\list{}{\labelwidth\z@ \itemindent-\leftmargin
                        \let\makelabel\descriptionlabel}}
               {\endlist}
\newcommand*\descriptionlabel[1]{\hspace\labelsep
                                \normalfont\bfseries #1}

%\newcommand\appendix{\par
%  \setcounter{section}{0}%
 % \setcounter{subsection}{0}%
%  \gdef\thesection{\@Alph\c@section}}
\newcommand\appendix{\par
  \setcounter{section}{0}
  \setcounter{subsection}{0}
  \setcounter{figure}{0}
  \setcounter{table}{0}
  \renewcommand\thesection{Appendix \Alph {section}}
  \renewcommand\thefigure{\Alph{section}\arabic{figure}}
  \renewcommand\thetable{\Alph{section}\arabic{table}}
}

%Array and tabular + tabbing parameters:
\setlength\arraycolsep{5\p@}
\setlength\tabcolsep{6\p@}
\setlength\arrayrulewidth{.4\p@}
\setlength\doublerulesep{2\p@}
\setlength\tabbingsep{\labelsep}

%Frame box params:
\setlength\fboxsep{3\p@}
\setlength\fboxrule{.4\p@}

%Define the equation  number:
\renewcommand \theequation {\@arabic\c@equation}
%\renewcommand \@eqnum{(\theequation)}


%List vertical spacing parameters
\dbg@ut{Global list vertical spacings: \protect\topsep=\the\topsep,\protect\partopsep=\the\partopsep,\protect\itemsep=\the\itemsep,\protect\parsep=\the\parsep}
%List horizontal spacing parameters
\dbg@ut{Global list horizontal spacings: \protect\leftmargin=\the\leftmargin, \protect\rightmargin=\the\rightmargin, \protect\listparindent=\the\listparindent, \protect\itemindent=\the\itemindent, \protect\labelwidth=\the\labelwidth, \protect\labelsep=\the\labelsep}

%The table of contents and lists of figures and tables:
\newcommand\@pnumwidth{1.55em}
\newcommand\@tocrmarg{2.55em}
\newcommand\@dotsep{3.1}
\setcounter{tocdepth}{4}

\newcommand\tableofcontents{%
	\setcounter{page}{1}
	\pagestyle{rrptoc}
	\section*{\contentsname
		\@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
	\@starttoc{toc}%
	\setcounter{page}{1}
	\pagestyle{headings}
}

\newcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}

\newcommand*\l@subsection{\@dottedtocline{2}{1.5em}{2.3em}}
\newcommand*\l@subsubsection{\@dottedtocline{3}{3.8em}{3.2em}}
\newcommand*\l@subsubsubsection{\@dottedtocline{4}{5.5em}{4.1}}
\newcommand*\l@paragraph{\@dottedtocline{5}{7.0em}{5em}}
\newcommand*\l@subparagraph{\@dottedtocline{6}{10em}{6.1em}}

\newcommand\listoffigures{%
    \section*{\listfigurename}%
      \@mkboth{\MakeUppercase\listfigurename}%
              {\MakeUppercase\listfigurename}%
    \@starttoc{lof}%
    }

\newcommand*\l@figure{\@dottedtocline{1}{1.5em}{2.3em}}

\newcommand\listoftables{%
    \section*{\listtablename}%
      \@mkboth{%
          \MakeUppercase\listtablename}%
         {\MakeUppercase\listtablename}%
    \@starttoc{lot}%
    }

\let\l@table\l@figure

%theindex from article.cls is completely excluded!!!
%Footnotes:

\renewcommand\footnoterule{\kern-0.4pt \hrule \@width \z@}	%no line before footnotes

\renewcommand{\thefootnote}{\fnsymbol{footnote}}	

\newcommand\@makefntext[1]{%
    \parindent 1em%
    \noindent
    \hb@xt@1.8em{\hss\@makefnmark}#1}

\skip\@mpfootins = \skip\footins

%decrease probability of having single lines (orphans and widows) at begining/end of pages (defaults = 150)
\widowpenalty=250
\clubpenalty=250

%Errors for existing glyph conflict for (var)epsilon, (var)rho (package mathptmx is responsible...)
%\def\rrp@boolState#1{\expandafter\csname if#1\expandafter\endcsname True\expandafter\else False\expandafter\fi}


%Various names:
\newcommand\contentsname{Contents}
\newcommand\listfigurename{List of Figures}
\newcommand\listtablename{List of Tables}
\newcommand\indexname{Index}
\newcommand\appendixname{Appendix}
\newcommand\abstractname{Abstract}


% General definitions
\newcommand{\etal}{{\it et al.}}
\newcommand{\ie}{{\it  i.e.~}}
\newcommand{\eg}{{\it  e.g.}}

% Definitions for the journal names
\newcommand{\adv}{    {\it Adv. Space Res. }}
\newcommand{\aip}{    {\it AIP Conference Series }}
\newcommand{\angeo}{   {\it Annales Geophysicae }}
\newcommand{\aap}{    {\it Astron. Astrophys. }}
\newcommand{\aaps}{   {\it Astron. Astrophys. Suppl. }}
\newcommand{\aapr}{   {\it Astron. Astrophys. Rev. }}
\newcommand{\ag}{     {\it Ann. Geophys. }}
\newcommand{\an}{     {\it Astronomische Nachrichten }}
\newcommand{\aj}{     {\it Astron. J. }}
\newcommand{\apj}{    {\it Astrophys. J.  }}
\newcommand{\apjs}{    {\it Astrophys. J.Suppl.  }}
\newcommand{\apss}{   {\it Astrophys. Space Sci. }}
\newcommand{\cjaa}{   {\it Chin. J. Astron. Astrophys. }}
\newcommand{\gafd}{   {\it Geophys. Astrophys. Fluid Dyn. }}
\newcommand{\grl}{    {\it Geophys. Res. Lett. }}
\newcommand{\iau}{    {\it IAU Symp. }}
\newcommand{\ijga}{   {\it Int. J. Geomag. Aeron. }}
\newcommand{\jastp}{  {\it J. Atmos. Solar Terr. Phys. }}
\newcommand{\jgr}{    {\it J. Geophys. Res. }}
\newcommand{\jgra}{   {\it J.Geophys.Res. A }}
\newcommand{\mnras}{  {\it Mon. Not. Roy. Astron. Soc. }}
\newcommand{\nat}{    {\it Nature }}
\newcommand{\newA}{    {\it New Astronomy }}
\newcommand{\pasp}{   {\it Pub. Astron. Soc. Pac. }}
\newcommand{\pasj}{   {\it Pub. Astron. Soc. Japan }}
\newcommand{\pre}{    {\it Phys. Rev. E }}
\newcommand{\roaj}{    {\it Romanian Astron. J. }}
\newcommand{\solphys}{{\it Solar Phys. }}
\newcommand{\sovast}{ {\it Sov. Astron. }}
\newcommand{\ssr}{    {\it Space Sci. Rev. }}

\def\today{\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space\number\day, \number\year}
\pagenumbering{arabic}
\pagestyle{headings}
\if@twoside
\else
  \raggedbottom
\fi

%For author style disable enlargethispage command
%\renewcommand\enlargethispage[1]{}

%Loading additional needed packages and files:
%\RequirePackage{cite}					%to better process references (,- between refs)
\RequirePackage{textcase}			%to change case only for text
\RequirePackage[breakwords]{truncate}			%to trim the header title
\RequirePackage{ifpdf}				%to detect when pdftex is used to generate PDF files
\RequirePackage{amsfonts}	%for mathematical symbols, fonts and environments
\RequirePackage{amsmath}
\RequirePackage{amssymb}
\RequirePackage[usenames,dvipsnames]{color}
\RequirePackage[hyphens]{url}
\RequirePackage{lastpage}
%\RequirePackage{mynatbib}

\definecolor{rrp-lightgray}{gray}{0.95}

%insert other RRP math mode definitions
%\InputIfFileExists{rrp_mathdefs.tex}{\relax}{\ClassWarning{\class@name}{Supplemental mathematical commands definition file 'rrp_mathdefs.tex' not found...}}
%elliptic Jacobi functions
\DeclareMathOperator{\sn}{sn}
\DeclareMathOperator{\cn}{cn}
\DeclareMathOperator{\dn}{dn}

\newcommand{\ddiv}{\ensuremath{\mathop{\operator@font div}\nolimits}}
\newcommand{\grad}{\ensuremath{\mathop{\operator@font grad}\nolimits}}
\newcommand{\artanh}{\ensuremath{\mathop{\operator@font artanh}\nolimits}}
\newcommand{\sech}{\ensuremath{\mathop{\operator@font sech}\nolimits}}
\newcommand{\eps}{\ensuremath{\varepsilon}}
\newcommand{\cc}{\ifmmode\mathrm{cc.\;}\else\textrm{cc.~}\fi}
\newcommand{\ict}{\ifmmode\mathcal{C}\else\texttt{C}\fi}
\newcommand{\deriv }{\mathrm{d}}
\newcommand{\dd }{\text{d}}
\newcommand{\logd }{\mathrm{log}}
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\beq}{\begin{eqnarray}}
\newcommand{\eeq}{\end{eqnarray}}
%%%

%%%
\let\op@format\mathfrak
%\let\op@format\mathcal
\def\op#1{%
 \ifnum`#1=\lccode`#1
  \expandafter\ensuremath\op@format{\uppercase{#1}}
 \else%
  \expandafter\ensuremath\op@format{#1}
 \fi%
}%


\dbg@ut{Leaving \class@name\space class code...}
\normalsize
\endinput

%%%%%%%%%%%%%%%%%%
