summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCOperationsTrou.tex
blob: d26dbade32c00beecd7c479649be33c3e139be97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
%%%
% Op\'erations pos\'es à trou
%%%
%% D'après https://tex.stackexchange.com/questions/277246/drawing-a-circle-around-the-numbers-in-xlop-package

%\begin{document}%
%
%\end{document}

\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)]{};}

\newcommand\PfCchiffreclip[2]{%
  \ifboolKV[ClesOperations]{Solution}{%
    \xintFor* ##1 in{\xintSeq{1}{\PfCListeTroulen}}\do{%
      \xintifboolexpr{\thedivxlop==\PfCListeTrou[##1]}{%
        \color{PfCSolOp}}{}%
    }%
  }{}%
  \tikz[remember picture] \node[inner sep=0pt](#1){#2};%
}%

\newcommand\PfCentoureclip[2]{\tikz[remember picture,overlay] \node[preaction={draw={\useKV[ClesOperations]{CouleurCadre}},ultra thick,opacity=1,
transform canvas={xshift=0em,yshift=0em}},rectangle,fill=PfCSolOp,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,Listes=false}
\defKV[ClesOperations]{Liste=\setKV[ClesOperations]{Listes}\xdef\PfCFooListeTrou{#1}}%

\newcommand\Division[3][]{%
  \useKVdefault[ClesOperations]%
  \setKV[ClesOperations]{#1}%
  \setcounter{divxlop}{0}%
  \ifboolKV[ClesOperations]{Solution}{\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurSolution}}}{\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurFond}}}%
  \ifboolKV[ClesOperations]{Listes}{%
    \setsepchar{,}\ignoreemptyitems%
    \readlist*\PfCListeTrou{\PfCFooListeTrou}%
    \reademptyitems%
    %,displayintermediary=all
    \opidiv[lineheight=1.75em,columnwidth=1.5em,voperator=bottom,operandstyle=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},intermediarystyle=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},remainderstyle=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},resultstyle=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop}]{#2}{#3}%
    \ifboolKV[ClesOperations]{Solution}{}{%
      \foreachitem\compteur\in\PfCListeTrou{%
        \xdef\PfCRetiensTrou{\PfCListeTrou[\compteurcnt]}%
        \PfCentoureclip{A\PfCRetiensTrou}{A\PfCRetiensTrou}%
      }%
    }%
  }{%
      \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{divxlop}{0}%
  \ifboolKV[ClesOperations]{Solution}{\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurSolution}}\colorlet{PfCCouleurVirgule}{PfCSolOp}}{\colorlet{PfCSolOp}{\useKV[ClesOperations]{CouleurFond}}\colorlet{PfCCouleurVirgule}{\useKV[ClesOperations]{CouleurVirgule}}}%
  \ifboolKV[ClesOperations]{Listes}{%
  \setsepchar{,}\ignoreemptyitems%
  \readlist*\PfCListeTrou{\PfCFooListeTrou}%
  \reademptyitems%
  \begingroup
  \setlength{\baselineskip}{1.75em}
  \StrLen{#3}[\PfCLongueurFacteurDeux]
  \ifnum\PfCLongueurFacteurDeux=1\relax
  \opset{lineheight=\baselineskip} % nécessaire
  \else
  \opset{lineheight=\baselineskip,displayintermediary=all,displayshiftintermediary=all} % nécessaire
  \fi
  \opmul[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,voperator=bottom,operandstyle=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},intermediarystyle=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},resultstyle=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
  \endgroup%
  \ifboolKV[ClesOperations]{Solution}{}{%
    \foreachitem\compteur\in\PfCListeTrou{%
      \xdef\PfCRetiensTrou{\PfCListeTrou[\compteurcnt]}%
      \PfCentoureclip{A\PfCRetiensTrou}{A\PfCRetiensTrou}%
    }%
  }%
  }{%
  \begingroup
  \setlength{\baselineskip}{2em}
  \StrLen{#3}[\PfCLongueurFacteurDeux]
  \ifnum\PfCLongueurFacteurDeux=1\relax
  \opset{lineheight=\baselineskip} % nécessaire
  \else
  \opset{lineheight=\baselineskip,displayintermediary=all,displayshiftintermediary=all} % nécessaire
  \fi
  \opmul[decimalsepsymbol={,},lineheight=2em,columnwidth=1.5em,voperator=bottom,intermediarystyle=\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}%
  }%
  \endgroup
  }
}%

\newcommand\Addition[3][]{%
  \useKVdefault[ClesOperations]%
  \setKV[ClesOperations]{#1}%
  \setcounter{divxlop}{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}}}%
  \ifboolKV[ClesOperations]{Listes}{%
    \setsepchar{,}\ignoreemptyitems%
    \readlist*\PfCListeTrou{\PfCFooListeTrou}%
    \reademptyitems%
    \opadd[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,voperator=bottom,operandstyle.1=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},operandstyle.2=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},resultstyle=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
    \ifboolKV[ClesOperations]{Solution}{}{%
      \foreachitem\compteur\in\PfCListeTrou{%
        \xdef\PfCRetiensTrou{\PfCListeTrou[\compteurcnt]}%
        \PfCentoureclip{A\PfCRetiensTrou}{A\PfCRetiensTrou}%
      }%
    }%
  }{%
    \opadd[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,voperator=bottom,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\Soustraction[3][]{%
  \useKVdefault[ClesOperations]%
  \setKV[ClesOperations]{#1}%
  \setcounter{divxlop}{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}}}%
  \ifboolKV[ClesOperations]{Listes}{%
    \setsepchar{,}\ignoreemptyitems%
    \readlist*\PfCListeTrou{\PfCFooListeTrou}%
    \reademptyitems%
    \opsub[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,voperator=bottom,operandstyle=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},resultstyle=\stepcounter{divxlop}\PfCchiffreclip{A\thedivxlop},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
    \ifboolKV[ClesOperations]{Solution}{}{%
      \foreachitem\compteur\in\PfCListeTrou{%
        \xdef\PfCRetiensTrou{\PfCListeTrou[\compteurcnt]}%
        \PfCentoureclip{A\PfCRetiensTrou}{A\PfCRetiensTrou}%
      }%
    }%
  }{%
    \opsub[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,voperator=bottom,resultstyle=\stepcounter{divxlop}\color{PfCSolOp}\PfCchiffre{A\thedivxlop},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
    \foreach \i in {1,...,\thedivxlop}{%
      \PfCentoure{A\i}{A\i}
    }%
  }%
}%

\NewDocumentCommand\MultiAddition{om}{%
  \useKVdefault[ClesOperations]%
  \setKV[ClesOperations]{#1}%
  \setcounter{divxlop}{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}}}%
  \opmanyadd[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,vmanyoperator=bottom,resultstyle=\stepcounter{divxlop}\color{PfCSolOp}\PfCchiffre{A\thedivxlop},resultstyle.d=\color{PfCCouleurVirgule}]#2
  \foreach \i in {1,...,\thedivxlop}{%
    \PfCentoure{A\i}{A\i}%
  }%
}%