\usepackage[french,english]{babel}

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

\usepackage{caption}
\usepackage{subcaption}
\captionsetup{subrefformat=simple}

\captionsetup[figure]{labelfont=bf}
\captionsetup[subfigure]{labelfont=bf}
\captionsetup[listing]{labelfont=bf}
\captionsetup[table]{labelfont=bf}

\usepackage[olditem,oldenum]{paralist}

\RequirePackage{setspace}
\onehalfspacing

\usepackage{tocloft}
\setlength{\cftfignumwidth}{2.5em}  % Adjust this value as needed

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

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

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

\renewcommand{\floatpagefraction}{.8}%

\usepackage{etoolbox}

\pretocmd{\section}{\clearpage}{}{}

\makeatletter
\preto\Gin@extensions{png,}
\DeclareGraphicsRule{.png}{pdf}{.pdf}{\noexpand\Gin@base.pdf}
\preto\Gin@extensions{gif,}
\DeclareGraphicsRule{.gif}{png}{.png}{\noexpand\Gin@base.png}
\makeatother

\usepackage{xpatch} % Recommanded for biblatex
\usepackage[        % use biblatex for bibliography
    backend=biber,  % use biber backend (bibtex replacement) or bibtex
    style=numeric-comp, % 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} % It seems I don't need that as I don't want to use unicode char
  \usepackage{fontspec}
  \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}

\definecolor{my-blue}{HTML}{6b7adb}
\definecolor{my-pale-blue}{HTML}{e6e9f9}
\definecolor{my-red}{HTML}{db6b6b}
\definecolor{my-pale-red}{HTML}{f9e6e6}
\definecolor{my-green}{HTML}{6bdbb6}
\definecolor{my-pale-green}{HTML}{e6f9f3}
\definecolor{my-yellow}{HTML}{dbd26b}
\definecolor{my-pale-yellow}{HTML}{f9f7e6}
\definecolor{my-orange}{HTML}{dba76b}
\definecolor{my-pale-orange}{HTML}{f9f0e6}
\definecolor{my-grey}{HTML}{a3a3a3}
\definecolor{my-pale-grey}{HTML}{f0f0f0}
\definecolor{my-turq}{HTML}{6bc7db}
\definecolor{my-pale-turq}{HTML}{e6f6f9}

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

\let\OldTexttt\texttt
\renewcommand{\texttt}[1]{{\ttfamily\hl{\mbox{\,#1\,}}}}

\usepackage{scrhack}

\usepackage{float}
\usepackage{enumitem}

% highlight
\usepackage{soul}
\sethlcolor{my-pale-grey}

% \usepackage[headsepline]{scrlayer-scrpage}
% \pagestyle{scrheadings}

\usepackage[autooneside=false,headsepline]{scrlayer-scrpage}
% \pagestyle{scrheadings}
% \automark[section]{chapter}

% Clear default header styles
\clearpairofpagestyles
\automark[section]{chapter}

% Set the header content
\ihead{\headmark}  % Chapter (or section on even pages) aligned to the left
\ohead{\pagemark}  % Page number aligned to the right

% Enable the page style
\pagestyle{scrheadings}

\setkomafont{headsepline}{\color{black}}  % Change color if desired
\ModifyLayer[addvoffset=\dp\strutbox]{headsepline}  % Fine-tune position

% \automark{section}
% \renewhead*{headings}{
%   \ifstr{\headmark}{}{}{%
%     \headmark\hfill
%   }
% }

\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

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

\usepackage{hypcap}

\usepackage{bookmark}

\bookmarksetup{depth=2}

\makeindex
\makeglossaries