% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
%                                  Copyleft Trullemans Gregory                                    %
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% @version 2.1                                                                                    %
% @date 2021-04-03                                                                                 %
%                                                                                                 %
% Seconde version du template de la Fédération francophone de Gymnastique et de fitness.          %
% Suite à la mise à jour du site internet fin 2020, le FfG définit une nouvelle charte graphique  %
% complète.                                                                                       %
%                                                                                                 %
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% Package definition
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\ProvidesPackage{ffgTemplate}


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% Required Package
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\RequirePackage[a4paper, top=2cm, bottom=2.5cm, left=2.5cm, right=2.5cm]{geometry}  % Gestion des marges
\RequirePackage[french]{babel}									% Gestion du français
\RequirePackage{graphicx}										% Gestion des images
\RequirePackage{xcolor}											% Gestion des couleurs
\RequirePackage{hyperref}										% Gestion des hyperliens
\RequirePackage{fancyhdr}										% Gestion des en-têtes et pieds de pages.
\RequirePackage{pifont}											% Gestion des symbols (\ding{55} dans le footer)
\RequirePackage{array}											% Gestion (améliorée) des tableaux
\RequirePackage{ulem}											% Gestion (avancée) des soulignements
\RequirePackage{mathtools, amsmath, amstext, amssymb, amsthm}	% Package de l'AMS + mathtools
\RequirePackage{gensymb}										% symbole \degree
\RequirePackage{cancel}
\RequirePackage{nicefrac}										% Gestion des fractions
\RequirePackage{xspace}											% Gestion intelligente de l'espace après une commande
\RequirePackage{lmodern}										% Police de caractère
\RequirePackage{calc}											% Syntaxe naturelle pour les calculs
\RequirePackage{framed}
\RequirePackage{tcolorbox}										% Pour créer des boites colorées.
\RequirePackage{multirow}										% Pour fusionner des lignes dans un tableau

% Layout fisrt page
\RequirePackage{eso-pic}								% Gestion du background de la page de garde.
\RequirePackage[absolute]{textpos}						% Gestion des positions du texte (option de config : showboxes)
\RequirePackage{fontspec}								% Gestion de "arial" ET "arial narrow" comme font.
\RequirePackage{anyfontsize}							% Gestion des tailles de police hors dictionnaire
\RequirePackage{shadowtext}								% Gestion des ombres

% Layout Document 
\RequirePackage[explicit]{titlesec}						% Gestion des sections
\RequirePackage{titletoc}								% Gestion de la table des matière
\RequirePackage{titling}								% Gestion des titres
\RequirePackage{enumitem}								% Gestion des listes

% Tools kit
\RequirePackage{fancybox}								% pour dessiner des boites ;-)
\RequirePackage{etoolbox}								% Renew command & robust command
\RequirePackage{float}

% other package
\RequirePackage{bm}										% Notation mathématique en gras
\RequirePackage{lscape}									% Gestion du mode "paysage"

\frenchbsetup{StandardItemLabels=true}


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% Define global variable for document
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\def\federationName{Fédération francophone de Gymnastique et de fitness}
\def\federationAcronym{FfG}


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% (Re)Define parametres for document
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\setmainfont{Arial}
\addto\captionsfrench{\def\tablename{Tableau}}					% Définition du mot pour les tableaux
\addto\captionsfrench{\def\figurename{Figure}}					% Définition du mot pour les Figures

% Color definition
\definecolor{ffg_darkblue}{RGB}{21,29,76}
\definecolor{ffg_lightblue}{RGB}{0, 120, 190}
\definecolor{ffg_red}{RGB}{241, 83, 60}

\definecolor{ffg_title_color}{RGB}{12, 97, 158}
\definecolor{ffg_section_color}{RGB}{24, 146, 239}

\definecolor{footer_color}{RGB}{128, 128, 128}
\definecolor{flyingblue}{RGB}{49, 123, 181}
\definecolor{greymoreknowledge}{RGB}{200, 200, 200}

% Parametres for TextPos
\setlength{\TPHorizModule}{1mm}
\textblockorigin{5mm}{5mm}										% start everything near the top-left corner
\setlength{\parindent}{0pt}										% Pas d'indentation au placement du texte

\setlength\fboxrule{0.75pt}
\newcommand{\mybox}[1]{\fbox{$~~~ \displaystyle#1 ~~~$}}

\newcommand\NextYear{%
   \advance\year by 1 \the\year\advance\year by -1}
	

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% Image's first page definition
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\newcommand\BackgroundPic{%
	\put(0,0){%
		\parbox[b][\paperheight]{\paperwidth}{%
			\vfill
			\centering
			\includegraphics[scale=1]{firstpage.png}%
			\vfill
		}
	}
}


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% First Page's definition
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\def\maketitle{%
	\null
	\thispagestyle{empty}%

	% Titre du document
	\begin{textblock}{200}(0,3)
		\centering
		{\fontsize{33}{42}\selectfont {\bfseries \textcolor{ffg_darkblue}{FORMATION~\formationType~\discipline}\par}}
		\vspace{2.5cm}
		{\fontsize{33}{42}\selectfont {\bfseries \textcolor{ffg_red}{Module :\\\moduleTitle}\par}}
	\end{textblock}

	% Type de document
	\begin{textblock}{200}(0,8)
		\begin{center}
			{\fontsize{28}{42}\selectfont \textcolor{ffg_lightblue}{Formation des Cadres}\par}%
		\end{center}
	\end{textblock}

	% Années
	\begin{textblock}{200}(0,11.5)
		\centering
		\begin{center}
			{\fontsize{30}{84}\selectfont \textcolor{white}{{\the\year}\hspace{3cm} {\NextYear}}\par}%
		\end{center}
	\end{textblock}

	\null
	\cleardoublepage
}


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% Other page definition
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\fancypagestyle{plain}{%
	\renewcommand\headrulewidth{0pt}
	\fancyhead[C]{} 
	\fancyhead[L]{}
	\fancyhead[R]{}
	\fancyhf{}

	%% Footer
	\renewcommand{\footrulewidth}{0pt}
	\fancyfoot[L]{\fontsize{9}{10}\selectfont \textit{\textcolor{footer_color}{Formation des Cadres\\ \discipline}}}
	\fancyfoot[C]{\fontsize{9}{10}\selectfont \textit{\textcolor{footer_color}{p. \thepage}}}
	\fancyfoot[R]{\fontsize{9}{10}\selectfont \textit{\textcolor{footer_color}{Edition \the\year~-~\NextYear}}}
}


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% Titles layout redefinition
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\makeatletter
\colorlet{shadecolor}{ffg_title_color}


% Numbered chapter title
\titleformat{\chapter}[display]
	{\fontsize{16pt}{12pt}\selectfont\color{white}\begin{shaded*}}
	{\thechapter \qquad #1}
	{0pt}
	{\end{shaded*}}
\titlespacing{\chapter}
	{0pt}
	{0pt}
	{0pt}

% Unnumbered chapter title
\titleformat{name=\chapter, numberless}[display]
	{\fontsize{16pt}{12pt}\selectfont\color{white}\begin{shaded*}}
	{#1}
	{0pt}
	{\end{shaded*}}
\titlespacing{name=\chapter, numberless}
	{0pt}
	{-20pt}
	{-20pt}


% Numbered section title
\titleformat{\section}[display]
	{\fontsize{14pt}{12pt}\selectfont\color{ffg_section_color}}
	{\thesection \qquad #1}
	{0pt}
	{}
	[\vspace{-4mm} {\color{ffg_lightblue}\titlerule[.6mm]} \enlargethispage{-\parskip}]
\titlespacing*{\section}
	{0pt}		% left
	{24pt}		% top
	{10pt}		% bottom

% Unnumbered section title
\titleformat{name=\section, numberless}[display]
	{\fontsize{14pt}{12pt}\selectfont\color{ffg_section_color}}
	{\thesection \qquad #1}
	{0pt}
	{}
	[\vspace{-4mm} {\color{ffg_lightblue}\titlerule[.6mm]} \enlargethispage{-\parskip}]


% Numbered subsection title
\titleformat{\subsection}[display]
	{\fontsize{13pt}{12pt}\selectfont\color{ffg_title_color}}
	{\quad \thesubsection \quad #1}
	{0pt}
	{}
\titlespacing*{\subsection}
	{0pt}
	{18pt}
	{0pt}

% Unnumbered subsection title
\titleformat{name=\subsection, numberless}[display]
	{\fontsize{13pt}{12pt}\selectfont\color{ffg_title_color}}
	{\quad #1}
	{0pt}
	{}
\titlespacing*{\subsection}
	{0pt}
	{18pt}
	{0pt}

 
% Numbered subsubsection title
\titleformat{\subsubsection}[display]
	{\fontsize{11pt}{12pt}\selectfont\color{ffg_title_color}}
	{\qquad \thesubsubsection \quad #1}
	{0pt}
	{}
\titlespacing*{\subsubsection}
	{0pt}
	{12pt}
	{-10pt}

% Unnumbered subsubsection title
\titleformat{name=\subsubsection, numberless}[display]
	{\fontsize{11pt}{12pt}\selectfont\color{ffg_title_color}}
	{\qquad #1}
	{0pt}
	{}
\titlespacing*{name=\subsubsection, numberless}
	{0pt}
	{12pt}
	{-10pt}

\makeatother

\pagestyle{plain}
\AtBeginDocument{
	\setcounter{secnumdepth}{3}
	\setcounter{tocdepth}{3}
	\AddToShipoutPicture*{\BackgroundPic}
}


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% Redefine Theoreme & Definition
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\renewenvironment{leftbar}[1][\hsize]
{
	\def\FrameCommand
	{
		{\color{ffg_title_color}\vrule width 3pt}
		\hspace{0pt}
	}
	\MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}
}
{\endMakeFramed}

\newtheoremstyle{new_theorem_style}
	{\topsep}			% space before \topsep
	{\topsep}			% space after\topsep
	{\itshape}			% body font
	{}					% indent
	{\bfseries}			% header font
	{}					% punctuation
	{\newline}			% after theorem header
	{\thmname{#1}~\thmnumber{#2}\thmnote{\ -\ #3}\\*[-1.5ex]}% header specification (empty for default)

\theoremstyle{new_theorem_style}
\newtheorem*{definitionT}{\color{ffg_title_color}{Définition}}
\newenvironment{definition}
{
	\begin{leftbar}
		\begin{definitionT}
			\mbox{}\noindent\ignorespaces}{
		\end{definitionT}
	\end{leftbar}
}


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% Define colorbox
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\newtcolorbox{knowledgebox}{colback=ffg_red!5!white, colframe=ffg_red!100!black, fonttitle=\bfseries, title={Savoir}, breakable} %breakable
\newtcolorbox{skillsbox}{colback=flyingblue!5!white, colframe=flyingblue!100!black, fonttitle=\bfseries, title={Savoir faire}, breakable} %breakable
\newtcolorbox{morebox}{colback=greymoreknowledge!5!white, colframe=greymoreknowledge!100!black, fonttitle=\bfseries, title={Allez plus loin\ldots}, breakable}
\newtcolorbox{dangerbox}[1]{colback=red!5!white, colframe=red!100!black, fonttitle=\bfseries, title={Important}, breakable} %breakable


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% References
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% http://www.liv.ac.uk/~maryrees/posterproduction/textpos.pdf
% http://latex-community.org/forum/viewtopic.php?f=4&t=23421
% http://www.grappa.univ-lille3.fr/FAQ-LaTeX/6.3.html
% https://www.overleaf.com/2177757tknnqv#/5555417/
% http://tutex.tug.org/pracjourn/2005-4/hefferon/hefferon.pdf
% http://tex.stackexchange.com/questions/528/style-class-tutorials