\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{psrp}[2019/01/09 PSRP paper class]

\AtEndDocument{\par \cright}

%% PRELIMINARY DECLARATIONS
\LoadClass[10pt]{article}
\RequirePackage[T1]{fontenc}
\RequirePackage{calc}
\RequirePackage{indentfirst}
\RequirePackage{fancyhdr}
\RequirePackage{graphicx,epstopdf}
\RequirePackage{lastpage}
\RequirePackage{ifthen}
\RequirePackage{lineno}
\RequirePackage{float}
\RequirePackage{amsmath}
\RequirePackage{setspace}
\RequirePackage{enumitem}
\RequirePackage{mathpazo}
\RequirePackage{booktabs} % for \toprule etc. in tables
\RequirePackage[largestsep]{titlesec}
\RequirePackage{etoolbox} % for \AtBeginDocument



%% OPTIONS
%% To choose the journal
\DeclareOption{oma}{\gdef\@journal{oma}}
\DeclareOption{oms}{\gdef\@journal{oms}}
\DeclareOption{easl}{\gdef\@journal{easl}}
\DeclareOption{pdam}{\gdef\@journal{odam}}
\DeclareOption{ojc}{\gdef\@journal{ojc}}
\DeclareOption{addendum}{\gdef\@arttype{Addendum}}
\DeclareOption{article}{\gdef\@arttype{Article}}
\DeclareOption{book}{\gdef\@arttype{Book}} %BOOK%
\DeclareOption{bookreview}{\gdef\@arttype{Book Review}}
\DeclareOption{briefreport}{\gdef\@arttype{Brief Report}}
\DeclareOption{casereport}{\gdef\@arttype{Case Report}}
\DeclareOption{changes}{\gdef\@arttype{Changes}}
\DeclareOption{comment}{\gdef\@arttype{Comment}}
\DeclareOption{commentary}{\gdef\@arttype{Commentary}}
\DeclareOption{communication}{\gdef\@arttype{Communication}}
\DeclareOption{conceptpaper}{\gdef\@arttype{Concept Paper}}
\DeclareOption{correction}{\gdef\@arttype{Correction}}
\DeclareOption{conferencereport}{\gdef\@arttype{Conference Report}}
\DeclareOption{expressionofconcern}{\gdef\@arttype{Expression of Concern}}
\DeclareOption{meetingreport}{\gdef\@arttype{Meeting Report}}
\DeclareOption{creative}{\gdef\@arttype{Creative}}
\DeclareOption{datadescriptor}{\gdef\@arttype{Data Descriptor}}
\DeclareOption{discussion}{\gdef\@arttype{Discussion}}
\DeclareOption{editorial}{\gdef\@arttype{Editorial}}
\DeclareOption{essay}{\gdef\@arttype{Essay}}
\DeclareOption{erratum}{\gdef\@arttype{Erratum}}
\DeclareOption{hypothesis}{\gdef\@arttype{Hypothesis}}
\DeclareOption{interestingimage}{\gdef\@arttype{Interesting Image}}
\DeclareOption{letter}{\gdef\@arttype{Letter}}
\DeclareOption{newbookreceived}{\gdef\@arttype{New Book Received}}
\DeclareOption{obituary}{\gdef\@arttype{Obituary}}
\DeclareOption{opinion}{\gdef\@arttype{Opinion}}
\DeclareOption{projectreport}{\gdef\@arttype{Project Report}}
\DeclareOption{reply}{\gdef\@arttype{Reply}}
\DeclareOption{retraction}{\gdef\@arttype{Retraction}}
\DeclareOption{review}{\gdef\@arttype{Review}}
\DeclareOption{sciprints}{\gdef\@arttype{Sciprints}}
\DeclareOption{shortnote}{\gdef\@arttype{Short Note}}
\DeclareOption{supfile}{\gdef\@arttype{Supfile}}
\DeclareOption{technicalnote}{\gdef\@arttype{Technical Note}}

%% To choose the status of the manuscript
\DeclareOption{submit}{\gdef\@status{submit}}
\DeclareOption{accept}{\gdef\@status{accept}}

%% To choose the whether there is one or more authors
\DeclareOption{oneauthor}{\gdef\@authornum{author}}
\DeclareOption{moreauthors}{\gdef\@authornum{authors}}

%% Add the chosen options to the class
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}

%% Process options
\ProcessOptions\relax

%% MORE DECLARATIONS

%%%% Maths environments
\RequirePackage{amsthm}
\newtheoremstyle{psrp}% name
{12pt}% space above
{12pt}% space below
{\itshape}% body font
{}% indent amount 1
{\bfseries}% theorem head font
{.}% punctuation after theorem head
{.5em}% space after theorem head
{}% theorem head spec (can be left empty, meaning `normal')

\newtheoremstyle{psrpdefinition}% name
{12pt}% space above
{12pt}% space below
{}% body font
{}% hndent amount 1
{\bfseries}% theorem head font
{.}% punctuation after theorem head
{.5em}% space after theorem head
{}% theorem head spec (can be left empty, meaning `normal')

\renewcommand{\qed}{\unskip\nobreak\quad\qedsymbol} %% This places the symbol right after the text instead of placing it at the end on the line.

\renewenvironment{proof}[1][\proofname]{\par %% \proofname allows to have "Proof of my theorem"
  \pushQED{\qed}%
  \normalfont \topsep6\p@\@plus6\p@\relax
  \trivlist
  \item[\hskip\labelsep
        \bfseries %% "Proof" is bold
    #1\@addpunct{.}]\ignorespaces %% Period instead of colon
}{%
  \popQED\endtrivlist\@endpefalse
}

%%%% Hyphenation
\RequirePackage[none]{hyphenat}
\sloppy

%%%% References
\RequirePackage[sort&compress]{natbib}
\bibpunct{[}{]}{,}{n}{}{}

\renewcommand\NAT@set@cites{%
  \ifNAT@numbers
    \ifNAT@super \let\@cite\NAT@citesuper
       \def\NAT@mbox##1{\unskip\nobreak\textsuperscript{##1}}%
       \let\citeyearpar=\citeyear
       \let\NAT@space\relax
       \def\NAT@super@kern{\kern\p@}%
    \else
       \let\NAT@mbox=\mbox
       \let\@cite\NAT@citenum
       \let\NAT@space\relax
       \let\NAT@super@kern\relax
    \fi
    \let\@citex\NAT@citexnum
    \let\@biblabel\NAT@biblabelnum
    \let\@bibsetup\NAT@bibsetnum
    \renewcommand\NAT@idxtxt{\NAT@name\NAT@spacechar\NAT@open\NAT@num\NAT@close}%
    \def\natexlab##1{}%
    \def\NAT@penalty{\penalty\@m}%
  \else
    \let\@cite\NAT@cite
    \let\@citex\NAT@citex
    \let\@biblabel\NAT@biblabel
    \let\@bibsetup\NAT@bibsetup
    \let\NAT@space\NAT@spacechar
    \let\NAT@penalty\@empty
    \renewcommand\NAT@idxtxt{\NAT@name\NAT@spacechar\NAT@open\NAT@date\NAT@close}%
    \def\natexlab##1{##1}%
  \fi}

%%%%% Hyperlinks
\ifthenelse{\equal{\@arttype}{Book}}{ %BOOK%
\RequirePackage[unicode=true,
bookmarksopen={true},
pdffitwindow=true,
colorlinks=true,
linkcolor=black,
citecolor=black,
urlcolor=black,
hyperfootnotes=false,
pdfstartview={FitH},
pdfpagemode=UseNone]{hyperref}
}{
\RequirePackage[unicode=true,
bookmarksopen={true},
pdffitwindow=true,
colorlinks=true,
linkcolor=blue,
citecolor=blue,
urlcolor=blue,
hyperfootnotes=false,
pdfstartview={FitH},
pdfpagemode= UseNone]{hyperref}
}

%% To have the possibility to change the urlcolor
\newcommand{\changeurlcolor}[1]{\hypersetup{urlcolor=#1}}

%% Metadata
\newcommand{\org@maketitle}{}% LATEX-Check
\let\org@maketitle\maketitle
\def\maketitle{%
\hypersetup{
pdftitle={\@Title},
pdfsubject={\@abstract},
pdfkeywords={\@keyword},
pdfauthor={\@AuthorNames}
}%
\org@maketitle
}

%%%% Footnotes
\RequirePackage[hang]{footmisc}
\setlength{\skip\footins}{1.2cm}
\setlength{\footnotemargin}{5mm}
\def\footnoterule{\kern-14\p@
\hrule \@width 2in \kern 11.6\p@}

%%%% URL
\RequirePackage{url}
\urlstyle{same}

%%%% Widows & orphans
\clubpenalty=10000
\widowpenalty=10000
\displaywidowpenalty=10000

%%%% Front matter
\newcommand{\firstargument}{}
\newcommand{\Title}[1]{\gdef\@Title{#1}}%
\newcommand{\Author}[1]{\gdef\@Author{#1}}%
\def\@AuthorNames{}
\newcommand{\AuthorNames}[1]{\gdef\@AuthorNames{#1}}%
\newcommand{\firstpage}[1]{\gdef\@firstpage{#1}}
\newcommand{\doinum}[1]{\gdef\@doinum{#1}}
\newcommand{\pubvolume}[1]{\gdef\@pubvolume{#1}}
\newcommand{\pubyear}[1]{\gdef\@pubyear{#1}}
\newcommand{\copyrightyear}[1]{\gdef\@copyrightyear{#1}}
\newcommand{\address}[2][]{\renewcommand{\firstargument}{#1}\gdef\@address{#2}}
\newcommand{\corresfirstargument}{}
\def\@corres{}
\newcommand{\corres}[2][]{\renewcommand{\corresfirstargument}{#1}\gdef\@corres{#2}}
\def\@conference{}
\newcommand{\conference}[1]{\gdef\@conference{#1}}%
\def\@abstract{}
\renewcommand{\abstract}[1]{\gdef\@abstract{#1}}
\def\@externaleditor{}
\newcommand{\externaleditor}[1]{\gdef\@externaleditor{#1}}
\newcommand{\history}[1]{\gdef\@history{#1}}
\def\@pacs{}
\newcommand{\PACS}[1]{\gdef\@pacs{#1}}
\def\@msc{}
\newcommand{\MSC}[1]{\gdef\@msc{#1}}
\def\@jel{}
\newcommand{\JEL}[1]{\gdef\@jel{#1}}
\def\@keyword{}
\newcommand{\keyword}[1]{\gdef\@keyword{#1}}
\def\@dataset{}
\newcommand{\dataset}[1]{\gdef\@dataset{#1}}
\def\@datasetlicense{}
\newcommand{\datasetlicense}[1]{\gdef\@datasetlicense{#1}}
\def\@firstnote{}
\newcommand{\firstnote}[1]{\gdef\@firstnote{#1}}
\def\@secondnote{}
\newcommand{\secondnote}[1]{\gdef\@secondnote{#1}}%
\def\@simplesumm{}
\newcommand{\simplesumm}[1]{\gdef\@simplesumm{#1}}
\newcommand{\pagenumbers}[1]{\gdef\@pagenumbers{#1}}

%BOOK%
\newcommand{\boxheight}[1]{\gdef\@boxheight{#1}}%
\newcommand{\Titlebox}[1]{\gdef\@Titlebox{#1}}%
\newcommand{\Authorbox}[1]{\gdef\@Authorbox{#1}} %
\newcommand{\firstpagebox}[1]{\gdef\@firstpagebox{#1}}
\newcommand{\lastpagebox}[1]{\gdef\@lastpagebox{#1}} %


%%%% Journal name for the header
\newcommand{\journalname}{%
  \ifthenelse{\equal{\@journal}{oma}}{Open J. Math. Anal.}{}%
  \ifthenelse{\equal{\@journal}{oms}}{Open J. Math. Sci.}{}%
  \ifthenelse{\equal{\@journal}{odam}}{Open J. Discret. Appl. Math.}{}%
  \ifthenelse{\equal{\@journal}{ojc}}{Open Chem.}{}%
  \ifthenelse{\equal{\@journal}{easl}}{Eng. Appl. Sci. Lett.}{}%
}

%%%% Header and footer on first page
%% The plain page style needs to be redefined because with \maketitle in the article class, LaTeX applies the the plain page style automatically to the first page.
\ifthenelse{\equal{\@arttype}{Book}}{}{%BOOK%
\ifthenelse{\equal{\@arttype}{Supfile}}{
	\fancypagestyle{plain}{
	\fancyhf{}
	\fancyhead[R]{
		\fontsize{8}{8}\selectfont S\thepage{} of S\pageref*{LastPage}%
		}%
	\fancyhead[L]{
		\fontsize{8}{8}\selectfont \ifthenelse{\equal{\@status}{submit}}{
			Version {\@ \today} submitted to {\em \journalname}%
			}{
			{\em \journalname} {\bfseries \@pubyear}, {\em \@pubvolume}, \ifthenelse{\equal{\@pagenumbers}{}}{
				\@firstpage --\pageref*{LastPage}}{\@pagenumbers}; doi:\@doinum%
			}%
		}%
	}%
}{
\ifthenelse{\equal{\@arttype}{Sciprints}}{
	\fancypagestyle{plain}{
		\fancyhf{}
		\fancyfoot[L]{\fontsize{8}{8}\selectfont%
		Not peer-reviewed\\{\changeurlcolor{black}\href{www.pisrt.org}{www.pisrt.org}}, doi:proprint/\@doinum}%
		}
	}{
	\fancypagestyle{plain}{
	\fancyhf{}
	\fancyfoot[L]{
		\fontsize{8}{8}\selectfont%
 	 	{\ifthenelse{\equal{\@status}{submit}}{
			\normalfont Submitted to {\em \journalname}, pages \thepage \ -- \color{black}{\pageref*{LastPage}}%
			}{
			\normalfont {\em \journalname}\ {\bfseries {\@pubyear}}, {\em \@pubvolume}, \ifthenelse{\equal{\@pagenumbers}{}}{
			\@firstpage --\pageref*{LastPage}%
			}{\@pagenumbers}; doi:\@doinum%
			}%
			}%
		}%
	 \fancyfoot[R]{
	 	\fontsize{8}{8}\selectfont{\changeurlcolor{black}\href{https://pisrt.org/psr-press/journals/\@journal}{https://pisrt.org/psr-press/journals/\@journal}}%
		}%
	 \fancyhead{}
	 \renewcommand{\headrulewidth}{0.0pt}%
	 \renewcommand{\footrulewidth}{0.2pt}%
	}%
	}%
	}%
}	

%%%% Maketitle part 1
\renewcommand{\@maketitle}{
\ifthenelse{\equal{\@arttype}{Supfile}}{
	\fontsize{18}{18}\selectfont
	\noindent\textbf{Supplementary Materials: \@Title}%
	\par
	\vspace{12pt}
	\fontsize{10}{10}\selectfont
	\noindent\boldmath\bfseries{\@Author}
}{
\ifthenelse{\equal{\@arttype}{Book}}{ %BOOK%
	\raggedright
	\fontsize{18}{18}\selectfont
	\noindent\textbf{\@Title}
	\par
	\vspace{12pt}
	\fontsize{10}{10}\selectfont
	\noindent\textbf{\@Author}
	\par
	\vspace{12pt}
	}{
	\begin{flushleft}
	\vspace*{-1.75cm}
	{%0
	\ifthenelse{\equal{\@arttype}{Sciprints}}{
	\href{www.pisrt.org}{\includegraphics[height=1.5cm]{logo-preprint}}%
		}{
		\ifthenelse{\equal{\@status}{submit}}{	
		\hfill \href{https://pisrt.org/psr-press}{\includegraphics[height=1.2cm]{logo-psrp}}\vspace{0.5cm}%
		}{
		\href{https://pisrt.org/psr-press/journals/\@journal}{\includegraphics[height=1.2cm]{\@journal-logo}}%
		\hfill \href{https://pisrt.org/psr-press}{\includegraphics[height=1.2cm]{logo-psrp}}%
		}%
		}%
	\par
	}%0
	{%1
    	\vspace{14pt}
    	\fontsize{10}{10}\selectfont
    	\ifthenelse{\equal{\@arttype}{Sciprints}}{PREPRINT}{\textit{\@arttype}}
    	\par
    	}%1
    	{%2
    	\vspace{-1pt}
    	\fontsize{18}{18}\selectfont
    	\bfseries{\@Title}
    	\par
    	\vspace{15pt}
    	}%2
   	{%3
   	\fontsize{10}{10}\selectfont
    	\boldmath\bfseries{\@Author}
    	\par
    	\vspace{-4pt}
    	}%3
    	\end{flushleft}
    }%
    }%
}

%%%% Maketitle part 2
\newcommand{\maketitlen}{ %BOOK%
\ifthenelse{\equal{\@arttype}{Book}}{
	\ifthenelse{\equal{\@abstract}{\@empty}}{}{
	\noindent\textbf{Abstract:\space}\@abstract
	\vspace{12pt}
	\par
	}
}{
\begin{flushleft}
\begin{spacing}{1.35}
	{%4
	\leftskip0.2cm
	\fontsize{9}{9}\selectfont
	\ifthenelse{\equal{\firstargument}{1}}{}{\hangafter=1\hangindent=1.7em \noindent}%
	\@address
	\par
	}%4
	{%5
	\leftskip0.2cm
	\fontsize{9}{9}\selectfont
	\ifthenelse{\equal{\@authornum}{authors}}{
	\ifthenelse{\equal{\@corres}{\@empty}}{}{\hangafter=1\hangindent=1.7em\noindent \textbf{*} \quad \@corres}
	\par
	}{}
	}%5
	{%6
	\leftskip0.2cm
	\fontsize{9}{9}\selectfont
	\ifthenelse{\equal{\@firstnote}{\@empty}}{}{\hangafter=1\hangindent=1.7em\noindent
	$\dagger$ \quad \@firstnote}
	\par
	}%6
	{%7
	\leftskip0.2cm
	\fontsize{9}{9}\selectfont
	\ifthenelse{\equal{\@secondnote}{\@empty}}{}{\hangafter=1\hangindent=1.7em \noindent $\ddagger$ \quad \@secondnote}
	\par
	}%7
	{%8
	\leftskip0.2cm
	\fontsize{9}{9}\selectfont
	\ifthenelse{\equal{\@conference}{\@empty}}{}{\hangafter=1\hangindent=1.7em\noindent \textsection
	\quad This paper is an extended version of our paper published in\space \@conference.}
	\par
	}%8
	{%9
	\vspace{6pt}
	\leftskip0.2cm
	\fontsize{9}{9}\selectfont
	\ifthenelse{\equal{\@externaleditor}{\@empty}}{}{\@externaleditor}
	\par
	}%9
	{%10
	\leftskip0.2cm
	\fontsize{9}{9}\selectfont
	\ifthenelse{\equal{\@status}{submit}}{Version {\@ \today} submitted to \journalname; Typeset by \LaTeX{} using class file psrp.cls}{\@history}
	\par
	\vspace{-4pt}
	}%10
\end{spacing}
\end{flushleft}
}
}

%%%% Abstract, keywords, journal data, PACS, MSC, JEL
\newcommand{\abstractkeywords}{
\ifthenelse{\equal{\@arttype}{Book}}{ %BOOK%
	\centerline{	
		\fbox{	
		\begin{minipage}[t][\@boxheight mm][t]{1.001\linewidth}
		Reprinted from \textit{\journalname}. %
		Cite as: \@Authorbox{} \@Titlebox. \textit{\journalname} \textbf{\@pubyear}, \textit{\@pubvolume}, \@firstpagebox{} \ifthenelse{\equal{\@lastpagebox}{\@empty}}{}{--\@lastpagebox}.
		\end{minipage}
		}
	}
}{
{%10
\begingroup
\vspace{-15pt}
\leftskip0.2cm
\ifthenelse{\equal{\@simplesumm}{\@empty}}{}{
\noindent\textbf{Simple Summary:\space}\@simplesumm
\vspace{12pt}
\par
}
\ifthenelse{\equal{\@abstract}{\@empty}}{}{
\noindent\textbf{Abstract:\space}\@abstract
\vspace{12pt}
\par
}
\endgroup
}%10
{%11
\begingroup
\leftskip0.2cm
\ifthenelse{\equal{\@keyword}{\@empty}}{}{
\noindent\textbf{Keywords:\space}\@keyword
\vspace{12pt}
\par
}
\endgroup
}%11
{% For journal Data:
\ifthenelse{\equal{\@dataset}{\@empty}}{}{
\begingroup
\leftskip0.2cm
\noindent\textbf{Data Set:\space}\@dataset
\vspace{12pt}
\par
\endgroup}
}%
{%For journal Data:
\ifthenelse{\equal{\@datasetlicense}{\@empty}}{}{
\begingroup
\leftskip0.2cm
\noindent\textbf{Data Set License:\space}\@datasetlicense
\vspace{12pt}
\par
\endgroup}
}%
{%12
\ifthenelse{\equal{\@pacs}{\@empty}}{}{
\begingroup
\leftskip0.2cm
\noindent\textbf{PACS:\space}\@pacs
\vspace{12pt}
\par
\endgroup}
}%12
{%13
\ifthenelse{\equal{\@msc}{\@empty}}{}{
\begingroup
\leftskip0.2cm
\noindent\textbf{MSC:\space}\@msc
\vspace{12pt}
\par
\endgroup}
}%13
{%14
\ifthenelse{\equal{\@jel}{\@empty}}{}{
\begingroup
\leftskip0.2cm
\noindent\textbf{JEL:\space}\@jel
\vspace{12pt}
\par
\endgroup}
}%14
\vspace{4pt}
\hrule
\vspace{12pt}
}
}

%%%% Print maketitle and abstractkeywords
\ifthenelse{\equal{\@arttype}{Supfile}}{
	\AfterEndPreamble{
	\maketitle
	\let\maketitle\relax
	\ifthenelse{\equal{\@status}{submit}}{\linenumbers}{}
	}%
	}{
	\AfterEndPreamble{
	\maketitle
	\let\maketitle\relax
	\maketitlen
	\let\maketitlen\relax
	\ifthenelse{\equal{\@status}{submit}}{\linenumbers}{}
	\abstractkeywords
	}%
	}
\AtBeginDocument{
	\DeclareSymbolFont{AMSb}{U}{msb}{m}{n}
	\DeclareSymbolFontAlphabet{\mathbb}{AMSb}
}

%%%% Section headings
\titleformat {\section} [block] {\raggedright \fontsize{11}{11}\selectfont\bfseries} {\thesection. \space} {0pt} {}
\titlespacing {\section} {0pt} {12pt} {6pt}

\titleformat {\subsection} [block] {\raggedright \fontsize{10}{10}\selectfont\bfseries} {\thesubsection .\space} {0pt} {}
\titlespacing {\subsection} {0pt} {12pt} {6pt}

\titleformat {\subsubsection} [block] {\raggedright \fontsize{10}{10}\selectfont} {\thesubsubsection .\space} {0pt} {}
\titlespacing {\subsubsection} {0pt} {12pt} {6pt}

\titleformat {\paragraph} [block] {\raggedright \fontsize{10}{10}\selectfont} {} {0pt} {}
\titlespacing {\paragraph} {0pt} {12pt} {6pt}

%%%% Special section title style for back matter
\newcommand{\supplementary}[1]{
\par\vspace{6pt}\noindent{\fontsize{9}{9}\selectfont\textbf{Supplementary Materials:} {#1}\par}}

\newcommand{\acknowledgments}[1]{
\vspace{6pt}\noindent{\fontsize{9}{9}\selectfont\textbf{Acknowledgments:} {#1}\par}}

\newcommand{\authorcontributions}[1]{%
\vspace{6pt}\noindent{\fontsize{9}{9}\selectfont\textbf{Author Contributions:} {#1}\par}}
\newcommand{\dataavailability}[1]{%
\vspace{6pt}\noindent{\fontsize{9}{9}\selectfont\textbf{Data Availability:} {#1}\par}}
\newcommand{\fundinginformation}[1]{%
\vspace{6pt}\noindent{\fontsize{9}{9}\selectfont\textbf{Funding Information:} {#1}\par}}

\newcommand{\conflictofinterests}[1]{%
\vspace{6pt}\noindent{\fontsize{9}{9}\selectfont\textbf{Conflicts of Interest:} {#1}\par}}

\newcommand{\sampleavailability}[1]{%
\vspace{12pt}\noindent{\fontsize{9}{9}\selectfont\textbf{Sample Availability:} {#1}\par}}

\newcommand{\abbreviations}[1]{%
\vspace{12pt}\noindent{\selectfont\textbf{Abbreviations}\par\vspace{6pt}\noindent {#1}\par}}

%%%%% Defines the appendix
\renewcommand{\appendix}{
\setcounter{section}{0}%
\setcounter{subsection}{0}%
\setcounter{subsubsection}{0}%
\gdef\thesection{\@Alph\c@section}%
\gdef\thesubsection{\@Alph\c@section.\@arabic\c@subsection}%
\titleformat {\section} [block] {\raggedright \fontsize{11}{11}\selectfont\bfseries} {\appendixname~\thesection.~} {0pt} {}
\titlespacing {\section} {0pt} {12pt} {6pt}
\titleformat {\subsection} [block] {\raggedright \fontsize{10}{10}\selectfont\bfseries} {\appendixname~\thesubsection.~} {0pt} {}
\titlespacing {\subsection} {0pt} {12pt} {6pt}
\titleformat {\subsubsection} [block] {\raggedright \fontsize{10}{10}\selectfont} {\appendixname~\thesubsubsection.~} {0pt} {}
\titlespacing {\subsubsection} {0pt} {12pt} {6pt}
\gdef\theHsection{\@Alph\c@section.}% for hyperref
\gdef\theHsubsection{\@Alph\c@section.\@arabic\c@subsection}% for hyperref
\csname appendixmore\endcsname
}

%%%% Layout
\ifthenelse{\equal{\@arttype}{Book}}{%BOOK%
	\RequirePackage[left=2.5cm,
					right=2.5cm,
					top=2.5cm,
					bottom=2.5cm,
					paperwidth=216mm,
					paperheight=320mm,
					includefoot]{geometry}
	}{
	\RequirePackage[left=2.0cm,
				right=2.0cm,
				top=0.7cm,
				bottom=0.5cm,
				includehead,
				includefoot]{geometry}
	}
\linespread{1.13}
\setlength{\parindent}{0.75cm}

%%%% Figures and tables
\newfloat{boxenv}{H}{lop}
\floatname{boxenv}{Box}
\floatstyle{plain}
\restylefloat{figure}
\floatstyle{plaintop}
\restylefloat{table}
\floatstyle{plaintop}
\restylefloat{boxenv}
\floatstyle{plain}
\restylefloat{scheme}
\RequirePackage{caption}
\captionsetup[figure]{position=bottom, margin=0.75cm, labelfont={bf, small, stretch=1.17}, labelsep=period, textfont={small, stretch=1.17}, aboveskip=6pt, belowskip=12pt, justification=justified}
\captionsetup[scheme]{position=bottom, margin=0.75cm, labelfont={bf, small, stretch=1.17}, labelsep=period, textfont={small, stretch=1.17}, aboveskip=6pt, belowskip=12pt, justification=justified}
\captionsetup[table]{position=top, margin=0.75cm, labelfont={bf, small, stretch=1.17}, labelsep=period, textfont={small, stretch=1.17}, aboveskip=6pt, belowskip=12pt, justification=justified}
\captionsetup[boxenv]{position=top, margin=0.75cm, labelfont={bf, small, stretch=1.17}, labelsep=period, textfont={small, stretch=1.17}, aboveskip=6pt, belowskip=12pt, justification=justified}

%% For table footnotes
\newsavebox{\@justcentbox}
\newcommand{\justifyorcenter}[1]{
\sbox \@justcentbox{#1}
\ifdim \wd \@justcentbox >\hsize #1
\else \centerline{#1} \fi
}

%%%% Bullet lists
\newlength{\wideitemsep}
\setlength{\wideitemsep}{.5\itemsep}
\addtolength{\wideitemsep}{-7pt}
\let\olditem\item
\renewcommand{\item}{\setlength{\itemsep}{\wideitemsep}\olditem}

%%%% Supplementary file
\ifthenelse{\equal{\@arttype}{Supfile}}{
	\renewcommand{\thefigure}{S\arabic{figure}}%
	\renewcommand{\thetable}{S\arabic{table}}%
	}{}%

%%%% Header and footer (all pages except the first)
%\renewcommand\headrule{} %% set line (from fancyhdr) in header to nothing
\pagestyle{fancy}





\pagestyle{fancy}
\lhead{
	\ifthenelse{\equal{\@arttype}{Book}}{}{ %BOOK%
	\ifthenelse{\equal{\@arttype}{Sciprints}}{\fontsize{8}{8}\selectfont \textit{Sciprints}}{
		\fontsize{8}{8}\selectfont
		\ifthenelse{\equal{\@status}{submit}}{
			Version {\@ \today} submitted to {\em \journalname}%
			}{
			\ifthenelse{\equal{\@arttype}{Supfile}}{
			{\em \journalname} {\bfseries \@pubyear}, {\em \@pubvolume}, \ifthenelse{\equal{\@pagenumbers}{}}{
			\@firstpage --\pageref*{LastPage}%
			}{\@pagenumbers}%
			; doi:\@doinum%
			}{
			{\em \journalname} {\bfseries \@pubyear}, {\em \@pubvolume}, \ifthenelse{\equal{\@pagenumbers}{}}{
			\@firstpage --\pageref*{LastPage}%
			}{
			\@pagenumbers}%
			}%
			}%
		}%
		}%
}
\rhead{
	\ifthenelse{\equal{\@arttype}{Book}}{}{ %BOOK%
	\ifthenelse{\equal{\@journal}{recycling}
		\OR \equal{\@journal}{philosophies}
		\OR \equal{\@journal}{sinusitis}
		\OR \equal{\@journal}{fishes}
		\OR \equal{\@journal}{jfmk}}{
			\ifthenelse{\equal{\@arttype}{Supfile}}{
				\fontsize{8}{8}\selectfont S\thepage{}
				}{
				\ifthenelse{\equal{\@status}{submit}}{
					\fontsize{8}{8}\selectfont\thepage
					}{
					\fontsize{8}{8}\selectfont\thepage{}%
					}%
				}%
			}{
			\ifthenelse{\equal{\@arttype}{Supfile}}{
				\thepage%
				}{
				\thepage%
				}%
			}%
		}%
}
\cfoot{\ifthenelse{\equal{\@arttype}{Book}}{\thepage}{}}
\lfoot{
	\ifthenelse{\equal{\@arttype}{Sciprints}}{
		\fontsize{8}{8}\selectfont Not peer-reviewed\\{\changeurlcolor{black} \href{www.sciprints.net}{www.sciprints.net}}, doi:sciprints/\@doinum
		}{}
	}

%%%% Bibliography
\renewcommand\@biblabel[1]{[#1]\hfill}
\def\thebibliography#1{
\linespread{1.44}
\vspace{12pt}
\fontsize{10}{10}\selectfont
\noindent{{\bfseries \bibname}}
\vspace{6pt}
\fontsize{9}{9}\selectfont
\list{{\arabic{enumi}}}{\def\makelabel##1{\hss{##1}}
\topsep=0\p@
\parsep=5\p@
\partopsep=0\p@
\itemsep=0\p@
\labelsep=1.5mm
\itemindent=0\p@
\settowidth\labelwidth{\footnotesize[#1]}%
\leftmargin\labelwidth
\advance\leftmargin\labelsep
%\advance\leftmargin -\itemindent
\usecounter{enumi}}
%\def\newblock{\ }
%\sloppy\clubpenalty4000\widowpenalty4000
%\sfcode`\.=1000\relax
}
\let\endthebibliography=\endlist

%%%% Copyright info
\newcommand{\cright}{%
\ifthenelse{\equal{\@arttype}{Supfile} \OR \equal{\@arttype}{Book}}{}{% %BOOK%
	\vspace{12pt}
	\noindent
	\linespread{1.44}
	\fontsize{9}{9}\selectfont
	\ifthenelse{\equal{\@status}{submit}}{
		\noindent \copyright{} {\@ \the\year} by the \@authornum. %
		Submitted to \ifthenelse{\equal{\@arttype}{Sciprints}}{Sciprints}{{\em \journalname}} for %
		\ifthenelse{\equal{\@arttype}{Sciprints}}{preprint}{possible open access publication} %
		under the terms and conditions of the Creative Commons Attribution license %
		(\changeurlcolor{black}\href{http://creativecommons.org/licenses/by/4.0/.}{http://creativecommons.org/licenses/by/4.0/})
		}{
		\begin{minipage}{.2\textwidth}
			\hspace{-1.2mm}\vspace{2mm}\href{http://creativecommons.org/}{\includegraphics[height=1.5cm]{logo-ccby}}
		\end{minipage}%
		\begin{minipage}{.8\textwidth}
			\copyright \ {\@copyrightyear} by the \@authornum; %
			licensee \ifthenelse{\equal{\@arttype}{Sciprints}}{\textit{Sciprints}}{PSRP}, Lahore, Pakistan. %
			This article is an open access article distributed under the terms and conditions %
			of the Creative Commons Attribution (CC-BY) license %
			(\changeurlcolor{black}\href{http://creativecommons.org/licenses/by/4.0/}{http://creativecommons.org/licenses/by/4.0/}).
		\end{minipage}
		}
	}
}

\endinput
