% Source: https://github.com/DorianDepriester/TemplateThese/blob/master/Preambule.tex
%% Réglage des fontes et typo
\usepackage[utf8]{inputenc}		% LaTeX, comprend les accents !
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[bottom]{footmisc}
\usepackage[french]{babel}
% \frenchbsetup{
%   FrenchFootnotes=false,
%   AutoSpaceFootnotes=false
% }  
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % Bibliographie
\usepackage[
  defernumbers,
  style=ext-numeric,
  sorting=nty,
  articlein=false,
  backend=biber]{biblatex}
\addbibresource{bibliography.bib}
\DeclareLabelname[movie]{
  \field{director}
  \field{producer}
}

\DeclareBibliographyDriver{movie}{%
  \printnames{editor}%
  \newunit\newblock
  \printfield{title}%
  \newunit
  \printfield{year}%
  \finentry}

\DefineBibliographyStrings{french}{%
  in = {dans},
  % director = {réalisateur},
  % scriptwriter = {scénariste},
}

\DeclareNameAlias{author}{family-given}
\DeclareNameAlias{sortname}{family-given}
\DeclareNameAlias{editor}{family-given}
\DeclareNameAlias{editor}{family-given}
\renewcommand*{\multinamedelim}{\addcomma\space}
\renewcommand*{\finalnamedelim}{\addcomma\space}
\renewcommand*{\nameyeardelim}{\addcomma\space}

\defbibfilter{papers}{
  type=article or
  type=inproceedings
}


\usepackage[autostyle=true,french=guillemets]{csquotes}
\MakeOuterQuote{"}
\MakeAutoQuote{«}{»}
\MakeBlockQuote{<}{|}{>}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % Allure générale du document

\usepackage[section]{placeins}	% Place un FloatBarrier à chaque nouvelle section
\usepackage{epigraph}
\usepackage[font={small}]{caption}
\usepackage{tocloft}
\addtolength{\cftchapnumwidth}{1em}
\addtolength{\cftsecnumwidth}{1em}
\addtolength{\cftsubsecnumwidth}{1em}
\addtolength{\cftfignumwidth}{1em}
\addtolength{\cfttabnumwidth}{1em}
\addtolength{\cftbeforechapskip}{-1pt} 
\usepackage[titletoc, title]{appendix}
\usepackage{titlesec}
\titlespacing{\paragraph}{0pt}{\medskipamount}{5pt}
\titleformat{\paragraph}[runin]{\normalfont\normalsize\bfseries}{\theparagraph}{0em}{}[~:\space]
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Mise en forme du texte        
\usepackage{blindtext}
\usepackage{svg}
\usepackage{graphicx}
\graphicspath{{images/}{../images/}}

\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{array}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{tabularx}
\usepackage{xcolor}
\usepackage{dramatist}
\usepackage{qrcode}%[draft]
\usepackage{caption}
\usepackage[position=bottom]{subcaption}
\usepackage{pdfpages}
\usepackage{comment}
% \usepackage{pst-barcode}
\usepackage{longtable}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{booktabs}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Navigation dans le document
\usepackage[
  pdftex,
  pdfborder={0 0 0},
  colorlinks=false,
  linkcolor=black,
  citecolor=black
]{hyperref}	% Créera automatiquement les liens internes au PDF
% Doit être chargé en dernier (Sauf exceptions ci-dessous)
\usepackage{bookmark}
\usepackage{xurl}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Packages qui doivent être chargés APRES hyperref	             
\usepackage[top=2.5cm, bottom=2cm, left=3cm, right=2.5cm,
  headheight=15pt]{geometry}

\usepackage{fancyhdr}			% Entête et pieds de page. Doit être placé APRES geometry
% \pagestyle{fancy}	
\makeatletter
% clear double page Style
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
      \begingroup
      \mbox{}
      \vspace*{\fill}
      \vspace{\fill}
      \thispagestyle{plain}
      \newpage
      \if@twocolumn\mbox{}\newpage\fi
      \endgroup\fi\fi}

% empty page after part Style
\def\@endpart{\vfil\newpage
  \if@twoside
    \if@openright
      \null
      \thispagestyle{plain}%
      \vspace*{\fill}%

      \newpage
    \fi
  \fi
  \if@tempswa
    \twocolumn
  \fi}
\makeatother
\fancypagestyle{corps}{
  \fancyhf{}
  % \fancyhead[le]{\thepage} %section
  \fancyhead[le]{\slshape \nouppercase \leftmark}
  % \fancyhead[ro]{\thepage} % chapter
  \fancyhead[lo]{\slshape \nouppercase \rightmark}
  \fancyfoot[le,ro]{\thepage}
  \renewcommand{\headrulewidth}{0.4pt}
}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0pt}
  \fancyfoot[le,ro]{\thepage}
}



\usepackage{tocbibind}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Glossaire

\usepackage[acronym, toc, nopostdot, automake=immediate]{glossaries}
\makeglossaries
% hyperfirst=false
% \loadglsentries{sections/glossaire}			% Utilisation d'un fichier externe pour la définition des entrées (Glossaire.tex)		% Utilisation d'un fichier externe pour la définition des entrées (Glossaire.tex)	


\glsaddkey% star version needed as default value needs expanding
{enablef}% key
{\relax}% default value
{\glsentryenablef}% command analogous to \glsentrytext
{\Glsentryenablef}% command analogous to \Glsentrytext
{\glsenablef}% command analogous to \glstext
{\Glsenablef}% command analogous to \Glstext
{\GLSenablef}% command analogous to \GLStext


\newacronymstyle{custom-fn}% new style name
{% Check for long form in case of a mixed glossary
  \ifglshaslong{\glslabel}{\glsgenacfmt}{\glsgenentryfmt}%
}%
{% Style definitions:
  % User needs to supply the description:
  \renewcommand*{\GenericAcronymFields}{}%
  % Need to ensure hyperlinks are switched off on first use:
  \glshyperfirstfalse
  % Redefine the commands used by \glsgenacfmt on first use:
  \renewcommand*{\genacrfullformat}[2]{%
    \glsentrylong{##1}\space(\glsentryshort{##1})##2%
    \ifglshasdesc{##1}%
    {\footnote{\glsentrydesc{##1}}}%
    {}%
  }%
  \renewcommand*{\Genacrfullformat}[2]{%
    \firstacronymfont{\Glsentryshort{##1}}##2%
    \footnote{\glsentrylong{##1}: \glsentrydesc{##1}}%
  }%
  \renewcommand*{\genplacrfullformat}[2]{%
    \firstacronymfont{\glsentryshortpl{##1}}##2%
    \footnote{\glsentrylongpl{##1}: \glsentrydesc{##1}}%
  }%
  \renewcommand*{\Genplacrfullformat}[2]{%
    \firstacronymfont{\Glsentryshortpl{##1}}##2%
    \footnote{\glsentrylongpl{##1}: \glsentrydesc{##1}}%
  }%
  % Redefine the no-link full forms:
  \renewcommand*{\glsentryfull}[1]{%
    \glsentrylong{##1}\space(\acronymfont{\glsentryshort{##1}})%
  }%
  \renewcommand*{\Glsentryfull}[1]{%
    \Glsentrylong{##1}\space(\acronymfont{\glsentryshort{##1}})%
  }%
  \renewcommand*{\glsentryfullpl}[1]{%
    \glsentrylongpl{##1}\space(\acronymfont{\glsentryshortpl{##1}})%
  }%
  \renewcommand*{\Glsentryfullpl}[1]{%
    \Glsentrylongpl{##1}\space(\acronymfont{\glsentryshortpl{##1}})%
  }%
  % Redefine the link full forms:
  \renewcommand*{\acrfullfmt}[3]{%
    \glslink[##1]{##2}{%
      \glsentrylong{##2}##3\space(\acronymfont{\glsentryshort{##2}})%
    }%
  }%
  \renewcommand*{\Acrfullfmt}[3]{%
    \glslink[##1]{##2}{%
      \Glsentrylong{##2}##3\space(\acronymfont{\glsentryshort{##2}})%
    }%
  }%
  \renewcommand*{\ACRfullfmt}[3]{%
    \glslink[##1]{##2}{%
      \MakeTextUppercase{%
        \glsentrylong{##2}##3\space
        (\acronymfont{\glsentryshort{##2}})%
      }%
    }%
  }%
  \renewcommand*{\acrfullplfmt}[3]{%
    \glslink[##1]{##2}{%
      \glsentrylongpl{##2}##3\space
      (\acronymfont{\glsentryshortpl{##2}})%
    }%
  }%
  \renewcommand*{\Acrfullplfmt}[3]{%
    \glslink[##1]{##2}{%
      \Glsentrylongpl{##2}##3\space
      (\acronymfont{\glsentryshortpl{##2}})%
    }%
  }%
  \renewcommand*{\ACRfullplfmt}[3]{%
    \glslink[##1]{##2}{%
      \MakeTextUppercase{%
        \glsentrylongpl{##2}##3\space
        (\acronymfont{\glsentryshortpl{##2}})%
      }%
    }%
  }%
  % Use smallcaps for the acronym in the document text:
  \renewcommand*{\acronymfont}[1]{\textsc{##1}}%
  \renewcommand*{\acrpluralsuffix}{\glstextup{\glspluralsuffix}}%
  % Sort acronyms according to the long form:
  \renewcommand*{\acronymsort}[2]{\MakeLowercase{\Glsentrylong{##1}}}%
  % Set the name in the list of acronyms to the long form followed by
  % the short form (in upper case) in parentheses:
  \renewcommand*{\acronymentry}[1]{%
    \Glsentrylong{##1}\space(\MakeTextUppercase{\glsentryshort{##1}})}%
}
\setacronymstyle{custom-fn}
\setglossarystyle{altlist}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\definecolor{tablerulecolor}{rgb}{0.75,0.75,0.75}
\definecolor{tablerowcolor}{rgb}{0.95,0.95,0.95}
\definecolor{yellowuser}{HTML}{cecd02}
\definecolor{greenuser}{HTML}{28cb00}
\definecolor{reduser}{HTML}{ce0004}
\definecolor{blueuser}{HTML}{484dc6}
% \definecolor{lgray}{gray!50}

\lstdefinestyle{mystyle}{
  backgroundcolor=\color{backcolour},
  commentstyle=\color{codegreen},
  keywordstyle=\color{magenta},
  numberstyle=\tiny\color{codegray},
  stringstyle=\color{codepurple},
  basicstyle=\scriptsize, %\ttfamily
  breakatwhitespace=false,
  breaklines=true,
  captionpos=b,
  keepspaces=true,
  numbers=left,
  numbersep=5pt,
  showspaces=false,
  showstringspaces=false,
  showtabs=false,
  tabsize=2,
  xleftmargin=3.5em,
  xrightmargin=2em,
  frame=lines,
  framexleftmargin=0.5em,
  framexrightmargin=0.5em
}

\lstset{style=mystyle}
\usepackage[some,center]{background}
\backgroundsetup{
  scale=1,
  angle=0,
  opacity=1}

\usepackage{blindtext}