% utmj.cls
%% Custom LaTeX Class for the University of Tennessee Mathematical Journal (UTMJ)
%% Version 1.0 - Built by Tuoc Phan

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{utmj}[2026/05/25 v1.0 UTMJ Automated Journal Class]

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass[twoside,12pt]{article}

% --- Core Packages ---
\RequirePackage[letterpaper,left=1.2in,right=1.2in,top=1in,bottom=1in,headheight=15pt,headsep=15pt]{geometry}
\RequirePackage{amsmath,amssymb,amsfonts,amsthm, mathrsfs}
\RequirePackage{graphicx,xcolor,multicol}
\RequirePackage[T1]{fontenc}
\RequirePackage{lmodern}
\RequirePackage{fancyhdr,titlesec}
\RequirePackage{xparse} % Required for the advanced \author command
\RequirePackage{xstring} %use with page count
\RequirePackage{lastpage}

\RequirePackage{microtype}
\RequirePackage{atbegshi}
%\RequirePackage{academicons} %ORCID Icon
\RequirePackage{orcidlink}
\RequirePackage{tikz}
\RequirePackage{hyperref}
\RequirePackage{cleveref}

% --- Formatting & Hyperlinks ---
\hypersetup{colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue}

\titleformat{\section}{\sffamily\large\bfseries}{\thesection}{1em}{} % \normalfont\large\bfseries
\titleformat{\subsection}{\sffamily\normalsize\bfseries}{\thesubsection}{1em}{} %\normalfont\normalsize\bfseries

% --- Theorem Environments ---
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

% =====================================================
% UTMJ AUTHOR SYSTEM (SAFE / AMS-COMPATIBLE VERSION)
% =====================================================

\newcommand{\@shortauthors}{}  
\newcommand{\@fullauthors}{}
\newcommand{\@shortauthorslist}{}
\newcommand{\theaddresses}{}
\newcounter{utmj@authorcount}

%===== 1. Create the new custom counter
\newcounter{UTMJcontentpage}
% -----------------------------------------
% Syntax: \UTMJauthor[affil ID][short name]{full name}
% -----------------------------------------

\DeclareDocumentCommand{\UTMJauthor}{o o m}{%
  \stepcounter{utmj@authorcount}%
  % -----------------------
  % FULL AUTHOR LIST
  % -----------------------
  \ifx\@fullauthors\@empty
    \IfValueTF{#1}{%
      \gdef\@fullauthors{#3\textsuperscript{#1\hspace{2pt}}}%
    }{%
      \gdef\@fullauthors{#3}%
    }%
  \else
    \IfValueTF{#1}{%
      \g@addto@macro\@fullauthors{\and #3\textsuperscript{#1\hspace{2pt}}}%
    }{%
      \g@addto@macro\@fullauthors{\and #3}%
    }%
  \fi
  % -----------------------
  % RUNNING HEADER AUTHORS (STORE ONLY)
  % -----------------------
  \IfValueTF{#2}{%
    \ifx\@shortauthorslist\@empty
      \gdef\@shortauthorslist{#2}%
    \else
      \g@addto@macro\@shortauthorslist{,#2}%
    \fi
  }{%
    \ifx\@shortauthorslist\@empty
      \gdef\@shortauthorslist{#3}%
    \else
      \g@addto@macro\@shortauthorslist{,#3}%
    \fi
  }%
} 
% ==== FAIL-SAFE LATEX3 PARSER ====
\ExplSyntaxOn
\cs_generate_variant:Nn \seq_set_from_clist:Nn { NV }

\newcommand{\formatshortauthors}{%
  \tl_if_empty:NTF \@shortauthorslist 
    { \relax } 
    {
      % Split the comma list cleanly into a sequence variable
      \seq_set_from_clist:NV \l_tmpa_seq \@shortauthorslist
      % Join the sequence dynamically with proper commas and "and"
      \seq_use:Nnnn \l_tmpa_seq { ~and~ } { ,~ } { ,~and~ }
    }
}
\ExplSyntaxOff

% -----------------------------------------
% Affiliation command
% -----------------------------------------

\newcommand{\UTMJaddress}[2]{%
  \g@addto@macro\theaddresses{%
    {\small\itshape\textsuperscript{#1}#2\par\vskip 0.15em}%
  }%
}
%========
%ORCID INFORMATION
%======
\newcommand{\orcid}[1]{%
  \textsuperscript{\orcidlink{#1}}%
}

% =====================================================
% CORRESPONDING AUTHOR SYSTEM
% =====================================================

\newcommand{\UTMJcorrauthsymbol}{\textsuperscript{\ensuremath{\dagger}}}
\newif\ifutmjcorrauth
\utmjcorrauthfalse

% mark author in name line
\newcommand{\corrauth}{%
  \UTMJcorrauthsymbol%
  \global\utmjcorrauthtrue
}
% print footnote 
\newcommand{\UTMJprintcorrauth}{%
  \ifutmjcorrauth
    \footnotetext{\ensuremath{\dagger}\ Corresponding author}%
  \fi
}

% --- Page Number Parser ---
\newcommand{\@startpage}{1} % Default if \pagerange isn't used

\newcommand{\UTMJpagerange}[1]{%
  \def\@pagerange{#1}%
  \StrBefore{#1}{-}[\tempstartpage]%
  \StrSubstitute{\tempstartpage}{ }{}[\tempstartpage]%
  \ifx\tempstartpage\empty
    \def\@startpage{#1}% 
  \else
    \let\@startpage\tempstartpage
  \fi
  % --- ADD THIS LINE TO SYNC WITH LATEX ENGINE COUNTER ---
  \setcounter{page}{\@startpage}%
}


% --- Metadata Fields ---
\newcommand{\msc}[1]{\def\@msc{#1}}
\newcommand{\email}[1]{\def\@email{#1}}
\newcommand{\shorttitle}[1]{\def\@shorttitle{#1}}
\newcommand{\keywords}[1]{\def\@keywords{#1}}
\newcommand{\volume}[1]{\def\@volume{#1}}
\newcommand{\issue}[1]{\def\@issue{#1}}
\newcommand{\article}[1]{\def\@article{#1}}
\newcommand{\pubyear}[1]{\def\@pubyear{#1}}
\newcommand{\pagerange}[1]{\def\@pagerange{#1}}
\newcommand{\doi}[1]{\def\@doistring{#1}}
\newcommand{\datereceived}[1]{\def\@datereceived{#1}}
\newcommand{\daterevised}[1]{\def\@daterevised{#1}}
\newcommand{\dateaccepted}[1]{\def\@dateaccepted{#1}}

% Defaults
\def\@msc{} \def\@email{} \def\@shorttitle{} \def\@keywords{}
\def\@volume{1} \def\@issue{1} \def\@pubyear{2026} \def\@pagerange{1--15}
\def\@doistring{10.21128/utmj.unknown}
\def\@datereceived{\today} \def\@daterevised{} \def\@dateaccepted{\today}


% --- Cover Page Toggle ---
\definecolor{tennesseeorange}{rgb}{1.0, 0.508, 0.0}
\newif\ifutmjcover
\utmjcovertrue

% User command to disable the journal cover
\newcommand{\nocover}{\utmjcoverfalse}
\newcommand{\withcover}{\utmjcovertrue}

% --- Editorial Variables and Defaults ---
% 1. Editor-in-Chief
\newcommand{\@editorinchief}{Xiaobing Feng} % Default value
\newcommand{\editorinchief}[1]{\renewcommand{\@editorinchief}{#1}}

% 2. Managing Editors
\newcommand{\@managingeditors}{Tuoc Phan \quad\rule[-0.2ex]{0.5pt}{2ex}\quad Steve Wise} % Default value
\newcommand{\managingeditors}[1]{\renewcommand{\@managingeditors}{#1}}

% 3. Editorial Board
\newcommand{\@editorialboard}{% Default value structured for the multicols environment
  \noindent Theodora Bourni\\
  Suzanne Lenhart\\
  Tadele Meghesha\\
  Shashikant Mulay\\
  Duc Nguyen\\[0.2cm] \columnbreak
  \noindent Hung Nguyen\\
  Yulan Qing\\
  Jan Rosinski\\
  Abner J. Salgado\\
  Vyron Vellis
}
\newcommand{\editorialboard}[1]{\renewcommand{\@editorialboard}{#1}}

% 4. Guest Editors (Optional Ñ empty by default)
\newcommand{\@guesteditors}{} 
\newcommand{\guesteditors}[1]{\renewcommand{\@guesteditors}{#1}}

%5. Advisory Board
\newcommand{\@advisoryboard}{}
\newcommand{\advisoryboard}[1]{\renewcommand{\@advisoryboard}{#1}}



\newcommand{\makejournalcover}{%
  \pagestyle{empty}%
  \pagecolor[rgb]{0.94, 0.92, 0.84}% Set cover background color
  
  \vspace*{-1.4cm}% Pushes metadata text tightly into top margin
  \noindent\hfill \textsf{\footnotesize Vol.\ \@volume, No.\ \@issue, \article, \@pubyear, pp.\ \@pagerange}
  \vspace*{0.2cm}% Gap between metadata and title
  
  \begin{center}
    \fontfamily{lmr}\selectfont
    \vspace*{0.2cm}
    {\fontsize{25}{25}\bfseries\scshape\color{tennesseeorange} UNIVERSITY OF TENNESSEE}\\[0.4cm]
    {\fontsize{25}{25}\bfseries\scshape\color{tennesseeorange} MATHEMATICAL JOURNAL}\\[0.4cm]
\ifx\@advisoryboard\empty
      \vskip 0.5cm
    \else 
\fi 
    \includegraphics[width=0.55\textwidth]{UTMJ-LOGO.png}\\[0.8 cm]
  \end{center}
\ifx\@advisoryboard\empty
      \vskip 0.5cm
    \else 
\fi 
  \begin{center}
    {\fontfamily{lmr}\selectfont\bfseries
    {\large EDITOR-IN-CHIEF}}\\[0.2cm]
    {\large \@editorinchief}\\[0.5cm]
\ifx\@advisoryboard\empty
      \vskip 0.5cm
    \else 
\fi 
    {\fontfamily{lmr}\selectfont\bfseries
    {\large MANAGING EDITORS}}\\[0.2cm]
    {\large \@managingeditors}\\[0.5cm]
\ifx\@advisoryboard\empty
      \vskip 0.5cm
    \else 
\fi 
    % --- Dynamic Guest Editors Section (Placed Above Editorial Board) ---
    \ifx\@guesteditors\empty
      % Automatically skips and leaves no blank space if omitted
      \rule{0.7\linewidth}{0.5pt} \vskip 0.6cm
    \else {\fontfamily{lmr}\selectfont\bfseries
      {\large GUEST EDITORS}}\\[0.2cm]
      {\large \@guesteditors}\\[0.5cm]
    \fi
%    \rule{0.7\linewidth}{0.5pt}
%    \vskip 0.6cm
% 
\ifx\@advisoryboard\empty
      \vskip 0.5cm
    \else 
\fi
    {\fontfamily{lmr}\selectfont\bfseries   
    {\large EDITORIAL BOARD}}
    \vskip 0.2cm
    \begin{minipage}{0.75\linewidth}
      \begin{multicols}{2}
        \centering
        \@editorialboard
      \end{multicols}
    \end{minipage}\\[0.5cm]
% \end{center}
\ifx\@advisoryboard\empty
      % Automatically skips and leaves no blank space if omitted
    \else 
{\fontfamily{lmr}\selectfont\bfseries  
{\large ADVISORY BOARD}} \vskip 0.2cm
    \begin{minipage}{0.75\linewidth}
      \begin{multicols}{2}
        \centering
        \@advisoryboard
      \end{multicols}
    \end{minipage}
\fi 
  \end{center}


  \vfill 
  \clearpage
  \pagecolor{white}% Reset background color for the actual paper text
  \setcounter{page}{\@startpage}
}

%% --- Cover Page Layout ---
%\definecolor{tennesseeorange}{rgb}{1.0, 0.508, 0.0}
%
%\newcommand{\makejournalcover}{%
%  \pagestyle{empty}%
%  \pagecolor[rgb]{0.94, 0.92, 0.84}% Set cover background color
%  
%  \vspace*{-1.4cm}% Pushes metadata text tightly into top margin
%  \noindent\hfill \textsf{\footnotesize Vol.\ \@volume, No.\ \@issue, \@pubyear, pp.\ \@pagerange}
%  \vspace*{0.5cm}% Gap between metadata and title
%  
%  \begin{center}
%    \fontfamily{lmr}\selectfont
%    \vspace*{0.5cm}
%    {\fontsize{25}{25}\bfseries\scshape\color{tennesseeorange} UNIVERSITY OF TENNESSEE}\\[0.4cm]
%    {\fontsize{25}{25}\bfseries\scshape\color{tennesseeorange} MATHEMATICAL JOURNAL}\\[0.8cm]
%    \includegraphics[width=0.55\textwidth]{UTMJ-LOGO.png}\\[1.5cm]
%  \end{center}
%
%  \begin{center}
%    \fontfamily{lmr}\selectfont\bfseries
%    {\large EDITOR-IN-CHIEF}\\[0.1cm]
%    {\large Xiaobing Feng}\\[0.6cm]
%    
%    {\large MANAGING EDITORS}\\[0.1cm]
%    {\large Tuoc Phan \quad\rule[-0.2ex]{0.5pt}{2ex}\quad Steve Wise}\\[0.8cm]
%
%    \rule{0.7\linewidth}{0.5pt}
%    \vskip 0.8cm
%    
%    {\large EDITORIAL BOARD}
%    \vskip 0.4cm
%    
%    \begin{minipage}{0.75\linewidth}
%      \begin{multicols}{2}
%        \centering
%        \noindent Theodora Bourni\\
%        Suzanne Lenhart\\
%        Tadele Meghesha\\
%        Shashikant Mulay\\
%        Duc Nguyen\vfill\columnbreak
%        \noindent Hung Nguyen\\
%        Yulan Qing\\
%        Jan Rosinski\\
%        Abner J. Salgado\\
%        Vyron Vellis
%      \end{multicols}
%    \end{minipage}
%  \end{center}
%
% \vfill 
%  \clearpage
%  \pagecolor{white}% Reset background color for the actual paper text
%  \setcounter{page}{\@startpage}
%}

% Automatically trigger the merged cover page right when the document builds
\AtBeginDocument{%
  \ifutmjcover
    \makejournalcover
     \setcounter{UTMJcontentpage}{0}
  \fi 
  \pagestyle{fancy}
  \setcounter{UTMJcontentpage}{1}
}
% 2. Automatically advance the counter on every page shipout
\AddToHook{shipout/before}{\stepcounter{UTMJcontentpage}}

% --- Headers & Footers (Clean, Alternating, Native Setup) ---

\fancyhf{} % Clear all defaults
% Running Headers (Blank on the first content page)
\fancyhead[C]{%
  \ifnum\value{UTMJcontentpage}=1 %
    % Page 1: Leave completely blank
  \else
    \ifodd\value{UTMJcontentpage}%
      {\small\formatshortauthors}% % Page 3, 5, 7... (Odd layout)
    \else%
      {\small\@shorttitle}%        % Page 2, 4, 6... (Even layout)
    \fi%
  \fi
}
% Clear any default layout settings first
\fancyfoot{} 
% Combine everything into the main footer block using our physical counter
\fancyfoot[L]{%
    \ifnum\value{UTMJcontentpage}=1 %
      % Page 1 Left: Completely blank (No copyright!)
    \else
      \ifodd\value{UTMJcontentpage}%
        % Physical Odd Page 3, 5... : Copyright goes on the Left
        \footnotesize\copyright\ \@pubyear\ \textls[60]{\textsc{University of Tennessee Mathematical Journal}}%
      \else%
        % Physical Even Page: Page Number goes on the Left
        \small\thepage%
      \fi%
    \fi
  }%
  
\fancyfoot[R]{%
    \ifnum\value{UTMJcontentpage}=1 %
      % Page 1 Right: Just print the page number
      \small\thepage%
    \else
      \ifodd\value{UTMJcontentpage}%
        % Physical Odd Page 3, 5... : Page Number goes on the Right
        \small\thepage%
      \else%
        % Physical Even Page: Copyright goes on the Right
        \footnotesize\copyright\ \@pubyear\ \textls[60]{\textsc{University of Tennessee Mathematical Journal}}%
      \fi%
    \fi
  }%
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

% Ensure style holds even on standard structural changes
\fancypagestyle{plain}{
\fancyfoot{} 
\fancyfoot[L]{%
    \ifnum\value{UTMJcontentpage}=1 %
      % Page 1 Left: Completely blank (No copyright!)
    \else
      \ifodd\value{UTMJcontentpage}%
        % Physical Odd Page 3, 5... : Copyright goes on the Left
        \footnotesize\copyright\ \@pubyear\ \textls[60]{\textsc{University of Tennessee Mathematical Journal}}%
      \else%
        % Physical Even Page: Page Number goes on the Left
        \small\thepage%
      \fi%
    \fi
  }%
  
  \fancyfoot[R]{%
    \ifnum\value{UTMJcontentpage}=1 %
      % Page 1 Right: Just print the page number
      \small\thepage%
    \else
      \ifodd\value{UTMJcontentpage}%
        % Physical Odd Page 3, 5... : Page Number goes on the Right
        \small\thepage%
      \else%
        % Physical Even Page: Copyright goes on the Right
        \footnotesize\copyright\ \@pubyear\ \textls[60]{\textsc{University of Tennessee Mathematical Journal}}%
      \fi%
    \fi
  }%
\renewcommand{\headrulewidth}{0pt}%
\renewcommand{\footrulewidth}{0pt}%
}

% --- Custom Environments ---
\providecommand\blfootnote[1]{%
  \begingroup\renewcommand\thefootnote{}\footnote{#1}\addtocounter{footnote}{-1}\endgroup
}

\newenvironment{acknowledgments}{%
  \vspace{1.5em}\section*{Acknowledgments}\small\par\noindent\ignorespaces
}{\par\vspace{1.5em}}

\renewenvironment{abstract}{%
  \small\begin{list}{}{%
    \setlength{\leftmargin}{0.4in}\setlength{\rightmargin}{0.4in}%
    \setlength{\topsep}{0pt}\setlength{\partopsep}{0pt}\setlength{\parsep}{0pt}%
  }\item[]\noindent{\bfseries Abstract.}\quad\itshape
}{\end{list}\vspace{0.8em}}

\let\oldthebibliography\thebibliography
\let\oldendthebibliography\endthebibliography
\renewenvironment{thebibliography}[1]{%
  \begin{oldthebibliography}{#1}\small
  \setlength{\itemsep}{2pt}\setlength{\parsep}{0pt}%
  \addcontentsline{toc}{section}{\refname}%
}{\end{oldthebibliography}}

% --- Title Block ---
\renewcommand{\@maketitle}{%
  \newpage\null\vspace*{-5.5em} 
  \begin{flushleft}
    {\small \textls[80]{\textsc{University of Tennessee Mathematical Journal}}}\\
    {\footnotesize Vol.\ \@volume, No.\ \@issue, Art.\ \@article, pp.\ \@pagerange\ (\@pubyear)}\\
    {\footnotesize DOI: \href{https://doi.org/\@doistring}{\@doistring}}
  \end{flushleft}
  \vskip 1.2em 
%====== 
\begin{center}%
    {\LARGE \bfseries\centering\@title \par}\vskip 1.0em 
    {\large
      \let\and\quad  
      \@fullauthors\par
    }%
    \ifx\theaddresses\@empty\else\vskip 0.4em\theaddresses\fi 
  \end{center}%
%====
 \par\vskip 0.2em 
  \begin{center} 
    {\footnotesize Received: \@datereceived \ifx\@daterevised\@empty\else; Revised: \@daterevised\fi ; Accepted: \@dateaccepted}
  \end{center}
  \par\vskip 1.0em 
  \ifx\@msc\@empty\else\blfootnote{\textit{2020 Mathematics Subject Classification.} \@msc}\fi
  \ifx\@keywords\@empty\else\blfootnote{\textit{Keywords:} \@keywords}\fi
  \ifx\@email\@empty\else\blfootnote{\textit{E-mail addresses:} \@email}\fi
 \UTMJprintcorrauth
  \thispagestyle{plain}% Forces custom footer onto the first structural paper page
% As soon as page 1 ships out, ensure page 2 and onward are fancy
  \AddToHook{shipout/after}{%
    \global\pagestyle{fancy}%
  }%
  \setcounter{footnote}{0}%
}