\usepackage[french,english]{babel}

\usepackage{graphicx}
\graphicspath{{figs/}}

\usepackage{subcaption}
\captionsetup{subrefformat=parens}

\usepackage[      %
    acronym,      % Separate acronyms and glossary
    toc,          % appear in ToC
    automake,     % auto-use the makeglossaries command (requires shell-escape)
    nonumberlist, % don't back reference pages
    nogroupskip,  % don't group by letter
    nopostdot     % don't add a dot at the end of each element
]{glossaries}

\usepackage[stylemods=longextra]{glossaries-extra}

\setabbreviationstyle[acronym]{long-short}
\setglossarystyle{long-name-desc}

\usepackage[olditem,oldenum]{paralist}

\RequirePackage{setspace}
\onehalfspacing

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}

\usepackage{floatrow}
\floatsetup[table]{font={footnotesize,sf},capposition=top}

\usepackage[binary-units=true]{siunitx}

\sisetup{%
  detect-all           = true,
  detect-family        = true,
  detect-mode          = true,
  detect-shape         = true,
  detect-weight        = true,
  detect-inline-weight = math,
}

\DeclareSIUnit\px{px}
\DeclareSIUnit\rms{rms}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{dsfont}

\let\originalleft\left
\let\originalright\right
\renewcommand{\left}{\mathopen{}\mathclose\bgroup\originalleft}
\renewcommand{\right}{\aftergroup\egroup\originalright}

\clubpenalty         = 10000
\widowpenalty        = 10000
\displaywidowpenalty = 10000

\usepackage{scrlayer-scrpage}

\pagestyle{scrheadings}

\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}}

\setcounter{secnumdepth}{\subsubsectionnumdepth}

\makeatletter
\renewcommand*{\chapterformat}{  \mbox{\chapappifchapterprefix{\nobreakspace}{\color{BrickRed}\fontsize{40}{45}\selectfont\thechapter}\autodot\enskip}}
% Section with color
% \renewcommand\@seccntformat[1]{\color{BrickRed} {\csname the#1\endcsname}\hspace{0.3em}}
\renewcommand\@seccntformat[1]{{\csname the#1\endcsname}\hspace{0.3em}}
\makeatother

\renewcommand{\floatpagefraction}{.8}%

\usepackage{etoolbox}

\usepackage[            %
    colorlinks=true,    %
    citecolor=BrickRed, %
    linkcolor=BrickRed, %
    urlcolor=BrickRed,  %
    unicode             %
    ]{hyperref}

\usepackage{bookmark}

\bookmarksetup{depth=2}

\usepackage{xpatch} % Recommanded for biblatex
\usepackage[        % use biblatex for bibliography
    backend=biber,  % use biber backend (bibtex replacement) or bibtex
    style=ieee,     % bib style
    hyperref=true,  % activate hyperref support
    backref=true,   % activate backrefs
    isbn=false,     % don't show isbn tags
    url=false,      % don't show url tags
    doi=false,      % don't show doi tags
    urldate=long,   % display type for dates
    maxnames=3,     %
    minnames=1,     %
    maxbibnames=5,  %
    minbibnames=3,  %
    maxcitenames=2, %
    mincitenames=1  %
    ]{biblatex}

\defbibenvironment{mypubs}
 {\list
     {}
     {\setlength{\leftmargin}{\bibhang}%
      \setlength{\itemindent}{-\leftmargin}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}}
  {\endlist}
  {\item}

\AtEveryBibitem{%
  \clearfield{urlyear}
  \clearfield{urlmonth}
  \clearfield{note}
 \clearfield{issn} % Remove issn
 \clearfield{doi} % Remove doi
\ifentrytype{online}{}{% Remove url except for @online
  \clearfield{url}
}
}

\setlength\bibitemsep{1.1\itemsep}

\renewcommand*{\bibfont}{\footnotesize}

\usepackage{minitoc}
% Change section font
\renewcommand{\mtcSfont}{\small}
% Change indentation
\setlength{\mtcindent}{0pt}
% \usepackage[nottoc]{tocbibind}

\ifxetexorluatex
  \usepackage{unicode-math}
  \setmainfont{EB Garamond}
  \setmathfont{Garamond Math}

  % Load some missing symbols from another font.
  \setmathfont{STIX Two Math}[%
    range = {
      \sharp,
      \natural,
      \flat,
      \clubsuit,
      \spadesuit,
      \checkmark
    }
  ]
  \setmonofont[Scale=MatchLowercase]{Source Code Pro}
\else
  \usepackage[lf]{ebgaramond} % https://tug.org/FontCatalogue/quattrocento/
  \usepackage[oldstyle,scale=0.7]{sourcecodepro} % https://tug.org/FontCatalogue/sourcecodepro/
  \singlespacing
\fi

\usepackage[usenames,dvipsnames]{xcolor}

\usepackage{csquotes}

\def\signed #1{{\leavevmode\unskip\nobreak\hfil\penalty50\hskip1em
    \hbox{}\nobreak\hfill #1%
    \parfillskip=0pt \finalhyphendemerits=0 \endgraf}}

\newsavebox\mybox
\newenvironment{aquote}[1]
{\savebox\mybox{#1}\begin{quote}\openautoquote\hspace*{-.7ex}}
  {\unskip\closeautoquote\vspace*{1mm}\signed{\usebox\mybox}\end{quote}}

\usepackage{setspace}
\setstretch{1.25}

\setparsizes{0em}{0.1\baselineskip plus .1\baselineskip}{1em plus 1fil}

\numberwithin{equation}{chapter}

\usepackage{listings}
\usepackage{minted}
\setminted{autogobble=true,fontsize=\small,baselinestretch=0.8}
\setminted[python]{python3=true,tabsize=4}
\usemintedstyle{trac}
\lstset{abovecaptionskip=0}
\renewcommand{\listingscaption}{Code Snippet}

\AtEndEnvironment{listing}{\vspace{-16pt}}

\usepackage{scrhack}
