%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This is file `MR.cls',
% a class file for Mathematical Reports,
% Publishing House of the Romanian Academy, ISSN: 2285-3898.
%
% Copyright (c) Ionut Tutu [ittutu at gmail dot com]
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 of this license
% or (at your option) any later version.  The latest version of this
% license is in http://www.latex-project.org/lppl.txt; version 1.3 or
% later is part of distributions of LaTeX version 2005/12/01 or later.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{MR}[2023/08/27]
\ProcessOptions\relax

%% Options  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\if@onlinefirst
\DeclareOption{onlinefirst}{\@onlinefirsttrue}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

%% Start from the class article  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\LoadClass[leqno,twoside,11pt,hidelinks]{article}

%% Language support  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[english]{babel}

%% LaTeX toolbox  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{etoolbox}

%% Page format  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[%
a5paper,
width=131mm,
height=201mm,
headheight=14pt,
headsep=12pt,
includehead,
centering
]{geometry}

%% Headers  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\@titlerunning}{}
\newcommand{\titlerunning}[1]{%
  \renewcommand{\@titlerunning}{#1}%
}

\newcommand{\@authorrunning}{}
\newcommand{\authorrunning}[1]{%
  \renewcommand{\@authorrunning}{#1}%
}

\newcounter{@tome}
\newcommand{\Tome}[1]{%
  \setcounter{@tome}{#1}%
}

\newcounter{@year}
\newcommand{\Year}[1]{%
  \setcounter{@year}{#1}%
}

\newcommand{\@issue}{}
\newcommand{\Issue}[1]{%
  \renewcommand{\@issue}{#1}
}

\newcounter{@volpage}
\newcommand{\VolPage}[1]{%
  \setcounter{@volpage}{#1}%
}
\newcommand{\thevolpage}{%
  \number\numexpr\value{@volpage}+\value{page}-1\relax
}

\newcommand{\@DOI}{}
\newcommand{\DOI}[1]{%
  \renewcommand{\@DOI}{#1}%
}

\RequirePackage{calc}
\RequirePackage{fancyhdr}
\AtEndDocument{\EDNotes}
\RequirePackage{lastpage}
\RequirePackage{refcount}

\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0pt}%
  \renewcommand{\footrulewidth}{0pt}%
  \lfoot{\hspace*{\widthof{\ } * -1}%
    \raisebox{0pt}[0pt][0pt]{\raisebox{32pt}{\parbox{\textwidth}{%
          \footnotesize
          MATH.\ REPORTS\
          \if@onlinefirst\else
            \textbf{\the@tome(\the\numexpr\value{@tome}+50\relax)} (\the@year),
            \textit{\@issue},
            \thevolpage--%
            \the\numexpr\value{@volpage}+\getpagerefnumber{LastPage}-1\relax
            \\[1.5pt]%
            doi: \href{http://dx.doi.org/\@DOI}{\@DOI}%
          \fi
        }%
      }%
    }%
  }%
}
\pagestyle{fancy}
\fancyhf{}
\chead[\footnotesize\@authorrunning]{\footnotesize\@titlerunning}
\lhead[\footnotesize\thevolpage]{\footnotesize\thepage}
\rhead[\footnotesize\thepage]{\footnotesize\thevolpage}
\renewcommand{\footrulewidth}{0pt}

%% Title  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{afterpage}
\RequirePackage{authblk}

\newcommand{\@communicatedby}{}
\newcommand{\CommunicatedBy}[1]{%
  \renewcommand{\@communicatedby}{#1}%
}

\newcommand{\MakeTitle}{%
  \affil{}%
  \maketitle
  \enlargethispage{-23pt}%
  \footnotetext{\vspace{-\baselineskip}}%
  \let \thanks \footnotetext
  \def\thefootnote{\fnsymbol{footnote}}%
}

\renewcommand{\@maketitle}{%
  \newpage \null
  \vskip 2em\vskip \z@skip%
  \let \footnote \thanks
  \begin{center}%
    \vskip -44pt%
    \large
    \expandafter\spacedcaps\expandafter{\@title}\par
    \vskip 18pt%
    \setlength{\affilsep}{-\baselineskip}%
    \large \lineskip .5em%
    \begin{tabular}[t]{c}%
      \@author
    \end{tabular}%
    \par
    {\itshape\footnotesize Communicated by \@communicatedby}%
  \end{center}%
  \par
  \vskip 18pt%
}

\renewcommand\@author{%
  \ifx \AB@affillist \AB@empty
    \AB@author
  \else
    \ifnum \value{affil}>\value{Maxaffil}%
      \def\rlap##1{##1}%
      \AB@authlist\\[\affilsep]\AB@affillist
    \else
      \expandafter\SpacedCaps\expandafter{\AB@authors}%
    \fi
  \fi
}

\renewcommand{\Authfont}{%
  \footnotesize
}

%% Abstract  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[notquote]{hanging}

\renewenvironment{abstract}{%
  \begingroup
  \leftskip 9mm%
  \rightskip 9mm%
  \footnotesize
  \noindent
  \ignorespaces
}{%
  \endgroup
  \gdef\thefootnote{\arabic{footnote}}%
}

\newlength{\@hangindent}
\newcommand{\@AMSclass}{}
\newcommand{\@scname}{%
  \textit{AMS~2020~Subject~Classification:~}%
}
\newcommand{\AMSclass}[1]{%
  \renewcommand{\@AMSclass}{#1}%
  \addvspace{6pt}%
  \settowidth{\@hangindent}{\@scname}%
  \hangpara{\@hangindent}{1}%
  \makebox[\@hangindent]{\@scname}#1.\par
  \addvspace{\medskipamount}%
}

\newcommand{\@keywords}{}
\newcommand{\@kwname}{%
  \textit{Key~words:~}%
}
\newcommand{\keywords}[1]{%
  \renewcommand{\@keywords}{#1}%
  \addvspace{6pt}%
  \settowidth{\@hangindent}{\@kwname}%
  \hangpara{\@hangindent}{1}%
  \makebox[\@hangindent]{\@kwname}#1.\par
  \addvspace{\medskipamount}%
}

%% Sectioning  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{titlesec}

\titleformat{\section}{%
  \bfseries\filcenter
}{%
  \normalfont \thesection.%
}{4pt}{\MakeUppercase}
\titlespacing{\section}{0pt}{%
  22pt plus 4pt minus 4pt%
}{10pt plus 4pt minus 2pt}

\titleformat{\subsection}{%
  \bfseries\filcenter
}{%
  \normalfont \thesubsection.%
}{4pt}{}
\titlespacing{\subsection}{0pt}{%
  22pt plus 4pt minus 4pt%
}{10pt plus 4pt minus 2pt}

\setlength{\parindent}{9mm}
\RequirePackage{indentfirst}

%% Fonts  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{textcase}

\newcommand{\spacedcaps}[1]{%
  \uppercase{#1}%
}
\newcommand{\SpacedCaps}[1]{%
  \MakeTextUppercase{#1}%
}

%% AMS macros  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[leqno]{amsmath}
\RequirePackage{amssymb}
\RequirePackage{amsthm}

%% Spacing  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\apptocmd\normalsize{
 \abovedisplayskip=6pt plus 2pt minus 3pt
 \abovedisplayshortskip=0pt plus 1pt minus 3pt
 \belowdisplayskip=6pt plus 2pt minus 3pt
 \belowdisplayshortskip=0pt plus 3pt minus 4pt
}{}{}

\allowdisplaybreaks

\AtBeginDocument{%
  \flushbottom
  \normalsize
}

\newcommand{\rmedskip}{%
  \vspace{6pt}%
}

%% Theorem styles  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newtheoremstyle{def}% name
{6pt plus 2pt minus 2pt}% space above
{6pt plus 2pt minus 2pt}% space below
{}% body font
{\parindent}% indent amount
{\itshape}% theorem head font
{.}% punctuation after theorem head
{.5em}% space after theorem head
{}% theorem head spec (can be left empty, meaning ‘normal’)

\newtheoremstyle{thm}% name
{6pt plus 2pt minus 2pt}% space above
{6pt plus 2pt minus 2pt}% space below
{\itshape}% body font
{\parindent}% indent amount
{\scshape}% theorem head font
{.}% punctuation after theorem head
{.5em}% space after theorem head
{}% theorem head spec (can be left empty, meaning ‘normal’)

\RequirePackage{xpatch}
\xpatchcmd{\proof}{\hskip\labelsep}{\hskip\parindent\hskip\labelsep}{}{}
\xpatchcmd{\qed}{\hfill}{~}{}{}

%% Lists  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\PassOptionsToPackage{inline}{enumitem}
\RequirePackage{enumitem}

%% Captions  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[
  font=footnotesize,
  justification=centering,
  margin=9mm
]{caption}
\captionsetup{labelsep=endash}

%% Footnotes  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand*{\thefootnote}{%
  \fnsymbol{footnote}%
}

%% Bibliography  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newenvironment{references}[1]{%
  \begingroup
  \footnotesize
  \renewcommand{\refname}{\normalfont References}%
  \thebibliography{#1}%
}{%
  \endthebibliography
  \endgroup
}

%% Acknowledgements  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newenvironment{acknowledgements}{%
  \par\medskip
  \begingroup
  \footnotesize
  \indent\textbf{Acknowledgments.\ }%
  \ignorespaces
}{%
  \endgroup
}

%% End-document notes  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\@received}{}
\newcommand{\Received}[1]{%
  \renewcommand{\@received}{#1}%
}

\newcommand{\@affiliation}{}
\newcommand{\affiliation}[1]{%
  \renewcommand{\@affiliation}{#1}%
}

\newcommand{\EDNotes}{%
  \par\medskip
  \begingroup
  \itshape\footnotesize\noindent
  \parbox[t]{.40\linewidth}{\centering Received \@received}%
  \parbox[t]{.60\linewidth}{\centering \@affiliation}%
  \endgroup
}

\newcommand{\printaffil}{\footnotesize\@affiliation}

%% Hypertext marks  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{hyperref}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput
