$-- Keeping in template layout for backward compatibility
\documentclass[$if(layout)$$layout$$else$$for(classoption)$$classoption$$sep$,$endfor$$endif$]{elsarticle} %review=doublespace preprint=single 5p=2 column
%%% Begin My package additions %%%%%%%%%%%%%%%%%%%
\usepackage[hyphens]{url}
$if(journal)$
\journal{$journal$} % Sets Journal name
$endif$
\usepackage{lineno} % add
$if(linenumbers)$
\linenumbers % turns line numbering on
$endif$
\usepackage{graphicx}
\usepackage{xstring}
\usepackage[table]{xcolor}
%%%%%%%%%%%%%%%% end my additions to header
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
    \usepackage[utf8]{inputenc}
    $if(euro)$
    \usepackage{eurosym}
    $endif$
\else % if luatex or xelatex
    \usepackage{fontspec}
    \ifxetex
    \usepackage{xltxtra,xunicode}
    \fi
    \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
    \newcommand{\euro}{€}
    $if(mainfont)$
    \setmainfont{$mainfont$}
    $endif$
    $if(sansfont)$
    \setsansfont{$sansfont$}
    $endif$
    $if(monofont)$
    \setmonofont{$monofont$}
    $endif$
    $if(mathfont)$
    \setmathfont{$mathfont$}
    $endif$
\fi
% use microtype if available
\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
$if(geometry)$
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
$endif$
$if(natbib)$
\usepackage{natbib}
\setcitestyle{$natbiboptions$}
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$}
$endif$
$if(listings)$
\usepackage{listings}
$endif$
$if(lhs)$
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
$endif$
$if(verbatim-in-note)$
\usepackage{fancyvrb}
$endif$
$if(graphics)$
\usepackage{graphicx}
$endif$
\ifxetex
    \usepackage[setpagesize=false, % page size defined by xetex
                unicode=false, % unicode breaks when used with xetex
                xetex]{hyperref}
\else
    \usepackage[unicode=true]{hyperref}
\fi
\hypersetup{breaklinks=true,
            bookmarks=true,
            pdfauthor={$author-meta$},
            pdftitle={$title-meta$},
            colorlinks=$if(colorlinks)$true$else$false$endif$,
            urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,
            linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,
            pdfborder={0 0 0}}
\urlstyle{same}  % don't use monospace font for urls
$if(links-as-notes)$
% Make links footnotes instead of hotlinks:
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(strikeout)$
\usepackage[normalem]{ulem}
% avoid problems with \sout in headers with hyperref:
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
$endif$
$if(numbersections)$
\setcounter{secnumdepth}{5}
$else$
\setcounter{secnumdepth}{0}
$endif$
$if(verbatim-in-note)$
\VerbatimFootnotes % allows verbatim text in footnotes
$endif$
$if(lang)$
\ifxetex
    \usepackage{polyglossia}
    \setmainlanguage{$mainlang$}
\else
    \usepackage[$lang$]{babel}
\fi
$endif$
% Pandoc toggle for numbering sections (defaults to be off)
$if(numbersections)$
$else$
\setcounter{secnumdepth}{0}
$endif$
$if(highlighting-macros)$
% Pandoc syntax highlighting
$highlighting-macros$
$endif$
% tightlist command for lists without linebreak
\providecommand{\tightlist}{%
    \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
$if(tables)$
% From pandoc table feature
\usepackage{longtable,booktabs,array}
$if(multirow)$
\usepackage{multirow}
$endif$
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
$endif$
$if(csl-refs)$
% Pandoc citation processing
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newlength{\cslentryspacingunit} % times entry-spacing
\setlength{\cslentryspacingunit}{\parskip}
% for Pandoc 2.8 to 2.10.1
\newenvironment{cslreferences}%
  {$if(csl-hanging-indent)$\setlength{\parindent}{0pt}%
  \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces$endif$}%
  {\par}
% For Pandoc 2.11+
\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing
{% don't indent paragraphs
    \setlength{\parindent}{0pt}
    % turn on hanging indent if param 1 is 1
    \ifodd #1
    \let\oldpar\par
    \def\par{\hangindent=\cslhangindent\oldpar}
    \fi
    % set entry spacing
    \setlength{\parskip}{#2\cslentryspacingunit}
    }%
{}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{#1\hfill\break}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
$endif$
$for(header-includes)$
$header-includes$
$endfor$

\usepackage{xifthen}
% set special color for EST
\ifthenelse{\equal{$journal$}{Environmental Science \& Technology}}
{\definecolor{seccol}{RGB}{56, 95, 66}}
{\definecolor{seccol}{RGB}{0, 0, 0}}

$if(uppersections)$
\usepackage{titlesec}
\titleformat{\section}
{\color{seccol}\large\bfseries\MakeUppercase}{\thesection}{1em}{}
$endif$
$if(sectiononnewpage)$
\AddToHook{cmd/section/before}{\clearpage}
$endif$

\usepackage{enumitem}
\usepackage{fontspec}
\usepackage{float}
\setmainfont{Helvetica}
\usepackage[normalem]{ulem}
\usepackage{hyperref}
\usepackage{nameref} %needed by zref-xr
\usepackage{zref-xr,zref-hyperref,zref-user}
\usepackage{xr-hyper}

% force to use \zref
$if(msname)$
\def\msname{$msname$}
\zexternaldocument*{\msname}
\renewcommand{\ref}{\zref}
$endif$
$if(smname)$
\def\smname{$smname$}
\zexternaldocument*{\smname}
$endif$

\zxrsetup{toltxlabel=true}
{\catcode`\#=12 \gdef\hashchar{#1}}
\makeatletter
\newcommand\hzref[1]{\edef\next{%
    \noexpand\href{%
      \zref@extractdefault{#1}{url}{}%
      \zref@ifrefcontainsprop{#1}{anchor}{%
      \hashchar\zref@extract{#1}{anchor}}{}}%
      {\noexpand\zref{#1}}}\next}
\makeatother



$if(revision)$
% \usepackage{xcolor}
\usepackage{adjustbox}
\usepackage{mdframed}
\newmdenv[topline=false,
          leftline=true,
          bottomline=false,
          rightline=false,
          linewidth=3pt,
          %backgroundcolor=lightgray,
          linecolor=gray!30,
          backgroundcolor=gray!5,
          skipabove=\topsep,
          skipbelow=\topsep,
          leftmargin=0pt,
          rightmargin=0pt,
          innertopmargin=0pt,
          innerbottommargin=0pt
          ]{refquote}
\newmdenv[topline=false,
          leftline=true,
          bottomline=false,
          rightline=false,
          linewidth=3pt,
          %backgroundcolor=lightgray,
          backgroundcolor=red!3!white,
          linecolor=red!30!white,
          skipabove=\topsep,
          skipbelow=\topsep,
          leftmargin=0pt,
          rightmargin=0pt,
          innertopmargin=10pt,
          innerbottommargin=10pt
          ]{question}
\setenumerate{labelsep=*, leftmargin=1.0pc}
% setup hyperlink for page and line number
\def\msname{$if(msname)$$msname$$else$MS$endif$}
\def\smname{$if(smname)$$smname$$else$SM$endif$}
\setenumerate{labelsep=*, leftmargin=1.0pc}
%\zexternaldocument*{ManuscriptNew\veraa}
\zexternaldocument*{\msname}
\zexternaldocument*{\smname}
\newcommand{\hlabel}[1]{\label{#1}\hypertarget{#1}{
    \linelabel{line:#1}}}
%\externaldocument[si-]{\smname\veraa}[\smname\veraa.pdf]
\makeatletter
    \newcommand{\clab}[2]{%
        \protected@write\@auxout{\let\clab\@secondoftwo}{
        \string\newlabel{r:#1}{{#2}{}}}%
        \hlabel{#1}#2\hlabel{#1end}}
\makeatother 
\newcommand{\zhypera}[1]{\href[pdfnewwindow]{\msname.pdf\##1}{\\[1ex]\textbf{Page \zpageref{#1}, Line
\zref{line:#1}--\zref{line:#1end}:}\\}}
\newcommand{\cref}[1]{\begin{refquote}\zhypera{#1}{\zref{r:#1}}\\[-0.5ex]\end{refquote}}
% \newenvironment{ra}[1][\unskip]{\par \noindent \\[-1ex] \textbf{Response/Action:}\par\bf}{\ \\}
\renewenvironment{quote}{\begin{question}}{\end{question}}
% \renewenvironment{verbatim}{\begin{ra}}{\end{ra}}
$endif$

% def default corresponding authors and equal contributing authors variables
\def\hascorr{0}
\def\haseqc{0}
% check if corresponding author(s) and equal contributing authors are available
$for(author)$$if(author.correspondence)$\def\hascorr{1}$endif$$if(author.equalcontribution)$\def\haseqc{1}$endif$ $endfor$

\newcommand{\getcorrauthinfo}{
    \subsection{Corresponding Author(s)}
    \def\a{} \def\b{} \def\c{}
    \hspace{-2.2em}
    $for(author)$
    $if(author.correspondence)$
    \textbf{$author.name$:}
    \vspace{-1em}
    \begin{enumerate}[labelindent=-12pt,label=\arabic*.,itemindent=0em,leftmargin=!, itemsep = -10pt]
    $for(author.institute)$ \def\a{$author.institute$}
    $for(institute)$ \def\b{$institute.id$} \def\c{$institute.name$}
        \ifx \a\b \item \c; \fi
    $endfor$ 
    $endfor$ 
        $if(author.email)$\item email: $author.email$;$endif$
        $if(author.orcid)$\item orcid: $author.orcid$;$endif$
        $if(author.tel)$\item Tel: $author.tel$;$endif$
        $if(author.fax)$\item Fax: $author.fax$$endif$
    \end{enumerate}
    $endif$
    $endfor$
}

\newcommand{\getotherauthinfo}{
    \subsection{Author(s)}
    \def\a{} \def\b{} \def\c{}
    \hspace{-2.2em}
    $for(author)$
    $if(author.correspondence)$
    $else$
    \textbf{$author.name$:}
    \vspace{-1em}
    \begin{enumerate}[labelindent=-12pt,label=\arabic*.,itemindent=0em,leftmargin=!, itemsep = -10pt]
    $for(author.institute)$ \def\a{$author.institute$} $for(institute)$ \def\b{$institute.id$} \def\c{$institute.name$}
        \ifx \a\b \item \c; \fi
    $endfor$ 
    $endfor$ 
        $if(author.email)$\item email: $author.email$;$endif$
        $if(author.orcid)$\item orcid: $author.orcid$;$endif$
        $if(author.tel)$\item Tel: $author.tel$;$endif$
        $if(author.fax)$\item Fax: $author.fax$$endif$
    \end{enumerate}
    $endif$
    $endfor$
}

$preamble$

% remove the two line around Abstract
$if(abstract)$
$else$
\makeatletter
\renewcommand{\MaketitleBox}{%
    \resetTitleCounters
    \def\baselinestretch{1}%
    \begin{center}
        \def\baselinestretch{1}%
        \large \@title \par
        \vskip 18pt
        \normalsize\elsauthors \par
        \vskip 30pt
        \footnotesize \itshape \elsaddress \par
    \end{center}
    \vskip 12pt
}
\makeatother
$endif$

\begin{document}
$for(include-before)$
$include-before$
$endfor$
\begin{frontmatter}

   \title{$title$$if(subtitle)$\\\Large{$subtitle$}$endif$}
   $for(author)$\author$if(authorwithinstitute)$[$for(author.institute)$$author.institute$$sep$,$endfor$]$endif${$author.name$$if(author.correspondence)$\corref{corrauth}$endif$$if(author.equalcontribution)$\corref{eqcon}$endif$ $if(author.footnote)$\fnref{$author.footnote$}$endif$}$if(author.email)$\ead{$author.email$}$endif$$endfor$
   $if(authorwithinstitute)$ $for(institute)$ \address[$institute.id$]{$institute.name$} $endfor$ $endif$
    % generate corresponding authors.
    % \StrBehind is from xstring package
    \ifnum \hascorr=1
        \def\corrauths{
            $for(author)$$if(author.correspondence)$and $author.name$ ($author.email$) $endif$$endfor$}
        \cortext[corrauth]{Corresponding to \StrBehind*{\corrauths}{and }.}
    \fi

    % generate equal contributing authors.
    \ifnum \haseqc=1
        \def\eqa{$for(author)$$if(author.equalcontribution)$and $author.name$ $endif$$endfor$}
        \cortext[eqcon]{\StrBehind*{\eqa}{and } are equally contributed to this work.}
    \fi

    $for(footnote)$
    \fntext[$footnote.id$]{$footnote.text$}
    $endfor$

    $if(abstract)$
    \begin{abstract}
        $abstract$
    \end{abstract}
    $if(keywords)$
    \begin{keyword}
        $for(keywords/allbutlast)$$keywords$ \sep $endfor$
        $for(keywords/last)$$keywords$$endfor$
    \end{keyword}
    $endif$
    $endif$
\end{frontmatter}

$body$

$if(authorwithinstitute)$
$else$
\section{Author Information}

\getcorrauthinfo{}

\getotherauthinfo{}

$endif$


$if(natbib)$
$if(bibliography)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$bibliography$}
$endif$
$endif$

$for(include-after)$
$include-after$
$endfor$
\end{document}
