\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mathweb}[2026/02/05 Classe de livres mathweb.fr]

\LoadClass[openany]{book}

\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\RequirePackage[french]{babel}
\RequirePackage{lmodern}
\RequirePackage[table]{xcolor}
\RequirePackage{tabularx}
\RequirePackage{varwidth}
\RequirePackage{eurosym}
\RequirePackage{eso-pic}

\RequirePackage{geometry}
\geometry{tmargin=2cm,bmargin=1.5cm,hmargin=1.5cm}

\RequirePackage[most]{tcolorbox}
	\usetikzlibrary{shapes.geometric, calc, shadows, decorations.pathmorphing,spy,shapes.symbols}
	\usetikzlibrary{decorations.pathreplacing,calligraphy} 
	% pour faire des accolades -- ex: \draw [decorate,decoration = {calligraphic brace,amplitude=10pt,raise=3pt}] (5.5,3) --  (5.5,0);
	\tcbuselibrary{skins,breakable,theorems,listingsutf8,xparse,external}
	\tcbset{external/prefix=python/}
\RequirePackage{tkz-tab,tkz-fct,tkz-euclide}

\RequirePackage[explicit]{titlesec}
\RequirePackage{pagecolor}
\RequirePackage{fancyhdr}
	\renewcommand{\headrulewidth}{0pt}
	\renewcommand{\footrulewidth}{0pt}
	\let\oldmainmatter\mainmatter
	\renewcommand{\mainmatter}{\oldmainmatter\pagestyle{coursstyle}}

\RequirePackage{minitoc}	
	\renewcommand{\mtctitle}{} 
	\mtcsetrules{minitoc}{off}
	
\RequirePackage[colorlinks=true,linkcolor=orange]{hyperref} %linktoc
\RequirePackage{enumitem}

\RequirePackage{pas-math}
\RequirePackage{cancel}
\RequirePackage{fontawesome}
\RequirePackage{multicol,multirow}
\RequirePackage{diagbox}
\RequirePackage{systeme}
\RequirePackage{etoolbox}
	\AtEndDocument{%
		\addtocontents{toc}{%
			\vspace*{1cm}%
			\hspace*{7mm}%
			\textit{\faBook~~\arabic{nb@exos@mathweb} exercices entièrement corrigés}%
		}%
	}

\RequirePackage{cellspace}
	\setlength{\cellspacebottomlimit}{3pt}
	\setlength{\cellspacetoplimit}{3pt}
	% patch
	\let\@startpbox@action\@startpbox
	% fin du patch

\setlength{\parindent}{0pt}
\graphicspath{{img/}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \itemclass 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\itemclass}[1]
{
	\setlist[itemize,1]{label={\color{#1}\textbullet}}
	\setlist[itemize,2]{label={\color{#1}$\rightarrow$}}
	\setlist[enumerate,1]{label=\fcolorbox{#1}{#1}{\arabic*},font=\color{white}\normalsize\bfseries}
	\setlist[enumerate,2]{label=\textcolor{#1}{\alph*.},font=\normalsize\bfseries}
}

\itemclass{black}{}
\raggedbottom

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \drawshadow
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Shadow
	\def\shadowshift{3pt,-3pt}
	\def\shadowradius{5pt}
	\colorlet{innercolor}{black!60}
	\colorlet{outercolor}{gray!05}
	\newcommand\drawshadow[2]{
		\begin{pgfonlayer}{shadow}
		% Effet d'ombre en forme de cercle en bas à gauche
		\shade[outercolor, inner color=innercolor, outer color=outercolor] ($(#1.south west)+(\shadowshift)+(\shadowradius/2 , \shadowradius/2)$) circle (\shadowradius);
		% Effet d'ombre en forme de cercle en bas à droite
		\shade[outercolor, inner color=innercolor, outer color=outercolor] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2 , \shadowradius/2)$) circle (\shadowradius);
		% Effet d'ombre en forme de cercle en haut à droite
		\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.north east)+(\shadowshift)+(-\shadowradius/2 , -\shadowradius/2)$) circle (\shadowradius);
		% Dégradé de haut en bas sur la partie sud du rectangle
		\shade[top color=innercolor,bottom color=outercolor] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
		% Dégradé de gauche à droite sur le côté droit du rectangle
		\shade[left color=innercolor,right color=outercolor] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$);
		% On remplit le rectangle créé avec une couleur noire
		\filldraw[#2] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)-(\shadowradius/2,\shadowradius/2)$);
		\end{pgfonlayer}
	}
	\pgfdeclarelayer{shadow}
	\pgfsetlayers{shadow,main}
	

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compteur d'exercices 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcounter{nb@exos@mathweb}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% couverture
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\couverture}[1]{%
	\newgeometry{margin=0cm}~
	\AddToShipoutPictureBG*{%
		\AtPageLowerLeft{%
			\put(0,0){%
				\includegraphics[width=220mm,height=280mm]{{#1}}%
			}
		}
	}
	\thispagestyle{empty}%
	\restoregeometry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Cardinal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DeclareMathOperator{\card}{Card}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \if@frontmatter, \if\backmatter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newif\if@frontmatter
\@frontmattertrue  % par défaut on commence en frontmatter
\newif\if@backmatter
\@backmatterfalse

\let\orig@frontmatter\frontmatter
\renewcommand{\frontmatter}{%
  \orig@frontmatter
  \@frontmattertrue
}

\let\orig@mainmatter\mainmatter
\renewcommand{\mainmatter}{%
  \orig@mainmatter
  \@frontmatterfalse
  \@backmatterfalse
}

\let\orig@backmatter\backmatter
\renewcommand{\backmatter}{%
  \orig@backmatter
  \@frontmatterfalse
  \@mainmatterfalse
  \stepcounter{chapter}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Repère
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% repère 

\newcommand{\rep}[4]{% xmin,ymin,xmax,ymax
\draw[gray,dashed] (#1,#2) grid (#3,#4);
\draw[->,>=stealth'] (#1,0) -- (#3,0);
\draw[->,>=stealth'] (0,#2) -- (0,#4);
\draw[thick,red,->,>=stealth'] (0,0) -- (1,0) node[midway,below] {$\vv{\imath}$};
\draw[thick,red,->,>=stealth'] (0,0) -- (0,1) node[midway,left] {$\vv{\jmath}$};
\node[below left] at (0,0) {O};
\clip (#1,#2) rectangle (#3,#4);
}

\input{def-foot-head}
\input{def-chapter}
\input{def-toc}
\input{def-exotype}
\input{def-python}
\input{def-exercices}
\input{def-corriges}