% Bookdown LaTeX header file

% Inclusion of external PDF documents (such as a cover image)
% See https://www.ctan.org/pkg/pdfpages
\usepackage{pdfpages}

% To properly handle URLs in bibliographies
% See https://tex.stackexchange.com/questions/484176/biblatex-overflowing-url
\usepackage{xurl}

% PDF bookmarks
% See https://ctan.org/pkg/bookmark
%     https://texdoc.org/serve/bookmark.pdf/0
\usepackage[depth=2]{bookmark}

% Indexing
% See https://en.wikibooks.org/wiki/LaTeX/Indexing
%     https://www.ctan.org/pkg/makeidx
%     https://bookdown.org/yihui/bookdown/latex-index.html
%\usepackage{imakeidx}
\usepackage{makeidx}
\makeindex

% No matter what is said in the docs, this was required
% But maybe because tufte::tufte_book was being used instead of bookdown::tufte_book2
% So perhaps this is not needed anymore
% See https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#theorems
%     https://ctan.math.illinois.edu/macros/latex/contrib/thmtools/doc/thmtools-manual.pdf
\usepackage{amsthm,thmtools}

% Bookdown docs recommends to not mess with this
% See https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#theorems
%\newtheorem{definition}{Definição}[chapter]
%\newtheorem{hiphotesis}{Hipótese}[chapter]
%\newtheorem{conjecture}{Conjectura}[chapter]
%\newtheorem{demonstration}{Demonstração}[chapter]
%\newtheorem{etimology}{Etimologia}[chapter]

% Fix positions of margin notes
% See https://ctan.org/pkg/marginfix
%     https://tex.stackexchange.com/questions/119726/horizontal-margins-for-margin-notes-in-the-tufte-classes
%     https://tex.stackexchange.com/questions/624033/long-sidenotes-break-marginfix-or-how-to-make-breakable-sidenotes
\usepackage{marginfix}

% Workaround to theorems work correctly
% Maybe this is not needed anymore
% See https://stackoverflow.com/questions/46942352/r-bookdown-document-with-theorem-does-not-render-when-output-file-is-specified
\let\BeginKnitrBlock\begin \let\EndKnitrBlock\end

% Set page size
%
% This command conflicts with something and gives an error
%\usepackage[paperwidth=6in, paperheight=9in]{geometry}
%
% This command needs tuning for the margins
%\newgeometry{paperwidth=6in, paperheight=9in}
%
% This also needs tuning
% See https://tex.stackexchange.com/questions/201893/change-paper-size-in-tufte-book-class#380699
%\newgeometry{
%  % showframe,
%  paperwidth=6in,
%  paperheight=9in,
%  left=0.55in,
%  right=0.45in,
%  top=.5in,
%  bottom=.5in,
%  marginparsep=0.25in,
%  marginparwidth=0.65in,
%  includemp,
%  includehead,
%  % The text width and height are calculated automatically.
%}
%
% This should work, but we're setting this at 00-header.md
%\newgeometry{b5paper}

% Coverpage and copyright notice before title in R bookdown
% See https://stackoverflow.com/questions/45963505/coverpage-and-copyright-notice-before-title-in-r-bookdown
\let\oldmaketitle\maketitle
\AtBeginDocument{\let\maketitle\relax}

% Custom header
\IfFileExists{snippets/header.tex}{\input{snippets/header.tex}}{}
