%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	ABNTeX-o-matic	%
%	B.C.D.A. VASCONCELOS 2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% abreviacoes, abstract, advertencia, agradecimentos, ano, autor, autora, biblatex, biblatex-phi, biblatexoptions, biblio-style, biblio-title, bibliography, citecolor, citeproc, compilado, contracapa, creditos, curso, dedicatoria, epigrafe, fontfamily, fontfamilyoptions, glossary, glossaryfile, greekfont, greekfontoptions, include-after, indentarprimeiralinha, indentarprimeiralinhaem, index, instituicao, linhadepesquisa, linkcolor, lugar, mainfont, mainfontoptions, matematica, monofont, monofontoptions, natbib, natbiboptions, orientador, orientadora, printshorthands, resumo, sansfont, sansfontoptions, subtitulo, sumario, titulacao, titulo, trabalho, urlcolor

\NeedsTeXFormat{LaTeX2e}
\documentclass[paper=a4,
           oneside,
           pagesize,
           fontsize=12pt,
           DIV=10,                % TODO: Make configurable
           BCOR=10mm,             % TODO: Make configurable
           cleardoublepage=empty,
           numbers=noenddot,
           titlepage,
           toc=bibliography,
           toc=index,]{scrbook}
\RequirePackage{ifpdf}
\RequirePackage{ifxetex}
\RequirePackage{ifluatex}
\newif\ifxetexorluatex
\ifxetex
  \usepackage[protrusion=true]{microtype}
  \usepackage[ngerman,french,english,brazil]{babel}
  \xetexorluatextrue
\else
  \ifluatex
    \usepackage[expansion, protrusion=true]{microtype}
\usepackage[ngerman,french,greek,english,brazil]{babel} 
    \xetexorluatextrue
  \else
    \xetexorluatexfalse
  \fi
\fi
\ifxetexorluatex
%  \RequirePackage{fontspec}
\else
  \RequirePackage[utf8]{inputenc}
\fi
% Makes it possible to switch between different languages in the text
% while keeping hyphenation rules correct. Should you add another one
% in the list, please ensure that `english` is the last one. The last
% language is used to control standard hyphenation.
\RequirePackage{csquotes} % Context-sensitive quotation marks
\RequirePackage{xspace}   % For automatically "eating" spaces
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Multi-line comments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\comment}[1]{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tight-list
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fonts & colours
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[usenames,dvipsnames]{xcolor}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Graphics
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{graphicx}
\graphicspath{%
  {Figures/}
  {./}
}
% Suppress warnings about page groups in PDFs. This is not justified
% in most of the cases. I am pretty sure I am including my images in
% the right manner.
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname pdfsuppresswarningpagegroup\endcsname\relax
\else
  \pdfsuppresswarningpagegroup=1\relax
\fi
\RequirePackage{subcaption}
% Make sub-references using \subref being typeset with parentheses.
% Otherwise, only the counter will be printed.
\captionsetup{subrefformat=parens}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Paragraph lists & compact enumerations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[%
    olditem,  % Do not modify itemize environments by default
    oldenum   % Do not modify enumerate environments by default
  ]{paralist}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{booktabs}
\RequirePackage{multirow}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Proper typesetting of units
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[binary-units=true]{siunitx}
\sisetup{%
  detect-all           = true,
  detect-family        = true,
  detect-mode          = true,
  detect-shape         = true,
  detect-weight        = true,
  detect-inline-weight = math,
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Penalties
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clubpenalty         = 10000
\widowpenalty        = 10000
\displaywidowpenalty = 10000
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Headers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[singlespacing=true]{scrlayer-scrpage}
\pagestyle{scrheadings}
\renewcommand*{\chaptermarkformat}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Typefaces for parts, chapters, and sections
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand{\partformat}{\huge\partname~\thepart\autodot}
\renewcommand{\raggedpart}{\flushleft}
\setkomafont{part}{\normalfont\huge\scshape}
\setkomafont{sectioning}{\normalfont\scshape}
\setkomafont{descriptionlabel}{\normalfont\bfseries}
\setkomafont{caption}{\small}
\setkomafont{captionlabel}{\usekomafont{caption}}

%  Redefine citeproc
\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
  \begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
% avoid brackets around text for \cite:
\makeatletter
 \def\@biblabel#1{}
 \def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother

% Large number for chapter
\renewcommand*{\chapterformat}{%
  \fontsize{30}{35}\selectfont\thechapter\autodot\enskip
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Paracol e multicol
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{multicol} %\begin{multicols}{2}
\usepackage{paracol}
\footnotelayout{m}
 %\begin{paracol}{2}  \switchcolumn \end{paracol}
\usepackage{array}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fonte pequenas e espaçamento simples nas citações
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{etoolbox}
\AtBeginEnvironment{quote}{\singlespacing\small}
\renewenvironment{quote}{%
   \list{}{%
     \leftmargin4cm   % this is the adjusting screw
     \rightmargin0cm
   }
   \item\relax
}
{\endlist}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Espaçamento simples no ambiente paracol
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\AtBeginEnvironment{paracol}{\singlespacing\small}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parte do original. Função?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[binary-units=true]{siunitx}
\DeclareSIUnit\px{px}
\sisetup{%
  detect-all           = true,
  detect-family        = true,
  detect-mode          = true,
  detect-shape         = true,
  detect-weight        = true,
  detect-inline-weight = math,
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pacote para epígrafes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{epigraph}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ajustes para o logo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{metalogo}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Espaçamento
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[doublespacing]{setspace}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Schemata
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{schemata}


%%%---Set up clickable section headers----------
% make headings back-links to TOC
% See https://tex.stackexchange.com/a/251964/73149, 
% and https://tex.stackexchange.com/questions/412773/
\makeatletter
% configure chapter back-links
\let\hyperchapter\chapter
\def\chapter{\@ifstar\starchapter\mychapter}
\def\starchapter{\hyperchapter*}
\newcommand{\mychapter}[2][\@empty]% #1=optional (toc and top of page), #2=title
{\ifx#1\@empty \hyperchapter[#2]{\hyperlink{toc.chapter.\thechapter}{#2}}
 \else \hyperchapter[#1]{\hyperlink{toc.chapter.\thechapter}{#2}}
 \fi}
% configure section back-links
\let\hypersection\section
\def\section{\@ifstar\starsection\mysection}
\def\starsection{\hypersection*}
\newcommand{\mysection}[2][\@empty]% #1=optional (toc), #2=title
{\ifx#1\@empty \hypersection[#2]{\hyperlink{toc.section.\thesection}{#2}}
 \else \hypersection[#1]{\hyperlink{toc.section.\thesection}{#2}}
 \fi}
 % configure subsection back-links
\let\hypersubsection\subsection
\def\subsection{\@ifstar\starsubsection\mysubsection}
\def\starsubsection{\hypersubsection*}
\newcommand{\mysubsection}[2][\@empty]% #1=optional (toc), #2=title
{\ifx#1\@empty \hypersubsection[#2]{\hyperlink{toc.subsection.\thesubsection}{#2}}
 \else \hypersubsection[#1]{\hyperlink{toc.subsection.\thesubsection}{#2}}
 \fi}
% configure subsubsection back-links
\let\hypersubsubsection\subsubsection
\def\subsubsection{\@ifstar\starsubsubsection\mysubsubsection}
\def\starsubsubsection{\hypersubsubsection*}
\newcommand{\mysubsubsection}[2][\@empty]% #1=optional (toc), #2=title
{\ifx#1\@empty \hypersubsubsection[#2]{\hyperlink{toc.subsubsection.\thesubsubsection}{#2}}
 \else \hypersubsubsection[#1]{\hyperlink{toc.subsubsection.\thesubsubsection}{#2}}
 \fi}
% close out
\makeatother
%%%---End set up clickable section headers----------


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Opções e ajustes	
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$if(matematica)$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Matemática
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{amsmath}
\RequirePackage{amsthm}
\RequirePackage{dsfont}
% Fix the spacing of \left and \right. Use these with the proper bracket
% in order to ensure that they scale automatically.
\let\originalleft\left
\let\originalright\right
\renewcommand{\left}{\mathopen{}\mathclose\bgroup\originalleft}
\renewcommand{\right}{\aftergroup\egroup\originalright}
\DeclareMathOperator*{\argmin}          {arg\,min}
\DeclareMathOperator {\dist}            {dist}
\DeclareMathOperator {\im}              {im}
\newcommand{\domain}{\ensuremath{\mathds{D}}}
\newcommand{\real}  {\ensuremath{\mathds{R}}}
% Proper differential operators
\newcommand{\diff}[1]{\ensuremath{\operatorname{d}\!{#1}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ordinals
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand  {\st}{\textsuperscript{\textup{st}}\xspace}
\newcommand  {\rd}{\textsuperscript{\textup{rd}}\xspace}
\newcommand  {\nd}{\textsuperscript{\textup{nd}}\xspace}
\renewcommand{\th}{\textsuperscript{\textup{th}}\xspace}
$endif$
$if(indentarprimeiralinha)$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Indentação de parágrafo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{indentfirst}
$if(indentarprimeiralinhaem)$
\setlength{\parindent}{$indentarprimeiralinhaem$} 
$endif$$endif$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Hyperlinks & bookmarks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[%
  colorlinks = true,
  citecolor  = $if(citecolor)$ $citecolor$ $else$ RoyalBlue $endif$,
  linkcolor  = $if(linkcolor)$ $linkcolor$ $else$ RoyalBlue $endif$,
  urlcolor   = $if(urlcolor)$ $urlcolor$ $else$ RoyalBlue $endif$,
  ]{hyperref}
\usepackage{bookmark}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Polyglossia
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{polyglossia}
\newcommand{\familytype}{\l_xpg_familytype_tl}
\setdefaultlanguage[variant=brazilian]{portuguese}
\setotherlanguage[variant=ancient]{greek}
	\newcommand{\pt}[1]{\textportuges{#1}}
	\newcommand{\grc}[1]{\textgreek{#1}} 
	
%\newcommand{\grc}[1]{\selectlanguage{greek}\hyphenrules{polygreek}{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Bibliografia
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$if(natbib)$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Natbib
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[$natbiboptions$]{natbib}
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$}
$endif$
$if(biblatex)$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	BibLaTeX
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[$if(biblio-style)$style=$it$,$endif$$for(biblatexoptions)$$it$$sep$,$endfor$]{biblatex}
$endif$
$if(biblatex-phi)$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	BibLaTeX-Phi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[backend=biber, style=philosophy-modern, backref, url=false, publocformat=loccolonpub, volumeformat = romansc, scauthors = all, inbeforejournal=true, shorthandintro = false, latinemph=true]{biblatex} % configuração mais próxima possível da ABNT utilizando o pacote

\defbibheading{FP}{\chapter*{Referências}\label{referencias}\addcontentsline{toc}{chapter}{Referências}

% Separação entre fontes primárias e secundárias
\section*{Fontes Primárias\label{fontesprimarias}\addcontentsline{toc}{section}{Fontes Primárias}}}
\defbibheading{FS}{\section*{Fontes Secundárias\label{fontessecundarias}\addcontentsline{toc}{section}{Fontes Secundárias}}}

\addbibresource{/Users/bcdav/Dropbox/Application Support/BBEdit/Pandoc/refs/Content.bib}
$endif$
$for(bibliography)$
% Arquivo de bibliografia
\addbibresource{$bibliography$}
$endfor$
$if(csl-refs)$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Pandoc Citeproc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
  \newlength{\csllabelwidth}
\setlength{\csllabelwidth}{1em}
\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing
 {% don't indent paragraphs
  \setlength{\parindent}{0pt}
  % turn on hanging indent if param 1 is 1
  \ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
  % set entry spacing
  \ifnum #2 > 0
  \setlength{\parskip}{#2\baselineskip}
  \fi
 }%
 {}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{#1\hfill\break}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
$endif$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Fontes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$if(fontfamily)$
\usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$}
$else$
\usepackage{lmodern}
$endif$
$if(mainfont)$
  \setmainfont[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$]{$mainfont$}
$endif$
$if(sansfont)$
  \setsansfont[$for(sansfontoptions)$$sansfontoptions$$sep$,$endfor$]{$sansfont$}
$endif$
$if(monofont)$
  \setmonofont[$for(monofontoptions)$$monofontoptions$$sep$,$endfor$]{$monofont$}
$endif$
$if(greekfont)$
  \newfontfamily\greekfont[$for(greekfontoptions)$$greekfontoptions$$sep$,$endfor$]{$greekfont$}
$endif$
$for(fontfamilies)$
  \newfontfamily{$fontfamilies.name$}[$for(fontfamilies.options)$$fontfamilies.options$$sep$,$endfor$]{$fontfamilies.font$}
$endfor$
$if(glossary)$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Glossário
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[toc, style=altlisthypergroup]{glossaries} %todo: glossaries: get sorting right
\makeglossaries
%\glslink{<label>}{<alternate text>}
$if(glossaryfile)$\input{"$glossaryfile$"}$endif$
$endif$
$if(index)$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Índice
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{makeidx}
\makeindex
$endif$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Correção para tornar capítulos o nível mais alto
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\let\subsubsection\subsection
\let\subsection\section
\let\section\chapter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ---------------------------------%
%			  Incipit			   %
% ---------------------------------%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\let\hypercontentsline=\contentsline
\renewcommand{\contentsline}[4]{\hypertarget{toc.#4}{}\hypercontentsline{#1}{#2}{#3}{#4}}
\frontmatter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Elementos pré-textuais
%	(a.k.a. frontmatter)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Capa
$if(titulo)$ $if(instituicao)$ $if(ano)$ $if(lugar)$
\begin{titlepage}
\makeatletter \begin{center} \textsc{$instituicao$}\\ \vspace*{2cm}
$if(autor)$$autor$$endif$$if(autora)$$autora$$endif$ \\ \vspace*{2cm}
\begin{Huge} $titulo$ \\  \end{Huge} \vspace*{1cm}
\begin{Large} $if(subtitulo)$$subtitulo$$endif$ \end{Large} \vfill
$lugar$ \\ $ano$  \end{center}
% Contracapa
$if(contracapa)$
\newpage \thispagestyle{empty}  
\begin{center} $if(autor)$$autor$$endif$$if(autora)$$autora$$endif$ \\ \vfill
\begin{Huge} $titulo$ \end{Huge} \vspace*{1,5cm}
\begin{flushright} $contracapa$ \end{flushright} \vfill 
$lugar$ \\ $ano$ \end{center}
\makeatother \end{titlepage}  
$else$ $if(trabalho)$ $if(linhadepesquisa)$ $if(curso)$ $if(titulacao)$
\newpage \thispagestyle{empty}  
\begin{center} $if(autor)$$autor$$endif$$if(autora)$$autora$$endif$ \\ \vfill
\begin{Huge} $titulo$ \end{Huge} \vspace*{1,5cm}
\begin{quote} $trabalho$ apresentada ao programa de Pós-Graduação em $curso$ da $instituicao$, como requisito parcial para a obtenção do título de \emph{$titulacao$} em $curso$. \end{quote}  \vspace*{2cm}
\begin{flushright} $if(orientador)$ Orientador: $orientador$ \\ $endif$ $if(orientadora)$ Orientadora: $orientadora$ \\$endif$
Linha de Pesquisa: $linhadepesquisa$ \\ \end{flushright} \vfill 
$lugar$ \\ $ano$ \end{center}
\makeatother \end{titlepage}
$else$
\end{titlepage}
$endif$ $endif$ $endif$ $endif$ $endif$ $endif$ $endif$ $endif$ $endif$
$if(dedicatoria)$
% Dedicatoria
\clearpage \thispagestyle{empty}  
\mbox{} \vfill
	\begin{flushright} \emph{$dedicatoria$} \end{flushright}
$endif$ $if(agradecimentos)$
% Agradecimentos
\clearpage \thispagestyle{empty}  
	\begin{center}\textsc{\textbf{Agradecimentos}}\end{center}
	$agradecimentos$
{\vfil}{}{}{}
$endif$ $if(epigrafe)$
% Epígrafe
\clearpage \thispagestyle{empty}  
	\begin{quote}\begin{flushright}
		$epigrafe$
	\end{flushright}\end{quote} 
{\vfil}{}{}{}
$endif$ $if(advertencia)$
% Advertência
\clearpage \thispagestyle{empty}  
	\begin{center}\textsc{\textbf{Advertência}}\end{center}
	$advertencia$
$endif$ $if(resumo)$
% Resumo
\clearpage \thispagestyle{empty}  
$else$ $if(abstract)$
\clearpage \thispagestyle{empty}  
$endif$ $endif$
$if(resumo)$
\begin{center}\textsc{\textbf{Resumo}}\end{center}
$resumo$ \\ $endif$ $if(abstract)$
\begin{center}\textsc{\textbf{Abstract}}\end{center}
$abstract$ \\
{\vfil}{}{}{}
$endif$ $if(abreviacoes)$
% Abreviações
\clearpage \thispagestyle{empty}  
\begin{center}\textsc{\textbf{Lista de Abreviações}}\end{center}
\begin{multicols}{2}\begin{onehalfspace}\begin{flushleft}
$abreviacoes$ \end{flushleft}\end{onehalfspace}\end{multicols}
$endif$ $if(printshorthands)$
\clearpage \thispagestyle{empty}  
\begin{onehalfspace} \printshorthands \end{onehalfspace}
$endif$
% Sumário
$if(sumario)$
\clearpage \begin{onehalfspace}
\tableofcontents \end{onehalfspace}
$endif$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Parte principal
%	a.k.a. mainmatter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mainmatter
  \clearpage
	$body$
\bookmarksetup{startatroot}
\backmatter
	\begingroup 
		\let\clearpage\relax 
	\endgroup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Elementos pós-textuais
%	a.k.a. backmatter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 	Bibliografia
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$if(natbib)$ $if(bibliography)$
\small \singlespacing
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
$endif$ $endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$ $if(biblatex-phi)$
\printbibliography[keyword=FontePrimária, heading=FP]
\printbibliography[keyword=FonteSecundária, heading=FS]
$endif$
$for(include-after)$
	$include-after$
$endfor$ $if(glossary)$
\printglossary
$endif$$if(index)$  
\printindex
$endif$
\endsinglespace
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	ABNTeX-o-matic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$if(creditos)$
\newpage
\thispagestyle{empty}  
\begin{center} \begin{onehalfspace}
	\mbox{}
	\vfill
Compilado usando \emph{ABNTex-o-matic} para\\
 \vspace*{0cm}		
		\begin{Huge} 
			\XeLaTeX \\ 
		\end{Huge}
 \vspace*{0,5cm}	
https://github.com/bcdavasconcelos/ABNTeX-o-matic 	
$if(compilado)$ Em $compilado$ $endif$
\end{onehalfspace} \end{center}
$endif$
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Everything comes to an end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
