\documentclass[12pt,a4paper]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{tikz,tkz-tab}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usetikzlibrary{arrows.meta,calc,positioning}
\usepackage{fontspec}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{array}
\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{french}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.15]{Amiri}
\newfontfamily\arabicfontsf[Script=Arabic,Scale=1.15]{Amiri}
\newcommand{\cadre}[1]{\begin{center}\begin{LTR}#1\end{LTR}\end{center}}
\newcommand{\cadrertl}[1]{\begin{center}#1\end{center}}
\newcommand{\ipa}[1]{#1}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\newcounter{q}
\newcommand{\sujet}[1]{%
  \newpage\stepcounter{q}%
  \begin{tcolorbox}[colback=blue!5,colframe=blue!60!black,arc=3mm,boxrule=1pt]
  \centering {\Large\bfseries مسابقة بين الثانويات -- الرياضيات}\\[2mm]
  {\large السؤال رقم \theq \quad -- \quad #1 \quad -- \quad المدة: دقيقتان}
  \end{tcolorbox}\vspace{5mm}\large}
\newcommand{\rep}{\vfill\begin{tcolorbox}[colback=white,colframe=black!50,height=3.2cm,title=الإجابة:]\end{tcolorbox}}
\newenvironment{sanad}{\begin{tcolorbox}[colback=orange!4,colframe=orange!60!black,title=السند,fonttitle=\bfseries]}{\end{tcolorbox}}
\begin{document}
\setcounter{q}{14}
\sujet{الحساب التكاملي}

$(C_f)$ التمثيل البياني لدالة $f$ معرفة ومستمرة على المجال $[0;4]$:

\cadre{\begin{tikzpicture}
\begin{axis}[axis lines=middle,grid=both,width=9cm,height=6.5cm,xmin=-0.5,xmax=4.8,ymin=-0.5,ymax=3,
 xtick={0,...,4},ytick={0,1,2},xlabel=$x$,ylabel=$y$,ticklabel style={font=\small}]
\addplot[fill=orange!25,draw=none] coordinates {(0,0)(2,2)(4,2)(4,0)} -- cycle;
\addplot[blue,very thick] coordinates {(0,0)(2,2)(4,2)};
\node[blue] at (axis cs:3,2.4) {$(C_f)$};
\end{axis}\end{tikzpicture}}

\textbf{السؤال:} احسب التكامل $\displaystyle I=\int_{0}^{4} f(x)\,dx$، ثم القيمة المتوسطة للدالة $f$ على $[0;4]$.

\rep
\end{document}
