%
% Note that the order that the packages are imported sometimes it
% matters. That is, some packages should be imported before others.
% Otherwise, it may not work correctly.
%
% You may have to add new packages, remove packages, or modify their
% input arguments to obtain the intended functionality.
%

% This package identifies which TeX engine is in use (pdfTeX or LuaTeX).
\usepackage{iftex}

% Input encoding.
% LuaTeX uses UTF-8 encoding by default.
\ifPDFTeX
\usepackage[utf8]{inputenc}
\fi

% Font encoding.
\usepackage[T1]{fontenc}
\usepackage{textcomp}

% Using "Latin Modern" font is better.
% https://tex.stackexchange.com/questions/88368/how-do-i-invoke-cm-super
% http://tug.org/pipermail/macostex-archives/2004-July/006964.html
% https://tex.stackexchange.com/questions/30814/identity-of-latex-default-sans-serif-font/30816
% https://tex.stackexchange.com/questions/66674/when-i-load-multiple-font-packages-which-one-will-win
% https://tex.stackexchange.com/questions/25249/how-do-i-use-a-particular-font-for-a-small-section-of-text-in-my-document
\usepackage{lmodern}

% Select the language.
% The "csquotes" package should be used with the "babel" package.
% https://tex.stackexchange.com/questions/229638/package-biblatex-warning-babel-polyglossia-detected-but-csquotes-missing
\makeatletter
\ifportuguese@use
\usepackage[portuguese]{babel}
\usepackage[style=portuguese,threshold=1]{csquotes}
\else
\ifukenglish@use
\usepackage[UKenglish]{babel}
\usepackage[style=UKenglish,threshold=1]{csquotes}
\else
\ifusenglish@use
\usepackage[USenglish]{babel}
\usepackage[style=USenglish,threshold=1]{csquotes}
\fi
\fi
\fi
\makeatother

\usepackage[%
a4paper,%
% These margins are according to the UA rules.
% http://www.ua.pt/sga/PageText.aspx?id=4630
% left=30mm,%
% right=25mm,%
% bottom=30mm,%
% top=30mm,%
% However, one may want to slightly modify the margins, so there is no
% shift when changing pages in a PDF document viewer.
% https://en.wikibooks.org/wiki/Basic_Book_Design/Margins
left=30mm,%
right=30mm,%
bottom=30mm,%
top=30mm,%
% To show visible frames for the text area and page.
% showframe,%
]{geometry}

% Mathematical utilities.
\usepackage{amsmath}
\usepackage{amssymb}

\ifPDFTeX

% Font type selection in pdfTeX.

% Linux libertine font type.
% https://ctan.org/pkg/libertine
% \usepackage{libertine}
% \renewcommand{\ttdefault}{lmtt}
% \usepackage[libertine]{newtxmath}

\else
\ifLuaTeX

% Font type selection in LuaTeX.
% https://ctan.org/pkg/fontspec
\usepackage{fontspec}

% By default it is used the CMU font:
%   main: CMU Serif
%   sans: CMU Sans Serif
%   mono: CMU Typewriter Text
%   math: Latin Modern Math
%
% Libertinus font is also a nice choice.
% https://github.com/alerque/libertinus
% https://en.wikipedia.org/wiki/Linux_Libertine
% If you want to use Libertinus select:
%   main: Libertinus Serif
%   sans: Libertinus Sans
%   mono: Inconsolata (one monospaced font at your choice)
%   math: Libertinus Math
%
% You may need to install the fonts if they are missing. You can use
% other fonts that are not mentioned here.
% https://www.overleaf.com/learn/latex/Questions/Which_OTF_or_TTF_fonts_are_supported_via_fontspec%3F
%
% \setmainfont{BaskervilleF}
% \setmainfont{CMU Concrete}
\setmainfont{CMU Serif}
% \setmainfont{FreeSerif}
% \setmainfont{Georgia}\renewcommand{\textsc}{\textrm}
% \setmainfont{Libertinus Serif}
% \setmainfont{Linux Libertine O}
% \setmainfont{Noto Serif}
% \setmainfont{Quattrocento}\renewcommand{\textsc}{\textrm}
% \setmainfont{TeX Gyre Bonum}
% \setmainfont{TeX Gyre Pagella}
% \setmainfont{TeX Gyre Schola}
% \setmainfont{TeX Gyre Termes}
% \setmainfont{Times New Roman}\renewcommand{\textsc}{\textrm}
%
% \setsansfont{Arial}
% \setsansfont{CMU Bright}
\setsansfont{CMU Sans Serif}
% \setsansfont{CMU Sans Serif Demi Condensed}\renewcommand{\textsf}{\textnormal}
% \setsansfont{Libertinus Sans}
% \setsansfont{Linux Biolinum O}
% \setsansfont{Verdana}
%
\setmonofont{CMU Typewriter Text}
% \setmonofont{Inconsolata}
%
% To use \mathbf{} without errors.
% https://github.com/wspr/unicode-math/issues/556
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}
% \setmathfont{Libertinus Math}

\else
\RequireLuaTeX
\fi
\fi

% Line spacing. The "setspace" package has to be loaded before the
% "hyperref" package to ensure that the links of footnotes are correct.
% https://tex.stackexchange.com/questions/203439/footnotes-misbehaving-in-report-go-to-front-page-but-behave-correctly-in-other-r
\usepackage{setspace}

\usepackage[font=onehalfspacing]{caption}

% To use more colors.
\usepackage[x11names,table]{xcolor}

% To rotate pages.
\usepackage{pdflscape}

% Managing URLs.
\usepackage[hyphens,spaces]{url}

% BibLaTeX bibliography. Select the preferred citation style.

% Alternatively, you can configure your own.
% From the "biblatex" documentation: "When using the hyperref package,
% it is preferable to load it after biblatex."
\input{tex/config/biblatex/author-year.tex}
% \input{tex/config/biblatex/numeric.tex}

% Input ".bib" file name with the references.
\addbibresource{tese.bib}

% To break URLs.
% https://stackoverflow.com/questions/2625714/linebreak-in-url-with-bibtex-and-hyperref-package
% https://tex.stackexchange.com/questions/22854/url-line-breaks-with-biblatex
\setcounter{biburlnumpenalty}{3000}
\setcounter{biburlucpenalty}{6000}
\setcounter{biburllcpenalty}{9000}

% Add a line break before the URL.
% https://tex.stackexchange.com/questions/27953/linebreak-before-url-with-biblatex-alphabetic
\DeclareFieldFormat{formaturl}{\iffieldundef{url}{}{\newline #1}}
\renewbibmacro*{url+urldate}{%
  \printtext[formaturl]{%
    \printfield{url}}%
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addspace}%
     \printtext[urldate]{\printurldate}}}

% References (citations, images, tables, among others).
% Links cannot break between pages (it is mandatory to manually
% rearrange the text).
% https://tex.stackexchange.com/questions/1522/pdfendlink-ended-up-in-different-nesting-level-than-pdfstartlink
\usepackage[%
breaklinks,%
% draft,%
hidelinks,%
colorlinks,%
linktoc=all,%
% linktoc=page,%
% For debugging.
% allcolors=blue,%
% For final printed version. Choose the colors you want.
allcolors=black,%
linkcolor=black,%
citecolor=blue,%
urlcolor=blue,%
]{hyperref}

% To make the hyperlink put the cursor at the beginning of the figure
% (that is, not in the figure caption).
\usepackage[all]{hypcap}

% The "cleveref" package has to be loaded after the "hyperref" package.
% The "cleveref" has to be loaded after the "amsmath" package to
% correctly reference equations.
% https://tex.stackexchange.com/questions/148699/equation-reference-undefined-when-using-cref-and-packageamsmath
\usepackage[nameinlink,noabbrev]{cleveref}

% Multiple references to the same footnote.
% https://tex.stackexchange.com/questions/10102/multiple-references-to-the-same-footnote-with-hyperref-support-is-there-a-bett
\crefformat{footnote}{#2\footnotemark[#1]#3}

% To create hyperlinks from the footnotes at the bottom of the page,
% back to the occurrence of the footnote in the main text.
% This package conflicts with the "\footcitetext" command from the
% "biblatex" package.
\usepackage{footnotebackref}

% Table footnote.
% https://tex.stackexchange.com/questions/1583/footnotes-in-tables
% From the "tablefootnote" documentation:
% When the document is compiled with LuaLaTeX, hyperlinks in rotated
% content will be misplaced. Use it with caution.
% \usepackage{tablefootnote}

% Header and footer treatment.
\usepackage{fancyhdr}

% To place floats (figures, tables) at fixed position using the
% "\FloatBarrier" command.
\usepackage{placeins}

% To allow tables spanning multiple pages.
% https://texfaq.org/FAQ-longtab
% To prevent longtable breaking in multirow.
% https://tex.stackexchange.com/questions/64956/prevent-longtable-breaking-in-multirow
% A longtable example.
% http://users.sdsc.edu/~ssmallen/latex/longtable.html
\usepackage{longtable}

% To enhance the quality of tables.
\usepackage{booktabs}

% To specify vertical alignment in rows (tables).
\usepackage{array}

% Horizontally centered and right aligned.
% https://tex.stackexchange.com/questions/154958/vertically-centered-and-right-left-center-horizontal-alignment-in-tabular

% Note: the following shortcuts for column alignments are easy to
% memorize. They form a 3x3 square in the QWERTY keyboard layout.

% --- Top (vertical alignment) ---
% Justified.
% p{...}
% Left-aligned.
\newcolumntype{E}[1]{>{\raggedright\arraybackslash}p{#1}}
% Centered.
\newcolumntype{R}[1]{>{\centering\arraybackslash}p{#1}}
% Right-aligned.
\newcolumntype{T}[1]{>{\raggedleft\arraybackslash}p{#1}}

% --- Middle (vertical alignment) ---
% Justified.
% m{...}
% Left-aligned.
\newcolumntype{D}[1]{>{\raggedright\arraybackslash}m{#1}}
% Centered.
\newcolumntype{F}[1]{>{\centering\arraybackslash}m{#1}}
% Right-aligned.
\newcolumntype{G}[1]{>{\raggedleft\arraybackslash}m{#1}}

% --- Bottom (vertical alignment) ---
% Justified.
% b{...}
% Left-aligned.
\newcolumntype{C}[1]{>{\raggedright\arraybackslash}b{#1}}
% Centered.
\newcolumntype{V}[1]{>{\centering\arraybackslash}b{#1}}
% Right-aligned.
\newcolumntype{B}[1]{>{\raggedleft\arraybackslash}b{#1}}

% Extra column with zero width and no padding. This is used to avoid the
% incorrect alignment in the last column.
% https://tex.stackexchange.com/questions/159257/increase-latex-table-row-height
% https://tex.stackexchange.com/questions/68732/vertical-alignment-in-table-m-column-row-size-problem-in-last-column
\newcolumntype{N}{@{}m{0pt}@{}}

% Empty column separator.
% https://texfaq.org/FAQ-fixwidtab
\newcolumntype{O}{@{}}

% To use 2% of the \textwidth as column separator.
\newcolumntype{I}{@{\hskip0.02\textwidth}}

% Multirow in tables.
\usepackage{multirow}

% New lines in multirow cells.
% https://tex.stackexchange.com/questions/331716/newline-in-multirow-environment
\usepackage{makecell}

% To change the itemize character.
\usepackage{enumitem}

% To compact the "itemize" list.
% https://stackoverflow.com/questions/4968557/latex-very-compact-itemize/4974583#4974583
\setlist{itemsep=5pt,topsep=5pt,parsep=5pt,partopsep=5pt}

% To place "longtable" tables at the top of the page.
\usepackage{afterpage}

% Hyphenation throughout the document.
\usepackage{hyphenat}
% To disable hyphenation use the "none" option.
% \usepackage[none]{hyphenat}
\usepackage{siunitx}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{matrix,backgrounds,calc,shapes,positioning,fit}
\usepackage{pifont}
\usepackage{physics} 



\newcommand\solidrule[1][1cm]{\rule[0.5ex]{#1}{.4pt}}
\newcommand\dashedrule{\mbox{%
  \solidrule[1mm]\hspace{1mm}\solidrule[1mm]\hspace{1mm}\solidrule[1mm]}}
% For rotating text with the "turn" command.
\usepackage{rotating}

% To use the "\sfrac" command.
\usepackage{xfrac}

% Disable displaying page number, header and footer on empty pages.
\usepackage{emptypage}

% Colored boxes.
% \usepackage[most]{tcolorbox}

% To force not to break the line after a hyphen. This conflicts with
% latexdiff. Use it with caution.
% https://tex.stackexchange.com/questions/103608/how-to-force-latex-not-to-break-the-line-after-a-hyphen
% \usepackage[shortcuts]{extdash}

% For creating a list of abbreviations.
\usepackage[%
nogroupskip=false,%
nonumberlist=true,%
nopostdot=true,%
% style=alttree,%
style=listdotted,%
% style=long,%
% style=super,%
shortcuts=abbreviations,%
% The "uathesis" style file is already adding the glossary into the
% table of contents.
toc=false,%
]{glossaries-extra}

% To revert \markright, \markboth and \@starttoc related with the
% \MakeUpperCase command. This is required to not mix up with the
% uppercase of chapter headings.
\glsxtrRevertMarks

% To disable all abbreviation hyperlinks.
% https://tex.stackexchange.com/questions/25805/disable-hyperlinks-in-some-entries-for-glossaries
% \glsdisablehyper

% To add links inside captions.
% https://tex.stackexchange.com/questions/30800/gls-inside-caption-without-protect
\robustify{\gls}

% To specify the widest name of the short form of an abbreviation.
% This applies when the "alttree" style is used.
\glssetwidest{123456789012345}

% To specify dotted distance between abbreviation and description.
% This applies when the "listdotted" style is used.
% https://tex.stackexchange.com/questions/17956/dotted-distance-between-acronym-and-description-in-acronymlist-from-glossaries
\setlength{\glslistdottedwidth}{.28\textwidth}

% To remove bold of the short forms in the glossary.
\renewcommand{\glsnamefont}[1]{\normalfont #1}

% To generate the glossary.
% https://tex.stackexchange.com/questions/243750/acronym-glossary-doesnt-appear
\makenoidxglossaries

% Appendices.
% https://ctan.org/pkg/appendix
% https://texfaq.org/FAQ-appendix
% https://tex.stackexchange.com/questions/49643/making-appendix-for-thesis
% Do not use the "page" option if you do not want to create an
% additional page with only the title "Appendices".
\usepackage[toc,page]{appendix}
% \usepackage[toc]{appendix}
