% Fichier comprenant les macros de styles

\newcounter{cnt@chap}
\newcounter{cnt@prop}
\newcounter{cnt@thm}
\newcounter{cnt@defi}
\newcounter{cnt@rem}
\newcounter{cnt@act}
\newcounter{cnt@nota}
\newcounter{cnt@ex}
\newcounter{cnt@demo}

% \env : environnement de couleurs
% Syntaxe : \env[style=nom de l'environnement,pluriel (option)]{texte}

\define@cmdkey [PAS] {env} {style}{}
\define@cmdkey [PAS] {env} {name}{}
\define@cmdkey [PAS] {env} {color}{}
\define@cmdkey [PAS] {env} {title}{}
\define@cmdkey [PAS] {env} {symb}{}
\define@boolkey[PAS] {env} {num}[true]{} % ajout du 19/08/2014
\define@boolkey[PAS] {env} {toc}[true]{} 
\define@boolkey[PAS] {env} {notoc}[true]{} 
\define@boolkey[PAS] {env} {pluriel}[true]{} 
\define@boolkey[PAS] {env} {endsymb}[true]{} 
\define@boolkey[PAS] {env} {degrade}[true]{} 
\define@boolkey[PAS] {env} {notitle}[true]{} 
\define@boolkey[PAS] {env} {notitlebreak}[true]{}
\presetkeys    [PAS] {env} {style= , name= , title= ,pluriel = false, color=, symb = $\blacksquare$, degrade = false, toc=false, notoc=false, notitle=false, notitlebreak=false, endsymb=false, num=false}{}

\newcommand*{\env}[1][]{\pasEnv[#1]}

\long\def\pasEnv[#1]#2{
   \setkeys[PAS]{env}{#1}
	\if@everytoc
   	\ifx\cmdPAS@env@name\@empty
   	\else
   		\ifPAS@env@notoc
   		\else
				\phantomsection
				\addcontentsline{toc}{section}{\cmdPAS@env@name}
			\fi
   	\fi
   \else
		\ifPAS@env@toc
			\phantomsection
			\addcontentsline{toc}{section}{\cmdPAS@env@name}
		\fi
	\fi
	%
   \IfStrEq{\cmdPAS@env@style}{prop}
   {%
   \ifPAS@env@pluriel
   	\def\texte{Propri\'et\'es}
   \else
   	\def\texte{Propri\'et\'e}
   \fi
   \ifPAS@env@num
   	\stepcounter{cnt@prop}
   	\edef\texte{\texte~\thecnt@prop}
   \fi
   \def\couleur{red}%
   }{}
   \IfStrEq{\cmdPAS@env@style}{demo}
   {%
   \ifPAS@env@pluriel
   	\def\texte{D\'emonstrations}
   \else
   	\def\texte{D\'emonstration}
   \fi
    \ifPAS@env@num
   	\stepcounter{cnt@demo}
   	\edef\texte{\texte~\thecnt@demo}
   \fi
   \def\couleur{black}%
   }{}
   \IfStrEq{\cmdPAS@env@style}{rem}{\ifPAS@env@pluriel\def\texte{Remarques}\else\def\texte{Remarque}\fi\def\couleur{rem}}{}
   \IfStrEq{\cmdPAS@env@style}{defi}
	{%
		\ifPAS@env@pluriel
			\def\texte{D\'efinitions}
		\else
			\def\texte{D\'efinition}
		\fi
		\ifPAS@env@num
   		\stepcounter{cnt@defi}
   		\edef\texte{\texte~\thecnt@defi}
   	\fi
		\def\couleur{defi}
	}{}
	\IfStrEq{\cmdPAS@env@style}{thm}{\ifPAS@env@pluriel\def\texte{Th\'eor\`emes}\else\def\texte{Th\'eor\`eme}\fi\ifPAS@env@num\stepcounter{cnt@thm}\edef\texte{\texte~\thecnt@thm}\fi\def\couleur{thm}}{}
   \IfStrEq{\cmdPAS@env@style}{ex}{\ifPAS@env@pluriel\def\texte{Exemples}\else\def\texte{Exemple}\fi \ifPAS@env@num\stepcounter{cnt@ex}\edef\texte{\texte~\thecnt@ex}\fi\def\couleur{ex}}{}
   \IfStrEq{\cmdPAS@env@style}{nota}{\ifPAS@env@pluriel\def\texte{Notations}\else\def\texte{Notation}\fi \ifPAS@env@num\stepcounter{cnt@nota}\edef\texte{\texte~\thecnt@nota}\fi\def\couleur{nota}}{}
   \IfStrEq{\cmdPAS@env@style}{act}{\ifPAS@env@pluriel\def\texte{Activit\'es}\else\def\texte{Activit\'e}\fi \ifPAS@env@num\stepcounter{cnt@act}\edef\texte{\texte~\thecnt@act}\fi\def\couleur{orange}}{}
	\IfStrEq{\cmdPAS@env@style}{meth}{\ifPAS@env@pluriel\def\texte{M\'ethodes}\else\def\texte{M\'ethode}\fi \ifPAS@env@num\stepcounter{cnt@meth}\edef\texte{\texte~\thecnt@meth}\fi\def\couleur{brown}}{}
	\IfStrEq{\cmdPAS@env@title}{}{}{\def\texte{\cmdPAS@env@title}}
	\IfStrEq{\cmdPAS@env@color}{}{}{\def\couleur{\cmdPAS@env@color}}
	\ifPAS@env@degrade
		\tikzstyle{noeud} = [rectangle,inner ysep=10pt, inner xsep=5pt, fill=\couleur!10,path fading=east]
	\else
		\tikzstyle{noeud} = [rectangle,inner ysep=10pt, inner ysep=5pt, fill=\couleur!10]
	\fi
	\itemclass{\couleur}
   \noindent
   \begin{tikzpicture}
   	\node [noeud] (box)
   	{%
      	\begin{minipage}{\dimexpr\textwidth-40pt}
			\itshape #2
			\ifPAS@env@endsymb
				\hfill \cmdPAS@env@symb
			\fi
      	\end{minipage}
   	};
   	\ifPAS@env@notitle\else
   		\node[text=white,fill=\couleur,rectangle, shading=ball, ball color=\couleur, above right] (title) at ($(box.north west)+(-0.03,0)$)
   		{\kern-3pt\begin{ant}\textbf{\texte}\end{ant}};
   	\fi
   	\draw[color=\couleur!50!black,very thick] (box.north west)--(box.south west)--(box.south east);
   	\node[left,color=\couleur] at (box.north east) {\emph{\cmdPAS@env@name}};
   \end{tikzpicture}   
   \vspace{0.5cm}
}

% Environnement "pasbox"

\newsavebox{\pas@box}
%
\newcounter{suite@box}
\newenvironment*{pasbox}[1][]
{%
   \setcounter{suite@box}{0}
   \setkeys[PAS]{env}{#1}
   \if@everytoc
   	\ifx\cmdPAS@env@name\@empty\else
   		\ifPAS@env@notoc\else
				\phantomsection
				\addcontentsline{toc}{section}{\cmdPAS@env@name}
			\fi
   	\fi
   \else
		\ifPAS@env@toc
			\phantomsection
			\addcontentsline{toc}{section}{\cmdPAS@env@name}
		\fi
	\fi
	\IfStrEq{\cmdPAS@env@style}{thm}
   {%
   	\ifPAS@env@pluriel
   		\def\texte{Th\'eor\`emes}
   	\else
   		\def\texte{Th\'eor\`eme}
   	\fi
   	 \ifPAS@env@num
   	\stepcounter{cnt@thm}
   	\edef\texte{\texte~\thecnt@thm}
   \fi
   	\def\couleur{thm}
   }{}
   \IfStrEq{\cmdPAS@env@style}{demo}
   {%
   	\ifPAS@env@pluriel
   		\def\texte{D\'emonstrations}
   	\else
   		\def\texte{D\'emonstration}
   	\fi
   	 \ifPAS@env@num
   	\stepcounter{cnt@dem}
   	\edef\texte{\texte~\thecnt@dem}
   \fi
   	\def\couleur{black}
   }{}
   \IfStrEq{\cmdPAS@env@style}{prop}
   {%
   	\ifPAS@env@pluriel
   		\def\texte{Propri\'et\'es}
   	\else
   		\def\texte{Propri\'et\'e}
   	\fi
   	 \ifPAS@env@num
   	\stepcounter{cnt@prop}
   	\edef\texte{\texte~\thecnt@prop}
   \fi
   	\def\couleur{red}
   }{}
   \IfStrEq{\cmdPAS@env@style}{rem}
   {%
   	\ifPAS@env@pluriel
   		\def\texte{Remarques}
   	\else
   		\def\texte{Remarque}
   	\fi
   	 \ifPAS@env@num
   	\stepcounter{cnt@rem}
   	\edef\texte{\texte~\thecnt@rem}
   \fi
   	\def\couleur{rem}
   }{}
   \IfStrEq{\cmdPAS@env@style}{defi}
	{%
	 \ifPAS@env@pluriel
		\def\texte{D\'efinitions}
	 \else
		\def\texte{D\'efinition}
	 \fi
	  \ifPAS@env@num
   	\stepcounter{cnt@defi}
   	\edef\texte{\texte~\thecnt@defi}
   \fi
	 \def\couleur{defi}
	}{}
   	\IfStrEq{\cmdPAS@env@style}{ex}
   	{%
   	 \ifPAS@env@pluriel
   	 	\def\texte{Exemples}
   	 \else
   	 	\def\texte{Exemple}
   	 \fi
   	  \ifPAS@env@num
   	\stepcounter{cnt@ex}
   	\edef\texte{\texte~\thecnt@ex}
   \fi
   	 \def\couleur{ex}
   	}{}
   	\IfStrEq{\cmdPAS@env@style}{nota}
   	{%
   	\ifPAS@env@pluriel
   	\def\texte{Notations}
   	\else
   	\def\texte{Notation}
   	\fi
   	 \ifPAS@env@num
   	\stepcounter{cnt@nota}
   	\edef\texte{\texte~\thecnt@nota}
   \fi
   	\def\couleur{nota}
   	}{}
   	\IfStrEq{\cmdPAS@env@style}{act}
   	{%
   		\ifPAS@env@pluriel
   			\def\texte{Activit\'es}
   		\else
   			\def\texte{Activit\'e}
   		\fi
   		 \ifPAS@env@num
   	\stepcounter{cnt@act}
   	\edef\texte{\texte~\thecnt@act}
   \fi
   		\def\couleur{orange}
   	}{}
	\IfStrEq{\cmdPAS@env@style}{meth}
	{%
		\ifPAS@env@pluriel
			\def\texte{M\'ethodes}
		\else
			\def\texte{M\'ethode}
		\fi
		 \ifPAS@env@num
   	\stepcounter{cnt@meth}
   	\edef\texte{\texte~\thecnt@meth}
   \fi
		\def\couleur{brown}
	}{}
	\IfStrEq{\cmdPAS@env@title}{}{}{\def\texte{\cmdPAS@env@title}}
	\IfStrEq{\cmdPAS@env@color}{}{}{\def\couleur{\cmdPAS@env@color}}
	\ifPAS@env@degrade
		\tikzstyle{noeud} = [rectangle,inner ysep=10pt, inner xsep=5pt, fill=\couleur!10,path fading=east,outer sep=0pt]
	\else
		\tikzstyle{noeud} = [rectangle,inner ysep=10pt, inner xsep=5pt, fill=\couleur!10,outer sep=0pt]
	\fi
	\itemclass{\couleur}
	\begin{lrbox}{\pas@box}
		\begin{minipage}{\dimexpr\linewidth-\parindent-14pt}
}
{
		\ifPAS@env@endsymb
			\hfill \cmdPAS@env@symb
		\fi
    		\end{minipage}
	\end{lrbox}
	\begin{tikzpicture}
   	\node [noeud] (box)
   	{%
		\usebox{\pas@box}
   	};
   	\ifnum\thesuite@box=1
   		\edef\texte{\texte~(suite)}
   		\ifPAS@env@notitlebreak\else\ifPAS@env@notitle\else
   			\node[text=white,fill=\couleur,rectangle, shading=ball, ball color=\couleur, above right] (title) at ($(box.north west)+(-0.03,0)$)
   			{\begin{ant}\kern-3pt\texte\end{ant}};
   		\fi\fi
   	\else
   		\ifPAS@env@notitle\else
   			\node[text=white,fill=\couleur,rectangle, shading=ball, ball color=\couleur, above right] (title) at ($(box.north west)+(-0.03,0)$)
   			{\kern-3pt\begin{ant}\texte\end{ant}};
   		\fi
   	\fi
   		\draw[color=\couleur!50!black,very thick] (box.north west)--(box.south west)--(box.south east);
   		\node[left,color=\couleur] at ($(box.north east)+(0,1pt)$) {\emph{\cmdPAS@env@name}};
   		\end{tikzpicture}   
   		\vspace{0.5cm}
}

% \breakbox

\newcommand*{\breakbox}
{%
	\end{minipage}
	\end{lrbox}
	\stepcounter{suite@box}
	\begin{tikzpicture}
   	\node [noeud] (box)
   	{%
		\usebox{\pas@box}
   	};
   	\ifPAS@env@notitle\else
   	\node[text=white,fill=\couleur,rectangle, shading=ball, ball color=\couleur, above right] (title) at ($(box.north west)+(-0.03,0)$)
   		{\begin{ant}\textbf{\texte}\end{ant}};
   	\fi
   		\draw[color=\couleur!50!black,very thick] (box.north west)--(box.south west)--(box.south east);
   		\node[left,color=\couleur] at (box.north east) {\emph{\cmdPAS@env@name}};
   		\node[rounded corners=3pt,draw=\couleur!50!black,very thick,left,fill=white] at ($(box.south east)+(-0.5,0)$) {...};
   	\end{tikzpicture}\par 
   	\begin{lrbox}{\pas@box} 
   		\begin{minipage}{\dimexpr\linewidth-\parindent-14pt}
}

%%%%%%%%%% définition du titre

\newlength\pas@titlelinewidth

\define@cmdkey [PAS] {chap} {num}{}
\define@cmdkey [PAS] {chap} {color}{}
\define@cmdkey [PAS] {chap} {pos}{}
\define@boolkey[PAS] {chap} {autonum}[true]{} 
\presetkeys    [PAS] {chap} {num = ,
 							 color = red,
 							 pos = right,
							 autonum = false}{} % maj 19/08/2014

\newcommand*{\chap}[1][]{\pasChap[#1]}

\def\pasChap[#1]#2#3{
   \setkeys[PAS]{chap}{#1}
   \setcounter{cnt@chap}{0}
   \ifPAS@chap@autonum\stepcounter{cnt@chap}\def\titre@chapitre{\thecnt@chap}\else\def\titre@chapitre{\cmdPAS@chap@num} \clearpage \fi
   \IfStrEq{\cmdPAS@chap@pos}{right}
      { \tikzstyle{pastitrepos} = [text=\cmdPAS@chap@color,rectangle,left]
        \tikzstyle{pastrait} = [right color=\cmdPAS@chap@color, left color=white,thick]
        \tikzstyle{passstitre} = [\cmdPAS@chap@color,left,scale=0.5]
        \setlength{\pas@titlelinewidth}{\dimexpr2cm-\linewidth}
        \def\PASpos{box.north west}
        \def\PAStrait{box.west}
        \def\PASsstitre{box.south west}
        \def\PAStitrealign{flushright}
      }
      { \tikzstyle{pastitrepos} = [text=\cmdPAS@chap@color,rectangle,right]
        \tikzstyle{pastrait} = [left color=\cmdPAS@chap@color, right color=white,thick]
        \tikzstyle{passstitre} = [\cmdPAS@chap@color,right,scale=0.5]
        \setlength{\pas@titlelinewidth}{\dimexpr\linewidth-2cm}
        \def\PASpos{box.north east}   
        \def\PAStrait{box.east}  
        \def\PASsstitre{box.south east}
        \def\PAStitrealign{flushleft}
      }
   \noindent
   \begin{\PAStitrealign}
   \begin{tikzpicture}
   % Le numero de chapitre
   \node[fill=\cmdPAS@chap@color, shading=ball, ball color=\cmdPAS@chap@color, very thick,circle, inner xsep=5pt, inner ysep=2pt] (box) at (0,0) {\kern-5pt\begin{Large}\textcolor{white}{\begin{ant}\textbf{\titre@chapitre}\end{ant}}\end{Large}};
   % le titre
   \node[pastitrepos] at (\PASpos) {\begin{minipage}{\dimexpr\textwidth-2cm}\begin{\PAStitrealign} \begin{Large}\textcolor{\cmdPAS@chap@color}{ \begin{ant} #2 \end{ant}}\end{Large} \end{\PAStitrealign} \end{minipage}};
   % la ligne
   \shade[pastrait] (\PAStrait) rectangle +(\pas@titlelinewidth,-0.01);
   % le sous-titre
   \node[passstitre] at (\PASsstitre) {\begin{ant}#3\end{ant}};
   \end{tikzpicture}
   \end{\PAStitrealign}
}

%%%%%%%%%%%% Définition d'un mot

\newcommand{\definmot}[1]{\texttt{\textbf{\textcolor{\couleur}{#1}}}}

% Itemclass

\newcommand{\itemclass}[1] % #1 = couleur
{
	\setlist[itemize,1]{label={\color{#1!50!black}\textbullet}}
	\setlist[itemize,2]{label={\color{#1!50!black}$\rightarrow$}}
	\setlist[enumerate,1]
	{%
		label=\fcolorbox{#1!50!black}
		{#1!50!black}
		{\color{#1!20}\normalsize\bfseries\arabic*}
	}
	\setlist[enumerate,2]{label=\textcolor{#1!50!black}{\normalsize\bfseries\alph*.}}
}
\itemclass{black}{}

%%%%%%%%%%%% Pour le sommaire

\renewcommand*\l@section{\color{blue!50!black}\def\@linkcolor{blue!50!black}\@dottedtocline{1}{1em}{2.3em}}
\def\contentsline#1#2#3#4{%
  \ifx\\#4\\%
    \csname l@#1\endcsname{#2}{#3}%
  \else
      \csname l@#1\endcsname{\hyper@linkstart{link}{#4}{#2}\hyper@linkend}{%
        \hyper@linkstart{link}{#4}{#3}\hyper@linkend
      }%
  \fi
}
\renewcommand{\contentsname}{\color{purple}\titreFONT\huge Sommaire}

%%%%%%%%%%% FONTES

\def\titreFONT{\fontfamily{phv}\fontseries{bx}\selectfont} % pb6
\def\tocFONT{\fontfamily{phv}\fontseries{m}\selectfont}

%%%%%%%%%%% PREREQUIS

\newsavebox{\prerequisBox}
\newsavebox{\imgPrerequis}
\newlength{\largeurimgPrerequis}

\newenvironment{prerequis}
{%
	\begin{lrbox}{\imgPrerequis}
	\includegraphics[scale=0.25]{prerequis.png}
	\end{lrbox}
	\settowidth{\largeurimgPrerequis}{\usebox{\imgPrerequis}}%
	\begin{lrbox}{\prerequisBox}
	\begin{minipage}{\dimexpr\textwidth-0.5\largeurimgPrerequis-15pt}
	\begin{itemize}[leftmargin=1em,label={\color{purple}$\bullet$}]
	\tocFONT
}
{%
	\end{itemize}
	\end{minipage}
	\end{lrbox}
	\begin{tikzpicture}
	\node (titre) {\includegraphics[scale=0.25]{prerequis.png}};
	\node[below right,text=purple] at (titre.north east) {\titreFONT\huge Pr\'erequis};
	\node[below right] (contenu) at (titre.south) {\usebox{\prerequisBox}};
	\draw[purple,very thick] (contenu.north west) -- (contenu.south west);
	\end{tikzpicture}
}

%%%%%%%%%%%%%%% A RETENIR
\newsavebox{\imageBox}
\newlength{\largeurimageBox}
\newsavebox{\aretenirBox}
\newenvironment{aretenir}[1][1]
{%
\def\sc{#1}
\begin{lrbox}{\imageBox}
\includegraphics[scale=\sc]{coeur.png}
\end{lrbox}
\settowidth{\largeurimageBox}{\usebox{\imageBox}}%
\begin{lrbox}{\aretenirBox}
\begin{minipage}{\dimexpr\linewidth-\largeurimageBox-1em-10pt}
}
{%
\end{minipage}
\end{lrbox}
\begin{tikzpicture}
\node[below right,rounded corners,very thick,draw=red!60!black] (box) {\usebox{\aretenirBox}};
\node[below left] at ($(box.north west)+(0,0.8em)$) {\includegraphics[scale=\sc]{coeur.png}};
\end{tikzpicture}
\vspace*{2em}
}

%%%%%%%%%%%%%%%%%% ATTENTION

\newsavebox{\attentionBox}

\newenvironment{attention}[1][1]
{%
\def\sc{#1}
\begin{lrbox}{\imageBox}
\includegraphics[scale=\sc]{attention.png}
\end{lrbox}
\settowidth{\largeurimageBox}{\usebox{\imageBox}}%
\begin{lrbox}{\attentionBox}
\begin{minipage}{\dimexpr\linewidth-\largeurimageBox-1em-10pt}
}
{%
\end{minipage}
\end{lrbox}
\begin{tikzpicture}
\node[below right,rounded corners,very thick,draw=red!60!black] (box) {\usebox{\attentionBox}};
\node[below left] at ($(box.north west)+(0,0.8em)$) {\includegraphics[scale=\sc]{attention.png}};
\end{tikzpicture}
\vspace*{2em}
}

%%%%%%%%%%%%%%%% BONUS

\newcounter{bonus}
\newcommand*{\bonus}{\@ifstar{\bonus@star}{\bonus@nostar}}
\newcommand*\bonus@star[1]{%
\newpage
\begingroup
\fontfamily{phv}\fontseries{bx}\fontsize{16}{14}\selectfont
\color{blue!40!black}Compl\'ement \thebonus : #1
\endgroup
\vspace*{1em}
}
\newcommand*\bonus@nostar[1]{%
\stepcounter{bonus}
\newpage
\phantomsection
\addcontentsline{toc}{section}{Compl\'ement \thebonus : #1}
\begingroup
\fontfamily{phv}\fontseries{bx}\fontsize{16}{14}\selectfont
\color{blue!40!black}Compl\'ement \thebonus : #1
\endgroup
\vspace*{1em}
}
