\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{PresentationArticle}[2011/05/24 Mise en forme cours et exercices L.F.B.]

\newif\ifop@rectoverso
\op@rectoversofalse

\DeclareOption{twoside}{\op@rectoversotrue}
\DeclareOption*{}
\ProcessOptions

\newcommand{\op@annee}{2015/2016}

\RequirePackage{calc,ifthen}
\RequirePackage{etoolbox}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% Couleurs %%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[svgnames,table]{xcolor}

%%%%%%%%%%%%%%%% "Thèmes" %%%%%%%%%%%%%%%%%%%%%%

 \colorlet{LFBcouleur1}{blue!80!black}
 \colorlet{LFBcouleur2}{purple}
% \colorlet{LFBcouleur3}{Green!80!Yellow}
 \colorlet{LFBcouleur3}{gray!40}
 \colorlet{LFBcouleur4}{blue!25!black!20}
 \colorlet{LFBcouleur5}{black!70!blue}
 \colorlet{LFBcouleur6}{black}


%%%%%%%%%%%%% Couleurs éléments %%%%%%%%%%%%%%%

 \colorlet{LFBcoulentete}{LFBcouleur3}
 \colorlet{LFBcoulpied}{LFBcouleur3}
 \colorlet{LFBcoulnumexos}{LFBcouleur5}
 \colorlet{LFBcoulrule}{LFBcouleur5}
 \colorlet{LFBcoulsection}{LFBcouleur1}
 \colorlet{LFBcoultable1}{LFBcouleur4}
 \colorlet{LFBcoultable2}{LFBcouleur3}
 \colorlet{LFBcoultheo}{LFBcouleur4}
 \colorlet{LFBcouldef}{LFBcouleur3}
 \colorlet{opcoultexte}{LFBcouleur6}

%%%%%%%%%%%% Format page %%%%%%%%%%%%%%%%%%
\@ifpackageloaded{geometry}%
         {}
         {\RequirePackage{geometry}
          %\geometry{a4paper,hmargin=2cm,top=0cm,bottom=1cm,headheight=1.5cm,includehead,includefoot}
          \geometry{a4paper,hmargin=2cm,top=0.7cm,bottom=1.5cm,headheight=3.5ex,includehead,includefoot}}

\setlength{\parindent}{0pt}





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%% Graphiques %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{graphicx}
\RequirePackage{ifpdf}
 \ifpdf
   \DeclareGraphicsRule{*}{mps}{*}{}
 \fi




\RequirePackage{fancyhdr}
\RequirePackage{titlesec}


  %%%%%%%%%%%%% En-Tête et pieds de page %%%%%%%%%%%%%%%%%%
  
  

%définitions en-têtes et pieds de page
  \pagestyle{fancy}
  \fancyhf{}
  \renewcommand{\headrulewidth}{0pt}

\newcommand{\op@boiteentete}{\makebox[0pt][l]{\hspace*{-3ex}%
                                 \color{LFBcouleur3}\rule[-0.8ex]{\linewidth+6ex}{3ex}}}

\ifop@rectoverso
  \fancyhead[LO]{%
                \op@boiteentete%
                \color{LFBcouleur5}\small\scshape\op@entete}
  \fancyhead[RO]{\color{LFBcouleur5}\small\scshape\op@titre}
  \fancyhead[LE]{%
                \op@boiteentete%
                \color{LFBcouleur5}\small\scshape\op@titre}
  \fancyhead[RE]{\color{LFBcouleur5}\small\scshape\op@entete}
  \fancyfoot[RO,LE]{\color{LFBcouleur5}\thepage}
  \fancyfoot[RE,LO]{\color{LFBcouleur5}\scriptsize\op@classe{} -- \op@annee}
\else
  \fancyhead[L]{%
                \op@boiteentete%
                \color{LFBcouleur5}\small\scshape\op@titre%
               }
  \fancyhead[R]{\color{LFBcouleur5}\small\scshape\op@entete}
  \fancyfoot[R]{\color{LFBcouleur5}\thepage}
  \fancyfoot[L]{\color{LFBcouleur5}\scriptsize\op@classe{} -- \op@annee}
\fi

% pages de titre
  \fancypagestyle{plain}{% 
          \fancyhf{}
          \ifop@rectoverso
               \fancyfoot[RO,LE]{\color{LFBcouleur5}\thepage}
               \fancyfoot[RE,LO]{\color{LFBcouleur5}\scriptsize\op@classe{} -- \op@annee}
          \else
               \fancyfoot[R]{\color{LFBcouleur5}\thepage}
               \fancyfoot[L]{\color{LFBcouleur5}\scriptsize\op@classe{} -- \op@annee}
          \fi
          }


%%%%%%%%%%%% Titre des documents
\newcommand{\op@entete}{}
\newcommand{\op@soustitre}{}
\newcommand{\op@classe}{}
\newcommand{\op@typedoc}{}
\newcommand{\op@numero}{}
\newcommand{\op@titre}{}
\newcommand{\op@duree}{}

\newcommand{\soustitre}[1]{\renewcommand{\op@soustitre}{#1}}

\newcommand{\classe}[1]{\renewcommand{\op@classe}{#1}}
\newcommand{\typedoc}[2]{\renewcommand{\op@typedoc}{#1}
%                         \renewcommand{\op@titre}{#1}
                         \renewcommand{\op@soustitre}{\op@classe{}  -- \@date{}}
                         \renewcommand{\op@numero}{#2}
                         \ifthenelse{\equal{\op@typedoc}{Exercices corrigés}}%
                                    {\renewcommand{\op@entete}{\op@typedoc}%
                                     \renewcommand{\op@soustitre}{\op@typedoc}}{}%
                         \ifthenelse{\equal{\op@typedoc}{Cours}}%
                                    {\renewcommand{\op@entete}{\op@typedoc{}}%
                                     \renewcommand{\op@soustitre}{Rappels de cours}}{}%
                        \ifthenelse{\equal{\op@typedoc}{Devoir}}%
                                    {\renewcommand{\op@titre}{Devoir surveillé \no \op@numero}
                                     \renewcommand{\op@soustitre}{\op@classe{} -- \@date{} -- Durée : \op@duree}%
                                     \renewcommand{\op@entete}{\@date}}{}
                        \ifthenelse{\equal{\op@typedoc}{Interrogation}}%
                                    {\renewcommand{\op@titre}{Interrogation \no \op@numero}
                                     \renewcommand{\op@soustitre}{\op@classe{} -- \@date{}}%
                                     \renewcommand{\op@entete}{\@date}}{}

                         \ifthenelse{\equal{\op@typedoc}{Exercices}}%
                                    {\renewcommand{\op@entete}{\op@typedoc{} \op@numero}%
                                     \renewcommand{\op@soustitre}{\op@typedoc{} \op@numero}}{}%
                         \ifthenelse{\equal{\op@typedoc}{DM}}%
                                    {\renewcommand{\op@titre}{Devoir maison}%
                                     \renewcommand{\op@soustitre}{\op@classe{} -- À rendre le \@date}%
                                     \renewcommand{\op@entete}{À rendre le \@date}}{} 
                         \ifthenelse{\equal{\op@typedoc}{Corr}}%
                                    {\renewcommand{\op@soustitre}{\op@classe{} -- \@date{} -- Éléments de correction}%
                                    \renewcommand{\op@entete}{Devoir surveillé \no \op@numero}}{}        
                         \ifthenelse{\equal{\op@typedoc}{TP}}%
                                    {\renewcommand{\op@soustitre}{Travaux pratiques}%
                                     \renewcommand{\op@entete}{Travaux pratiques}}{} 
                        }
                        
\newcommand{\titre}[1]{\renewcommand{\op@titre}{#1}}
\newcommand{\duree}[1]{\renewcommand{\op@duree}{#1}}

\newcommand{\affichetitre}{%
                           \thispagestyle{plain}
                           \noindent{\color{LFBcouleur5}\huge\bfseries \op@titre}\par
                           \noindent{\color{LFBcouleur3}\rule{\linewidth}{1ex}}\par
                           \noindent{\bfseries \op@soustitre}\par
                           \vspace{2.5\baselineskip}
                           }



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% Fin présentation type article %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newenvironment{changemargin}[2]{%
  \begin{list}{}{%
    \setlength{\topsep}{0pt}%
    \setlength{\leftmargin}{#1}%
    \setlength{\rightmargin}{#2}%
    \setlength{\listparindent}{\parindent}%
    \setlength{\itemindent}{\parindent}%
    \setlength{\parsep}{\parskip}%
  }%
  \item[]}{\end{list}}


%%%%%%%%%%%%%%%%%% Titres section
\titleformat{\section}%
  {\normalfont\Large\bfseries\color{LFBcoulsection}}{\thesection}{1em}{}
\titlespacing*{\section}{0pt}{7ex plus 1ex minus .2ex}{2.3ex plus .2ex}


\RequirePackage{multicol}
  \setlength{\multicolsep}{12pt}
  \setlength{\columnsep}{40pt}
  \setlength{\columnseprule}{0.5pt}
  \renewcommand\columnseprulecolor{\color{LFBcoulrule}}



 \newenvironment{masection}[1]%
                 {\begin{multicols}{2}[\section{#1}]}%
                 {%
                 \end{multicols}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% Listes %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage[inline]{enumitem}

\newcommand{\m@rgeenum}{%
     \ifthenelse{\doublecol@number=0}%
               {\setlength{\leftmargin}{\labelwidth+\labelsep+17pt-\itemindent}}%
               {}%
        }

\newlength\op@labelwidth
\newcommand*{\op@label}{\textendash} % ou \textemdash par défaut
\settowidth{\op@labelwidth}{\op@label}
\setlist[itemize]{label=\op@label,nosep}
\setlist[1]{labelindent=\parindent}
\setlist{labelwidth=\op@labelwidth,
itemsep=0.4ex plus 0.2ex minus 0.2ex,
parsep=0.4ex plus 0.2ex minus 0.2ex,
topsep=0.8ex plus 0.4ex minus 0.4ex,
partopsep=0.4ex plus 0.2ex minus 0.2ex,
leftmargin=!}

\setlist[enumerate]{labelindent=\parindent,leftmargin=*,noitemsep}
\setlist[enumerate,1]{before=\m@rgeenum}
\setlist[enumerate,2]{leftmargin=*,label=\alph*),widest=a,ref=\theenumi.\alph*}
%\setlist[itemize]{nolistsep}

%%%%%%%% enumerate sur plusieurs colonnes %%%%%%%%
\newcounter{CE@numcolenu} % nombre d'environnements colenu (pour hyperref)
\AtBeginDocument{\def\theHCE@numitem{\theCE@numcolenu.\arabic{CE@numitem}}}

\newcounter{CE@numitem}   % numéro d'item
\newcounter{CE@numcol}    % numéro de colonne
\newcounter{CE@nombrecol} % nombre de colonnes
\newlength{\CE@largcol}
\newlength{\CE@itemsep}
\newlength{\CE@topsep}
\newenvironment{colenumerate}[2][]%
                {\let\CE@olditem\item
                 \let\item\CE@colitem
                 \stepcounter{CE@numcolenu}
                 \setcounter{CE@numitem}{0}  % Numéro item
                 \setcounter{CE@numcol}{0}   % Numéro colonne courante
                 \setcounter{CE@nombrecol}{#2} % Nombre de colonnes
                 \setlength{\CE@largcol}{(\linewidth-\parindent)/#2}% Largeur de chaque colonne
                 % Pour récupérer la valeur de \topsep
                 \raisebox{0pt}[0pt][0pt]%
                          {\makebox[0pt][l]%
                                   {\parbox{\linewidth}%
                                           {\begin{enumerate}[#1]
                                           \CE@olditem[]\global\CE@topsep=\topsep
                                           \end{enumerate}}%
                                   }%
                           }%
                 % À faire en dédut d'item
                 \def\CE@debitem{\begin{minipage}{\CE@largcol}
                                 \refstepcounter{CE@numitem}
                                 \stepcounter{CE@numcol}
                                 \begin{enumerate}[#1,start=\value{CE@numitem}]
                                 }
                 % À faire en fin d'item
                 \def\CE@finitem{\par
                                 \vspace{\CE@topsep}
                                 \noindent}
                 %\par
                 }%
                {\CE@finitem\par\vspace{-\CE@itemsep}\vspace{\CE@topsep}}
                        
\newcommand{\CE@colitem}{\CE@finitem%
                         \CE@debitem%
                         \ifthenelse{\value{CE@numcol}=\value{CE@nombrecol}}%
                               {\setcounter{CE@numcol}{0}%
                                \def\CE@finitem{\global\CE@itemsep=\itemsep   % On récupère itemsep
                                                \global\advance\CE@itemsep by \parsep
                                                \end{enumerate}
                                                \end{minipage}
                                                \par\vspace{\CE@itemsep}\noindent}}%
                               {%
                               \def\CE@finitem{\end{enumerate}
                                               \end{minipage}%
                                               }}%
                         \CE@olditem}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% COURS %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \RequirePackage{framed}
\RequirePackage{amsmath,amssymb,mathrsfs}
\RequirePackage{mathtools}

  \RequirePackage[framed,hyperref,amsmath,thmmarks]{ntheorem}
  \setlength{\FrameSep}{4pt}


\newenvironment{colorframe}{%
%  \def\FrameCommand{\shadowbox}%
  \def\FrameCommand{\fcolorbox{black}{LFBcoultheo}}%
  \MakeFramed {\advance\hsize-\width \FrameRestore}}%
 {\endMakeFramed}

\renewenvironment{leftbar}{%
  \def\FrameCommand{\color{LFBcouldef}\vrule width 3pt \hspace{10pt}\color{black}}%
  \MakeFramed {\advance\hsize-\width \FrameRestore}}%
 {\endMakeFramed}


\theoremstyle{plain}
\theoremseparator{\quad}
\theorembodyfont{\itshape}
\theoremprework{\leftbar\vspace{-0.5\baselineskip}}
\theorempostwork{\vspace{-0.7\baselineskip}\endleftbar}

\ifdef{\thechapter}{\newtheorem{definition}{Définition}[chapter]}
                   {\newtheorem{definition}{Définition}}

%\renewcommand{\thedefinition}{\arabic{definition}}

%\theoremclass{definition}
%\newtheorem{remarque}{Remarque}
%\renewcommand{\theremarque}{}
\theoremclass{definition}
\newtheorem{methode}{Méthode}

\theoremstyle{break}
\theoremseparator{}
\theorembodyfont{\upshape}
\theoremprework{\colorlet{bg}{LFBcoultheo}\colorframe\vspace{-0.5\baselineskip}}
\theorempostwork{\vspace{-0.5\baselineskip}\endcolorframe\colorlet{bg}{white}}

\ifdef{\thechapter}{\newtheorem{theoreme}{Théorème}[chapter]}
                   {\newtheorem{theoreme}{Théorème}}
%\renewcommand{\thetheoreme}{\arabic{chapter}.\arabic{theoreme}}

\theoremclass{theoreme}
\newtheorem{corollaire}[theoreme]{Corollaire}



\theoremstyle{nonumberplain}
\theoremseparator{\quad}
\theorembodyfont{\itshape}
\theoremprework{\vspace{1ex}\begin{footnotesize}\begin{itshape}}
\theorempostwork{\end{itshape}\end{footnotesize}}

\newtheorem{exemple}{Exemple}
\renewcommand{\theexemple}{\arabic{exemple}}

\theoremstyle{empty}
\theoremseparator{\quad}
\theorembodyfont{\upshape}
\theoremprework{\vspace{1ex}\begin{footnotesize}\begin{changemargin}{4ex}{0ex}}
\theorempostwork{\end{changemargin}\end{footnotesize}}

\newtheorem{reponse}{Réponse}
\renewcommand{\thereponse}{\arabic{reponse}}


\theoremstyle{empty}
\theoremseparator{\quad}
\theorembodyfont{\upshape}
\theoremprework{%\vspace{1ex}
                \begin{changemargin}{4ex}{0ex}\color{opcoultexte}
                }
\theorempostwork{\end{changemargin}}

\newtheorem{repex}{Réponse}
\renewcommand{\therepex}{\arabic{repex}}

\theoremstyle{plain}
\newtheorem{remarque}{Remarque :}
\renewcommand{\theremarque}{}


\theoremstyle{nonumberbreak}
\theoremheaderfont{\scshape\bfseries}\theorembodyfont{\upshape}
\theoremseparator{}
\theoremsymbol{\rule{1.5ex}{1.5ex}}
\newtheorem{demonstration}{Démonstration}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% Exercices %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{exercice}
\newcounter{refex}
\renewcommand{\therefex}{\arabic{exercice}}
\newcounter{partie}[exercice]
\newcounter{refpart}
\renewcommand{\thepartie}{\Alph{partie}}
\renewcommand{\therefpart}{\Alph{partie}}


\newenvironment{exercicecl@ssique}[1][]{%
                     \stepcounter{exercice}
                     \refstepcounter{refex}
                     \vspace{0.5em}
                     \par
                     \def\@svsechd{\large \color{white} \colorbox{LFBcoulnumexos}{\bfseries\arabic{exercice}}}%
                     \@xsect{-1em}%
                     \ifthenelse{\equal{#1}{}}{}{\textbf{#1}\par\nobreak}%
                     }{\par\vspace{1.5em}}

\newenvironment{exercicedev@ir}[1][]{%
                     \stepcounter{exercice}
                     \refstepcounter{refex}
                     \vspace{0.5em}
                     \par
                     {\bfseries {\setlength{\fboxsep}{2pt}\color{white} \colorbox{LFBcoulnumexos}{Exercice \arabic{exercice}}}
                     \quad \color{LFBcoulnumexos}\hrulefill \quad #1} \par\nobreak\vspace{0.5em}
                     }{\par\vspace{1.5em}}

\newenvironment{exercice@nonnum}[2][]{%
                     \stepcounter{exercice}
                     \refstepcounter{refex}
                     \vspace{0.5em}
                     \par
                     {\bfseries {\setlength{\fboxsep}{2pt}\color{white} \colorbox{LFBcoulnumexos}{Exercice #2}}
                     \quad \color{LFBcoulnumexos}\hrulefill \quad #1} \par\nobreak\vspace{0.5em}
                     }{\par\vspace{1.5em}}

\newenvironment{exercice}%
                   {\ifthenelse{\doublecol@number=0}{\exercicedev@ir}{\exercicecl@ssique}}%
                   {\ifthenelse{\doublecol@number=0}{\endexercicedev@ir}{\endexercicecl@ssique}}   

\newenvironment{exercice*}{\exercice@nonnum}{\endexercice@nonnum}

\newenvironment{partie}[1][]{%
                     \stepcounter{partie}
                     \refstepcounter{refpart}
                      \par \vspace{0.5ex}\noindent
                     \textbf{Partie \thepartie \ifthenelse{\equal{#1}{}}{}{\quad -\quad#1}%
                     }\nopagebreak\par%
                     }{\par\vspace{1em}}

 \newcommand{\includegraphicstop}[2][]{\raisebox{-\height+1em}{\includegraphics[#1]{#2}}}
 
 \newcommand{\consigne}[1]{\textit{#1}}


\endinput