%%
%% This is file `BICA.cls', [2024/1/20 BICA document class]
%%
%% built from the standard `article' document class by
%% BICA Copy editor R.C. Bunge.  31 October 2024.
%%
%% Structure of this file is borrowed extensively from
%% ``The LaTeX Companion'' 2nd edition.
%% All page number references are for TLC2e.
%%
%% Much of the initial work was completed by
%% BICA Production Manager and Editor-in-Chief D.L. Kreher.
%%
%% 4 Jan 2025 D.L. Kreher: Added \ContactsHere.
%%	Now \begin{Contacts}...\end{Contacts}
%%	can be placed anywhere between \documentclass{BICA}
%%	and \end{document}. Then we put \ContactsHere 
%%	on the page where the contact information is to appear.
%%	they will appear at the bottom of that page if there 
%%	is room; otherwise they will appear at the top (I think) 
%%	of the next page.  \ContactsHere must of course be 
%%	invoked after "\end{Contacts}" and befor "\end{document}.
%%	Usually it is placed immediately after the bibliography.
%%
%% 4 Jan 2025 D.L. Kreher: Added \RequirePackage[abbrev]{amsrefs}
%%	and various Bibspec commands to specify how bibliography
%%	entries will look if bibtex is used.
%%
%% 4 Jan 2025 D.L. Kreher: Revised the \Contacts code.
%%	Now with out using \ContactsHere, the contact info
%%	will be written on the last page of the article.
%%	However if \ContactsHere is invoked on some page,
%%	then the contact info will be written at the bottom 
%%	of that page  and not also on the last page. This may 
%%	useful if there are appendices.
%%
%% 7 Jan 2025 D.L. Kreher: moved the code that adjust the 
%%	inter-bibitem spacing after the 
%%       \RequirePackage[abbrev]{amsrefs}
%%	command. Also after this command the font and fontsize
%%	were reset back to normalfont and normalsize.
%%
%% 8 Jan 2025 D.L. Kreher: redefined \CAU the corresponding
%%	author marker to use \textsuperscript instead of the
%%	mathmode "^". This generates proper spacing after the
%%	marker (star).
%%
%% 16 Jan 2025 D.L. Kreher: Removed hyperlinks, because we
%%	includepdfpages to up load the article's pdf into
%%	the volume and to make reprints. It is at this time
%%	a known issue with includepdfpages that hyperlinks
%%	will not upload correrctly. However it looks like
%%	there maybe some very recent advances that may address
%%	this issue, see the PAX project :
%%	https://ctan.org/pkg/pax?lang=en
%%
%% 16 Jan 2025 R.C. Bunge: Added editor notes  commands
%%
%% 16 Jan 2025 D.L. Kreher: Added a math font for v
%%	to distinguish between Latin v and Greek nu
%%	
%% 18 Jan 2025 D.L. Kreher: Included
%%		\RequirePackage[hidelinks]{hyperref}
%%	which is necessary to handled URLs properly in the
%%	bibliography.
%%
%% 20 Jan 2025 R.C. Bunge: improvements the Editor note commands. 
%%	And defined medsep and longseo for the 
%%	enumitem list environments. Also medsep is now the default.
%%
%% ------------------------------------------------------------
%%   Identification
%% ------------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
 \ProvidesClass{BICA}
%% 
%% ------------------------------------------------------------
%%  Initial Code
%% ------------------------------------------------------------
\newif\if@print

%% ------------------------------------------------------------
%%  Set flag for production
%% ------------------------------------------------------------
\usepackage{etoolbox}
\newtoggle{ProdFlag}
\togglefalse{ProdFlag}
%% ------------------------------------------------------------
%%  Declaration of Options
%% ------------------------------------------------------------
\DeclareOption{11pt}{\OptionNotUsed}
\DeclareOption{12pt}{\OptionNotUsed}
\DeclareOption{twocolumn}{\OptionNotUsed}
\DeclareOption{titlepage}{\OptionNotUsed}
\DeclareOption{fleqn}{\OptionNotUsed}
\DeclareOption{leqno}{\OptionNotUsed}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\DeclareOption{onlinecopy}{\@printfalse \PassOptionsToClass{oneside}{article}}
\DeclareOption{printcopy}{\@printtrue \PassOptionsToClass{twoside}{article}}
\DeclareOption{Prod}{\toggletrue{ProdFlag}}
%% ------------------------------------------------------------
%%  Execution of Options
%% ------------------------------------------------------------
\ExecuteOptions{printcopy}
\ProcessOptions \relax
%% ------------------------------------------------------------
%%  Package Loading
%% ------------------------------------------------------------
\LoadClass{article}

\RequirePackage[centering, text={4.5in,7.125in}, paperwidth=6in, paperheight=9in]{geometry}

\renewcommand\bfdefault{b}

\RequirePackage[parfill, skip=1\baselineskip plus 1ex minus 2pt]{parskip}
\newcommand\killparfillskip{\hspace*{-30pt}}
\RequirePackage{amsmath,amsthm,amssymb,thmtools,mathtools}
\RequirePackage[defaultlines=2,all]{nowidow}
\RequirePackage{embrac,xcolor,xurl}
\RequirePackage{float,enumitem}
%%
\RequirePackage{titling}
  \setlength{\droptitle}{-2\baselineskip} 
  \pretitle{\begin{flushleft}\LARGE\bfseries}
  \posttitle{\end{flushleft}\vskip2em}
  \preauthor{\begin{flushleft}\scshape}
  \postauthor{\vskip-2.5\baselineskip\end{flushleft}}
%%
\date{}
\renewcommand{\date}[1]{\relax}
%%
\newcommand{\email}[1]{{\rm\href{mailto:#1}{#1}}}
\newcommand{\emailx}[1]{\textnormal{#1}}
%%
%% Keywords and classification commands
%%
\RequirePackage[hang]{footmisc}
\setlength{\footnotemargin}{0em}
\setlength{\skip\footins}{2em}

\newcommand\keywords[1]{%
  \begin{NoHyper}%
  \let\svthefootnote\thefootnote%
  \let\thefootnote\relax\footnotetext{\raggedright\hspace*{-\footnotemargin}\textbf{Key words and phrases:} #1}%
  \let\thefootnote\svthefootnote%
  \end{NoHyper}%
}
\newcommand\classification[1]{%
  \begin{NoHyper}%
  \let\svthefootnote\thefootnote%
  \let\thefootnote\relax\footnotetext{\raggedright\hspace*{-\footnotemargin}\textbf{AMS (MOS) Subject Classifications:} #1}%
  \let\thefootnote\svthefootnote%
  \end{NoHyper}%
}


%%
%% Some small adjustments
%%
%\setlength{\parskip}{\baselineskip}%
%\setlength{\parindent}{0pt}%
\settowidth{\thanksmarkwidth}{*}
\setlength{\thanksmargin}{-\thanksmarkwidth}
\SetEnumitemKey{medsep}{topsep=-6pt, itemsep=-6pt}
\SetEnumitemKey{longsep}{topsep=0pt, itemsep=0pt}
\setlist{medsep}
%%
%% To distinguish between Latin v and Greek nu
%%
\DeclareSymbolFont{CMletters}{OML}{cmm}{m}{it}
\DeclareMathSymbol{v}{\mathord}{CMletters}{`v}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Margin notes from Editor to Author
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand*{\EditorNote}[1]{%
  \marginpar[
    \raggedleft\fcolorbox{red}{red!25}{\parbox[t]{15mm}{\tiny\raggedright #1}}\hspace*{-3mm}
  ]{
    \hspace*{-3mm}\fcolorbox{red}{red!25}{\parbox[t]{15mm}{\tiny\raggedright #1}}}%
  }
\newcommand*{\InlineEditorNote}[1]{\smash{\fcolorbox{red}{red!25}{#1}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand*{\CAU}{\textsuperscript{$\star$}}
\g@addto@macro\bfseries{\boldmath}

\protected\def\verythinspace{%
  \ifmmode
    \mskip0.5\thinmuskip
  \else
    \ifhmode
      \kern0.08334em
    \fi
  \fi
}
%% ------------------------------------------------------------
%%  Main Code
%% ------------------------------------------------------------
%%
%% Define Abstract environment
%%
\renewenvironment{abstract}
 {\par\vspace{-2.5\baselineskip}\textbf{\abstractname.}}
 {\par\medskip}
%%
%% define pmod* a nicer pmod.
%%
\let\old@pmod\pmod
\renewcommand{\pmod}{\@ifstar\@pmods\old@pmod}
\def\@pmods#1{\mkern4mu({\operator@font mod}\mkern 6mu#1)}
%%
%%
 \newcommand*{\OldAuthorAddress}[3]%
 {\par{\small%\noindent
     \textsc{#1}\\ %%%  #1 = Author's Name
     \textsc{#2}\\ %%%  #2 = Author's Affiliation
     \email{#3} %%%  #3 = Author's Email Address
   \par
 }}
 \newenvironment{OldContacts}%
   {\par\vfill}
   {\clearpage}
%%
%%
%%
%% BICA definitions
%%
\declaretheoremstyle[
  headfont=\normalfont\bfseries,
  notefont=\mdseries, notebraces={\textup{(}}{\textup{)}},
  bodyfont=\normalfont,
  postheadspace=0.4em,
qed=\qedsymbol
]{BICAdefinition}
%%
\theoremstyle{BICAdefinition}
 \newtheorem{construction}{Construction}[section]
 \newtheorem{definition}[construction]{Definition}
 \newtheorem{remark}[construction]{Remark}
 \newtheorem{remarks}[construction]{Remarks}
 \newtheorem{example}[construction]{Example}
 \newtheorem{exercise}[construction]{Exercise}
 \newtheorem{observation}[construction]{Observation}
 \newtheorem{problem}[construction]{Problem}
 \newtheorem{conjecture}[construction]{Conjecture}
%%
 \newtheorem*{construction*}{Construction}
 \newtheorem*{definition*}{Definition}
 \newtheorem*{remark*}{Remark}
 \newtheorem*{remarks*}{Remarks}
 \newtheorem*{example*}{Example}
 \newtheorem*{exercise*}{Exercise}
 \newtheorem*{observation*}{Observation}
 \newtheorem*{problem*}{Problem}
 \newtheorem{conjecture*}{Conjecture}
%%
%% BICA theorems
%%
\declaretheoremstyle[
  headfont=\normalfont\bfseries,
  notefont=\mdseries, notebraces={\textup{(}}{\textup{)}},
  bodyfont=\slshape,
  postheadspace=0.4em,
qed=\qedsymbol
]{BICAtheorem}
%%
\theoremstyle{BICAtheorem}
 \newtheorem{theorem}[construction]{Theorem}
 \newtheorem{fact}[construction]{Fact}
 \newtheorem{lemma}[construction]{Lemma}
 \newtheorem{claim}[construction]{Claim}
 \newtheorem{proposition}[construction]{Proposition}
 \newtheorem{corollary}[construction]{Corollary}
 \newtheorem{question}[construction]{Question}
%%
 \newtheorem*{fact*}{Fact}
 \newtheorem*{theorem*}{Theorem}
 \newtheorem*{lemma*}{Lemma}
 \newtheorem*{claim*}{Claim}
 \newtheorem*{proposition*}{Proposition}
 \newtheorem*{corollary*}{Corollary}
 \newtheorem*{question*}{Question}
%%
 \numberwithin{figure}{section}
 \numberwithin{table}{section}
%%
%%
%% cammand to make aliases for theorem-like environments.
%%
\newcommand{\envalias}[2]{\newenvironment{#1}{\begin{#2}}{\end{#2}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Example
%%
%% \envalias{thm}{theorem}
%% \begin{thm}
%%  E=mc^2
%% \end{thm}
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Used to reduced inter-word spacing as a last resort. 
%%   (EDITOR USE ONLY!)
%%
\newcommand*{\SetSpaces}[2]{%
  \begingroup
  \spaceskip=#1
  \xspaceskip=#1
  #2%
  \endgroup}
\iftoggle{ProdFlag}%
{%
 \pagestyle{empty}
 \g@addto@macro\maketitle{\thispagestyle{empty}}
}{}
%%
%% Author contacts
%%
  \newcommand*{\BICA@Name}{}%
  \newcommand*{\BICA@Affil}{}%
  \newcommand*{\BICA@email}{}%
%%
  \NewHook{BICAContacts}
  \newcommand{\ContactsHere}{\UseOneTimeHook{BICAContacts}}
  \AtEndDocument{\UseOneTimeHook{BICAContacts}}
  \newcommand*{\AuthorAddress}[3]%
  {\AddToHook{BICAContacts}{\par{\small
      \textsc{#1}\\ %%%  #1 = Author's Name
      \textsc{#2}\\ %%%  #2 = Author's Affiliation
      \email{#3}\killparfillskip %%%  #3 = Author's Email Address
    \par
  }}}
  \newenvironment{Contacts}%
  {\AddToHook{BICAContacts}{\par\vfill}}
  {\AddToHook{BICAContacts}{\clearpage}}
%%
%% bibliography amsrefs and bibtex 
%%
 \RequirePackage[abbrev]{amsrefs}\relax
\RequirePackage{xurl}
\RequirePackage[hidelinks]{hyperref}
%%
\renewcommand{\biblistfont}{%
    \normalfont
    \normalsize
}
%%
%% Reduce space between bibitems
%%
\let\OLDthebibliography\thebibliography
\renewcommand\thebibliography[1]{
  \OLDthebibliography{#1}
  \setlength{\parskip}{0pt} 
  \setlength{\itemsep}{0.5ex plus 0.3ex}
}
  \BibSpec{thesis}{%
  +{}{\PrintAuthors}	{author}
  +{,}{ \textsl}	{title}
  +{,}{ \PrintThesisType}	{type}
  +{,}{ \textsc}	{organization}
  +{,}{ \textrm}	{date}
  +{,}{ \textrm}	{note}
  +{.}{ }			{transition}
  }
  \BibSpec{article}{%
  +{}{\PrintAuthors}	{author}
  +{,}{ \textrm}		{title}
  +{,}{ \textsl}		{journal}
  +{}{ \textbf}		{volume}
  +{}{\parenthesize}	{number}
  +{}{ \parenthesize}	{date}
  +{,}{ }	{pages}
  +{,}{ \url}{url}
  +{,}{ \textrm}		{note}
  +{.}{ }			{transition}
  }
  \BibSpec{proceedings}{%
  +{}{\PrintAuthors}	{editor}
  +{,}{ \textsl}	{title}
  +{,}{ \textsc}	{series}
  +{,}{ \textrm}	{publisher}
  +{,}{ \textrm}	{date}
  +{.}{ }			{transition}
  }
  \BibSpec{collection.article}{%
  +{}{\PrintAuthors}	{author}
  +{,}{ \textrm}	{title}
  +{,}{ in \textsl}	{booktitle}
  +{,}{ \PrintEditorsA}	{editor}
  +{,}{ \textrm}		{publisher}
  +{,}{ \parenthesize}	{date}
  +{,}{ }	{pages}
  +{.}{ }			{transition}
  }
  \BibSpec{report}{%
  +{}{\PrintAuthors}	{author}
  +{,}{ \textrm}	{title}
  +{,}{ \textsl}	{organization}
  +{,}{ Tech. Rep.}	{number}
  +{,}{ \parenthesize}	{date}
  +{,}{ \url}	{url}
  +{.}{ }			{transition}
  }
  \BibSpec{miscellaneous}{%
  +{}{\PrintAuthors}	{author}
  +{,}{ \textrm}	{title}
  +{,}{ \parenthesize}	{date}
  +{,}{ \url}	{url}
  +{,}{ \textrm}	{note}
  +{.}{ }			{transition}
  }
  \BibSpec{book}{%
  +{}{\PrintAuthors}	{author}
  +{}{\PrintEditorsA}	{editor}
  +{,}{ \textsl}	{title}
  +{,}{ \textrm}	{publisher}
  +{,}{ \textrm}	{date}
  +{.}{ }			{transition}
  }
