% PDFLaTeX
\usepackage{lmodern}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lettrine, lipsum} % Pour mettre des lettrines - Pour les tests

\usepackage{fancyhdr, fourier-orns} % En-têtes et pieds de pages -- Bonus pour les en-têtes (\headrule)
\fancyhf{} % Efface tout
\fancypagestyle{mainstyle}{
\renewcommand{\headrulewidth}{0pt}
\fancyhead[L]{\textsc{\nouppercase{\leftmark}}} % Mettre l'en-tête en small capitals
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[C]{\thepage}}
\pagestyle{plain} % mainstyle appliqué plus tard
\renewcommand{\headrule}{\hrulefill \raisebox{-2.1pt}[10pt][10pt]{\quad\decofourleft\decotwo\decofourright\quad}\hrulefill}

\usepackage{graphicx, float, subcaption} % Pour mettre les images
\graphicspath{{./Images/}} % Sous-répertoire pour mettre les images

\usepackage{enumitem, multicol, pifont, eurosym} % Pour les listes à puce
\setlist[itemize, 1]{label = {--}, itemsep = \baselineskip}
\setlist[enumerate, 1]{label = \arabic*), itemsep = \baselineskip}

\usepackage{amsmath, amsfonts, amssymb, mathrsfs, esvect, stmaryrd} % Pour faire des maths

\usepackage{array, booktabs, longtable} % Pour les tableaux
\renewcommand{\arraystretch}{1.3}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

\usepackage[breakable, listings, skins]{tcolorbox} % Boîtes personnalisables
\usepackage{pgfornament, pgfplots} % TikZ et tracé de fonctions
\usetikzlibrary{arrows, arrows.meta, decorations.text, mindmap, positioning}

\usepackage{pdfpages, qrcode} % Pour inclure des PDF -- Pour le QR Code

\usepackage[hyphens]{url} % Pour des césures correctes dans les URLs
\usepackage[pdfauthor = {{Adrien Bouzigues - I13 Cl215}}, pdftitle = {{Initiation à LaTeX}}, pdfstartview = Fit, pdfpagelayout = SinglePage, pdfnewwindow = true, bookmarksnumbered = true, breaklinks, colorlinks, linkcolor = red, urlcolor = black, citecolor = cyan, linktoc = all]{hyperref} % Renvois -- Options Adobe

% Chargement après hyperref selon le guide d'utilisation
\usepackage[os = win]{menukeys} % Pour "écrire" des touches claviers
\renewmenumacro{\keys}[+]{shadowedroundedkeys} % Style choisi pour les touches -- [+] = séparateur

\makeatletter\@addtoreset{section}{chapter}\makeatother % RAZ des numéros de section après un chapitre
\renewcommand{\thepart}{\Roman{part}}
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\thesection}{\thechapter.\arabic{section}}


% Commandes créées
% Page de garde et mind map
\definecolor{BlueFR}{RGB}{0,35,149}
\definecolor{RedFR}{RGB}{237,41,57}
\definecolor{NewOrange}{RGB}{247,111,43}
\definecolor{Gold}{RGB}{255,215,0}
\definecolor{NewGold}{RGB}{130,114,46}
\definecolor{LOrchid}{RGB}{177,97,245}
\definecolor{LOrange}{RGB}{255,102,32}
\definecolor{LLimeGreen}{RGB}{140,251,0}
\definecolor{LCyan}{RGB}{4,254,251}
\definecolor{LRed}{RGB}{255,12,12}

% Aperçu Texmaker (Aide_LaTeX1.png) -- Hred = Red - Hyellow = Gold
\definecolor{Horange}{RGB}{255,156,0}
\definecolor{Hgreen}{RGB}{0,167,0}
\definecolor{Hblue}{RGB}{0,234,255}
\definecolor{Hpurple}{RGB}{169,15,219}


% Raccourcis
\newcommand{\Windows}{\texttt{Windows}}
\newcommand{\Linux}{\texttt{Linux}}
\newcommand{\Apple}{\texttt{Apple}}
\newcommand{\LinkedIn}{\texttt{LinkedIn}}
\newcommand{\MiKTeX}{\texttt{MiKTeX}}
\newcommand{\Texmaker}{\texttt{Texmaker}}
\newcommand{\TikZ}{Ti\textit{k}Z}
\newcommand{\Paint}{\texttt{Paint}}
\newcommand{\GIMP}{\texttt{GIMP}}
\newcommand{\Inkscape}{\texttt{Inkscape}}


% "Boîtes" -- Package tcolorbox
% Boîtes types
\newtcolorbox{boitetype}[4][]{enhanced, breakable, before upper = {\parindent17.6pt}, beforeafter skip = \baselineskip, colframe = #3, colback = #4, boxrule = 2pt, arc = 4mm, fonttitle = \bfseries, title = {#2}, coltitle = black, #1} % before upper = alinéa dans boîte

\newtcolorbox{boitecointype}[7][]{%
cornerrulewidth/.store in = {\tcbcornerrulewidth},
cornerrulewidth = #7,
topcornercolor/.store in = {\tcbtopcornercolor},
topcornercolor = #3,
bottomcornercolor/.store in = {\tcbbottomcornercolor},
bottomcornercolor = #4,
enhanced, breakable, before upper = {\parindent17.6pt}, beforeafter skip = \baselineskip, sharp corners, boxrule = 0pt, colback = #5, title = {#2}, fonttitle = \bfseries, coltitle = black, colbacktitle = #6, underlay unbroken = {
	\draw[\tcbtopcornercolor, line width = \tcbcornerrulewidth] ([xshift = -\tcbcornerrulewidth/2]frame.west) -- ([shift = {(-\tcbcornerrulewidth/2,\tcbcornerrulewidth/2)}]frame.north west) -- ([yshift = \tcbcornerrulewidth/2]frame.north);
	\draw[\tcbtopcornercolor, line width = \tcbcornerrulewidth] ([xshift = \tcbcornerrulewidth/2]frame.east) -- ([shift = {(\tcbcornerrulewidth/2,-\tcbcornerrulewidth/2)}]frame.south east) -- ([yshift = -\tcbcornerrulewidth/2]frame.south);
}, underlay first = {
	\draw[\tcbtopcornercolor, line width = \tcbcornerrulewidth] ([xshift = -\tcbcornerrulewidth/2]frame.west) -- ([shift = {(-\tcbcornerrulewidth/2,\tcbcornerrulewidth/2)}]frame.north west) -- ([yshift = \tcbcornerrulewidth/2]frame.north);
}, underlay last = {
	\draw[\tcbtopcornercolor, line width = \tcbcornerrulewidth] ([xshift = \tcbcornerrulewidth/2]frame.east) -- ([shift = {(\tcbcornerrulewidth/2,-\tcbcornerrulewidth/2)}]frame.south east) -- ([yshift = -\tcbcornerrulewidth/2]frame.south);
}, #1}


% Construction des autres boîtes en fonction d'une boîte type
\newenvironment{boite}[3][]{\begin{boitetype}[#1]{#2}{#3}{white}}{\end{boitetype}}
\newenvironment{boitecoin}[3][]{\begin{boitecointype}[#1]{#2}{#3}{#3}{#3!5!white}{#3!50}{2pt}}{\end{boitecointype}}

\newenvironment{regles}[2][]{\begin{boitetype}[sharp corners, boxrule = 3pt, coltitle = white, #1]{#2}{BrickRed}{Goldenrod}}{\end{boitetype}}
\newenvironment{definition}[2][]{\begin{boitecoin}[#1]{#2}{Green}}{\end{boitecoin}}
\newenvironment{conseil}[2][]{\begin{boitetype}[#1]{#2}{cyan}{cyan!40}}{\end{boitetype}}
\newenvironment{attention}[2][]{\begin{boitetype}[left = 6mm, coltitle = white, sharp corners = west, underlay = {%
	\path[fill = yellow!50!black] (frame.south west) rectangle node[white] {\huge\bfseries{}!} ([xshift = 4mm]frame.north west);
}, drop fuzzy shadow, #1]{#2}{yellow!20!black}{yellow!50}}{\end{boitetype}} % Nouvelle boîte "attention" -- Inspiration : boîte "marker" (code source guide tcolorbox)

% Utilité ? --> Si non, à supprimer !
%\newenvironment{exemple}[2][]{\begin{boitetype}[sharp corners, boxrule = 0pt, #1]{#2}{Goldenrod}{Goldenrod!40}}{\end{boitetype}}

% !!! A supprimer !!! Temporaire (génération V2)
\newenvironment{conseilbox}[2][]{\begin{boitetype}[#1]{#2}{cyan}{cyan!40}}{\end{boitetype}}
\newenvironment{attentionbox}[2][]{\begin{boitetype}[#1]{#2}{orange}{orange!40}}{\end{boitetype}}
% !!! Fin suppression !!!

% Boite type avec listing impossible --> problème lors de l'appel du nouvel environnement (en gros, avec une couche supplémentaire \newenvironment, listing n'arrive pas à bien détecter le début et la fin de l'environnement donc erreur)
%\newtcblisting{code}[2][]{enhanced, breakable, before upper = {\parindent17.6pt}, beforeafter skip = \baselineskip, colframe = LimeGreen, colback = LimeGreen!5, boxrule = 2pt, arc = 4mm, fonttitle = \bfseries, title = {#2}, coltitle = black, colbacktitle = LimeGreen!50, listing options = {basicstyle = \ttfamily\small, keepspaces = true, columns = flexible, breaklines = true, inputencoding = utf8, language = TeX, numbers = none, showstringspaces = false, commentstyle = \color{gray}}, listing only, #1} % Ou passer en "listing and text" ? (affichage du résultat ==> enlever/commenter tous les préambules)

% Stockage de 2 variables principales (plus propre)
% Autre solution : utiliser le code source tcolorbox (tcbcol@frame : couleur définie par colback)
% Attention : breakable impossible si "listing side text"...
\newtcblisting{code}[2][]{
maincolor/.store in = {\tcbmaincol},
maincolor = LimeGreen,
rulewidth/.store in = {\tcbrulewidth},
rulewidth = 2pt,
enhanced, breakable, beforeafter skip = \baselineskip, sharp corners, boxrule = \tcbrulewidth, colframe = \tcbmaincol, colback = \tcbmaincol!15, colbacktitle = \tcbmaincol!50, coltitle = black, fonttitle = \bfseries, title = {#2}, attach boxed title to top center = {yshift = -\tcbrulewidth/2-\tcboxedtitleheight/2, yshifttext = -\tcboxedtitleheight/2}, boxed title style = {boxrule = \tcbrulewidth, frame code = {
	\path[tcb fill frame] ([xshift = -3mm]frame.west) -- (frame.north west) -- (frame.north east) -- ([xshift = 3mm]frame.east) -- (frame.south east) -- (frame.south west) -- cycle;}, interior code = {
	\path[tcb fill interior] ([xshift = -2mm]interior.west) -- (interior.north west) -- (interior.north east) -- ([xshift = 2mm]interior.east) -- (interior.south east) -- (interior.south west) -- cycle;}},
listing options = {basicstyle = \ttfamily\small, keepspaces = true, columns = flexible, breaklines = true, breakatwhitespace = true, inputencoding = utf8, language = TeX, numbers = none, showstringspaces = false, commentstyle = \color{gray}}, listing only, drop fuzzy shadow, #1}

\newtcblisting{codedisplay}[2][]{
maincolor/.store in = {\tcbmaincol},
maincolor = LimeGreen,
rulewidth/.store in = {\tcbrulewidth},
rulewidth = 2pt,
enhanced, breakable, beforeafter skip = \baselineskip, sharp corners, boxrule = \tcbrulewidth, colframe = \tcbmaincol, colback = \tcbmaincol!15, colbacktitle = \tcbmaincol!50, coltitle = black, fonttitle = \bfseries, title = {#2}, attach boxed title to top center = {yshift = -\tcbrulewidth/2-\tcboxedtitleheight/2, yshifttext = -\tcboxedtitleheight/2}, boxed title style = {boxrule = \tcbrulewidth, frame code = {
	\path[tcb fill frame] ([xshift = -3mm]frame.west) -- (frame.north west) -- (frame.north east) -- ([xshift = 3mm]frame.east) -- (frame.south east) -- (frame.south west) -- cycle;}, interior code = {
	\path[tcb fill interior] ([xshift = -2mm]interior.west) -- (interior.north west) -- (interior.north east) -- ([xshift = 2mm]interior.east) -- (interior.south east) -- (interior.south west) -- cycle;}},
listing options = {basicstyle = \ttfamily\small, keepspaces = true, columns = flexible, breaklines = true, breakatwhitespace = true, inputencoding = utf8, language = TeX, numbers = none, showstringspaces = false, commentstyle = \color{gray}}, listing side text, righthand ratio = 0.4, sidebyside gap = 13mm, bicolor, colbacklower = white, drop fuzzy shadow, #1}

% Boîte spéciale code TikZ ???

% Ne fonctionne pas...
%\newenvironment{code}[2][]{\begin{boitecodetype}[#1]{#2}{LimeGreen}{LimeGreen!5!white}{LimeGreen!50}{2pt}{TeX}}{\end{boitecodetype}}

% Nécessaire ? --> chapitre PSTricks...
\newtcblisting{codePY}[2][]{breakable, beforeafter skip = \baselineskip, colframe = Orchid, colback = white, boxrule = 2pt, arc = 6pt, title = \textbf{#2}, coltitle = black, listing options = {basicstyle = \ttfamily\small, keepspaces = true, columns = flexible, breaklines = true, inputencoding = utf8, language = Python, xleftmargin = 17pt, numbers = left, numbersep = 13pt, numberstyle = \ttfamily\footnotesize\color{OrangeRed}, showstringspaces = false, commentstyle = \color{gray}, keywordstyle = \color{Blue}, stringstyle = \color{orange}}, listing only, #1}

% Pour résoudre le problème des accents dans le code (listings sous tcolorbox)
\lstset{literate = {à}{{\`a}}1 {â}{{\^a}}1 {é}{{\'e}}1 {è}{{\`e}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1 {ç}{{\c{}c}}1 {°}{{\degres{}}}1}