%%%
% Op\'erations pos\'es à trou
%%%
%% D'après https://tex.stackexchange.com/questions/277246/drawing-a-circle-around-the-numbers-in-xlop-package

\newcommand\PfCchiffre[2]{\tikz[remember picture] \node[inner sep=0pt](#1){#2};}

\newcommand\PfCentoure[2]{\tikz[remember picture,overlay] \node[preaction={draw={\useKV[ClesOperations]{CouleurCadre}},ultra thick,opacity=1,
transform canvas={xshift=0em,yshift=0em}},rectangle,rounded corners,ultra thick,inner sep=.55em,fit=(#1.center)(#2.center)]{} ;}

\newcounter{divxlop}%
\newcounter{mulxlop}%
\newcounter{addxlop}%
\newcounter{subxlop}%

\setKVdefault[ClesOperations]{Solution=false,CouleurCadre=LightSteelBlue,CouleurSolution=red,CouleurFond=white,CouleurVirgule=white}

\newcommand\Division[3][]{%
  \useKVdefault[ClesOperations]%
  \setKV[ClesOperations]{#1}%
  \setcounter{divxlop}{0}%
  \ifboolKV[ClesOperations]{Solution}{\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurSolution}}}{\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurFond}}}%
  \opidiv[lineheight=1.5em,columnwidth=1.25em,displayintermediary=all,voperator=bottom,intermediarystyle=\stepcounter{divxlop}\color{PfCSolOp}\PfCchiffre{A\thedivxlop},remainderstyle=\stepcounter{divxlop}\color{PfCSolOp}\PfCchiffre{A\thedivxlop},resultstyle=\stepcounter{divxlop}\color{PfCSolOp}\PfCchiffre{A\thedivxlop}]{#2}{#3}%
  \foreach \i in {1,...,\thedivxlop}{%
    \PfCentoure{A\i}{A\i}%
  }%
}%

\newcommand\DivisionD[3][]{%
  \useKVdefault[ClesOperations]%
  \setKV[ClesOperations]{#1}%
  \setcounter{divxlop}{0}%
  \ifboolKV[ClesOperations]{Solution}{\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurSolution}}\colorlet{PfCCouleurVirgule}{PfCSolOp}}{\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurFond}}\colorlet{PfCCouleurVirgule}{\useKV[ClesOperations]{CouleurVirgule}}}%
  \opdiv[decimalsepsymbol={,},lineheight=1.5em,columnwidth=1.5em,displayintermediary=all,voperator=bottom,intermediarystyle=\stepcounter{divxlop}\color{PfCSolOp}\PfCchiffre{A\thedivxlop},remainderstyle=\stepcounter{divxlop}\color{PfCSolOp}\PfCchiffre{A\thedivxlop},resultstyle=\stepcounter{divxlop}\color{PfCSolOp}\PfCchiffre{A\thedivxlop},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
  \foreach \i in {1,...,\thedivxlop}{%
    \PfCentoure{A\i}{A\i}%
  }%
}%

\newcommand\Multiplication[3][]{%
  \useKVdefault[ClesOperations]%
  \setKV[ClesOperations]{#1}%
  \setcounter{mulxlop}{0}%
  \ifboolKV[ClesOperations]{Solution}{\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurSolution}}\colorlet{PfCCouleurVirgule}{PfCSolOp}}{\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurFond}}\colorlet{PfCCouleurVirgule}{\useKV[ClesOperations]{CouleurVirgule}}}%
  \opmul[decimalsepsymbol={,},lineheight=2em,columnwidth=1.5em,displayintermediary=all,voperator=bottom,intermediarystyle=\stepcounter{mulxlop}\color{PfCSolOp}\PfCchiffre{A\themulxlop},resultstyle=\stepcounter{mulxlop}\color{PfCSolOp}\PfCchiffre{A\themulxlop},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
  \foreach \i in {1,...,\themulxlop}{%
    \PfCentoure{A\i}{A\i}%
  }%
}%

\newcommand\Addition[3][]{%
  \useKVdefault[ClesOperations]%
  \setKV[ClesOperations]{#1}%
  \setcounter{addxlop}{0}%
  \ifboolKV[ClesOperations]{Solution}{\opset{carryadd,carrystyle=\color{PfCSolOp}\scriptsize}\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurSolution}}\colorlet{PfCCouleurVirgule}{PfCSolOp}}{\opset{carryadd=false}\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurFond}}\colorlet{PfCCouleurVirgule}{\useKV[ClesOperations]{CouleurVirgule}}}%
  \opadd[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,displayintermediary=all,voperator=bottom,intermediarystyle=\stepcounter{addxlop}\color{PfCSolOp}\PfCchiffre{A\theaddxlop},resultstyle=\stepcounter{addxlop}\color{PfCSolOp}\PfCchiffre{A\theaddxlop},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}
  \foreach \i in {1,...,\theaddxlop}{%
    \PfCentoure{A\i}{A\i}%
  }%
}%

\newcommand\Soustraction[3][]{%
  \useKVdefault[ClesOperations]%
  \setKV[ClesOperations]{#1}%
  \setcounter{subxlop}{0}%
  \ifboolKV[ClesOperations]{Solution}{\opset{carrysub,carrystyle=\color{PfCSolOp}\scriptsize}\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurSolution}}\colorlet{PfCCouleurVirgule}{PfCSolOp}}{\opset{carrysub=false}\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurFond}}\colorlet{PfCCouleurVirgule}{\useKV[ClesOperations]{CouleurVirgule}}}%
  \opsub[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,displayintermediary=all,voperator=bottom,intermediarystyle=\stepcounter{subxlop}\color{PfCSolOp}\PfCchiffre{A\thesubxlop},resultstyle=\stepcounter{subxlop}\color{PfCSolOp}\PfCchiffre{A\thesubxlop},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
  \foreach \i in {1,...,\thesubxlop}{%
    \PfCentoure{A\i}{A\i}
  }%
}%