\usepackage[top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm]{geometry}

% ----------------- Fonts, encoding and language packages ------------------
\usepackage{fouriernc} % Use the New Century Schoolbook font
\usepackage[utf8]{inputenc} % Required for inputting international UTF-8 characters
\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage{babel} % Language package (language is defined in documentclass)
\usepackage{setspace} % Font/line (and others) spacing configuration
\usepackage{tocbibind} % Insert TOC reference link into TOC
\usepackage[section]{placeins} % Place figures in their section only

% ------------- Tables, figures and other special environments -------------
\usepackage{graphicx} % Import and manage graphics
\usepackage{tabularx} % Better table control (ie. auto cell's width)
\usepackage{multirow} % Allows multirow cells in tables
\usepackage{pdfpages} % Insert PDF documents
\usepackage{subcaption} % To use subfigures
\usepackage[export]{adjustbox} % Adjust figures position
\usepackage{marginnote} % Insert notes in doc margins

% Table column types (gray italic column / centered expanding column)
\newcolumntype{\grayc}{>{\itshape\large\raggedright\arraybackslash\columncolor{gray90}}c}
\newcolumntype{\centerX}{>{\centering\arraybackslash}X}

% --------------------- Codes and scripts environments ---------------------
\usepackage{listings} % Create lists with line numbers (used for code view)
\usepackage{minted} % Color syntax for scripts in multiple languages

% ----------------------------- Color defines ------------------------------
\usepackage{xcolor,colortbl} % Table cells color editing
\usepackage{color} % Main color package (define colors)
\definecolor{accentcolor}{RGB}{0,119,139} % Accent color used in the whole doc
\definecolor{gray75}{gray}{0.75} % Title lines main color
\definecolor{gray90}{gray}{0.90} % Table main rows/columns
\definecolor{darkgreen}{rgb}{.0, .5, .0} % EXTENDS command color

% Insert links, color them and modify PDF settings
\usepackage[colorlinks=true,allcolors=accentcolor,bookmarks=true]{hyperref}

\definecolor{ENSBlue}{RGB}{0, 119, 139}
\definecolor{ENSGrey}{rgb}{0.3, 0.3, 0.3}
\definecolor{ENSLightGrey}{RGB}{190, 200, 200}
\definecolor{ENSDarkBlue}{RGB}{10, 50, 80}
\definecolor{matlabGreen}{RGB}{28, 172, 0} % Pour le listing des codes
\definecolor{matlabLilas}{RGB}{170, 55, 241}

% -------------------- Bibliography configuration --------------------------
\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}
\usepackage{csquotes} % To ensure quotes with biblatex are working well
\addbibresource{Bibliographie.bib} % Bibliography file to load

% --------------------------- Title style editing --------------------------
\usepackage{titlesec} % Lets modify header styles (chapter, section, etc)
\newcommand{\hspct}{\hspace{18pt}} % Horizontal space for chapter title
\newcommand{\hspst}{\hspace{9pt}} % Horizontal space for section title
\newcommand{\hspsst}{\hspace{4.5pt}} % Horizontal space for subsection title

\titleformat{\chapter}[hang]
    {\color{ENSBlue}\Huge\bfseries\raggedright} % Huge size and bold font
    {\thechapter\hspct % Number and horizontal space
     \textcolor{ENSBlue}{\rule[-0.25\baselineskip]{5pt}{\baselineskip}}
     \hspct}{0pt}{} % Horizontal space then name

\titleformat{\section}[hang]
    {\color{ENSBlue}\Large\bfseries\raggedright} % Huge size and bold font
    {\thesection\hspst\textcolor{ENSDarkBlue}{-}\hspst}{0pt}{} % Number, horizontal space then name
    [\hrule height 0.5pt]

\titleformat{\subsection}[hang]
    {\color{ENSBlue}\large\bfseries\raggedright} % Color, Huge size and bold font
    {\thesubsection\hspsst\textcolor{ENSDarkBlue}{-}\hspsst}{0pt}{} % Number, horizontal space then name
    
\titleformat{\subsubsection}[hang]
    {\color{ENSBlue}\large\bfseries\raggedright} % Color, Huge size and bold font
    {\thesubsection\hspsst\textcolor{ENSDarkBlue}{-}\hspsst}{0pt}{} % Number, horizontal space then name

\titleformat{\subsubsubsection}[hang]
    {\color{ENSBlue}\large\bfseries\raggedright} % Color, Huge size and bold font
    {\thesubsection\hspsst\textcolor{ENSDarkBlue}{-}\hspsst}{0pt}{} % Number, horizontal space then name 
    

% -------------------------- Mathematic packages --------------------------
\usepackage{amsmath} % Create matrices, subequations and more
\usepackage{amssymb} % Math font to create symbols from characters

% Mathematic new commands
\newcommand{\sgn}{\text{sgn}} % Sign function as text

% -------------------------- FRENCH translations --------------------------

\iflanguage{french}{ % Replace "Table" with "Tableau" in FRENCH only
    \AtBeginDocument{\renewcommand\tablename{\textsc{Tableau}}}
    \AtBeginDocument{\renewcommand\listingscaption{\textsc{Code}}}
    \AtBeginDocument{\renewcommand\lstlistlistingname{Liste des codes}}
}
    
% -------------------------- New useful commands --------------------------
\newcommand{\todo}[1]{\textbf{\textcolor{blue}{(TODO: #1)}} \PackageWarning{setup}{#1}} % TODO command
\newcommand{\extend}[1]{\textbf{\textcolor{darkgreen}{(EXTEND: #1)}} \PackageWarning{setup}{#1}} % EXTENDS command
\newcommand{\draft}[1]{\textbf{\textcolor{red}{(DRAFT: #1)}} \PackageWarning{setup}{#1}} % DRAFT command

% Reset page number and change page numbering style
\newcommand{\changepagenumbering}[1]{
    \setcounter{page}{1}
    \pagenumbering{#1}
}

\makeatletter
\newcommand*{\field}[1]{\gdef\@field{#1}} % Defines "field" variable used in title page
\newcommand*{\project}[1]{\gdef\@project{#1}} % Defines "project" variable used in title page
\newcommand*{\mainlogo}[1]{\gdef\@mainlogo{#1}} % Defines "mainlogo" variable used in title page
\newcommand*{\logoCN}[1]{\gdef\@logoCN{#1}} % Defines "optionallogo" variable used in title page
\newcommand*{\logoCNRS}[1]{\gdef\@logoCNRS{#1}} % Defines "optionallogo" variable used in title page
\makeatother

% Existing environments configuration
\usepackage{etoolbox} % Allows to append commands to existing environements

\iflanguage{english}{
    \AtBeginEnvironment{itemize}{\setlength{\baselineskip}{0em}} % Change itemize line skip
    \AtBeginEnvironment{itemize}{\setlength{\parskip}{.7em}} % Change itemize line vertical space
    
    \AtBeginEnvironment{enumerate}{\setlength{\baselineskip}{0em}} % Change enumerate line skip
    \AtBeginEnvironment{enumerate}{\setlength{\parskip}{.7em}} % Change enumerate line vertical space
}

\AtBeginEnvironment{tabularx}{\def\arraystretch{1.6}} % Change array vertical padding within cells
