%%% % Arbre de calculs %%% \newtoks\toklistearbre% \newtoks\toklistearbrefractions% \newtoks\toklistearbreexpressions% \def\UpdatetoksArbreCalcul#1\nil{\IfDecimal{#1}{\addtotok\toklistearbre{#1,}}{\addtotok\toklistearbre{"#1",}}}% \def\UpdatetoksArbreFractions#1\nil{\addtotok\toklistearbrefractions{"#1",}}% \def\UpdatetoksArbreExpressions#1\nil{\addtotok\toklistearbreexpressions{"#1",}}% \setKVdefault[ArbreCalcul]{Correction=false,Couleur=LightSteelBlue,Substitue=7,Litteral=false,Largeur=8mm,LargeurC=8mm,Ecart=1.5cm,Hauteur=10mm,Lettre="x",CouleurDepart=LightGreen,Fractions=false,Nombres={},Expressions={},Etape=infinity}% \defKV[ArbreCalcul]{Fraction=\setKV[ArbreCalcul]{Fractions}}% \NewDocumentCommand\ArbreCalcul{om}{% \useKVdefault[ArbreCalcul]% \setKV[ArbreCalcul]{#1}% \toklistearbre{}% \toklistearbrefractions{}% \toklistearbreexpressions{}% \infixtoRPN{#2}% \setsepchar{ }\ignoreemptyitems% \readlist*\ListeNombres{\RPN}% \reademptyitems% \foreachitem\compteur\in\ListeNombres{\expandafter\UpdatetoksArbreCalcul\compteur\nil}% \ifboolKV[ArbreCalcul]{Fractions}{% \xdef\Foo{\useKV[ArbreCalcul]{Nombres}}% \setsepchar{,}\ignoreemptyitems% \readlist*\ListeFractions{\Foo}% \reademptyitems \foreachitem\compteur\in\ListeFractions{\expandafter\UpdatetoksArbreFractions\compteur\nil}% \BuildArbreCalculFraction{\the\toklistearbre}{\the\toklistearbrefractions}% }{% \ifboolKV[ArbreCalcul]{Litteral}{ \xdef\Foo{\useKV[ArbreCalcul]{Nombres}}% \setsepchar{,}\ignoreemptyitems% \readlist*\ListeFractions{\Foo}% \reademptyitems \foreachitem\compteur\in\ListeFractions{\expandafter\UpdatetoksArbreFractions\compteur\nil}% \xdef\Foo{\useKV[ArbreCalcul]{Expressions}}% \setsepchar{,}\ignoreemptyitems% \readlist*\ListeExpressions{\Foo}% \reademptyitems \foreachitem\compteur\in\ListeExpressions{\expandafter\UpdatetoksArbreExpressions\compteur\nil}% % listarbre : \the\toklistearbre% % % listfracions : \the\toklistearbrefractions % % listexpressions : \the\toklistearbreexpressions \BuildArbreCalculLitteral{\the\toklistearbre}{\the\toklistearbrefractions}{\the\toklistearbreexpressions}% }{% \BuildArbreCalcul{\the\toklistearbre}% }% }% }% \NewDocumentCommand\BuildArbreCalcul{m}{% \ifluatex \mplibforcehmode \begin{mplibcode} boolean Correction,Litteral,Allume[]; Correction=\useKV[ArbreCalcul]{Correction}; Litteral=\useKV[ArbreCalcul]{Litteral}; NombreSubstitue=\useKV[ArbreCalcul]{Substitue}; etape=0; Etape=\useKV[ArbreCalcul]{Etape}; color Evidence,CoulDepart; Evidence=\useKV[ArbreCalcul]{Couleur}; CoulDepart=\useKV[ArbreCalcul]{CouleurDepart}; pair pointprec; path base[]; base1=unitsquare xscaled \useKV[ArbreCalcul]{Largeur} yscaled 5mm; base2=fullcircle scaled 5mm; base3=unitsquare xscaled \useKV[ArbreCalcul]{LargeurC} yscaled 5mm; vardef BlocCalcul(expr Ba,Bb,op,cha,chb)=% % Ba point gauche % Bb point droite % op opération à afficher etape:=etape+1; save $; picture $; path cc[]; pair Bc; Bc=(0.5*(xpart(Ba)+xpart(Bb)),if ypart(Bb)"neg": trace BlocCalcul(A[numeropoint-1],A[numeropoint],Operations[k],ValeurPile[numeropoint-1],ValeurPile[numeropoint]); A[numeropoint-1]:=pointprec; Allume[numeropoint-1]:=true; numeropoint:=numeropoint-1; fi; fi; endfor; \end{mplibcode} \fi }% \NewDocumentCommand\BuildArbreCalculFraction{mm}{% \ifluatex \mplibforcehmode \begin{mplibcode} boolean Correction,Allume[]; Correction=\useKV[ArbreCalcul]{Correction}; string Fraction; Fraction=\useKV[ArbreCalcul]{Fraction}; color Evidence,CoulDepart; Evidence=\useKV[ArbreCalcul]{Couleur}; CoulDepart=\useKV[ArbreCalcul]{CouleurDepart}; pair pointprec; path base[]; base1=unitsquare xscaled \useKV[ArbreCalcul]{Largeur} yscaled \useKV[ArbreCalcul]{Hauteur}; base2=fullcircle scaled 5mm; base3=unitsquare xscaled \useKV[ArbreCalcul]{LargeurC} yscaled \useKV[ArbreCalcul]{Hauteur}; vardef BlocCalcul(expr Ba,Bb,op,cha,chb)=% % Ba point gauche % Bb point droite % op opération à afficher etape:=etape+1; save $; picture $; path cc[]; pair Bc; Bc=(0.5*(xpart(Ba)+xpart(Bb)),if ypart(Bb)"neg": trace BlocCalcul(A[numeropoint-1],A[numeropoint],Operations[k],ValeurPile[numeropoint-1],ValeurPile[numeropoint]); A[numeropoint-1]:=pointprec; Allume[numeropoint-1]:=true; numeropoint:=numeropoint-1; fi; fi; endfor; \end{mplibcode} \fi }% \NewDocumentCommand\BuildArbreCalculLitteral{mmm}{% \ifluatex \mplibforcehmode \begin{mplibcode} boolean Correction,Allume[]; Correction=\useKV[ArbreCalcul]{Correction}; color Evidence,CoulDepart; Evidence=\useKV[ArbreCalcul]{Couleur}; CoulDepart=\useKV[ArbreCalcul]{CouleurDepart}; pair pointprec; path base[]; base1=unitsquare xscaled \useKV[ArbreCalcul]{Largeur} yscaled \useKV[ArbreCalcul]{Hauteur}; base2=fullcircle scaled 5mm; base3=unitsquare xscaled \useKV[ArbreCalcul]{LargeurC} yscaled \useKV[ArbreCalcul]{Hauteur}; vardef BlocCalcul(expr Ba,Bb,op,cha,chb)=% % Ba point gauche % Bb point droite % op opération à afficher etape:=etape+1; save $; picture $; path cc[]; pair Bc; Bc=(0.5*(xpart(Ba)+xpart(Bb)),if ypart(Bb)"neg": trace BlocCalcul(A[numeropoint-1],A[numeropoint],Operations[k],ValeurPile[numeropoint-1],ValeurPile[numeropoint]); A[numeropoint-1]:=pointprec; Allume[numeropoint-1]:=true; numeropoint:=numeropoint-1; fi; fi; endfor; \end{mplibcode} \fi }%