\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{samsabstract}[2026/08/30 SAMS conference abstract]

% pass any class options straight through to article
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass{article}

% Core AMS packages only (present in a minimal LaTeX install). Optional
% extras (mathtools, mathrsfs, bm, stmaryrd, braket, tikz, tikz-cd) are left
% for the author to enable in the abstract file if needed.
\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\RequirePackage{amssymb}
\RequirePackage{amsthm}      % theorem environments and \proof
\RequirePackage{amscd}       % simple CD commutative diagrams

% ----- theorem environments (unnumbered) -----
\theoremstyle{plain}
\newtheorem*{theorem}{Theorem}
\newtheorem*{lemma}{Lemma}
\newtheorem*{proposition}{Proposition}
\newtheorem*{corollary}{Corollary}
\newtheorem*{conjecture}{Conjecture}
\theoremstyle{definition}
\newtheorem*{definition}{Definition}
\newtheorem*{example}{Example}
\newtheorem*{question}{Question}
\theoremstyle{remark}
\newtheorem*{remark}{Remark}

% ----- internal storage -----
\newcommand{\sams@title}{}
\newcommand{\sams@spkfirst}{}
\newcommand{\sams@spklast}{}
\newcommand{\sams@spkemail}{}
\newcommand{\sams@collabname}{}
\newcommand{\sams@authors}{}
\newcommand{\sams@institutions}{}
\newcommand{\sams@affsep}{}
\newcommand{\sams@session}{General}
\newcommand{\sams@classification}{}
\newcommand{\sams@refs}{}

% ----- title -----
\newcommand{\talktitle}[1]{\def\sams@title{#1}}

% ----- presenter (first author) -----
% display name is "First Last"; legacy \speakername sets the full name
\newcommand{\sams@spkdisplay}{%
  \ifx\sams@spkfirst\@empty\sams@spklast\else\sams@spkfirst~\sams@spklast\fi}
\newcommand{\speakerfirstname}[1]{\def\sams@spkfirst{#1}}
\newcommand{\speakerlastname}[1]{\def\sams@spklast{#1}}
\newcommand{\speakername}[1]{\def\sams@spkfirst{}\def\sams@spklast{#1}}
\newcommand{\speakeremail}[1]{\def\sams@spkemail{#1}}
\newcommand{\speakeraffiliation}[1]{%
  \def\sams@authors{\underline{\mbox{\sams@spkdisplay}}\textsuperscript{#1}~(\sams@spkemail)}%
}

% ----- collaborators (email recorded but not shown: presenter email only) -----
\newcommand{\collaboratorname}[1]{\def\sams@collabname{#1}}
\newcommand{\collaboratoremail}[1]{}
\newcommand{\sams@addcollab}[2]{\g@addto@macro\sams@authors{,~#1\textsuperscript{#2}}}
\newcommand{\collaboratoraffiliation}[1]{%
  \expandafter\sams@addcollab\expandafter{\sams@collabname}{#1}%
}

% ----- affiliations (number -> institution) -----
\newcommand{\sams@addaff}[3]{\g@addto@macro\sams@institutions{#1#3\textsuperscript{#2}}}
\newcommand{\affiliation}[2]{%
  \expandafter\sams@addaff\expandafter{\sams@affsep}{#1}{#2}%
  \def\sams@affsep{\\}%
}

% ----- session and classification -----
% blank special session defaults to "General"
\newcommand{\SAMSSpecialSession}[1]{%
  \edef\sams@tmp{\zap@space#1 \@empty}%
  \ifx\sams@tmp\@empty\else\def\sams@session{#1}\fi
}
\newcommand{\SAMSClassification}[1]{\def\sams@classification{#1}}

% ----- references -----
\newcommand{\sams@printref}[2]{\noindent[#1]\hspace{5pt}#2\\[4pt]}
\newcommand{\refitem}[2][]{\g@addto@macro\sams@refs{\sams@printref{#1}{#2}}}

% ----- rendering -----
\newenvironment{talkabstract}{%
  \begin{center}\large\bfseries\MakeUppercase{\sams@title}\end{center}%
  \begin{center}\sams@authors\end{center}%
  \begin{center}\sams@institutions\end{center}%
  \begin{center}\bfseries Abstract\end{center}%
  \par\medskip\noindent\ignorespaces
}{\par}

\newenvironment{references}{}{}

\AtEndDocument{%
  \par\bigskip
  \noindent{\bf SAMS Special Session:}~\sams@session\\
  \noindent{\bf SAMS Classification:}~\sams@classification
  \ifx\sams@refs\@empty\else
    \par\medskip
    \begin{center}\bfseries References\end{center}%
    \sams@refs
  \fi
}

\endinput
