%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                               %
%    		 pas-exos.sty  V2       encodage : UTF8       	    %
%                                                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                               %
%           	Créé par Stéphane PASQUET 		          		%
%                                                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Informations générales
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pas-exos}[2017/06/10]

%% Compteurs d'exercices

\newcounter{nbexos}
\setcounter{nbexos}{\z@}

% Chargement des extensions ----------------------------------->
\RequirePackage[latin1]{inputenc}
\RequirePackage[frenchb]{babel}
\RequirePackage[T1]{fontenc}
\RequirePackage{textcomp}
\RequirePackage{etex}
\RequirePackage[margin=2cm]{geometry}
\RequirePackage[svgnames,table]{xcolor}
\RequirePackage{mathrsfs}
\RequirePackage[explicit]{titlesec}
\RequirePackage{fancyhdr}
\RequirePackage[np]{numprint}
\RequirePackage{enumitem}
\RequirePackage{multicol}
\RequirePackage{eurosym}
\RequirePackage{tabularx}
\RequirePackage{cellspace}
\setlength{\cellspacetoplimit}{3pt}
\setlength{\cellspacebottomlimit}{3pt}
\RequirePackage{pas-algo}
\RequirePackage{mathtools}
\RequirePackage{tkz-euclide}
\RequirePackage{tkz-fct}
\RequirePackage{tkz-tab}
\usetikzlibrary{decorations.pathmorphing,decorations.text}
\RequirePackage{pas-math}
\RequirePackage{cancel}
\RequirePackage{systeme}
\RequirePackage{ulem}
\RequirePackage{setspace}
\RequirePackage{xkeyval}
\RequirePackage{pifont}
\RequirePackage{mathptmx}
\RequirePackage{listingsutf8}
\lstset{%
	inputencoding=latin1,
	frame=single,
	basicstyle=\ttfamily,
	language=python,
	columns=flexible,
	keepspaces=true,
	upquote=true,
	commentstyle=\color{red},
	mathescape,
	breaklines=true,
	classoffset=0,
  	keywordstyle=\bfseries\color{violet}%,
  	%morekeywords={from,import}
}

% =============================================
%Import symbols from font cm without importing the whole package
% =============================================
\newcommand\imCMsym[4][\mathord]{%
  \DeclareFontFamily{U} {#2}{}
  \DeclareFontShape{U}{#2}{m}{n}{
    <-6> #25
    <6-7> #26
    <7-8> #27
    <8-9> #28
    <9-10> #29
    <10-12> #210
    <12-> #212}{}
  \DeclareSymbolFont{CM#2} {U} {#2}{m}{n}
  \DeclareMathSymbol{#4}{#1}{CM#2}{#3}
}
\newcommand\alsoimCMsym[4][\mathord]{\DeclareMathSymbol{#4}{#1}{CM#2}{#3}}

\imCMsym{cmmi}{124}{\CMjmath}
\imCMsym[\mathop]{cmsy}{113}{\CMamalg}
\imCMsym[\mathop]{cmex}{96}{\CMcoprod}
\alsoimCMsym[\mathop]{cmex}{97}{\CMbigcoprod}
\let\jmath\CMjmath

% Option --------------------------------------------->
\newif\if@source
\DeclareOption{source}{\@sourcetrue}
\ProcessOptions


% Couleurs ------------------------------------------->

\def\color@toc@chapter{violet}
\def\color@toc@section{purple}
\def\colorItem{white}
\def\colorItemBg{purple!40}
\def\colorExTitle{violet}
\definecolor{violet}{cmyk}{0.68,0.01,0,0.43}
\definecolor{vert}{cmyk}{0.17,0,0.17,0.07}
\definecolor{purple}{cmyk}{0.93,0.82,0,0.58}
\RequirePackage[colorlinks=true,urlcolor=violet,linkcolor=violet]{hyperref}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%% Tables des matières %%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setcounter{secnumdepth}{0}
\addto\captionsfrench{\renewcommand{\contentsname}{Sommaire}}

\newcommand{\parttoccolor}{\color@toc@section}
\newcommand{\chaptertoccolor}{\color@toc@chapter}
\newcommand{\sectiontoccolor}{\color@toc@section}

\renewcommand*\l@part[2]{%
  \ifnum\c@tocdepth>\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.9em}%
	\def\@linkcolor{\parttoccolor}
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      \fcolorbox{violet!30}{violet!30}{\begin{minipage}{\textwidth}\color{\parttoccolor}\mathversion{bold}\fontfamily{phv}\fontseries{b}\selectfont #1\strut\end{minipage}}\par
      \penalty\@highpenalty
    \endgroup
  \fi}

\renewcommand*\l@chapter[2]{%
  \ifnum\c@tocdepth>\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.9em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      \def\@linkcolor{\chaptertoccolor}%
      \color{\chaptertoccolor}{\mathversion{bold}\fontfamily{phv}\fontseries{b}\selectfont#1}\nobreak\
       \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfil\nobreak\hb@xt@\@pnumwidth{\hss
        \def\@linkcolor{\chaptertoccolor}%
        \color{\chaptertoccolor}#2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
  
\def\@dottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.9\p@
    {\leftskip #2\relax\rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil #5}%
     \par}%
  \fi}
  
\def\contentsline#1#2#3#4
{%
	\fontfamily{lmss}\selectfont
	\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*\l@section{\color{\sectiontoccolor}\def\@linkcolor{\sectiontoccolor}\@dottedtocline{1}{1pt}{3.5em}}

\pagestyle{fancy}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\headrulewidth}{0pt}
\lhead{}
\chead{}
\rhead{}
\cfoot{\fontfamily{lmss}\selectfont\color{purple}\thepage}
\setlength{\parindent}{0cm}


%<-------------- Définition des titres de section ----------------->

%-------------- PART --------------------->

\renewcommand*\part[1]
{%
\ifnum \c@secnumdepth >\m@ne
  \refstepcounter{part}%
  \addcontentsline{toc}{part}{#1}%
\else
  \addcontentsline{toc}{part}{#1}%
\fi
	\newgeometry{margin=0cm}
	\thispagestyle{fancy}
	\noindent
	\begin{tikzpicture}
		\clip (current page.south west) rectangle (current page.north east);
		% image de fond
		\node[above right,inner sep=0pt,outer sep=0pt] at (current page.south west) {\includegraphics[scale=1]{part.jpg}};
		% Date
		\node[text=white] at (current page.center) {\begin{minipage}{0.66\paperwidth}\fontfamily{lmss}\fontseries{b}\selectfont\Huge\partname\nobreakspace\thepart\\[1cm]#1\end{minipage}};
	\end{tikzpicture}
	\restoregeometry
}

%-------------- CHAPTER --------------------->

\renewcommand{\thechapter}{\@Roman\c@chapter}
\titleformat{\chapter} 
  {}
  {}{0pt}
  {%
  	\thispagestyle{fancy}
	\noindent
	\begin{tikzpicture}
		\fill[blue!20] (0,0) rectangle+(0.99\linewidth,-1.5cm);
		\fill[top color=blue!5,bottom color=white] (0,-1) rectangle +(0.99\linewidth,-5cm);
		\fill[violet] (12cm,0) rectangle +(4cm,-4.5cm);
		\fill[violet!80] (12cm,-4.5cm) rectangle+(0.5cm,0.5cm);
		\fill[violet!70] (12.5cm,-4.5cm) rectangle+(0.5cm,0.5cm);
		\fill[violet!60] (13cm,-4.5cm) rectangle+(0.5cm,0.5cm);
		\fill[violet!60] (12cm,-4cm) rectangle+(0.5cm,0.5cm);
		\fill[violet!50] (12.5cm,-4cm) rectangle+(0.5cm,0.5cm);
		\fill[violet!40] (12cm,-3.5cm) rectangle+(0.5cm,0.5cm);
		\fill[violet!40] (13.5cm,-4.5cm) rectangle+(0.5cm,0.5cm);
		\fill[vert] (12cm,-4.5cm) rectangle +(4cm,-1.5cm);
		\node[below] at (14cm,-0.5cm) 
		{%
			\begin{minipage}{4cm}
				\if@mainmatter
					\begin{center}
					\color{white}\fontfamily{lmss}\fontseries{b}\selectfont{\Large \'Enonc\'es}
					\end{center}
				\fi
			\end{minipage}
		};
		%
		% Titre
		%
		\node[below right] (titre) at (0.25cm,-1.5cm) 
		{%
			\begin{minipage}{11cm}
			\fontfamily{lmss}\fontseries{b}\selectfont\color{purple}\fontsize{24}{24}\selectfont #1
			\end{minipage}
		};
		\node[below right,text=purple] (url) at ($(titre.south west)+(0,-1em)$) {\fontfamily{lmss}\fontshape{it}\selectfont Disponible sur \url{http://www.mathweb.fr}};
		\if@mainmatter
			\node[below right,circle,fill=\colorExTitle,text=white,scale=0.5] (legendeA) at ($(url.south west)+(0,-1em)$) {\fontfamily{lmss}\fontseries{b}\selectfont A};
			\node[right,scale=0.8] at (legendeA.east) {\fontfamily{lmss}\selectfont Exercices d'application du cours};
			\node[below right,circle,fill=\colorExTitle,text=white,scale=0.5] (legendeR) at ($(url.south west)+(0,-2.5em)$) {\fontfamily{lmss}\fontseries{b}\selectfont R};
			\node[right,scale=0.8] at (legendeR.east) {\fontfamily{lmss}\selectfont Exercices de r\'eflexion};
			\node[below right,text=gray] (legendeV) at ($(url.south west)+(-0.15,-4em)$) {\large\ding{44}};
			\node[right,scale=0.8] at ($(legendeV.east)+(-0.1,0)$) {\fontfamily{lmss}\selectfont Exercice \& corrig\'e relus avec attention pour \'eviter les erreurs};
		\fi
		%
		% Date
		%
		\node at (14cm,-5.5cm) 
		{%
			\begin{minipage}{4cm}
			\begin{center}
			\fontfamily{lmss}\fontseries{b}\selectfont\color{black}\today
			\end{center}
			\end{minipage}
		};
	\end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{0pt}{-10pt}

% <------------- Exercice -------------------------->

\define@cmdkey [PAS] {exo}{N}{} % niveau (sur 5)
\define@cmdkey [PAS] {exo}{style}{} % Réflexion, application du cours, 
\define@boolkey[PAS] {exo} {verif}[true]{}
\presetkeys    [PAS] {exo} {style= , N= , verif=false}{}

\newcommand*{\exercice}[1][]{\pasexo[#1]}

\newcounter{numexos}[chapter]
\setcounter{numexos}{\z@}

\xdef\namefic{}

\long\def\pasexo[#1]#2{
    \setkeys[PAS]{exo}{#1}
    \stepcounter{nbexos}
	\stepcounter{numexos}
	\addcontentsline{toc}{section}{\thechapter.\thenumexos~~#2}
	\ifnum\thenumexos>1\par\bigskip\fi
	\ifPAS@exo@verif
		\def\symb@verif{\large\color{gray}\,\ding{44}}
	\else
		\def\symb@verif{}
	\fi
	\begingroup
	\label{\thechapter-\thenumexos}
	\color{\colorExTitle}
	{\small\hyperref[toc]{\color{\colorExTitle}$\blacksquare$}}~\fontfamily{lmss}\fontseries{b}\selectfont Exercice \thenumexos. #2\strut\hfill
	\ifnum\cmdPAS@exo@N=1\ding{72}\ding{73}\ding{73}\ding{73}\ding{73}\fi
	\ifnum\cmdPAS@exo@N=2\ding{72}\ding{72}\ding{73}\ding{73}\ding{73}\fi
	\ifnum\cmdPAS@exo@N=3\ding{72}\ding{72}\ding{72}\ding{73}\ding{73}\fi
	\ifnum\cmdPAS@exo@N=4\ding{72}\ding{72}\ding{72}\ding{72}\ding{73}\fi
	\ifnum\cmdPAS@exo@N=5\ding{72}\ding{72}\ding{72}\ding{72}\ding{72}\fi	
	\enspace
	\tikz\node[circle,fill=\colorExTitle,text=white,scale=0.5] {\fontfamily{lmss}\fontseries{b}\selectfont\cmdPAS@exo@style};
	\par\begingroup\if@source\ifx\namefic\@empty\else\small\fontseries{n}\selectfont\color{gray}(Source : \namefic\numsrc)\fi\fi\endgroup\hfill\scalebox{0.75}{\tikz\node[rectangle,rounded corners=3pt,draw,outer ysep=3pt,outer xsep=0pt,inner sep=3pt] {Corrig\'e page \pageref{corr-\thechapter-\thenumexos}\symb@verif};}%
	\endgroup
	\vskip0.5em
}

% Titre de la correction

\newcommand*\correction
{%
	\newpage
	\begin{tikzpicture}
\fill[blue!20] (0,0) rectangle+(\textwidth,-1.5cm);
\fill[top color=blue!5,bottom color=white] (0,-1) rectangle +(\textwidth,-5cm);
\fill[violet] (12cm,0) rectangle +(4cm,-4.5cm);
\fill[violet!80] (12cm,-4.5cm) rectangle+(0.5cm,0.5cm);
\fill[violet!70] (12.5cm,-4.5cm) rectangle+(0.5cm,0.5cm);
\fill[violet!60] (13cm,-4.5cm) rectangle+(0.5cm,0.5cm);
\fill[violet!60] (12cm,-4cm) rectangle+(0.5cm,0.5cm);
\fill[violet!50] (12.5cm,-4cm) rectangle+(0.5cm,0.5cm);
\fill[violet!40] (12cm,-3.5cm) rectangle+(0.5cm,0.5cm);
\fill[violet!40] (13.5cm,-4.5cm) rectangle+(0.5cm,0.5cm);
\fill[vert] (12cm,-4.5cm) rectangle +(4cm,-1.5cm);
\node[below] at (14cm,-0.5cm) {%
\begin{minipage}{4cm}
\if@mainmatter
\begin{center}
\color{white}\fontfamily{lmss}\fontseries{b}\selectfont{\Large Corrig\'es}
\end{center}
\fi
\end{minipage}
};
% Titre
\node[below right] (titre) at (0.25cm,-1.5cm) {%
\begin{minipage}{11cm}
\fontfamily{lmss}\fontseries{b}\selectfont\color{purple}\Huge
\end{minipage}
};
% Date
\node at (14cm,-5.5cm) {%
\begin{minipage}{4cm}
\begin{center}
\fontfamily{lmss}\fontseries{b}\selectfont\color{black}\today
\end{center}
\end{minipage}
};
\end{tikzpicture}
	\setcounter{numexos}{\z@}
}

\newcommand*\corrige
{%
	\refstepcounter{numexos}
	\par
	\ifnum\thenumexos>1\bigskip\fi
	\begingroup
	\color{\colorExTitle}
	{\small\hyperref[toc]{\color{\colorExTitle}$\blacksquare$}}~\fontfamily{lmss}\fontseries{b}\selectfont Corrig\'e de l'exercice \thenumexos.\label{corr-\thechapter-\thenumexos}\hfill{\small\hyperref[\thechapter-\thenumexos]{[Retour \`a l'\'enonc\'e de l'exercice]}}
	\endgroup
}

% multicolonne

\setlength{\columnseprule}{0pt}
\setlength{\columnsep}{1em}

% Listes

\setlength{\itemindent}{0pt}
\setlist[itemize,1]{label={\color{\colorItemBg}\textbullet}}
\setlist[itemize,2]{label={\color{\colorItemBg}$\rightarrow$}}
\setlist[enumerate,1]
	{%
		label=\fcolorbox{\colorItemBg}
		{\colorItemBg}
		{\color{\colorItem}\normalsize\bfseries\arabic*},
		leftmargin=7mm
	}
\setlist[enumerate,2]
	{%
	  label=\textcolor{purple}{\normalsize$\alph*.$},
	  leftmargin=7mm
	}

% Partie

\newcommand{\partie}[1]{%
\begin{center}
\fontfamily{lmss}
\fontseries{b}
\selectfont
\color{purple}
Partie~#1
\end{center}%
}


%% Sectionnn

\newcommand{\sectionnn}[1]{\vspace*{1cm}\begingroup\fontfamily{lmss}\fontsize{14}{12}\bfseries\color{purple}\selectfont#1\endgroup\vskip1em}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%% Page de garde %%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\subtitle}[1]{\def\@subtitle{#1}}
\renewcommand{\maketitle}
{%
\newpage
\newgeometry{margin=0cm}
\noindent
\begin{tikzpicture}
\clip (current page.south west) rectangle (current page.north east);
% image de fond
\node[above right,inner sep=0pt,outer sep=0pt] at ($(current page.south west)+(-1em,-1em)$) {\includegraphics[scale=1.1]{pasExosCouv.jpg}};
% Date
\fill[black,opacity=0.7] ($(current page.south east)+(0,0.8)$) -- 
				($(current page.south east)+(-7.4,0.8)$) -- 
				($(current page.south east)+(-6.4,1.8)$) -- 
				($(current page.south east)+(0,1.8)$) -- cycle;
\fill[violet] ($(current page.south east)+(0,1)$) -- 
				($(current page.south east)+(-7,1)$) -- 
				($(current page.south east)+(-6,2)$) -- 
				($(current page.south east)+(0,2)$) -- cycle;
\node[text=white,inner ysep=5mm,left] (collection) at ($(current page.south east)+(0,1.4)$) {\fontfamily{lmss}\fontseries{b}\selectfont\Large\@date};
% Collection
\fill[gray,opacity=0.7] ($(current page.north west)+(0,-1.2)$) -- 
				($(current page.north east)+(-2.8,-1.2)$) -- 
				($(current page.north east)+(-3.8,-3.2)$) -- 
				($(current page.north west)+(0,-3.2)$) -- cycle;
\fill[black] ($(current page.north west)+(0,-1)$) -- 
				($(current page.north east)+(-3,-1)$) -- 
				($(current page.north east)+(-4,-3)$) -- 
				($(current page.north west)+(0,-3)$) -- cycle;
\node[text=white, inner ysep=5mm, right] at ($(current page.north west)+(0,-2)$) {\fontfamily{lmss}\fontseries{b}\fontsize{40}{40}\selectfont Disponible sur \textit{mathweb.fr}};
% Titre
\node[text=gray, text width=0.8\linewidth, opacity=0.7,below right] at ($(current page.north west)+(2,-5)+(0.1,-0.1)$) {\bfseries\fontfamily{pb6}\fontsize{40}{40}\selectfont\bfseries\@title};
\node[text=yellow!50!white, text width=0.8\linewidth,below right] (titre) at ($(current page.north west)+(2,-5)$) {\bfseries\fontfamily{pb6}\fontsize{40}{40}\selectfont\bfseries\@title};

% Sous-Titre
\ifx\@subtitle\@empty\else
\node[text=white,fill=black,below right, inner sep=1em,rounded corners=2em] (soustitre) at ($(titre.south west)+(0,-3)$) {\bfseries\fontfamily{pb6}\fontsize{26}{28}\selectfont\bfseries\@subtitle};
\fi

% Auteur
\node[text=white,xscale=1.3,yscale=2,opacity=0.2] at ($(current page.south west)+(5,5)+(0.1,-0.1)$) {\bfseries\fontfamily{pb6}\selectfont\huge \@author};
\node[text=yellow!50!white] at ($(current page.south west)+(5,5)$) {\bfseries\fontfamily{pb6}\selectfont\huge \@author};
\end{tikzpicture}
\restoregeometry
}
\endinput
