\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{retmat}[2026/05/15 Classe estavel da Revista Tocantinense de Matematica]

\LoadClass[11pt,a4paper]{article}

% =========================================================
% Opcoes da classe
% Uso recomendado para submissao/revisao:
%   \documentclass[portuguese,review]{retmat}
% Para versao final sem linhas numeradas:
%   \documentclass[portuguese,final]{retmat}
% Para migrar ao ingles:
%   \documentclass[english,review]{retmat}
% =========================================================
\newif\ifretmatenglish
\newif\ifretmatreview
\DeclareOption{english}{\retmatenglishtrue}
\DeclareOption{portuguese}{\retmatenglishfalse}
\DeclareOption{review}{\retmatreviewtrue}
\DeclareOption{final}{\retmatreviewfalse}
\ExecuteOptions{portuguese,review}
\ProcessOptions\relax

% =========================================================
% Pacotes basicos e configuracao de pagina
% =========================================================
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\ifretmatenglish
  \RequirePackage[english]{babel}
\else
  \RequirePackage[brazil]{babel}
\fi
\RequirePackage{lmodern}
\RequirePackage{microtype}
\RequirePackage[a4paper,left=2.7cm,right=2.7cm,top=2.7cm,bottom=3.5cm,headheight=24pt,headsep=18pt,footskip=50pt]{geometry}
\RequirePackage{graphicx}
\RequirePackage{xcolor}
\RequirePackage{array}
\RequirePackage{booktabs}
\RequirePackage{etoolbox}
\RequirePackage{amsmath,amssymb,amsfonts,amsthm,mathtools}
\RequirePackage{mathrsfs}
\RequirePackage{lineno}
\RequirePackage{fancyhdr}
\RequirePackage{url}
\RequirePackage{hyperref}

\definecolor{retmatblue}{RGB}{0,72,132}
\definecolor{retmatgray}{RGB}{92,92,92}
\hypersetup{
  colorlinks=true,
  linkcolor=retmatblue,
  citecolor=retmatblue,
  urlcolor=retmatblue
}

% =========================================================
% Numeracao de linhas
% =========================================================
\ifretmatreview
  \AtBeginDocument{\linenumbers}
\fi
\newcommand{\retmatlinenumberson}{\linenumbers}
\newcommand{\retmatlinenumbersoff}{\nolinenumbers}

% =========================================================
% Informacoes editoriais
% =========================================================
\newcommand{\journalname}{Revista Tocantinense de Matematica}
\newcommand{\journalshort}{ReTMAT}

\newcommand{\retmatlogo}[1]{\def\@retmatlogo{#1}}
\newcommand{\retmatvolume}[1]{\def\@retmatvolume{#1}}
\newcommand{\retmatissue}[1]{\def\@retmatissue{#1}}
\newcommand{\retmatyear}[1]{\def\@retmatyear{#1}}
\newcommand{\retmatpages}[1]{\def\@retmatpages{#1}}
\newcommand{\retmatdoi}[1]{\def\@retmatdoi{#1}}
\newcommand{\received}[1]{\def\@retmatreceived{#1}}
\newcommand{\accepted}[1]{\def\@retmataccepted{#1}}
\newcommand{\shorttitle}[1]{\def\@retmatshorttitle{#1}}
\newcommand{\shortauthors}[1]{\def\@retmatshortauthors{#1}}

\retmatlogo{logo_Retmat.png}
\retmatvolume{1}
\retmatissue{1}
\retmatyear{2026}
\retmatpages{1--10}
\retmatdoi{}
\received{}
\accepted{}
\shorttitle{ReTMAT}
\shortauthors{}

% =========================================================
% Autores e informacoes no rodape
% Mais estavel que \thanks no Overleaf.
% =========================================================
\newcommand{\retmatauthors}[1]{\def\@retmatauthors{#1}}
\newcommand{\retmatauthorinfo}[1]{\def\@retmatauthorinfo{#1}}
\retmatauthors{}
\retmatauthorinfo{}

% =========================================================
% Palavras-chave e MSC
% =========================================================
\newcommand{\keywords}[1]{\def\@retmatkeywords{#1}}
\newcommand{\msc}[1]{\def\@retmatmsc{#1}}
\keywords{}
\msc{}

\ifretmatenglish
  \newcommand{\retmatkeywordsname}{Keywords}
  \newcommand{\retmatmscname}{MSC 2020}
  \newcommand{\retmatreceivedname}{Received}
  \newcommand{\retmatacceptedname}{Accepted}
\else
  \newcommand{\retmatkeywordsname}{Palavras-chave}
  \newcommand{\retmatmscname}{MSC 2020}
  \newcommand{\retmatreceivedname}{Recebido}
  \newcommand{\retmatacceptedname}{Aceito}
\fi

\newcommand{\printkeywords}{%
  \ifstrempty{\@retmatkeywords}{}{\par\noindent\textbf{\retmatkeywordsname:} \@retmatkeywords\par\medskip}%
  \ifstrempty{\@retmatmsc}{}{\noindent\textbf{\retmatmscname:} \@retmatmsc\par\medskip}%
}

% =========================================================
% Abstract e Keywords em ingles para artigos em portugues
% Mantem o mesmo padrao visual do ambiente abstract: titulo centralizado
% e mesmo tamanho de fonte.
% Uso no main.tex:
%   \begin{abstracten} ... \end{abstracten}
%   \keywordsen{keyword 1; keyword 2; keyword 3}
% =========================================================
\newenvironment{abstracten}{%
  \par\vspace{0.35cm}%
  \begin{center}\small\bfseries Abstract\end{center}%
  \begin{quote}\small
}{%
  \end{quote}%
  \par\vspace{0.15cm}%
}

\newcommand{\keywordsen}[1]{%
  \par\noindent\textbf{Keywords:} #1\par\medskip%
}

% =========================================================
% Cabecalho simples, nao carregado
% =========================================================
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\small\journalshort}
\fancyhead[R]{\small\thepage}
\renewcommand{\headrulewidth}{0.3pt}

% =========================================================
% Ambientes matematicos com nomes automaticos por idioma
% =========================================================
\theoremstyle{plain}
\ifretmatenglish
  \newtheorem{theorem}{Theorem}[section]
  \newtheorem{proposition}[theorem]{Proposition}
  \newtheorem{lemma}[theorem]{Lemma}
  \newtheorem{corollary}[theorem]{Corollary}
\else
  \newtheorem{theorem}{Teorema}[section]
  \newtheorem{proposition}[theorem]{Proposição}
  \newtheorem{lemma}[theorem]{Lema}
  \newtheorem{corollary}[theorem]{Corolário}
\fi

\theoremstyle{definition}
\ifretmatenglish
  \newtheorem{definition}[theorem]{Definition}
  \newtheorem{example}[theorem]{Example}
\else
  \newtheorem{definition}[theorem]{Definição}
  \newtheorem{example}[theorem]{Exemplo}
\fi

\theoremstyle{remark}
\ifretmatenglish
  \newtheorem{remark}[theorem]{Remark}
\else
  \newtheorem{remark}[theorem]{Observação}
\fi

% =========================================================
% Ambientes editoriais simples
% =========================================================
\newenvironment{acknowledgements}{%
  \section*{\ifretmatenglish Acknowledgements\else Agradecimentos\fi}%
}{ }
\newenvironment{funding}{%
  \section*{\ifretmatenglish Funding\else Financiamento\fi}%
}{ }

% =========================================================
% Primeira pagina: logo esquerda, dados da revista direita.
% Dados dos autores no rodape da primeira pagina, sem \thanks.
% =========================================================
\renewcommand{\maketitle}{%
  \ifretmatreview\nolinenumbers\fi
  \fancypagestyle{retmatfirst}{%
    \fancyhf{}%
    \renewcommand{\headrulewidth}{0pt}%
    \renewcommand{\footrulewidth}{0.3pt}%
    \fancyfoot[L]{\parbox{0.95\textwidth}{\footnotesize\@retmatauthorinfo}}%
  }%
  \thispagestyle{retmatfirst}%
  \noindent
  \begin{minipage}[t]{0.42\textwidth}
    \vspace{0pt}
    \IfFileExists{\@retmatlogo}{\includegraphics[height=3cm]{\@retmatlogo}}{\fbox{\strut Logo ReTMAT}}
  \end{minipage}%
  \hfill
  \begin{minipage}[t]{0.54\textwidth}
    \vspace{0pt}\raggedleft\small
    \textbf{\journalname}\par
    Vol. \@retmatvolume, n. \@retmatissue, \@retmatyear, p. \@retmatpages\par
    \ifstrempty{\@retmatdoi}{}{DOI: \href{https://doi.org/\@retmatdoi}{\@retmatdoi}\par}
    \ifstrempty{\@retmatreceived}{}{\retmatreceivedname: \@retmatreceived\par}
    \ifstrempty{\@retmataccepted}{}{\retmatacceptedname: \@retmataccepted\par}
  \end{minipage}

  \vspace{1.1cm}
  \begin{center}
    {\Large\bfseries \@title\par}
    \vspace{0.45cm}
    {\normalsize \@retmatauthors\par}
  \end{center}
  \vspace{0.5cm}
  \ifretmatreview\linenumbers\fi
}
