%% abnt.sty
%% Copyright (c) Youssef Cherem <ycherem(at)gmail.com>, 2020
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% 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
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `author-maintained'.
% 
% The Current Maintainer of this work is Youssef Cherem.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{abnt}[2020/06/06]
\RequirePackage[left=3cm,top=3cm,right=2cm,bottom=2cm]{geometry}
\RequirePackage{setspace}
\onehalfspacing
\RequirePackage[automark,markcase=used]{scrlayer-scrpage}
\newcommand{\pretextual}{\clearpairofpagestyles}

\newcommand{\textual}{
\pagestyle{scrheadings}
\rohead*{\pagemark}
% same as: %\lohead[\pagemark]{\pagemark} 
\lehead*{\pagemark}
}



\RequirePackage{etoolbox}%\ifdefempty{def}{true}{false}


\def\@makechapterhead#1{%
	%\vspace*{50\p@}% <----------------- Space from top of page to Chapter #
	{\parindent \z@ \raggedright \normalfont
		\ifnum \c@secnumdepth >\m@ne
		\huge\bfseries \thechapter\ \enspace %\. <-- Chapter #
		%\par\nobreak
		%\vskip 20\p@% <-------------- Space between Chapter # and title
		\fi
		\interlinepenalty\@M
		\Huge \bfseries #1\par\nobreak% <------------------ Chapter title
		\vskip 40\p@% <------------------ Space between chapter title and first paragraph
}}

\def\@makeschapterhead#1{%
	%\vspace*{50\p@}%
	{\parindent \z@ \centering
		\normalfont
		\interlinepenalty\@M
		\Huge \bfseries  #1\par\nobreak
		\vskip 40\p@
}}


\RequirePackage{chngcntr}
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}
 
 
%all with dots, even for non-koma classes
\usepackage{tocbasic}
\DeclareTOCStyleEntry[
linefill=\TOCLineLeaderFill,
%entryformat=%\large\textbf,
%pagenumberformat=\color{red},
%entrynumberformat=\color{red},
%beforeskip= 0pt plus .2pt
%pagenumberformat=%\large\textbf%\normalfont
]{tocline}{chapter}  

\newcommand{\@orientador}{}
\newcommand{\orientador}[1]{\gdef\@orientador{#1}}

\newcommand{\@orientadora}{}
\newcommand{\orientadora}[1]{\gdef\@orientadora{#1}}


\newcommand{\@coorientador}{}
\newcommand{\coorientador}[1]{\gdef\@coorientador{#1}}

\newcommand{\@coorientadora}{}
\newcommand{\coorientadora}[1]{\gdef\@coorientadora{#1}}


\newcommand{\oorientador}{\if\@orientador\empty\relax \else Orientador: \@orientador\fi}
\newcommand{\aorientadora}{\if\@orientadora\empty\relax \else Orientadora: \@orientadora\fi}
\newcommand{\ocoorientador}{\if\@coorientador\empty\relax \else Coorientador: \@coorientador\fi}
\newcommand{\acoorientadora}{\if\@coorientadora\empty\relax \else Coorientadora: \@coorientadora\fi}


\newcommand{\@instituicao}{}
\newcommand{\instituicao}[1]{\gdef\@instituicao{#1}}

\newcommand{\@local}{}
\newcommand{\local}[1]{\gdef\@local{#1}}

\newcommand{\@tipotrabalho}{}
\newcommand{\tipotrabalho}[1]{\gdef\@tipotrabalho{#1}}


%titlefont, @authorfont and @datefont defined by koma classes

\@ifundefined{KOMAClassName}{%
	\typeout{Usando uma classe padrĂ£o}
% if not koma
\RequirePackage{emptypage}
\newcommand*{\@titlefont}{\bfseries}
\newcommand*{\titlefont}[1]{\gdef\@titlefont{#1}}
\newcommand*{\@authorfont}{\normalfont}
\newcommand*{\authorfont}[1]{\gdef\@authorfont{#1}}
\newcommand*{\@datefont}{\normalfont}
\newcommand*{\datefont}[1]{\gdef\@datefont{#1}}


%% floating environments
\RequirePackage{newfloat}
\DeclareFloatingEnvironment[fileext=lom,listname={Lista de mapas},within=none]{mapa}
\DeclareFloatingEnvironment[fileext=loq,listname={Lista de quadros},within=none]{quadro}

\RequirePackage{caption}

%\DeclareCaptionListFormat{list}{#1#2~--}
%\DeclareCaptionListFormat{list}{#1#2~--}
\DeclareCaptionListFormat{listafigura}{\figurename\ #1#2\hfill--\hfill}%\hfill--\hfill
\DeclareCaptionListFormat{listamapa}{\mapaname\ #1#2\hfill--\hfill}
\DeclareCaptionListFormat{listaquadro}{\quadroname\ #1#2\hfill--\hfill}
\DeclareCaptionListFormat{listatabela}{\tablename\ #1#2\hfill--\hfill}
\captionsetup[figure]{listformat=listafigura}
\captionsetup[mapa]{listformat=listamapa}
\captionsetup[quadro]{listformat=listaquadro}
\captionsetup[table]{listformat=listatabela}
\captionsetup{labelsep=endash}

%%% commented on 29/12/19
%%% for new lists with koma with \DeclareNewTOC, none of this is needed
\renewcommand*{\l@figure}{\@dottedtocline{1}{1.5em}{5.5em}}
\renewcommand*{\l@table}{\@dottedtocline{1}{1.5em}{5.5em}}
\renewcommand*{\l@mapa}{\@dottedtocline{1}{1.5em}{5.5em}}
\renewcommand*{\l@quadro}{\@dottedtocline{1}{1.5em}{6em}}


}
{% if koma
\typeout{Usando KOMA-Sript.}	
%\KOMAoptions{cleardoublepage=empty} not needed in koma version 3.0 and later
\newcommand*{\@titlefont}{\bfseries}
\renewcommand*{\titlefont}[1]{\gdef\@titlefont{#1}}
\renewcommand*{\@authorfont}{\normalfont}
\newcommand*{\authorfont}[1]{\gdef\@authorfont{#1}}
\renewcommand*{\@datefont}{\normalfont}
\newcommand*{\datefont}[1]{\gdef\@datefont{#1}}


%%% floating environments, easier with koma

\DeclareNewTOC[%
type=mapa,%
types=mapas,%
float,% define a floating environment
floattype=4,%
name=Mapa,%
%counterwithin=chapter,
listname={Lista de Mapas},
%tocentryindent=0pt,% <- added
tocentrydynnumwidth,% <- added
tocentrynumsep=0pt% <- added
]{lom}
\setuptoc{lom}{chapteratlist}

\DeclareNewTOC[%
type=quadro,%
types=quadros,%
float,% define a floating environment
floattype=4,%
name=Quadro,%
%counterwithin=chapter,
listname={Lista de Quadros},
%tocentryindent=0pt,% <- added
tocentrydynnumwidth,% <- added
tocentrynumsep=0pt% <- added
]{loq}
\setuptoc{loq}{chapteratlist}


%prepagenumber ?

\BeforeStartingTOC[lof]{\def\autodot{\hfill~--~\hfill}}
\BeforeStartingTOC[lot]{\def\autodot{\hfill~--~\hfill}}
\BeforeStartingTOC[lom]{\def\autodot{\hfill~--~\hfill}}
\BeforeStartingTOC[loq]{\def\autodot{\hfill~--~\hfill}}

\KOMAoptions{listof=entryprefix}
\renewcommand*{\captionformat}{~--~}

}


\@ifclassloaded{scrbook}{% 
\typeout{Usando a classe scrbook}
}{}

\newcommand*{\@localfont}{\normalfont}
\newcommand*{\localfont}[1]{\gdef\@localfont{#1}}


\newcommand*{\@instituicaofont}{\normalfont}
\newcommand*{\instituicaofont}[1]{\gdef\@instituicaofont{#1}}


\newcommand{\capa}{%
	\begin{titlepage}
		\centering
		{\@instituicaofont\@instituicao}\par\vspace*{4\baselineskip} 
		{\@authorfont\@author}\par
		\vspace*{4\baselineskip} 
		{\@titlefont\@title}
		\vfill
		{\@localfont\@local}\\
		{\@datefont\@date}
		
		\if@twoside \cleardoublepage \else \clearpage \fi
	\end{titlepage}
}

\newcommand{\folhaderosto}{%
	\setcounter{page}{1}
\thispagestyle{empty}
\begin{center}
{\@authorfont\@author}
\vfill
\vfill
{\@titlefont\@title}
\end{center}
\vfill
\bgroup
\leftskip=6cm
\singlespacing%
\noindent\@tipotrabalho\par\medskip  
\noindent \ifdefempty{\@orientador}{\aorientadora}{\oorientador}\par
\noindent \ifdefempty{\@coorientador}{\acoorientadora}{\ocoorientador}

\par
\egroup
\vfill
\vfill
\begin{center}
{\@localfont\@local}\\
{\@datefont\@date}
\end{center}
\if@twoside \cleardoublepage \else \clearpage \fi
}


\newenvironment{citacao}{\vskip -4pt
	\singlespacing\setlength{\parindent}{0pt}
	\leftskip=6cm\footnotesize}{\par\medskip}

\RequirePackage{enumerate}



\endinput