% tkz-grapheur-fr.tex
% Copyright 2026 Cédric Pierquet
% Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txt
% macros [fr] de tkz-grapheur-fr

%\makeatletter

%====COMMANDE POUR NB DECIMAL ALEA ENTRE BORNES
\NewDocumentCommand\ChoisirNbAlea{ s O{0} m m O{\monbnalea} }{%
  \def\tmpborneinf{\xinteval{floor(#3)}}%
  \def\tmpbornesup{\xinteval{ceil(#4)}}%
  \xintifboolexpr{#2 == 0}%
    {%
      \xdef#5{\fpeval{randint(\tmpborneinf,\tmpbornesup)}}%
    }%
    {%
      \def\tmptest{0}%
      \whiledo{\tmptest=0}{%
        \xintifboolexpr{(\tmpbornesup-\tmpborneinf) == 1}%
          {%
            \xdef\tmpresalea{\fpeval{\tmpborneinf+round(rand(),#2)}}%
          }%
          {%
            \xdef\tmpresalea{\fpeval{round(randint(\tmpborneinf,\tmpbornesup)+rand(),#2)}}%
          }%
        \IfBooleanTF{#1}%
          {%
            \xintifboolexpr{\tmpresalea < #4 'and' \tmpresalea > #3 }{\def\tmptest{1}}{\def\tmptest{0}}%
          }%
          {%
            \xintifboolexpr{\tmpresalea <= #4 'and' \tmpresalea >= #3 }{\def\tmptest{1}}{\def\tmptest{0}}%
          }%
      }%
      \xdef#5{\tmpresalea}%
    }%
}

%====PATCH NUM
\@ifundefined{ArrondirNum}%
  {%
    \NewDocumentCommand\ArrondirNum{ s O{2} D<>{} m}{%
      \IfBooleanTF{#1}%
        {%
          \xintfloateval{round(#4,#2)}\relax%
        }%
        {%
          \num[#3]{\xintfloateval{round(#4,#2)}}\relax%
        }%
    }%
  }%
  {%
    \RenewDocumentCommand\ArrondirNum{ s O{2} D<>{} m}{%
      \IfBooleanTF{#1}%
      {%
        \xintfloateval{round(#4,#2)}\relax%
      }%
      {%
        \num[#3]{\xintfloateval{round(#4,#2)}}\relax%
      }%
    }%
  }%

%===COMMANDE INTERNE POUR FORMATER EN FRACTIONS
\NewDocumentCommand\FormatterFraction{ s O{} m }{%
  %*=moins sur le numérateur
  %2=argument.optionnel[d/t/dec=...]
  %3=argument mandataire {calcul ou fraction}
  \def\calculargument{\xintPRaw{\xintIrr{\xinteval{#3}}}}%on calcule et on transforme en A/B
  \IfSubStr{\calculargument}{/}%on teste si le symbole / apparaît
  {%si oui := fraction
    \StrBefore{\calculargument}{/}[\numerateur]%on extrait le numérateur
    \StrBehind{\calculargument}{/}[\denominateur]%on extrait le dénominateur
    \ifblank{#2}%
    {%
      \IfBooleanTF{#1}%
      {\ensuremath{\frac{\num{\numerateur}}{\num{\denominateur}}}}%
      {%
        \ifthenelse{\numerateur < 0}%
          {\ensuremath{-\frac{\num{\fpeval{abs(\numerateur)}}}{\num{\denominateur}}}}%
          {\ensuremath{\frac{\num{\numerateur}}{\num{\denominateur}}}}%
      }%
    }%
    {}%si l'argument optionnel est vide
    \IfStrEq{#2}{d}%
    {%
      \IfBooleanTF{#1}%
      {\ensuremath{\displaystyle\frac{\num{\numerateur}}{\num{\denominateur}}}}%
      {%
        \ifthenelse{\numerateur < 0}%
          {\ensuremath{-\displaystyle\frac{\num{\fpeval{abs(\numerateur)}}}{\num{\denominateur}}}}%
          {\ensuremath{\displaystyle\frac{\num{\numerateur}}{\num{\denominateur}}}}%
      }%
    }%
    {}%si l'argument optionnel est vide
    \IfStrEq{#2}{t}%
    {%
      \IfBooleanTF{#1}%
      {\ensuremath{\tfrac{\num{\numerateur}}{\num{\denominateur}}}}%
      {%
        \ifthenelse{\numerateur < 0}%
          {\ensuremath{-\frac{\num{\fpeval{abs(\numerateur)}}}{\num{\denominateur}}}}%
          {\ensuremath{\frac{\num{\numerateur}}{\num{\denominateur}}}}%
      }%
    }%
    {}%si l'argument optionnel est vide
    \IfStrEq{#2}{n}%
    {%
      \ensuremath{\nicefrac{\num{\numerateur}}{\num{\denominateur}}}%
    }%
    {}%si l'argument optionnel est vide
  }{%si non := entier
    \num{\calculargument}%on affiche l'entier, avec le package siunitx
  }%
}

%affichage d'un label en radians
\NewDocumentCommand\FormatterTrigo{ O{t} m }{%étoilée en dfrac
  \IfStrEq{#2}{0}%cas où l'argument vaut 0
    {\def\restmp{0}}%
    {%
      \StrDel{#2}{*}[\restmpsansmoins]%
      \StrSubstitute{\restmpsansmoins}{pi}{\pi}[\restmppi]%
      \IfSubStr{#2}{/}%
      {%
        \StrCut{\restmppi}{/}\tmpnum\tmpdenom%
        \IfSubStr{\tmpnum}{-}%
        {%
          \StrDel{\tmpnum}{-}[\restmppinum]%
          \IfStrEqCase{#1}{%
            {t}{\def\restmp{-\frac{\restmppinum}{\tmpdenom}}}%
            {d}{\def\restmp{-\displaystyle\frac{\restmppinum}{\tmpdenom}}}%
            {n}{\def\restmp{\nicefrac{-\restmppinum}{\tmpdenom}}}%
          }%
        }%
        {%
          \IfStrEqCase{#1}{%
            {t}{\def\restmp{\frac{\tmpnum}{\tmpdenom}}}%
            {d}{\def\restmp{\displaystyle\frac{\tmpnum}{\tmpdenom}}}%
            {n}{\def\restmp{\nicefrac{\tmpnum}{\tmpdenom}}}%
          }%
        }%
      }%
      {%
        \def\restmp{\restmppi}%
      }%
    }%
  \ensuremath{\restmp}%
}

%====FORMATAGE DES RACINES SIMPLES
\NewDocumentCommand\FormatterRacine{ O{t} m }{%
  \IfStrEq{#2}{0}%cas où l'argument vaut 0
    {\ensuremath{0}}%
    {%
      \IfSubStr{#2}{sqrt}%
        {%
          \StrDel{#2}{*}[\tmpargbrut]%
          \StrBetween[1,1]{\tmpargbrut}{sqrt(}{)}[\tmpargnumrac]%
          \StrBefore{\tmpargbrut}{sqrt}[\tmparavantrac]%
          \IfStrEqCase{\tmparavantrac}{
            {}{\xdef\tmparavantrac{}}%
            {-}{\xdef\tmparavantrac{-}}%
          }[\xdef\tmparavantrac{\num{\tmparavantrac}}]%
          \IfSubStr{\tmpargbrut}{/}%
            {%
              \StrBehind{\tmpargbrut}{/}[\tmpargdenomrac]%
              \IfStrEqCase{#1}{%
                {d}{%
                  \ensuremath{\displaystyle\frac{\tmparavantrac\sqrt{\num{\tmpargnumrac}}}{\num{\tmpargdenomrac}}}%
                }%
                {t}{%
                  \ensuremath{\frac{\tmparavantrac\sqrt{\num{\tmpargnumrac}}}{\num{\tmpargdenomrac}}}%
                }%
                {n}{%
                  \ensuremath{\nicefrac{\tmparavantrac\sqrt{\num{\tmpargnumrac}}}{\num{\tmpargdenomrac}}}%
                }%
              }%
            }%
            {%
              \ensuremath{\tmparavantrac\sqrt{\num{\tmpargnumrac}}}%
            }%
        }%
        {%
          \FormatterFraction[#1]{#2}%
        }%
    }%
}

%====COMMANDE INTERNE DE CONVERSION
\ExplSyntaxOn
  \NewDocumentCommand\ConvertirPtToCm{ m } { \dim_to_decimal_in_unit:nn { #1 } { 1 cm } }
\ExplSyntaxOff

%====RECUPERER COORDONNEES NOEUD
\NewDocumentCommand\RecupererAbscisse{ m O{\monabs} }{%
  \path #1;
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef#2{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
}
\NewDocumentCommand\RecupererOrdonnee{ m O{\monordo} }{%
  \path #1;
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef#2{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
}

\NewDocumentCommand\RecupererCoordonnees{ m O{\monabs} O{\monordo} }{%
  \RecupererAbscisse{#1}[#2]%
  \RecupererOrdonnee{#1}[#3]%
}

%===UNITÉS
\newcommand\DistanceEntreNoeuds[3][\MyTmpDist]{%
    \pgfpointdiff{\pgfpointanchor{#2}{center}}
                 {\pgfpointanchor{#3}{center}}
    % no need to use a new dimen
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    % to convert from pt to cm
    \pgfmathparse{veclen(\pgf@xa,\pgf@ya)/28.45274}
    \global\let#1\pgfmathresult %macro globale
}

\newcommand\TikZUnites{
    \coordinate (@0) at (\pflOx,\pflOy) ;
    \coordinate (@X) at ({\pflOx+1},\pflOy) ;
    \coordinate (@Y) at ({\pflOx},{\pflOy+1}) ;
    \DistanceEntreNoeuds[\pflxunit]{@0}{@X}
    \DistanceEntreNoeuds[\pflyunit]{@0}{@Y}
}

%TailleGrad=\setlength\pflthickgrad{#1},%
\defKV[GraphiqueTikz]{%
  TailleGrad=\def\pfltmpthickgrad{#1},%
  Xmin=\def\pflxmintmp{#1},%
  Xmax=\def\pflxmaxtmp{#1},%
  Ymin=\def\pflymintmp{#1},%
  Ymax=\def\pflymaxtmp{#1},%
  Taille=\def\pflgraphdims{#1},%
  Largeur=\def\pflgraphwidth{#1},%
  Hauteur=\def\pflgraphheight{#1},%
  Theme=\def\pflgraphthem{#1},%
  NomFigure=\def\pflgraphnom{#1},%
  XYratio=\def\pflgraphratio{#1},%
  Origx=\def\pflOxtmp{#1},%
  Origy=\def\pflOytmp{#1},%
  Xgrille=\def\pflgrillextmp{#1},%
  Xgrillei=\def\pflgrillexitmp{#1},%
  Xgrilles=\def\pflgrillexstmp{#1},%
  Ygrille=\def\pflgrilleytmp{#1},%
  Ygrillei=\def\pflgrilleyitmp{#1},%
  Ygrilles=\def\pflgrilleystmp{#1},%
  NbgradsX=\def\pflnbgradsx{#1},%
  NbgradsY=\def\pflnbgradsy{#1}
}
\setKVdefault[GraphiqueTikz]{%
  AffCadre=false,%
  TailleGrad=3pt,%
  Xmin=-3,%
  Xmax=3,%
  Ymin=-3,%
  Ymax=3,%
  Taille={},%
  Largeur={},%
  Hauteur={},%
  Theme={},
  Milli=false,%
  NomFigure={},%
  XYratio={1},%
  Origx={0},%
  Origy={0},%
  Xgrille={1},%
  Xgrillei={1},%
  Xgrilles={0.5},%
  Ygrille={1},%
  Ygrillei={1},%
  Ygrilles={0.5},%
  GradsAuto=false,%
  NbgradsX=8,%
  NbgradsY=6
}

\newlength\tmptkzgheight
\newlength\tmptkzgwidth

\NewDocumentEnvironment{GraphiqueTikz}{ O{} D<>{} }%
%1 = options tikz, classiques
%2 = clés spécifiques
{%
  \restoreKV[GraphiqueTikz]%
  \setKV[GraphiqueTikz]{#2}%
  %GradsAuto : override de Xgrille/Ygrille
  \ifboolKV[GraphiqueTikz]{GradsAuto}%
    {%
      \tkzgDeltaGradAuto[\pflxmintmp]{\pflxmaxtmp}{\pflnbgradsx}[\pflgrillextmp]%
      \tkzgDeltaGradAuto[\pflymintmp]{\pflymaxtmp}{\pflnbgradsy}[\pflgrilleytmp]%
      % ajustement des bornes sur le pas calculé
      \tkzgMinAjuste{\pflxmintmp}{\pflgrillextmp}{\pflxmintmp}%
      \tkzgMaxAjuste{\pflxmaxtmp}{\pflgrillextmp}{\pflxmaxtmp}%
      \tkzgMinAjuste{\pflymintmp}{\pflgrilleytmp}{\pflymintmp}%
      \tkzgMaxAjuste{\pflymaxtmp}{\pflgrilleytmp}{\pflymaxtmp}%
      % sous-grilles
      \xdef\pflgrillexstmp{\xintfloateval{\pflgrillextmp/2}}%
      \xdef\pflgrilleystmp{\xintfloateval{\pflgrilleytmp/2}}%
      \xdef\pflgrillexitmp{\pflgrillextmp}%
      \xdef\pflgrilleyitmp{\pflgrilleytmp}%
    }%
    {}%
  %les graduations
  \IfSubStr{\pfltmpthickgrad}{/}%
    {%
      \StrCut{\pfltmpthickgrad}{/}{\pfltmpthickgradu}{\pfltmpthickgradd}%
      \setlength\pflthickgradu{\pfltmpthickgradu}%
      \setlength\pflthickgradd{\pfltmpthickgradd}%
    }%
    {%
      \setlength\pflthickgradu{\pfltmpthickgrad}%
      \setlength\pflthickgradd{\pfltmpthickgrad}%
    }%
  %l'environnement
  \IfStrEq{\pflgraphdims}{}%
  {%pas de Taille
    \IfStrEq{\pflgraphwidth}{}%
      {%pas de Largeur
        \IfStrEq{\pflgraphheight}{}%
          {%rien du tout → classique
            \begin{tikzpicture}[#1]%
          }%
          {%Hauteur seule + XYratio obligatoire
            \setlength\tmptkzgheight{\pflgraphheight}%
            \setlength\pflglobalheight{\fpeval{(\tmptkzgheight)/(\pflymaxtmp-\pflymintmp)}pt}%
            \setlength\pflglobalwidth{\fpeval{1/(\pflgraphratio)}\pflglobalheight}%
            \begin{tikzpicture}[x=\pflglobalwidth,y=\pflglobalheight,
                Xmin=\pflxmintmp,Xmax=\pflxmaxtmp,
                Ymin=\pflymintmp,Ymax=\pflymaxtmp,
                Xgrille=\pflgrillextmp,Xgrillei=\pflgrillexitmp,Xgrilles=\pflgrillexstmp,
                Ygrille=\pflgrilleytmp,Ygrillei=\pflgrilleyitmp,Ygrilles=\pflgrilleystmp,
                Origx=\pflOxtmp,Origy=\pflOytmp,#1]%
          }%
      }%
      {%Largeur seule
        \setlength\tmptkzgwidth{\pflgraphwidth}%
        \setlength\pflglobalwidth{\fpeval{(\tmptkzgwidth)/(\pflxmaxtmp-\pflxmintmp)}pt}%
        \IfStrEq{\pflgraphheight}{}%
          {%Largeur + XYratio
            \setlength\pflglobalheight{\fpeval{\pflgraphratio}\pflglobalwidth}%
          }%
          {%Largeur + Hauteur explicites
            \setlength\tmptkzgheight{\pflgraphheight}%
            \setlength\pflglobalheight{\fpeval{(\tmptkzgheight)/(\pflymaxtmp-\pflymintmp)}pt}%
          }%
        \begin{tikzpicture}[x=\pflglobalwidth,y=\pflglobalheight,
            Xmin=\pflxmintmp,Xmax=\pflxmaxtmp,
            Ymin=\pflymintmp,Ymax=\pflymaxtmp,
            Xgrille=\pflgrillextmp,Xgrillei=\pflgrillexitmp,Xgrilles=\pflgrillexstmp,
            Ygrille=\pflgrilleytmp,Ygrillei=\pflgrilleyitmp,Ygrilles=\pflgrilleystmp,
            Origx=\pflOxtmp,Origy=\pflOytmp,#1]%
      }%
  }%
  {%Taille=w/h → priorité absolue
    \StrCut{\pflgraphdims}{/}{\pfltmpwidth}{\pfltmpheight}%
    \setlength\pflglobalwidth{\fpeval{(\pfltmpwidth)/(\pflxmaxtmp-\pflxmintmp)}pt}%
    \setlength\pflglobalheight{\fpeval{(\pfltmpheight)/(\pflymaxtmp-\pflymintmp)}pt}%
    \begin{tikzpicture}[x=\pflglobalwidth,y=\pflglobalheight,
        Xmin=\pflxmintmp,Xmax=\pflxmaxtmp,
        Ymin=\pflymintmp,Ymax=\pflymaxtmp,
        Xgrille=\pflgrillextmp,Xgrillei=\pflgrillexitmp,Xgrilles=\pflgrillexstmp,
        Ygrille=\pflgrilleytmp,Ygrillei=\pflgrilleyitmp,Ygrilles=\pflgrilleystmp,
        Origx=\pflOxtmp,Origy=\pflOytmp,#1]%
  }%
  %thèmes personnalisés
  \IfStrEqCase{\pflgraphthem}{%
    {standard}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepdefault!75}}\tikzset{pflgrilles/.style={line width=\pflthickgrids,pflgrillesdefault}}\tikzset{pflgrillei/.style={line width=\pflthickgridi,pflgrilleidefault}}}%
    {gris}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepgray!75}}\tikzset{pflgrilles/.style={line width=\pflthickgrids,pflgrillesgray}}\tikzset{pflgrillei/.style={line width=\pflthickgridi,pflgrilleigray}}}%
    {bleu}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepblue!75}}\tikzset{pflgrilles/.style={line width=\pflthickgrids,pflgrillesblue}}\tikzset{pflgrillei/.style={line width=\pflthickgridi,pflgrilleiblue}}}%
    {vert}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepgreen!75}}\tikzset{pflgrilles/.style={line width=\pflthickgrids,pflgrillesgreen}}\tikzset{pflgrillei/.style={line width=\pflthickgridi,pflgrilleigreen}}}%
    {chaud}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepwarm!75}}\tikzset{pflgrilles/.style={line width=\pflthickgrids,pflgrilleswarm}}\tikzset{pflgrillei/.style={line width=\pflthickgridi,pflgrilleiwarm}}}%
    {contraste}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepcontrast!75}}\tikzset{pflgrilles/.style={line width=\pflthickgrids,pflgrillescontrast}}\tikzset{pflgrillei/.style={line width=\pflthickgridi,pflgrilleicontrast}}}%
    {seyes}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepseyes}}\tikzset{pflgrilles/.style={line width=\pflthickgrids,pflgrillesseyes}}\tikzset{pflgrillei/.style={line width=\pflthickgridi,pflgrilleiseyes}}}%
  }%
  %unités x/y pour des calculs de coordonnées (dommage vu que dans certains cas on les connais déjà :-/)
  \TikZUnites
  %noeuds fenêtre + axes
  \IfStrEq{\pflgraphnom}{}%
    {%
      \coordinate (graphe-ne) at ({\pflxmax},{\pflymax}) ;
      \coordinate (graphe-nw) at ({\pflxmin},{\pflymax}) ;
      \coordinate (graphe-se) at ({\pflxmax},{\pflymin}) ;
      \coordinate (graphe-sw) at ({\pflxmin},{\pflymin}) ;
      \coordinate (graphe-n) at ($(graphe-ne)!0.5!(graphe-nw)$) ;
      \coordinate (graphe-e) at ($(graphe-ne)!0.5!(graphe-se)$) ;
      \coordinate (graphe-s) at ($(graphe-se)!0.5!(graphe-sw)$) ;
      \coordinate (graphe-w) at ($(graphe-sw)!0.5!(graphe-nw)$) ;
      \coordinate (graphe-c) at ($(graphe-sw)!0.5!(graphe-ne)$) ;
      \coordinate (axeox-w) at ({\pflxmin},{\pflOy}) ;
      \coordinate (axeox-e) at ({\pflxmax},{\pflOy}) ;
      \coordinate (axeoy-s) at ({\pflOx},{\pflymin}) ;
      \coordinate (axeoy-n) at ({\pflOx},{\pflymax}) ;
      \coordinate (axes-orig) at ({\pflOx},{\pflOy}) ;
    }%
    {%
      \coordinate (\pflgraphnom-graphe-ne) at ({\pflxmax},{\pflymax}) ;
      \coordinate (\pflgraphnom-graphe-nw) at ({\pflxmin},{\pflymax}) ;
      \coordinate (\pflgraphnom-graphe-se) at ({\pflxmax},{\pflymin}) ;
      \coordinate (\pflgraphnom-graphe-sw) at ({\pflxmin},{\pflymin}) ;
      \coordinate (\pflgraphnom-graphe-n) at ($(\pflgraphnom-graphe-ne)!0.5!(\pflgraphnom-graphe-nw)$) ;
      \coordinate (\pflgraphnom-graphe-e) at ($(\pflgraphnom-graphe-ne)!0.5!(\pflgraphnom-graphe-se)$) ;
      \coordinate (\pflgraphnom-graphe-s) at ($(\pflgraphnom-graphe-se)!0.5!(\pflgraphnom-graphe-sw)$) ;
      \coordinate (\pflgraphnom-graphe-w) at ($(\pflgraphnom-graphe-sw)!0.5!(\pflgraphnom-graphe-nw)$) ;
      \coordinate (\pflgraphnom-graphe-c) at ($(\pflgraphnom-graphe-sw)!0.5!(\pflgraphnom-graphe-ne)$) ;
      \coordinate (\pflgraphnom-axeox-w) at ({\pflxmin},{\pflOy}) ;
      \coordinate (\pflgraphnom-axeox-e) at ({\pflxmax},{\pflOy}) ;
      \coordinate (\pflgraphnom-axeoy-s) at ({\pflOx},{\pflymin}) ;
      \coordinate (\pflgraphnom-axeoy-n) at ({\pflOx},{\pflymax}) ;
      \coordinate (\pflgraphnom-axes-orig) at ({\pflOx},{\pflOy}) ;
    }%
    %noeuds utiles pour les calculs
    \coordinate (bbxTop) at (current bounding box.north) ;
    \coordinate (bbxBottom) at (current bounding box.south) ;
    \ifboolKV[GraphiqueTikz]{AffCadre}{\draw[pflcadre] ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;}{}%
    %back to normal
}%
{%
  \end{tikzpicture}%
}

%====AXES
\defKV[GraphiqueTikzAxes]{
  Format=\def\pflformataxes{#1},%
  Rotation=\def\pfllanglelabel{#1}%
}
\setKVdefault[GraphiqueTikzAxes]{%
  Grille=true,%
  Grille Intermediaire=false,%
  Elargir=0,%
  Grads=true,%
  Origine=false,%
  Police={},%
  Format=num,%
  Traits=true,%
  Dernier=false,%
  Derriere=false,%
  Devant=false,%
  Fleches=true,%
  Puissance=true,%
  AxeOy=true,%
  Rotation=0%
}

\NewDocumentCommand\FormatterValeurAxex{ m m }{%
  \IfStrEqCase{#1}{%
    {num}{\num{#2}}%
    {annee}{#2}%
    {year}{#2}%
    {frac}{\FormatterFraction{#2}}%
    {dfrac}{\FormatterFraction[d]{#2}}%
    {nfrac}{\FormatterFraction[n]{#2}}%
    {trig}{\FormatterTrigo{#2}}%
    {dtrig}{\FormatterTrigo[d]{#2}}%
    {ntrig}{\FormatterTrigo[n]{#2}}%
    {sqrt}{\FormatterRacine{#2}}%
    {dsqrt}{\FormatterRacine[d]{#2}}%
    {nsqrt}{\FormatterRacine[n]{#2}}%
  }[#2]%
}

\NewDocumentCommand\FormatterValeurAxey{ m m }{%
  \IfStrEqCase{#1}{%
    {num}{\num{#2}}%
    {annee}{#2}%
    {year}{#2}%
    {frac}{\FormatterRacine{#2}}%
    {dfrac}{\FormatterFraction[d]{#2}}%
    {nfrac}{\FormatterFraction[n]{#2}}%
    {trig}{\FormatterTrigo{#2}}%
    {dtrig}{\FormatterTrigo[d]{#2}}%
    {ntrig}{\FormatterTrigo[n]{#2}}%
    {sqrt}{\FormatterRacine{#2}}%
    {dsqrt}{\FormatterRacine[d]{#2}}%
    {nsqrt}{\FormatterRacine[n]{#2}}%
  }[#2]%
}

\NewDocumentCommand\TracerAxesGrilles{ s O{} m D<>{#3} m D<>{#5} }{%
  \restoreKV[GraphiqueTikzAxes]%
  \setKV[GraphiqueTikzAxes]{#2}%
  %nœuds axes élargis
  \IfStrEq{\pflgraphnom}{}%
  {%
    \coordinate (axeox-ee) at ([xshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflxmax},{\pflOy}) ;
    \coordinate (axeoy-nn) at ([yshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflOx},{\pflymax}) ;
  }%
  {%
    \coordinate (\pflgraphnom-axeox-ee) at ([xshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflxmax},{\pflOy}) ;
    \coordinate (\pflgraphnom-axeoy-nn) at ([yshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflOx},{\pflymax}) ;
  }%
  %cas particuliers sous/sur impression
  \ifboolKV[GraphiqueTikzAxes]{Derriere}%
    {%
      \setKV[GraphiqueTikzAxes]{Grads=false}
    }%
    {}%
  \ifboolKV[GraphiqueTikzAxes]{Devant}%
    {%
      \setKV[GraphiqueTikzAxes]{Grille=false}
    }%
    {}%
  %suite
  \IfSubStr{\pflformataxes}{/}%
    {%
      \StrCut{\pflformataxes}{/}{\pflformataxex}{\pflformataxey}%
    }%
    {%
      \xdef\pflformataxex{\pflformataxes}\xdef\pflformataxey{\pflformataxes}%
    }%
  \ifboolKV[GraphiqueTikzAxes]{Grille}%
    {%
      \ifboolKV[GraphiqueTikz]{Milli}%
        {%
          \draw[pflgrilles,xstep=\fpeval{0.1*\pflgrillex},ystep=\fpeval{0.1*\pflgrilley}] ({\pflxmin},{\pflymin}) grid ({\pflxmax},{\pflymax});
          \draw[pflgrillei,xstep=\fpeval{0.5*\pflgrillex},ystep=\fpeval{0.5*\pflgrilley}] ({\pflxmin},{\pflymin}) grid ({\pflxmax},{\pflymax});
        }%
        {%
          \draw[pflgrilles,xstep=\pflgrillexs,ystep=\pflgrilleys] ({\pflxmin},{\pflymin}) grid ({\pflxmax},{\pflymax});
        }%
        \ifboolKV[GraphiqueTikzAxes]{Grille Intermediaire}%
          {%
            \draw[pflgrillei,xstep=\pflgrillexi,ystep=\pflgrilleyi] ({\pflxmin},{\pflymin}) grid ({\pflxmax},{\pflymax});
          }%
          {}%
      \draw[pflgrillep,xstep=\pflgrillex,ystep=\pflgrilley] ({\pflxmin},{\pflymin}) grid ({\pflxmax},{\pflymax});
      \ifboolKV[GraphiqueTikzAxes]{Dernier}%
        {%
          \draw[pflgrillep] ({\pflxmin},{\pflymax})--({\pflxmax},{\pflymax}) ;
          \draw[pflgrillep] ({\pflxmax},{\pflymin})--({\pflxmax},{\pflymax}) ;
        }%
        {}%
    }%
    {}%
  %axes
  \ifboolKV[GraphiqueTikzAxes]{Fleches}%
    {%
      \draw[pflaxes] ({\pflxmin},{\pflOy}) -- ([xshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflxmax},{\pflOy}) ;
      \ifboolKV[GraphiqueTikzAxes]{AxeOy}%
        {%
          \draw[pflaxes] ({\pflOx},{\pflymin}) -- ([yshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflOx},{\pflymax}) ;
        }%
        {}%
    }%
    {%
      \draw[pflaxessansfleche] ({\pflxmin},{\pflOy}) -- ([xshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflxmax},{\pflOy}) ;
      \ifboolKV[GraphiqueTikzAxes]{AxeOy}%
        {%
          \draw[pflaxessansfleche] ({\pflOx},{\pflymin}) -- ([yshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflOx},{\pflymax}) ;
        }%
        {}%
    }%
  \IfEq{#3}{auto}%
    {%
      \xdef\tmprangexvalues{\xintfloateval{seq(i,i=\pflOx..[\pflgrillex]..\pflxmax),seq(i,i=\pflOx-\pflgrillex..[-\pflgrillex]..\pflxmin)}}%
      %seq(i,i=\pflxmin..[\pflgrillex]..\pflxmax)}}\StrDel{\tmprangexvalues}{ }[\tmprangexvalues]%
      \xdef\pflformataxex{num}%
    }%
    {%
      \xdef\tmprangexvalues{#3}%
    }%
  \IfEq{#5}{auto}%
    {%
      \xdef\tmprangeyvalues{\xintfloateval{seq(i,i=\pflOy..[\pflgrilley]..\pflymax),seq(i,i=\pflOy-\pflgrilley..[-\pflgrilley]..\pflymin)}}%
      %\xintfloateval{seq(i,i=\pflymin..[\pflgrilley]..\pflymax)}}\StrDel{\tmprangeyvalues}{ }[\tmprangeyvalues]%
      \xdef\pflformataxey{num}%
    }%
    {%
      \xdef\tmprangeyvalues{#5}%
    }%
  \foreach \x in \tmprangexvalues {\draw[pfltrait] ([yshift=\pflthickgradu]{\x},{\pflOy}) -- ([yshift=-\pflthickgradd]{\x},{\pflOy}) ;}% ++(0,{-2\pflthickgrad}) ;}
  \ifboolKV[GraphiqueTikzAxes]{AxeOy}%
    {%
      \foreach \y in \tmprangeyvalues {\draw[pfltrait] ([xshift=\pflthickgradu]{\pflOx},{\y}) -- ([xshift=-\pflthickgradd]{\pflOx},{\y}) ;}%++({-2\pflthickgrad},0) ;}
    }%
    {}%
  \ifboolKV[GraphiqueTikzAxes]{Grads}%
    {%
      %origine
      \ifboolKV[GraphiqueTikzAxes]{Origine}%
        {%
          \draw ({\pflOx},{\pflOy}) node[pflnoeud,below left,font={\useKV[GraphiqueTikzAxes]{Police}}] {\FormatterValeurAxex{\pflformataxex}{\pflOx}} ;
        }%
        {}%
      %graduations x, sauf si auto...
      \foreach \x in \tmprangexvalues {%
        \IfBooleanTF{#1}%
          {%
            \xintifboolexpr{\x == \pflOx}{}{\draw ([yshift={-\pflthickgradd}]{\x},{\pflOy}) node[pflnoeud,below,font={\useKV[GraphiqueTikzAxes]{Police}}] {\FormatterValeurAxex{\pflformataxex}{\x}} ;}
          }%
          {%
            \draw ([yshift={-\pflthickgradd}]{\x},{\pflOy}) node[pflnoeud,below,font={\useKV[GraphiqueTikzAxes]{Police}}] {\FormatterValeurAxex{\pflformataxex}{\x}} ;
          }%
        }%
      \ifboolKV[GraphiqueTikzAxes]{AxeOy}%
        {%
          \foreach \y in \tmprangeyvalues {%
            \IfBooleanTF{#1}%
              {%
                \xintifboolexpr{\y == \pflOy}{}{\draw ([xshift={-\pflthickgradd}]{\pflOx},{\y}) node[pflnoeud,left,font={\useKV[GraphiqueTikzAxes]{Police}}] {\FormatterValeurAxey{\pflformataxey}{\y}} ;}
              }%
              {%
                \draw ([xshift={-\pflthickgradd}]{\pflOx},{\y}) node[pflnoeud,left,font={\useKV[GraphiqueTikzAxes]{Police}}] {\FormatterValeurAxey{\pflformataxey}{\y}} ;
              }%
            }%
        }%
        {}%
    }%
    {
      \ifboolKV[GraphiqueTikzAxes]{Origine}%
        {%
          \draw ({\pflOx},{\pflOy}) node[pflnoeud,below left,font={\useKV[GraphiqueTikzAxes]{Police}}] {\FormatterValeurAxex{\pflformataxex}{\pflOx}} ;
        }%
        {}%
    }%
}

\NewDocumentCommand\TracerAxesGrillePol{ O{} m m }{%
  \restoreKV[GraphiqueTikzAxes]%
  \setKV[GraphiqueTikzAxes]{#1}%
  %cercles secondaires
  \foreach \r in {\pflpolgrids,\fpeval{2*\pflpolgrids},...,\pflpolrayonmax}{%
    \draw[pflgrilles] (0,0) circle[radius=\r] ;
  }%
  %cercles ppaux
  \foreach \r in {\pflpolgrid,\fpeval{2*\pflpolgrid},...,\pflpolrayonmax}{%
    \draw[pflgrillep] (0,0) circle[radius=\r] ;
  }%
  %droites radiales secondaires
  \foreach \a in {0,\pflgrillets,...,180}{%
    \draw[pflgrilles] ({-(\pflpolrayonmax)*cos(\a)},{-(\pflpolrayonmax)*sin(\a)}) --
    ({(\pflpolrayonmax)*cos(\a)},{(\pflpolrayonmax)*sin(\a)}) ;
  }%
  %droites radiales ppales
  \foreach \a in {0,\pflgrillet,...,180}{%
    \draw[pflgrillep] ({-(\pflpolrayonmax)*cos(\a)},{-(\pflpolrayonmax)*sin(\a)}) --
    ({(\pflpolrayonmax)*cos(\a)},{(\pflpolrayonmax)*sin(\a)}) ;
  }%
  %ensuite les axes, via la macro principale
  \TracerAxesGrilles[#1,Grille=false]{#2}{#3}
}

%===DEFINIR POINTS
\setKVdefault[GraphiqueTikzDefPoints]{Couleur=black,Aff=false,Style=o}

\NewDocumentCommand\DefinirPts{ O{} m }{%
  \restoreKV[GraphiqueTikzDefPoints]%
  \setKV[GraphiqueTikzDefPoints]{#1}%
  \foreach \tmpnamept/\tmpxpt/\tmpypt in {#2}{%
  \coordinate (\tmpnamept) at ({\tmpxpt},{\tmpypt}) ;
    \ifboolKV[GraphiqueTikzDefPoints]{Aff}%
      {%
        \MarquerPts*[Style={\useKV[GraphiqueTikzDefPoints]{Style}},Couleur={\useKV[GraphiqueTikzDefPoints]{Couleur}}]{(\tmpnamept)}
      }%
      {}%
  }
}

\defKV[GraphiqueTikzMarkPoints]{%
  Couleur=\def\pflcouleurpoints{#1},%
  Style=\def\pflstylepoints{#1}
}
\setKVdefault[GraphiqueTikzMarkPoints]{%
  Couleur=black,%
  Taillec=2pt,%
  Taillex=2pt,%
  Tailleo=1.75pt,%
  Style=o,%
  Traits=false,%
  ModeTransfo={}
}
\NewDocumentCommand\MarquerPts{ s O{} D<>{\normalfont\normalsize} m }{%
  %étoilée = sans label
  %2=clés
  %3=points
  \restoreKV[GraphiqueTikzMarkPoints]%
  \setKV[GraphiqueTikzMarkPoints]{#2}%
  \IfBooleanTF{#1}%
    {%
      \IfStrEq{\pflstylepoints}{x}%
        {%
          \foreach \Point in {#4} {%
            \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
              {%
                \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \draw[color=\pflcouleurpoints] \Point pic{pflptcroix={\useKV[GraphiqueTikzMarkPoints]{Taillex}}/45} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{+}%
        {%
          \foreach \Point in {#4} {%
            \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
              {%
                \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \draw[color=\pflcouleurpoints] \Point pic{pflptcroix={\useKV[GraphiqueTikzMarkPoints]{Taillex}}/90} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{c}%
        {%
          \foreach \Point in {#4} {%
            \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
              {%
                \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \filldraw[draw=none,fill=\pflcouleurpoints] \Point pic{pflptcarre={\useKV[GraphiqueTikzMarkPoints]{Taillec}}/0} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{d}%
        {%
          \foreach \Point in {#4} {%
            \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
              {%
                \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \filldraw[draw=none,fill=\pflcouleurpoints] \Point pic{pflptcarre={\useKV[GraphiqueTikzMarkPoints]{Tailleo}}/45} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{o}%
        {%
          \IfSubStr{\pflcouleurpoints}{/}%
            {%
              \StrCut{\pflcouleurpoints}{/}{\pflcouleurpointsA}{\pflcouleurpointsB}%
              \foreach \Point in {#4} {%
                \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
                  {%
                    \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \filldraw[pfltrait,fill=\pflcouleurpointsB,draw=\pflcouleurpointsA] \Point circle[radius={\useKV[GraphiqueTikzMarkPoints]{Tailleo}}] ;
              }%
            }%
            {%
              \foreach \Point in {#4} {%
                \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
                  {%
                    \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \filldraw[color=\pflcouleurpoints] \Point circle[radius={\useKV[GraphiqueTikzMarkPoints]{Tailleo}}] ;
              }%
            }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{ggb}%
        {%
          \IfSubStr{\pflcouleurpoints}{/}%
            {%
              \StrCut{\pflcouleurpoints}{/}{\pflcouleurpointsA}{\pflcouleurpointsB}%
              \foreach \Point/\Label/\Pos in {#4} {%
                \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
                  {%
                    \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \draw[pflpointggb,color=\pflcouleurpointsA,fill=\pflcouleurpointsB] \Point circle[radius={\useKV[GraphiqueTikzMarkPoints]{Tailleo}}] ;
              }%
            }%
            {%
              \foreach \Point/\Label/\Pos in {#4} {%
                \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
                  {%
                    \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \filldraw[color=\pflcouleurpoints] \Point circle[radius={\useKV[GraphiqueTikzMarkPoints]{Tailleo}}] ;
              }%
            }%
        }%
        {}%
    }%
    {%avec label
      \IfStrEq{\pflstylepoints}{x}%
        {%
          \foreach \Point/\Label/\Pos in {#4} {%
            \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
              {%
                \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \draw[color=\pflcouleurpoints] \Point pic{pflptcroix={\useKV[GraphiqueTikzMarkPoints]{Taillex}}/45} node[pflnoeud,\Pos,font=#3] {\Label} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{+}%
        {%
          \foreach \Point/\Label/\Pos in {#4} {%
            \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
              {%
                \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \draw[color=\pflcouleurpoints] \Point pic{pflptcroix={\useKV[GraphiqueTikzMarkPoints]{Taillex}}/90} node[pflnoeud,\Pos,font=#3] {\Label} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{c}%
        {%
          \foreach \Point/\Label/\Pos in {#4} {%
            \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
              {%
                \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \filldraw[draw=none,fill=\pflcouleurpoints] \Point pic{pflptcarre={\useKV[GraphiqueTikzMarkPoints]{Taillec}}/0} node[pflnoeud,\Pos,text=\pflcouleurpoints,font=#3] {\Label} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{d}%
        {%
          \foreach \Point/\Label/\Pos in {#4} {%
            \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
              {%
                \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \filldraw[draw=none,fill=\pflcouleurpoints] \Point pic{pflptcarre={\useKV[GraphiqueTikzMarkPoints]{Tailleo}}/45} node[pflnoeud,\Pos,text=\pflcouleurpoints,font=#3] {\Label} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{o}%
        {%
          \IfSubStr{\pflcouleurpoints}{/}%
            {%
              \StrCut{\pflcouleurpoints}{/}{\pflcouleurpointsA}{\pflcouleurpointsB}%
              \foreach \Point/\Label/\Pos in {#4} {%
                \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
                  {%
                    \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \draw[pfltrait,color=\pflcouleurpointsA,fill=\pflcouleurpointsB] \Point circle[radius={\useKV[GraphiqueTikzMarkPoints]{Tailleo}}] node[pflnoeud,\Pos,font=#3] {\Label} ;
              }%
            }%
            {%
              \foreach \Point/\Label/\Pos in {#4} {%
                \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
                  {%
                    \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \filldraw[color=\pflcouleurpoints] \Point circle[radius={\useKV[GraphiqueTikzMarkPoints]{Tailleo}}] node[pflnoeud,\Pos,font=#3] {\Label} ;
              }%
            }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{ggb}%
        {%
          \IfSubStr{\pflcouleurpoints}{/}%
            {%
              \StrCut{\pflcouleurpoints}{/}{\pflcouleurpointsA}{\pflcouleurpointsB}%
              \foreach \Point/\Label/\Pos in {#4} {%
                \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
                  {%
                    \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \draw[pflpointggb,color=\pflcouleurpointsA,fill=\pflcouleurpointsB] \Point circle[radius={\useKV[GraphiqueTikzMarkPoints]{Tailleo}}] node[pflnoeud,\Pos,font=#3] {\Label} ;
              }%
            }%
            {%
              \foreach \Point/\Label/\Pos in {#4} {%
                \ifboolKV[GraphiqueTikzMarkPoints]{Traits}%
                  {%
                    \draw[color=\pflcouleurpoints,pfltraitantec] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \filldraw[color=\pflcouleurpoints] \Point circle[radius={\useKV[GraphiqueTikzMarkPoints]{Tailleo}}] node[pflnoeud,\Pos,font=#3] {\Label} ;
              }%
            }%
        }%
        {}%
    }%
}

%===AJOUTER DES VALEURS MANUELLEMENT
\NewDocumentCommand\RajouterValeursAxeX{ O{} m m }{%
  \restoreKV[GraphiqueTikzAxes]%
  \setKV[GraphiqueTikzAxes]{#1}%
  \ifboolKV[GraphiqueTikzAxes]{Traits}{\foreach \x in {#2}{\draw[pfltrait] ([yshift=\pflthickgradu]{\x},{\pflOy})--++(0,{-\pflthickgradu-\pflthickgradd}) ;}}{}%
  \setsepchar{,}%
  \readlist*\LstValX{#2}%
  \readlist*\LstValFmtX{#3}%
  \foreach \i in {1,...,\LstValXlen}{%
    \itemtomacro\LstValX[\i]\mavalx%
    \itemtomacro\LstValFmtX[\i]\mavalfmtx%
    \draw ([yshift={-\pflthickgradd}]{\mavalx},{\pflOy}) node[pflnoeud,below,font={\useKV[GraphiqueTikzAxes]{Police}}] {\mavalfmtx} ;
  }%
}

\NewDocumentCommand\RajouterValeursAxeY{ O{} m m }{%
  \restoreKV[GraphiqueTikzAxes]%
  \setKV[GraphiqueTikzAxes]{#1}%
  \ifboolKV[GraphiqueTikzAxes]{Traits}{\foreach \y in {#2}{\draw[pfltrait] ([xshift=\pflthickgradu]{\pflOx},{\y})--++({-\pflthickgradu-\pflthickgradd},0) ;}}{}%
  \setsepchar{,}%
  \readlist*\LstValY{#2}%
  \readlist*\LstValFmtY{#3}%
  \foreach \i in {1,...,\LstValYlen}{%
    \itemtomacro\LstValY[\i]\mavaly%
    \itemtomacro\LstValFmtY[\i]\mavalfmty%
    \draw ([xshift={-\pflthickgradd}]{\pflOx},{\mavaly}) node[pflnoeud,left,font={\useKV[GraphiqueTikzAxes]{Police}}] {\mavalfmty} ;
  }%
}

\NewDocumentCommand\RajouterLabelsAxeX{ O{} m m }{%
  \restoreKV[GraphiqueTikzAxes]%
  \setKV[GraphiqueTikzAxes]{#1}%
  \ifboolKV[GraphiqueTikzAxes]{Traits}{\foreach \x in {#2}{\draw[pfltrait] ([yshift=\pflthickgradu]{\x},{\pflOy})--++(0,{-\pflthickgradu-\pflthickgradd}) ;}}{}%
  \IfEq{\pfllanglelabel}{0}%
    {%
      \tikzset{pfllegendelabelsqualix/.style={font=\small,below}}
    }%
    {%
      \xintifboolexpr{ \pfllanglelabel > 0 }%
        {%
          \tikzset{pfllegendelabelsqualix/.style={font=\small,rotate=\pfllanglelabel,anchor=east}}
        }%
        {%
          \tikzset{pfllegendelabelsqualix/.style={font=\small,rotate=\pfllanglelabel,anchor=west}}
        }%
    }%
  \setsepchar{,}%
  \readlist*\LstValX{#2}%
  \readlist*\LstValFmtX{#3}%
  \foreach \i in {1,...,\LstValXlen}{%
    \itemtomacro\LstValX[\i]\mavalx%
    \itemtomacro\LstValFmtX[\i]\mavalfmtx%
    \draw ([yshift={-\pflthickgradd}]{\mavalx},{\pflOy}) node[pfllegendelabelsqualix,font={\useKV[GraphiqueTikzAxes]{Police}}] {\mavalfmtx} ;
  }%
}

\NewDocumentCommand\RajouterLabelsAxeY{ O{} m m }{%
  \restoreKV[GraphiqueTikzAxes]%
  \setKV[GraphiqueTikzAxes]{#1}%
  \ifboolKV[GraphiqueTikzAxes]{Traits}{\foreach \y in {#2}{\draw[pfltrait] ([xshift=\pflthickgradu]{\pflOx},{\y})--++({-\pflthickgradu-\pflthickgradd},0) ;}}{}%
  \IfEq{\pfllanglelabel}{0}%
    {%
      \tikzset{pfllegendelabelsqualiy/.style={font=\small,left}}
    }%
    {%
      \tikzset{pfllegendelabelsqualiy/.style={font=\small,left,rotate=\pfllanglelabel,anchor=east}}
    }%
  \setsepchar{,}%
  \readlist*\LstValY{#2}%
  \readlist*\LstValFmtY{#3}%
  \foreach \i in {1,...,\LstValYlen}{%
    \itemtomacro\LstValY[\i]\mavaly%
    \itemtomacro\LstValFmtY[\i]\mavalfmty%
    \draw ([xshift={-\pflthickgradd}]{\pflOx},{\mavaly}) node[pfllegendelabelsqualiy,font={\useKV[GraphiqueTikzAxes]{Police}}] {\mavalfmty} ;
  }%
}

\NewDocumentCommand\GenererPolynomeLagrange{ O{polylagrange} m m }{% (merci jfb pour son aide !!!!!!!!!!) syntaxe particulière
  % #1 = argument optionnel, nom du polynôme complet polylagrange
  % #2 = liste séparée par virgules x_1, ..., x_N
  % #3 = liste séparée par virgules y_1, ..., y_N
  % -------------------------------
  % #2 et #3 peuvent être n'importe quoi dont l'expansion complète
  % donne le même nombre de termes séparés par des virgules.
  % De plus ils peuvent utiliser la syntaxe de xint.
  % -------------------------------
  \xintdeffloatvar tmp_List_X = [#2];%
  \xintdeffloatvar tmp_List_Y = [#3];%
  % récupérer la longueur
  \edef\tmpN{\xinteval{len(*tmp_List_X)}}%
  % assigner les entrées à des variables temporaires
  \xintdeffloatvar \xintiloop [1+1] tmp_x_\xintiloopindex
  \ifnum\xintiloopindex<\tmpN\space,\repeat=*tmp_List_X;%
  \xintdeffloatvar \xintiloop [1+1] tmp_y_\xintiloopindex
  \ifnum\xintiloopindex<\tmpN\space,\repeat=*tmp_List_Y;%
  % Définition de polynômes interpolateurs élémentaires
  % Attention lorsque l'on va définir le polynôme final
  % comme combinaison linéaire, les polynômes élémentaires
  % resteront présents par leurs symboles car ils auront
  % une indéterminée comme variable.
  % Il faut donc que leurs noms soient dans le même namespace
  % que le polynôme final.  C'est donc ici #1 le name space. (OK !)
  \xintFor* ##1 in {\xintSeq{1}{\tmpN}}\do{%
    \xintdeffloatfunc #1_##1(x) =
    iter(1; (i==##1)?{omit}{@*(x - tmp_x_\xintiieval{i})}, i=1..\tmpN)/
    iter(1; (i==##1)?{omit}{@*(tmp_x_##1 - tmp_x_\xintiieval{i})}, i=1..\tmpN);%
    }%
  % Définition du polynôme somme des y_i * L_i(x) \xintdeffunc Lagrange(x)
  \xintdeffloatfunc #1(x) = add(tmp_y_\xinteval{i} * #1_\xinteval{i}(x), i=1..\tmpN);%
}
\NewCommandCopy\DefineLagrangeCurve\GenererPolynomeLagrange

\NewDocumentCommand\MarquerPtsLagrange{ s O{} D<>{\normalfont\normalsize} m m }{%
  %#4 & #5 = liste des points, comme pour générer
  \setsepchar{,}%
  \readlist*\lagrangepointsabs{#4}%
  \readlist*\lagrangepointsordo{#5}%
  \foreach \i in {1,...,\lagrangepointsabslen}{%
    \IfBooleanTF{#1}%
      {\MarquerPts*[#2]<#3>{({\lagrangepointsabs[\i]},{\lagrangepointsordo[\i]})}}%
      {\MarquerPts[#2]<#3>{({\lagrangepointsabs[\i]},{\lagrangepointsordo[\i]})}}%
  }%
}

%====FONCTIONS ET COURBES 'classique + interpo + spline + dérivée + primitive'
\defKV[GraphiqueTikzCourbe]{%
  Couleur=\def\pflcoulcurve{#1},%
  Pas=\def\pflstepcurve{#1},%
  Nom=\def\pflnamecurve{#1},%
  StyleTrace=\def\pflstylecurve{#1},%
  DeltaVI=\def\pfldeltavi{#1},%
  h=\def\pflhderiv{#1},%
  ValeursInterdites=\def\pflvalsinterdites{#1},%
  Sens=\def\pflsensparab{#1}
}
\setKVdefault[GraphiqueTikzCourbe]{%
  Couleur=black,%
  Debut={\pflxmin},%
  Fin={\pflxmax},%
  Pas={},%
  Clip=true,%
  Nom={},%
  Trace=false,%
  Tension=0.5,%
  StyleTrace={},%
  RestreindreY=false,%
  Restreindre=false,%
  h={},%
  DeltaVI={auto},%
  Spline=false,%
  ValeursInterdites={},%
  Sens=V,%
  DefGlobale=false
}

\NewDocumentCommand\DefinirFonction{ O{} D<>{f} m }{%old version
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  \xintdeffloatfunc #2(x) := #3 ;
  \IfStrEq{\pflstepcurve}{}%
  {%
    \IfStrEq{\pflvalsinterdites}{}%
      {%
        \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/200}}%
      }%
      {%
        \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/250}}%
      }%
  }%
  {}%
  \ifboolKV[GraphiqueTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}
  %suite
  \ifboolKV[GraphiqueTikzCourbe]{Trace}%
  {%
    \path[draw,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
    plot[smooth] coordinates {%
      \xintthecoords\xintfloatexpr seq((x,#2(x)),x={\useKV[GraphiqueTikzCourbe]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzCourbe]{Fin}},{\useKV[GraphiqueTikzCourbe]{Fin}})
      \relax}
    ;
  }%
  {%
    \path[draw=none,pflcourbe,color=\pflcoulcurve,name path global=\pflnamecurve] plot[smooth] coordinates {%
    \xintthecoords\xintfloatexpr
    seq((x,#2(x)),x={\useKV[GraphiqueTikzCourbe]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzCourbe]{Fin}},{\useKV[GraphiqueTikzCourbe]{Fin}})
    \relax
    };
  }%
  \ifboolKV[GraphiqueTikzCourbe]{Clip}{\end{scope}}{}
  }

\NewDocumentCommand\DefinirCourbe{ O{} D<>{f} m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  \ifboolKV[GraphiqueTikzCourbe]{DefGlobale}{\xintglobaldefstrue}{}%
  \xintdeffloatfunc #2(x) := #3 ;
  \ifboolKV[GraphiqueTikzCourbe]{DefGlobale}{\xintglobaldefsfalse}{}%
  %test dimension too large
  \xdef\pfloffsetV{\xintfloateval{((\pflymax)-(\pflymin))/20}}%
  \xdef\pflMinoffsetV{\xintfloateval{(\pflymin)-(\pfloffsetV)}}%
  \xdef\pflMaxoffsetV{\xintfloateval{(\pflymax)+(\pfloffsetV)}}%
  %bifurcation BI/noVI
  \IfStrEq{\pflvalsinterdites}{}%
    {%si pas de VI, code direct
      \IfStrEq{\pflstepcurve}{}%
        {%
          \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/200}}%
        }%
        {}%
      \ifboolKV[GraphiqueTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}
      \ifboolKV[GraphiqueTikzCourbe]{Trace}%
      {%
        \ifboolKV[GraphiqueTikzCourbe]{RestreindreY}%
        {%
          \path[draw,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
            plot[smooth] coordinates {%
            \xintthecoords\xintfloatexpr
            seq((x,min(max(#2(x),\pflMinoffsetV),\pflMaxoffsetV)),x={\useKV[GraphiqueTikzCourbe]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzCourbe]{Fin}},{\useKV[GraphiqueTikzCourbe]{Fin}})
            \relax
          };
        }%
        {%
          \path[draw,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
            plot[smooth] coordinates {%
            \xintthecoords\xintfloatexpr
            seq((x,#2(x)),x={\useKV[GraphiqueTikzCourbe]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzCourbe]{Fin}},{\useKV[GraphiqueTikzCourbe]{Fin}})
            \relax
          };
        }%
      }%
      {%
        \ifboolKV[GraphiqueTikzCourbe]{RestreindreY}%
        {%
          \path[draw=none,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
            plot[smooth] coordinates {%
            \xintthecoords\xintfloatexpr
            seq((x,min(max(#2(x),\pflMinoffsetV),\pflMaxoffsetV)),x={\useKV[GraphiqueTikzCourbe]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzCourbe]{Fin}},{\useKV[GraphiqueTikzCourbe]{Fin}})
            \relax
          };
        }%
        {%
          \path[draw=none,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
            plot[smooth] coordinates {%
            \xintthecoords\xintfloatexpr
            seq((x,#2(x)),x={\useKV[GraphiqueTikzCourbe]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzCourbe]{Fin}},{\useKV[GraphiqueTikzCourbe]{Fin}})
            \relax
          };
        }%
      }%
      \ifboolKV[GraphiqueTikzCourbe]{Clip}{\end{scope}}{}
    }%
    {%sinon, VI, code spécifique
      \IfStrEq{\pfldeltavi}{auto}%
       {%
         \xdef\pfldeltavi{\xintfloateval{((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/250}}%
       }%
       {}%
      \IfStrEq{\pflstepcurve}{}%
        {%
          \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/250}}%
        }%
        {}%
      %génération des branches, si VI
      \edef\pflvalsinterditesexp{\pflvalsinterdites}%
      \xdef\pfllistebornes{\useKV[GraphiqueTikzCourbe]{Debut}}%
      \foreach \i in \pflvalsinterditesexp {%
        %\xdef\pfllistebornes{\pfllistebornes,\xintfloateval{\i-(\pflstepcurve)},\xintfloateval{\i+(\pflstepcurve)}}%\pfldeltavi
        \xdef\pfllistebornes{\pfllistebornes,\xintfloateval{\i-(\pfldeltavi)},\xintfloateval{\i+(\pfldeltavi)}}%
      }%
      \xdef\pfllistebornes{\pfllistebornes,\useKV[GraphiqueTikzCourbe]{Fin}}%
      \setsepchar{,}%
      \readlist*\tkzintlistebornes{\pfllistebornes}%
      \xdef\tkzgrphnbbranches{\fpeval{\tkzintlisteborneslen/2}}%
      %suite
      \ifboolKV[GraphiqueTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}
      \ifboolKV[GraphiqueTikzCourbe]{Trace}%
        {%
          \path[draw,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
            \foreach \ib [evaluate=\ib as \ibdeb using {int(2*\ib-1)},evaluate=\ib as \ibfin using {int(2*\ib)}] in {1,...,\tkzgrphnbbranches}{%
              plot[smooth] coordinates {%
                \xintthecoords\xintfloatexpr seq((x,min(max(#2(x),\pflMinoffsetV),\pflMaxoffsetV)), x={\tkzintlistebornes[\ibdeb]}..[\pflstepcurve]..{\tkzintlistebornes[\ibfin]},{\tkzintlistebornes[\ibfin]}) \relax}
             } ;%
        }%
        {%
          \path[draw=none,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
            \foreach \ib [evaluate=\ib as \ibdeb using {int(2*\ib-1)},evaluate=\ib as \ibfin using {int(2*\ib)}] in {1,...,\tkzgrphnbbranches}{%
              plot[smooth] coordinates {%
                \xintthecoords\xintfloatexpr seq((x,min(max(#2(x),\pflMinoffsetV),\pflMaxoffsetV)), x={\tkzintlistebornes[\ibdeb]}..[\pflstepcurve]..{\tkzintlistebornes[\ibfin]},{\tkzintlistebornes[\ibfin]}) \relax}
             } ;
        }%
        \ifboolKV[GraphiqueTikzCourbe]{Clip}{\end{scope}}{}
    }%
}

\NewDocumentCommand\TracerCourbe{ O{} D<>{} m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  %test dimension too large
  \xdef\pfloffsetV{\xintfloateval{((\pflymax)-(\pflymin))/20}}%
  \xdef\pflMinoffsetV{\xintfloateval{(\pflymin)-(\pfloffsetV)}}%
  \xdef\pflMaxoffsetV{\xintfloateval{(\pflymax)+(\pfloffsetV)}}%
  %bifurcation BI/noVI
  \IfStrEq{\pflvalsinterdites}{}%
    {%si pas de VI, code direct
      \IfStrEq{\pflstepcurve}{}%
        {%
          \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/200}}%
        }%
        {}%
      \ifboolKV[GraphiqueTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}
      \IfStrEq{\pflnamecurve}{}%
        {%
          \ifboolKV[GraphiqueTikzCourbe]{RestreindreY}%
            {%
              \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve]
                plot[smooth] coordinates {%
                \xintthecoords\xintfloatexpr
                seq((x,min(max(#3,\pflMinoffsetV),\pflMaxoffsetV)),x={\useKV[GraphiqueTikzCourbe]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzCourbe]{Fin}},{\useKV[GraphiqueTikzCourbe]{Fin}})
                \relax
              };
            }%
            {%
              \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve]
                plot[smooth] coordinates {%
                \xintthecoords\xintfloatexpr
                seq((x,#3),x={\useKV[GraphiqueTikzCourbe]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzCourbe]{Fin}},{\useKV[GraphiqueTikzCourbe]{Fin}})
                \relax
              };
            }%
        }%
        {%
          \ifboolKV[GraphiqueTikzCourbe]{RestreindreY}%
            {%
              \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
                plot[smooth] coordinates {%
                \xintthecoords\xintfloatexpr
                seq((x,min(max(#3,\pflMinoffsetV),\pflMaxoffsetV)),x={\useKV[GraphiqueTikzCourbe]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzCourbe]{Fin}},{\useKV[GraphiqueTikzCourbe]{Fin}})
                \relax
              };
            }%
            {%
              \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
                plot[smooth] coordinates {%
                \xintthecoords\xintfloatexpr
                seq((x,#3),x={\useKV[GraphiqueTikzCourbe]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzCourbe]{Fin}},{\useKV[GraphiqueTikzCourbe]{Fin}})
                \relax
              };
            }%
        }%
      \ifboolKV[GraphiqueTikzCourbe]{Clip}{\end{scope}}{}
    }%
    {%sinon, VI, code spécifique
      \IfStrEq{\pfldeltavi}{auto}%
       {%
         \xdef\pfldeltavi{\xintfloateval{((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/250}}%
       }%
       {}%
      \IfStrEq{\pflstepcurve}{}%
        {%
          \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/250}}%
        }%
        {}%
      %génération des branches, si VI
      \edef\pflvalsinterditesexp{\pflvalsinterdites}%
      \xdef\pfllistebornes{\useKV[GraphiqueTikzCourbe]{Debut}}%
      \foreach \i in \pflvalsinterditesexp {%
        %\xdef\pfllistebornes{\pfllistebornes,\xintfloateval{\i-(\pflstepcurve)},\xintfloateval{\i+(\pflstepcurve)}}%\pfldeltavi
        \xdef\pfllistebornes{\pfllistebornes,\xintfloateval{\i-(\pfldeltavi)},\xintfloateval{\i+(\pfldeltavi)}}%
      }%
      \xdef\pfllistebornes{\pfllistebornes,\useKV[GraphiqueTikzCourbe]{Fin}}%
      \setsepchar{,}%
      \readlist*\tkzintlistebornes{\pfllistebornes}%
      %\typeout{=== \pfllistebornes ===}
      \xdef\tkzgrphnbbranches{\fpeval{\tkzintlisteborneslen/2}}%
      \ifboolKV[GraphiqueTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}
      \IfStrEq{\pflnamecurve}{}%
        {%
          \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve]
            \foreach \ib [evaluate=\ib as \ibdeb using {int(2*\ib-1)},evaluate=\ib as \ibfin using {int(2*\ib)}] in {1,...,\tkzgrphnbbranches}{%
              plot[smooth] coordinates {%
                \xintthecoords\xintfloatexpr seq((x,min(max(#3,\pflMinoffsetV),\pflMaxoffsetV)), x={\tkzintlistebornes[\ibdeb]}..[\pflstepcurve]..{\tkzintlistebornes[\ibfin]},{\tkzintlistebornes[\ibfin]}) \relax}
            } ;%
        }%
        {%
          \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
            \foreach \ib [evaluate=\ib as \ibdeb using {int(2*\ib-1)},evaluate=\ib as \ibfin using {int(2*\ib)}] in {1,...,\tkzgrphnbbranches}{%
              plot[smooth] coordinates {%
                \xintthecoords\xintfloatexpr seq((x,min(max(#3,\pflMinoffsetV),\pflMaxoffsetV)), x={\tkzintlistebornes[\ibdeb]}..[\pflstepcurve]..{\tkzintlistebornes[\ibfin]},{\tkzintlistebornes[\ibfin]}) \relax}
            } ;%
        }%
      \ifboolKV[GraphiqueTikzCourbe]{Clip}{\end{scope}}{}
    }%
}

\defKV[GraphiqueVoisinageTikz]{%
  Couleurs=\def\tkzgraphcoulvoisin{#1},%
  CouleurAsymptote=\def\tkzgraphcoulasymptvoisin{#1},%
  Opacite=\def\tkzgraphopacvoisin{#1},%
  Entree=\def\tkzgraphentreevoisin{#1},%
  LimiteEn=\def\tkzgraphvalavoisin{#1},%
  TypeLimite=\def\tkzgraphtypevoisin{#1},%
  DebutX=\def\tkzgraphxinitvoisin{#1},%
  FinX=\def\tkzgraphxfinvoisin{#1}
}

\setKVdefault[GraphiqueVoisinageTikz]{%
  Couleurs=blue,%
  CouleurAsymptote=orange,%
  Opacite=0.15,
  Entree=auto,%
  LimiteEn=0,%
  TypeLimite={L en +inf},%
  Asymptote=true,%
  Fleches=true,%
  DebutX=\pflxmin,%
  FinX=\pflxmax
}

\NewDocumentCommand\AfficherVoisinage{ O{} D<>{cf} m m }{%
  %#1 = Clés
  %#2 = nom de la courbe
  %#3 = limite/seuil
  %#4 = epsilon si besoin
  \restoreKV[GraphiqueVoisinageTikz]%
  \setKV[GraphiqueVoisinageTikz]{#1}%
  \IfStrEqCase{\tkzgraphtypevoisin}{%
    %------------------------
    %limite finie en +infini%
    {L en +inf}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path tube-haut : y = L+epsilon (droite horizontale)
        % path tube-bas  : y = L-epsilon (droite horizontale)
        \path[pfltraitvoisinage,name path global=pfltubeH] ({\tkzgraphxinitvoisin},{#3+(#4)}) -- ({\pflxmax},{#3+(#4)}) ;
        \path[pfltraitvoisinage,name path global=pfltubeB] ({\tkzgraphxinitvoisin},{#3-(#4)}) -- ({\pflxmax},{#3-(#4)}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pfltubeH,name=pflintH, total=\t}] \pgfextra{\xdef\tmpintHtot{\t}};
        \path[name intersections={of=#2 and pfltubeB,name=pflintB, total=\t}] \pgfextra{\xdef\tmpintBtot{\t}};
        % récupération des dernières abscisses%
        % Cas possibles
        \xintifboolexpr{\tmpintHtot > 0 'and' \tmpintBtot > 0}%
        {% intersection des deux côtés → max des deux dernières abscisses
          \path (pflintH-\tmpintHtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\pflxentreeH{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
          \path (pflintB-\tmpintBtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\pflxentreeB{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
          \xdef\tmpvoisinageentreeX{\xintfloateval{max(\pflxentreeH,\pflxentreeB)}}%
        }%
        {\xintifboolexpr{\tmpintHtot > 0}%
          {% uniquement par le haut
            \path (pflintH-\tmpintHtot) ;
            \pgfgetlastxy{\macrox}{\macroy}%
            \xdef\tmpvoisinageentreeX{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
          }%
          {\xintifboolexpr{\tmpintBtot > 0}%
            {% uniquement par le bas
              \path (pflintB-\tmpintBtot) ;
              \pgfgetlastxy{\macrox}{\macroy}%
              \xdef\tmpvoisinageentreeX{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
            }%
            {% aucune intersection → courbe entièrement dans le tube
              \xdef\tmpvoisinageentreeX{\pflxmin}%
            }%
          }%
        }%
      }%
      {%
        \xdef\tmpvoisinageentreeX{\tkzgraphentreevoisin}%
      }%
      \ifboolKV[GraphiqueVoisinageTikz]{Asymptote}%
        {%
           \draw[pfltraitvoisinage,color=\tkzgraphcoulasymptvoisin] ({\pflxmin},{(#3)}) -- (\pflxmax,{(#3)}) ;
        }%
        {}%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] (\tmpvoisinageentreeX,{(#3)-(#4)}) rectangle ({\pflxmax},{(#3)+(#4)}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\pflxmin},{(#3)-(#4)}) -- (\pflxmax,{(#3)-(#4)}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\pflxmin},{(#3)+(#4)}) -- (\pflxmax,{(#3)+(#4)}) ;
      \draw[pfltraitvoisinage,densely dashed,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{#3-(#4)}) -- ({\tmpvoisinageentreeX},{#3+(#4)}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tmpvoisinageentreeX},{#3+(#4)}) --++ (0,3mm) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tmpvoisinageentreeX},{#3-(#4)}) --++ (0,-3mm) ;
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{#3+(#4)}) --++ (0,3mm) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{#3-(#4)}) --++ (0,-3mm) ;
    }%
    }%
    %------------------------
    %limite finie en -infini%
    {L en -inf}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path tube-haut : y = L+epsilon (droite horizontale)
        % path tube-bas  : y = L-epsilon (droite horizontale)
        \path[pfltraitvoisinage,name path global=pfltubeH] ({\pflxmin},{#3+(#4)}) -- ({\tkzgraphxfinvoisin},{#3+(#4)}) ;
        \path[pfltraitvoisinage,name path global=pfltubeB] ({\pflxmin},{#3-(#4)}) -- ({\tkzgraphxfinvoisin},{#3-(#4)}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pfltubeH,name=pflintH, total=\t}] \pgfextra{\xdef\tmpintHtot{\t}};
        \path[name intersections={of=#2 and pfltubeB,name=pflintB, total=\t}] \pgfextra{\xdef\tmpintBtot{\t}};
        % récupération des dernières abscisses%
        % Cas possibles
        \xintifboolexpr{\tmpintHtot > 0 'and' \tmpintBtot > 0}%
        {% intersection des deux côtés → max des deux dernières abscisses
          \path (pflintH-\tmpintHtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\pflxentreeH{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
          \path (pflintB-\tmpintBtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\pflxentreeB{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
          \xdef\tmpvoisinageentreeX{\xintfloateval{max(\pflxentreeH,\pflxentreeB)}}%
        }%
        {\xintifboolexpr{\tmpintHtot > 0}%
          {% uniquement par le haut
            \path (pflintH-\tmpintHtot) ;
            \pgfgetlastxy{\macrox}{\macroy}%
            \xdef\tmpvoisinageentreeX{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
          }%
          {\xintifboolexpr{\tmpintBtot > 0}%
            {% uniquement par le bas
              \path (pflintB-\tmpintBtot) ;
              \pgfgetlastxy{\macrox}{\macroy}%
              \xdef\tmpvoisinageentreeX{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
            }%
            {% aucune intersection → courbe entièrement dans le tube
              \xdef\tmpvoisinageentreeX{\pflxmax}%
            }%
          }%
        }%
      }%
      {%
        \xdef\tmpvoisinageentreeX{\tkzgraphentreevoisin}%
      }%
    \ifboolKV[GraphiqueVoisinageTikz]{Asymptote}%
        {%
           \draw[pfltraitvoisinage,color=\tkzgraphcoulasymptvoisin] ({\pflxmin},{(#3)}) -- (\pflxmax,{(#3)}) ;
        }%
        {}%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] (\tmpvoisinageentreeX,{(#3)-(#4)}) rectangle ({\pflxmin},{(#3)+(#4)}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\pflxmin},{(#3)-(#4)}) -- (\pflxmax,{(#3)-(#4)}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\pflxmin},{(#3)+(#4)}) -- (\pflxmax,{(#3)+(#4)}) ;
      \draw[pfltraitvoisinage,densely dashed,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{#3-(#4)}) -- ({\tmpvoisinageentreeX},{#3+(#4)}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tmpvoisinageentreeX},{#3+(#4)}) --++ (0,3mm) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tmpvoisinageentreeX},{#3-(#4)}) --++ (0,-3mm) ;
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{#3+(#4)}) --++ (0,3mm) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{#3-(#4)}) --++ (0,-3mm) ;
    }%
    }%
    %------------------------
    %limite infinie en +infini%
    {+inf en +inf}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path seuil : y = #3
        \path[pfltraitvoisinage,name path global=pflseuilvoisin] ({\tkzgraphxinitvoisin},{#3}) -- ({\pflxmax},{#3}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pflseuilvoisin,name=pflintS,total=\t}] \pgfextra{\xdef\tmpintStot{\t}};
        % Cas possibles
        \xintifboolexpr{\tmpintStot > 0}%
      {%
        \path (pflintS-\tmpintStot) ;
            \pgfgetlastxy{\macrox}{\macroy}%
            \xdef\tmpvoisinageentreeX{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
      }%
      {%
        \xdef\tmpvoisinageentreeX{\pflxmin}%
      }%
      }%
      {%
        \xdef\tmpvoisinageentreeX{\tkzgraphentreevoisin}%
      }%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] (\tmpvoisinageentreeX,{(#3)}) rectangle ({\pflxmax},{\pflymax}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\pflxmin},{(#3)}) -- (\pflxmax,{(#3)}) ;
      \draw[pfltraitvoisinage,,densely dashed,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{(#3)}) -- (\tmpvoisinageentreeX,{\pflymax}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tmpvoisinageentreeX},{#3}) --++ (0,-3mm);
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{#3}) --++ (0,-3mm);
    }%
    }%
    %limite -infinie en +infini%
    {-inf en +inf}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path seuil : y = #3
        \path[pfltraitvoisinage,name path global=pflseuilvoisin] ({\pflxmin},{#3}) -- ({\tkzgraphxfinvoisin},{#3}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pflseuilvoisin,name=pflintS,total=\t}] \pgfextra{\xdef\tmpintStot{\t}};
        % Cas possibles
        \xintifboolexpr{\tmpintStot > 0}%
      {%
        \path (pflintS-\tmpintStot) ;
            \pgfgetlastxy{\macrox}{\macroy}%
            \xdef\tmpvoisinageentreeX{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
      }%
      {%
        \xdef\tmpvoisinageentreeX{\pflxmax}%
      }%
      }%
      {%
        \xdef\tmpvoisinageentreeX{\tkzgraphentreevoisin}%
      }%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] (\tmpvoisinageentreeX,{(#3)}) rectangle ({\pflxmax},{\pflymin}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\pflxmin},{(#3)}) -- (\pflxmax,{(#3)}) ;
    \draw[pfltraitvoisinage,,densely dashed,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{(#3)}) -- (\tmpvoisinageentreeX,{\pflymin}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tmpvoisinageentreeX},{#3}) --++ (0,3mm);
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{#3}) --++ (0,3mm);
    }%
    }%
  %limite +infinie en -infini%
    {+inf en -inf}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path seuil : y = #3
        \path[pfltraitvoisinage,name path global=pflseuilvoisin] ({\pflxmin},{#3}) -- ({\tkzgraphxfinvoisin},{#3}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pflseuilvoisin,name=pflintS,total=\t}] \pgfextra{\xdef\tmpintStot{\t}};
        % Cas possibles
        \xintifboolexpr{\tmpintStot > 0}%
      {%
        \path (pflintS-\tmpintStot) ;
            \pgfgetlastxy{\macrox}{\macroy}%
            \xdef\tmpvoisinageentreeX{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
      }%
      {%
        \xdef\tmpvoisinageentreeX{\pflxmin}%
      }%
      }%
      {%
        \xdef\tmpvoisinageentreeX{\tkzgraphentreevoisin}%
      }%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] (\tmpvoisinageentreeX,{(#3)}) rectangle ({\pflxmin},{\pflymax}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\pflxmin},{(#3)}) -- (\pflxmax,{(#3)}) ;
      \draw[pfltraitvoisinage,,densely dashed,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{(#3)}) -- (\tmpvoisinageentreeX,{\pflymax}) ;
      \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tmpvoisinageentreeX},{#3}) --++ (0,-3mm);
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{#3}) --++ (0,-3mm);
    }%
    }%
  %limite +infinie en -infini%
    {-inf en -inf}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path seuil : y = #3
        \path[pfltraitvoisinage,name path global=pflseuilvoisin] ({\pflxmin},{#3}) -- ({\tkzgraphxfinvoisin},{#3}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pflseuilvoisin,name=pflintS,total=\t}] \pgfextra{\xdef\tmpintStot{\t}};
        % Cas possibles
        \xintifboolexpr{\tmpintStot > 0}%
      {%
        \path (pflintS-\tmpintStot) ;
            \pgfgetlastxy{\macrox}{\macroy}%
            \xdef\tmpvoisinageentreeX{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
      }%
      {%
        \xdef\tmpvoisinageentreeX{\pflxmax}%
      }%
      }%
      {%
        \xdef\tmpvoisinageentreeX{\tkzgraphentreevoisin}%
      }%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] (\tmpvoisinageentreeX,{(#3)}) rectangle ({\pflxmin},{\pflymin}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\pflxmin},{(#3)}) -- (\pflxmax,{(#3)}) ;
    \draw[pfltraitvoisinage,densely dashed,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{(#3)}) -- (\tmpvoisinageentreeX,{\pflymin}) ;
      \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tmpvoisinageentreeX},{#3}) --++ (0,3mm);
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tmpvoisinageentreeX},{#3}) --++ (0,3mm);
    }%
    }%
    %------------------------
    %limite infinie en a%
    {+inf en a}
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path tube-haut : x = L+epsilon (droite verticale)
        % path tube-bas  : x = L-epsilon (droite verticale)
        \path[pfltraitvoisinage,name path global=pfltubeG] ({#3-(#4)},{\pflymin}) -- ({#3-(#4)},{\pflymax}) ;
        \path[pfltraitvoisinage,name path global=pfltubeD] ({#3+(#4)},{\pflymin}) -- ({#3+(#4)},{\pflymax}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pfltubeG,name=pflintG, total=\t}] \pgfextra{\xdef\tmpintGtot{\t}};
        \path[name intersections={of=#2 and pfltubeD,name=pflintD, total=\t}] \pgfextra{\xdef\tmpintDtot{\t}};
        % récupération des dernières abscisses%
        % Cas possibles
        \xintifboolexpr{\tmpintGtot > 0 'and' \tmpintDtot > 0}%
        {% intersection des deux côtés → min des deux deltas...
          \path (pflintG-\tmpintGtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\pflyentreeG{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
          \path (pflintD-\tmpintDtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\pflyentreeD{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
      \xdef\pflyentree{\xintfloateval{max(\pflyentreeG,\pflyentreeD)}}%
        }%
        {\xintifboolexpr{\tmpintDtot > 0}%
          {% uniquement par la droite
            \path (pflintD-\tmpintDtot) ;
            \pgfgetlastxy{\macrox}{\macroy}%
            \xdef\pflyentree{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
          }%
          {\xintifboolexpr{\tmpintGtot > 0}%
            {% uniquement par le bas
              \path (pflintG-\tmpintGtot) ;
              \pgfgetlastxy{\macrox}{\macroy}%
              \xdef\pflyentree{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
            }%
            {% aucune intersection → courbe entièrement dans le tube
              \xdef\pflyentree{\pflymin}%
            }%
          }%
        }%
      }%
      {%
        \xdef\pflyentree{\tkzgraphentreevoisin}%
      }%
    \ifboolKV[GraphiqueVoisinageTikz]{Asymptote}%
        {%
           \draw[pfltraitvoisinage,\tkzgraphcoulasymptvoisin] ({(#3)},{\pflymin}) -- ({(#3)},{\pflymax}) ;
        }%
        {}%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] ({(#3)-(#4)},{\pflyentree}) rectangle ({(#3)+(#4)},{\pflymax}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)-(#4)},{\pflymin}) -- ({(#3)-(#4)},{\pflymax}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)+(#4)},{\pflymin}) -- ({(#3)+(#4)},{\pflymax}) ;
    \draw[pfltraitvoisinage,,densely dashed,color=\tkzgraphcoulvoisin] ({(#3)-(#4)},{\pflyentree}) -- ({(#3)+(#4)},{\pflyentree}) ;
      % \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)-(#4)},{\tmpvoisinageentreeY}) -- ({(#3)+(#4)},{\tmpvoisinageentreeY}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3-(#4)},{\pflyentree}) --++ (-3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3+(#4)},{\pflyentree}) --++ (3mm,0) ;
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({#3-(#4)},{\pflyentree}) --++ (-3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({#3+(#4)},{\pflyentree}) --++ (3mm,0) ;
    }%
    }%
  %------------------------
    %limite -infinie en a%
    {-inf en a}
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path tube-haut : x = L+epsilon (droite verticale)
        % path tube-bas  : x = L-epsilon (droite verticale)
        \path[pfltraitvoisinage,name path global=pfltubeG] ({#3-(#4)},{\pflymin}) -- ({#3-(#4)},{\pflymax}) ;
        \path[pfltraitvoisinage,name path global=pfltubeD] ({#3+(#4)},{\pflymin}) -- ({#3+(#4)},{\pflymax}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pfltubeG,name=pflintG, total=\t}] \pgfextra{\xdef\tmpintGtot{\t}};
        \path[name intersections={of=#2 and pfltubeD,name=pflintD, total=\t}] \pgfextra{\xdef\tmpintDtot{\t}};
        % récupération des dernières abscisses%
        % Cas possibles
        \xintifboolexpr{\tmpintGtot > 0 'and' \tmpintDtot > 0}%
        {% intersection des deux côtés
          \path (pflintG-\tmpintGtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\pflyentreeG{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
          \path (pflintD-\tmpintDtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\pflyentreeD{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
      \xdef\pflyentree{\xintfloateval{min(\pflyentreeG,\pflyentreeD)}}%
        }%
        {\xintifboolexpr{\tmpintDtot > 0}%
          {% uniquement par la droite
            \path (pflintD-\tmpintDtot) ;
            \pgfgetlastxy{\macrox}{\macroy}%
            \xdef\pflyentree{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
          }%
          {\xintifboolexpr{\tmpintGtot > 0}%
            {% uniquement par le bas
              \path (pflintG-\tmpintGtot) ;
              \pgfgetlastxy{\macrox}{\macroy}%
              \xdef\pflyentree{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
            }%
            {% aucune intersection → courbe entièrement dans le tube
              \xdef\pflyentree{\pflymax}%
            }%
          }%
        }%
      }%
      {%
        \xdef\pflyentree{\tkzgraphentreevoisin}%
      }%
    \ifboolKV[GraphiqueVoisinageTikz]{Asymptote}%
        {%
           \draw[pfltraitvoisinage,\tkzgraphcoulasymptvoisin] ({(#3)},{\pflymin}) -- ({(#3)},{\pflymax}) ;
        }%
        {}%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] ({(#3)-(#4)},{\pflyentree}) rectangle ({(#3)+(#4)},{\pflymin}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)-(#4)},{\pflymin}) -- ({(#3)-(#4)},{\pflymax}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)+(#4)},{\pflymin}) -- ({(#3)+(#4)},{\pflymax}) ;
      \draw[pfltraitvoisinage,densely dashed,color=\tkzgraphcoulvoisin] ({(#3)-(#4)},{\pflyentree}) -- ({(#3)+(#4)},{\pflyentree}) ;
      % \draw[pfltraitvoisinage,\tkzgraphcoulvoisin] ({(#3)-(#4)},{\tmpvoisinageentreeY}) -- ({(#3)+(#4)},{\tmpvoisinageentreeY}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3-(#4)},{\pflyentree}) --++ (-3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3+(#4)},{\pflyentree}) --++ (3mm,0) ;
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({#3-(#4)},{\pflyentree}) --++ (-3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({#3+(#4)},{\pflyentree}) --++ (3mm,0) ;
    }%
    }%
    %------------------------
    %limite infinie en Ld%
    {+inf en a+}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path tube-haut : x = L+epsilon (droite verticale)
        \path[pfltraitvoisinage,name path global=pfltubeD] ({#3+(#4)},{\pflymin}) -- ({#3+(#4)},{\pflymax}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pfltubeD,name=pflintD, total=\t}] \pgfextra{\xdef\tmpintDtot{\t}};
        % récupération des dernières abscisses%
        % Cas possibles
        \xintifboolexpr{\tmpintDtot > 0}%
        {% uniquement par le haut
          \path (pflintD-\tmpintDtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\tmpvoisinageentreeY{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
        }%
        {% aucune intersection → courbe entièrement dans le tube
          \xdef\tmpvoisinageentreeY{\pflymin}%
        }%
      }%
      {%
        \xdef\tmpvoisinageentreeY{\tkzgraphentreevoisin}%
      }%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] ({(#3)},{\tmpvoisinageentreeY}) rectangle ({(#3)+(#4)},{\pflymax}) ;
      \ifboolKV[GraphiqueVoisinageTikz]{Asymptote}%
        {%
           \draw[pfltraitvoisinage,color=\tkzgraphcoulasymptvoisin] ({(#3)},{\pflymin}) -- ({(#3)},{\pflymax}) ;
        }%
        {}%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)+(#4)},{\pflymin}) -- ({(#3)+(#4)},{\pflymax}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)},{\tmpvoisinageentreeY}) -- ({(#3)+(#4)},{\tmpvoisinageentreeY}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3},{\tmpvoisinageentreeY}) --++ (-3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3+(#4)},{\tmpvoisinageentreeY}) --++ (3mm,0) ;
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3},{\tmpvoisinageentreeY}) --++ (-3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3+(#4)},{\tmpvoisinageentreeY}) --++ (3mm,0) ;
    }%
    }%
  %------------------------
    %limite infinie en Lg%
    {+inf en a-}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path tube-haut : x = L+epsilon (droite verticale)
        \path[pfltraitvoisinage,name path global=pfltubeD] ({#3-(#4)},{\pflymin}) -- ({#3-(#4)},{\pflymax}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pfltubeD,name=pflintD, total=\t}] \pgfextra{\xdef\tmpintDtot{\t}};
        % récupération des dernières abscisses%
        % Cas possibles
        \xintifboolexpr{\tmpintDtot > 0}%
        {% uniquement par le haut
          \path (pflintD-\tmpintDtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\tmpvoisinageentreeY{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
        }%
        {% aucune intersection → courbe entièrement dans le tube
              \xdef\tmpvoisinageentreeY{\pflymin}%
        }%
      }%
      {%
        \xdef\tmpvoisinageentreeY{\tkzgraphentreevoisin}%
      }%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] ({(#3)},{\tmpvoisinageentreeY}) rectangle ({(#3)-(#4)},{\pflymax}) ;
      \ifboolKV[GraphiqueVoisinageTikz]{Asymptote}%
        {%
           \draw[pfltraitvoisinage,color=\tkzgraphcoulasymptvoisin] ({(#3)},{\pflymin}) -- ({(#3)},{\pflymax}) ;
        }%
        {}%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)-(#4)},{\pflymin}) -- ({(#3)-(#4)},{\pflymax}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)},{\tmpvoisinageentreeY}) -- ({(#3)-(#4)},{\tmpvoisinageentreeY}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3},{\tmpvoisinageentreeY}) --++ (3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3-(#4)},{\tmpvoisinageentreeY}) --++ (-3mm,0) ;
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({#3},{\tmpvoisinageentreeY}) --++ (3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({#3-(#4)},{\tmpvoisinageentreeY}) --++ (-3mm,0) ;

    }%
    }%
    %------------------------
    %limite -infinie en Lg%
    {-inf en a-}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path tube-haut : x = L+epsilon (droite verticale)
        \path[pfltraitvoisinage,name path global=pfltubeD] ({#3-(#4)},{\pflymin}) -- ({#3-(#4)},{\pflymax}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pfltubeD,name=pflintD, total=\t}] \pgfextra{\xdef\tmpintDtot{\t}};
        % récupération des dernières abscisses%
        % Cas possibles
        \xintifboolexpr{\tmpintDtot > 0}%
        {% uniquement par le haut
          \path (pflintD-\tmpintDtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\tmpvoisinageentreeY{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
        }%
        {% aucune intersection → courbe entièrement dans le tube
              \xdef\tmpvoisinageentreeY{\pflymax}%
        }%
      }%
      {%
        \xdef\tmpvoisinageentreeY{\tkzgraphentreevoisin}%
      }%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] ({(#3)},{\tmpvoisinageentreeY}) rectangle ({(#3)-(#4)},{\pflymin}) ;
      \ifboolKV[GraphiqueVoisinageTikz]{Asymptote}%
        {%
           \draw[pfltraitvoisinage,color=\tkzgraphcoulasymptvoisin] ({(#3)},{\pflymin}) -- ({(#3)},{\pflymax}) ;
        }%
        {}%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)-(#4)},{\pflymin}) -- ({(#3)-(#4)},{\pflymax}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)},{\tmpvoisinageentreeY}) -- ({(#3)-(#4)},{\tmpvoisinageentreeY}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3},{\tmpvoisinageentreeY}) --++ (3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3-(#4)},{\tmpvoisinageentreeY}) --++ (-3mm,0) ;
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({#3},{\tmpvoisinageentreeY}) --++ (3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({#3-(#4)},{\tmpvoisinageentreeY}) --++ (-3mm,0) ;
    }%


    }%
  %------------------------
    %limite -infinie en Ld%
    {-inf en a+}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
        % path tube-haut : x = L+epsilon (droite verticale)
        \path[pfltraitvoisinage,name path global=pfltubeD] ({#3+(#4)},{\pflymin}) -- ({#3+(#4)},{\pflymax}) ;
        % intersections avec la courbe
        \path[name intersections={of=#2 and pfltubeD,name=pflintD, total=\t}] \pgfextra{\xdef\tmpintDtot{\t}};
        % récupération des dernières abscisses%
        % Cas possibles
        \xintifboolexpr{\tmpintDtot > 0}%
        {% uniquement par le haut
          \path (pflintD-\tmpintDtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\tmpvoisinageentreeY{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
        }%
        {% aucune intersection → courbe entièrement dans le tube
              \xdef\tmpvoisinageentreeY{\pflymax}%
        }%
      }%
      {%
        \xdef\tmpvoisinageentreeY{\tkzgraphentreevoisin}%
      }%
      \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin] ({(#3)},{\tmpvoisinageentreeY}) rectangle ({(#3)+(#4)},{\pflymin}) ;
      \ifboolKV[GraphiqueVoisinageTikz]{Asymptote}%
        {%
           \draw[pfltraitvoisinage,color=\tkzgraphcoulasymptvoisin] ({(#3)},{\pflymin}) -- ({(#3)},{\pflymax}) ;
        }%
        {}%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)+(#4)},{\pflymin}) -- ({(#3)+(#4)},{\pflymax}) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({(#3)},{\tmpvoisinageentreeY}) -- ({(#3)+(#4)},{\tmpvoisinageentreeY}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3},{\tmpvoisinageentreeY}) --++ (-3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({#3+(#4)},{\tmpvoisinageentreeY}) --++ (3mm,0) ;
    }%
    {%
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({#3},{\tmpvoisinageentreeY}) --++ (-3mm,0) ;
      \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({#3+(#4)},{\tmpvoisinageentreeY}) --++ (3mm,0) ;
    }%
    }%
  %------------------------
    %continuité
    {L en a}%
    {%
      \IfStrEq{\tkzgraphentreevoisin}{auto}%
      {%
      %partie droite path tube-haut-bas : x = L+-epsilon (droites verticales)
        \path[pfltraitvoisinage,name path global=pfltubeDH] ({\tkzgraphvalavoisin},{#3+(#4)}) -- ({\pflxmax},{#3+(#4)}) ;
    \path[pfltraitvoisinage,name path global=pfltubeDB] ({\tkzgraphvalavoisin},{#3-(#4)}) -- ({\pflxmax},{#3-(#4)}) ;
        \path[name intersections={of=#2 and pfltubeDH,name=pflintDH, total=\t}] \pgfextra{\xdef\tmpintDHtot{\t}};
    \path[name intersections={of=#2 and pfltubeDB,name=pflintDB, total=\t}] \pgfextra{\xdef\tmpintDBtot{\t}};
        \xintifboolexpr{\tmpintDHtot > 0 'and' \tmpintDBtot > 0}%
      {%
        \path (pflintDH-1) ;
        \pgfgetlastxy{\macrox}{\macroy}%
        \xdef\pflxentreeDH{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
        \path (pflintDB-1) ;
        \pgfgetlastxy{\macrox}{\macroy}%
        \xdef\pflxentreeDB{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
        \xdef\pflvoisindeltaD{\xintfloateval{min(\pflxentreeDH,\pflxentreeDB)-\tkzgraphvalavoisin}}%
      }%
      {%
        \xintifboolexpr{\tmpintDHtot > 0}%
          {%
            \path (pflintDH-1) ;
            \pgfgetlastxy{\macrox}{\macroy}%
            \xdef\pflvoisindeltaD{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)-\tkzgraphvalavoisin}}%
          }%
          {%
            \xintifboolexpr{\tmpintDBtot > 0}%
              {%
                \path (pflintDB-1) ;
                \pgfgetlastxy{\macrox}{\macroy}%
                \xdef\pflvoisindeltaD{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)-\tkzgraphvalavoisin}}%
              }%
              {% aucune intersection → courbe dans le tube sur toute la partie droite
                \xdef\pflvoisindeltaD{\xintfloateval{\pflxmax-\tkzgraphvalavoisin}}%
              }%
          }%
      }%
      % partie gauche — paths de pflxmin à a
      \path[pfltraitvoisinage,name path global=pfltubeGH] ({\pflxmin},{#3+(#4)}) -- ({\tkzgraphvalavoisin},{#3+(#4)}) ;
      \path[pfltraitvoisinage,name path global=pfltubeGB] ({\pflxmin},{#3-(#4)}) -- ({\tkzgraphvalavoisin},{#3-(#4)}) ;
      \path[name intersections={of=#2 and pfltubeGH,name=pflintGH, total=\t}] \pgfextra{\xdef\tmpintGHtot{\t}};
      \path[name intersections={of=#2 and pfltubeGB,name=pflintGB, total=\t}] \pgfextra{\xdef\tmpintGBtot{\t}};
      % récupération du delta gauche
      \xintifboolexpr{\tmpintGHtot > 0 'and' \tmpintGBtot > 0}%
        {%
          \path (pflintGH-\tmpintGHtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\pflxentreeGH{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
          \path (pflintGB-\tmpintGBtot) ;
          \pgfgetlastxy{\macrox}{\macroy}%
          \xdef\pflxentreeGB{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
          \xdef\pflvoisindeltaG{\xintfloateval{\tkzgraphvalavoisin-max(\pflxentreeGH,\pflxentreeGB)}}%
        }%
        {%
          \xintifboolexpr{\tmpintGHtot > 0}%
            {%
              \path (pflintGH-\tmpintGHtot) ;
              \pgfgetlastxy{\macrox}{\macroy}%
              \xdef\pflvoisindeltaG{\xintfloateval{\tkzgraphvalavoisin-(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
            }%
            {%
              \xintifboolexpr{\tmpintGBtot > 0}%
                {%
                  \path (pflintGB-\tmpintGBtot) ;
                  \pgfgetlastxy{\macrox}{\macroy}%
                  \xdef\pflvoisindeltaG{\xintfloateval{\tkzgraphvalavoisin-(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
                }%
                {% aucune intersection
                  \xdef\pflvoisindeltaG{\xintfloateval{\tkzgraphvalavoisin-\pflxmin}}%
                }%
            }%
        }%
      % delta final
      \xdef\pflvoisindelta{\xintfloateval{min(\pflvoisindeltaD,\pflvoisindeltaG)}}%
    }%
    {%
      \xdef\pflvoisindelta{\tkzgraphentreevoisin}%
    }%
    % tube horizontal restreint à ]a-delta, a+delta[
    \fill[opacity=\tkzgraphopacvoisin,color=\tkzgraphcoulvoisin]
      ({\xintfloateval{\tkzgraphvalavoisin-\pflvoisindelta}},{#3-(#4)})
      rectangle
      ({\xintfloateval{\tkzgraphvalavoisin+\pflvoisindelta}},{#3+(#4)}) ;
    % bords horizontaux
    \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin]
      ({\pflxmin},{#3-(#4)}) -- ({\pflxmax},{#3-(#4)}) ;
    \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin]
      ({\pflxmin},{#3+(#4)}) -- ({\pflxmax},{#3+(#4)}) ;
    \draw[pfltraitvoisinage,,densely dashed,color=\tkzgraphcoulvoisin] ({\tkzgraphvalavoisin-\pflvoisindelta},{#3-(#4)}) -- ({\tkzgraphvalavoisin-\pflvoisindelta},{#3+(#4)}) ;
    \draw[pfltraitvoisinage,,densely dashed,color=\tkzgraphcoulvoisin] ({\tkzgraphvalavoisin+\pflvoisindelta},{#3-(#4)}) -- ({\tkzgraphvalavoisin+\pflvoisindelta},{#3+(#4)}) ;
    \ifboolKV[GraphiqueVoisinageTikz]{Asymptote}%
      {%
         \draw[pfltraitvoisinageasympt,color=\tkzgraphcoulasymptvoisin] ({(\tkzgraphvalavoisin)},{\pflymin}) -- ({(\tkzgraphvalavoisin)},{\pflymax}) ;
         \draw[pfltraitvoisinageasympt,color=\tkzgraphcoulasymptvoisin] ({\pflxmin},{#3}) -- ({\pflxmax},{#3}) ;

      }%
      {}%
    \ifboolKV[GraphiqueVoisinageTikz]{Fleches}%
      {%
        \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tkzgraphvalavoisin-\pflvoisindelta},{#3-(#4)}) --++ (0,-3mm) ;
        \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tkzgraphvalavoisin-\pflvoisindelta},{#3+(#4)}) --++ (0,3mm) ;
        \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tkzgraphvalavoisin+\pflvoisindelta},{#3-(#4)}) --++ (0,-3mm) ;
        \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin,pflflecheg] ({\tkzgraphvalavoisin+\pflvoisindelta},{#3+(#4)}) --++ (0,3mm) ;
      }%
      {%
        \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tkzgraphvalavoisin-\pflvoisindelta},{#3-(#4)}) --++ (0,-3mm) ;
        \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tkzgraphvalavoisin-\pflvoisindelta},{#3+(#4)}) --++ (0,3mm) ;
        \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tkzgraphvalavoisin+\pflvoisindelta},{#3-(#4)}) --++ (0,-3mm) ;
        \draw[pfltraitvoisinage,color=\tkzgraphcoulvoisin] ({\tkzgraphvalavoisin+\pflvoisindelta},{#3+(#4)}) --++ (0,3mm) ;
      }%
  }
  }%
}

%----COURBES PARAMETRIQUES
\NewDocumentCommand\DefinirCourbeParam{ O{} D<>{x} D<>{y} m m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  \xintdeffloatfunc #2(t) := #4 ;
  \xintdeffloatfunc #3(t) := #5 ;
  %test dimension too large ??
  \ifboolKV[GraphiqueTikzCourbe]{Restreindre}%
  {%
    \xdef\pfloffsetV{\xintfloateval{((\pflymax)-(\pflymin))/20}}%
    \xdef\pflMinoffsetV{\xintfloateval{(\pflymin)-(\pfloffsetV)}}%
    \xdef\pflMaxoffsetV{\xintfloateval{(\pflymax)+(\pfloffsetV)}}%
    \xdef\pfloffsetH{\xintfloateval{((\pflxmax)-(\pflxmin))/20}}%
    \xdef\pflMinoffsetH{\xintfloateval{(\pflxmin)-(\pfloffsetH)}}%
    \xdef\pflMaxoffsetH{\xintfloateval{(\pflxmax)+(\pfloffsetH)}}%
  }%
  {}%
  %fin test
  \IfStrEq{\pflstepcurve}{}%
  {%
    \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/250}}%
  }%
  {}%
  \ifboolKV[GraphiqueTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}
  \ifboolKV[GraphiqueTikzCourbe]{Trace}%
  {%
    \ifboolKV[GraphiqueTikzCourbe]{Restreindre}%
    {%
      \path[draw,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
          seq((min(max(#2(t),\pflMinoffsetH),\pflMaxoffsetH), min(max(#3(t),\pflMinoffsetV),\pflMaxoffsetV)),
          t=\useKV[GraphiqueTikzCourbe]{Debut}%
          ..[\pflstepcurve]..%
          \useKV[GraphiqueTikzCourbe]{Fin},
          \useKV[GraphiqueTikzCourbe]{Fin})
        \relax
      };
    }%
    {%
      \path[draw,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
          seq((#2(t),#3(t)),
          t=\useKV[GraphiqueTikzCourbe]{Debut}%
          ..[\pflstepcurve]..%
          \useKV[GraphiqueTikzCourbe]{Fin},
          \useKV[GraphiqueTikzCourbe]{Fin})
        \relax
      };
    }%
  }%
  {%
    \ifboolKV[GraphiqueTikzCourbe]{Restreindre}%
    {%
      \path[draw=none,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
        seq((min(max(#2(t),\pflMinoffsetH),\pflMaxoffsetH), min(max(#3(t),\pflMinoffsetV),\pflMaxoffsetV)),
        t=\useKV[GraphiqueTikzCourbe]{Debut}%
        ..[\pflstepcurve]..%
        \useKV[GraphiqueTikzCourbe]{Fin},
        \useKV[GraphiqueTikzCourbe]{Fin})
        \relax
      };
    }%
    {%
      \path[draw=none,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
          seq((#2(t),#3(t)),
          t=\useKV[GraphiqueTikzCourbe]{Debut}%
          ..[\pflstepcurve]..%
          \useKV[GraphiqueTikzCourbe]{Fin},
          \useKV[GraphiqueTikzCourbe]{Fin})
        \relax
      };
    }%
  }%
    \ifboolKV[GraphiqueTikzCourbe]{Clip}{\end{scope}}{}
}

\NewDocumentCommand\TracerCourbeParam{ O{} D<>{} m m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  %test dimension too large ??
  \ifboolKV[GraphiqueTikzCourbe]{Restreindre}%
  {%
    \xdef\pfloffsetV{\xintfloateval{((\pflymax)-(\pflymin))/20}}%
    \xdef\pflMinoffsetV{\xintfloateval{(\pflymin)-(\pfloffsetV)}}%
    \xdef\pflMaxoffsetV{\xintfloateval{(\pflymax)+(\pfloffsetV)}}%
    \xdef\pfloffsetH{\xintfloateval{((\pflxmax)-(\pflxmin))/20}}%
    \xdef\pflMinoffsetH{\xintfloateval{(\pflxmin)-(\pfloffsetH)}}%
    \xdef\pflMaxoffsetH{\xintfloateval{(\pflxmax)+(\pfloffsetH)}}%
  }%
  {}%
  %fin test
  \IfStrEq{\pflstepcurve}{}%
  {%
    \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/250}}%
  }%
  {}%
  \ifboolKV[GraphiqueTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}
  \IfEq{\pflnamecurve}{}%
  {%
    \ifboolKV[GraphiqueTikzCourbe]{RestreindreY}%
    {%
      \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
          seq((min(max(#3,\pflMinoffsetH),\pflMaxoffsetH), min(max(#4,\pflMinoffsetV),\pflMaxoffsetV)),
          t=\useKV[GraphiqueTikzCourbe]{Debut}%
          ..[\pflstepcurve]..%
          \useKV[GraphiqueTikzCourbe]{Fin},
          \useKV[GraphiqueTikzCourbe]{Fin})
        \relax
      };
    }%
    {%
      \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
          seq((#3,#4),
          t=\useKV[GraphiqueTikzCourbe]{Debut}%
          ..[\pflstepcurve]..%
          \useKV[GraphiqueTikzCourbe]{Fin},
          \useKV[GraphiqueTikzCourbe]{Fin})
        \relax
      };
    }%
  }%
  {%
    \ifboolKV[GraphiqueTikzCourbe]{RestreindreY}%
    {%
      \path[draw,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
          seq((min(max(#3,\pflMinoffsetH),\pflMaxoffsetH), min(max(#4,\pflMinoffsetV),\pflMaxoffsetV)),
          t=\useKV[GraphiqueTikzCourbe]{Debut}%
          ..[\pflstepcurve]..%
          \useKV[GraphiqueTikzCourbe]{Fin},
          \useKV[GraphiqueTikzCourbe]{Fin})
        \relax
      };
    }%
    {%
      \path[draw,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
          seq((#3,#4),
          t=\useKV[GraphiqueTikzCourbe]{Debut}%
          ..[\pflstepcurve]..%
          \useKV[GraphiqueTikzCourbe]{Fin},
          \useKV[GraphiqueTikzCourbe]{Fin})
          \relax
      };
    }%
  }%
  \ifboolKV[GraphiqueTikzCourbe]{Clip}{\end{scope}}{}
}

\NewDocumentCommand\DefinirCourbePol{ O{} D<>{phi} m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  \xintdeffloatfunc #2(theta) := #3 ;%
  \DefinirCourbeParam[#1]<phix><phiy>{pflpol(t)*cos(t)}{pflpol(t)*sin(t)}%
}

\NewDocumentCommand\TracerCourbePol{ O{} m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  \xintdeffloatfunc tmppflpol(theta) := #2 ;%
  \TracerCourbeParam[#1]{tmppflpol(t)*cos(t)}{tmppflpol(t)*sin(t)}%
}

%====MACRO INTERNE : nb dérivé via intersections (pour spline)
\NewDocumentCommand\tkzg@nbderive@spline{ m m m }{%
    \path[name path=pflvlineL] ({#2-#3},{\pflymin}) -- ({#2-#3},{\pflymax}) ;
    \path[name path=pflvlineR] ({#2+#3},{\pflymin}) -- ({#2+#3},{\pflymax}) ;
    \path[name intersections={of=#1 and pflvlineL, name=pflintL}] ;
    \path[name intersections={of=#1 and pflvlineR, name=pflintR}] ;
    \path (pflintL-1) ; \pgfgetlastxy{\macrox}{\macroy}%
    \xdef\tkzg@nbderivLY{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
    \path (pflintR-1) ; \pgfgetlastxy{\macrox}{\macroy}%
    \xdef\tkzg@nbderivRY{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
    \xdef\tkzg@nbderiv{\xintfloateval{(\tkzg@nbderivRY-\tkzg@nbderivLY)/(2*#3)}}%
}

%====TRACER LA DERIVEE NUMERIQUE D'UNE FONCTION NOMMEE OU D'UN SPLINE
\NewDocumentCommand\TracerDerivee{ O{} m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  \IfStrEq{\pflstepcurve}{}%
    {\xdef\pflstepcurve{\xintfloateval{%
      ((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/200}}%
    }%
    {}%
  \IfStrEq{\pflhderiv}{}%
    {\ifboolKV[GraphiqueTikzCourbe]{Spline}%
      {\xdef\pflhderiv{\xintfloateval{0.5*\pflstepcurve}}}%
      {\def\pflhderiv{0.1}}%
    }%
    {}%
  \ifboolKV[GraphiqueTikzCourbe]{Spline}%
    {%
      % Bornes sécurisées
      \xdef\pfldebutderiv{\xintfloateval{(\useKV[GraphiqueTikzCourbe]{Debut})+\pflhderiv}}%
      \xdef\pflfinderiv{\xintfloateval{(\useKV[GraphiqueTikzCourbe]{Fin})-\pflhderiv}}%
      % Liste des xi
      \edef\pfllistexvals{\xintfloateval{%
        seq(x, x=\pfldebutderiv..[\pflstepcurve]..\pflfinderiv, \pflfinderiv)}}%
      % Construction de la liste de points (xi, f'(xi))
      \gdef\pfllistederivspline{}%
      \foreach \tmpxi in \pfllistexvals {%
        \tkzg@nbderive@spline{#2}{\tmpxi}{\pflhderiv}%
        \xdef\pfllistederivspline{\pfllistederivspline (\tmpxi,\tkzg@nbderiv)}%
      }%
      % Tracé
      \ifboolKV[GraphiqueTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}%
      \IfEq{\pflnamecurve}{}%
        {%
          \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve] plot[smooth] coordinates {\pfllistederivspline} ;
        }%
        {%
          \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve] plot[smooth] coordinates {\pfllistederivspline} ;
        }%
      \ifboolKV[GraphiqueTikzCourbe]{Clip}{\end{scope}}{}%
    }%
    {%
      % Bornes sécurisées : on recule de h de chaque côté (semble OK)
      \xdef\pfldebutderiv{\xintfloateval{(\useKV[GraphiqueTikzCourbe]{Debut})+\pflhderiv}}%
      \xdef\pflfinderiv  {\xintfloateval{(\useKV[GraphiqueTikzCourbe]{Fin})  -\pflhderiv}}%
      % Dérivée numérique centrée
      \xintdeffloatfunc pflnumderiv(x) :=  (#2(x+\pflhderiv) - #2(x-\pflhderiv)) / (2*\pflhderiv);%
      % Tracé
      \ifboolKV[GraphiqueTikzCourbe]{Clip}%
      {\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}%
        \IfEq{\pflnamecurve}{}%
          {%
            \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve]
              plot[smooth] coordinates {%
                \xintthecoords\xintfloatexpr
                seq((x,pflnumderiv(x)),
                x=\pfldebutderiv..[\pflstepcurve]..\pflfinderiv,
                \pflfinderiv)
                \relax
              };%
          }%
          {%
            \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
              plot[smooth] coordinates {%
                \xintthecoords\xintfloatexpr
                seq((x,pflnumderiv(x)),
                x=\pfldebutderiv..[\pflstepcurve]..\pflfinderiv,
                \pflfinderiv)
                \relax
              };%
          }%
        \ifboolKV[GraphiqueTikzCourbe]{Clip}{\end{scope}}{}%
        }%
}

\NewDocumentCommand\TracerPrimitive{ O{} m m m }{%
  % #1 = options KV (Couleur, Debut, Fin, Pas, Clip, StyleTrace...)
  % #2 = nom de la fonction (définie via \DefinirCourbe)
  % #3 = x0 (abscisse du point de passage)
  % #4 = y0 (ordonnée du point de passage)
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  % Pas de tracé par défaut
  \IfStrEq{\pflstepcurve}{}%
    {\xdef\pflstepcurve{\xintfloateval{%
      ((\useKV[GraphiqueTikzCourbe]{Fin})-(\useKV[GraphiqueTikzCourbe]{Debut}))/200}}}%
    {}%
  % Bornes sécurisées (comme pour \TracerDerivee)
  \xdef\pfldebutprim{\xintfloateval{(\useKV[GraphiqueTikzCourbe]{Debut})+\pflstepcurve/10}}%
  \xdef\pflfinprim  {\xintfloateval{(\useKV[GraphiqueTikzCourbe]{Fin})  -\pflstepcurve/10}}%
  % Primitive numérique — méthode des trapèzes, gestion des deux sens
  \xintdeffloatfunc pflnumprimitive(x) :=
    (x > #3) ?
      {%  x à droite de x0 : intégrale de x0 à x
        #4 + \pflstepcurve*(
          #2(#3)/2
          + add(#2(t), t=(#3+\pflstepcurve)..[(\pflstepcurve)]..(x-\pflstepcurve))
          + #2(x)/2
        )
      }
      { (x < #3) ?
        {%  x à gauche de x0 : intégrale de x à x0, changement de signe
          #4 - \pflstepcurve*(
            #2(x)/2
            + add(#2(t), t=(x+\pflstepcurve)..[(\pflstepcurve)]..(#3-\pflstepcurve))
            + #2(#3)/2
          )
        }
        { #4 }%  x == x0 exactement
      };%
  % Tracé
  \ifboolKV[GraphiqueTikzCourbe]{Clip}%
    {\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}%
  \IfEq{\pflnamecurve}{}%
    {%
      \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,pflnumprimitive(x)),
              x=\pfldebutprim..[\pflstepcurve]..\pflfinprim,
              \pflfinprim)
          \relax
        };%
    }%
    {%
      \path[draw,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,pflnumprimitive(x)),
              x=\pfldebutprim..[\pflstepcurve]..\pflfinprim,
              \pflfinprim)
          \relax
        };%
    }%
  \ifboolKV[GraphiqueTikzCourbe]{Clip}{\end{scope}}{}%
}

\NewDocumentCommand\DefinirListeInterpo{ m O{\malisteinterpo} }{%
  \def#2{#1}%
}

\NewDocumentCommand\DefinirCourbeInterpo{ O{} m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  \begin{scope}
    \ifboolKV[GraphiqueTikzCourbe]{Trace}%
      {%
        \path[draw,pflcourbe,\pflstylecurve,color=\pflcoulcurve,name path global=\pflnamecurve] plot[smooth,tension={\useKV[GraphiqueTikzCourbe]{Tension}}] coordinates {#2};
      }%
      {%
        \path[draw=none,pflcourbe,color=\pflcoulcurve,name path global=\pflnamecurve] plot[smooth,tension={\useKV[GraphiqueTikzCourbe]{Tension}}] coordinates {#2};
      }%
  \end{scope}
}

\NewDocumentCommand\TracerCourbeInterpo{ O{} m }{%
  %2=liste
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  \begin{scope}
    \draw[pflcourbe,\pflstylecurve,color=\pflcoulcurve] plot [smooth,tension={\useKV[GraphiqueTikzCourbe]{Tension}}] coordinates {#2} ;
  \end{scope}
}

\NewDocumentCommand\DefinirListeSpline{ m O{\malistespline} }{%
  \def#2{#1}%
}

\newcommand\pflextractcoeff[2]{%1=liste,2=numero
  \setsepchar{§}%
  \readlist*\lcoeffs{#1}
  \ifnum \lcoeffslen=1
    \def\COEFFA{#1}
    \def\COEFFB{#1}
  \else
    \itemtomacro\lcoeffs[#2]\COEFF
    \IfSubStr{\COEFF}{/}%
      {\StrCut{\COEFF}{/}{\COEFFA}{\COEFFB}}%
      {\def\COEFFA{\COEFF}\def\COEFFB{\COEFF}}
  \fi
}

\defKV[GraphiqueTikzSpline]{%
  Couleur=\def\pflsplinecolor{#1},%
  Nom=\def\pflsplinename{#1},%
  Coeffs=\def\pflsplinecoeffs{#1},%
  StyleTrace=\def\pflsplinestyle{#1}
}

\setKVdefault[GraphiqueTikzSpline]{%
  Nom=spline,%
  Couleur=black,%
  Coeffs=3,%
  Trace=false,%
  Alt=false,%
  StyleTrace={}
}

\NewDocumentCommand\GenererSpline{ s m m O{\monspline} }{%
  %1=liste
  \setsepchar[.]{§./}%
  \readlist*\SPLlistepoints{#2}%
  %les données
  \def\tmpsplinenumdeb{1}
  \def\tmpsplinenumfin{\SPLlistepointslen}%
  \pflextractcoeff{#3}{\tmpsplinenumdeb}%
  %nb de calculs
  \def\SPLnbsplines{\inteval{\tmpsplinenumfin-1}}%
  %extraction des coordonnées
  \itemtomacro\SPLlistepoints[\tmpsplinenumdeb,1]\xa%
  \itemtomacro\SPLlistepoints[\tmpsplinenumdeb,2]\ya%
  \itemtomacro\SPLlistepoints[\tmpsplinenumdeb,3]\fprimea%
  \itemtomacro\SPLlistepoints[\tmpsplinenumdeb,1]\xb%
  \itemtomacro\SPLlistepoints[\tmpsplinenumdeb,2]\yb%
  \itemtomacro\SPLlistepoints[\tmpsplinenumdeb,3]\fprimeb%
  \IfBooleanTF{#1}%
  {%
    % mode Alt : on garde le signe de (xb-xa), pas de abs()
    \xdef#4{(\xa,\ya) ..controls +({((\xb)-(\xa))/\COEFFA},{(\fprimea)*((\xb)-(\xa))/\COEFFA}) and +({-((\xb)-(\xa))/\COEFFA},{-(\fprimeb)*((\xb)-(\xa))/\COEFFA}).. (\xb,\yb)}%
  }%
  {%
    % mode polaire : abs() sur le rayon uniquement
    \xdef#4{(\xa,\ya) ..controls +({atan (\fprimea)}:{((\xb)-(\xa))/\COEFFA}) and +({-180 + atan (\fprimeb)}:{((\xb)-(\xa))/\COEFFA}).. (\xb,\yb)}%
  }%
  \foreach \i in {\tmpsplinenumdeb,...,\SPLnbsplines}{%
    \pflextractcoeff{#3}{\i}%
    \def\j{\inteval{\i+1}}%
    \itemtomacro\SPLlistepoints[\i,1]\xa%
    \itemtomacro\SPLlistepoints[\i,2]\ya%
    \itemtomacro\SPLlistepoints[\i,3]\fprimea%
    \itemtomacro\SPLlistepoints[\j,1]\xb%
    \itemtomacro\SPLlistepoints[\j,2]\yb%
    \itemtomacro\SPLlistepoints[\j,3]\fprimeb%
    \IfBooleanTF{#1}%
    {%
      \xdef#4{#4 ..controls +({((\xb)-(\xa))/\COEFFA},{(\fprimea)*((\xb)-(\xa))/\COEFFA}) and +({-((\xb)-(\xa))/\COEFFA},{-(\fprimeb)*((\xb)-(\xa))/\COEFFA}).. (\xb,\yb)}%
    }%
    {%
      \xdef#4{#4 ..controls +({atan (\fprimea)}:{((\xb)-(\xa))/\COEFFA}) and +({-180 + atan (\fprimeb)}:{((\xb)-(\xa))/\COEFFB}).. (\xb,\yb)}%
    }%
  }%
}

\NewDocumentCommand\DefinirCourbeSpline{ O{} m D<>{\monspline} }{%
  %1=liste
  \restoreKV[GraphiqueTikzSpline]%
  \setKV[GraphiqueTikzSpline]{#1}%
  \ifboolKV[GraphiqueTikzSpline]{Alt}%
    {%
      \GenererSpline*{#2}{\pflsplinecoeffs}[#3]%
    }%
    {%
      \GenererSpline{#2}{\pflsplinecoeffs}[#3]%
    }%
  \begin{scope}
    \ifboolKV[GraphiqueTikzSpline]{Trace}%
      {%
        \path[draw,pflcourbe,\pflsplinestyle,color=\pflsplinecolor,name path global=\pflsplinename] #3 ;
      }%
      {%
        \path[draw=none,pflcourbe,name path global=\pflsplinename] #3 ;
      }%
  \end{scope}
}

\NewDocumentCommand\DefinirSpline{ O{} m D<>{\monspline} }{%old version
  %1=liste
  \restoreKV[GraphiqueTikzSpline]%
  \setKV[GraphiqueTikzSpline]{#1}%
  \GenererSpline{#2}{\pflsplinecoeffs}[#3]%
  \begin{scope}
    \ifboolKV[GraphiqueTikzSpline]{Trace}%
      {%
        \path[draw,pflcourbe,\pflsplinestyle,color=\pflsplinecolor,name path global=\pflsplinename] #3 ;
      }%
      {%
        \path[draw=none,pflcourbe,name path global=\pflsplinename] #3 ;
      }%
  \end{scope}
}

\NewDocumentCommand\TracerCourbeSpline{ O{} m D<>{\monspline} }{%
  %1=liste
  \restoreKV[GraphiqueTikzSpline]%
  \setKV[GraphiqueTikzSpline]{#1}%
  \ifboolKV[GraphiqueTikzSpline]{Alt}%
    {%
      \GenererSpline*{#2}{\pflsplinecoeffs}[#3]%
    }%
    {%
      \GenererSpline{#2}{\pflsplinecoeffs}[#3]%
    }%
  \begin{scope}
    \draw[pflcourbe,\pflsplinestyle,color=\pflsplinecolor] #3 ;
  \end{scope}
}

\NewDocumentCommand\TracerSpline{ O{} m D<>{\monspline} }{%old version
  %1=liste
  \restoreKV[GraphiqueTikzSpline]%
  \setKV[GraphiqueTikzSpline]{#1}%
  \GenererSpline{#2}{\pflsplinecoeffs}[#3]%
  \begin{scope}
    \draw[pflcourbe,\pflsplinestyle,color=\pflsplinecolor] #3 ;
  \end{scope}
}

%====SPLINE HOBBY
\usetikzlibrary{hobby}
\tikzset{
  pflhobbytangent/.style={%
    in angle={(180+#1)},Hobby finish,
    designated Hobby path=next,out angle=#1%
  }
}

\defKV[GraphiqueTikzSplineHobby]{%
  Nom=\def\pflhobbyname{#1},%
  Couleur=\def\pflhobbycoul{#1},%
  StyleTrace=\def\pflhobbystyle{#1}%
}
\setKVdefault[GraphiqueTikzSplineHobby]{%
  Nom=spline,%
  Couleur=black,%
  StyleTrace={},%
  Trace=false%
}

\NewDocumentCommand\GenererSplineHobby{ O{} m O{\monsplinehobby} }{%
  \xdef\SHratioYX{\xintfloateval{\pflyunit/\pflxunit}}%
  \setsepchar[.]{§./}%
  \readlist*\SHlistepoints{#2}%
  \def\SHnumdeb{1}%
  \def\SHnumfin{\SHlistepointslen}%
  % --- premier point : out angle seul ---
  \itemtomacro\SHlistepoints[\SHnumdeb,1]\SHxa%
  \itemtomacro\SHlistepoints[\SHnumdeb,2]\SHya%
  \itemtomacro\SHlistepoints[\SHnumdeb,3]\SHfprimea%
  \xdef\SHangleA{\xintfloateval{atand((\SHfprimea)*(\SHratioYX))}}%
  \xdef#3{([out angle=\SHangleA]\SHxa,\SHya)}%
  % --- points intermédiaires : style pflhobbytangent ---
  \foreach \SHi in {\inteval{\SHnumdeb+1},...,\inteval{\SHnumfin-1}}{%
    \itemtomacro\SHlistepoints[\SHi,1]\SHxi%
    \itemtomacro\SHlistepoints[\SHi,2]\SHyi%
    \itemtomacro\SHlistepoints[\SHi,3]\SHfprimei%
    \xdef\SHanglei{\xintfloateval{atand((\SHfprimei)*(\SHratioYX))}}%
    \xdef#3{#3 .. ([pflhobbytangent=\SHanglei]\SHxi,\SHyi)}%
  }%
  % --- dernier point : in angle seul ---
  \itemtomacro\SHlistepoints[\SHnumfin,1]\SHxz%
  \itemtomacro\SHlistepoints[\SHnumfin,2]\SHyz%
  \itemtomacro\SHlistepoints[\SHnumfin,3]\SHfprimez%
  \xdef\SHanglez{\xintfloateval{atand((\SHfprimez)*(\SHratioYX))+180}}%
  \xdef#3{#3 .. ([in angle=\SHanglez]\SHxz,\SHyz)}%
}

\NewDocumentCommand\DefinirCourbeSplineHobby{ O{} m D<>{\monsplinehobby} }{%
  \restoreKV[GraphiqueTikzSplineHobby]%
  \setKV[GraphiqueTikzSplineHobby]{#1}%
  \GenererSplineHobby[]{#2}[#3]%
  \typeout{#3}
  \begin{scope}
    \ifboolKV[GraphiqueTikzSplineHobby]{Trace}%
    {%
      \path[draw,pflcourbe,\pflhobbystyle,use Hobby shortcut,%
      color=\pflhobbycoul,name path global=\pflhobbyname] #3 ;%
    }%
    {%
      \path[draw=none,pflcourbe,use Hobby shortcut,%
      name path global=\pflhobbyname] #3 ;%
    }%
  \end{scope}
}

\NewDocumentCommand\TracerCourbeSplineHobby{ O{} m }{%
  \restoreKV[GraphiqueTikzSplineHobby]%
  \setKV[GraphiqueTikzSplineHobby]{#1}%
  \GenererSplineHobby[#1]{#2}%
  \begin{scope}
    \draw[pflcourbe,\pflhobbystyle,use Hobby shortcut,%
      color=\pflhobbycoul] \monsplinehobby ;%
  \end{scope}
}

%===INTERSECTION & ANTÉCÉDENTS
\defKV[GraphiqueTikzIntersect]{%
  Couleur=\def\pflintercoul{#1},%
  Nom=\def\pflintercurves{#1},%
  ListeRes=\def\pflinterlistres{#1}
}
\setKVdefault[GraphiqueTikzIntersect]{%
  Nom=S,
  Aff=true,
  Couleur=black,
  AffDroite=false,%
  Traits=false,%
  Style=o,%
  ListeRes={}
}

\NewDocumentCommand\TrouverIntersections{ O{} m m D<>{\myt} }{%
  \restoreKV[GraphiqueTikzIntersect]%
  \setKV[GraphiqueTikzIntersect]{#1}%
  \path[name intersections={of=#2 and #3,name=\pflintercurves,total=\t}] \pgfextra{\xdef#4{\t}};
  \ifboolKV[GraphiqueTikzIntersect]{Aff}%
    {%
      \xintifboolexpr{#4 == 0}{}%
        {%
          \foreach \i in {1,...,#4}{%
            \ifboolKV[GraphiqueTikzIntersect]{Traits}%
              {%
                \draw[pfltraitimg,color=\pflintercoul]let \p1 = (\pflintercurves-\i) in (\pflintercurves-\i) -- ({\x1},{\pflOy}) ;
              }%
              {}%
            \MarquerPts*[Style={\useKV[GraphiqueTikzIntersect]{Style}},Couleur={\useKV[GraphiqueTikzIntersect]{Couleur}}]{(\pflintercurves-\i)}
            %\filldraw[{\useKV[GraphiqueTikzIntersect]{Couleur}}] (\pflintercurves-\i) circle[pflpointc] ;
          }
        }%
    }%
    {}%
  \IfStrEq{\pflinterlistres}{}%
    {}%
    {%
      \xdef\tkzgtmplistabsc{}%
      \xintifboolexpr{#4 == 0}{}%
      {%
        \foreach \i in {1,...,#4}{%
          \RecupererAbscisse{(\pflintercurves-\i)}[\tmpabsi]%
          \xintifboolexpr{\i == 1}%
            {\xdef\tkzgtmplistabsc{\tmpabsi}}%
            {\xdef\tkzgtmplistabsc{\tkzgtmplistabsc,\tmpabsi}}%
        }%
      }%
      \expandafter\xdef\csname\pflinterlistres\endcsname{\tkzgtmplistabsc}%
    }%
}

\NewDocumentCommand\TrouverAntecedents{ O{} m m D<>{\myantec} }{%
  \restoreKV[GraphiqueTikzIntersect]%
  \setKV[GraphiqueTikzIntersect]{#1}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \ifboolKV[GraphiqueTikzIntersect]{AffDroite}%
      {%
        \path[draw,color=\pflintercoul,pflcourbe,name path=tmpanteced] ({\pflxmin},{#3})--({\pflxmax},{#3}) ;
      }%
      {%
        \path[draw=none,pflcourbe,name path=tmpanteced] ({\pflxmin},{#3})--({\pflxmax},{#3}) ;
      }%
    \path[name intersections={of=#2 and tmpanteced,name=\pflintercurves,total=\t}] \pgfextra{\xdef#4{\t}};
    \IfStrEq{\pflinterlistres}{}%
      {}%
      {%
        \xdef\tkzgtmplistabsc{}%
        \xintifboolexpr{#4 == 0}{}%
        {%
          \foreach \i in {1,...,#4}{%
            \RecupererAbscisse{(\pflintercurves-\i)}[\tmpabsi]%
            \xintifboolexpr{\i == 1}%
              {\xdef\tkzgtmplistabsc{\tmpabsi}}%
              {\xdef\tkzgtmplistabsc{\tkzgtmplistabsc,\tmpabsi}}%
          }%
        }%
        \expandafter\xdef\csname\pflinterlistres\endcsname{\tkzgtmplistabsc}%
      }%
    \ifboolKV[GraphiqueTikzIntersect]{Aff}%
      {%
        \xintifboolexpr{#4 == 0}{}%
        {%
          \foreach \i in {1,...,#4}{%
            \MarquerPts*[Style={\useKV[GraphiqueTikzIntersect]{Style}},Couleur={\useKV[GraphiqueTikzIntersect]{Couleur}}]{(\pflintercurves-\i)}
            %\filldraw[{\useKV[GraphiqueTikzIntersect]{Couleur}}] (\pflintercurves-\i) circle[pflpointc] ;
          }
        }%
      }%
      {}%
  \end{scope}
}

%====MONTE CARLO
\defKV[graphiquetikzmontecarlo]{%
  Couleurs=\def\graphtikzmccols{#1},%
  BornesX=\def\graphtikzmcxbornes{#1},%
  BornesY=\def\graphtikzmcybornes{#1}
}

\setKVdefault[graphiquetikzmontecarlo]{%
  Couleurs={blue/red},%
  BornesX={\pflxmin,\pflxmax},%
  BornesY={\pflymin,\pflymax}
}

\NewDocumentCommand\SimulerMonteCarlo{ O{} D<>{f} m O{\nbptsmcok} O{\nbptsmcko} }{%
  \restoreKV[graphiquetikzmontecarlo]%
  \setKV[graphiquetikzmontecarlo]{#1}%
  \StrCut{\graphtikzmccols}{/}{\tmpMCcolOK}{\tmpMCcolKO}%
  \StrCut{\graphtikzmcxbornes}{,}{\tmpMCxmin}{\tmpMCxmax}%
  \StrCut{\graphtikzmcybornes}{,}{\tmpMCymin}{\tmpMCymax}%
  \xdef#4{0}%
  \xdef#5{0}%
  \xdef\nbptsmc{#3}%
  \foreach \i in {1,...,#3}{%
    \xdef\tmpMCrandX{\xintfloateval{random()*((\tmpMCxmax)-(\tmpMCxmin))+(\tmpMCxmin)}}%
    \xdef\tmpMCrandY{\xintfloateval{random()*((\tmpMCymax)-(\tmpMCymin))+(\tmpMCymin)}}%
    \xdef\tmpMCrandfX{\xintfloateval{#2(\tmpMCrandX)}}%
    \xintifboolexpr{ \tmpMCrandfX  > \tmpMCrandY }%
      {%
        \xdef#4{\xinteval{#4+1}}%
        \filldraw[color=\tmpMCcolOK] (\tmpMCrandX,\tmpMCrandY) circle[pflpointmc] ;
      }%
      {%
        \xdef#5{\xinteval{#5+1}}%
        \filldraw[color=\tmpMCcolKO] (\tmpMCrandX,\tmpMCrandY) circle[pflpointmc] ;
      }%
  }%
}

%====MÉTHODES INTÉGRALES
\defKV[graphiquetikzintegr]{%
  Couleur=\def\graphtikzintgrcol{#1},%
  CouleurRemplissage=\def\graphtikzintgrcolrempl{#1},%
  NbSubDiv=\def\graphtikzintgrnb{#1},%
  Methode=\def\graphtikzintgrtype{#1},%
  Opacite=\def\graphtikzintgropac{#1}
}

\setKVdefault[graphiquetikzintegr]{%
  Couleur=red,%
  NbSubDiv=10,%
  Methode=RectanglesGauche,%
  Remplir=true,%
  CouleurRemplissage={\graphtikzintgrcol!25},%
  Opacite=0.25,%
  Spline=false
}

\NewDocumentCommand\RepresenterMethodeIntegrale{ O{} D<>{f} m m }{%opts+nom_fct/spline+a+b
  \useKVdefault[graphiquetikzintegr]%
  \setKV[graphiquetikzintegr]{#1}%
  \ifboolKV[graphiquetikzintegr]{Remplir}%
    {%
      \tikzset{pflfigureintegr/.style={pfltrait,draw=\graphtikzintgrcol,fill=\graphtikzintgrcolrempl,fill opacity=\graphtikzintgropac}}%
    }%
    {%
      \tikzset{pflfigureintegr/.style={pfltrait,color=\graphtikzintgrcol}}%
    }%
  \tikzset{figureintegr/.style={pfltrait,draw=\graphtikzintgrcol,fill=\graphtikzintgrcolrempl,fill opacity=\graphtikzintgropac}}%
  \def\TmpH{(#4-#3)/\graphtikzintgrnb}
  \ifboolKV[graphiquetikzintegr]{Spline}%
    {%
      \IfEq{\graphtikzintgrtype}{RectanglesGauche}%
        {%
          \foreach \i in {0,...,\inteval{\graphtikzintgrnb-1}}{%
            \path[draw=none,pflcourbe,name path=tmpintmethod] ({#3+\i*\TmpH},{\pflymin})--({#3+\i*\TmpH},{\pflymax}) ;
            \path[name intersections={of=#2 and tmpintmethod,name=KLM}] ;
            \draw[pflfigureintegr] let \p1 = (KLM-1) in ({#3+\i*\TmpH},{0}) rectangle++ ({\TmpH},{\y1}) ;
          }%
        }%
        {}%
      \IfEq{\graphtikzintgrtype}{RectanglesDroite}%
        {%
          \foreach \i in {0,...,\inteval{\graphtikzintgrnb-1}}{%
            \path[draw=none,pflcourbe,name path=tmpintmethod] ({#3+(\i+1)*\TmpH},{\pflymin})--({#3+(\i+1)*\TmpH},{\pflymax}) ;
            \path[name intersections={of=#2 and tmpintmethod,name=KLM}] ;
            \draw[pflfigureintegr] let \p1 = (KLM-1) in ({#3+\i*\TmpH},{0}) rectangle++ ({\TmpH},{\y1}) ;
          }%
        }%
        {}%
      \IfEq{\graphtikzintgrtype}{RectanglesMilieu}%
        {%
          \foreach \i in {0,...,\inteval{\graphtikzintgrnb-1}}{%
            \path[draw=none,pflcourbe,name path=tmpintmethod] ({#3+(\i+0.5)*\TmpH},{\pflymin})--({#3+(\i+0.5)*\TmpH},{\pflymax}) ;
            \path[name intersections={of=#2 and tmpintmethod,name=KLM}] ;
            \draw[pflfigureintegr] let \p1 = (KLM-1) in ({#3+\i*\TmpH},{0}) rectangle++ ({\TmpH},{\y1}) ;
          }%
        }%
        {}%
      \IfEq{\graphtikzintgrtype}{Trapezes}%
        {%
          \foreach \i in {0,...,\inteval{\graphtikzintgrnb-1}}{%
            \path[draw=none,pflcourbe,name path=tmpintmethodg] ({#3+(\i)*\TmpH},{\pflymin})--({#3+(\i)*\TmpH},{\pflymax}) ;
            \path[name intersections={of=#2 and tmpintmethodg,name=KLMg}] ;
            \path[draw=none,pflcourbe,name path=tmpintmethodd] ({#3+(\i+1)*\TmpH},{\pflymin})--({#3+(\i+1)*\TmpH},{\pflymax}) ;
            \path[name intersections={of=#2 and tmpintmethodd,name=KLMd}] ;
            \draw[pflfigureintegr] ({#3+\i*\TmpH},{0}) -- (KLMg-1) -- (KLMd-1) -- ({#3+(\i+1)*\TmpH},{0}) -- cycle ;
          }%
        }%
        {}%
    }%
    {%
      \IfEq{\graphtikzintgrtype}{RectanglesGauche}%
        {%
          \foreach \i in {0,...,\inteval{\graphtikzintgrnb-1}}%
            \draw[pflfigureintegr] ({#3+\i*\TmpH},{0}) rectangle++ ({\TmpH},{\xintfloateval{#2(#3+\i*\TmpH)}}) ;
        }%
        {}%
      \IfEq{\graphtikzintgrtype}{RectanglesDroite}%
        {%
          \foreach \i in {0,...,\inteval{\graphtikzintgrnb-1}}%
            \draw[pflfigureintegr] ({#3+\i*\TmpH},{0}) rectangle++ ({\TmpH},{\xintfloateval{#2(#3+(\i+1)*\TmpH)}}) ;
        }%
        {}%
      \IfEq{\graphtikzintgrtype}{RectanglesMilieu}%
        {%
          \foreach \i in {0,...,\inteval{\graphtikzintgrnb-1}}%
            \draw[pflfigureintegr] ({#3+\i*\TmpH},{0}) rectangle++ ({\TmpH},{\xintfloateval{#2(#3+(\i+0.5)*\TmpH)}}) ;
        }%
        {}%
      \IfEq{\graphtikzintgrtype}{Trapezes}%
        {%
          \foreach \i in {0,...,\inteval{\graphtikzintgrnb-1}}%
            \draw[pflfigureintegr] ({#3+\i*\TmpH},{0}) -- ({#3+\i*\TmpH},{\xintfloateval{#2(#3+\i*\TmpH)}}) -- ({#3+(\i+1)*\TmpH},{\xintfloateval{#2(#3+(\i+1)*\TmpH)}}) -- ({#3+(\i+1)*\TmpH},{0}) -- cycle ;
        }%
        {}%
    }%
}

%====INTÉGRALES
%v2 avec modification de la clé [Type=...] ?
\defKV[GraphiqueTikzIntegr]{%
  Couleurs=\def\pfldomtikzcolors{#1},%
  Style=\def\pfldomtikzstyle{#1},%
  Opacite=\def\pfldomtikzopac{#1},%
  Hachures=\def\pfldomtikzhatch{#1},%
  Type=\def\pfldomtikztype{#1},%
  Pas=\def\pflstepcurve{#1},%
  Bornes=\def\pflintbornes{#1},%
  Jonction=\def\pfldomtikzjoin{#1},%
  NomInterpo=\def\pfldomtikznameinterpo{#1},%
  NomInterpoB=\def\pfldomtikznameinterpob{#1},%
  NomSpline=\def\pfldomtikznamespline{#1},%
  NomSplineB=\def\pfldomtikznamesplineb{#1}
}
\setKVdefault[GraphiqueTikzIntegr]{%
  Couleurs=gray,%
  Style=remplissage,%
  Opacite=0.5,%
  Hachures={north west lines},%
  Type=fct,%
  Pas={},%
  Jonction=bevel,%
  Bornes=abs,%
  Bord=true,%
  Spline=false,%
  SplineB=false,%
  NomInterpo={\moninterpo},%
  NomInterpoB={\moninterpoB},%
  NomSpline={\monspline},%
  NomSplineB={\monsplineB},%
  Tension=0.5,%
  TensionB=0.5
}

\NewDocumentCommand\TracerIntegrale{ O{} D<>{} m O{0} m m }{%
  %1 = clés
  %2 = options particulières tikz
  %3 = fonction, en tikz
  %4 = fonction n°2 éventuelle
  %de #5 à #6
  \restoreKV[GraphiqueTikzIntegr]% revenir au valeurs par défaut
  \setKV[GraphiqueTikzIntegr]{#1}% lit les arguments optionnels
  %les couleurs
  \IfSubStr{\pfldomtikzcolors}{/}%
    {%
      \StrCut{\pfldomtikzcolors}{/}{\pfldomtikzcolorbord}{\pfldomtikzcolorfond}
    }%
    {%
      \xdef\pfldomtikzcolorbord{\pfldomtikzcolors}\xdef\pfldomtikzcolorfond{\pfldomtikzcolors}
    }%
  \ifboolKV[GraphiqueTikzIntegr]{Bord}%
    {%
      \tikzset{integralebordtikzstyle/.style={draw=\pfldomtikzcolorbord}}
    }%
    {%
      \tikzset{integralebordtikzstyle/.style={draw=none}}
    }%
  \IfStrEq{\pfldomtikzstyle}{hachures}%
    {%
      \tikzset{integraletikzstyle/.style={pfltrait,pattern=\pfldomtikzhatch,pattern color=\pfldomtikzcolorfond,line join=\pfldomtikzjoin}}
    }%
    {}%
  \IfStrEq{\pfldomtikzstyle}{remplissage}%
    {%
      \tikzset{integraletikzstyle/.style={pfltrait,fill=\pfldomtikzcolorfond,fill opacity=\pfldomtikzopac,line join=\pfldomtikzjoin}}
    }%
    {}%
  %extraction des infos x/y
  \IfStrEqCase{\pflintbornes}{%
    {abs}%
    {%
      \xdef\absnoeudA{#5}%
      \xdef\absnoeudB{#6}%
    }%
    {noeuds}%
    {%
      \path #5;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudA{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
      \path #6;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudB{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
    }%
    {abs/noeud}%
    {%
      \xdef\absnoeudA{#5}%
      \path #6;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudB{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
    }%
    {noeud/abs}%
    {%
      \path #5;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudA{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
      \xdef\absnoeudB{#6}%
    }%
  }%
  %suite avec les nbs points
  \IfStrEq{\pflstepcurve}{}%
    {%
      \xdef\pflstepcurve{\xintfloateval{((\absnoeudB)-(\absnoeudA))/100}}%
    }%
    {}%
  %TRACÉSen fonction des types de courbes
  \IfStrEq{\pfldomtikztype}{fct}%
    {%OK
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
        \draw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflOy}) -- plot[smooth] coordinates {\xintthecoords\xintfloatexpr seq((x,#3),x=\absnoeudA..[\pflstepcurve]..\absnoeudB,\absnoeudB)\relax} -- ({\absnoeudB},{\pflOy}) -- cycle ;
      \end{scope}
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{spl}%avec 3=courbe spline + clé [Spline] à utiliser !
    {%OK
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflOy}) -- \pfldomtikznamespline -- ({\absnoeudB},{\pflOy}) -- cycle ;
      \end{scope}
      \path[draw=none,pflcourbe,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[name intersections={of=#3 and tmpintbornea,name=YYY}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudA},{\pflOy})-- (YYY-1) ;
      \path[draw=none,pflcourbe,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=#3 and tmpintborneb,name=ZZZ}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudB},{\pflOy})-- (ZZZ-1) ;
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{itp}%avec 3=courbe interpo
    {%OK
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflOy}) -- plot [smooth,tension={\useKV[GraphiqueTikzIntegr]{Tension}}] coordinates {#3} -- ({\absnoeudB},{\pflOy}) -- cycle ;
      \end{scope}
      \path[draw=none,pflcourbe,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[name intersections={of=tmpintbornea and \pfldomtikznameinterpo,name=YYY}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudA},{\pflOy})-- (YYY-1) ;
      \path[draw=none,pflcourbe,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=tmpintborneb and \pfldomtikznameinterpo,name=ZZZ}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudB},{\pflOy})-- (ZZZ-1) ;
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{fct/fct}%avec #3=formule et #4=formule
    {%
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
        \draw[integraletikzstyle,integralebordtikzstyle,#2] plot[smooth] coordinates {\xintthecoords\xintfloatexpr seq((x,#3),x=\absnoeudA..[\pflstepcurve]..\absnoeudB,\absnoeudB)\relax} -- plot[smooth] coordinates {\xintthecoords\xintfloatexpr seq((x,#4),x=\absnoeudB..[-(\pflstepcurve)]..\absnoeudA,\absnoeudA)\relax} -- cycle ;
      \end{scope}
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{spl/spl}%avec #3=cbe spline + #4=cbe splineB
    {%
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \clip ({\absnoeudA},{\pflymin}) -- \pfldomtikznamespline -- ({\absnoeudB},{\pflymin}) -- cycle ;
        \clip ({\absnoeudA},{\pflymax}) -- \pfldomtikznamesplineb -- ({\absnoeudB},{\pflymax}) -- cycle ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,pflcourbe,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[name intersections={of=#3 and tmpintbornea,name=YYYA}] ;
      \path[name intersections={of=#4 and tmpintbornea,name=ZZZA}] ;
      \path[draw=none,pflcourbe,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=#3 and tmpintborneb,name=YYYB}] ;
      \path[name intersections={of=#4 and tmpintborneb,name=ZZZB}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] (YYYA-1)-- (ZZZA-1) ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] (YYYB-1)-- (ZZZB-1) ;
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{itp/itp}%avec #3=cbe interpo + #4=cbe interpoB
    {%
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \clip ({\absnoeudA},{\pflymin}) -- plot [smooth,tension={\useKV[GraphiqueTikzIntegr]{Tension}}] coordinates {#3} -- ({\absnoeudB},{\pflymin}) ;
        \clip ({\absnoeudA},{\pflymax}) -- plot [smooth,tension={\useKV[GraphiqueTikzIntegr]{TensionB}}] coordinates {#4} -- ({\absnoeudB},{\pflymax}) ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,pflcourbe,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[name intersections={of=tmpintbornea and \pfldomtikznameinterpo,name=YYYA}] ;
      \path[name intersections={of=tmpintbornea and \pfldomtikznameinterpob,name=ZZZA}] ;
      \path[draw=none,pflcourbe,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=tmpintborneb and \pfldomtikznameinterpo,name=YYYB}] ;
      \path[name intersections={of=tmpintborneb and \pfldomtikznameinterpob,name=ZZZB}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] (YYYA-1)-- (ZZZA-1) ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] (YYYB-1)-- (ZZZB-1) ;
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{fct/spl}%avec #3=formule + #4=spline
    {%
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \clip ({\absnoeudA},{\pflymin}) -- plot[smooth] coordinates {\xintthecoords\xintfloatexpr seq((x,#3),x=\absnoeudA..[\pflstepcurve]..\absnoeudB,\absnoeudB)\relax} -- ({\absnoeudB},{\pflymin}) -- cycle ;
        \clip ({\absnoeudA},{\pflymax}) -- \pfldomtikznamesplineb -- ({\absnoeudB},{\pflymax}) -- cycle ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,pflcourbe,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[name intersections={of=tmpintbornea and #4,name=ZZZA}] ;
      \path[draw=none,pflcourbe,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=tmpintborneb and #4,name=ZZZB}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudA},{\xintfloateval{subs(#3,x=\absnoeudA)}})-- (ZZZA-1) ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudB},{\xintfloateval{subs(#3,x=\absnoeudB)}})-- (ZZZB-1) ;
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{spl/fct}%avec #3=spline + #4=fct
    {%
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \clip ({\absnoeudA},{\pflymax}) -- plot[smooth] coordinates {\xintthecoords\xintfloatexpr seq((x,#4),x=\absnoeudA..[\pflstepcurve]..\absnoeudB,\absnoeudB)\relax} -- ({\absnoeudB},{\pflymax}) -- cycle ;
        \clip ({\absnoeudA},{\pflymin}) -- \pfldomtikznamespline -- ({\absnoeudB},{\pflymin}) -- cycle ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,pflcourbe,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[name intersections={of=tmpintbornea and #3,name=ZZZA}] ;
      \path[draw=none,pflcourbe,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=tmpintborneb and #3,name=ZZZB}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudA},{\xintfloateval{subs(#4,x=\absnoeudA)}})-- (ZZZA-1) ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudB},{\xintfloateval{subs(#4,x=\absnoeudB)}})-- (ZZZB-1) ;
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{fct/itp}%avec #3=formule + #4=liste interpo
    {%
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \clip ({\absnoeudA},{\pflymin}) -- plot[smooth] coordinates {\xintthecoords\xintfloatexpr seq((x,#3),x=\absnoeudA..[\pflstepcurve]..\absnoeudB,\absnoeudB)\relax} -- ({\absnoeudB},{\pflymin}) -- cycle ;
        \clip ({\absnoeudA},{\pflymax}) -- plot [smooth,tension={\useKV[GraphiqueTikzIntegr]{TensionB}}] coordinates {#4} -- ({\absnoeudB},{\pflymax}) ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,pflcourbe,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[draw=none,pflcourbe,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=tmpintbornea and \pfldomtikznameinterpob,name=ZZZAA}] ;
      \path[name intersections={of=tmpintborneb and \pfldomtikznameinterpob,name=ZZZAB}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudA},{\xintfloateval{subs(#3,x=\absnoeudA)}})-- (ZZZAA-1) ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudB},{\xintfloateval{subs(#3,x=\absnoeudB)}})-- (ZZZAB-1) ;
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{itp/fct}%
    {%
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \clip ({\absnoeudA},{\pflymax}) -- plot[smooth] coordinates {\xintthecoords\xintfloatexpr seq((x,#4),x=\absnoeudA..[\pflstepcurve]..\absnoeudB,\absnoeudB)\relax} -- ({\absnoeudB},{\pflymax}) -- cycle ;
        \clip ({\absnoeudA},{\pflymin}) -- plot [smooth,tension={\useKV[GraphiqueTikzIntegr]{Tension}}] coordinates {#3} -- ({\absnoeudB},{\pflymin}) ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,pflcourbe,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[draw=none,pflcourbe,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=tmpintbornea and \pfldomtikznameinterpo,name=ZZZAA}] ;
      \path[name intersections={of=tmpintborneb and \pfldomtikznameinterpo,name=ZZZAB}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudA},{\xintfloateval{subs(#4,x=\absnoeudA)}})-- (ZZZAA-1) ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] ({\absnoeudB},{\xintfloateval{subs(#4,x=\absnoeudB)}})-- (ZZZAB-1) ;
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{itp/spl}%
    {%
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \clip ({\absnoeudA},{\pflymin}) -- plot [smooth,tension={\useKV[GraphiqueTikzIntegr]{Tension}}] coordinates {#3} -- ({\absnoeudB},{\pflymin}) ;
        \clip ({\absnoeudA},{\pflymax}) -- \pfldomtikznamesplineb -- ({\absnoeudB},{\pflymax}) -- cycle ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,pflcourbe,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;%borne inf
      \path[draw=none,pflcourbe,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;%borne sup
      \path[name intersections={of=tmpintbornea and \pfldomtikznameinterpo,name=YYYKAA}] ;
      \path[name intersections={of=tmpintborneb and \pfldomtikznameinterpo,name=YYYKBB}] ;
      \path[name intersections={of=tmpintbornea and #4,name=ZZZKAA}] ;
      \path[name intersections={of=tmpintborneb and #4,name=ZZZKBB}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] (YYYKAA-1)-- (ZZZKAA-1) ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] (YYYKBB-1)-- (ZZZKBB-1) ;
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{spl/itp}%
    {%
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \clip ({\absnoeudA},{\pflymax}) -- plot [smooth,tension={\useKV[GraphiqueTikzIntegr]{TensionB}}] coordinates {#4} -- ({\absnoeudB},{\pflymax}) ;
        \clip ({\absnoeudA},{\pflymin}) -- \pfldomtikznamespline -- ({\absnoeudB},{\pflymin}) -- cycle ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,pflcourbe,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;%borne inf
      \path[draw=none,pflcourbe,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;%borne sup
      \path[name intersections={of=tmpintbornea and \pfldomtikznameinterpob,name=YYYKAA}] ;
      \path[name intersections={of=tmpintborneb and \pfldomtikznameinterpob,name=YYYKBB}] ;
      \path[name intersections={of=tmpintbornea and #3,name=ZZZKAA}] ;
      \path[name intersections={of=tmpintborneb and #3,name=ZZZKBB}] ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] (YYYKAA-1)-- (ZZZKAA-1) ;
      \draw[color=\pfldomtikzcolorbord,pfltrait] (YYYKBB-1)-- (ZZZKBB-1) ;
    }%
    {}%
}

%====REPRÉSENTER INTÉGRALE via path (version classique, path-based)
% Compatible avec \DefinirCourbe[Nom=...], \DefinirCourbeSpline[Nom=...],
% \DefinirCourbeInterpo[Nom=...]
\defKV[GraphiqueTikzIntegrPath]{%
  Couleurs=\def\pfldomtikzcolors{#1},%
  Style=\def\pfldomtikzstyle{#1},%
  Opacite=\def\pfldomtikzopac{#1},%
  Hachures=\def\pfldomtikzhatch{#1},%
  Bornes=\def\pflintbornes{#1}
}
\setKVdefault[GraphiqueTikzIntegrPath]{%
  Couleurs=gray,%
  Style=remplissage,%
  Opacite=0.5,%
  Hachures={north west lines},%
  Bord=true,%
  Bornes=abs%
}

\NewDocumentCommand\RepresenterIntegrale{ O{} m O{} m m }{%
  % #1=clés  #2=nom path 1  #3=nom path 2 (optionnel)
  % #4=borne a  #5=borne b
  \restoreKV[GraphiqueTikzIntegrPath]%
  \setKV[GraphiqueTikzIntegrPath]{#1}%
  % couleurs bord/fond
  \IfSubStr{\pfldomtikzcolors}{/}%
    {\StrCut{\pfldomtikzcolors}{/}{\pfldomcolorbord}{\pfldomcolorfond}}%
    {\xdef\pfldomcolorbord{\pfldomtikzcolors}%
     \xdef\pfldomcolorfond{\pfldomtikzcolors}}%
  % style
  \IfSubStr{,hachures,hatch,}{,\pfldomtikzstyle,}%
    {\tikzset{integraletikzstyle/.style={%
      draw=none,pattern=\pfldomtikzhatch,%
      pattern color=\pfldomcolorfond}}}%
    {\tikzset{integraletikzstyle/.style={%
      draw=none,fill=\pfldomcolorfond,%
      fill opacity=\pfldomtikzopac}}}%
   %extraction des infos x/y
  \IfStrEqCase{\pflintbornes}{%
    {abs}%
    {%
      \xdef\absnoeudA{#4}%
      \xdef\absnoeudB{#5}%
    }%
    {noeuds}%
    {%
      \path #4;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudA{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
      \path #5;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudB{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
    }%
    {abs/noeud}%
    {%
      \xdef\absnoeudA{#4}%
      \path #5;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudB{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
    }%
    {noeud/abs}%
    {%
      \path #4;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudA{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
      \xdef\absnoeudB{#5}%
    }%
  }%
  %suite
  \ifboolKV[GraphiqueTikzIntegrPath]{Bord}%
    {\tikzset{integralebordtikzstyle/.style={draw=\pfldomcolorbord}}}%
    {\tikzset{integralebordtikzstyle/.style={draw=none}}}%
  % tracé
  \IfStrEq{#3}{}%
    {%---- cas 1 : sous la courbe
      \begin{scope}%
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;%
        \filldraw[integraletikzstyle,integralebordtikzstyle]%
          ({\absnoeudA},{\pflOy})%
          [spath/restore=#2]%
          -- ({\absnoeudB},{\pflOy}) -- ({\absnoeudA},{\pflOy}) ;%
      \end{scope}%
      % traits verticaux aux bornes (protégés)
      \ifboolKV[GraphiqueTikzIntegrPath]{Bord}%
        {%
          \path[draw=none,name path=tmpintbornea] ({\absnoeudA},{\pflymin}) -- ({\absnoeudA},{\pflymax}) ;%
          \path[draw=none,name path=tmpintborneb] ({\absnoeudB},{\pflymin}) -- ({\absnoeudB},{\pflymax}) ;%
          \path[name intersections={of=#2 and tmpintbornea, name=YYYRI,total=\t}] \pgfextra{\xdef\pflintborneAtot{\t}} ;%
          \path[name intersections={of=#2 and tmpintborneb, name=ZZZRI,total=\t}] \pgfextra{\xdef\pflintborneBtot{\t}} ;%
          \xintifboolexpr{\pflintborneAtot > 0}%
            {\draw[color=\pfldomcolorbord,pfltrait] ({\absnoeudA},{\pflOy}) -- (YYYRI-1) ;}{}%
          \xintifboolexpr{\pflintborneBtot > 0}%
            {\draw[color=\pfldomcolorbord,pfltrait] ({\absnoeudB},{\pflOy}) -- (ZZZRI-1) ;}{}%
        }{}%
    }%
    {%---- cas 2 : entre deux courbes (double scope)
      % scope 1 : #2 au-dessus de #3
      \begin{scope}%
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;%
        \clip ({\absnoeudA},{\pflymin}) [spath/restore=#2] -- ({\absnoeudB},{\pflymin}) -- ({\absnoeudA},{\pflymin}) ;%
        \clip ({\absnoeudA},{\pflymax}) [spath/restore=#3] -- ({\absnoeudB},{\pflymax}) -- ({\absnoeudA},{\pflymax}) ;%
        \filldraw[integraletikzstyle,integralebordtikzstyle] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;%
      \end{scope}%
      % scope 2 : #3 au-dessus de #2
      \begin{scope}%
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;%
        \clip ({\absnoeudA},{\pflymin}) [spath/restore=#3] -- ({\absnoeudB},{\pflymin}) -- ({\absnoeudA},{\pflymin}) ;%
        \clip ({\absnoeudA},{\pflymax}) [spath/restore=#2] -- ({\absnoeudB},{\pflymax}) -- ({\absnoeudA},{\pflymax}) ;%
        \filldraw[integraletikzstyle,integralebordtikzstyle] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;%
      \end{scope}%
      % traits verticaux aux bornes (protégés)
      \ifboolKV[GraphiqueTikzIntegrPath]{Bord}%
        {%
          \path[draw=none,name path=tmpintbornea] ({\absnoeudA},{\pflymin}) -- ({\absnoeudA},{\pflymax}) ;%
          \path[draw=none,name path=tmpintborneb] ({\absnoeudB},{\pflymin}) -- ({\absnoeudB},{\pflymax}) ;%
          \path[name intersections={of=#2 and tmpintbornea, name=YYYRI,total=\t}] \pgfextra{\xdef\pflintborneAtot{\t}} ;%
          \path[name intersections={of=#2 and tmpintborneb,name=ZZZRI,total=\t}] \pgfextra{\xdef\pflintborneBtot{\t}} ;%
          \path[name intersections={of=#3 and tmpintbornea,name=YYYRIB,total=\t}] \pgfextra{\xdef\pflintborneABtot{\t}} ;%
          \path[name intersections={of=#3 and tmpintborneb,name=ZZZRIB,total=\t}] \pgfextra{\xdef\pflintborneBBtot{\t}} ;%
          \xintifboolexpr{\pflintborneAtot > 0}%
            {\draw[color=\pfldomcolorbord,pfltrait] ({\absnoeudA},{\pflOy}) -- (YYYRI-1) ;}%
            {}%
          \xintifboolexpr{\pflintborneBtot > 0}%
            {\draw[color=\pfldomcolorbord,pfltrait] ({\absnoeudB},{\pflOy}) -- (ZZZRI-1) ;}%
            {}%
          \xintifboolexpr{\pflintborneABtot > 0}%
            {\draw[color=\pfldomcolorbord,pfltrait] ({\absnoeudA},{\pflOy}) -- (YYYRIB-1) ;}%
            {}%
          \xintifboolexpr{\pflintborneBBtot > 0}%
            {\draw[color=\pfldomcolorbord,pfltrait] ({\absnoeudB},{\pflOy}) -- (ZZZRIB-1) ;}%
            {}%
        }{}%
    }%
}

%====POINTS
\NewDocumentCommand\PlacerPoints{ s O{black} D<>{\normalfont\normalsize} m }{%
  \IfBooleanTF{#1}%
    {%
      \foreach \Point in {#4}{%
        \filldraw[#2] \Point circle[pflpointc] ;
      }
    }%
    {%
      \foreach \Point/\Pos/\Label in {#4}{%
        \filldraw[#2] \Point circle[pflpointc] node[pflnoeud,\Pos,font=#3] {\Label} ;
      }
    }%
}

%====STATS À 2 VARIABLES
\defKV[GraphiqueTikzRegLin]{%
  Arrondis=\def\pflarrondisreglin{#1},
  Nom=\def\pflnamereglin{#1},
  NomPara=\def\pflnameregquad{#1},
  Debut=\def\pflreglinmin{#1},
  Fin=\def\pflreglinmax{#1},%
  TaillePts=\def\pflreglintaillepts{#1},%
  ModeTransfo=\def\pflreglinmode{#1}
}
\setKVdefault[GraphiqueTikzRegLin]{
  CouleurNuage=black,
  CouleurDroite=black,
  CouleurPara=black,
  Arrondis={},
  Debut={\pflxmin},
  Fin={\pflxmax},
  Nom=reglin,%
  NomPara=quadreg,%
  TracerDroite=false,%
  TracerParabole=false,%
  Style=o,%
  TaillePts=1.75pt,%
  ModeTransfo={lin}
}

\NewDocumentCommand\TracerNuageSuite{ s O{} m }{%
  \useKVdefault[GraphiqueTikzRegLin]%
  \setKV[GraphiqueTikzRegLin]{#2}% on paramètres les nouvelles clés et on les simplifie
  \xintdeffloatfunc tmpu(n) := #3 ;
  \IfStrEq{\pflnamereglin}{reglin}{\def\pflnamereglin{u}}{}%
  \IfBooleanTF{#1}%
    {%
      \foreach \n in {\pflreglinmin,...,\pflreglinmax}{%
        \MarquerPts*%
          [Style={\useKV[GraphiqueTikzRegLin]{Style}},Couleur={\useKV[GraphiqueTikzRegLin]{CouleurNuage}},Taillec=\pflreglintaillepts,Taillex=\pflreglintaillepts,Tailleo=\pflreglintaillepts]%
          {(\n,\xintfloateval{tmpu(\n)})}%
      }
    }%
    {%
      \foreach \n in {\pflreglinmin,...,\pflreglinmax}{%
        \MarquerPts%
          [Style={\useKV[GraphiqueTikzRegLin]{Style}},Couleur={\useKV[GraphiqueTikzRegLin]{CouleurNuage}},Taillec=\pflreglintaillepts,Taillex=\pflreglintaillepts,Tailleo=\pflreglintaillepts]%
          {(\n,\xintfloateval{tmpu(\n)})/{$\pflnamereglin_{\n}$}/below}%
      }
    }%
}

%====TOILE RÉCURRENCE (OK avec courbe + spline !!)
\defKV[tkzwebrecurr]{%
  Couleur=\def\pflrecurcolor{#1},%
  Nom=\def\pflrecurnom{#1},%
  No=\def\pflrecurno{#1},%
  Nb=\def\pflrecurnb{#1},%
  Uno=\def\pflrecuruno{#1},
  TailleLabel=\def\pflrecurlabelsize{#1},%
  PosLabel=\def\pflrecurlabelpos{#1}
}

\setKVdefault[tkzwebrecurr]{%
  Couleur=black,%
  Spline=false,%
  No=0,%
  Nom=u,%
  Nb=5,%
  AffTermes=false,%
  AffPointilles=true,%
  TailleLabel=\small,%
  PosLabel=below
}

\NewDocumentCommand\TracerToileRecurrence{ O{} m }{
  %<clés> + fonction/courbe
  \useKVdefault[tkzwebrecurr]%
  \setKV[tkzwebrecurr]{#1}% on paramètres les nouvelles clés et on les simplifie
  \ifboolKV[tkzwebrecurr]{Spline}%
    {%
      \foreach \i [remember=\i as \x (initially \pflrecuruno)] in {1,...,\pflrecurnb}{%
        %\xdef\y{\xintfloateval{#2(\x)}}%
        \path[draw=none,pflcourbe,name path=tmprecur] ({\x},{\pflymin})--({\x},{\pflymax}) ;
        \path[name intersections={of=#2 and tmprecur,name=ZZZZ}] ;
        %\coordinate (\pflrecurnoms) at (ZZZZ-1) ;
        \GetYcoord{(ZZZZ-1)}[\y]
        %test de la position courbe / bissectrice ?
        \ifnum \i=1
          \newdimen \X
          \newdimen \Y
          \X = \x pt
          \Y = \y pt
          \ifdim \Y < \X
            \draw[pfltraitrec,color=\pflrecurcolor] (\x,\y)--(\y,\y) ;
          \else
            \draw[pfltraitrec,color=\pflrecurcolor] (\x,\x)--(\x,\y)--(\y,\y) ;
          \fi
        \else
          \draw[pfltraitrec,color=\pflrecurcolor] (\x,\x)--(\x,\y)--(\y,\y) ;
        \fi
        \ifboolKV[tkzwebrecurr]{AffPointilles}%
          {%
            \def\indice{\fpeval{\i+\pflrecurno-1}}%
            \ifboolKV[tkzwebrecurr]{AffTermes}%
              {%
                \draw[pfltraitrecpointill,color=\pflrecurcolor] (\x,\y)--(\x,\pflxmin) node[\pflrecurlabelpos,font=\pflrecurlabelsize]{$\pflrecurnom_{\indice}$};%
              }%
              {%
                \draw[pfltraitrecpointill,color=\pflrecurcolor] (\x,\y)--(\x,\pflxmin) ;%
              }%
          }%
          {}
        \def\i{\y}%
      }%
    }%
    {%
      \foreach \i [remember=\i as \x (initially \pflrecuruno)] in {1,...,\pflrecurnb}{%
        \xdef\y{\xintfloateval{#2(\x)}}%
        %test de la position courbe / bissectrice ?
        \ifnum \i=1
          \newdimen \X
          \newdimen \Y
          \X = \x pt
          \Y = \y pt
          \ifdim \Y < \X
            \draw[pfltraitrec,color=\pflrecurcolor] (\x,\y)--(\y,\y) ;
          \else
            \draw[pfltraitrec,color=\pflrecurcolor] (\x,\x)--(\x,\y)--(\y,\y) ;
          \fi
        \else
          \draw[pfltraitrec,color=\pflrecurcolor] (\x,\x)--(\x,\y)--(\y,\y) ;
        \fi
        \ifboolKV[tkzwebrecurr]{AffPointilles}%
          {%
            \def\indice{\fpeval{\i+\pflrecurno-1}}%
            \ifboolKV[tkzwebrecurr]{AffTermes}%
              {%
                \draw[pfltraitrecpointill,color=\pflrecurcolor] (\x,\y)--(\x,\pflxmin) node[\pflrecurlabelpos,font=\pflrecurlabelsize]{$\pflrecurnom_{\indice}$};%
              }%
              {%
                \draw[pfltraitrecpointill,color=\pflrecurcolor] (\x,\y)--(\x,\pflxmin) ;%
              }%
          }%
          {}
        \def\i{\xintfloateval{\y}}%
      }%
    }%
}

\defKV[GraphiqueTikzNuageSuiteF]{%
  CouleurNuage=\def\pflnuagetmpcolor{#1},%
  Style=\def\pflnuagetmpstyle{#1},%
  TaillePts=\def\pflnuagetmptaille{#1},%
  Debut=\def\pflnuagetmpdebut{#1},%
  Fin=\def\pflnuagetmpfin{#1},%
  Nom=\def\pflnuagetmpnom{#1},%
  Type=\def\pflnuagetmptype{#1}%
}
\setKVdefault[GraphiqueTikzNuageSuiteF]{%
  CouleurNuage=black,%
  Style=o,%
  TaillePts=1.75pt,%
  Debut=0,%
  Fin=10,%
  Nom=u,%
  Type=Recurrent%
}
 
\NewDocumentCommand\TracerNuageSuiteF{ s O{} m m }{%
  \useKVdefault[GraphiqueTikzNuageSuiteF]%
  \setKV[GraphiqueTikzNuageSuiteF]{#2}%
  % définir f(x) := formule
  \xintdeffloatfunc tmpuf(x) := #4 ;%
  % u courant initialisé à u_Debut
  \xdef\pflsuiterecval{\xintfloateval{#3}}%
  % boucle de Debut jusqu'à Fin
  \foreach \n in {\pflnuagetmpdebut,...,\pflnuagetmpfin}{%
    \IfBooleanTF{#1}%
      {%
        % version * : points seuls, sans label
        \MarquerPts*%
          [Style=\pflnuagetmpstyle,%
           Couleur=\pflnuagetmpcolor,%
           Taillec=\pflnuagetmptaille,%
           Taillex=\pflnuagetmptaille,%
           Tailleo=\pflnuagetmptaille]%
          {(\n,\pflsuiterecval)}%
      }%
      {%
        % version sans * : points avec label $u_n$
        \MarquerPts%
          [Style=\pflnuagetmpstyle,%
           Couleur=\pflnuagetmpcolor,%
           Taillec=\pflnuagetmptaille,%
           Taillex=\pflnuagetmptaille,%
           Tailleo=\pflnuagetmptaille]%
          {(\n,\pflsuiterecval)/{$\pflnuagetmpnom_{\n}$}/below}%
      }%
    % itération u_{n+1} = f(u_n), sauf au dernier rang
    \xintifboolexpr{ \n < \pflnuagetmpfin }%
      {%
        \xdef\pflsuiterecval{\xintfloateval{tmpuf(\pflsuiterecval)}}%
      }{}%
  }%
}

\NewDocumentCommand\TracerNuageSuiteFn{ s O{} m m }{%
  \useKVdefault[GraphiqueTikzNuageSuiteF]%
  \setKV[GraphiqueTikzNuageSuiteF]{#2}%
  % définir f(x,n) := formule — x=u_n, n=rang
  \xintdeffloatfunc tmpufn(x,n) := #4 ;%
  % u courant initialisé à u_Debut
  \xdef\pflsuiterecval{\xintfloateval{#3}}%
  % boucle de Debut jusqu'à Fin
  \foreach \n in {\pflnuagetmpdebut,...,\pflnuagetmpfin}{%
    \IfBooleanTF{#1}%
      {%
        \MarquerPts*%
          [Style=\pflnuagetmpstyle,%
           Couleur=\pflnuagetmpcolor,%
           Taillec=\pflnuagetmptaille,%
           Taillex=\pflnuagetmptaille,%
           Tailleo=\pflnuagetmptaille]%
          {(\n,\pflsuiterecval)}%
      }%
      {%
        \MarquerPts%
          [Style=\pflnuagetmpstyle,%
           Couleur=\pflnuagetmpcolor,%
           Taillec=\pflnuagetmptaille,%
           Taillex=\pflnuagetmptaille,%
           Tailleo=\pflnuagetmptaille]%
          {(\n,\pflsuiterecval)/{$\pflnuagetmpnom_{\n}$}/below}%
      }%
    % itération u_{n+1} = f(u_n, n), sauf au dernier rang
    \xintifboolexpr{ \n < \pflnuagetmpfin }{%
      \xdef\pflsuiterecval{\xintfloateval{tmpufn(\pflsuiterecval,\n)}}%
    }{}%
  }%
}

\NewDocumentCommand\TracerNuageSuiteDouble{ s O{} m m m }{%
  \useKVdefault[GraphiqueTikzNuageSuiteF]%
  \setKV[GraphiqueTikzNuageSuiteF]{#2}%
  % définir f(x,y) := formule
  \xintdeffloatfunc tmpuab(x,y) := #5 ;%
  % deux états : A=u_n, B=u_{n+1}
  \xdef\pflsuiterecvalA{\xintfloateval{#3}}%
  \xdef\pflsuiterecvalB{\xintfloateval{#4}}%
  % tracé du premier point (rang Debut)
  \IfBooleanTF{#1}%
    {%
      \MarquerPts*%
        [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
         Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
        {(\pflnuagetmpdebut,\pflsuiterecvalA)}%
    }%
    {%
      \MarquerPts%
        [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
         Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
        {(\pflnuagetmpdebut,\pflsuiterecvalA)/{$\pflnuagetmpnom_{\pflnuagetmpdebut}$}/below}%
    }%
  % tracé du second point (rang Debut+1), seulement si Fin > Debut
  \xintifboolexpr{ \pflnuagetmpfin > \pflnuagetmpdebut }%
    {%
      \IfBooleanTF{#1}%
        {%
          \MarquerPts*%
            [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
             Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
            {(\inteval{\pflnuagetmpdebut+1},\pflsuiterecvalB)}%
        }%
        {%
          \MarquerPts%
            [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
             Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
            {(\inteval{\pflnuagetmpdebut+1},\pflsuiterecvalB)/{$\pflnuagetmpnom_{\inteval{\pflnuagetmpdebut+1}}$}/below}%
        }%
    }{}%
  % boucle de glissement à partir du rang Debut+2
  \foreach \n in {\inteval{\pflnuagetmpdebut+2},...,\pflnuagetmpfin}{%
    \xdef\pflsuiterecvalC{\xintfloateval{tmpuab(\pflsuiterecvalA,\pflsuiterecvalB)}}%
    \xdef\pflsuiterecvalA{\pflsuiterecvalB}%
    \xdef\pflsuiterecvalB{\pflsuiterecvalC}%
    \IfBooleanTF{#1}%
      {%
        \MarquerPts*%
          [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
           Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
          {(\n,\pflsuiterecvalB)}%
      }%
      {%
        \MarquerPts%
          [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
           Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
          {(\n,\pflsuiterecvalB)/{$\pflnuagetmpnom_{\n}$}/below}%
      }%
  }%
}

\NewDocumentCommand\TracerNuageSuiteDoubleN{ s O{} m m m }{%
  \useKVdefault[GraphiqueTikzNuageSuiteF]%
  \setKV[GraphiqueTikzNuageSuiteF]{#2}%
  % définir f(x,y,n) := formule
  \xintdeffloatfunc tmpuabn(x,y,n) := #5 ;%
  \xdef\pflsuiterecvalA{\xintfloateval{#3}}%
  \xdef\pflsuiterecvalB{\xintfloateval{#4}}%
  % tracé du premier point (rang Debut)
  \IfBooleanTF{#1}%
    {%
      \MarquerPts*%
        [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
         Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
        {(\pflnuagetmpdebut,\pflsuiterecvalA)}%
    }%
    {%
      \MarquerPts%
        [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
         Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
        {(\pflnuagetmpdebut,\pflsuiterecvalA)/{$\pflnuagetmpnom_{\pflnuagetmpdebut}$}/below}%
    }%
  % tracé du second point (rang Debut+1), seulement si Fin > Debut
  \xintifboolexpr{ \pflnuagetmpfin > \pflnuagetmpdebut }%
    {%
      \IfBooleanTF{#1}%
        {%
          \MarquerPts*%
            [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
             Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
            {(\inteval{\pflnuagetmpdebut+1},\pflsuiterecvalB)}%
        }%
        {%
          \MarquerPts%
            [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
             Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
            {(\inteval{\pflnuagetmpdebut+1},\pflsuiterecvalB)/{$\pflnuagetmpnom_{\inteval{\pflnuagetmpdebut+1}}$}/below}%
        }%
    }{}%
  % boucle de glissement : à l'itération \n, on calcule u_n = f(u_{n-2},u_{n-1},n-2)
  \foreach \n in {\inteval{\pflnuagetmpdebut+2},...,\pflnuagetmpfin}{%
    \xdef\pflsuiterecvalC{\xintfloateval{tmpuabn(\pflsuiterecvalA,\pflsuiterecvalB,\n-2)}}%
    \xdef\pflsuiterecvalA{\pflsuiterecvalB}%
    \xdef\pflsuiterecvalB{\pflsuiterecvalC}%
    \IfBooleanTF{#1}%
      {%
        \MarquerPts*%
          [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
           Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
          {(\n,\pflsuiterecvalB)}%
      }%
      {%
        \MarquerPts%
          [Style=\pflnuagetmpstyle,Couleur=\pflnuagetmpcolor,%
           Taillec=\pflnuagetmptaille,Taillex=\pflnuagetmptaille,Tailleo=\pflnuagetmptaille]%
          {(\n,\pflsuiterecvalB)/{$\pflnuagetmpnom_{\n}$}/below}%
      }%
  }%
}

\NewDocumentCommand\TracerNuageSuiteAuto{ s O{} m O{} m }{%
  %1 = version étoilée := avec ou sans labels
  %2 = clés
  %3 = u0 obligatoire, même si vide :-)
  %4 = u1 optionnel
  %5 = fonction
  \useKVdefault[GraphiqueTikzNuageSuiteF]%
  \setKV[GraphiqueTikzNuageSuiteF]{#2}%
    \IfStrEqCase{\pflnuagetmptype}%
    {%
      {Explicite}{%
        % u_n = f(n) -- #3 et #4 ignorés, on réutilise le moteur de TracerNuageSuite
        \IfBooleanTF{#1}%
          {\TracerNuageSuite*[#2]{#5}}%
          {\TracerNuageSuite [#2]{#5}}%
      }%
      {RecurrentN}{%
        % u_{n+1} = f(u_n, n) -- #4 ignoré
        \IfBooleanTF{#1}%
          {\TracerNuageSuiteFn*[#2]{#3}{#5}}%
          {\TracerNuageSuiteFn [#2]{#3}{#5}}%
      }%
      {RecurrentDouble}{%
        % u_{n+2} = f(u_n, u_{n+1})
        \IfBooleanTF{#1}%
          {\TracerNuageSuiteDouble*[#2]{#3}{#4}{#5}}%
          {\TracerNuageSuiteDouble [#2]{#3}{#4}{#5}}%
      }%
      {RecurrentDoubleN}{%
        % u_{n+2} = f(u_n, u_{n+1}, n)
        \IfBooleanTF{#1}%
          {\TracerNuageSuiteDoubleN*[#2]{#3}{#4}{#5}}%
          {\TracerNuageSuiteDoubleN [#2]{#3}{#4}{#5}}%
      }%
    }%
    [%
      % défaut : Recurrent -- u_{n+1} = f(u_n) -- #4 ignoré
      \IfBooleanTF{#1}%
        {\TracerNuageSuiteF*[#2]{#3}{#5}}%
        {\TracerNuageSuiteF [#2]{#3}{#5}}%
    ]%
}

\NewDocumentCommand\TracerNuage{ O{} D<>{d} m m }{%
  \useKVdefault[GraphiqueTikzRegLin]%
  \setKV[GraphiqueTikzRegLin]{#1}% on paramètres les nouvelles clés et on les simplifie
  %listes des données
  \def\xliste{#3}
  \def\yliste{#4}
  \setsepchar{,}%
  \readlist*\LX{\xliste}
  \readlist*\LY{\yliste}
  %taille des listes
  \def\LNB{\inteval{\LXlen}}
  %nuage
  \foreach \i in {1,...,\LXlen}{%
    \itemtomacro\LX[\i]\tmpmavalx%
    \itemtomacro\LY[\i]\tmpmavaly%
    \MarquerPts*[Style={\useKV[GraphiqueTikzRegLin]{Style}},Couleur={\useKV[GraphiqueTikzRegLin]{CouleurNuage}}]{(\tmpmavalx,\tmpmavaly)}%
  }
  %droite de régression
  \ifboolKV[GraphiqueTikzRegLin]{TracerDroite}%
    {%
      %somme des LX et des LY OK
      \xdef\LXSomme{0}
      \xdef\LYSomme{0}
      \foreach \i in {1,2,...,\LNB}{
        \xdef\LXSomme{\xintfloateval{\LXSomme+\LX[\i]}}
      }
      \foreach \i in {1,2,...,\LNB}{
        \xdef\LYSomme{\xintfloateval{\LYSomme+\LY[\i]}}
      }
      %moyenne des LX et des LY OK
      \xdef\LXmoy{\xintfloateval{\LXSomme/\LNB}}
      \xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}
      %variance des LX et des LY OK
      \xdef\LXvar{0}
      \foreach \i in {1,2,...,\LNB}{
        \xdef\LXvar{\xintfloateval{\LXvar+(\LX[\i]-\LXmoy)*(\LX[\i]-\LXmoy)}}
      }
      \xdef\LXvar{\xintfloateval{\LXvar/\LNB}}
      \xdef\LYvar{0}
      \foreach \i in {1,2,...,\LNB}{
        \xdef\LYvar{\xintfloateval{\LYvar+(\LY[\i]-\LYmoy)*(\LY[\i]-\LYmoy)}}
      }
      \xdef\LYvar{\xintfloateval{\LYvar/\LNB}}
      %covariance des XY OK
      \xdef\LXYvar{0}
      \foreach \i in {1,2,...,\LNB}{
        \xdef\LXYvar{\xintfloateval{\LXYvar+(\LX[\i]-\LXmoy)*(\LY[\i]-\LYmoy)}}
      }
      \xdef\LXYvar{\xintfloateval{\LXYvar/\LNB}}
      %COEFFS OK
      \IfStrEq{\pflarrondisreglin}{}%
      {%
        \xdef\tmpcoeffreglina{\xintfloateval{\LXYvar/\LXvar}}
        \xdef\tmpcoeffreglinb{\xintfloateval{\LYmoy-\tmpcoeffreglina*\LXmoy}}
      }%
      {%
        \IfSubStr{\pflarrondisreglin}{/}%
        {%
          \StrCut{\pflarrondisreglin}{/}{\pflarrondisreglina}{\pflarrondisreglinb}
        }%
        {%
          \xdef\pflarrondisreglina{\pflarrondisreglin}\xdef\pflarrondisreglinb{\pflarrondisreglin}
        }%
        \xdef\tmpcoeffreglina{\xintfloateval{round(\LXYvar/\LXvar,\pflarrondisreglina)}}
        \xdef\tmpcoeffreglinb{\xintfloateval{round(\LYmoy-\tmpcoeffreglina*\LXmoy,\pflarrondisreglinb)}}
      }%
      \xintdeffloatfunc #2(x) := (\tmpcoeffreglina)*x+(\tmpcoeffreglinb) ;
      %tracé
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
        \draw[pflcourbe,color={\useKV[GraphiqueTikzRegLin]{CouleurDroite}},name path global=\pflnamereglin,samples=2,domain=\pflreglinmin:\pflreglinmax] plot (\x,{\tmpcoeffreglina*\x+\tmpcoeffreglinb}) ;
      \end{scope}
    }%
    {}%
  \ifboolKV[GraphiqueTikzRegLin]{TracerParabole}%
    {%
      %somme importantes
      \xdef\LXSomme{0}%
      \xdef\LXCSomme{0}%
      \xdef\LYSomme{0}%
      \xdef\LXXSomme{0}%
      \xdef\LXYSomme{0}%
      \xdef\LXXCSomme{0}%
      \xdef\LXCXCSomme{0}%
      \xdef\LXCYSomme{0}%
      %calculs
      \foreach \i in {1,2,...,\LNB}{%
        \xdef\LXSomme{\xintfloateval{\LXSomme+\LX[\i]}}%
        \xdef\LXCSomme{\xintfloateval{\LXCSomme+(\LX[\i])^2}}%
      }%
      \foreach \i in {1,2,...,\LNB}{%
        \xdef\LYSomme{\xintfloateval{\LYSomme+\LY[\i]}}%
      }%
      \xdef\LXmoy{\xintfloateval{\LXSomme/\LNB}}%
      \xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
      \xdef\LXCmoy{\xintfloateval{\LXCSomme/\LNB}}%
      %calculs suites
      \foreach \i in {1,2,...,\LNB}{%
        \xdef\LXXSomme{\xintfloateval{\LXXSomme+(\LX[\i]-\LXmoy)^2}}%
        \xdef\LXYSomme{\xintfloateval{\LXYSomme+(\LX[\i]-\LXmoy)*(\LY[\i]-\LYmoy)}}%
        \xdef\LXXCSomme{\xintfloateval{\LXXCSomme+(\LX[\i]-\LXmoy)*((\LX[\i])*(\LX[\i])-\LXCmoy)}}%
        \xdef\LXCXCSomme{\xintfloateval{\LXCXCSomme+((\LX[\i])^2-\LXCmoy)^2}}%
        \xdef\LXCYSomme{\xintfloateval{\LXCYSomme+((\LX[\i])^2-\LXCmoy)*(\LY[\i]-\LYmoy)}}%
      }%
      %COEFFS OK
      \IfStrEq{\pflarrondisreglin}{}%
        {%
          \xdef\tmpcoeffregquadb{\xintfloateval{(\LXYSomme*\LXCXCSomme-\LXCYSomme*\LXXCSomme)/(\LXXSomme*\LXCXCSomme-(\LXXCSomme)^2)}}
          \xdef\tmpcoeffregquada{\xintfloateval{(\LXCYSomme*\LXXSomme-\LXYSomme*\LXXCSomme)/(\LXXSomme*\LXCXCSomme-(\LXXCSomme)^2)}}
          \xdef\tmpcoeffregquadc{\xintfloateval{\LYmoy-\tmpcoeffregquadb*\LXmoy-\tmpcoeffregquada*\LXCmoy}}
        }%
        {%
          \xdef\tmpcoeffregquadb{\xintfloateval{round((\LXYSomme*\LXCXCSomme-\LXCYSomme*\LXXCSomme)/(\LXXSomme*\LXCXCSomme-(\LXXCSomme)^2),\pflarrondisreglin)}}
          \xdef\tmpcoeffregquada{\xintfloateval{round((\LXCYSomme*\LXXSomme-\LXYSomme*\LXXCSomme)/(\LXXSomme*\LXCXCSomme-(\LXXCSomme)^2),\pflarrondisreglin)}}
          \xdef\tmpcoeffregquadc{\xintfloateval{round(\LYmoy-\tmpcoeffregquadb*\LXmoy-\tmpcoeffregquada*\LXCmoy,\pflarrondisreglin)}}
        }%
      \xintdeffloatfunc #2(x) := (\tmpcoeffregquada)*x^2+(\tmpcoeffregquadb)*x+\tmpcoeffregquadc ;
      %tracé
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
        \draw[pflcourbe,color={\useKV[GraphiqueTikzRegLin]{CouleurPara}},name path global=\pflnameregquad,samples=250,domain=\pflreglinmin:\pflreglinmax] plot (\x,{\tmpcoeffregquada*(\x)^2+\tmpcoeffregquadb*\x+\tmpcoeffregquadc}) ;
      \end{scope}
    }%
    {}%
}

\if@loadxintreg
%régressions alternatives
\NewDocumentCommand\TracerAjustement{ O{} D<>{cbajust} m D<>{} m m }{%
  %1=options de tracés
  %2=nom courbe
  %3=type
  %4=arrondis
  %5=liste X
  %6=liste Y
  \IfStrEq{#3}{lin}%
    {%
      \xintlinreg[round={#4}]{#5}{#6}%
      \DefinirFonction[#1,Trace]<#2>{\linrega*x+\linregb}%
    }%
    {}%
  \IfStrEq{#3}{quad}%
    {%
      \xintquadreg[round={#4}]{#5}{#6}%
      \DefinirFonction[#1,Trace]<#2>{\quadrega*x^2+\quadregb*x+\quadregc}%
    }%
    {}%
  \IfStrEq{#3}{pow}%
    {%
      \xintpowreg[round={#4}]{#5}{#6}%
      \DefinirFonction[#1,Trace]<#2>{\powrega*x^(\powregb)}%
    }%
    {}%
  \IfStrEq{#3}{expab}%
    {%
      \xintexpabreg[round={#4}]{#5}{#6}%
      \DefinirFonction[#1,Trace]<#2>{\expabrega*(\expabregb)^x}%
    }%
    {}%
  \IfStrEq{#3}{hyp}%
    {%
      \xinthypreg[round={#4}]{#5}{#6}%
      \DefinirFonction[#1,Trace]<#2>{\hyprega+(\hypregb)/x}%
    }%
    {}%
  \IfStrEq{#3}{log}%
    {%
      \xintlogreg[round={#4}]{#5}{#6}%
      \DefinirFonction[#1,Trace]<#2>{\logrega+(\logregb)*log(x)}%
    }%
    {}%
  \IfStrEq{#3}{exp}%
    {%
      \xintexpreg[round={#4}]{#5}{#6}%
      \DefinirFonction[#1,Trace]<#2>{exp(\exprega*x+\expregb)}%
    }%
    {}%
  \IfStrEq{#3}{expalt}%
    {%
      \xintexpreg[Alt,round={#4}]{#5}{#6}%
      \DefinirFonction[#1,Trace]<#2>{\expregb*exp(\exprega*x)}%
    }%
    {}%
  \IfStrEq{#3}{cub}%
    {%
      \xintcubreg[round={#4}]{#5}{#6}%
      \DefinirFonction[#1,Trace]<#2>{\cubrega*x^3+\cubregb*x^2+\cubregc*x+\cubregd}%
    }%
    {}%
  \IfSubStr{#3}{expoff}%
    {%
      \StrBehind{#3}{=}[\expoffset]%
      \xintexpoffreg[round={#4},offset=\expoffset]{#5}{#6}%
      \DefinirFonction[#1,Trace]<#2>{\expoffset+\expregoffb*exp(\expregoffa*x)}%
    }%
    {}%
}
\fi

%===IMAGES & ANTÉCÉDENTS
\defKV[GraphiqueTikzImg]{
  Couleurs=\def\pflimgcolors{#1},%
  Nom=\def\pflantecednoms{#1}%
}

\setKVdefault[GraphiqueTikzImg]{
  Couleurs=black,%
  Traits=false,%
  Spline=false,%
  Nom={},%
  Style=o
}

\NewDocumentCommand\DefinirImage{ O{} m m }{%
  \useKVdefault[GraphiqueTikzImg]%
  \setKV[GraphiqueTikzImg]{#1}%
  \ifboolKV[GraphiqueTikzImg]{Spline}%
    {%
      \path[draw=none,pflcourbe,name path=tmpimage] ({#3},{\pflymin})--({#3},{\pflymax}) ;
      \path[name intersections={of=#2 and tmpimage,name=ZZZZ}] ;
      \coordinate (\pflantecednoms) at (ZZZZ-1) ;
    }%
    {%
      \xdef\tmpresimg{\xintfloateval{#2(#3)}}%
      \coordinate (\pflantecednoms) at ({#3},{\tmpresimg}) ;
    }%
}

\NewDocumentCommand\PlacerImages{ O{} m m }{%
  \useKVdefault[GraphiqueTikzImg]%
  \setKV[GraphiqueTikzImg]{#1}%
  \IfSubStr{\pflimgcolors}{/}%
    {%
      \StrCut{\pflimgcolors}{/}{\pflimgcolorpt}{\pflimgcolorline}
    }%
    {%
      \xdef\pflimgcolorpt{\pflimgcolors}\xdef\pflimgcolorline{\pflimgcolors}
    }%
  \ifboolKV[GraphiqueTikzImg]{Spline}%
    {%
      \foreach \i in {#3}{%
        \path[draw=none,pflcourbe,name path=tmpimage] ({\i},{\pflymin})--({\i},{\pflymax}) ;
        \path[name intersections={of=#2 and tmpimage,name=ZZ}] ;
        \ifboolKV[GraphiqueTikzImg]{Traits}%
          {%
            \draw[color=\pflimgcolorline,pfltraitimg] let \p1 = (ZZ-1) in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
          }%
          {}%
        \MarquerPts*[Style={\useKV[GraphiqueTikzImg]{Style}},Couleur=\pflimgcolorpt]{(ZZ-1)}
        %\filldraw[\pflimgcolorpt] (ZZ-1) circle[radius=2pt] ;
      }
    }%
    {%
      \foreach \i in {#3}{%
        \xdef\tmpresimg{\xintfloateval{#2(\i)}}%
        \ifboolKV[GraphiqueTikzImg]{Traits}%
          {%
            \draw[color=\pflimgcolorline,pfltraitimg] ({\i},{\pflOy}) |- ({\pflOx},{\tmpresimg}) ;
          }%
          {}%
        \MarquerPts*[Style={\useKV[GraphiqueTikzImg]{Style}},Couleur=\pflimgcolorpt]{({\i},{\tmpresimg})}
        %\filldraw[\pflimgcolorpt] ({\i},{\tmpresimg}) circle[radius=2pt] ;
      }%
    }%
}

\NewDocumentCommand\PlacerAntecedents{ O{} m m }{%avec le nom de la courbe...
  \useKVdefault[GraphiqueTikzImg]%
  \setKV[GraphiqueTikzImg]{#1}%
  \xdef\pflstepcurve{\xintfloateval{0.1*\pflgrillexs}}
  \IfSubStr{\pflimgcolors}{/}%
  {%
    \StrCut{\pflimgcolors}{/}{\pflimgcolorpt}{\pflimgcolorline}%
  }%
  {%
    \xdef\pflimgcolorpt{\pflimgcolors}\xdef\pflimgcolorline{\pflimgcolors}%
  }%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \path[draw=none,pflcourbe,name path=tmpanteced] ({\pflxmin},{#3})--({\pflxmax},{#3}) ;
    \path[name intersections={of=#2 and tmpanteced,name=ZZ,total=\t}] \pgfextra{\xdef\tmptotanteced{\t}};
    \xintifboolexpr{\tmptotanteced == 0}{}%
      {%
        \ifboolKV[GraphiqueTikzImg]{Traits}%
          {%
            \draw[color=\pflimgcolorline,pfltraitantec] ({\pflxmin},{#3})--({\pflxmax},{#3}) ;
          }%
          {}%
        \foreach \i in {1,...,\tmptotanteced}{%
          \IfStrEq{\pflantecednoms}{}%
            {}%
            {%
              \coordinate (\pflantecednoms-\i) at (ZZ-\i) ;
            }%
          \ifboolKV[GraphiqueTikzImg]{Traits}%
            {%
              \draw[color=\pflimgcolorline,pfltraitimg] let \p1 = (ZZ-\i) in (ZZ-\i) -- ({\x1},{\pflOy}) ;
            }%
            {}%
          \MarquerPts*[Style={\useKV[GraphiqueTikzImg]{Style}},Couleur=\pflimgcolorpt]{(ZZ-\i)}
          %\filldraw[\pflimgcolorpt] (ZZ-\i) circle[radius=2pt] ;
        }%
      }%
  \end{scope}
}

%===NOMBRE DÉRIVÉ ET TANGENTE (EXPÉRIEMENTAL)
\NewDocumentCommand\CalculerNbDerive{ s m m m }{%*=gauche+nomfct+abspt+h
  \IfBooleanTF{#1}%
    {%
      \xdef\TmpResNbDeriv{\xintfloateval{(#2(#3)-#2(#3-#4))/(#4)}}%
    }%
    {%
      \xdef\TmpResNbDeriv{\xintfloateval{(#2(#3+#4)-#2(#3))/(#4)}}%
    }%
}

\defKV[GraphiqueTikzTgte]{%
  Couleurs=\def\pfltgttikzcolors{#1},%
  DecG=\def\pfltgttikzkl{#1},%
  DecD=\def\pfltgttikzkr{#1},%
  h=\def\pfltgttikzh{#1},%
  Sens=\def\pfltgttikzsens{#1},%
  Delta=\def\tmptgtedelta{#1}
}
\setKVdefault[GraphiqueTikzTgte]{%
  Couleurs=black,%
  DecG=1,%
  DecD=1,%
  AffPoint=false,%
  Spline=false,%
  h=0.1,%
  Sens=gd,%
  Noeud=false,%
  Delta=0.01,%
  Style=o
}

\NewDocumentCommand\TracerTangente{ O{} m m D<>{} }{%
  \restoreKV[GraphiqueTikzTgte]%
  \setKV[GraphiqueTikzTgte]{#1}%
  %en fonction de la gestion de l'abscisse
  \ifboolKV[GraphiqueTikzTgte]{Noeud}%
    {%
      \path #3;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\pfltgttikzx{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
    }%
    {%
      \xdef\pfltgttikzx{#3}%
    }%
  %parties communes
  \IfSubStr{\pfltgttikzcolors}{/}%
    {%
      \StrCut{\pfltgttikzcolors}{/}{\pfltgttikzline}{\pfltgttikzpoint}
    }%
    {%
      \xdef\pfltgttikzline{\pfltgttikzcolors}\xdef\pfltgttikzpoint{\pfltgttikzcolors}
    }%
  \xdef\tmptgtdeb{\xintfloateval{\pfltgttikzx-(\pfltgttikzkl)}}%
  \xdef\tmptgtfin{\xintfloateval{\pfltgttikzx+(\pfltgttikzkr)}}%
  %suivant le type de courbe
  \ifboolKV[GraphiqueTikzTgte]{Spline}%
    {%
        \path[name path=tmpimage] ({\pfltgttikzx},{\pflymin})--({\pfltgttikzx},{\pflymax}) ;
        \path[name intersections={of=#2 and tmpimage,name=TANp}] ;
        \IfStrEq{\pfltgttikzsens}{gd}%
          {%
            \path[name path=L-vline] ({\pfltgttikzx-\tmptgtedelta},{\pflymin}) -- ({\pfltgttikzx-\tmptgtedelta},{\pflymax}) ;
            \path[name path=R-vline] ({\pfltgttikzx+\tmptgtedelta},{\pflymin}) -- ({\pfltgttikzx+\tmptgtedelta},{\pflymax}) ;
            %\coordinate (LXcoor) at ($(TANp-1)+({-\tmptgtedelta},0)$) ;
            %\coordinate (RXcoor) at ($(TANp-1)+({\tmptgtedelta},0)$) ;
          }%
          {}%
        \IfStrEq{\pfltgttikzsens}{g}%
          {%
            \path[name path=L-vline] ({\pfltgttikzx-\tmptgtedelta},{\pflymin}) -- ({\pfltgttikzx-\tmptgtedelta},{\pflymax}) ;
            \path[name path=R-vline] ({\pfltgttikzx},{\pflymin}) -- ({\pfltgttikzx},{\pflymax}) ;
            %\coordinate (LXcoor) at ($(TANp-1)+({-\tmptgtedelta},0)$) ;
            %\coordinate (RXcoor) at (TANp-1) ;
            \def\tmptgtfin{\pfltgttikzx}%
          }%
          {}%
        \IfStrEq{\pfltgttikzsens}{d}%
          {%
            \path[name path=L-vline] ({\pfltgttikzx},{\pflymin}) -- ({\pfltgttikzx},{\pflymax}) ;
            \path[name path=R-vline] ({\pfltgttikzx+\tmptgtedelta},{\pflymin}) -- ({\pfltgttikzx+\tmptgtedelta},{\pflymax}) ;
            \def\tmptgtdeb{\pfltgttikzx}%
          }%
          {}%
        \path[name intersections={of=#2 and L-vline,name=LXcut}] ;
        \path[name intersections={of=#2 and R-vline,name=RXcut}] ;
        \coordinate (tzXproj) at ($(LXcut-1)!(TANp-1)!(RXcut-1)$) ; % projection
        \coordinate (LLpoint) at ($(LXcut-1)+(TANp-1)-(tzXproj)$) ; % move
        \coordinate (RRpoint) at ($(RXcut-1)+(TANp-1)-(tzXproj)$) ; % move
        \path (LLpoint);
        \pgfgetlastxy{\macrox}{\macroy}%
        \xdef\tzTANLLX{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
        \xdef\tzTANLLY{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
        \path (RRpoint);
        \pgfgetlastxy{\macrox}{\macroy}%
        \xdef\tzTANRRX{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
        \xdef\tzTANRRY{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
        \def\tztangentLFn{(\tzTANRRY-\tzTANLLY)/(\tzTANRRX-\tzTANLLX)*(\x-\tzTANLLX)+\tzTANLLY}%
        \begin{scope}
          \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
          \draw[pfltrait,color=\pfltgttikzline,domain=\tmptgtdeb:\tmptgtfin,samples=2,#4] plot (\x,{\tztangentLFn}) ;
        \end{scope}
    }%
    {%
      \IfStrEq{\pfltgttikzsens}{g}%
        {%
          \CalculerNbDerive*{#2}{\pfltgttikzx}{\pfltgttikzh}%
        }%
        {%
          \CalculerNbDerive{#2}{\pfltgttikzx}{\pfltgttikzh}%
        }%
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
        \draw[pfltrait,color=\pfltgttikzline,#4] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,\TmpResNbDeriv*(x-(\pfltgttikzx))+#2(\pfltgttikzx)),x=\tmptgtdeb,\tmptgtfin)
          \relax
        };
      \end{scope}
    }%
  \ifboolKV[GraphiqueTikzTgte]{AffPoint}%
    {%
      \ifboolKV[GraphiqueTikzTgte]{Spline}%
        {%
          \MarquerPts*[Style={\useKV[GraphiqueTikzTgte]{Style}},Couleur=\pfltgttikzpoint]{(TANp-1)}
          %\filldraw[] (TANp-1) circle[pflpointc] ;
        }%
        {%
          \xdef\tmpimgtgt{\xintfloateval{#2(\pfltgttikzx)}}%
          \MarquerPts*[Style={\useKV[GraphiqueTikzTgte]{Style}},Couleur=\pfltgttikzpoint]{({\pfltgttikzx},\tmpimgtgt)}
          %\filldraw[\pfltgttikzpoint] ({\pfltgttikzx},\tmpimgtgt) circle[pflpointc] ;
        }%
    }%
    {}%
}

%====LOI NORMALE
\defKV[GraphiqueTikzGaussienne]{%
  Pas=\def\pflgaussstep{#1},%
  Nom=\def\pflgaussname{#1},%
  StyleTrace=\def\pflgaussstyle{#1}
}

\setKVdefault[GraphiqueTikzGaussienne]{%
  Nom=gaussienne,%
  Couleur=black,%
  Trace=false,%
  Pas={},%
  Debut={\pflxmin},%
  Fin={\pflxmax},%
  StyleTrace={}
}

\NewDocumentCommand\DefinirLoiNormale{ O{} D<>{phi} m m }{%
  %1=options
  %2=mu
  %3=sigma
  \restoreKV[GraphiqueTikzGaussienne]%
  \setKV[GraphiqueTikzGaussienne]{#1}%
  \xintdeffloatfunc #2(x) := 1/((#4)*sqrt(2*pi))*exp(-0.5*((x-(#3))/(#4))^2) ;%
  \IfStrEq{\pflgaussstep}{}%
    {%
      \xdef\pflgaussstep{\xintfloateval{((\useKV[GraphiqueTikzGaussienne]{Fin})-(\useKV[GraphiqueTikzGaussienne]{Debut}))/200}}%
    }%
    {}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \ifboolKV[GraphiqueTikzGaussienne]{Trace}%
      {%
        \path[draw,pflcourbe,\pflgaussstyle,color={\useKV[GraphiqueTikzGaussienne]{Couleur}},name path global=\pflgaussname] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphiqueTikzGaussienne]{Debut}}..[\pflgaussstep]..{\useKV[GraphiqueTikzGaussienne]{Fin}},{\useKV[GraphiqueTikzGaussienne]{Fin}})
          \relax
        } ;
      }%
      {%
        \path[draw=none,pflcourbe,name path global=\pflgaussname]  plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphiqueTikzGaussienne]{Debut}}..[\pflgaussstep]..{\useKV[GraphiqueTikzGaussienne]{Fin}},{\useKV[GraphiqueTikzGaussienne]{Fin}})
          \relax
        } ;
      }%
  \end{scope}
}

\NewDocumentCommand\TracerLoiNormale{ O{} m }{%
  %1=options
  %2=mu
  %3=sigma
  \restoreKV[GraphiqueTikzGaussienne]%
  \setKV[GraphiqueTikzGaussienne]{#1}%
  \IfStrEq{\pflgaussstep}{}%
    {%
      \xdef\pflgaussstep{\xintfloateval{((\useKV[GraphiqueTikzGaussienne]{Fin})-(\useKV[GraphiqueTikzGaussienne]{Debut}))/200}}%
    }%
    {}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \draw[pflcourbe,\pflgaussstyle,color={\useKV[GraphiqueTikzGaussienne]{Couleur}}]  plot[smooth] coordinates {%
      \xintthecoords\xintfloatexpr
      seq((x,#2),x={\useKV[GraphiqueTikzGaussienne]{Debut}}..[\pflgaussstep]..{\useKV[GraphiqueTikzGaussienne]{Fin}},{\useKV[GraphiqueTikzGaussienne]{Fin}})
      \relax
    } ;
  \end{scope}
}

\NewDocumentCommand\DefinirLoiKhiDeux{ O{} D<>{khi} m }{%
  %1=options
  %2=mu
  %3=sigma
  \restoreKV[GraphiqueTikzGaussienne]%
  \setKV[GraphiqueTikzGaussienne]{#1}%
  \xintdeffloatfunc #2(x) := (x<0)?{0}{(1/(2^((#3)/2)*pflgamma((#3)/2)))*x^((#3)/2-1)*exp(-x/2)};
  \IfStrEq{\pflgaussstep}{}%
  {%
    \xdef\pflgaussstep{\xintfloateval{((\useKV[GraphiqueTikzGaussienne]{Fin})-(\useKV[GraphiqueTikzGaussienne]{Debut}))/200}}%
  }%
  {}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \ifboolKV[GraphiqueTikzGaussienne]{Trace}%
      {%
        \path[draw,pflcourbe,\pflgaussstyle,color={\useKV[GraphiqueTikzGaussienne]{Couleur}},name path global=\pflgaussname] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphiqueTikzGaussienne]{Debut}}..[\pflgaussstep]..{\useKV[GraphiqueTikzGaussienne]{Fin}},{\useKV[GraphiqueTikzGaussienne]{Fin}})
          \relax
        } ;
      }%
      {%
        \path[draw=none,pflcourbe,name path global=\pflgaussname]  plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphiqueTikzGaussienne]{Debut}}..[\pflgaussstep]..{\useKV[GraphiqueTikzGaussienne]{Fin}},{\useKV[GraphiqueTikzGaussienne]{Fin}})
          \relax
        } ;
      }%
  \end{scope}
}

\NewDocumentCommand\TracerLoiKhiDeux{ O{} m }{%
  %1=options
  %2=mu
  %3=sigma
  \restoreKV[GraphiqueTikzGaussienne]%
  \setKV[GraphiqueTikzGaussienne]{#1}%
  \IfStrEq{\pflgaussstep}{}%
    {%
      \xdef\pflgaussstep{\xintfloateval{((\useKV[GraphiqueTikzGaussienne]{Fin})-(\useKV[GraphiqueTikzGaussienne]{Debut}))/200}}%
    }%
    {}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \draw[pflcourbe,\pflgaussstyle,color={\useKV[GraphiqueTikzGaussienne]{Couleur}}]  plot[smooth] coordinates {%
      \xintthecoords\xintfloatexpr
      seq((x,#2),x={\useKV[GraphiqueTikzGaussienne]{Debut}}..[\pflgaussstep]..{\useKV[GraphiqueTikzGaussienne]{Fin}},{\useKV[GraphiqueTikzGaussienne]{Fin}})
      \relax
    } ;
  \end{scope}
}

%====DROITE
\defKV[GraphiquetikzDroite]{%
  Nom=\def\pfldroitename{#1},%
  StyleTrace=\def\pfldroitestyle{#1}
}

\setKVdefault[GraphiquetikzDroite]{%
  Pente=false,%
  Couleur=black,%
  Debut={\pflxmin},%
  Fin={\pflxmax},%
  Nom={},%
  StyleTrace={}
}

\NewDocumentCommand\TracerDroite{ O{} m m D<>{} }{%
  \restoreKV[GraphiquetikzDroite]%
  \setKV[GraphiquetikzDroite]{#1}%
  %1er point
  \path #2;%
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef\pfldtetikzxA{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
  \xdef\pfldtetikzyA{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
  %2ème point si besoin
  \ifboolKV[GraphiquetikzDroite]{Pente}%
    {%
      \xdef\pfldtepente{\xintfloateval{#3}}%
    }%
    {%
      \path #3;%
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\pfldtetikzxB{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
      \xdef\pfldtetikzyB{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
      \xdef\pfldtepente{\xintfloateval{(\pfldtetikzyB-\pfldtetikzyA)/(\pfldtetikzxB-\pfldtetikzxA)}}%
    }%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
    \xintifboolexpr{\pfldtetikzxA == \pfldtetikzxB}%
      {%
        \IfEq{\pfldroitename}{}%
          {%
            \draw[pfltrait,\pfldroitestyle,color={\useKV[GraphiquetikzDroite]{Couleur}},#4] (\pfldtetikzxA,\pflymin) -- (\pfldtetikzxA,\pflymax) ;
          }%
          {%
            \draw[pfltrait,\pfldroitestyle,color={\useKV[GraphiquetikzDroite]{Couleur}},#4,name path global=\pfldroitename] (\pfldtetikzxA,\pflymin) -- (\pfldtetikzxA,\pflymax) ;
          }%
      }%
      {%
        \IfEq{\pfldroitename}{}%
          {%
            \draw[pfltrait,\pfldroitestyle,color={\useKV[GraphiquetikzDroite]{Couleur}},domain={\useKV[GraphiquetikzDroite]{Debut}}:{\useKV[GraphiquetikzDroite]{Fin}},samples=2,#4] plot (\x,{\pfldtepente*(\x-\pfldtetikzxA)+\pfldtetikzyA}) ;
          }%
          {%
            \draw[pfltrait,\pfldroitestyle,color={\useKV[GraphiquetikzDroite]{Couleur}},domain={\useKV[GraphiquetikzDroite]{Debut}}:{\useKV[GraphiquetikzDroite]{Fin}},samples=2,name path global=\pfldroitename,#4] plot (\x,{\pfldtepente*(\x-\pfldtetikzxA)+\pfldtetikzyA}) ;
          }%
      }%
  \end{scope}
}

%====ASYMPTOTE
\NewDocumentCommand\TracerAsymptote{ O{} m D<>{} }{%
  \restoreKV[GraphiquetikzDroite]%
  \setKV[GraphiquetikzDroite]{#1}%
  %tracé
  \draw[pfltrait,\pfldroitestyle,color={\useKV[GraphiquetikzDroite]{Couleur}},#3] ({#2},{\pflymin})--({#2},{\pflymax}) ;
}


%====MINMAX
\defKV[GraphiqueTikzMinMax]{%
  Pas=\def\pflminmaxstep{#1},%
  Methode=\def\pflminmaxmethode{#1},%
  Coeffs=\def\pflminmaxcoeffs{#1}
}
\setKVdefault[GraphiqueTikzMinMax]{%
  Debut={\pflxmin},%
  Fin={\pflxmax},%
  Pas={},%
  Tension=0.5,%
  Methode=fonction,%
  Coeffs=3
}

\NewDocumentCommand\TrouverMaximum{ O{} m O{c-max} }{%
  %1=clés
  %2=paramètres en fonction de [Methode]
  \restoreKV[GraphiqueTikzMinMax]%
  \setKV[GraphiqueTikzMinMax]{#1}%
  \IfStrEq{\pflstepcurve}{}%
    {%
      \xdef\pflminmaxstep{\xintfloateval{((\useKV[GraphiqueTikzMinMax]{Fin})-(\useKV[GraphiqueTikzMinMax]{Debut}))/200}}%
    }%
    {}%
  \begin{scope}[bezier bounding box,local bounding box=bbtmpmax]
    \IfStrEq{\pflminmaxmethode}{fonction}%
      {%
        \path[draw=none,name path=curvetmpmax] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphiqueTikzMinMax]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzMinMax]{Fin}},{\useKV[GraphiqueTikzMinMax]{Fin}})
          \relax
        };
      }%
      {}%
    \IfStrEq{\pflminmaxmethode}{interpo}%
      {%
        \path[draw=none,name path=curvetmpmax] plot[smooth,tension={\useKV[GraphiqueTikzMinMax]{Tension}}] coordinates {#2};
      }%
      {}%
    \IfStrEq{\pflminmaxmethode}{spline}%
      {%
        \GenererSpline{#2}{\pflminmaxcoeffs}[\tmpsplineminmax]%
        \path[draw=none,name path=curvetmpmax] \tmpsplineminmax ;
      }%
      {}%
    \IfStrEq{\pflminmaxmethode}{path}%
      {%
        % le path #2 est déjà un name path global → l'utiliser directement
        \path[draw=none, name path=curvetmpmax,spath/restore=#2] ;%
      }%
      {}%
    %retour
    \path[name path=tmpmax] ([yshift=-0.25\pgflinewidth]bbtmpmax.north east) -- ([yshift=-0.25\pgflinewidth]bbtmpmax.north west) ;
    \path[name intersections={of=curvetmpmax and tmpmax,name=#3,total=\t}] \pgfextra{\xdef\pflmaxintersecttot{\t}} ;
    \xintifboolexpr{\pflmaxintersecttot > 1}%
      {%
        \coordinate (#3) at  ($0.5*(#3-1)+0.5*(#3-2)+(0,0.25\pgflinewidth)$) ;%
      }%
      {%
        % pas d'intersection → nœud fictif hors fenêtre
        \coordinate (#3) at ([xshift=-5pt,yshift=-5pt]\pflxmin,\pflymin) ;%
      }%
  \end{scope}
}

\NewDocumentCommand\TrouverMinimum{ O{} m O{c-min} }{%
  %1=clés
  %2=paramètres en fonction de [Methode]
  \restoreKV[GraphiqueTikzMinMax]%
  \setKV[GraphiqueTikzMinMax]{#1}%
  \IfStrEq{\pflstepcurve}{}%
    {%
      \xdef\pflminmaxstep{\xintfloateval{((\useKV[GraphiqueTikzMinMax]{Fin})-(\useKV[GraphiqueTikzMinMax]{Debut}))/200}}%
    }%
    {}%
  \begin{scope}[bezier bounding box,local bounding box=bbtmpmin]
    \IfStrEq{\pflminmaxmethode}{fonction}%
      {%
        \path[draw=none,name path=curvetmpmin] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphiqueTikzMinMax]{Debut}}..[\pflstepcurve]..{\useKV[GraphiqueTikzMinMax]{Fin}},{\useKV[GraphiqueTikzMinMax]{Fin}})
          \relax
        };
      }%
      {}%
    \IfStrEq{\pflminmaxmethode}{interpo}%
      {%
        \path[draw=none,name path=curvetmpmin] plot[smooth,tension={\useKV[GraphiqueTikzMinMax]{Tension}}] coordinates {#2};
      }%
      {}%
    \IfStrEq{\pflminmaxmethode}{spline}%
      {%
        \GenererSpline{#2}{\pflminmaxcoeffs}[\tmpsplineminmax]%
        \path[draw=none,name path=curvetmpmin] \tmpsplineminmax ;
      }%
      {}%
    \IfStrEq{\pflminmaxmethode}{path}%
      {%
        % le path #2 est déjà un name path global → l'utiliser directement
        \path[draw=none, name path=curvetmpmin,spath/restore=#2] ;%
      }%
      {}%
    %retour
    \path[name path=tmpmin] ([yshift=0.25\pgflinewidth]bbtmpmin.south east) -- ([yshift=0.25\pgflinewidth]bbtmpmin.south west) ;
    \path[name intersections={of=curvetmpmin and tmpmin,name=#3,total=\t}] \pgfextra{\xdef\pflmaxintersecttot{\t}} ;
    \xintifboolexpr{\pflmaxintersecttot > 1}%
      {%
        \coordinate (#3) at  ($0.5*(#3-1)+0.5*(#3-2)+(0,-0.25\pgflinewidth)$) ;%
      }%
      {%
        % pas d'intersection → nœud fictif hors fenêtre
        \coordinate (#3) at ([xshift=-5pt,yshift=-5pt]\pflxmin,\pflymin) ;%
      }%
  \end{scope}
}

%====TEXTES
\defKV[GraphiqueTikzNode]{%
  Couleur=\def\pflnodecol{#1},%
  Police=\def\pflnodefonte{#1},%
  Position=\def\pfnodepos{#1}
}
\setKVdefault[GraphiqueTikzNode]{%
  Couleur=black,%
  Police={\normalfont\normalsize},%
  Position={}
}
\NewDocumentCommand\PlacerTexte{ O{} m m }{%
  \restoreKV[GraphiqueTikzNode]%
  \setKV[GraphiqueTikzNode]{#1}%
  \draw #2 node[pflnoeud,font=\pflnodefonte,text=\pflnodecol,\pfnodepos] {#3} ;
}

\NewDocumentCommand\TracerEllipse{ O{} m m m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  %booléens spécifiques pour Axes de symétries, foyers, sommets
  \path #2 ;
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef\pflxcentreellipse{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
  \xdef\pflycentreellipse{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
  %on parse à courbe param !
  \TracerCourbeParam[#1]{\pflxcentreellipse+(#3)*cos(t)}{\pflycentreellipse+(#4)*sin(t)}%
  %pour les foyers
  \xdef\tmptkzcellipse{\xintfloateval{sqrt(max(#3,#4)^2-min(#3,#4)^2)}}%
}

\NewDocumentCommand\TracerParabole{ O{} m m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  \path #2 ;
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef\pflxsommetparabole{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
  \xdef\pflysommetparabole{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
  % Sens=V (défaut) ou Sens=H
  \IfStrEq{\pflsensparab}{H}{%
    % axe horizontal : x = h + t²/(4p), y = k + t
    % t joue le rôle de y-k, on borne sur Ymin/Ymax
    \TracerCourbeParam[#1,%
    Debut=\xintfloateval{\pflymin-\pflysommetparabole},%
    Fin=\xintfloateval{\pflymax-\pflysommetparabole}]%
    {\pflxsommetparabole+(t)^2/(4*(#3))}{\pflysommetparabole+(t)}%
  }{%
    % axe vertical : x = h + t, y = k + t²/(4p)
    % t joue le rôle de x-h, on borne sur Xmin/Xmax
    \TracerCourbeParam[#1,%
    Debut=\xintfloateval{\pflxmin-\pflxsommetparabole},%
    Fin=\xintfloateval{\pflxmax-\pflxsommetparabole}]%
    {\pflxsommetparabole+(t)}{\pflysommetparabole+(t)^2/(4*(#3))}%
  }%
}

\NewDocumentCommand\TracerHyperbole{ O{} m m m }{%
  \restoreKV[GraphiqueTikzCourbe]%
  \setKV[GraphiqueTikzCourbe]{#1}%
  \path #2 ;
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef\pflxcentrehyperbole{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
  \xdef\pflycentrehyperbole{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
  \xdef\pflnamecurveA{\pflnamecurve{}A}%
  \xdef\pflnamecurveB{\pflnamecurve{}B}%
  \IfStrEq{\pflsensparab}{H}%
  {%
    % axe horizontal : x = h ± a*cosh(t), y = k + b*sinh(t)
    \TracerCourbeParam[#1,Debut=-5,Fin=5,Nom=\pflnamecurveA]%
      {\pflxcentrehyperbole+(#3)*((exp(t)+exp(-t))/2)}%
      {\pflycentrehyperbole+(#4)*((exp(t)-exp(-t))/2)}%
    \TracerCourbeParam[#1,Debut=-5,Fin=5,Nom=\pflnamecurveB]%
      {\pflxcentrehyperbole-(#3)*((exp(t)+exp(-t))/2)}%
      {\pflycentrehyperbole+(#4)*((exp(t)-exp(-t))/2)}%
  }%
  {%
    % axe vertical : y = k ± b*cosh(t), x = h + a*sinh(t)
    \TracerCourbeParam[#1,Debut=-5,Fin=5,Nom=\pflnamecurveA]%
    {\pflxcentrehyperbole+(#3)*((exp(t)-exp(-t))/2)}%
    {\pflycentrehyperbole+(#4)*((exp(t)+exp(-t))/2)}%
    \TracerCourbeParam[#1,Debut=-5,Fin=5,Nom=\pflnamecurveB]%
    {\pflxcentrehyperbole+(#3)*((exp(t)-exp(-t))/2)}%
    {\pflycentrehyperbole-(#4)*((exp(t)+exp(-t))/2)}%
  }%
}

\defKV[GraphiqueTikzConique]{%
  Sens=\def\pflsensparab{#1}
}

\setKVdefault[GraphiqueTikzConique]{%
  CouleurPoints=black,%
  CouleurDroites=black,% couleur spécifique pour les éléments
  AffCentre=false,%
  AffFoyers=false,%
  AffSommets=false,%
  AffAxes=false,%
  AffDirectrice=false,% parabole
  AffAsymptotes=false,% hyperbole,%
  AffTout=false,%
  Sens=V
}

\NewDocumentCommand\AfficherElementsEllipse{ O{} m m m m }{%
  % #1=clés #2=nom #3=centre #4=a #5=b
  \restoreKV[GraphiqueTikzConique]%
  \setKV[GraphiqueTikzConique]{#1}%
  \path #3 ;
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef\pflxcentre{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
  \xdef\pflycentre{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
  \xdef\pflcellipse{\xintfloateval{sqrt(abs((#4)^2-(#5)^2))}}%
  %booléen spécifique
  \ifboolKV[GraphiqueTikzConique]{AffTout}%
    {%
      \setKV[GraphiqueTikzConique]{AffCentre=true,AffFoyers=true,AffSommets=true,AffAxes=true}%
    }%
    {}%
  % nœuds centre
  \coordinate (#2-C) at (\pflxcentre,\pflycentre) ;
  % on détermine si grand axe horizontal ou vertical
  \xintifboolexpr{ #4 > #5 }%
    {%
      \coordinate (#2-F1) at (\xintfloateval{\pflxcentre+\pflcellipse},\pflycentre) ;%
      \coordinate (#2-F2) at (\xintfloateval{\pflxcentre-\pflcellipse},\pflycentre) ;%
    }%
    {%
      \coordinate (#2-F1) at (\pflxcentre,\xintfloateval{\pflycentre+\pflcellipse}) ;%
      \coordinate (#2-F2) at (\pflxcentre,\xintfloateval{\pflycentre-\pflcellipse}) ;%
    }%
  % nœuds sommets
  \coordinate (#2-S1) at (\xintfloateval{\pflxcentre+(#4)},\pflycentre) ;%
  \coordinate (#2-S2) at (\xintfloateval{\pflxcentre-(#4)},\pflycentre) ;%
  \coordinate (#2-S3) at (\pflxcentre,\xintfloateval{\pflycentre+(#5)}) ;%
  \coordinate (#2-S4) at (\pflxcentre,\xintfloateval{\pflycentre-(#5)}) ;%
  % affichages
  \ifboolKV[GraphiqueTikzConique]{AffAxes}%
    {%
      \draw[color={\useKV[GraphiqueTikzConique]{CouleurDroites}},pfltraitvoisinageasympt]
        (\xintfloateval{\pflxcentre-1.1*(#4)},\pflycentre) --
        (\xintfloateval{\pflxcentre+1.1*(#4)},\pflycentre) ;%
      \draw[color={\useKV[GraphiqueTikzConique]{CouleurDroites}},pfltraitvoisinageasympt]
        (\pflxcentre,\xintfloateval{\pflycentre-1.1*(#5)}) --
        (\pflxcentre,\xintfloateval{\pflycentre+1.1*(#5)}) ;%
    }%
    {}%
  \ifboolKV[GraphiqueTikzConique]{AffCentre}%
    {%
      \MarquerPts*[Couleur={\useKV[GraphiqueTikzConique]{CouleurPoints}}]{(#2-C)}
    }{}%
  \ifboolKV[GraphiqueTikzConique]{AffFoyers}%
    {%
      \MarquerPts*[Couleur={\useKV[GraphiqueTikzConique]{CouleurPoints}}]{(#2-F1),(#2-F2)}%
    }%
    {}%
  \ifboolKV[GraphiqueTikzConique]{AffSommets}%
    {%
      \MarquerPts*[Couleur={\useKV[GraphiqueTikzConique]{CouleurPoints}}]{(#2-S1),(#2-S2),(#2-S3),(#2-S4)}%
    }%
    {}%
}

\NewDocumentCommand\AfficherElementsParabole{ O{} m m m }{%
  % #1=clés #2=nom #3=sommet #4=p
  \restoreKV[GraphiqueTikzConique]%
  \setKV[GraphiqueTikzConique]{#1}%
  \path #3 ;
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef\pflxsommet{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
  \xdef\pflysommet{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
  % AffTout
  \ifboolKV[GraphiqueTikzConique]{AffTout}%
  {\setKV[GraphiqueTikzConique]{AffFoyers=true,AffSommets=true,AffAxes=true,AffDirectrice=true}}%
  {}%
  % nœud sommet
  \coordinate (#2-S) at (\pflxsommet,\pflysommet) ;%
  % foyer et directrice selon sens
  \IfStrEq{\pflsensparab}{H}{%
    % axe horizontal : foyer à (h+p, k), directrice x = h-p
    \coordinate (#2-F) at (\xintfloateval{\pflxsommet+(#4)},\pflysommet) ;%
    \coordinate (#2-D1) at (\xintfloateval{\pflxsommet-(#4)},\pflymin) ;%
    \coordinate (#2-D2) at (\xintfloateval{\pflxsommet-(#4)},\pflymax) ;%
    \coordinate (#2-A1) at (\pflxmin,\pflysommet) ;%
    \coordinate (#2-A2) at (\pflxmax,\pflysommet) ;%
  }%
  {%
    % axe vertical : foyer à (h, k+p), directrice y = k-p
    \coordinate (#2-F) at (\pflxsommet,\xintfloateval{\pflysommet+(#4)}) ;%
    \coordinate (#2-D1) at (\pflxmin,\xintfloateval{\pflysommet-(#4)}) ;%
    \coordinate (#2-D2) at (\pflxmax,\xintfloateval{\pflysommet-(#4)}) ;%
    \coordinate (#2-A1) at (\pflxsommet,\pflymin) ;%
    \coordinate (#2-A2) at (\pflxsommet,\pflymax) ;%
  }%
  % axe de symétrie
  \ifboolKV[GraphiqueTikzConique]{AffAxes}%
  {%
    \draw[color={\useKV[GraphiqueTikzConique]{CouleurDroites}},pfltraitvoisinageasympt]
    (#2-A1) -- (#2-A2) ;%
  }{}%
  % directrice
  \ifboolKV[GraphiqueTikzConique]{AffDirectrice}%
  {%
    \draw[color={\useKV[GraphiqueTikzConique]{CouleurDroites}},pfltraitvoisinageasympt]
    (#2-D1) -- (#2-D2) ;%
  }{}%
  % foyer
  \ifboolKV[GraphiqueTikzConique]{AffFoyers}%
  {%
    \MarquerPts*[Couleur={\useKV[GraphiqueTikzConique]{CouleurPoints}}]{(#2-F)}%
  }{}%
  % sommet
  \ifboolKV[GraphiqueTikzConique]{AffSommets}%
  {%
    \MarquerPts*[Couleur={\useKV[GraphiqueTikzConique]{CouleurPoints}}]{(#2-S)}%
  }{}%
}

\NewDocumentCommand\AfficherElementsHyperbole{ O{} m m m m }{%
  % #1=clés #2=nom #3=centre #4=a #5=b
  \restoreKV[GraphiqueTikzConique]%
  \setKV[GraphiqueTikzConique]{#1}%
  \path #3 ;
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef\pflxcentre{\xintfloateval{(\ConvertirPtToCm{\macrox})/(\pflxunit)}}%
  \xdef\pflycentre{\xintfloateval{(\ConvertirPtToCm{\macroy})/(\pflyunit)}}%
  % c = sqrt(a²+b²) pour l'hyperbole !
  \xdef\pflchyperbole{\xintfloateval{sqrt((#4)^2+(#5)^2)}}%
  % AffTout
  \ifboolKV[GraphiqueTikzConique]{AffTout}%
  {\setKV[GraphiqueTikzConique]{AffCentre=true,AffFoyers=true,AffSommets=true,AffAsymptotes=true}}%
  {}%
  % nœud centre
  \coordinate (#2-C) at (\pflxcentre,\pflycentre) ;%
  % foyers et sommets selon sens
  \IfStrEq{\pflsensparab}{V}%
  {%
    % axe vertical
    \coordinate (#2-F1) at (\pflxcentre,\xintfloateval{\pflycentre+\pflchyperbole}) ;%
    \coordinate (#2-F2) at (\pflxcentre,\xintfloateval{\pflycentre-\pflchyperbole}) ;%
    \coordinate (#2-S1) at (\pflxcentre,\xintfloateval{\pflycentre+(#5)}) ;%
    \coordinate (#2-S2) at (\pflxcentre,\xintfloateval{\pflycentre-(#5)}) ;%
  }%
  {%
    % axe horizontal
    \coordinate (#2-F1) at (\xintfloateval{\pflxcentre+\pflchyperbole},\pflycentre) ;%
    \coordinate (#2-F2) at (\xintfloateval{\pflxcentre-\pflchyperbole},\pflycentre) ;%
    \coordinate (#2-S1) at (\xintfloateval{\pflxcentre+(#4)},\pflycentre) ;%
    \coordinate (#2-S2) at (\xintfloateval{\pflxcentre-(#4)},\pflycentre) ;%
  }%
  % affichages
  \ifboolKV[GraphiqueTikzConique]{AffAsymptotes}%
  {%
    \begin{scope}
    \clip (\pflxmin,\pflymin) rectangle (\pflxmax,\pflymax) ;
    % asymptotes : pentes ±b/a (H) ou ±a/b (V)
    \IfStrEq{\pflsensparab}{V}%
    {%
      \draw[color={\useKV[GraphiqueTikzConique]{CouleurDroites}},pfltraitvoisinageasympt]
        (\pflxmin, \xintfloateval{\pflycentre+(#4)/(#5)*(\pflxmin-\pflxcentre)}) --
        (\pflxmax, \xintfloateval{\pflycentre+(#4)/(#5)*(\pflxmax-\pflxcentre)}) ;
    \draw[color={\useKV[GraphiqueTikzConique]{CouleurDroites}},pfltraitvoisinageasympt]
      (\pflxmin, \xintfloateval{\pflycentre-(#4)/(#5)*(\pflxmin-\pflxcentre)}) --
      (\pflxmax, \xintfloateval{\pflycentre-(#4)/(#5)*(\pflxmax-\pflxcentre)}) ;
    }%
    {%
      \draw[color={\useKV[GraphiqueTikzConique]{CouleurDroites}},pfltraitvoisinageasympt]
        (\pflxmin, \xintfloateval{\pflycentre+(#5)/(#4)*(\pflxmin-\pflxcentre)}) --
        (\pflxmax, \xintfloateval{\pflycentre+(#5)/(#4)*(\pflxmax-\pflxcentre)}) ;
      \draw[{\useKV[GraphiqueTikzConique]{CouleurDroites}},pfltraitvoisinageasympt]
        (\pflxmin, \xintfloateval{\pflycentre-(#5)/(#4)*(\pflxmin-\pflxcentre)}) --
        (\pflxmax, \xintfloateval{\pflycentre-(#5)/(#4)*(\pflxmax-\pflxcentre)}) ;
    }%
    \end{scope}%
  }{}%
  \ifboolKV[GraphiqueTikzConique]{AffCentre}%
    {\MarquerPts*[Couleur={\useKV[GraphiqueTikzConique]{CouleurPoints}}]{(#2-C)}}{}%
  \ifboolKV[GraphiqueTikzConique]{AffFoyers}%
    {\MarquerPts*[Couleur={\useKV[GraphiqueTikzConique]{CouleurPoints}}]{(#2-F1),(#2-F2)}}{}%
  \ifboolKV[GraphiqueTikzConique]{AffSommets}%
    {\MarquerPts*[Couleur={\useKV[GraphiqueTikzConique]{CouleurPoints}}]{(#2-S1),(#2-S2)}}{}%
}

%====ECC
\defKV[tkzgECC]{%
  Couleur=\def\tkzecc@coul@graph{#1},%
  CouleursParams=\def\tkzecc@coul@params{#1}
}

\setKVdefault[tkzgECC]{%
  Couleur=black,%
  AffParams=true,%
  CouleursParams={black},%
  TraitsComplets=true
}

\NewDocumentCommand\TracerCourbeECC{ O{} m m }{%
  \restoreKV[tkzgECC]%
  \setKV[tkzgECC]{#1}%
  \IfSubStr{\tkzecc@coul@params}{/}%
    {%
      \StrCut{\tkzecc@coul@params}{/}{\tkzecc@coul@quart}{\tkzecc@coul@med}%
    }%
    {%
      \def\tkzecc@coul@quart{\tkzecc@coul@params}\def\tkzecc@coul@med{\tkzecc@coul@params}%
    }%
  \setsepchar{,}%
  \readlist*\DataClass{#2}%
  \readlist*\DataEff{#3}%
  \xdef\DonneesECC{0}%
  \xintFor* ##1 in {\xintSeq{1}{\DataEfflen}}\do{%
    \xdef\DonneesTmp{0}
    \xintFor* ##2 in {\xintSeq{1}{##1}}\do{%
      \xdef\DonneesTmp{\xintfloateval{\DonneesTmp+\DataEff[##2]}}%
    }%
    \xdef\DonneesECC{\DonneesECC,\DonneesTmp}%
  }%
  \readlist*\DataECC\DonneesECC%
  \itemtomacro\DataClass[1]\DonneesXmin%
  \itemtomacro\DataClass[-1]\DonneesXmax%
  \itemtomacro\DataECC[-1]\DonneesEffMax%
  \xdef\DonneesListeECC{(\DataClass[1],\DataECC[1])}%
  \xintFor* ##1 in {\xintSeq{2}{\DataECClen}}\do{%
    \xdef\DonneesListeECC{\DonneesListeECC--(\DataClass[##1],\DataECC[##1])}%
  }%
    %paramètres par interpolation
  \xintFor* ##1 in {\xintSeq{1}{\DataEfflen}}\do{%
    \xdef\isuiv{\xinteval{##1+1}}%
    \xintifboolexpr{\DataECC[##1] < (0.25*\DonneesEffMax) 'and' \DataECC[\isuiv] >= (0.25*\DonneesEffMax)}%
      {%
        \xdef\pentetmpECC{(\DataECC[\isuiv]-\DataECC[##1])/(\DataClass[\isuiv]-\DataClass[##1])}%OK
        \xdef\ValPremQuartile{\xintfloateval{(0.25*\DonneesEffMax+\pentetmpECC*\DataClass[##1]-\DataECC[##1])/(\pentetmpECC)}}%
      }
      {}%
    \xintifboolexpr{\DataECC[##1] < (0.50*\DonneesEffMax) 'and' \DataECC[\isuiv] >= (0.50*\DonneesEffMax)}%
      {%
        \xdef\pentetmpECC{(\DataECC[\isuiv]-\DataECC[##1])/(\DataClass[\isuiv]-\DataClass[##1])}%OK
        \xdef\ValMed{\xintfloateval{(0.50*\DonneesEffMax+\pentetmpECC*\DataClass[##1]-\DataECC[##1])/(\pentetmpECC)}}%
      }
      {}%
    \xintifboolexpr{\DataECC[##1] < (0.75*\DonneesEffMax) 'and' \DataECC[\isuiv] >= (0.75*\DonneesEffMax)}%
      {%
        \xdef\pentetmpECC{(\DataECC[\isuiv]-\DataECC[##1])/(\DataClass[\isuiv]-\DataClass[##1])}%OK
        \xdef\ValTroisQuartile{\xintfloateval{(0.75*\DonneesEffMax+\pentetmpECC*\DataClass[##1]-\DataECC[##1])/(\pentetmpECC)}}%
      }
      {}%
  }%
  %partie graphique
  \draw[pflcourbeecc,\tkzecc@coul@graph] \DonneesListeECC ;
  \xintFor* ##1 in {\xintSeq{1}{\DataECClen}}\do{%
    \filldraw[\tkzecc@coul@graph] (\DataClass[##1],\DataECC[##1]) circle[pflpointnuage] ;
  }%
  \ifboolKV[tkzgECC]{AffParams}%
      {%
        %médiane
        \ifboolKV[tkzgECC]{TraitsComplets}%
          {%
            \draw[pfltraitsparamecc,color=\tkzecc@coul@med] (\pflxmin,{0.50*\DonneesEffMax})--(\pflxmax,{0.50*\DonneesEffMax});
            \draw[pfltraitsparamecc,color=\tkzecc@coul@quart] (\pflxmin,{0.25*\DonneesEffMax})--++({\pflxmax-\pflxmin},0);
            \draw[pfltraitsparamecc,color=\tkzecc@coul@quart] (\pflxmin,{0.75*\DonneesEffMax})--++({\pflxmax-\pflxmin},0);
          }%
          {%
            \draw[pfltraitsparamecc,color=\tkzecc@coul@med] (\pflxmin,{0.50*\DonneesEffMax})--(\ValMed,{0.50*\DonneesEffMax});
            \draw[pfltraitsparamecc,color=\tkzecc@coul@quart] (\pflxmin,{0.25*\DonneesEffMax})--++({\ValPremQuartile-\pflxmin},0);
            \draw[pfltraitsparamecc,color=\tkzecc@coul@quart] (\pflxmin,{0.75*\DonneesEffMax})--++({\ValTroisQuartile-\pflxmin},0);
          }%
        \draw[pfltraitsparamecc,color=\tkzecc@coul@med] (\ValMed,{0.5*\DonneesEffMax})--(\ValMed,0) ; \draw[\tkzecc@coul@med,thick,fill=white] (\ValMed,{0.5*\DonneesEffMax}) circle[pflpointnuage] ;
        \draw[pfltraitsparamecc,color=\tkzecc@coul@quart] (\ValPremQuartile,{0.25*\DonneesEffMax})--(\ValPremQuartile,\pflymin) ; \draw[\tkzecc@coul@quart,thick,fill=white] (\ValPremQuartile,{0.25*\DonneesEffMax}) circle[pflpointnuage] ;
        \draw[pfltraitsparamecc,color=\tkzecc@coul@quart] (\ValTroisQuartile,{0.75*\DonneesEffMax})--(\ValTroisQuartile,\pflymin) ; \draw[\tkzecc@coul@quart,thick,fill=white] (\ValTroisQuartile,{0.75*\DonneesEffMax}) circle[pflpointnuage] ;
      }%
      {}%
}

%====PTS DISCONTINUITÉ
\defKV[tkzptdiscont]{%
  Couleur=\def\pfldiscontcouleur{#1},%
  Pos=\def\pfldiscontpos{#1},%
  Echelle=\def\pfldiscontechelle{#1},%
  Type=\def\pfldisconttype{#1}
}

\setKVdefault[tkzptdiscont]{%
  Couleur=black,%
  Pos=D,%
  Echelle=1,%
  Type=par
}

\NewDocumentCommand\AfficherPtsDiscont{ O{} m }{%
  \restoreKV[tkzptdiscont]
  \setKV[tkzptdiscont]{#1}%
  \setsepchar[.]{§./}%
  \readlist*\SPLlisteDiscont{#2}%
  \def\SPLlisteDiscontNb{\SPLlisteDiscontlen}%
  \foreach \i in {1,...,\SPLlisteDiscontNb}{%
    \begin{scope}[shift={(\SPLlisteDiscont[\i,1],\SPLlisteDiscont[\i,2])},rotate={atan \SPLlisteDiscont[\i,3]},scale=\pfldiscontechelle]
      \IfStrEq{\pfldisconttype}{rond}%
        {%
          \draw[pflcourbediscont,fill=white,draw=\pfldiscontcouleur] (0,0) circle[radius=3pt] ;
        }{}%
      \IfStrEq{\pfldiscontpos}{D}%
        {%
          \IfStrEq{\pfldisconttype}{par}%
            {%
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) to[out=90,in=170] (4pt,5pt) ;
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) to[out=-90,in=-170] (4pt,-5pt) ;
            }{}%
          \IfStrEq{\pfldisconttype}{demirond}%
            {%
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) to[out=90,in=180] (3pt,3pt) ;
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) to[out=-90,in=180] (3pt,-3pt) ;
            }{}%
          \IfStrEq{\pfldisconttype}{cro}%
            {%
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) |- (4pt,5pt) ;
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) |- (4pt,-5pt) ;
            }{}%
        }%
        {%
          \IfStrEq{\pfldisconttype}{par}%
            {%
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) to[out=90,in=-10] (-4pt,5pt) ;
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) to[out=-90,in=10] (-4pt,-5pt) ;
            }{}%
          \IfStrEq{\pfldisconttype}{demirond}%
            {%
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) to[out=90,in=0] (-3pt,3pt) ;
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) to[out=-90,in=0] (-3pt,-3pt) ;
            }{}%
          \IfStrEq{\pfldisconttype}{cro}%
            {%
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) |- (-4pt,5pt) ;
              \draw[pflcourbediscont,color=\pfldiscontcouleur] (0,0) |- (-4pt,-5pt) ;
            }{}%
        }%
    \end{scope}
  }%
}

%====linear inequality [fr]
\defKV[GraphiquetikzInegLin]{%
  Opacite=\def\pflineglinopac{#1},%
  Nom=\def\pflineglinname{#1},%
  Style=\def\pflineglintikzstyle{#1},%
  Hachures=\def\pflineglintikzhatch{#1}
}

\setKVdefault[GraphiquetikzInegLin]{%
  Opacite=0.25,
  Couleur=black,%
  Style=hachures,%
  Hachures={north west lines},%
  Swap=false,%
  PointillesSiStrict=true
}

\NewDocumentCommand\InegaliteLineaire{O{}D<>{f}mm}{%
  \restoreKV[GraphiquetikzInegLin]%
  \setKV[GraphiquetikzInegLin]{#1}%
  %style for filling... ?
  \IfStrEq{\pflineglintikzstyle}{hachures}%
    {%
      \tikzset{dominegallintikzstyle/.style={draw=none,pattern=\pflineglintikzhatch,pattern color={\useKV[GraphiquetikzInegLin]{Couleur}},line join=bevel}}
    }%
    {}%
  \IfStrEq{\pflineglintikzstyle}{remplissage}%
    {%
      \tikzset{dominegallintikzstyle/.style={draw=none,fill={\useKV[GraphiquetikzInegLin]{Couleur}},fill opacity=\pflineglinopac,line join=bevel}}
    }%
    {}%
  \ifboolKV[GraphiquetikzInegLin]{PointillesSiStrict}%
    {%
      \IfSubStr{#4}{=}%
        {%
          \tikzset{stylelinelinineq/.style={pfltrait}}%
        }%
        {%
          \tikzset{stylelinelinineq/.style={pfltraitpointille}}%
        }%
    }%
    {%
      \tikzset{stylelinelinineq/.style={pfltrait}}%
    }%
  %dummy equation
  \xintdeffloatfunc pfldummy(x,y) := #3;
  %coeffc
  \xdef\coeffc{\xintfloateval{pfldummy(0,0)}}%
  %coeffa
  \xdef\coeffa{\xintfloateval{pfldummy(1,0)-pfldummy(0,0)}}%
  %coeffb
  \xdef\coeffb{\xintfloateval{pfldummy(0,1)-pfldummy(0,0)}}%
  %swap
  \ifboolKV[GraphiquetikzInegLin]{Swap}%
    {\IfBeginWith{#4}{<}{\def\tmpinegalsign{>}}{\def\tmpinegalsign{<}}}%
    {\def\tmpinegalsign{#4}}%
  %particular part
  \xintifboolexpr{ \coeffb == 0 }%vertical
    {%
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
        \xintifboolexpr{ \coeffa > 0 }%
          {%
            \IfBeginWith{\tmpinegalsign}{>}%
              {%
                \draw[stylelinelinineq,dominegallintikzstyle] ({-(\coeffc)/(\coeffa)},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
              }%
              {%
                \draw[stylelinelinineq,dominegallintikzstyle] ({-(\coeffc)/(\coeffa)},{\pflymin}) rectangle ({\pflxmin},{\pflymax}) ;
              }%
          }%
          {%
            \IfBeginWith{\tmpinegalsign}{>}%
              {%
                \draw[stylelinelinineq,dominegallintikzstyle] ({-(\coeffc)/(\coeffa)},{\pflymin}) rectangle ({\pflxmin},{\pflymax}) ;
              }%
              {%
                \draw[stylelinelinineq,dominegallintikzstyle] ({-(\coeffc)/(\coeffa)},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
              }%
          }%
        \draw[stylelinelinineq,color={\useKV[GraphiquetikzInegLin]{Couleur}}] ({-(\coeffc)/(\coeffa)},{\pflymin}) -- ({-(\coeffc)/(\coeffa)},{\pflymax}) ;
      \end{scope}
    }%
    {% b!=0 ()
      \xdef\tmpvalzzyxmin{\xintfloateval{(-\coeffc-\coeffa*(\pflxmin))/(\coeffb)}}%
      \xdef\tmpvalzzyxmax{\xintfloateval{(-\coeffc-\coeffa*(\pflxmax))/(\coeffb)}}%
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
        %---
          \xintifboolexpr{ \coeffb > 0 }%
            {%
              \IfBeginWith{\tmpinegalsign}{<}%
                {%
                  \clip ({\pflxmin},{\pflymin}) -- ({\pflxmax},{\pflymin}) -- ({\pflxmax},{\tmpvalzzyxmax}) -- ({\pflxmin},{\tmpvalzzyxmin}) -- cycle ;
                  \fill[dominegallintikzstyle] ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
                }%
                {%
                  \clip ({\pflxmin},{\tmpvalzzyxmin}) -- ({\pflxmax},{\tmpvalzzyxmax}) -- ({\pflxmax},{\pflymax}) -- ({\pflxmin},{\pflymax}) -- cycle ;
                  \fill[dominegallintikzstyle] ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
                }%
            }%
            {%
              \IfBeginWith{\tmpinegalsign}{<}%
                {%
                  \clip ({\pflxmin},{\tmpvalzzyxmin}) -- ({\pflxmax},{\tmpvalzzyxmax}) -- ({\pflxmax},{\pflymax}) -- ({\pflxmin},{\pflymax}) -- cycle ;
                  \fill[dominegallintikzstyle] ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
                }%
                {%
                  \clip ({\pflxmin},{\pflymin}) -- ({\pflxmax},{\pflymin}) -- ({\pflxmax},{\tmpvalzzyxmax}) -- ({\pflxmin},{\tmpvalzzyxmin}) -- cycle ;
                  \fill[dominegallintikzstyle] ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
                }%
            }%
        %---
        \draw[stylelinelinineq,color={\useKV[GraphiquetikzInegLin]{Couleur}}] ({\pflxmin},{(-\coeffc-\coeffa*(\pflxmin))/(\coeffb)}) -- ({\pflxmax},{(-\coeffc-\coeffa*(\pflxmax))/(\coeffb)}) ;
      \end{scope}
    }%
}

%====TRANSFORMATION f(x-a)+b (formule, spline, interpo)
\defKV[GraphiqueTikzTransfo]{%
  Nom=\def\pflnametransfo{#1},%
  StyleTrace=\def\pflstyletransfo{#1},%
  Pas=\def\pflsteptransfo{#1},%
  Coeffs=\def\pflcoeffstransfo{#1},%
  Tension=\def\pfltensiontransfo{#1}
}

\setKVdefault[GraphiqueTikzTransfo]{%
  Nom={},%
  Couleur=black,%
  Debut={\pflxmin},%
  Fin={\pflxmax},%
  Pas={},%
  Clip=true,%
  Spline=false,%
  Interpo=false,%
  Alt=false,%
  Coeffs=3,%
  Tension=0.5,%
  StyleTrace={}%
}

\NewDocumentCommand\TracerTransformee{ O{} m m m }{%
  %#1 = clés
  %#2 = objet : nom_fct (formule xint) OU liste spline OU liste interpo
  %#3 = a  (décalage horizontal : on trace f(x-a)+b)
  %#4 = b  (décalage vertical)
  \restoreKV[GraphiqueTikzTransfo]%
  \setKV[GraphiqueTikzTransfo]{#1}%
  %---
  \ifboolKV[GraphiqueTikzTransfo]{Spline}%
  {%
    %---cas SPLINE : transformation géométrique des points de contrôle---
    \tkzg@transfo@spline{#2}{#3}{#4}%
    % bifurcation [Alt]
    \ifboolKV[GraphiqueTikzTransfo]{Alt}%
    {%
      \DefinirCourbeSpline%
        [Alt,Trace,%
        Couleur={\useKV[GraphiqueTikzTransfo]{Couleur}},%
        Nom=\pflnametransfo,%
        StyleTrace=\pflstyletransfo,%
        Coeffs=\pflcoeffstransfo]%
        {\TRFlistedecaleespline}%
    }%
    {%
      \DefinirCourbeSpline%
        [Trace,%
        Couleur={\useKV[GraphiqueTikzTransfo]{Couleur}},%
        Nom=\pflnametransfo,%
        StyleTrace=\pflstyletransfo,%
        Coeffs=\pflcoeffstransfo]%
        {\TRFlistedecaleespline}%
    }%
  }%
  {%
    \ifboolKV[GraphiqueTikzTransfo]{Interpo}%
    {%
      %---cas INTERPO : décalage des points (xi+a, yi+b)---
      \tkzg@transfo@interpo{#2}{#3}{#4}%
      \DefinirCourbeInterpo%
        [Trace,%
        Couleur={\useKV[GraphiqueTikzTransfo]{Couleur}},%
        Nom=\pflnametransfo,%
        StyleTrace=\pflstyletransfo,%
        Tension=\pfltensiontransfo]%
        {\TRFlistedecaleeinterpo}%
    }%
    {%
      %---cas FORMULE xint : g(x) = f(x-a)+b---
      \IfStrEq{\pflsteptransfo}{}%
      {%
        \xdef\pflsteptransfo{\xintfloateval{%
            ((\useKV[GraphiqueTikzTransfo]{Fin})-%
            (\useKV[GraphiqueTikzTransfo]{Debut}))/200}}%
      }%
      {}%
      \xintdeffloatfunc pfltransfo(x) := #2(x-(#3))+(#4) ;%
      \ifboolKV[GraphiqueTikzTransfo]{Clip}%
      {\begin{scope}%
          \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;}%
        {}%
        \IfEq{\pflnametransfo}{}%
        {%
          \draw[pflcourbe,\pflstyletransfo,%
          color={\useKV[GraphiqueTikzTransfo]{Couleur}}]
          plot[smooth] coordinates {%
            \xintthecoords\xintfloatexpr
            seq((x, pfltransfo(x)),
            x=\useKV[GraphiqueTikzTransfo]{Debut}%
            ..[\pflsteptransfo]..%
            \useKV[GraphiqueTikzTransfo]{Fin},%
            \useKV[GraphiqueTikzTransfo]{Fin})
            \relax
          } ;%
        }%
        {%
          \path[draw,pflcourbe,\pflstyletransfo,%
          color={\useKV[GraphiqueTikzTransfo]{Couleur}},%
          name path global=\pflnametransfo]
          plot[smooth] coordinates {%
            \xintthecoords\xintfloatexpr
            seq((x, pfltransfo(x)),
            x=\useKV[GraphiqueTikzTransfo]{Debut}%
            ..[\pflsteptransfo]..%
            \useKV[GraphiqueTikzTransfo]{Fin},%
            \useKV[GraphiqueTikzTransfo]{Fin})
            \relax
          } ;%
        }%
        \ifboolKV[GraphiqueTikzTransfo]{Clip}{\end{scope}}{}%
    }%
  }%
}

\defKV[GraphiqueTikzReflexion]{%
  Axe=\def\pflaxereflexion{#1},%
  Nom=\def\pflnamereflexion{#1},%
  StyleTrace=\def\pflstylereflexion{#1},%
  Pas=\def\pflstepreflexion{#1},%
  Coeffs=\def\pflcoeffsreflexion{#1},%
  Tension=\def\pfltensiontransfo{#1}
}

\setKVdefault[GraphiqueTikzReflexion]{%
  Axe=x,%
  Nom={},%
  Couleur=black,%
  Debut={\pflxmin},%
  Fin={\pflxmax},%
  Pas={},%
  Clip=true,%
  Spline=false,%
  Interpo=false,%
  Alt=false,%
  Coeffs=3,%
  Tension=0.5,%
  StyleTrace={}%
}

\NewDocumentCommand\TracerReflexion{ O{} m }{%
  %#1 = clés
  %#2 = objet : nom_fct (formule xint) OU liste spline OU liste interpo
  \restoreKV[GraphiqueTikzReflexion]%
  \setKV[GraphiqueTikzReflexion]{#1}%
  %---
  \ifboolKV[GraphiqueTikzReflexion]{Spline}%
  {%
    %---cas SPLINE---
    \IfStrEq{\pflaxereflexion}{yx}%
    {%
      %---Axe=yx spline : symétrie via scope matriciel---
      % La matrice (0,1,1,0) échange x et y = symétrie par rapport à y=x
      % Requiert des unités égales en x et y pour être visuellement correcte (test à faire ou pas ?)
      \xintifboolexpr{abs(\xintfloateval{\pflyunit/\pflxunit} - 1) < 0.001}%
      {}%
      {%
        \PackageWarning{tkz-grapheur}{Axe=yx+Spline : unites x et y differentes, rendu visuellement incorrect}%
      }%
      % #2 = liste spline originale, on génère le chemin dans \RFXcheminspline
      \ifboolKV[GraphiqueTikzReflexion]{Alt}%
      {\GenererSpline*{#2}{\pflcoeffsreflexion}[\RFXcheminspline]}%
      {\GenererSpline{#2}{\pflcoeffsreflexion}[\RFXcheminspline]}%
      \begin{scope}[cm={0,1,1,0,(0,0)}]%
        \IfEq{\pflnamereflexion}{}%
        {%
          \draw[pflcourbe,\pflstylereflexion,color={\useKV[GraphiqueTikzReflexion]{Couleur}}] \RFXcheminspline ;%
        }%
        {%
          \path[draw,pflcourbe,\pflstylereflexion,color={\useKV[GraphiqueTikzReflexion]{Couleur}},name path global=\pflnamereflexion] \RFXcheminspline ;%
        }%
      \end{scope}%
    }%
    {%
      \tkzg@reflexion@spline{#2}{\pflaxereflexion}%
      \ifboolKV[GraphiqueTikzReflexion]{Alt}%
      {%
        \DefinirCourbeSpline%
          [Alt,Trace,%
          Couleur={\useKV[GraphiqueTikzReflexion]{Couleur}},%
          Nom=\pflnamereflexion,%
          StyleTrace=\pflstylereflexion,%
          Coeffs=\pflcoeffsreflexion]%
          {\RFXlistedecaleespline}%
      }%
      {%
        \DefinirCourbeSpline%
          [Trace,%
          Couleur={\useKV[GraphiqueTikzReflexion]{Couleur}},%
          Nom=\pflnamereflexion,%
          StyleTrace=\pflstylereflexion,%
          Coeffs=\pflcoeffsreflexion]%
          {\RFXlistedecaleespline}%
      }%
    }%
  }%
  {%
    \ifboolKV[GraphiqueTikzReflexion]{Interpo}%
    {%
      %---cas INTERPO---
      \tkzg@reflexion@interpo{#2}{\pflaxereflexion}%
      \DefinirCourbeInterpo%
        [Trace,%
        Couleur={\useKV[GraphiqueTikzReflexion]{Couleur}},%
        Nom=\pflnamereflexion,%
        StyleTrace=\pflstylereflexion,%
        Tension=\pfltensiontransfo]%
        {\RFXlistedecaleeinterpo}%
    }%
    {%
      %---cas FORMULE xint---
      \IfStrEq{\pflstepreflexion}{}%
      {%
        \xdef\pflstepreflexion{\xintfloateval{%
            ((\useKV[GraphiqueTikzReflexion]{Fin})-%
            (\useKV[GraphiqueTikzReflexion]{Debut}))/200}}%
      }%
      {}%
      \IfStrEqCase{\pflaxereflexion}{%
        {x}{%
          % -f(x) : on définit g(x) = -f(x)
          \xintdeffloatfunc pflreflexion(x) := -(#2(x)) ;%
        }%
        {y}{%
          % f(-x) : on définit g(x) = f(-x)
          \xintdeffloatfunc pflreflexion(x) := #2(-(x)) ;%
        }%
        {yx}{%
          %
        }%
      }%
      \ifboolKV[GraphiqueTikzReflexion]{Clip}%
      {\begin{scope}%
          \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;}%
        {}%
        \IfStrEq{\pflaxereflexion}{yx}%
        {%
          %---cas yx : courbe paramétrique (f(t), t)---
          \IfEq{\pflnamereflexion}{}%
          {%
            \draw[pflcourbe,\pflstylereflexion,%
            color={\useKV[GraphiqueTikzReflexion]{Couleur}}]
            plot[smooth] coordinates {%
              \xintthecoords\xintfloatexpr
              seq((#2(t), t),
              t=\useKV[GraphiqueTikzReflexion]{Debut}%
              ..[\pflstepreflexion]..%
              \useKV[GraphiqueTikzReflexion]{Fin},%
              \useKV[GraphiqueTikzReflexion]{Fin})
              \relax
            } ;%
          }%
          {%
            \path[draw,pflcourbe,\pflstylereflexion,%
            color={\useKV[GraphiqueTikzReflexion]{Couleur}},%
            name path global=\pflnamereflexion]
            plot[smooth] coordinates {%
              \xintthecoords\xintfloatexpr
              seq((#2(t), t),
              t=\useKV[GraphiqueTikzReflexion]{Debut}%
              ..[\pflstepreflexion]..%
              \useKV[GraphiqueTikzReflexion]{Fin},%
              \useKV[GraphiqueTikzReflexion]{Fin})
              \relax
            } ;%
          }%
        }%
        {%
          %---cas x et y : tracé classique de pflreflexion---
          \IfEq{\pflnamereflexion}{}%
          {%
            \draw[pflcourbe,\pflstylereflexion,%
            color={\useKV[GraphiqueTikzReflexion]{Couleur}}]
            plot[smooth] coordinates {%
              \xintthecoords\xintfloatexpr
              seq((x, pflreflexion(x)),
              x=\useKV[GraphiqueTikzReflexion]{Debut}%
              ..[\pflstepreflexion]..%
              \useKV[GraphiqueTikzReflexion]{Fin},%
              \useKV[GraphiqueTikzReflexion]{Fin})
              \relax
            } ;%
          }%
          {%
            \path[draw,pflcourbe,\pflstylereflexion,%
            color={\useKV[GraphiqueTikzReflexion]{Couleur}},%
            name path global=\pflnamereflexion]
            plot[smooth] coordinates {%
              \xintthecoords\xintfloatexpr
              seq((x, pflreflexion(x)),
              x=\useKV[GraphiqueTikzReflexion]{Debut}%
              ..[\pflstepreflexion]..%
              \useKV[GraphiqueTikzReflexion]{Fin},%
              \useKV[GraphiqueTikzReflexion]{Fin})
              \relax
            } ;%
          }%
        }%
        \ifboolKV[GraphiqueTikzReflexion]{Clip}{\end{scope}}{}%
    }%
  }%
}

%====POLYNÔME DE TAYLOR / MACLAURIN
\defKV[GraphiqueTikzTaylor]{%
  Ordre=\def\pfltaylorordre{#1},%
  h=\def\pfltaylorh{#1},%
  Nom=\def\pfltaylornom{#1},%
  StyleTrace=\def\pfltaylorstyle{#1},%
  Pas=\def\pfltaylorpas{#1}%
}

\setKVdefault[GraphiqueTikzTaylor]{%
  Ordre=5,%
  h=0.01,%
  Couleur=black,%
  Debut={\pflxmin},%
  Fin={\pflxmax},%
  Pas={},%
  Clip=true,%
  Trace=false,%
  Nom={},%
  StyleTrace={}%
}

\NewDocumentCommand\DefinirTaylor{ O{} D<>{taylorN} m m }{%
  %#1 = clés
  %#2 = nom de la fonction Taylor (pour réutilisation)
  %#3 = nom de la fonction xint originale
  %#4 = point de développement a
  \restoreKV[GraphiqueTikzTaylor]%
  \setKV[GraphiqueTikzTaylor]{#1}%
  % calcul du pas de tracé si non fourni
  \IfStrEq{\pfltaylorpas}{}%
  {%
    \xdef\pfltaylorpas{\xintfloateval{%
        ((\useKV[GraphiqueTikzTaylor]{Fin})-(\useKV[GraphiqueTikzTaylor]{Debut}))/200}}%
  }%
  {}%
  % construction du polynôme
  \tkzg@taylor@build{#3}{\pfltaylorordre}{#4}{\pfltaylorh}%
  % on nomme la fonction pour réutilisation
  \xintdeffloatfunc #2(x) := pfltaylorpoly(x) ;%
  % tracé conditionnel
  \ifboolKV[GraphiqueTikzTaylor]{Clip}%
  {\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;}%
    {}%
    \ifboolKV[GraphiqueTikzTaylor]{Trace}%
    {%
      \IfEq{\pfltaylornom}{}%
      {%
        \draw[pflcourbe,\pfltaylorstyle,color={\useKV[GraphiqueTikzTaylor]{Couleur}}]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x, min(max(pfltaylorpoly(x),\pflMinoffsetV),\pflMaxoffsetV)),
          x=\useKV[GraphiqueTikzTaylor]{Debut}%
          ..[\pfltaylorpas]..%
          \useKV[GraphiqueTikzTaylor]{Fin},%
          \useKV[GraphiqueTikzTaylor]{Fin})
          \relax
        } ;%
      }%
      {%
        \path[draw,pflcourbe,\pfltaylorstyle,%
        color={\useKV[GraphiqueTikzTaylor]{Couleur}},%
        name path global=\pfltaylornom]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x, min(max(pfltaylorpoly(x),\pflMinoffsetV),\pflMaxoffsetV)),
          x=\useKV[GraphiqueTikzTaylor]{Debut}%
          ..[\pfltaylorpas]..%
          \useKV[GraphiqueTikzTaylor]{Fin},%
          \useKV[GraphiqueTikzTaylor]{Fin})
          \relax
        } ;%
      }%
    }%
    {%
      % pas de tracé mais path nommé si Nom= fourni
      \IfEq{\pfltaylornom}{}%
      {}%
      {%
        \path[draw=none,pflcourbe,name path global=\pfltaylornom]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x, min(max(pfltaylorpoly(x),\pflMinoffsetV),\pflMaxoffsetV)),
          x=\useKV[GraphiqueTikzTaylor]{Debut}%
          ..[\pfltaylorpas]..%
          \useKV[GraphiqueTikzTaylor]{Fin},%
          \useKV[GraphiqueTikzTaylor]{Fin})
          \relax
        } ;%
      }%
    }%
    \ifboolKV[GraphiqueTikzTaylor]{Clip}{\end{scope}}{}%
}

%---commande \TracerTaylor
\NewDocumentCommand\TracerTaylor{ O{} m m }{%
  %#1 = clés
  %#2 = nom de la fonction xint originale
  %#3 = point de développement a
  \restoreKV[GraphiqueTikzTaylor]%
  \setKV[GraphiqueTikzTaylor]{#1}%
  % calcul du pas de tracé si non fourni
  \IfStrEq{\pfltaylorpas}{}%
  {%
    \xdef\pfltaylorpas{\xintfloateval{%
        ((\useKV[GraphiqueTikzTaylor]{Fin})-(\useKV[GraphiqueTikzTaylor]{Debut}))/200}}%
  }%
  {}%
  % construction du polynôme
  \tkzg@taylor@build{#2}{\pfltaylorordre}{#3}{\pfltaylorh}%
  % tracé
  \ifboolKV[GraphiqueTikzTaylor]{Clip}%
  {\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;}%
    {}%
    \IfEq{\pfltaylornom}{}%
    {%
      \draw[pflcourbe,\pfltaylorstyle,color={\useKV[GraphiqueTikzTaylor]{Couleur}}]
      plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
        seq((x, min(max(pfltaylorpoly(x),\pflMinoffsetV),\pflMaxoffsetV)),
        x=\useKV[GraphiqueTikzTaylor]{Debut}%
        ..[\pfltaylorpas]..%
        \useKV[GraphiqueTikzTaylor]{Fin},%
        \useKV[GraphiqueTikzTaylor]{Fin})
        \relax
      } ;%
    }%
    {%
      \path[draw,pflcourbe,\pfltaylorstyle,%
      color={\useKV[GraphiqueTikzTaylor]{Couleur}},%
      name path global=\pfltaylornom]
      plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
        seq((x, min(max(pfltaylorpoly(x),\pflMinoffsetV),\pflMaxoffsetV)),
        x=\useKV[GraphiqueTikzTaylor]{Debut}%
        ..[\pfltaylorpas]..%
        \useKV[GraphiqueTikzTaylor]{Fin},%
        \useKV[GraphiqueTikzTaylor]{Fin})
        \relax
      } ;%
    }%
    \ifboolKV[GraphiqueTikzTaylor]{Clip}{\end{scope}}{}%
}

%====LOI EXPO
\defKV[GraphiqueTikzLoiProbasCont]{%
  Pas=\def\pflloiprobastep{#1},%
  Nom=\def\pflloiprobaname{#1}
}

\setKVdefault[GraphiqueTikzLoiProbasCont]{%
  Nom=densite,%
  Couleur=black,%
  Trace=false,%
  Pas={},%
  Debut={\pflxmin},%
  Fin={\pflxmax}
}

\NewDocumentCommand\DefinirLoiExponentielle{ O{} D<>{fdexpo} m }{%
  %1=options
  %2=mu
  %3=sigma
  \restoreKV[GraphiqueTikzLoiProbasCont]%
  \setKV[GraphiqueTikzLoiProbasCont]{#1}%
  \xintdeffloatfunc #2(x) := (#3)*exp(-(#3)*x) ;%
  \IfStrEq{\pflloiprobastep}{}%
  {%
    \xdef\pflloiprobastep{\xintfloateval{((\useKV[GraphiqueTikzLoiProbasCont]{Fin})-(\useKV[GraphiqueTikzLoiProbasCont]{Debut}))/200}}%
  }%
  {}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \ifboolKV[GraphiqueTikzLoiProbasCont]{Trace}%
    {%
      \path[draw,pflcourbe,color={\useKV[GraphiqueTikzLoiProbasCont]{Couleur}},name path global=\pflloiprobaname] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
        seq((x,#2(x)),x={\useKV[GraphiqueTikzLoiProbasCont]{Debut}}..[\pflloiprobastep]..{\useKV[GraphiqueTikzLoiProbasCont]{Fin}},{\useKV[GraphiqueTikzLoiProbasCont]{Fin}})
        \relax
      } ;
    }%
    {%
      \path[draw=none,pflcourbe,name path global=\pflloiprobaname]  plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
        seq((x,#2(x)),x={\useKV[GraphiqueTikzLoiProbasCont]{Debut}}..[\pflloiprobastep]..{\useKV[GraphiqueTikzLoiProbasCont]{Fin}},{\useKV[GraphiqueTikzLoiProbasCont]{Fin}})
        \relax
      } ;
    }%
  \end{scope}
}

\NewDocumentCommand\TracerLoiExponentielle{ O{} m }{%
  %1=options
  %2=mu
  %3=sigma
  \restoreKV[GraphiqueTikzLoiProbasCont]%
  \setKV[GraphiqueTikzLoiProbasCont]{#1}%
  \IfStrEq{\pflloiprobastep}{}%
  {%
    \xdef\pflloiprobastep{\xintfloateval{((\useKV[GraphiqueTikzLoiProbasCont]{Fin})-(\useKV[GraphiqueTikzLoiProbasCont]{Debut}))/200}}%
  }%
  {}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \draw[pflcourbe,color={\useKV[GraphiqueTikzLoiProbasCont]{Couleur}}]  plot[smooth] coordinates {%
      \xintthecoords\xintfloatexpr
      seq((x,#2),x={\useKV[GraphiqueTikzLoiProbasCont]{Debut}}..[\pflloiprobastep]..{\useKV[GraphiqueTikzLoiProbasCont]{Fin}},{\useKV[GraphiqueTikzLoiProbasCont]{Fin}})
      \relax
    } ;
  \end{scope}
}

%====LOI DE STUDENT
% f(x) = Γ((ν+1)/2) / (√(νπ)·Γ(ν/2)) · (1+x²/ν)^(-(ν+1)/2)
% #2 = nom fonction xint  #3 = ν (degrés de liberté)
\NewDocumentCommand\DefinirLoiStudent{ O{} D<>{fdstudent} m }{%
  %#1=options  #2=nom fonction  #3=ν
  \restoreKV[GraphiqueTikzLoiProbasCont]%
  \setKV[GraphiqueTikzLoiProbasCont]{#1}%
  \xintdeffloatfunc #2(x) :=
    pflgamma((#3+1)/2) / (sqrt((#3)*pi)*pflgamma((#3)/2))
    * (1+(x)^2/(#3))^(-((#3+1)/2)) ;%
  \IfStrEq{\pflloiprobastep}{}%
  {%
    \xdef\pflloiprobastep{\xintfloateval{%
      ((\useKV[GraphiqueTikzLoiProbasCont]{Fin})-(\useKV[GraphiqueTikzLoiProbasCont]{Debut}))/200}}%
  }{}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \ifboolKV[GraphiqueTikzLoiProbasCont]{Trace}%
    {%
      \path[draw,pflcourbe,color={\useKV[GraphiqueTikzLoiProbasCont]{Couleur}},name path global=\pflloiprobaname]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),
          x={\useKV[GraphiqueTikzLoiProbasCont]{Debut}}%
          ..[\pflloiprobastep]..%
          {\useKV[GraphiqueTikzLoiProbasCont]{Fin}},%
          {\useKV[GraphiqueTikzLoiProbasCont]{Fin}})
          \relax
        } ;
    }%
    {%
      \path[draw=none,pflcourbe,name path global=\pflloiprobaname]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),
          x={\useKV[GraphiqueTikzLoiProbasCont]{Debut}}%
          ..[\pflloiprobastep]..%
          {\useKV[GraphiqueTikzLoiProbasCont]{Fin}},%
          {\useKV[GraphiqueTikzLoiProbasCont]{Fin}})
          \relax
        } ;
    }%
  \end{scope}
}

\NewDocumentCommand\TracerLoiStudent{ O{} m }{%
  %#1=options  #2=nom fonction xint (définie par \DefinirLoiStudent)
  \restoreKV[GraphiqueTikzLoiProbasCont]%
  \setKV[GraphiqueTikzLoiProbasCont]{#1}%
  \IfStrEq{\pflloiprobastep}{}%
  {%
    \xdef\pflloiprobastep{\xintfloateval{%
      ((\useKV[GraphiqueTikzLoiProbasCont]{Fin})-(\useKV[GraphiqueTikzLoiProbasCont]{Debut}))/200}}%
  }{}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \draw[pflcourbe,color={\useKV[GraphiqueTikzLoiProbasCont]{Couleur}}]
      plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
        seq((x,#2),
        x={\useKV[GraphiqueTikzLoiProbasCont]{Debut}}%
        ..[\pflloiprobastep]..%
        {\useKV[GraphiqueTikzLoiProbasCont]{Fin}},%
        {\useKV[GraphiqueTikzLoiProbasCont]{Fin}})
        \relax
      } ;
  \end{scope}
}

%====LOI DE FISCHER (F de Snedecor)
% f(x) = Γ((d1+d2)/2)/(Γ(d1/2)·Γ(d2/2)) · (d1/d2)^(d1/2) · x^(d1/2-1) · (1+d1·x/d2)^(-(d1+d2)/2)
% définie pour x > 0 → penser à mettre Debut=0.001
% #3 = d1, #4 = d2 (degrés de liberté)
\NewDocumentCommand\DefinirLoiFischer{ O{} D<>{fdfischer} m m }{%
  %#1=options  #2=nom fonction  #3=d1  #4=d2
  \restoreKV[GraphiqueTikzLoiProbasCont]%
  \setKV[GraphiqueTikzLoiProbasCont]{#1}%
  \xintdeffloatfunc #2(x) :=
    (pflgamma((#3+(#4))/2)/(pflgamma((#3)/2)*pflgamma((#4)/2)))
    * ((#3)/(#4))^((#3)/2) * (x)^((#3)/2-1)
    * (1+(#3)*(x)/(#4))^(-((#3+(#4))/2)) ;%
  \IfStrEq{\pflloiprobastep}{}%
  {%
    \xdef\pflloiprobastep{\xintfloateval{%
      ((\useKV[GraphiqueTikzLoiProbasCont]{Fin})-(\useKV[GraphiqueTikzLoiProbasCont]{Debut}))/200}}%
  }{}%
  \xdef\tmpminloifischer{\xintfloateval{max(0.001,\useKV[GraphiqueTikzLoiProbasCont]{Debut})}}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \ifboolKV[GraphiqueTikzLoiProbasCont]{Trace}%
    {%
      \path[draw,pflcourbe,color={\useKV[GraphiqueTikzLoiProbasCont]{Couleur}},name path global=\pflloiprobaname]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),
          x={\tmpminloifischer}%
          ..[\pflloiprobastep]..%
          {\useKV[GraphiqueTikzLoiProbasCont]{Fin}},%
          {\useKV[GraphiqueTikzLoiProbasCont]{Fin}})
          \relax
        } ;
    }%
    {%
      \path[draw=none,pflcourbe,name path global=\pflloiprobaname]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),
          x={\tmpminloifischer}%
          ..[\pflloiprobastep]..%
          {\useKV[GraphiqueTikzLoiProbasCont]{Fin}},%
          {\useKV[GraphiqueTikzLoiProbasCont]{Fin}})
          \relax
        } ;
    }%
  \end{scope}
}

\NewDocumentCommand\TracerLoiFischer{ O{} m }{%
  %#1=options  #2=nom fonction xint (définie par \DefinirLoiFischer)
  \restoreKV[GraphiqueTikzLoiProbasCont]%
  \setKV[GraphiqueTikzLoiProbasCont]{#1}%
  \IfStrEq{\pflloiprobastep}{}%
  {%
    \xdef\pflloiprobastep{\xintfloateval{%
      ((\useKV[GraphiqueTikzLoiProbasCont]{Fin})-(\useKV[GraphiqueTikzLoiProbasCont]{Debut}))/200}}%
  }{}%
  \xdef\tmpminloifischer{\xintfloateval{max(0.001,\useKV[GraphiqueTikzLoiProbasCont]{Debut})}}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \draw[pflcourbe,color={\useKV[GraphiqueTikzLoiProbasCont]{Couleur}}]
      plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
        seq((x,#2),
        x={\tmpminloifischer}%
        ..[\pflloiprobastep]..%
        {\useKV[GraphiqueTikzLoiProbasCont]{Fin}},%
        {\useKV[GraphiqueTikzLoiProbasCont]{Fin}})
        \relax
      } ;
  \end{scope}
}
%alias intégrale--proba ;-)
\NewCommandCopy\RepresenterProbaContinue\TracerIntegrale

%====HISTO POISSON
% P(X=k) = e^(-λ) * λ^k / k!
% #3 = λ (paramètre), k = 0,1,2,...
\defKV[tkzHistoPoisson]{%
  CouleurTraits=\def\tkzGraphPoissonColTraits{#1},%
  Plage=\def\tkzGraphPoissonPlage{#1},%
  CouleurPlage=\def\tkzGraphPoissonColPlage{#1},%
  ClipX=\def\tkzGraphPoissonXminmax{#1},%
  CouleurNormale=\def\tkzGraphPoissonColNorm{#1},%
  Nmax=\def\tkzGraphPoissonNmax{#1},%
  Style=\def\tkzGraphPoissonStyle{#1}
}
\setKVdefault[tkzHistoPoisson]{%
  CouleurTraits=black,%
  Plage={},%
  CouleurPlage=black,%
  ClipX={},%
  AffNormale=false,%
  CouleurNormale=black,%
  Nmax={},%
  Style=histo
}
\NewDocumentCommand\TracerLoiPoisson{ O{} D<>{phipoisson} m }{%
  % #1=clés  #2=nom courbe normale approx  #3=λ
  \restoreKV[tkzHistoPoisson]%
  \setKV[tkzHistoPoisson]{#1}%
  \def\tkzGraphPoissonL{#3}%
  % Nmax auto si non fourni : on prend λ + 4√λ arrondi
  \IfStrEq{\tkzGraphPoissonNmax}{}%
    {\xdef\tkzGraphPoissonNmax{\xinttheexpr round(#3+4*sqrt(#3))\relax}}%
    {}%
  % bornes d'affichage
  \IfStrEq{\tkzGraphPoissonXminmax}{}%
    {%
      \xdef\tkzGraphPoissonXmin{0}%
      \xdef\tkzGraphPoissonXmax{\tkzGraphPoissonNmax}%
    }%
    {%
      \StrCut{\tkzGraphPoissonXminmax}{-}{\tkzGraphPoissonXmin}{\tkzGraphPoissonXmax}%
      \IfStrEq{\tkzGraphPoissonXmin}{*}{\xdef\tkzGraphPoissonXmin{0}}{}%
      \IfStrEq{\tkzGraphPoissonXmax}{*}{\xdef\tkzGraphPoissonXmax{\tkzGraphPoissonNmax}}{}%
    }%
  % bornes de coloriage
  \IfStrEq{\tkzGraphPoissonPlage}{}%
    {}%
    {%
      \StrCut{\tkzGraphPoissonPlage}{-}{\tkzGraphPoissonColorMin}{\tkzGraphPoissonColorMax}%
      \IfStrEq{\tkzGraphPoissonColorMin}{*}{\xdef\tkzGraphPoissonColorMin{\tkzGraphPoissonXmin}}{}%
      \IfStrEq{\tkzGraphPoissonColorMax}{*}{\xdef\tkzGraphPoissonColorMax{\tkzGraphPoissonXmax}}{}%
    }%
  % coloriage éventuel
  \IfStrEq{\tkzGraphPoissonPlage}{}%
    {}%
    {%
      \xintFor* ##1 in {\xintSeq{\tkzGraphPoissonColorMin}{\tkzGraphPoissonColorMax}}\do{%
        \xdef\tkztmpYYY{\xintfloateval{exp(-(#3))*(#3)^(##1)/factorial(##1)}}%
    %
    \IfStrEq{\tkzGraphPoissonStyle}{batons}%
    {%
      \draw[pflbarresprobas,color=\tkzGraphPoissonColPlage] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;

    }%
    {%
      \draw[draw=none,fill=\tkzGraphPoissonColPlage,fill opacity=0.5] ({##1-0.5},{\pflymin}) rectangle++ (1,{\tkztmpYYY-\pflymin}) ;
    }%
    %
      }%
    }%
  % tracé
  \xintFor* ##1 in {\xintSeq{\tkzGraphPoissonXmin}{\tkzGraphPoissonXmax}}\do{%
    \xdef\tkztmpYYY{\xintfloateval{exp(-(#3))*(#3)^(##1)/factorial(##1)}}%
  \IfStrEq{\tkzGraphPoissonStyle}{batons}%
  {%
    \IfStrEq{\tkzGraphPoissonPlage}{}%si plage, on colorie tout
      {%
        \draw[pflbarresprobas,color=\tkzGraphPoissonColTraits] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
      }%
      {%
        \xintifboolexpr{\tkzGraphPoissonColorMin <= ##1 <= \tkzGraphPoissonColorMax}%
          {}%
          {%
            \draw[pflbarresprobas,color=\tkzGraphPoissonColTraits] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
          }%
      }%
  }%
  {%
    \draw[pfltrait,color=\tkzGraphPoissonColTraits] ({##1-0.5},{\pflymin}) rectangle++ (1,{\tkztmpYYY-\pflymin}) ;
  }%
  }%
  % approximation normale : N(λ, √λ) (why not !)
  \ifboolKV[tkzHistoPoisson]{AffNormale}%
    {%
      \xdef\tkzMinNormHistoPoisson{\xintfloateval{\tkzGraphPoissonXmin-0.5}}%
      \xdef\tkzMaxNormHistoPoisson{\xintfloateval{\tkzGraphPoissonXmax+0.5}}%
      \xdef\tkzEsperNorm{\xintfloateval{#3}}%
      \xdef\tkzVarNorm{\xintfloateval{sqrt(#3)}}%
      \DefinirLoiNormale[Trace,Couleur=\tkzGraphPoissonColNorm,pflcourbe,%
        Debut=\tkzMinNormHistoPoisson,Fin=\tkzMaxNormHistoPoisson]%
        <#2>{\tkzEsperNorm}{\tkzVarNorm}%
    }%
    {}%
}

%====HISTO HYPERGÉOMÉTRIQUE
% P(X=k) = C(K,k)*C(N-K,n-k) / C(N,n)
% #3=N (population totale)  #4=K (succès dans population)  #5=n (taille tirage)
% k varie de max(0,n+K-N) à min(n,K)
\defKV[tkzHistoHyperGeo]{%
  CouleurTraits=\def\tkzGraphHyperColTraits{#1},%
  Plage=\def\tkzGraphHyperPlage{#1},%
  CouleurPlage=\def\tkzGraphHyperColPlage{#1},%
  ClipX=\def\tkzGraphHyperXminmax{#1},%
  CouleurNormale=\def\tkzGraphHyperColNorm{#1},%
  Style=\def\tkzGraphHyperStyle{#1}
}
\setKVdefault[tkzHistoHyperGeo]{%
  CouleurTraits=black,%
  Plage={},%
  CouleurPlage=black,%
  ClipX={},%
  AffNormale=false,%
  CouleurNormale=black,%
  Style=histo
}
\NewDocumentCommand\TracerLoiHyperGeo{ O{} D<>{phihypergeo} m m m }{%
  % #1=clés  #2=nom courbe normale approx  #3=N  #4=K  #5=n
  \restoreKV[tkzHistoHyperGeo]%
  \setKV[tkzHistoHyperGeo]{#1}%
  % bornes naturelles de k
  \xdef\tkzGraphHyperKmin{\xinttheexpr max(0,#5+#4-#3)\relax}%
  \xdef\tkzGraphHyperKmax{\xinttheexpr min(#5,#4)\relax}%
  % bornes d'affichage
  \IfStrEq{\tkzGraphHyperXminmax}{}%
    {%
      \xdef\tkzGraphHyperXmin{\tkzGraphHyperKmin}%
      \xdef\tkzGraphHyperXmax{\tkzGraphHyperKmax}%
    }%
    {%
      \StrCut{\tkzGraphHyperXminmax}{-}{\tkzGraphHyperXmin}{\tkzGraphHyperXmax}%
      \IfStrEq{\tkzGraphHyperXmin}{*}{\xdef\tkzGraphHyperXmin{\tkzGraphHyperKmin}}{}%
      \IfStrEq{\tkzGraphHyperXmax}{*}{\xdef\tkzGraphHyperXmax{\tkzGraphHyperKmax}}{}%
    }%
  % bornes de coloriage
  \IfStrEq{\tkzGraphHyperPlage}{}%
    {}%
    {%
      \StrCut{\tkzGraphHyperPlage}{-}{\tkzGraphHyperColorMin}{\tkzGraphHyperColorMax}%
      \IfStrEq{\tkzGraphHyperColorMin}{*}{\xdef\tkzGraphHyperColorMin{\tkzGraphHyperXmin}}{}%
      \IfStrEq{\tkzGraphHyperColorMax}{*}{\xdef\tkzGraphHyperColorMax{\tkzGraphHyperXmax}}{}%
    }%
  % coloriage éventuel
  \IfStrEq{\tkzGraphHyperPlage}{}%
    {}%
    {%
      \xintFor* ##1 in {\xintSeq{\tkzGraphHyperColorMin}{\tkzGraphHyperColorMax}}\do{%
        \xdef\tkztmpYYY{\xintfloateval{binomial(#4,##1)*binomial(#3-(#4),#5-(##1))/binomial(#3,#5)}}%
    \IfStrEq{\tkzGraphHyperStyle}{batons}%
      {%
        \draw[pflbarresprobas,color=\tkzGraphHyperColPlage] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
      }%
      {%
        \draw[draw=none,fill=\tkzGraphHyperColPlage,fill opacity=0.5] ({##1-0.5},{\pflymin}) rectangle++ (1,{\tkztmpYYY-\pflymin}) ;
      }%
      }%
    }%
  % tracé
  \xintFor* ##1 in {\xintSeq{\tkzGraphHyperXmin}{\tkzGraphHyperXmax}}\do{%
    \xdef\tkztmpYYY{\xintfloateval{binomial(#4,##1)*binomial(#3-(#4),#5-(##1))/binomial(#3,#5)}}%
  %
  \IfStrEq{\tkzGraphHyperStyle}{batons}%
  {%
    \IfStrEq{\tkzGraphHyperPlage}{}%si plage, on colorie tout
      {%
        \draw[pflbarresprobas,color=\tkzGraphHyperColTraits] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
      }%
      {%
        \xintifboolexpr{\tkzGraphHyperColorMin <= ##1 <= \tkzGraphHyperColorMax}%
          {}%
          {%
            \draw[pflbarresprobas,color=\tkzGraphHyperColTraits] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
          }%
      }%
  }%
  {%
    \draw[pfltrait,color=\tkzGraphHyperColTraits] ({##1-0.5},{\pflymin}) rectangle++ (1,{\tkztmpYYY-\pflymin}) ;
  }%
  %
  }%
  % approximation normale : N(nK/N, √(nK(N-K)(N-n)/(N²(N-1))))
  \ifboolKV[tkzHistoHyperGeo]{AffNormale}%
    {%
      \xdef\tkzMinNormHistoHyper{\xintfloateval{\tkzGraphHyperXmin-0.5}}%
      \xdef\tkzMaxNormHistoHyper{\xintfloateval{\tkzGraphHyperXmax+0.5}}%
      \xdef\tkzEsperNorm{\xintfloateval{(#5)*(#4)/(#3)}}%
      \xdef\tkzVarNorm{\xintfloateval{sqrt((#5)*(#4)*((#3)-(#4))*((#3)-(#5))/((#3)^2*((#3)-1)))}}%
      \DefinirLoiNormale[Trace,Couleur=\tkzGraphHyperColNorm,pflcourbe,%
        Debut=\tkzMinNormHistoHyper,Fin=\tkzMaxNormHistoHyper]%
        <#2>{\tkzEsperNorm}{\tkzVarNorm}%
    }%
    {}%
}

%====HISTO LOI GÉOMÉTRIQUE
% P(X=k) = (1-p)^(k-1) * p  pour k = 1, 2, 3, ...
% #3 = p (probabilité de succès)
\defKV[tkzHistoGeo]{%
  CouleurTraits=\def\tkzGraphGeoColTraits{#1},%
  Plage=\def\tkzGraphGeoPlage{#1},%
  CouleurPlage=\def\tkzGraphGeoColPlage{#1},%
  ClipX=\def\tkzGraphGeoXminmax{#1},%
  Nmax=\def\tkzGraphGeoNmax{#1},%
  Style=\def\tkzGraphGeoStyle{#1},%
  CouleurExpo=\def\tkzGraphGeoColExpo{#1}
}
\setKVdefault[tkzHistoGeo]{%
  CouleurTraits=black,%
  Plage={},%
  CouleurPlage=black,%
  ClipX={},%
  Nmax={},%
  Style=histo,%
  AffExpo=false,%
  CouleurExpo=black
}
\NewDocumentCommand\TracerLoiGeo{ O{} m }{%
  % #1=clés  #2=p
  \restoreKV[tkzHistoGeo]%
  \setKV[tkzHistoGeo]{#1}%
  % Nmax auto si non fourni : 1/p + 4*sqrt((1-p)/p²)
  \IfStrEq{\tkzGraphGeoNmax}{}%
    {\xdef\tkzGraphGeoNmax{\xinttheexpr round(1/(#2)+4*sqrt((1-(#2))/(#2)^2))\relax}}%
    {}%
  % bornes d'affichage
  \IfStrEq{\tkzGraphGeoXminmax}{}%
    {%
      \xdef\tkzGraphGeoXmin{1}%
      \xdef\tkzGraphGeoXmax{\tkzGraphGeoNmax}%
    }%
    {%
      \StrCut{\tkzGraphGeoXminmax}{-}{\tkzGraphGeoXmin}{\tkzGraphGeoXmax}%
      \IfStrEq{\tkzGraphGeoXmin}{*}{\xdef\tkzGraphGeoXmin{1}}{}%
      \IfStrEq{\tkzGraphGeoXmax}{*}{\xdef\tkzGraphGeoXmax{\tkzGraphGeoNmax}}{}%
    }%
  % bornes de coloriage
  \IfStrEq{\tkzGraphGeoPlage}{}%
    {}%
    {%
      \StrCut{\tkzGraphGeoPlage}{-}{\tkzGraphGeoColorMin}{\tkzGraphGeoColorMax}%
      \IfStrEq{\tkzGraphGeoColorMin}{*}{\xdef\tkzGraphGeoColorMin{\tkzGraphGeoXmin}}{}%
      \IfStrEq{\tkzGraphGeoColorMax}{*}{\xdef\tkzGraphGeoColorMax{\tkzGraphGeoXmax}}{}%
    }%
  % coloriage éventuel
  \IfStrEq{\tkzGraphGeoPlage}{}%
    {}%
    {%
      \xintFor* ##1 in {\xintSeq{\tkzGraphGeoColorMin}{\tkzGraphGeoColorMax}}\do{%
        \xdef\tkztmpYYY{\xintfloateval{(1-(#2))^(##1-1)*(#2)}}%
        \IfStrEq{\tkzGraphGeoStyle}{batons}%
        {%
          \draw[pflbarresprobas,color=\tkzGraphGeoColPlage] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
        }%
        {%
          \draw[draw=none,fill=\tkzGraphGeoColPlage,fill opacity=0.5] ({##1-0.5},{\pflymin}) rectangle++ (1,{\tkztmpYYY-\pflymin}) ;
        }%
      }%
    }%
  % tracé
  \xintFor* ##1 in {\xintSeq{\tkzGraphGeoXmin}{\tkzGraphGeoXmax}}\do{%
    \xdef\tkztmpYYY{\xintfloateval{(1-(#2))^(##1-1)*(#2)}}%
    \IfStrEq{\tkzGraphGeoStyle}{batons}%
    {%
      \IfStrEq{\tkzGraphGeoPlage}{}%
        {%
          \draw[pflbarresprobas,color=\tkzGraphGeoColTraits] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
        }%
        {%
          \xintifboolexpr{\tkzGraphGeoColorMin <= ##1 <= \tkzGraphGeoColorMax}%
            {}%
            {%
              \draw[pflbarresprobas,color=\tkzGraphGeoColTraits] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
            }%
        }%
    }%
    {%
      \draw[pfltrait,color=\tkzGraphGeoColTraits] ({##1-0.5},{\pflymin}) rectangle++ (1,{\tkztmpYYY-\pflymin}) ;
    }%
  }%
  \ifboolKV[tkzHistoGeo]{AffExpo}%
  {%
    \xdef\tkzMinExpoGeo{\xintfloateval{\tkzGraphGeoXmin-0.5}}%
    \xdef\tkzMaxExpoGeo{\xintfloateval{\tkzGraphGeoXmax+0.5}}%
    \xdef\tkzExpoParam{\xintfloateval{-ln(1-(#2))}}%
    \DefinirLoiExponentielle[Trace,Couleur=\tkzGraphGeoColExpo,pflcourbe,%
      Debut=\tkzMinExpoGeo,Fin=\tkzMaxExpoGeo]%
      <phiexpo>{\tkzExpoParam}%
  }%
  {}%
}

%====HISTOBINOM (mis à jour : CouleurTraits + Style)
\defKV[tkzHistoBinom]{%
  CouleurTraits=\def\tkzGraphBinomColTraits{#1},%
  Plage=\def\tkzGraphBinomPlage{#1},%
  CouleurPlage=\def\tkzGraphBimomColPlage{#1},%
  ClipX=\def\tkzGraphBinomXminmax{#1},%
  CouleurNormale=\def\tkzGraphBinomColNorm{#1},%
  Style=\def\tkzGraphBinomStyle{#1}
}
\setKVdefault[tkzHistoBinom]{%
  CouleurTraits=black,%
  Plage={},%
  CouleurPlage=black,%
  ClipX={},%
  AffNormale=false,%
  CouleurNormale=black,%
  Style=histo%
}
\NewDocumentCommand\TracerHistoBinomiale{ O{} D<>{phi} m m }{%
  \restoreKV[tkzHistoBinom]%
  \setKV[tkzHistoBinom]{#1}%
  \def\tkzGraphBinomN{#3}%
  \def\tkzGraphBinomP{#4}%
  % bornes d'affichage
  \IfStrEq{\tkzGraphBinomXminmax}{}%
    {%
      \xdef\tkzGraphBinomXmin{0}%
      \xdef\tkzGraphBinomXmax{\tkzGraphBinomN}%
    }%
    {%
      \StrCut{\tkzGraphBinomXminmax}{-}{\tkzGraphBinomXmin}{\tkzGraphBinomXmax}%
      \IfStrEq{\tkzGraphBinomXmin}{*}{\xdef\tkzGraphBinomXmin{0}}{}%
      \IfStrEq{\tkzGraphBinomXmax}{*}{\xdef\tkzGraphBinomXmax{\tkzGraphBinomN}}{}%
    }%
  % bornes de coloriage
  \IfStrEq{\tkzGraphBinomPlage}{}%
    {}%
    {%
      \StrCut{\tkzGraphBinomPlage}{-}{\tkzGraphBinomColorMin}{\tkzGraphBinomColorMax}%
      \IfStrEq{\tkzGraphBinomColorMin}{*}{\xdef\tkzGraphBinomColorMin{\tkzGraphBinomXmin}}{}%
      \IfStrEq{\tkzGraphBinomColorMax}{*}{\xdef\tkzGraphBinomColorMax{\tkzGraphBinomXmax}}{}%
    }%
  % coloriage éventuel
  \IfStrEq{\tkzGraphBinomPlage}{}%
    {}%
    {%
      \xintFor* ##1 in {\xintSeq{\tkzGraphBinomColorMin}{\tkzGraphBinomColorMax}}\do{%
        \xdef\tkztmpYYY{\xintfloateval{binomial(\tkzGraphBinomN,##1)*(\tkzGraphBinomP)^(##1)*(1-(\tkzGraphBinomP))^((\tkzGraphBinomN)-(##1))}}%
        \IfStrEq{\tkzGraphBinomStyle}{batons}%
        {%
          \draw[pflbarresprobas,color=\tkzGraphBimomColPlage] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
        }%
        {%
          \draw[draw=none,fill=\tkzGraphBimomColPlage,fill opacity=0.5] ({##1-0.5},{\pflymin}) rectangle++ (1,{\tkztmpYYY-\pflymin}) ;
        }%
      }%
    }%
  % tracé
  \xintFor* ##1 in {\xintSeq{\tkzGraphBinomXmin}{\tkzGraphBinomXmax}}\do{%
    \xdef\tkztmpYYY{\xintfloateval{binomial(\tkzGraphBinomN,##1)*(\tkzGraphBinomP)^(##1)*(1-(\tkzGraphBinomP))^((\tkzGraphBinomN)-(##1))}}%
    \IfStrEq{\tkzGraphBinomStyle}{batons}%
    {%
      \IfStrEq{\tkzGraphBinomPlage}{}%
        {%
          \draw[pflbarresprobas,color=\tkzGraphBinomColTraits] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
        }%
        {%
          \xintifboolexpr{\tkzGraphBinomColorMin <= ##1 <= \tkzGraphBinomColorMax}%
            {}%
            {%
              \draw[pflbarresprobas,color=\tkzGraphBinomColTraits] ({##1},{\pflymin}) -- ({##1},{\tkztmpYYY-\pflymin}) ;
            }%
        }%
    }%
    {%
      \draw[pfltrait,color=\tkzGraphBinomColTraits] ({##1-0.5},{\pflymin}) rectangle++ (1,{\tkztmpYYY-\pflymin}) ;
    }%
  }%
  % approximation normale
  \ifboolKV[tkzHistoBinom]{AffNormale}%
    {%
      \xdef\tkzMinNormHistoBinom{\xintfloateval{\tkzGraphBinomXmin-0.5}}%
      \xdef\tkzMaxNormHistoBinom{\xintfloateval{\tkzGraphBinomXmax+0.5}}%
      \xdef\tkzEsperNorm{\xintfloateval{(#3)*(#4)}}%
      \xdef\tkzVarNorm{\xintfloateval{sqrt((#3)*(#4)*(1-(#4)))}}%
      \DefinirLoiNormale[Trace,Couleur=\tkzGraphBinomColNorm,pflcourbe,%
        Debut=\tkzMinNormHistoBinom,Fin=\tkzMaxNormHistoBinom]%
        <#2>{\tkzEsperNorm}{\tkzVarNorm}%
    }%
    {}%
}
\NewCommandCopy\TracerLoiBinomiale\TracerHistoBinomiale

%====RACINES ET LISTE D'ABSCISSES
\NewDocumentCommand\TrouverRacines{ O{} m D<>{\myracines} }{%
  % wrapper de \TrouverAntecedents avec y=0 (zéros de la fonction)
  % #1 = clés (Nom, Aff, Traits, Couleur, AffDroite, Style)
  % #2 = nom de la courbe
  % #3 = macro stockant le nb de racines (défaut \myracines)
  \TrouverAntecedents[#1]{#2}{0}<#3>%
}

\NewDocumentCommand\PlacerRacines{ O{} m }{%
  % wrapper de \PlacerAntecedents avec y=Oy (zéros de la fonction)
  % #1 = clés (Traits, Couleurs, Nom, Style)
  % #2 = nom de la courbe
  \PlacerAntecedents[#1]{#2}{0}%
}

\NewDocumentCommand\CreerListeAbscisses{ m m O{mylistabs} }{%
  % #1 = préfixe des nœuds (ex: R, S, A...) sans \
  % #2 = nb de nœuds
  % #3 = nom de la macro de sortie (ex: mesracines) sans \
  \xdef\tkzgtmplistabsc{}%
  \xintifboolexpr{#2 == 0}{}%
    {%
      \foreach \i in {1,...,#2}{%
        \RecupererAbscisse{(#1-\i)}[\tmpabsi]%
        \xintifboolexpr{\i == 1}%
          {\xdef\tkzgtmplistabsc{\tmpabsi}}%
          {\xdef\tkzgtmplistabsc{\tkzgtmplistabsc,\tmpabsi}}%
      }%
    }%
  \expandafter\xdef\csname#3\endcsname{\tkzgtmplistabsc}%
}

%====GÉNÉRATION DE FONCTIONS HORS ENVIRONNEMENT
\NewDocumentCommand\GenererFonction{ s D<>{f} m }{%
  % #2 = nom fonction xint
  % #3 = expression
  \IfBooleanT{#1}{\xintglobaldefstrue}%
  \xintdeffloatfunc #2(x) = #3 ;%
  \IfBooleanT{#1}{\xintglobaldefsfalse}%
}

\NewDocumentCommand\GenererFamilleFonctions{ s D<>{f} m m m }{%
  % #2 = nom famille (namespace)
  % #3 = expression avec n comme paramètre xint
  % #4 = indice début
  % #5 = indice fin
  \IfBooleanT{#1}{\xintglobaldefstrue}%
  % 1/ fonction à 2 variables
  \xintdeffloatfunc #2(x,n) = #3 ;%
  % 2/ spécialisation → fonctions à 1 variable
  \xintFor* ##1 in {\xintSeq{#4}{#5}} \do {%
    \xintdeffloatfunc #2_##1(x) = #2(x,##1) ;%
  }%
  \IfBooleanT{#1}{\xintglobaldefsfalse}%
  % stockage
  \expandafter\xdef\csname pflnb@#2\endcsname{\inteval{(#5)-(#4)+1}}%
  \expandafter\xdef\csname pfldeb@#2\endcsname{#4}%
  \expandafter\xdef\csname pflfin@#2\endcsname{#5}%
}

%====FAMILLES DE COURBES (indexées sur N)
\defKV[GraphiqueTikzFamille]{%
  Couleur=\def\pflfamcouleur{#1},%
  Couleurs=\def\pflfamcouleurs{#1},%
  CouleurBase=\def\pflfamcouleurbase{#1},%
  Debut=\def\pflfamdebut{#1},%
  Fin=\def\pflfamfin{#1},%
  Pas=\def\pflfampas{#1}
}
\setKVdefault[GraphiqueTikzFamille]{%
  Couleur=black,%
  Couleurs={},%
  CouleurBase={},%
  Debut={\pflxmin},%
  Fin={\pflxmax},%
  Pas={},%
  Trace=false,%
  Clip=true,%
  RestreindreY=false,%
  DefGlobale=false
}

\NewDocumentCommand\DefinirFamilleCourbes{ O{} D<>{f} m m m }{%
  \restoreKV[GraphiqueTikzFamille]%
  \setKV[GraphiqueTikzFamille]{#1}%
  % offsets
  \xdef\pfloffsetV{\xintfloateval{((\pflymax)-(\pflymin))/20}}%
  \xdef\pflMinoffsetV{\xintfloateval{(\pflymin)-(\pfloffsetV)}}%
  \xdef\pflMaxoffsetV{\xintfloateval{(\pflymax)+(\pfloffsetV)}}%
  % nb courbes
  \xdef\tmpnbfam{\inteval{(#5)-(#4)+1}}%
  % lecture couleurs hors boucle
  \IfEq{\pflfamcouleurs}{}%
    {}%
    {\setsepchar{,}\readlist*\tmplistecouleurs{\pflfamcouleurs}}%
  % 1/ fonction 2 variables
  \ifboolKV[GraphiqueTikzFamille]{DefGlobale}{\xintglobaldefstrue}{}%
  \xintdeffloatfunc #2(x,n) = #3 ;%
  % 2/ boucle
  \xdef\tmpi{0}%
  \xintFor* ##1 in {\xintSeq{#4}{#5}} \do {%
    \xdef\tmpi{\inteval{\tmpi+1}}%
    % fonction xint à 1 variable
    \xintdeffloatfunc #2_##1(x) = #2(x,##1) ;%
    % couleur courante
    \IfEq{\pflfamcouleurs}{}%
      {%
        \IfEq{\pflfamcouleurbase}{}%
          {\def\tmpcoulcourante{\pflfamcouleur}}%
          {%
            \xdef\tmpopac{\xintfloateval{%
              round(30+\tmpi/\tmpnbfam*70,0)}}%
            \edef\tmpcoulcourante{\pflfamcouleurbase!\tmpopac}%
          }%
      }%
      {\itemtomacro\tmplistecouleurs[\tmpi]\tmpcoulcourante}%
    % nom du name path courant
    \edef\pflnamecurve{famille-#2-\tmpi}%
    % pas
    \xdef\pflstepcurve{\xintfloateval{%
      ((\pflfamfin)-(\pflfamdebut))/100}}%
    % bifurcation VI/noVI
    \IfStrEq{\pflvalsinterdites}{}%
      {%si pas de VI
        \ifboolKV[GraphiqueTikzFamille]{Clip}%
          {\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}%
        \ifboolKV[GraphiqueTikzFamille]{Trace}%
          {%
            \ifboolKV[GraphiqueTikzFamille]{RestreindreY}%
              {%
                \path[draw,pflcourbe,\pflstylecurve,color=\tmpcoulcourante,%
                  name path global=\pflnamecurve]
                  plot[smooth] coordinates {%
                  \xintthecoords\xintfloatexpr
                  seq((x,min(max(#2_##1(x),\pflMinoffsetV),\pflMaxoffsetV)),%
                    x={\pflfamdebut}..[\pflstepcurve]..{\pflfamfin},%
                    {\pflfamfin})
                  \relax
                };%
              }%
              {%
                \path[draw,pflcourbe,\pflstylecurve,color=\tmpcoulcourante,%
                  name path global=\pflnamecurve]
                  plot[smooth] coordinates {%
                  \xintthecoords\xintfloatexpr
                  seq((x,#2_##1(x)),%
                    x={\pflfamdebut}..[\pflstepcurve]..{\pflfamfin},%
                    {\pflfamfin})
                  \relax
                };%
              }%
          }%
          {%
            \ifboolKV[GraphiqueTikzFamille]{RestreindreY}%
              {%
                \path[draw=none,pflcourbe,\pflstylecurve,color=\tmpcoulcourante,%
                  name path global=\pflnamecurve]
                  plot[smooth] coordinates {%
                  \xintthecoords\xintfloatexpr
                  seq((x,min(max(#2_##1(x),\pflMinoffsetV),\pflMaxoffsetV)),%
                    x={\pflfamdebut}..[\pflstepcurve]..{\pflfamfin},%
                    {\pflfamfin})
                  \relax
                };%
              }%
              {%
                \path[draw=none,pflcourbe,\pflstylecurve,color=\tmpcoulcourante,%
                  name path global=\pflnamecurve]
                  plot[smooth] coordinates {%
                  \xintthecoords\xintfloatexpr
                  seq((x,#2_##1(x)),%
                    x={\pflfamdebut}..[\pflstepcurve]..{\pflfamfin},%
                    {\pflfamfin})
                  \relax
                };%
              }%
          }%
        \ifboolKV[GraphiqueTikzFamille]{Clip}{\end{scope}}{}%
      }%
      {%sinon, VI
        \edef\pflvalsinterditesexp{\pflvalsinterdites}%
        \xdef\pflstepcurve{\xintfloateval{%
          ((\pflfamfin)-(\pflfamdebut))/250}}%
        \xdef\pfllistebornes{\pflfamdebut}%
        \foreach \i in \pflvalsinterditesexp{%
          \xdef\pfllistebornes{\pfllistebornes,%
            \xintfloateval{\i-(\pflstepcurve)},%
            \xintfloateval{\i+(\pflstepcurve)}}%
        }%
        \xdef\pfllistebornes{\pfllistebornes,\pflfamfin}%
        \setsepchar{,}%
        \readlist*\tkzintlistebornes{\pfllistebornes}%
        \xdef\tkzgrphnbbranches{\fpeval{\tkzintlisteborneslen/2}}%
        \ifboolKV[GraphiqueTikzFamille]{Clip}%
          {\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}%
        \ifboolKV[GraphiqueTikzFamille]{Trace}%
          {%
            \path[draw,pflcourbe,\pflstylecurve,color=\tmpcoulcourante,%
              name path global=\pflnamecurve]
              \foreach \ib [evaluate=\ib as \ibdeb using {int(2*\ib-1)},%
                evaluate=\ib as \ibfin using {int(2*\ib)}]%
                in {1,...,\tkzgrphnbbranches}{%
                plot[smooth] coordinates {%
                  \xintthecoords\xintfloatexpr
                  seq((x,min(max(#2_##1(x),\pflMinoffsetV),\pflMaxoffsetV)),%
                    x={\tkzintlistebornes[\ibdeb]}..[\pflstepcurve]..%
                    {\tkzintlistebornes[\ibfin]},%
                    {\tkzintlistebornes[\ibfin]})
                  \relax}
              } ;%
          }%
          {%
            \path[draw=none,pflcourbe,\pflstylecurve,color=\tmpcoulcourante,%
              name path global=\pflnamecurve]
              \foreach \ib [evaluate=\ib as \ibdeb using {int(2*\ib-1)},%
                evaluate=\ib as \ibfin using {int(2*\ib)}]%
                in {1,...,\tkzgrphnbbranches}{%
                plot[smooth] coordinates {%
                  \xintthecoords\xintfloatexpr
                  seq((x,min(max(#2_##1(x),\pflMinoffsetV),\pflMaxoffsetV)),%
                    x={\tkzintlistebornes[\ibdeb]}..[\pflstepcurve]..%
                    {\tkzintlistebornes[\ibfin]},%
                    {\tkzintlistebornes[\ibfin]})
                  \relax}
              } ;%
          }%
        \ifboolKV[GraphiqueTikzFamille]{Clip}{\end{scope}}{}%
      }%
  }%
  \ifboolKV[GraphiqueTikzFamille]{DefGlobale}{\xintglobaldefsfalse}{}%
  % stockage
  \expandafter\xdef\csname pflnb@#2\endcsname{\tmpnbfam}%
  \expandafter\xdef\csname pfldeb@#2\endcsname{#4}%
  \expandafter\xdef\csname pflfin@#2\endcsname{#5}%
}

\NewDocumentCommand\TracerFamilleCourbes{ O{} m }{%
  \restoreKV[GraphiqueTikzFamille]%
  \setKV[GraphiqueTikzFamille]{#1}%
  \edef\tmpdeb{\csname pfldeb@#2\endcsname}%
  \edef\tmpfin{\csname pflfin@#2\endcsname}%
  \edef\tmpnb{\csname pflnb@#2\endcsname}%
  % offsets
  \xdef\pfloffsetV{\xintfloateval{((\pflymax)-(\pflymin))/20}}%
  \xdef\pflMinoffsetV{\xintfloateval{(\pflymin)-(\pfloffsetV)}}%
  \xdef\pflMaxoffsetV{\xintfloateval{(\pflymax)+(\pfloffsetV)}}%
  % lecture couleurs hors boucle
  \IfEq{\pflfamcouleurs}{}%
    {}%
    {\setsepchar{,}\readlist*\tmplistecouleurs{\pflfamcouleurs}}%
  % boucle
  \xdef\tmpi{0}%
  \xintFor* ##1 in {\xintSeq{\tmpdeb}{\tmpfin}} \do {%
    \xdef\tmpi{\inteval{\tmpi+1}}%
    % couleur courante
    \IfEq{\pflfamcouleurs}{}%
      {%
        \IfEq{\pflfamcouleurbase}{}%
          {\def\tmpcoulcourante{\pflfamcouleur}}%
          {%
            \xdef\tmpopac{\xintfloateval{%
              round(30+\tmpi/\tmpnb*70,0)}}%
            \edef\tmpcoulcourante{\pflfamcouleurbase!\tmpopac}%
          }%
      }%
      {\itemtomacro\tmplistecouleurs[\tmpi]\tmpcoulcourante}%
    % pas
    \xdef\pflstepcurve{\xintfloateval{%
      ((\pflfamfin)-(\pflfamdebut))/100}}%
    % bifurcation VI/noVI
    \IfStrEq{\pflvalsinterdites}{}%
      {%
        \ifboolKV[GraphiqueTikzFamille]{Clip}%
          {\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}%
        \ifboolKV[GraphiqueTikzFamille]{RestreindreY}%
          {%
            \draw[pflcourbe,\pflstylecurve,color=\tmpcoulcourante]
              plot[smooth] coordinates {%
              \xintthecoords\xintfloatexpr
              seq((x,min(max(#2_##1(x),\pflMinoffsetV),\pflMaxoffsetV)),%
                x={\pflfamdebut}..[\pflstepcurve]..{\pflfamfin},%
                {\pflfamfin})
              \relax
            };%
          }%
          {%
            \draw[pflcourbe,\pflstylecurve,color=\tmpcoulcourante]
              plot[smooth] coordinates {%
              \xintthecoords\xintfloatexpr
              seq((x,#2_##1(x)),%
                x={\pflfamdebut}..[\pflstepcurve]..{\pflfamfin},%
                {\pflfamfin})
              \relax
            };%
          }%
        \ifboolKV[GraphiqueTikzFamille]{Clip}{\end{scope}}{}%
      }%
      {%sinon VI
        \edef\pflvalsinterditesexp{\pflvalsinterdites}%
        \xdef\pflstepcurve{\xintfloateval{%
          ((\pflfamfin)-(\pflfamdebut))/250}}%
        \xdef\pfllistebornes{\pflfamdebut}%
        \foreach \i in \pflvalsinterditesexp {%
          \xdef\pfllistebornes{\pfllistebornes,%
            \xintfloateval{\i-(\pflstepcurve)},%
            \xintfloateval{\i+(\pflstepcurve)}}%
        }%
        \xdef\pfllistebornes{\pfllistebornes,\pflfamfin}%
        \setsepchar{,}%
        \readlist*\tkzintlistebornes{\pfllistebornes}%
        \xdef\tkzgrphnbbranches{\fpeval{\tkzintlisteborneslen/2}}%
        \ifboolKV[GraphiqueTikzFamille]{Clip}%
          {\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}%
        \draw[pflcourbe,\pflstylecurve,color=\tmpcoulcourante]
          \foreach \ib [evaluate=\ib as \ibdeb using {int(2*\ib-1)},%
            evaluate=\ib as \ibfin using {int(2*\ib)}]%
            in {1,...,\tkzgrphnbbranches}{%
            plot[smooth] coordinates {%
              \xintthecoords\xintfloatexpr
              seq((x,min(max(#2_##1(x),\pflMinoffsetV),\pflMaxoffsetV)),%
                x={\tkzintlistebornes[\ibdeb]}..[\pflstepcurve]..%
                {\tkzintlistebornes[\ibfin]},%
                {\tkzintlistebornes[\ibfin]})
              \relax}
          } ;%
        \ifboolKV[GraphiqueTikzFamille]{Clip}{\end{scope}}{}%
      }%
  }%
}

%====SEMILOG - LOGLOG
\NewDocumentEnvironment{GraphiqueTikzSemiLog}{ O{} D<>{} }%
%1 = options tikz, classiques
%2 = clés spécifiques
{%
  \restoreKV[GraphiqueTikz]%
  \setKV[GraphiqueTikz]{#2}%
  %l'environnement
  \IfStrEq{\pflgraphdims}{}%
    {%
      \begin{tikzpicture}[#1]%
    }%
    {%
      \StrCut{\pflgraphdims}{/}{\pfltmpwidth}{\pfltmpheight}%
      \setlength\pflglobalwidth{\fpeval{(\pfltmpwidth)/(\pflxmaxtmp-\pflxmintmp)}pt}%\the\pflglobalwidth+%
      \setlength\pflglobalheight{\fpeval{(\pfltmpheight)/(\pflymaxtmp-\pflymintmp)}pt}%\the\pflglobalheight%
      \begin{tikzpicture}[x=\pflglobalwidth,y=\pflglobalheight,Xmin=\pflxmintmp,Xmax=\pflxmaxtmp,Ymin=\pflymintmp,Ymax=\pflymaxtmp,#1]%
    }%
    %translationY
    % valeurs réelles → exposants
    \xdef\pflslogexpomin{\xintfloateval{log10(\pflymin)}}%
    \xdef\pflslogexpomax{\xintfloateval{log10(\pflymax)}}%
    % nb décades
    \xdef\pflymax{\xintfloateval{log10(\pflymax)-log10(\pflymin)}}%
    \xdef\pflymin{0}%
    \xdef\pflOy{0}%
    %thèmes personnalisés
    \IfStrEqCase{\pflgraphthem}{%
      {standard}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepdefault!75}}\tikzset{pflgrillei/.style={line width=\pflthickgrids,pflgrillesdefault}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleidefault}}}%
      {gris}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepgray!75}}\tikzset{pflgrillei/.style={line width\pflthickgrids,pflgrillesgray}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleigray}}}%
      {bleu}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepblue!75}}\tikzset{pflgrillei/.style={line width=\pflthickgrids,pflgrillesblue}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleiblue}}}%
      {vert}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepgreen!75}}\tikzset{pflgrillei/.style={line width=\pflthickgrids,pflgrillesgreen}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleigreen}}}%
      {chaud}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepwarm!75}}\tikzset{pflgrillei/.style={line width=\pflthickgrids,pflgrilleswarm}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleiwarm}}}%
      {contraste}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepcontrast!75}}\tikzset{pflgrillei/.style={line width=\pflthickgrids,pflgrillescontrast}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleicontrast}}}%
    }%
    %unités x/y pour des calculs de coordonnées
    \TikZUnites
    %noeuds fenêtre + axes
    \IfStrEq{\pflgraphnom}{}%
      {%
        \coordinate (graphe-ne) at ({\pflxmax},{\pflymax}) ;
        \coordinate (graphe-nw) at ({\pflxmin},{\pflymax}) ;
        \coordinate (graphe-se) at ({\pflxmax},{\pflymin}) ;
        \coordinate (graphe-sw) at ({\pflxmin},{\pflymin}) ;
        \coordinate (graphe-n) at ($(graphe-ne)!0.5!(graphe-nw)$) ;
        \coordinate (graphe-e) at ($(graphe-ne)!0.5!(graphe-se)$) ;
        \coordinate (graphe-s) at ($(graphe-se)!0.5!(graphe-sw)$) ;
        \coordinate (graphe-w) at ($(graphe-sw)!0.5!(graphe-nw)$) ;
        \coordinate (graphe-c) at ($(graphe-sw)!0.5!(graphe-ne)$) ;
        \coordinate (axeox-w) at ({\pflxmin},{\pflOy}) ;
        \coordinate (axeox-e) at ({\pflxmax},{\pflOy}) ;
        \coordinate (axeoy-s) at ({\pflOx},{\pflymin}) ;
        \coordinate (axeoy-n) at ({\pflOx},{\pflymax}) ;
        \coordinate (axes-orig) at ({\pflOx},{\pflOy}) ;
      }%
      {%
        \coordinate (\pflgraphnom-graphe-ne) at ({\pflxmax},{\pflymax}) ;
        \coordinate (\pflgraphnom-graphe-nw) at ({\pflxmin},{\pflymax}) ;
        \coordinate (\pflgraphnom-graphe-se) at ({\pflxmax},{\pflymin}) ;
        \coordinate (\pflgraphnom-graphe-sw) at ({\pflxmin},{\pflymin}) ;
        \coordinate (\pflgraphnom-graphe-n) at ($(\pflgraphnom-graphe-ne)!0.5!(\pflgraphnom-graphe-nw)$) ;
        \coordinate (\pflgraphnom-graphe-e) at ($(\pflgraphnom-graphe-ne)!0.5!(\pflgraphnom-graphe-se)$) ;
        \coordinate (\pflgraphnom-graphe-s) at ($(\pflgraphnom-graphe-se)!0.5!(\pflgraphnom-graphe-sw)$) ;
        \coordinate (\pflgraphnom-graphe-w) at ($(\pflgraphnom-graphe-sw)!0.5!(\pflgraphnom-graphe-nw)$) ;
        \coordinate (\pflgraphnom-graphe-c) at ($(\pflgraphnom-graphe-sw)!0.5!(\pflgraphnom-graphe-ne)$) ;
        \coordinate (\pflgraphnom-axeox-w) at ({\pflxmin},{\pflOy}) ;
        \coordinate (\pflgraphnom-axeox-e) at ({\pflxmax},{\pflOy}) ;
        \coordinate (\pflgraphnom-axeoy-s) at ({\pflOx},{\pflymin}) ;
        \coordinate (\pflgraphnom-axeoy-n) at ({\pflOx},{\pflymax}) ;
        \coordinate (\pflgraphnom-axes-orig) at ({\pflOx},{\pflOy}) ;
      }%
    %noeuds utiles pour les calculs
    \coordinate (bbxTop) at (current bounding box.north) ;
    \coordinate (bbxBottom) at (current bounding box.south) ;
    \ifboolKV[GraphiqueTikz]{AffCadre}{\draw[pflcadre] ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;}{}%
    %back to normal
}%
{%
    \end{tikzpicture}%
}

\NewDocumentCommand\TracerAxesGrillesSemiLog{ s O{} m }{%
  % #1 = étoile (masquer origine)
  % #2 = clés
  % #3 = valeurs X, les Y sont faites automatiquement
  \restoreKV[GraphiqueTikzAxes]%
  \setKV[GraphiqueTikzAxes]{#2}%
  % nœuds axes élargis
  \IfStrEq{\pflgraphnom}{}%
  {%
    \coordinate (axeox-ee) at ([xshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflxmax},{\pflOy}) ;
    \coordinate (axeoy-nn) at ([yshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflOx},{\pflymax}) ;
  }%
  {%
    \coordinate (\pflgraphnom-axeox-ee) at ([xshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflxmax},{\pflOy}) ;
    \coordinate (\pflgraphnom-axeoy-nn) at ([yshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflOx},{\pflymax}) ;
  }%
  % cas particuliers
  \ifboolKV[GraphiqueTikzAxes]{Derriere}{\setKV[GraphiqueTikzAxes]{Grads=false}}{}%
  \ifboolKV[GraphiqueTikzAxes]{Devant}{\setKV[GraphiqueTikzAxes]{Grille=false}}{}%
  % format axe X
  \IfSubStr{\pflformataxes}{/}%
  {\StrCut{\pflformataxes}{/}{\pflformataxex}{\pflformataxey}}%
  {\xdef\pflformataxex{\pflformataxes}\xdef\pflformataxey{\pflformataxes}}%
  % grille
  \ifboolKV[GraphiqueTikzAxes]{Grille}%
  {%
    % sous-décades Y
    \foreach \n in {0,...,\inteval{\pflymax-1}}{%
      \foreach \k in {2,3,4,5,6,7,8,9}{%
        \xdef\tmpsousdec{\xintfloateval{\n+log10(\k)}}%
        \draw[pflgrilles] ({\pflxmin},{\tmpsousdec})--({\pflxmax},{\tmpsousdec}) ;%
      }%
    }%
    % grille X
    \draw[pflgrilles,xstep=\pflgrillexs,ystep=99]
    ({\pflxmin},{\pflymin}) grid ({\pflxmax},{\pflymax}) ;%
    \draw[pflgrillep,xstep=\pflgrillex,ystep=99]
    ({\pflxmin},{\pflymin}) grid ({\pflxmax},{\pflymax}) ;%
    % décades Y
    \foreach \n in {0,...,\pflymax}{%
      \draw[pflgrillep] ({\pflxmin},{\n})--({\pflxmax},{\n}) ;%
    }%
    \ifboolKV[GraphiqueTikzAxes]{Dernier}%
    {%
      \draw[pflgrillep] ({\pflxmin},{\pflymax})--({\pflxmax},{\pflymax}) ;
      \draw[pflgrillep] ({\pflxmax},{\pflymin})--({\pflxmax},{\pflymax}) ;
    }%
    {}%
  }%
  {}%
  % axes
  \ifboolKV[GraphiqueTikzAxes]{Fleches}%
  {%
    \draw[pflaxes] ({\pflxmin},{0})--([xshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflxmax},{0}) ;
    \draw[pflaxes] ({\pflOx},{0})--([yshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflOx},{\pflymax}) ;
  }%
  {%
    \draw[pflaxessansfleche] ({\pflxmin},{0})--([xshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflxmax},{0}) ;
    \draw[pflaxessansfleche] ({\pflOx},{0})--([yshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflOx},{\pflymax}) ;
  }%
  % valeurs X — gestion auto
  \IfEq{#3}{auto}%
  {%
    \xdef\tmprangexvalues{\xintfloateval{seq(i,i=\pflxmin..[\pflgrillex]..\pflxmax)}}%
    \StrDel{\tmprangexvalues}{ }[\tmprangexvalues]%
    \xdef\pflformataxex{num}%
  }%
  {\xdef\tmprangexvalues{#3}}%
  % graduations X
  \draw[pfltrait] ([yshift=\pflthickgradu]{\pflxmin},{0})--++(0,{-\pflthickgradu-\pflthickgradd}) ;
  \foreach \x in \tmprangexvalues{%
    \draw[pfltrait] ([yshift=\pflthickgradu]{\x},{0})--++(0,{-\pflthickgradu-\pflthickgradd}) ;%
  }%
  % graduations Y
  \foreach \n in {0,...,\pflymax}{%
    \xdef\tmpexpo{\inteval{\n+\pflslogexpomin}}%
    \draw[pfltrait] ([xshift=\pflthickgradu]{\pflxmin},{\n})--++({-\pflthickgradu-\pflthickgradd},0) ;%
  }%
  \ifboolKV[GraphiqueTikzAxes]{Grads}%
  {%
    % labels X
    \foreach \x in \tmprangexvalues{%
      \IfBooleanTF{#1}%
      {\xintifboolexpr{\x == \pflOx}{}%
        {\draw ([yshift={-\pflthickgradd}]{\x},{0}) node[pflnoeud,below,font={\useKV[GraphiqueTikzAxes]{Police}}] {\FormatterValeurAxex{\pflformataxex}{\x}} ;}}%
      {\draw ([yshift={-\pflthickgradd}]{\x},{0}) node[pflnoeud,below,font={\useKV[GraphiqueTikzAxes]{Police}}] {\FormatterValeurAxex{\pflformataxex}{\x}} ;}%
    }%
    % labels Y —> $10^n$
    \foreach \n in {0,...,\pflymax}{%
      \xdef\tmpexpo{\inteval{\n+\pflslogexpomin}}%
      \draw ([xshift={-\pflthickgradd}]{\pflxmin},{\n}) node[left,pflnoeud,font={\useKV[GraphiqueTikzAxes]{Police}}] { \ifboolKV[GraphiqueTikzAxes]{Puissance}{$10^{\tmpexpo}$}{\num{\xintfloateval{10^(\tmpexpo)}}} } ;
    }%
  }%
  {}%
}

\NewDocumentEnvironment{GraphiqueTikzLogLog}{ O{} D<>{} }%
{%
  \restoreKV[GraphiqueTikz]%
  \setKV[GraphiqueTikz]{#2}%
  \IfStrEq{\pflgraphdims}{}%
    {\begin{tikzpicture}[#1]}%
    {%
      \StrCut{\pflgraphdims}{/}{\pfltmpwidth}{\pfltmpheight}%
      \setlength\pflglobalwidth{\fpeval{(\pfltmpwidth)/(\pflxmaxtmp-\pflxmintmp)}pt}%
      \setlength\pflglobalheight{\fpeval{(\pfltmpheight)/(\pflymaxtmp-\pflymintmp)}pt}%
      \begin{tikzpicture}[x=\pflglobalwidth,y=\pflglobalheight,%
        Xmin=\pflxmintmp,Xmax=\pflxmaxtmp,Ymin=\pflymintmp,Ymax=\pflymaxtmp,#1]%
    }%
    % translation X ET Y
    \xdef\pflslogexpominx{\xintfloateval{log10(\pflxmin)}}%
    \xdef\pflslogexpomaxx{\xintfloateval{log10(\pflxmax)}}%
    \xdef\pflxmax{\xintfloateval{log10(\pflxmax)-log10(\pflxmin)}}%
    \xdef\pflxmin{0}%
    \xdef\pflslogexpomin{\xintfloateval{log10(\pflymin)}}%
    \xdef\pflslogexpomax{\xintfloateval{log10(\pflymax)}}%
    \xdef\pflymax{\xintfloateval{log10(\pflymax)-log10(\pflymin)}}%
    \xdef\pflymin{0}%
    \xdef\pflOx{0}\xdef\pflOy{0}%
    %thèmes personnalisés
    \IfStrEqCase{\pflgraphthem}{%
      {standard}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepdefault!75}}\tikzset{pflgrillei/.style={line width=\pflthickgrids,pflgrillesdefault}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleidefault}}}%
      {gris}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepgray!75}}\tikzset{pflgrillei/.style={line width\pflthickgrids,pflgrillesgray}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleigray}}}%
      {bleu}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepblue!75}}\tikzset{pflgrillei/.style={line width=\pflthickgrids,pflgrillesblue}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleiblue}}}%
      {vert}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepgreen!75}}\tikzset{pflgrillei/.style={line width=\pflthickgrids,pflgrillesgreen}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleigreen}}}%
      {chaud}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepwarm!75}}\tikzset{pflgrillei/.style={line width=\pflthickgrids,pflgrilleswarm}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleiwarm}}}%
      {contraste}{\tikzset{pflgrillep/.style={line width=\pflthickgridp,pflgrillepcontrast!75}}\tikzset{pflgrillei/.style={line width=\pflthickgrids,pflgrillescontrast}}\tikzset{pflgrilles/.style={line width=\pflthickgridi,pflgrilleicontrast}}}%
    }%
      %unités x/y pour des calculs de coordonnées
      \TikZUnites
      %noeuds fenêtre + axes
      \IfStrEq{\pflgraphnom}{}%
      {%
        \coordinate (graphe-ne) at ({\pflxmax},{\pflymax}) ;
        \coordinate (graphe-nw) at ({\pflxmin},{\pflymax}) ;
        \coordinate (graphe-se) at ({\pflxmax},{\pflymin}) ;
        \coordinate (graphe-sw) at ({\pflxmin},{\pflymin}) ;
        \coordinate (graphe-n) at ($(graphe-ne)!0.5!(graphe-nw)$) ;
        \coordinate (graphe-e) at ($(graphe-ne)!0.5!(graphe-se)$) ;
        \coordinate (graphe-s) at ($(graphe-se)!0.5!(graphe-sw)$) ;
        \coordinate (graphe-w) at ($(graphe-sw)!0.5!(graphe-nw)$) ;
        \coordinate (graphe-c) at ($(graphe-sw)!0.5!(graphe-ne)$) ;
        \coordinate (axeox-w) at ({\pflxmin},{\pflOy}) ;
        \coordinate (axeox-e) at ({\pflxmax},{\pflOy}) ;
        \coordinate (axeoy-s) at ({\pflOx},{\pflymin}) ;
        \coordinate (axeoy-n) at ({\pflOx},{\pflymax}) ;
        \coordinate (axes-orig) at ({\pflOx},{\pflOy}) ;
      }%
      {%
        \coordinate (\pflgraphnom-graphe-ne) at ({\pflxmax},{\pflymax}) ;
        \coordinate (\pflgraphnom-graphe-nw) at ({\pflxmin},{\pflymax}) ;
        \coordinate (\pflgraphnom-graphe-se) at ({\pflxmax},{\pflymin}) ;
        \coordinate (\pflgraphnom-graphe-sw) at ({\pflxmin},{\pflymin}) ;
        \coordinate (\pflgraphnom-graphe-n) at ($(\pflgraphnom-graphe-ne)!0.5!(\pflgraphnom-graphe-nw)$) ;
        \coordinate (\pflgraphnom-graphe-e) at ($(\pflgraphnom-graphe-ne)!0.5!(\pflgraphnom-graphe-se)$) ;
        \coordinate (\pflgraphnom-graphe-s) at ($(\pflgraphnom-graphe-se)!0.5!(\pflgraphnom-graphe-sw)$) ;
        \coordinate (\pflgraphnom-graphe-w) at ($(\pflgraphnom-graphe-sw)!0.5!(\pflgraphnom-graphe-nw)$) ;
        \coordinate (\pflgraphnom-graphe-c) at ($(\pflgraphnom-graphe-sw)!0.5!(\pflgraphnom-graphe-ne)$) ;
        \coordinate (\pflgraphnom-axeox-w) at ({\pflxmin},{\pflOy}) ;
        \coordinate (\pflgraphnom-axeox-e) at ({\pflxmax},{\pflOy}) ;
        \coordinate (\pflgraphnom-axeoy-s) at ({\pflOx},{\pflymin}) ;
        \coordinate (\pflgraphnom-axeoy-n) at ({\pflOx},{\pflymax}) ;
        \coordinate (\pflgraphnom-axes-orig) at ({\pflOx},{\pflOy}) ;
      }%
      %noeuds utiles pour les calculs
      \coordinate (bbxTop) at (current bounding box.north) ;
      \coordinate (bbxBottom) at (current bounding box.south) ;
      \ifboolKV[GraphiqueTikz]{AffCadre}{\draw[pflcadre] ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;}{}%
      %back to normal
}
{%
  \end{tikzpicture}%
}

\NewDocumentCommand\TracerAxesGrillesLogLog{ s O{} }{%
  % pas d'argument X — les deux axes sont automatiques
  \restoreKV[GraphiqueTikzAxes]%
  \setKV[GraphiqueTikzAxes]{#2}%
  \ifboolKV[GraphiqueTikzAxes]{Grille}%
  {%
    % sous-décades X
    \foreach \n in {0,...,\inteval{\pflxmax-1}}{%
      \foreach \k in {2,3,4,5,6,7,8,9}{%
        \xdef\tmpsousdecx{\xintfloateval{\n+log10(\k)}}%
        \draw[pflgrilles] ({\tmpsousdecx},{\pflymin})--({\tmpsousdecx},{\pflymax}) ;%
      }%
    }%
    % sous-décades Y
    \foreach \n in {0,...,\inteval{\pflymax-1}}{%
      \foreach \k in {2,3,4,5,6,7,8,9}{%
        \xdef\tmpsousdecy{\xintfloateval{\n+log10(\k)}}%
        \draw[pflgrilles] ({\pflxmin},{\tmpsousdecy})--({\pflxmax},{\tmpsousdecy}) ;%
      }%
    }%
    % décades X et Y
    \foreach \n in {0,...,\pflxmax}{%
      \draw[pflgrillep] ({\n},{\pflymin})--({\n},{\pflymax}) ;%
    }%
    \foreach \n in {0,...,\pflymax}{%
      \draw[pflgrillep] ({\pflxmin},{\n})--({\pflxmax},{\n}) ;%
    }%
  }%
  {}%
  % axes
  \ifboolKV[GraphiqueTikzAxes]{Fleches}%
  {%
    \draw[pflaxes] ({0},{0})--([xshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflxmax},{0}) ;
    \draw[pflaxes] ({0},{0})--([yshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{0},{\pflymax}) ;
  }%
  {%
    \draw[pflaxessansfleche] ({0},{0})--([xshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{\pflxmax},{0}) ;
    \draw[pflaxessansfleche] ({0},{0})--([yshift={\useKV[GraphiqueTikzAxes]{Elargir}}]{0},{\pflymax}) ;
  }%
  \ifboolKV[GraphiqueTikzAxes]{Grads}%
  {%
    % labels X — $10^n$
    \foreach \n in {0,...,\pflxmax}{%
      \xdef\tmpexpox{\inteval{\n+\pflslogexpominx}}%
      \draw[pfltrait] ([yshift={\pflthickgradu}]{\n},{0})--++(0,{-\pflthickgradu-\pflthickgradd}) ;%
      \draw ([yshift={-\pflthickgradd}]{\n},{0})  node[pflnoeud,below,font={\useKV[GraphiqueTikzAxes]{Police}}] { \ifboolKV[GraphiqueTikzAxes]{Puissance}{$10^{\tmpexpox}$}{\num{\xintfloateval{10^(\tmpexpox)}}} } ;
    }%
    % labels Y — $10^n$
    \foreach \n in {0,...,\pflymax}{%
      \xdef\tmpexpo{\inteval{\n+\pflslogexpomin}}%
      \draw[pfltrait] ([xshift={\pflthickgradu}]{0},{\n})--++({-\pflthickgradu-\pflthickgradd},0) ;%
      \draw ([xshift={-\pflthickgradd}]{0},{\n}) node[left,pflnoeud,font={\useKV[GraphiqueTikzAxes]{Police}}] { \ifboolKV[GraphiqueTikzAxes]{Puissance}{$10^{\tmpexpo}$}{\num{\xintfloateval{10^(\tmpexpo)}}} } ;
    }%
  }%
  {}%
}

\NewDocumentCommand\TracerCourbeSemiLog{ O{} m }{%
  % protection : si f(x) <= 0 → on renvoie une valeur hors fenêtre
  \TracerCourbe[RestreindreY,#1]{log10(#2)-(\pflslogexpomin)}%
}

\NewDocumentCommand\TracerCourbeLogLog{ O{} m }{%
  % définition avec x réel → f(10^(x+expominx))
  \xintdeffloatfunc pfltmploglogfct(x) = #2 ;%
  \TracerCourbe[RestreindreY,#1]{log10(pfltmploglogfct(10^(x+\pflslogexpominx)))-(\pflslogexpomin)}%
}

\NewDocumentCommand\TracerNuageSemiLog{ O{} D<>{d} m m }{%
  \setsepchar{,}%
  \readlist*\LX{#3}%
  \readlist*\LY{#4}%
  \foreach \i in {1,...,\LXlen}{%
    \itemtomacro\LX[\i]\tmpmavalx%
    \itemtomacro\LY[\i]\tmpmavaly%
    % transformation y → log10(y) - expomin
    \xdef\tmpmavalytrans{\xintfloateval{log10(\tmpmavaly)-(\pflslogexpomin)}}%
    \MarquerPts*[#1]{(\tmpmavalx,\tmpmavalytrans)}%
  }%
}

\NewDocumentCommand\TracerNuageLogLog{ O{} D<>{d} m m }{%
  \setsepchar{,}%
  \readlist*\LX{#3}%
  \readlist*\LY{#4}%
  \foreach \i in {1,...,\LXlen}{%
    \itemtomacro\LX[\i]\tmpmavalx%
    \itemtomacro\LY[\i]\tmpmavaly%
    % transformation x ET y
    \xdef\tmpmavalxtrans{\xintfloateval{log10(\tmpmavalx)-(\pflslogexpominx)}}%
    \xdef\tmpmavalytrans{\xintfloateval{log10(\tmpmavaly)-(\pflslogexpomin)}}%
    \MarquerPts*[#1]{(\tmpmavalxtrans,\tmpmavalytrans)}%
  }%
}

%====LECTURE CSV ET TRACÉ
\defKV[GraphiqueTikzCSV]{%
  MaxLignes=\def\pflcsvmaxlignes{#1},%
  ModeTransfo=\def\pflcsvmode{#1}%
}
\setKVdefault[GraphiqueTikzCSV]{%
  MaxLignes=100000,%
  ModeTransfo=lin%
}
 
\NewDocumentCommand\CreerListesDepuisCSV{ O{} D(){semicolon} m m m m m }{%
  % #1 = clés (MaxLignes)
  % #2 = séparateur CSV entre ( ) -- semicolon par défaut
  % #3 = fichier csv
  % #4 = nom colonne X
  % #5 = nom colonne Y
  % #6 = nom macro liste X (sans \)
  % #7 = nom macro liste Y (sans \)
  \@ifpackageloaded{csvsimple}%
    {%
      \restoreKV[GraphiqueTikzCSV]%
      \setKV[GraphiqueTikzCSV]{#1}%
      \xdef\tmpcsvlistX{}%
      \xdef\tmpcsvlistY{}%
      \xdef\tmpcsvcompteur{0}%
      \csvreader[head to column names,separator=#2]{#3}{}%
      {%
        \xintifboolexpr{\tmpcsvcompteur < \pflcsvmaxlignes}%
          {%
            \xdef\tmpvalX{\csname#4\endcsname}%
            \xdef\tmpvalY{\csname#5\endcsname}%
            \xdef\tmpcsvlistX{\tmpcsvlistX\ifx\tmpcsvlistX\empty\else,\fi\tmpvalX}%
            \xdef\tmpcsvlistY{\tmpcsvlistY\ifx\tmpcsvlistY\empty\else,\fi\tmpvalY}%
            \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
          }{}%
      }%
      \expandafter\xdef\csname#6\endcsname{\tmpcsvlistX}%
      \expandafter\xdef\csname#7\endcsname{\tmpcsvlistY}%
    }%
    {%
      \PackageWarning{tkz-grapheur}%
        {csvsimple not loaded .: \CreerListesDepuisCSV or \CreateListsFromCSV not available :.}%
    }%
}
\NewCommandCopy\CreateListsFromCSV\CreerListesDepuisCSV
 
\NewDocumentCommand\TracerNuageDepuisCSV{ O{} D(){semicolon} D<>{} m m m }{%
  % #1 = clés CSV (Mode, MaxLignes)
  % #2 = séparateur CSV entre ( ) -- semicolon par défaut
  % #3 = clés points pour \MarquerPts
  % #4 = fichier csv
  % #5 = nom colonne X
  % #6 = nom colonne Y
  \@ifpackageloaded{csvsimple}%
  {%
    \restoreKV[GraphiqueTikzCSV]%
    \setKV[GraphiqueTikzCSV]{#1}%
    \xdef\tmpcsvcompteur{0}%
    \csvreader[%
    head to column names,%
    separator=#2%
    ]{#4}{}%
    {%
      \xintifboolexpr{\tmpcsvcompteur < \pflcsvmaxlignes}%
      {%
        \IfStrEqCase{\pflcsvmode}{%
          {lin}{%
            \xdef\tmpvalX{\csname#5\endcsname}%
            \xdef\tmpvalY{\csname#6\endcsname}%
            \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
            \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
          }%
          {xlog}{%
            \xintifboolexpr{\csname#5\endcsname > 0}%
            {%
              \xdef\tmpvalX{\xintfloateval{log10(\csname#5\endcsname)}}%
              \xdef\tmpvalY{\csname#6\endcsname}%
              \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
              \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
            }{}%
          }%
          {ylog}{%
            \xintifboolexpr{\csname#6\endcsname > 0}%
            {%
              \xdef\tmpvalX{\csname#5\endcsname}%
              \xdef\tmpvalY{\xintfloateval{log10(\csname#6\endcsname)}}%
              \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
              \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
            }{}%
          }%
          {xylog}{%
            \xintifboolexpr{%
              \csname#5\endcsname > 0 && \csname#6\endcsname > 0}%
            {%
              \xdef\tmpvalX{\xintfloateval{log10(\csname#5\endcsname)}}%
              \xdef\tmpvalY{\xintfloateval{log10(\csname#6\endcsname)}}%
              \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
              \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
            }{}%
          }%
          {semilogy}{%
            \xintifboolexpr{\csname#6\endcsname > 0}%
            {%
              \xdef\tmpvalX{\csname#5\endcsname}%
              \xdef\tmpvalY{\xintfloateval{log10(\csname#6\endcsname)-\pflslogexpomin}}%
              \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
              \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
            }{}%
          }%
          {semilogx}{%
            \xintifboolexpr{\csname#5\endcsname > 0}%
            {%
              \xdef\tmpvalX{\xintfloateval{log10(\csname#5\endcsname)-\pflslogexpominx}}%
              \xdef\tmpvalY{\csname#6\endcsname}%
              \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
              \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
            }{}%
          }%
          {loglog}{%
            \xintifboolexpr{%
              \csname#5\endcsname > 0 && \csname#6\endcsname > 0}%
            {%
              \xdef\tmpvalX{\xintfloateval{log10(\csname#5\endcsname)-\pflslogexpominx}}%
              \xdef\tmpvalY{\xintfloateval{log10(\csname#6\endcsname)-\pflslogexpomin}}%
              \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
              \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
            }{}%
          }%
        {lnx}{%
          \xintifboolexpr{\csname#5\endcsname > 0}%
          {\xdef\tmpvalX{\xintfloateval{ln(\csname#5\endcsname)}}%
           \xdef\tmpvalY{\csname#6\endcsname}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {lny}{%
          \xintifboolexpr{\csname#6\endcsname > 0}%
          {\xdef\tmpvalX{\csname#5\endcsname}%
           \xdef\tmpvalY{\xintfloateval{ln(\csname#6\endcsname)}}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {lnxy}{%
          \xintifboolexpr{\csname#5\endcsname > 0 && \csname#6\endcsname > 0}%
          {\xdef\tmpvalX{\xintfloateval{ln(\csname#5\endcsname)}}%
           \xdef\tmpvalY{\xintfloateval{ln(\csname#6\endcsname)}}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {log10x}{%
          \xintifboolexpr{\csname#5\endcsname > 0}%
          {\xdef\tmpvalX{\xintfloateval{log10(\csname#5\endcsname)}}%
           \xdef\tmpvalY{\csname#6\endcsname}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {log10y}{%
          \xintifboolexpr{\csname#6\endcsname > 0}%
          {\xdef\tmpvalX{\csname#5\endcsname}%
           \xdef\tmpvalY{\xintfloateval{log10(\csname#6\endcsname)}}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {log10xy}{%
          \xintifboolexpr{\csname#5\endcsname > 0 && \csname#6\endcsname > 0}%
          {\xdef\tmpvalX{\xintfloateval{log10(\csname#5\endcsname)}}%
           \xdef\tmpvalY{\xintfloateval{log10(\csname#6\endcsname)}}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {expx}{%
          \xdef\tmpvalX{\xintfloateval{exp(\csname#5\endcsname)}}%
          \xdef\tmpvalY{\csname#6\endcsname}%
          \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
          \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
        }%
        {expy}{%
          \xdef\tmpvalX{\csname#5\endcsname}%
          \xdef\tmpvalY{\xintfloateval{exp(\csname#6\endcsname)}}%
          \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
          \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
        }%
        {expxy}{%
          \xdef\tmpvalX{\xintfloateval{exp(\csname#5\endcsname)}}%
          \xdef\tmpvalY{\xintfloateval{exp(\csname#6\endcsname)}}%
          \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
          \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
        }%
        {invx}{%
          \xintifboolexpr{\csname#5\endcsname != 0}%
          {\xdef\tmpvalX{\xintfloateval{1/(\csname#5\endcsname)}}%
           \xdef\tmpvalY{\csname#6\endcsname}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {invy}{%
          \xintifboolexpr{\csname#6\endcsname != 0}%
          {\xdef\tmpvalX{\csname#5\endcsname}%
           \xdef\tmpvalY{\xintfloateval{1/(\csname#6\endcsname)}}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {invxy}{%
          \xintifboolexpr{\csname#5\endcsname != 0 && \csname#6\endcsname != 0}%
          {\xdef\tmpvalX{\xintfloateval{1/(\csname#5\endcsname)}}%
           \xdef\tmpvalY{\xintfloateval{1/(\csname#6\endcsname)}}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {sqrtx}{%
          \xintifboolexpr{\csname#5\endcsname >= 0}%
          {\xdef\tmpvalX{\xintfloateval{sqrt(\csname#5\endcsname)}}%
           \xdef\tmpvalY{\csname#6\endcsname}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {sqrty}{%
          \xintifboolexpr{\csname#6\endcsname >= 0}%
          {\xdef\tmpvalX{\csname#5\endcsname}%
           \xdef\tmpvalY{\xintfloateval{sqrt(\csname#6\endcsname)}}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {sqrtxy}{%
          \xintifboolexpr{\csname#5\endcsname >= 0 && \csname#6\endcsname >= 0}%
          {\xdef\tmpvalX{\xintfloateval{sqrt(\csname#5\endcsname)}}%
           \xdef\tmpvalY{\xintfloateval{sqrt(\csname#6\endcsname)}}%
           \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
           \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}}{}%
        }%
        {carrex}{%
          \xdef\tmpvalX{\xintfloateval{(\csname#5\endcsname)^2}}%
          \xdef\tmpvalY{\csname#6\endcsname}%
          \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
          \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
        }%
        {carrey}{%
          \xdef\tmpvalX{\csname#5\endcsname}%
          \xdef\tmpvalY{\xintfloateval{(\csname#6\endcsname)^2}}%
          \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
          \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
        }%
        {carrexy}{%
          \xdef\tmpvalX{\xintfloateval{(\csname#5\endcsname)^2}}%
          \xdef\tmpvalY{\xintfloateval{(\csname#6\endcsname)^2}}%
          \MarquerPts*[#3]{(\tmpvalX,\tmpvalY)}%
          \xdef\tmpcsvcompteur{\inteval{\tmpcsvcompteur+1}}%
        }%
        }%
      }%
      {}%
    }%
  }%
  {%
    \PackageWarning{tkz-grapheur}%
    {csvsimple not loaded .: \TracerNuageDepuisCSV or \PlotFromCSV not available :.}%
  }%
}
\NewCommandCopy\PlotFromCSV\TracerNuageDepuisCSV
%\makeatother

\NewDocumentCommand\TracerNuagePoints{ O{} m m }{%
  % #1 = clés GraphiqueTikzRegLin (dont ModeTransfo)
  % #2 = liste X
  % #3 = liste Y
  \restoreKV[GraphiqueTikzRegLin]%
  \setKV[GraphiqueTikzRegLin]{#1}%
  \setsepchar{,}%
  \readlist*\tmpLX{#2}%
  \readlist*\tmpLY{#3}%
  \foreach \i in {1,...,\tmpLXlen}{%
    \itemtomacro\tmpLX[\i]\tmpmavalx%
    \itemtomacro\tmpLY[\i]\tmpmavaly%
    \IfStrEqCase{\pflreglinmode}{%
      {lin}{%
        \MarquerPts*[#1]{(\tmpmavalx,\tmpmavaly)}%
      }%
      {xlog}{%
        \xintifboolexpr{\tmpmavalx > 0}%
          {%
            \xdef\tmpvalX{\xintfloateval{log10(\tmpmavalx)}}%
            \MarquerPts*[#1]{(\tmpvalX,\tmpmavaly)}%
          }{}%
      }%
      {ylog}{%
        \xintifboolexpr{\tmpmavaly > 0}%
          {%
            \xdef\tmpvalY{\xintfloateval{log10(\tmpmavaly)}}%
            \MarquerPts*[#1]{(\tmpmavalx,\tmpvalY)}%
          }{}%
      }%
      {xylog}{%
        \xintifboolexpr{\tmpmavalx > 0 && \tmpmavaly > 0}%
          {%
            \xdef\tmpvalX{\xintfloateval{log10(\tmpmavalx)}}%
            \xdef\tmpvalY{\xintfloateval{log10(\tmpmavaly)}}%
            \MarquerPts*[#1]{(\tmpvalX,\tmpvalY)}%
          }{}%
      }%
      {semilogy}{%
        \xintifboolexpr{\tmpmavaly > 0}%
          {%
            \xdef\tmpvalY{\xintfloateval{log10(\tmpmavaly)-\pflslogexpomin}}%
            \MarquerPts*[#1]{(\tmpmavalx,\tmpvalY)}%
          }{}%
      }%
      {semilogx}{%
        \xintifboolexpr{\tmpmavalx > 0}%
          {%
            \xdef\tmpvalX{\xintfloateval{log10(\tmpmavalx)-\pflslogexpominx}}%
            \MarquerPts*[#1]{(\tmpvalX,\tmpmavaly)}%
          }{}%
      }%
      {loglog}{%
        \xintifboolexpr{\tmpmavalx > 0 && \tmpmavaly > 0}%
          {%
            \xdef\tmpvalX{\xintfloateval{log10(\tmpmavalx)-\pflslogexpominx}}%
            \xdef\tmpvalY{\xintfloateval{log10(\tmpmavaly)-\pflslogexpomin}}%
            \MarquerPts*[#1]{(\tmpvalX,\tmpvalY)}%
          }{}%
      }%
      {lnx}{%
        \xintifboolexpr{\tmpmavalx > 0}%
        {%
        \xdef\tmpvalX{\xintfloateval{ln(\tmpmavalx)}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpmavaly)}%
        }{}%
      }%
      {lny}{%
        \xintifboolexpr{\tmpmavaly > 0}%
        {%
        \xdef\tmpvalY{\xintfloateval{ln(\tmpmavaly)}}%
        \MarquerPts*[#1]{(\tmpmavalx,\tmpvalY)}%
        }{}%
      }%
      {lnxy}{%
        \xintifboolexpr{\tmpmavalx > 0 && \tmpmavaly > 0}%
        {%
        \xdef\tmpvalX{\xintfloateval{ln(\tmpmavalx)}}%
        \xdef\tmpvalY{\xintfloateval{ln(\tmpmavaly)}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpvalY)}%
        }{}%
      }%
      {log10x}{%
        \xintifboolexpr{\tmpmavalx > 0}%
        {%
        \xdef\tmpvalX{\xintfloateval{log10(\tmpmavalx)}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpmavaly)}%
        }{}%
      }%
      {log10y}{%
        \xintifboolexpr{\tmpmavaly > 0}%
        {%
        \xdef\tmpvalY{\xintfloateval{log10(\tmpmavaly)}}%
        \MarquerPts*[#1]{(\tmpmavalx,\tmpvalY)}%
        }{}%
      }%
      {log10xy}{%
        \xintifboolexpr{\tmpmavalx > 0 && \tmpmavaly > 0}%
        {%
        \xdef\tmpvalX{\xintfloateval{log10(\tmpmavalx)}}%
        \xdef\tmpvalY{\xintfloateval{log10(\tmpmavaly)}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpvalY)}%
        }{}%
      }%
      {expx}{%
        \xdef\tmpvalX{\xintfloateval{exp(\tmpmavalx)}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpmavaly)}%
      }%
      {expy}{%
        \xdef\tmpvalY{\xintfloateval{exp(\tmpmavaly)}}%
        \MarquerPts*[#1]{(\tmpmavalx,\tmpvalY)}%
      }%
      {expxy}{%
        \xdef\tmpvalX{\xintfloateval{exp(\tmpmavalx)}}%
        \xdef\tmpvalY{\xintfloateval{exp(\tmpmavaly)}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpvalY)}%
      }%
      {invx}{%
        \xintifboolexpr{\tmpmavalx != 0}%
        {%
        \xdef\tmpvalX{\xintfloateval{1/(\tmpmavalx)}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpmavaly)}%
        }{}%
      }%
      {invy}{%
        \xintifboolexpr{\tmpmavaly != 0}%
        {%
        \xdef\tmpvalY{\xintfloateval{1/(\tmpmavaly)}}%
        \MarquerPts*[#1]{(\tmpmavalx,\tmpvalY)}%
        }{}%
      }%
      {invxy}{%
        \xintifboolexpr{\tmpmavalx != 0 && \tmpmavaly != 0}%
        {%
        \xdef\tmpvalX{\xintfloateval{1/(\tmpmavalx)}}%
        \xdef\tmpvalY{\xintfloateval{1/(\tmpmavaly)}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpvalY)}%
        }{}%
      }%
      {sqrtx}{%
        \xintifboolexpr{\tmpmavalx >= 0}%
        {%
        \xdef\tmpvalX{\xintfloateval{sqrt(\tmpmavalx)}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpmavaly)}%
        }{}%
      }%
      {sqrty}{%
        \xintifboolexpr{\tmpmavaly >= 0}%
        {%
        \xdef\tmpvalY{\xintfloateval{sqrt(\tmpmavaly)}}%
        \MarquerPts*[#1]{(\tmpmavalx,\tmpvalY)}%
        }{}%
      }%
      {sqrtxy}{%
        \xintifboolexpr{\tmpmavalx >= 0 && \tmpmavaly >= 0}%
        {%
        \xdef\tmpvalX{\xintfloateval{sqrt(\tmpmavalx)}}%
        \xdef\tmpvalY{\xintfloateval{sqrt(\tmpmavaly)}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpvalY)}%
        }{}%
      }%
      {carrex}{%
        \xdef\tmpvalX{\xintfloateval{(\tmpmavalx)^2}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpmavaly)}%
      }%
      {carrey}{%
        \xdef\tmpvalY{\xintfloateval{(\tmpmavaly)^2}}%
        \MarquerPts*[#1]{(\tmpmavalx,\tmpvalY)}%
      }%
      {carrexy}{%
        \xdef\tmpvalX{\xintfloateval{(\tmpmavalx)^2}}%
        \xdef\tmpvalY{\xintfloateval{(\tmpmavaly)^2}}%
        \MarquerPts*[#1]{(\tmpvalX,\tmpvalY)}%
      }%
    }%
  }%
}
\NewCommandCopy\PlotPoints\TracerNuagePoints

%====DIAGRAMME EN BÂTONS (données statistiques quelconques)
\defKV[tkzDiagBatons]{%
  CouleurTraits=\def\tkzDiagBatCouleurTraits{#1},%
  Couleurs=\def\tkzDiagBatCouleurs{#1},%
  Style=\def\tkzDiagBatStyle{#1},%
  Largeur=\def\tkzDiagBatLargeur{#1},%
  Arrondi=\def\tkzDiagBatArrondi{#1},%
  CouleurValeurs=\def\tkzDiagBatColVal{#1}%
}
\setKVdefault[tkzDiagBatons]{%
  CouleurTraits=black,%
  Couleurs={black},%
  Style=batons,%
  Largeur=0.8,%
  AffValeurs=false,%
  Arrondi=0,%
  CouleurValeurs=black%
}

\NewDocumentCommand\TracerDiagrammeBatons{ O{} m }{%
  % #1 = clés
  % #2 = série : x1/y1,x2/y2,...
  \restoreKV[tkzDiagBatons]%
  \setKV[tkzDiagBatons]{#1}%
  % lecture de la liste de couleurs (cyclique)
  \setsepchar{,}%
  \readlist*\tkzDiagBatListeCoul{\tkzDiagBatCouleurs}%
  % lecture des données
  \setsepchar[.]{,./}%
  \readlist*\tkzDiagBatListe{#2}%
  % demi-largeur pour le style histo
  \xdef\tkzDiagBatDemiLarg{\xintfloateval{\tkzDiagBatLargeur/2}}%
  % tracé barre par barre
  \foreach \i in {1,...,\tkzDiagBatListelen}{%
    \itemtomacro\tkzDiagBatListe[\i,1]\tkzDiagBatX%
    \itemtomacro\tkzDiagBatListe[\i,2]\tkzDiagBatY%
    % couleur cyclique selon l'indice
    \itemcycltomacro\tkzDiagBatListeCoul[\i]\tkzDiagBatCoulCour%
    % coordonnées pré-calculées pour le style histo
    \xdef\tkzDiagBatXmin{\xintfloateval{\tkzDiagBatX-\tkzDiagBatDemiLarg}}%
    \xdef\tkzDiagBatHauteur{\xintfloateval{\tkzDiagBatY-\pflymin}}%
    % tracé : bâton ou rectangle
    \IfStrEq{\tkzDiagBatStyle}{batons}%
      {%
        \draw[pflbarresprobas,color=\tkzDiagBatCoulCour]%
          ({\tkzDiagBatX},{\pflymin}) -- ({\tkzDiagBatX},{\tkzDiagBatY}) ;%
      }%
      {%
        \draw[pfltrait,color=\tkzDiagBatCouleurTraits,fill=\tkzDiagBatCoulCour,fill opacity=0.5]%
          ({\tkzDiagBatXmin},{\pflymin})%
          rectangle++ ({\tkzDiagBatLargeur},{\tkzDiagBatHauteur}) ;%
      }%
    % affichage de la valeur au-dessus de la barre
    \ifboolKV[tkzDiagBatons]{AffValeurs}%
      {%
        \node[\tkzDiagBatColVal,pfllabeleffectifs,above]%
          at ({\tkzDiagBatX},{\tkzDiagBatY})%
          {\num{\tkzDiagBatY}} ;%
      }%
      {}%
  }%
}

%====HISTOGRAMME (données statistiques quelconques, classes régulières ou non)
\defKV[tkzHistoStat]{%
  CouleurTraits=\def\tkzHistoStatCouleurtraits{#1},%
  Couleurs=\def\tkzHistoStatCouleurs{#1},%
  CouleurValeurs=\def\tkzHistoStatColVal{#1},%
  PosValeurs=\def\tkzHistoStatPosVal{#1}%
}
\setKVdefault[tkzHistoStat]{%
  CouleurTraits=black,%
  Couleurs={black},%
  Densite=false,%
  AffValeurs=false,%
  CouleurValeurs=black,%
  PosValeurs=above%
}

\NewDocumentCommand\TracerHistogramme{ O{} m }{%
  % #1 = clés
  % #2 = données : bi1/bs1/eff1,bi2/bs2/eff2,...
  \restoreKV[tkzHistoStat]%
  \setKV[tkzHistoStat]{#1}%
  % lecture de la liste de couleurs (cyclique)
  \setsepchar{,}%
  \readlist*\tkzHistoStatListeCoul{\tkzHistoStatCouleurs}%
  % lecture des données
  \setsepchar[.]{,./}%
  \readlist*\tkzHistoStatListe{#2}%
  % tracé classe par classe
  \foreach \i in {1,...,\tkzHistoStatListelen}{%
    \itemtomacro\tkzHistoStatListe[\i,1]\tkzHistoStatBI%
    \itemtomacro\tkzHistoStatListe[\i,2]\tkzHistoStatBS%
    \itemtomacro\tkzHistoStatListe[\i,3]\tkzHistoStatEff%
    % couleur cyclique selon l'indice
    \itemcycltomacro\tkzHistoStatListeCoul[\i]\tkzHistoStatCoulCour%
    % hauteur : effectif brut ou densité = effectif / amplitude
    \ifboolKV[tkzHistoStat]{Densite}%
      {%
        \xdef\tkzHistoStatH{%
          \xintfloateval{(\tkzHistoStatEff)/((\tkzHistoStatBS)-(\tkzHistoStatBI))}}%
      }%
      {\xdef\tkzHistoStatH{\tkzHistoStatEff}}%
    % hauteur du rectangle dans le repère
    \xdef\tkzHistoStatHrect{\xintfloateval{\tkzHistoStatH-(\pflymin)}}%
    % tracé du rectangle
    \draw[pfltrait,color=\tkzHistoStatCouleurtraits,fill=\tkzHistoStatCoulCour,fill opacity=0.5]%
      ({\tkzHistoStatBI},{\pflymin})%
      rectangle++ ({\tkzHistoStatBS-(\tkzHistoStatBI)},{\tkzHistoStatHrect}) ;%
    % affichage de la valeur
    \ifboolKV[tkzHistoStat]{AffValeurs}%
      {%
        \xdef\tkzHistoStatMilieu{\xintfloateval{(\tkzHistoStatBI+(\tkzHistoStatBS))/2}}%
        \node[\tkzHistoStatPosVal,\tkzHistoStatColVal,pfllabeleffectifs]%
          at ({\tkzHistoStatMilieu},{\tkzHistoStatH})%
          {\num{\tkzHistoStatEff}} ;%
      }%
      {}%
  }%
}

%====CARREAU DE RÉFÉRENCE POUR HISTOGRAMME EN DENSITÉ
\defKV[tkzCarrDensite]{%
  Couleur=\def\tkzCarrCouleur{#1},%
  CouleurBordure=\def\tkzCarrColBord{#1},%
  Opacite=\def\tkzCarrOpacite{#1},%
  Police=\def\tkzCarrPolice{#1},%
  Legende=\def\tkzCarrLegende{#1}
}
\setKVdefault[tkzCarrDensite]{%
  Couleur=gray,%
  CouleurBordure=black,%
  Opacite=0.5,%
  Police=\normalsize\normalfont,%
  Legende={}
}

\NewDocumentCommand\PlaceCarreauHistoDensite{ O{} m m m m }{%
  % #1 = clés
  % #2 = x coin bas-gauche  (unités du repère)
  % #3 = y coin bas-gauche  (unités du repère)
  % #4 = largeur            (unités x → amplitude)
  % #5 = hauteur            (unités y → densité)
  % aire = #4 × #5 = effectif correspondant
  \restoreKV[tkzCarrDensite]%
  \setKV[tkzCarrDensite]{#1}%
  % calcul de l'effectif représenté par ce carreau
  \xdef\tkzCarrAire{\xintfloateval{(#4)*(#5)}}%
  % label : fourni ou calculé automatiquement
  \IfStrEq{\tkzCarrLegende}{}%
    {\def\tkzCarrLabel{$\equiv \num{\tkzCarrAire}$ individu(s)}}%
    {\def\tkzCarrLabel{\tkzCarrLegende}}%
  % tracé du carreau
  \draw[pfltrait,color=\tkzCarrColBord,fill=\tkzCarrCouleur,fill opacity=\tkzCarrOpacite]%
    ({#2},{#3}) rectangle++ ({#4},{#5}) ;
  % label positionné au milieu
  \node[font=\tkzCarrPolice]%
    at ({(#2)+0.5*(#4)},{(#3)+0.5*(#5)}) {\tkzCarrLabel} ;%
}

%====BOÎTE À MOUSTACHES
\defKV[tkzBoiteMoustaches]{%
  Couleur=\def\tkzBaMCouleur{#1},%
  CouleurPointilles=\def\tkzBaMCouleurTraits{#1},%
  Elevation=\def\tkzBaMElevation{#1},%
  Hauteur=\def\tkzBaMHauteur{#1},%
  Moyenne=\def\tkzBaMMoyenne{#1},%
  Remplissage=\def\tkzBaMRemplissage{#1},%
  Arrondi=\def\tkzBaMArrondi{#1}%
}
\setKVdefault[tkzBoiteMoustaches]{%
  Couleur=black,%
  CouleurPointilles=black,%
  Elevation=0,%
  Hauteur=1,%
  AffMoyenne=false,%
  Moyenne=0,%
  Pointilles=false,%
  Valeurs=false,%
  Remplissage=white,%
  Arrondi=0,%
  Regroup=false
}

% macro interne : dessin à partir de 5 params déjà extraits
\NewDocumentCommand\tkzg@bam@draw{ m m m m m m }{%
  % #1=clés  #2=min  #3=Q1  #4=med  #5=Q3  #6=max
  \xdef\tkzBaMbas{\xintfloateval{\tkzBaMElevation-(\tkzBaMHauteur)/2}}%
  \xdef\tkzBaMhaut{\xintfloateval{\tkzBaMElevation+(\tkzBaMHauteur)/2}}%
  % pointillés vers l'axe Ox, en sous-impression ;-)
  \ifboolKV[tkzBoiteMoustaches]{Pointilles}%
    {%
      \draw[pfltraitantec,color=\tkzBaMCouleurTraits]%
        ({#2},{\tkzBaMbas}) -- ({#2},{\pflOy})%
        ({#3},{\tkzBaMbas}) -- ({#3},{\pflOy})%
        ({#4},{\tkzBaMbas}) -- ({#4},{\pflOy})%
        ({#5},{\tkzBaMbas}) -- ({#5},{\pflOy})%
        ({#6},{\tkzBaMbas}) -- ({#6},{\pflOy}) ;%
    }%
    {}%
  % boîte Q1--Q3
  \draw[pflcourbe,color=\tkzBaMCouleur,fill=\tkzBaMRemplissage]%
    ({#3},{\tkzBaMbas}) rectangle ({#5},{\tkzBaMhaut}) ;%
  % moustaches horizontales
  \draw[pflcourbe,color=\tkzBaMCouleur]%
    ({#2},{\tkzBaMElevation}) -- ({#3},{\tkzBaMElevation})%
    ({#5},{\tkzBaMElevation}) -- ({#6},{\tkzBaMElevation}) ;%
  % barres verticales : min, médiane, max
  \draw[pflcourbe,color=\tkzBaMCouleur]%
    ({#2},{\tkzBaMbas}) -- ({#2},{\tkzBaMhaut})%
    ({#6},{\tkzBaMbas}) -- ({#6},{\tkzBaMhaut})%
    ({#4},{\tkzBaMbas}) -- ({#4},{\tkzBaMhaut}) ;%
  % moyenne optionnelle
  \ifboolKV[tkzBoiteMoustaches]{AffMoyenne}%
    {\filldraw[color=\tkzBaMCouleur] ({\tkzBaMMoyenne},{\tkzBaMElevation}) circle[pflpointmc] ;}%
    {}%
  % valeurs des 5 paramètres sur l'axe Ox
  \ifboolKV[tkzBoiteMoustaches]{Valeurs}%
    {%
      \foreach \tkzBaMval in {#2,#3,#4,#5,#6}{%
        \draw[color=\tkzBaMCouleur]%
          ({\tkzBaMval},{\pflOy}) node[below,pfllabeleffectifs]%
          {\ArrondirNum[\tkzBaMArrondi]{\tkzBaMval}} ;%
      }%
    }%
    {}%
}

\NewDocumentCommand\TracerBoiteMoustaches{ s O{} m }{%
  % version normale  : #3 = min/Q1/mediane/Q3/max  (valeurs explicites)
  % version étoilée  : #3 = liste CSV brute        (calcul auto des params)
  \restoreKV[tkzBoiteMoustaches]%
  \setKV[tkzBoiteMoustaches]{#2}%
  \IfBooleanTF{#1}%
    {%
      % calcul des 5 paramètres depuis la liste brute (données individuelles ou groupées)
      \ifboolKV[tkzBoiteMoustaches]{Regroup}%
        {%
          \tkzgCalcParamStats*{#3}%
            [\tkzBaMautomin][\tkzBaMautoquun][\tkzBaMautomed][\tkzBaMautoqutr][\tkzBaMautomax]%
        }%
        {%
          \tkzgCalcParamStats{#3}%
            [\tkzBaMautomin][\tkzBaMautoquun][\tkzBaMautomed][\tkzBaMautoqutr][\tkzBaMautomax]%
        }%
      \tkzg@bam@draw{}%
        {\tkzBaMautomin}{\tkzBaMautoquun}{\tkzBaMautomed}%
        {\tkzBaMautoqutr}{\tkzBaMautomax}%
    }%
    {%
      % lecture des 5 paramètres explicites (format min/Q1/med/Q3/max)
      \setsepchar[.]{/}%
      \readlist*\tkzBaMParams{#3}%
      \itemtomacro\tkzBaMParams[1]\tkzBaMp@min%
      \itemtomacro\tkzBaMParams[2]\tkzBaMp@qu%
      \itemtomacro\tkzBaMParams[3]\tkzBaMp@med%
      \itemtomacro\tkzBaMParams[4]\tkzBaMp@qt%
      \itemtomacro\tkzBaMParams[5]\tkzBaMp@max%
      \tkzg@bam@draw{}%
        {\tkzBaMp@min}{\tkzBaMp@qu}{\tkzBaMp@med}%
        {\tkzBaMp@qt}{\tkzBaMp@max}%
    }%
}

%====DIAGRAMME CIRCULAIRE
\defKV[GraphiqueTikzCamembert]{%
  CouleurDefaut=\def\pflcamcouldef{#1},%
  RayonInt=\def\pflcamrayonint{#1},%
  Rayon=\def\pflcamrayon{#1},%
  Titre=\def\pflcamtitre{#1},%
  NomGraphique=\def\pflcamnomgraph{#1}%
}
\setKVdefault[GraphiqueTikzCamembert]{%
  CouleurDefaut=lightgray,%
  RayonInt=1.75,%
  Rayon=3,%
  Titre={},%
  NomGraphique={}
}

\defKV[GraphiqueTikzCamembertLeg]{%
  TailleCarreau=\def\pflcamlegtaille{#1},%
  Arrondi=\def\pflcamlegarrondi{#1},%
  Espacement=\def\pflcamespleg{#1},%
  DecalEst=\def\pflcamdecalest{#1}%
}
\setKVdefault[GraphiqueTikzCamembertLeg]{%
  TailleCarreau=0.28,%
  Pct=true,%
  Arrondi=0,%
  Espacement=0.55,%
  DecalEst=0.4%
}

%====DIAGRAMME
\NewDocumentCommand\DiagrammeCirculaire{ O{} m }{%
  \restoreKV[GraphiqueTikzCamembert]%
  \setKV[GraphiqueTikzCamembert]{#1}%
  \setsepchar[.]{,./}%
  \readlist*\pflcamlist{#2}%
  % calcul du total
  \xdef\pflcamtotalglobal{0}%
  \xintFor* ##1 in {\xintSeq{1}{\pflcamlistlen}} \do{%
    \itemtomacro\pflcamlist[##1,2]\tmpval%
    \xdef\pflcamtotalglobal{\xintfloateval{\pflcamtotalglobal+\tmpval}}%
  }%
  % nœuds cardinaux
  \IfEq{\pflcamnomgraph}{}%
    {%
      \coordinate (cam-centre) at (0,0) ;%
      \coordinate (cam-nord)   at (0,\pflcamrayon) ;%
      \coordinate (cam-sud)    at (0,-\pflcamrayon) ;%
      \coordinate (cam-est)    at (\pflcamrayon,0) ;%
      \coordinate (cam-ouest)  at (-\pflcamrayon,0) ;%
    }%
    {%
      \coordinate (\pflcamnomgraph-cam-centre) at (0,0) ;%
      \coordinate (\pflcamnomgraph-cam-nord)   at (0,\pflcamrayon) ;%
      \coordinate (\pflcamnomgraph-cam-sud)    at (0,-\pflcamrayon) ;%
      \coordinate (\pflcamnomgraph-cam-est)    at (\pflcamrayon,0) ;%
      \coordinate (\pflcamnomgraph-cam-ouest)  at (-\pflcamrayon,0) ;%
    }%
  % tracé des secteurs + nœuds
  \xdef\pflcamangle{90}%
  \xintFor* ##1 in {\xintSeq{1}{\pflcamlistlen}} \do{%
    \itemtomacro\pflcamlist[##1,2]\tmpval%
    \itemtomacro\pflcamlist[##1,3]\tmpcoulcam%
    \itemtomacro\pflcamlist[##1,4]\tmptypecam%
    \IfEq{\tmpcoulcam}{}%
      {\def\tmpcoulcam{\pflcamcouldef}}%
      {}
    \IfEq{\tmptypecam}{}%
      {\def\tmptypecam{solid}}%
      {}
    \xdef\pflcamsectangle{\xintfloateval{360*\tmpval/\pflcamtotalglobal}}%
    \xdef\pflcamanglefin{\xintfloateval{\pflcamangle-\pflcamsectangle}}%
    \xdef\pflcamanglemil{\xintfloateval{\pflcamangle-\pflcamsectangle/2}}%
    \IfEq{\tmptypecam}{solid}%
      {%
        \draw[fill=\tmpcoulcam,pfltraitcamembert] (0,0)
          -- (\pflcamangle:\pflcamrayon)
          arc (\pflcamangle:\pflcamanglefin:\pflcamrayon)
          -- cycle ;%
      }%
      {%
        \draw[pattern={\tmptypecam},pattern color={\tmpcoulcam},pfltraitcamembert] (0,0)
          -- (\pflcamangle:\pflcamrayon)
          arc (\pflcamangle:\pflcamanglefin:\pflcamrayon)
          -- cycle ;%
      }%
    \IfEq{\pflcamnomgraph}{}%
      {%
        \coordinate (cam-##1-debut) at (\pflcamangle:\pflcamrayon) ;%
        \coordinate (cam-##1-fin)   at (\pflcamanglefin:\pflcamrayon) ;%
        \coordinate (cam-##1-mil)   at (\pflcamanglemil:\pflcamrayon) ;%
        \coordinate (cam-##1-int)   at (\pflcamanglemil:{0.68*\pflcamrayon}) ;%
        \coordinate (cam-##1-ext)   at (\pflcamanglemil:{1.15*\pflcamrayon}) ;%
      }%
      {%
        \coordinate (\pflcamnomgraph-cam-##1-debut) at (\pflcamangle:\pflcamrayon) ;%
        \coordinate (\pflcamnomgraph-cam-##1-fin)   at (\pflcamanglefin:\pflcamrayon) ;%
        \coordinate (\pflcamnomgraph-cam-##1-mil)   at (\pflcamanglemil:\pflcamrayon) ;%
        \coordinate (\pflcamnomgraph-cam-##1-int)   at (\pflcamanglemil:{0.68*\pflcamrayon}) ;%
        \coordinate (\pflcamnomgraph-cam-##1-ext)   at (\pflcamanglemil:{1.15*\pflcamrayon}) ;%
      }%
    \xdef\pflcamangle{\pflcamanglefin}%
  }%
  \draw[pfltraitcamembert] (0,0) circle (\pflcamrayon) ;%
  \IfStrEq{\pflcamtitre}{}{}%
    {\node[pfllegendetitre] at (cam-nord) {\pflcamtitre} ;}%
}

\NewCommandCopy\TracerDiagrammeCirculaire\DiagrammeCirculaire

\NewDocumentCommand\TracerDiagrammeAnneau{ O{} m }{%
  \restoreKV[GraphiqueTikzCamembert]%
  \setKV[GraphiqueTikzCamembert]{#1}%
  \setsepchar[.]{,./}%
  \readlist*\pflcamlist{#2}%
  % calcul du total
  \xdef\pflcamtotalglobal{0}%
  \xintFor* ##1 in {\xintSeq{1}{\pflcamlistlen}} \do{%
    \itemtomacro\pflcamlist[##1,2]\tmpval%
    \xdef\pflcamtotalglobal{\xintfloateval{\pflcamtotalglobal+\tmpval}}%
  }%
  % nœuds cardinaux
  \IfEq{\pflcamnomgraph}{}%
    {%
      \coordinate (cam-centre) at (0,0) ;%
      \coordinate (cam-nord)   at (0,\pflcamrayon) ;%
      \coordinate (cam-sud)    at (0,-\pflcamrayon) ;%
      \coordinate (cam-est)    at (\pflcamrayon,0) ;%
      \coordinate (cam-ouest)  at (-\pflcamrayon,0) ;%
    }%
    {%
      \coordinate (\pflcamnomgraph-cam-centre) at (0,0) ;%
      \coordinate (\pflcamnomgraph-cam-nord)   at (0,\pflcamrayon) ;%
      \coordinate (\pflcamnomgraph-cam-sud)    at (0,-\pflcamrayon) ;%
      \coordinate (\pflcamnomgraph-cam-est)    at (\pflcamrayon,0) ;%
      \coordinate (\pflcamnomgraph-cam-ouest)  at (-\pflcamrayon,0) ;%
    }%
  % tracé des secteurs + nœuds
  \xdef\pflcamangle{90}%
  \begin{scope}
    %\clip[even odd rule] (0,0) circle (\pflcamrayon) (0,0) circle (\pflcamrayonint) ;
    % tracé des secteurs
    \xintFor* ##1 in {\xintSeq{1}{\pflcamlistlen}} \do{%
    \itemtomacro\pflcamlist[##1,2]\tmpval%
    \itemtomacro\pflcamlist[##1,3]\tmpcoulcam%
    \itemtomacro\pflcamlist[##1,4]\tmptypecam%
    \IfEq{\tmpcoulcam}{}%
      {\def\tmpcoulcam{\pflcamcouldef}}%
      {}
    \IfEq{\tmptypecam}{}%
      {\def\tmptypecam{solid}}%
      {}
    \xdef\pflcamsectangle{\xintfloateval{360*\tmpval/\pflcamtotalglobal}}%
    \xdef\pflcamanglefin{\xintfloateval{\pflcamangle-\pflcamsectangle}}%
    \xdef\pflcamanglemil{\xintfloateval{\pflcamangle-\pflcamsectangle/2}}%
    \IfEq{\tmptypecam}{solid}%
      {%
        \draw[fill=\tmpcoulcam, pfltraitcamembert]
          (\pflcamangle:\pflcamrayonint)                           % départ arc intérieur
          -- (\pflcamangle:\pflcamrayon)                           % rayon de départ
          arc (\pflcamangle:\pflcamanglefin:\pflcamrayon)          % arc extérieur
          -- (\pflcamanglefin:\pflcamrayonint)                     % rayon de fin
          arc (\pflcamanglefin:\pflcamangle:\pflcamrayonint)       % arc intérieur (sens inverse)
          -- cycle ;
      }%
      {%
        \draw[even odd rule,pattern={\tmptypecam},pattern color={\tmpcoulcam},pfltraitcamembert]
          (\pflcamangle:\pflcamrayonint)                           % départ arc intérieur
          -- (\pflcamangle:\pflcamrayon)                           % rayon de départ
          arc (\pflcamangle:\pflcamanglefin:\pflcamrayon)          % arc extérieur
          -- (\pflcamanglefin:\pflcamrayonint)                     % rayon de fin
          arc (\pflcamanglefin:\pflcamangle:\pflcamrayonint)       % arc intérieur (sens inverse)
          -- cycle ;
      }%
    \IfEq{\pflcamnomgraph}{}%
      {%
        \coordinate (cam-##1-debut) at (\pflcamangle:\pflcamrayon) ;%
        \coordinate (cam-##1-fin)   at (\pflcamanglefin:\pflcamrayon) ;%
        \coordinate (cam-##1-mil)   at (\pflcamanglemil:\pflcamrayon) ;%
        \coordinate (cam-##1-int)   at (\pflcamanglemil:{0.68*\pflcamrayon}) ;%
        \coordinate (cam-##1-ext)   at (\pflcamanglemil:{1.15*\pflcamrayon}) ;%
      }%
      {%
        \coordinate (\pflcamnomgraph-cam-##1-debut) at (\pflcamangle:\pflcamrayon) ;%
        \coordinate (\pflcamnomgraph-cam-##1-fin)   at (\pflcamanglefin:\pflcamrayon) ;%
        \coordinate (\pflcamnomgraph-cam-##1-mil)   at (\pflcamanglemil:\pflcamrayon) ;%
        \coordinate (\pflcamnomgraph-cam-##1-int)   at (\pflcamanglemil:{0.68*\pflcamrayon}) ;%
        \coordinate (\pflcamnomgraph-cam-##1-ext)   at (\pflcamanglemil:{1.15*\pflcamrayon}) ;%
      }%
    \xdef\pflcamangle{\pflcamanglefin}%
  }%
  \end{scope}
  \draw[pfltraitcamembert] (0,0) circle (\pflcamrayon) ;%
  \draw[pfltraitcamembert] (0,0) circle (\pflcamrayonint) ;%
  \IfStrEq{\pflcamtitre}{}{}%
    {\node[pfllegendetitre] at (cam-nord) {\pflcamtitre} ;}%
}

%====LÉGENDE — sous-tikzpicture ancré sur cam-est
\NewDocumentCommand\LegendeCirculaire{ O{} m }{%
  \restoreKV[GraphiqueTikzCamembertLeg]%
  \setKV[GraphiqueTikzCamembertLeg]{#1}%
  \setsepchar[.]{,./}%
  \readlist*\pflcamleglist{#2}%
  % calcul du total
  \xdef\pflcamlegtotal{0}%
  \xintFor* ##1 in {\xintSeq{1}{\pflcamleglistlen}} \do{%
    \itemtomacro\pflcamleglist[##1,2]\tmpval%
    \xdef\pflcamlegtotal{\xintfloateval{\pflcamlegtotal+\tmpval}}%
  }%
  % sous-tikzpicture dans un node ancré sur cam-est
  \IfEq{\pflcamnomgraph}{}%
    {%
      \coordinate (cam-legende) at ([xshift=\pflcamdecalest cm]cam-est) ;
    }%
    {%
      \coordinate (cam-legende) at ([xshift=\pflcamdecalest cm]\pflcamnomgraph-cam-est) ;
    }%
  \node[anchor=west] at (cam-legende) {%
    \begin{tikzpicture}
      \xintFor* ##1 in {\xintSeq{1}{\pflcamleglistlen}} \do{%
        \itemtomacro\pflcamleglist[##1,1]\tmplabel%
        \itemtomacro\pflcamleglist[##1,2]\tmpval%
        \itemtomacro\pflcamleglist[##1,3]\tmpcoulcam%
        \itemtomacro\pflcamleglist[##1,4]\tmptypecam%
        \IfEq{\tmptypecam}{}%
          {\def\tmptypecam{solid}}%
          {}%
        \IfEq{\tmpcoulcam}{}%
          {\def\tmpcoulcam{\pflcamcouldef}}%
          {}
        \xdef\tmppct{\xintfloateval{%
            round(100*\tmpval/\pflcamlegtotal,\pflcamlegarrondi)}}%
        \xdef\tmpy{\xintfloateval{-(##1-1)*\pflcamespleg}}%
        % carreau coloré
        \IfEq{\tmptypecam}{solid}%
          {%
            \draw[pflpointggb,fill={\tmpcoulcam}] (0,{\tmpy-\pflcamlegtaille/2}) rectangle (\pflcamlegtaille,{\tmpy+\pflcamlegtaille/2}) ;%
          }%
          {%
            \draw[pflpointggb,pattern={\tmptypecam},pattern color={\tmpcoulcam}] (0,{\tmpy-\pflcamlegtaille/2}) rectangle (\pflcamlegtaille,{\tmpy+\pflcamlegtaille/2}) ;%
          }%
        % label — colonne 1
        \node[anchor=west,pfllegendelabels]
          at ({\pflcamlegtaille+0.1},\tmpy) {{\tmplabel} (\ifboolKV[GraphiqueTikzCamembertLeg]{Pct}{\tmppct\,\%}{\ArrondirNum[\pflcamlegarrondi]{\tmpval}})} ;%
      }%
    \end{tikzpicture}%
  } ;%
}

%====POINTS D'INTÉRÊT version classique GraphiqueTikz (FR, path-based)
\defKV[GraphiqueTikzPointsInteretClassique]{%
  Couleur=\def\pflpicoul{#1},%
  CouleurRacines=\def\pflpicoulrac{#1},%
  CouleurMax=\def\pflpicoulmax{#1},%
  CouleurMin=\def\pflpicoulmin{#1},%
  Style=\def\pflpistyle{#1},%
  StyleRacines=\def\pflpistyler{#1},%
  StyleMax=\def\pflpistylema{#1},%
  StyleMin=\def\pflpistylemi{#1},%
  NomMax=\def\pflpinommax{#1},%
  NomMin=\def\pflpinommin{#1},%
  NomRacines=\def\pflpinomrac{#1},%
  Debut=\def\pflpidebut{#1},%
  Fin=\def\pflpifin{#1}%
}
\setKVdefault[GraphiqueTikzPointsInteretClassique]{%
  Couleur=black,%
  CouleurRacines={},%
  CouleurMax={},%
  CouleurMin={},%
  Style=ggb,%
  StyleRacines={},%
  StyleMax={},%
  StyleMin={},%
  Racines=true,%
  Maximum=true,%
  Minimum=true,%
  NomMax=c-max,%
  NomMin=c-min,%
  NomRacines=c-rac,%
  Debut={\pflxmin},%
  Fin={\pflxmax}%
}

\NewDocumentCommand\TrouverPointsInteret{ O{} m }{%
  % #1=clés  #2=nom path (name path global)
  \restoreKV[GraphiqueTikzPointsInteretClassique]%
  \setKV[GraphiqueTikzPointsInteretClassique]{#1}%
  % résolution couleurs
  \IfStrEq{\pflpicoulrac}{}{\xdef\pflpicoulrac{\pflpicoul}}{}%
  \IfStrEq{\pflpicoulmax}{}{\xdef\pflpicoulmax{\pflpicoul}}{}%
  \IfStrEq{\pflpicoulmin}{}{\xdef\pflpicoulmin{\pflpicoul}}{}%
  % résolution styles
  \IfStrEq{\pflpistyler}{}{\xdef\pflpistyler{\pflpistyle}}{}%
  \IfStrEq{\pflpistylema}{}{\xdef\pflpistylema{\pflpistyle}}{}%
  \IfStrEq{\pflpistylemi}{}{\xdef\pflpistylemi{\pflpistyle}}{}%
  \begin{pgfinterruptboundingbox}
  %---- racines
  \ifboolKV[GraphiqueTikzPointsInteretClassique]{Racines}%
    {%
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;%
        \PlacerAntecedents[Couleurs=\pflpicoulrac,Style=\pflpistyler,Nom=\pflpinomrac]{#2}{0}%
      \end{scope}
    }{}%
  %---- maximum
  \ifboolKV[GraphiqueTikzPointsInteretClassique]{Maximum}%
    {%
      \TrouverMaximum[Debut=\pflpidebut,Fin=\pflpifin,Methode=path]{#2}[\pflpinommax]%
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;%
        \MarquerPts*[Style=\pflpistylema,Couleur=\pflpicoulmax]{(\pflpinommax)}%
      \end{scope}
    }{}%
  %---- minimum
  \ifboolKV[GraphiqueTikzPointsInteretClassique]{Minimum}%
    {%
      \TrouverMinimum[Debut=\pflpidebut,Fin=\pflpifin,Methode=path]{#2}[\pflpinommin]%
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;%
        \MarquerPts*[Style=\pflpistylemi,Couleur=\pflpicoulmin]{(\pflpinommin)}%
      \end{scope}
    }{}%
  \end{pgfinterruptboundingbox}
}

%====MINI GRAPHIQUE — \MiniGraphiqueTkz
\defKV[MiniGraphiqueTkzKV]{%
  Largeur   = \def\pflmgwlargeur{#1},%
  Hauteur   = \def\pflmgwhauteur{#1},%
  Xmin      = \def\pflmgwxmin{#1},%
  Xmax      = \def\pflmgwxmax{#1},%
  Ymin      = \def\pflmgwymin{#1},%
  Ymax      = \def\pflmgwymax{#1},%
  DeltaVI   = \def\pflmgwdeltavi{#1},%
  Couleur   = \def\pflmgwcouleur{#1},%
  Domaine   = \def\pflmgwdomaine{#1},%
  Echelle   = \def\pflmgwechelle{#1}
}
\setKVdefault[MiniGraphiqueTkzKV]{%
  Largeur   = 4cm,%
  Hauteur   = 3cm,%
  Xmin      = -3,%
  Xmax      = 3,%
  Ymin      = -2,%
  Ymax      = 2,%
  Cadre     = true,%
  DeltaVI   = auto,%
  Couleur   = black,%
  Domaine   = {},%
  Echelle   = 1,%
  ProfLycee = false,%
  MainLevee = false
}

\NewDocumentCommand\MiniGraphiqueTkz{ O{} D<>{} m O{} }{%
  % #1 = clés tikz #2 = clés simplekv  #3 = f(x) § g(x) § ... #4 = VIf § VIg § ...
  \restoreKV[MiniGraphiqueTkzKV]%
  \setKV[MiniGraphiqueTkzKV]{#2}%
  % ── Calcul des unités x/y à partir de Largeur/Hauteur ─────────
  \setlength\tmptkzgwidth{\pflmgwlargeur}%
  \setlength\pflglobalwidth{\fpeval{(\pflmgwlargeur)/(\pflmgwxmax-\pflmgwxmin)}pt}%
  \setlength\tmptkzgheight{\pflmgwhauteur}%
  \setlength\pflglobalheight{\fpeval{(\pflmgwhauteur)/(\pflmgwymax-\pflmgwymin)}pt}%
  % ── Calcul du pas (250 avec VI) ───────────────────────────────
  \IfStrEq{\pflmgwdeltavi}{auto}%
    {\xdef\pflmgwdeltavi{\xintfloateval{(\pflmgwxmax-\pflmgwxmin)/250}}}%
    {}%
  % ── Les données ───────────────────────────────────────────────
  \xdef\pflxmin{\pflmgwxmin}%
  \xdef\pflxmax{\pflmgwxmax}%
  \xdef\pflymin{\pflmgwymin}%
  \xdef\pflymax{\pflmgwymax}%
  \IfStrEq{\pflmgwechelle}{auto}%basée sur 3cm de hauteur
    {%
      \xdef\pflmgwechelle{\fpeval{\tmptkzgheight/3cm}}%
    }%
    {}%
  % ── Le tikzpicture ────────────────────────────────────────────
  \begin{tikzpicture}[x=\pflglobalwidth,y=\pflglobalheight,#1]%
    \ifboolKV[MiniGraphiqueTkzKV]{ProfLycee}%
      {%
        \tikzset{pflminiaxes/.style={semithick,->,>=latex}}%
        \tikzset{pflminicadre/.style={lightgray}}%
        \tikzset{pflcourbe/.style={thick}}%
      }%
      {%
        \tikzset{pflminiaxes/.style={line width=\fpeval{\pflmgwechelle*0.8}pt,->,>=latex}}%
        \tikzset{pflminicadre/.style={line width=\fpeval{\pflmgwechelle*0.8}pt,gray}}%
        \tikzset{pflcourbe/.style={line width=\fpeval{\pflmgwechelle*1.05}pt}}
      }%
    % mainlevee
    \ifboolKV[MiniGraphiqueTkzKV]{MainLevee}%
      {%
        \tikzset{pflminiaxes/.append style={tkzgmainlevee}}%
        \tikzset{pflminicadre/.append style={tkzgmainlevee}}%
      }%
      {}%
    % clip au rectangle de la fenêtre
    \begin{scope}%
      \draw[pflminiaxes] (\pflmgwxmin,0)--(\pflmgwxmax,0);
      \draw[pflminiaxes] (0,\pflmgwymin)--(0,\pflmgwymax);
      \tkzglenoflist[§]{#3}%\resmylen
      \foreach \i in {1,...,\resmylen}{%
        \tkzggetvaluefromlist[§]{#3}{\i}[\mytmpfct]%
        \tkzgetvaluefromcycllist[§]{\pflmgwcouleur}{\i}[\mytmpcol]%
        \tkzggetvaluefromlist[§]{#4}{\i}[\mytmpvi]%
        % ── Découpage du Domaine (a:b) ou fallback sur Xmin:Xmax ─────
        \IfStrEq{\pflmgwdomaine}{}%
          {%
            \xdef\pflmgwdebut{\pflmgwxmin}%
            \xdef\pflmgwfin{\pflmgwxmax}%
          }%
          {%
            \tkzggetvaluefromlist[§]{\pflmgwdomaine}{\i}[\mytmpdomaine]%
            \StrCut{\mytmpdomaine}{:}{\pflmgwdebut}{\pflmgwfin}%
          }%
        \ifboolKV[MiniGraphiqueTkzKV]{MainLevee}%
          {%
            \xdef\pflstepcurveint{\xintfloateval{(\pflmgwxmax-\pflmgwxmin)/50}}%
            \xdef\pflmgwbruitamp{\xintfloateval{(\pflmgwymax-\pflmgwymin)*0.01}}%
            \DefinirCourbe%
              [Trace,Clip,Couleur={\mytmpcol},Debut=\pflmgwdebut,Fin=\pflmgwfin,ValeursInterdites={\mytmpvi},DeltaVI=\pflmgwdeltavi,RestreindreY,Pas=\pflstepcurveint]%
              {\mytmpfct + \pflmgwbruitamp*((random()<0.2)?{(random()-0.5)}{0})}%
          }%
          {%
            \DefinirCourbe%
              [Trace,Clip,Couleur={\mytmpcol},Debut=\pflmgwdebut,Fin=\pflmgwfin,ValeursInterdites={\mytmpvi},DeltaVI=\pflmgwdeltavi,RestreindreY]%
              {\mytmpfct}%
          }%
      }%
    \end{scope}%
    % cadre optionnel
    \ifboolKV[MiniGraphiqueTkzKV]{Cadre}%
      {\draw[pflminicadre] (\pflmgwxmin,\pflmgwymin) rectangle (\pflmgwxmax,\pflmgwymax);}%
      {}%
  \end{tikzpicture}%
}

\newsavebox{\pflmgwbox}

\NewDocumentCommand\MiniGraphiqueTkzTab{ O{} D<>{} m O{} m O{0.85} O{1.5} }{%
  %#1 = clés
  %#2 = numligne
  %#3 = échelle
  %#4 = décalage
  \savebox{\pflmgwbox}{%
    \MiniGraphiqueTkz[#1]<ProfLycee,#2,Largeur=\fpeval{2.1*#6}cm,Hauteur=\fpeval{#6*1}cm>{#3}[#4]%
  }%
  \coordinate (ZZZ) at ($(T2#5)!.5!(T2\the\numexpr#5+1\relax)$) ;
  \path (ZZZ.east) + ({#7+0.05*(#6)},0) node[anchor=center]{\usebox{\pflmgwbox}} ;
}

\endinput