$doc-class.tex()$
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{setspace}
$if(docmode)$
\geometry{inner=1in, outer=1in}
\fancyhfoffset[LE,RO]{0cm}
$endif$

$if(geometry)$
\geometry{$for(geometry)$$geometry$$sep$,$endfor$}
\fancyhfoffset[LE,RO]{0cm}
$endif$

$if(lang)$
\usepackage[bidi=default]{babel}
$if(babel-lang)$
\babelprovide[main,import]{$babel-lang$}
$if(title-block-keywords)$
\StartBabelCommands{$babel-lang$}{captions} [unicode, fontenc=TU EU1 EU2, charset=utf8] \SetString{\keywordname}{$title-block-keywords$}
\EndBabelCommands
$endif$


$if(mainfont)$
\babelfont{rm}[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$$if(mainfontfallback)$,RawFeature={fallback=mainfontfallback}$endif$]{$mainfont$}
$endif$
$endif$
$for(babel-otherlangs)$
\babelprovide[import]{$babel-otherlangs$}
$endfor$
$for(babelfonts/pairs)$
\babelfont[$babelfonts.key$]{rm}{$babelfonts.value$}
$endfor$
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
$endif$

\RequirePackage{longtable}
\RequirePackage{threeparttablex}

\usepackage{framed}


$header.tex()$

$if(highlighting-macros)$
$highlighting-macros$
$endif$

$tightlist.tex()$

$tables.tex()$

$graphics.tex()$


$citations.tex()$


$if(numbered-lines)$
$if(journalmode)$
\usepackage[nolongtablepatch]{lineno}
\setlength\linenumbersep{5pt}
\setlength\columnsep{25pt}
$else$
\usepackage[nolongtablepatch]{lineno}
$endif$

\linenumbers
$endif$

$if(linestretch)$
\setstretch{$linestretch$}
$endif$

$if(mathspec)$
\usepackage{mathspec}
$endif$

$if(mainfont)$
\usepackage{fontspec} 
$else$
\usepackage{newtx}
$endif$

\defaultfontfeatures{Scale=MatchLowercase}$-- must come before Beamer theme
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}

$if(fontfamily)$
\usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$}
$endif$
$if(mainfont)$
  \setmainfont[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$$if(mainfontfallback)$,RawFeature={fallback=mainfontfallback}$endif$]{$mainfont$}
$endif$
$if(sansfont)$
  \setsansfont[$for(sansfontoptions)$$sansfontoptions$$sep$,$endfor$$if(sansfontfallback)$,RawFeature={fallback=sansfontfallback}$endif$]{$sansfont$}
$endif$
$if(monofont)$
  \setmonofont[$for(monofontoptions)$$monofontoptions$$sep$,$endfor$]{$monofont$}
$endif$

$for(fontfamilies)$
  \setmonofont[$for(monofontoptions)$$monofontoptions$$sep$,$endfor$$if(monofontfallback)$,RawFeature={fallback=monofontfallback}$endif$]{$monofont$}
$endfor$

$if(mathfont)$
\setmathfont(Digits,Latin,Greek)[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$}
$endif$

$if(CJKmainfont)$
    \usepackage{xeCJK}
    \setCJKmainfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmainfont$}
    $if(CJKsansfont)$
      \setCJKsansfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKsansfont$}
    $endif$
    $if(CJKmonofont)$
      \setCJKmonofont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmonofont$}
    $endif$
$endif$

$title.tex()$

$if(journalmode)$
\usepackage{pbalance}
% \usepackage{float}
\makeatletter
\let\oldtpt\ThreePartTable
\let\endoldtpt\endThreePartTable
\def\ThreePartTable{\@ifnextchar[\ThreePartTable@i \ThreePartTable@ii}
\def\ThreePartTable@i[#1]{\begin{figure}[!htbp]
\onecolumn
\begin{minipage}{0.485\textwidth}
\oldtpt[#1]
}
\def\ThreePartTable@ii{\begin{figure}[!htbp]
\onecolumn
\begin{minipage}{0.48\textwidth}
\oldtpt
}
\def\endThreePartTable{
\endoldtpt
\end{minipage}
\twocolumn
\end{figure}}
\makeatother


\makeatletter
\let\endoldlt\endlongtable		
\def\endlongtable{
\hline
\endoldlt}
\makeatother

\newenvironment{twocolumntable}% environment name
{% begin code
\begin{table*}[!htbp]%
\onecolumn%
}%
{%
\twocolumn%
\end{table*}%
}% end code
$else$
\makeatletter
\let\endoldlt\endlongtable
\def\endlongtable{
\hline
\endoldlt
}
\makeatother
$if(floatsintext)$
$else$
$if(manuscriptmode)$
\RequirePackage{longtable}
\DeclareDelayedFloatFlavor{longtable}{table}
$endif$
$endif$
$endif$

\urlstyle{same}


$for(header-insert)$
$header-insert$
$endfor$

$for(header-includes)$
$header-includes$
$endfor$

% From https://tex.stackexchange.com/a/645996/211326
%%% apa7 doesn't want to add appendix section titles in the toc
%%% let's make it do it
\makeatletter
\xpatchcmd{\appendix}
  {\par}
  {\addcontentsline{toc}{section}{\@currentlabelname}\par}
  {}{}
\makeatother

%% Disable longtable counter
%% https://tex.stackexchange.com/a/248395/211326

\usepackage{etoolbox}

\makeatletter
\patchcmd{\LT@caption}
  {\bgroup}
  {\bgroup\global\LTpatch@captiontrue}
  {}{}
\patchcmd{\longtable}
  {\par}
  {\par\global\LTpatch@captionfalse}
  {}{}
\apptocmd{\endlongtable}
  {\ifLTpatch@caption\else\addtocounter{table}{-1}\fi}
  {}{}
\newif\ifLTpatch@caption
\makeatother

\begin{document}

$if(suppress-title-page)$
$else$
\maketitle
$endif$


$if(toc)$
\hypertarget{toc}{}
\tableofcontents
\newpage
\section[Introduction]{$title$}
$else$
$if(suppress-title-page)$
$if(suppress-title-introduction)$
$else$
\section[Introduction]{$title$}
$endif$
$endif$
$endif$

$if(numbersections)$
\setcounter{secnumdepth}{$if(number-depth)$$number-depth$$else$3$endif$}
$endif$

\setlength\LTleft{0pt}

$if(numbered-lines)$
\resetlinenumber[1]
$endif$

$if(first-page)$
\setcounter{page}{$first-page$}
$endif$

\ifdefined\Shaded\renewenvironment{Shaded}{\begin{snugshade}\begin{singlespace}}{\end{singlespace}\end{snugshade}}\fi

$if(journalmode)$
$else$

\ifdefined\cslhangindent\else\newlength{\cslhangindent}\fi
\ifdefined\csllabelwidth\else\newlength{\csllabelwidth}\fi
\setlength{\cslhangindent}{0.5in}

$endif$

$body$

$before-bib.tex()$

$if(zerocitations)$
$else$
$biblio.tex()$
$endif$

$for(include-after)$
$include-after$
$endfor$

$after-body.tex()$


\end{document}
