% tkz-grapheur-en.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 [en] de tkz-grapheur-fr

%\makeatletter

%====COMMANDE POUR NB DECIMAL ALEA ENTRE BORNES 
\NewDocumentCommand\PickRandomNb{ s O{0} m m O{\mmyrandomnb} }{%
  \def\tmpborneinf{\xinteval{floor(#3)}}%inf=\tmpborneinf\par%
  \def\tmpbornesup{\xinteval{ceil(#4)}}%sup=\tmpbornesup\par%
  \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)}}%
          }%
        %essai=\tmpresalea\par
        \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}%
      %res=%
    }%
}

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

%===COMMANDE INTERNE POUR FORMATER EN FRACTIONS
\NewDocumentCommand\FormatFraction{ 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\FormatTrig{ 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\FormatSqrt{ 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}}}%
            }%
        }%
        {%
          \FormatFraction[#1]{#2}%
        }%
    }%
}

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

%====RECUPERER COORDONNEES NOEUD
\NewDocumentCommand\GetXcoord{ m O{\myxcoord} }{%
  \path #1;
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef#2{\xintfloateval{(\ConvertPtToCm{\macrox})/(\pflxunit)}}%
}
\NewDocumentCommand\GetYcoord{ m O{\myycoord} }{%
  \path #1;
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef#2{\xintfloateval{(\ConvertPtToCm{\macroy})/(\pflyunit)}}%
}

\NewDocumentCommand\GetXYcoord{ m O{\myxcoord} O{\myycoord} }{%
  \GetXcoord{#1}[#2]%
  \GetYcoord{#1}[#3]%
}

%===UNITÉS
\newcommand\DistBetweenNodes[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\TikZUnits{
    \coordinate (@0) at (0,0) ;
    \coordinate (@X) at (1,0) ;
    \coordinate (@Y) at (0,1) ;
    \DistBetweenNodes[\pflxunit]{@0}{@X}
    \DistBetweenNodes[\pflyunit]{@0}{@Y}
}

%====ENVIRONNEMENT
\defKV[GraphicTikz]{%
  GradThick=\setlength\pflthickgrad{#1},%
  Xmin=\def\pflxmintmp{#1},%
  Xmax=\def\pflxmaxtmp{#1},%
  Ymin=\def\pflymintmp{#1},%
  Ymax=\def\pflymaxtmp{#1},%
  Size=\def\pflgraphdims{#1},%
  Theme=\def\pflgraphthem{#1},%
  FigName=\def\pflgraphnom{#1}
}
\setKVdefault[GraphicTikz]{%
  Frame=false,%
  GradThick=3pt,%
  Xmin=-3,%
  Xmax=3,%
  Ymin=-3,%
  Ymax=3,%
  Size={},%
  Theme={},
  Milli=false,%
  FigName={}
}

\NewDocumentEnvironment{GraphTikz}{ O{} D<>{} }%
%1 = options tikz, classiques
%2 = clés spécifiques
{%
  \restoreKV[GraphicTikz]%
  \setKV[GraphicTikz]{#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]%
    }%
  %thèmes personnalisés
  \IfStrEqCase{\pflgraphthem}{%
    {standard}{\tikzset{tkzgrphgridp/.style={line width=0.75pt,pflgrillepdefault!75}}\tikzset{tkzgrphgrids/.style={line width=0.25pt,pflgrillesdefault}}\tikzset{tkzgrphgridi/.style={line width=0.5pt,pflgrilleidefault}}}%
    {gray}{\tikzset{tkzgrphgridp/.style={line width=0.75pt,pflgrillepgray!75}}\tikzset{tkzgrphgrids/.style={line width=0.25pt,pflgrillesgray}}\tikzset{tkzgrphgridi/.style={line width=0.5pt,pflgrilleigray}}}%
    {blue}{\tikzset{tkzgrphgridp/.style={line width=0.75pt,pflgrillepblue!75}}\tikzset{tkzgrphgrids/.style={line width=0.25pt,pflgrillesblue}}\tikzset{tkzgrphgridi/.style={line width=0.5pt,pflgrilleiblue}}}%
    {green}{\tikzset{tkzgrphgridp/.style={line width=0.75pt,pflgrillepgreen!75}}\tikzset{tkzgrphgrids/.style={line width=0.25pt,pflgrillesgreen}}\tikzset{tkzgrphgridi/.style={line width=0.5pt,pflgrilleigreen}}}%
    {warm}{\tikzset{tkzgrphgridp/.style={line width=0.75pt,pflgrillepwarm!75}}\tikzset{tkzgrphgrids/.style={line width=0.25pt,pflgrilleswarm}}\tikzset{tkzgrphgridi/.style={line width=0.5pt,pflgrilleiwarm}}}%
    {contrast}{\tikzset{tkzgrphgridp/.style={line width=0.75pt,pflgrillepcontrast!75}}\tikzset{tkzgrphgrids/.style={line width=0.25pt,pflgrillescontrast}}\tikzset{tkzgrphgridi/.style={line width=0.5pt,pflgrilleicontrast}}}%
  }%
  %unités x/y pour des calculs de coordonnées
  \TikZUnits
  %nodes windows + axis
  \IfStrEq{\pflgraphnom}{}%
    {%
      \coordinate (graph-ne) at ({\pflxmax},{\pflymax}) ;
      \coordinate (graph-nw) at ({\pflxmin},{\pflymax}) ;
      \coordinate (graph-se) at ({\pflxmax},{\pflymin}) ;
      \coordinate (graph-sw) at ({\pflxmin},{\pflymin}) ;
      \coordinate (graph-n) at ($(graph-ne)!0.5!(graph-nw)$) ;
      \coordinate (graph-e) at ($(graph-ne)!0.5!(graph-se)$) ;
      \coordinate (graph-s) at ($(graph-se)!0.5!(graph-sw)$) ;
      \coordinate (graph-w) at ($(graph-sw)!0.5!(graph-nw)$) ;
      \coordinate (graph-c) at ($(graph-sw)!0.5!(graph-ne)$) ;
      \coordinate (xaxis-w) at ({\pflxmin},{\pflOy}) ;
      \coordinate (xaxis-e) at ({\pflxmax},{\pflOy}) ;
      \coordinate (yaxis-s) at ({\pflOx},{\pflymin}) ;
      \coordinate (yaxis-n) at ({\pflOx},{\pflymax}) ;
      \coordinate (axis-orig) at ({\pflOx},{\pflOy}) ;
    }%
    {%
      \coordinate (\pflgraphnom-graph-ne) at ({\pflxmax},{\pflymax}) ;
      \coordinate (\pflgraphnom-graph-nw) at ({\pflxmin},{\pflymax}) ;
      \coordinate (\pflgraphnom-graph-se) at ({\pflxmax},{\pflymin}) ;
      \coordinate (\pflgraphnom-graph-sw) at ({\pflxmin},{\pflymin}) ;
      \coordinate (\pflgraphnom-graph-n) at ($(\pflgraphnom-graph-ne)!0.5!(\pflgraphnom-graph-nw)$) ;
      \coordinate (\pflgraphnom-graph-e) at ($(\pflgraphnom-graph-ne)!0.5!(\pflgraphnom-graph-se)$) ;
      \coordinate (\pflgraphnom-graph-s) at ($(\pflgraphnom-graph-se)!0.5!(\pflgraphnom-graph-sw)$) ;
      \coordinate (\pflgraphnom-graph-w) at ($(\pflgraphnom-graph-sw)!0.5!(\pflgraphnom-graph-nw)$) ;
      \coordinate (\pflgraphnom-graph-c) at ($(\pflgraphnom-graph-sw)!0.5!(\pflgraphnom-graph-ne)$) ;
      \coordinate (\pflgraphnom-xaxis-w) at ({\pflxmin},{\pflOy}) ;
      \coordinate (\pflgraphnom-xaxis-e) at ({\pflxmax},{\pflOy}) ;
      \coordinate (\pflgraphnom-yaxis-s) at ({\pflOx},{\pflymin}) ;
      \coordinate (\pflgraphnom-yaxis-n) at ({\pflOx},{\pflymax}) ;
      \coordinate (\pflgraphnom-axes-orig) at ({\pflOx},{\pflOy}) ;
    }%
    %noeuds
    \coordinate (bbxTop) at (current bounding box.north) ;
    \coordinate (bbxBottom) at (current bounding box.south) ;
    \ifboolKV[GraphicTikz]{Frame}{\draw[tkzgrphframe] ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;}{}%
    %back to normal
}%
{%
  \end{tikzpicture}%
}

%====AXES
\defKV[GraphicTikzAxis]{
  Format=\def\pflformataxes{#1}
}
\setKVdefault[GraphicTikzAxis]{%
  Grid=true,%
  SubGrid =false,%
  Enlarge=0,%
  Grads=true,%
  Origin=false,%
  Font={},%
  Format=num,%
  Lines=true,%
  Last=false,%
  Behind=false,%
  Above=false,%
  Arrows=true
}

\NewDocumentCommand\FormatXaxisValues{ m m }{%
  \IfStrEqCase{#1}{%
    {num}{\num{#2}}%
    {year}{#2}%
    {frac}{\FormatFrac{#2}}%
    {dfrac}{\FormatFrac[d]{#2}}%
    {nfrac}{\FormatFrac[n]{#2}}%
    {trig}{\FormatTrig{#2}}%
    {dtrig}{\FormatTrig[d]{#2}}%
    {ntrig}{\FormatTrig[n]{#2}}%
    {sqrt}{\FormatSqrt{#2}}%
    {dsqrt}{\FormatSqrt[d]{#2}}%
    {nsqrt}{\FormatSqrt[n]{#2}}%
  }[#2]%
}

\NewDocumentCommand\FormatYaxisValues{ m m }{%
  \IfStrEqCase{#1}{%
    {num}{\num{#2}}%
    {year}{#2}%
    {frac}{\FormatSqrt{#2}}%
    {dfrac}{\FormatFrac[d]{#2}}%
    {nfrac}{\FormatFrac[n]{#2}}%
    {trig}{\FormatTrig{#2}}%
    {dtrig}{\FormatTrig[d]{#2}}%
    {ntrig}{\FormatTrig[n]{#2}}%
    {sqrt}{\FormatSqrt{#2}}%
    {dsqrt}{\FormatSqrt[d]{#2}}%
    {nsqrt}{\FormatSqrt[n]{#2}}%
  }[#2]%
}

\NewDocumentCommand\DrawAxisGrids{ s O{} m D<>{#3} m D<>{#5} }{%
  \restoreKV[GraphicTikzAxis]%
  \setKV[GraphicTikzAxis]{#2}%
  %nodes enlarge axis
  \IfStrEq{\pflgraphnom}{}%
  {%
    \coordinate (xaxis-ee) at ([xshift={\useKV[GraphicTikzAxis]{Enlarge}}]{\pflxmax},{\pflOy}) ;
    \coordinate (yaxis-nn) at ([yshift={\useKV[GraphicTikzAxis]{Enlarge}}]{\pflOx},{\pflymax}) ;
  }%
  {%
    \coordinate (\pflgraphnom-xaxis-ee) at ([xshift={\useKV[GraphicTikzAxis]{Enlarge}}]{\pflxmax},{\pflOy}) ;
    \coordinate (\pflgraphnom-yaxis-nn) at ([yshift={\useKV[GraphicTikzAxis]{Enlarge}}]{\pflOx},{\pflymax}) ;
  }%
  %cas particuliers sous/sur impression
  \ifboolKV[GraphicTikzAxis]{Behind}%
    {%
      \setKV[GraphicTikzAxis]{Grads=false}
    }%
    {}%
  \ifboolKV[GraphicTikzAxis]{Above}%
    {%
      \setKV[GraphicTikzAxis]{Grid=false}
    }%
    {}%
  %suite
  \IfSubStr{\pflformataxes}{/}%
    {%
      \StrCut{\pflformataxes}{/}{\pflformataxex}{\pflformataxey}%
    }%
    {%
      \xdef\pflformataxex{\pflformataxes}\xdef\pflformataxey{\pflformataxes}%
    }%
  \ifboolKV[GraphicTikzAxis]{Grid}%
    {%
      \draw[tkzgrphgrids,xstep=\pflgrillexs,ystep=\pflgrilleys] ({\pflxmin},{\pflymin}) grid ({\pflxmax},{\pflymax});
	  \ifboolKV[GraphicTikzAxis]{SubGrid}%
        {%
          \draw[tkzgrphgridi,xstep=\pflgrillexi,ystep=\pflgrilleyi] ({\pflxmin},{\pflymin}) grid ({\pflxmax},{\pflymax});
        }%
        {}%
      \draw[tkzgrphgridp,xstep=\pflgrillex,ystep=\pflgrilley] ({\pflxmin},{\pflymin}) grid ({\pflxmax},{\pflymax});
      \ifboolKV[GraphicTikzAxis]{Last}%
        {%
          \draw[tkzgrphgridp] ({\pflxmin},{\pflymax})--({\pflxmax},{\pflymax}) ;
          \draw[tkzgrphgridp] ({\pflxmax},{\pflymin})--({\pflxmax},{\pflymax}) ;
        }%
        {}%
    }%
    {}%
  %axis
  \ifboolKV[GraphicTikzAxis]{Arrows}%
    {%
      \draw[tkzgrphaxes] ({\pflxmin},{\pflOy}) -- ([xshift={\useKV[GraphicTikzAxis]{Enlarge}}]{\pflxmax},{\pflOy}) ;
      \draw[tkzgrphaxes] ({\pflOx},{\pflymin}) -- ([yshift={\useKV[GraphicTikzAxis]{Enlarge}}]{\pflOx},{\pflymax}) ;
    }%
    {%
      \draw[tkzgrphaxeswoarrows] ({\pflxmin},{\pflOy}) -- ([xshift={\useKV[GraphicTikzAxis]{Enlarge}}]{\pflxmax},{\pflOy}) ;
      \draw[tkzgrphaxeswoarrows] ({\pflOx},{\pflymin}) -- ([yshift={\useKV[GraphicTikzAxis]{Enlarge}}]{\pflOx},{\pflymax}) ;
    }%
  \IfEq{#3}{auto}%
    {%
      \xdef\tmprangexvalues{\xintfloateval{seq(i,i=\pflxmin..[\pflgrillex]..\pflxmax)}}\StrDel{\tmprangexvalues}{ }[\tmprangexvalues]%
      \xdef\pflformataxex{num}%
    }%
    {%
      \xdef\tmprangexvalues{#3}%
    }%
  \IfEq{#5}{auto}%
    {%
      \xdef\tmprangeyvalues{\xintfloateval{seq(i,i=\pflymin..[\pflgrilley]..\pflymax)}}\StrDel{\tmprangeyvalues}{ }[\tmprangeyvalues]%
      \xdef\pflformataxey{num}%
    }%
    {%
      \xdef\tmprangeyvalues{#5}%
    }%
  \foreach \x in \tmprangexvalues {\draw[tkzgrphline] ([yshift=\pflthickgrad]{\x},{\pflOy})--++(0,{-2\pflthickgrad}) ;}
  \foreach \y in \tmprangeyvalues {\draw[tkzgrphline] ([xshift=\pflthickgrad]{\pflOx},{\y})--++({-2\pflthickgrad},0) ;}
  \ifboolKV[GraphicTikzAxis]{Grads}%
    {%
      %origine
      \ifboolKV[GraphicTikzAxis]{Origin}%
        {%
          \draw ({\pflOx},{\pflOy}) node[tkzgrphnode,below left,font={\useKV[GraphicTikzAxis]{Font}}] {\FormatXaxisValues{\pflformataxex}{\pflOx}} ;
          %\draw (\pflOx,\pflOy) node[below left,font={\useKV[GraphicTikzAxis]{Font}}] {\ifboolKV[GraphicTikzAxis]{Num}{\num{\pflOx}}{\pflOx}} ;
        }%
        {}%
      %graduations x, sauf si auto...
      \foreach \x in \tmprangexvalues {%
        \IfBooleanTF{#1}%
          {%
            \xintifboolexpr{\x == \pflOx}{}{\draw ([yshift={-\pflthickgrad}]{\x},{\pflOy}) node[tkzgrphnode,below,font={\useKV[GraphicTikzAxis]{Font}}] {\FormatXaxisValues{\pflformataxex}{\x}} ;}
            %\xintifboolexpr{\x == \pflOx}{}{\draw ([yshift=-\pflthickgrad]\x,\pflOy) node[below,font={\useKV[GraphicTikzAxis]{Font}}] {\ifboolKV[GraphicTikzAxis]{Num}{\num{\x}}{\x}} ;}
          }%
          {%
            \draw ([yshift={-\pflthickgrad}]{\x},{\pflOy}) node[tkzgrphnode,below,font={\useKV[GraphicTikzAxis]{Font}}] {\FormatXaxisValues{\pflformataxex}{\x}} ;
            %\draw ([yshift=-\pflthickgrad]\x,\pflOy) node[below,font={\useKV[GraphicTikzAxis]{Font}}] {\ifboolKV[GraphicTikzAxis]{Num}{\num{\x}}{\x}} ;
          }%
        }%
      \foreach \y in \tmprangeyvalues {%
        \IfBooleanTF{#1}%
          {%
            \xintifboolexpr{\y == \pflOy}{}{\draw ([xshift={-\pflthickgrad}]{\pflOx},{\y}) node[tkzgrphnode,left,font={\useKV[GraphicTikzAxis]{Font}}] {\FormatYaxisValues{\pflformataxey}{\y}} ;}
            %\xintifboolexpr{\y == \pflOy}{}{\draw ([xshift=-\pflthickgrad]\pflOx,\y) node[left,font={\useKV[GraphicTikzAxis]{Font}}] {\ifboolKV[GraphicTikzAxis]{Num}{\num{\y}}{\y}} ;}
          }%
          {%
            \draw ([xshift={-\pflthickgrad}]{\pflOx},{\y}) node[tkzgrphnode,left,font={\useKV[GraphicTikzAxis]{Font}}] {\FormatYaxisValues{\pflformataxey}{\y}} ;
            %\draw ([xshift=-\pflthickgrad]\pflOx,\y) node[left,font={\useKV[GraphicTikzAxis]{Font}}] {\ifboolKV[GraphicTikzAxis]{Num}{\num{\y}}{\y}} ;
          }%
        }%
    }%
    {}%
}

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

%===DEFINIR POINTS
\setKVdefault[GraphicTikzDefPoints]{Color=black,Mark=false,Style=o}

\NewDocumentCommand\DefinePts{ O{} m }{%
  \restoreKV[GraphicTikzDefPoints]%
  \setKV[GraphicTikzDefPoints]{#1}%
  \foreach \tmpnamept/\tmpxpt/\tmpypt in {#2}{%
  \coordinate (\tmpnamept) at ({\tmpxpt},{\tmpypt}) ;
    \ifboolKV[GraphicTikzDefPoints]{Mark}%
      {%
        \MarkPts*[Style={\useKV[GraphicTikzDefPoints]{Style}},Color={\useKV[GraphicTikzDefPoints]{Color}}]{(\tmpnamept)}
        %\filldraw[{\useKV[GraphicTikzDefPoints]{Color}}] (\tmpnamept) circle[tkzgrphpointc] ;
      }%
      {}%
  }
}

\defKV[GraphicTikzMarkPoints]{%
  Color=\def\pflcouleurpoints{#1},%
  Style=\def\pflstylepoints{#1}
}
\setKVdefault[GraphicTikzMarkPoints]{%
  Color=black,%
  Sizec=2pt,%
  Sizex=2pt,%
  Sizeo=1.75pt,%
  Style=o,%
  Lines=false
}
\NewDocumentCommand\MarkPts{ s O{} D<>{\normalfont\normalsize} m }{%
  %étoilée = sans label
  %2=clés
  %3=points
  \restoreKV[GraphicTikzMarkPoints]%
  \setKV[GraphicTikzMarkPoints]{#2}%
  \IfBooleanTF{#1}%
    {%
      \IfStrEq{\pflstylepoints}{x}%
        {%
          \foreach \Point in {#4} {%
            \ifboolKV[GraphicTikzMarkPoints]{Lines}%
              {%
                \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \draw[{\useKV[GraphicTikzMarkPoints]{Color}}] \Point pic{tkzgraphcross={\useKV[GraphicTikzMarkPoints]{Sizex}}/45} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{+}%
        {%
          \foreach \Point in {#4} {%
            \ifboolKV[GraphicTikzMarkPoints]{Lines}%
              {%
                \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \draw[{\useKV[GraphicTikzMarkPoints]{Color}}] \Point pic{tkzgraphcross={\useKV[GraphicTikzMarkPoints]{Sizex}}/90} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{c}%
        {%
          \foreach \Point in {#4} {%
            \ifboolKV[GraphicTikzMarkPoints]{Lines}%
              {%
                \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \filldraw[draw=none,fill={\useKV[GraphicTikzMarkPoints]{Color}}] \Point pic{tkzgraphsquare={\useKV[GraphicTikzMarkPoints]{Sizec}}/0} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{d}%
        {%
          \foreach \Point in {#4} {%
            \ifboolKV[GraphicTikzMarkPoints]{Lines}%
              {%
                \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \filldraw[draw=none,fill={\useKV[GraphicTikzMarkPoints]{Color}}] \Point pic{tkzgraphsquare={\useKV[GraphicTikzMarkPoints]{Sizeo}}/45} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{o}%
        {%
          \IfSubStr{\pflcouleurpoints}{/}%
            {%
              \StrCut{\pflcouleurpoints}{/}{\pflcouleurpointsA}{\pflcouleurpointsB}%
              \foreach \Point in {#4} {%
                \ifboolKV[GraphicTikzMarkPoints]{Lines}%
                  {%
                    \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \filldraw[tkzgrphline,fill=\pflcouleurpointsB,draw=\pflcouleurpointsA] \Point circle[radius={\useKV[GraphicTikzMarkPoints]{Sizeo}}] ;
              }%
            }%
            {%
              \foreach \Point in {#4} {%
                \ifboolKV[GraphicTikzMarkPoints]{Lines}%
                  {%
                    \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \filldraw[\pflcouleurpoints] \Point circle[radius={\useKV[GraphicTikzMarkPoints]{Sizeo}}] ;
              }%
            }%
        }%
        {}%
    }%
    {%avec label
      \IfStrEq{\pflstylepoints}{x}%
        {%
          \foreach \Point/\Pos/\Label in {#4} {%
            \ifboolKV[GraphicTikzMarkPoints]{Lines}%
              {%
                \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \draw[{\useKV[GraphicTikzMarkPoints]{Color}}] \Point pic{tkzgraphcross={\useKV[GraphicTikzMarkPoints]{Sizex}}/45} node[tkzgrphnode,\Pos,font=#3] {\Label} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{+}%
        {%
          \foreach \Point/\Pos/\Label in {#4} {%
            \ifboolKV[GraphicTikzMarkPoints]{Lines}%
              {%
                \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \draw[{\useKV[GraphicTikzMarkPoints]{Color}}] \Point pic{tkzgraphcross={\useKV[GraphicTikzMarkPoints]{Sizex}}/90} node[tkzgrphnode,\Pos,font=#3] {\Label} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{c}%
        {%
          \foreach \Point/\Pos/\Label in {#4} {%
            \ifboolKV[GraphicTikzMarkPoints]{Lines}%
              {%
                \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \filldraw[draw=none,fill={\useKV[GraphicTikzMarkPoints]{Color}}] \Point pic{tkzgraphsquare={\useKV[GraphicTikzMarkPoints]{Sizec}}/0} node[tkzgrphnode,\Pos,{\useKV[GraphicTikzMarkPoints]{Color}},font=#3] {\Label} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{d}%
        {%
          \foreach \Point/\Pos/\Label in {#4} {%
            \ifboolKV[GraphicTikzMarkPoints]{Lines}%
              {%
                \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
              }%
              {}%
            \filldraw[draw=none,fill={\useKV[GraphicTikzMarkPoints]{Color}}] \Point pic{tkzgraphsquare={\useKV[GraphicTikzMarkPoints]{Sizeo}}/45} node[tkzgrphnode,\Pos,{\useKV[GraphicTikzMarkPoints]{Color}},font=#3] {\Label} ;
          }%
        }%
        {}%
      \IfStrEq{\pflstylepoints}{o}%
        {%
          \IfSubStr{\pflcouleurpoints}{/}%
            {%
              \StrCut{\pflcouleurpoints}{/}{\pflcouleurpointsA}{\pflcouleurpointsB}%
              \foreach \Point/\Pos/\Label in {#4} {%
                \ifboolKV[GraphicTikzMarkPoints]{Lines}%
                  {%
                    \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \draw[tkzgrphline,\pflcouleurpointsA,fill=\pflcouleurpointsB] \Point circle[radius={\useKV[GraphicTikzMarkPoints]{Sizeo}}] node[tkzgrphnode,\Pos,font=#3] {\Label} ;
              }%
            }%
            {%
              \foreach \Point/\Pos/\Label in {#4} {%
                \ifboolKV[GraphicTikzMarkPoints]{Lines}%
                  {%
                    \draw[{\useKV[GraphicTikzMarkPoints]{Color}},tkzgrphcounterimage] let \p1 = \Point in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
                  }%
                  {}%
                \filldraw[\pflcouleurpoints] \Point circle[radius={\useKV[GraphicTikzMarkPoints]{Sizeo}}] node[tkzgrphnode,\Pos,font=#3] {\Label} ;
              }%
            }%
        }%
        {}%
    }%
}

%===AJOUTER DES VALEURS MANUELLEMENT
\NewDocumentCommand\AddXvalues{ O{} m m }{%
  \restoreKV[GraphicTikzAxis]%
  \setKV[GraphicTikzAxis]{#1}%
  \ifboolKV[GraphicTikzAxis]{Lines}{\foreach \x in {#2}{\draw[tkzgrphline] ([yshift=\pflthickgrad]{\x},{\pflOy})--++(0,{-2\pflthickgrad}) ;}}{}%
  \setsepchar{,}%
  \readlist*\LstValX{#2}%
  \readlist*\LstValFmtX{#3}%
  \foreach \i in {1,...,\LstValXlen}{%
    \itemtomacro\LstValX[\i]\mavalx%
    \itemtomacro\LstValFmtX[\i]\mavalfmtx%
    \draw ([yshift={-\pflthickgrad}]{\mavalx},{\pflOy}) node[tkzgrphnode,below,font={\useKV[GraphicTikzAxis]{Font}}] {\mavalfmtx} ;
  }%
}

\NewDocumentCommand\AddYvalues{ O{} m m }{%
  \restoreKV[GraphicTikzAxis]%
  \setKV[GraphicTikzAxis]{#1}%
  \ifboolKV[GraphicTikzAxis]{Lines}{\foreach \y in {#2}{\draw[tkzgrphline] ([xshift=\pflthickgrad]{\pflOx},{\y})--++({-2\pflthickgrad},0) ;}}{}%
  \setsepchar{,}%
  \readlist*\LstValY{#2}%
  \readlist*\LstValFmtY{#3}%
  \foreach \i in {1,...,\LstValYlen}{%
    \itemtomacro\LstValY[\i]\mavaly%
    \itemtomacro\LstValFmtY[\i]\mavalfmty%
    \draw ([xshift={-\pflthickgrad}]{\pflOx},{\mavaly}) node[tkzgrphnode,left,font={\useKV[GraphicTikzAxis]{Font}}] {\mavalfmty} ;
  }%
}

%====FONCTIONS ET COURBES 'classique + interpo + spline'
\defKV[GraphicTikzCourbe]{%
  Step=\def\pflstepcurve{#1},%
  Name=\def\pflnamecurve{#1},
  H=\def\pflhderiv{#1},%
  TraceStyle=\def\pflsplinestyle{#1}
}
\setKVdefault[GraphicTikzCourbe]{%
  Color=black,%
  Start={\pflxmin},%
  End={\pflxmax},%
  Step={},%
  Clip=true,%
  Name={},%
  Trace=false,%
  Tension=0.5,%
  H={},%
  Spline=false,%
  TraceStyle={}
}

\NewDocumentCommand\DefineFunction{ O{} D<>{f} m }{%old version
  \restoreKV[GraphicTikzCourbe]%
  \setKV[GraphicTikzCourbe]{#1}%
  \xintdeffloatfunc #2(x) := #3 ;
  \IfStrEq{\pflstepcurve}{}%
    {%
      \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphicTikzCourbe]{End})-(\useKV[GraphicTikzCourbe]{Start}))/100}}%
    }%
    {}%
  \ifboolKV[GraphicTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \ifboolKV[GraphicTikzCourbe]{Trace}%
      {%
        \path[draw,tkzgrphcurve,\pflsplinestyle,{\useKV[GraphicTikzCourbe]{Color}},name path global=\pflnamecurve] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphicTikzCourbe]{Start}}..[\pflstepcurve]..{\useKV[GraphicTikzCourbe]{End}},{\useKV[GraphicTikzCourbe]{End}})
          \relax
        };
      }%
      {%
        \path[draw=none,tkzgrphcurve,{\useKV[GraphicTikzCourbe]{Color}},name path global=\pflnamecurve] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphicTikzCourbe]{Start}}..[\pflstepcurve]..{\useKV[GraphicTikzCourbe]{End}},{\useKV[GraphicTikzCourbe]{End}})
          \relax
        };
      }%
  \ifboolKV[GraphicTikzCourbe]{Clip}{\end{scope}}{}
}

\NewDocumentCommand\DefineCurve{ O{} D<>{f} m }{%
  \restoreKV[GraphicTikzCourbe]%
  \setKV[GraphicTikzCourbe]{#1}%
  \xintdeffloatfunc #2(x) := #3 ;
  \IfStrEq{\pflstepcurve}{}%
    {%
      \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphicTikzCourbe]{End})-(\useKV[GraphicTikzCourbe]{Start}))/100}}%
    }%
    {}%
  \ifboolKV[GraphicTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \ifboolKV[GraphicTikzCourbe]{Trace}%
      {%
        \path[draw,tkzgrphcurve,\pflsplinestyle,{\useKV[GraphicTikzCourbe]{Color}},name path global=\pflnamecurve] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphicTikzCourbe]{Start}}..[\pflstepcurve]..{\useKV[GraphicTikzCourbe]{End}},{\useKV[GraphicTikzCourbe]{End}})
          \relax
        };
      }%
      {%
        \path[draw=none,tkzgrphcurve,{\useKV[GraphicTikzCourbe]{Color}},name path global=\pflnamecurve] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphicTikzCourbe]{Start}}..[\pflstepcurve]..{\useKV[GraphicTikzCourbe]{End}},{\useKV[GraphicTikzCourbe]{End}})
          \relax
        };
      }%
  \ifboolKV[GraphicTikzCourbe]{Clip}{\end{scope}}{}
}

\NewDocumentCommand\DrawCurve{ O{} D<>{} m }{%
  \restoreKV[GraphicTikzCourbe]%
  \setKV[GraphicTikzCourbe]{#1}%
  \IfStrEq{\pflstepcurve}{}%
    {%
      \xdef\pflstepcurve{\xintfloateval{((\useKV[GraphicTikzCourbe]{End})-(\useKV[GraphicTikzCourbe]{Start}))/100}}%
    }%
    {}%
  \ifboolKV[GraphicTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}
  \IfEq{\pflnamecurve}{}%
    {%
      \draw[tkzgrphcurve,\pflsplinestyle,{\useKV[GraphicTikzCourbe]{Color}}] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
        seq((x,#3),x={\useKV[GraphicTikzCourbe]{Start}}..[\pflstepcurve]..{\useKV[GraphicTikzCourbe]{End}},{\useKV[GraphicTikzCourbe]{End}})
        \relax
      };
    }%
    {%
      \path[draw,tkzgrphcurve,{\useKV[GraphicTikzCourbe]{Color}},name path global=\pflnamecurve] plot[smooth] coordinates {%
        \xintthecoords\xintfloatexpr
        seq((x,#3),x={\useKV[GraphicTikzCourbe]{Start}}..[\pflstepcurve]..{\useKV[GraphicTikzCourbe]{End}},{\useKV[GraphicTikzCourbe]{End}})
        \relax
      };
    }%
  \ifboolKV[GraphicTikzCourbe]{Clip}{\end{scope}}{}
}

%====DERIVATE-PRIMITIVE OF FUNCTION OR SPLINE
\NewDocumentCommand\DrawDerivative{ O{} m }{%
  \restoreKV[GraphicTikzCourbe]%
  \setKV[GraphicTikzCourbe]{#1}%
  \IfStrEq{\pflstepcurve}{}%
    {\xdef\pflstepcurve{\xintfloateval{%
      ((\useKV[GraphicTikzCourbe]{Start})-(\useKV[GraphicTikzCourbe]{End}))/100}}%
    }%
    {}%
  \IfStrEq{\pflhderiv}{}%
    {\ifboolKV[GraphicTikzCourbe]{Spline}%
      {\xdef\pflhderiv{\pflstepcurve}}%      ← ordre du pas pour spline
      {\xdef\pflhderiv{\pflstepcurve}}%      ← petit h pour xint
    }%
    {}%
  \ifboolKV[GraphicTikzCourbe]{Spline}%
    {%
      % Bornes sécurisées
      \xdef\pfldebutderiv{\xintfloateval{(\useKV[GraphicTikzCourbe]{Start})+\pflhderiv}}%
      \xdef\pflfinderiv{\xintfloateval{(\useKV[GraphicTikzCourbe]{End})-\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[GraphicTikzCourbe]{Clip}{\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}%
      \IfEq{\pflnamecurve}{}%
        {%
          \draw[tkzgrphcurve,\pflstylecurve,{\useKV[GraphicTikzCourbe]{Color}}] plot[smooth] coordinates {\pfllistederivspline} ;
        }%
        {%
          \draw[tkzgrphcurve,\pflstylecurve,{\useKV[GraphicTikzCourbe]{Color}}] plot[smooth] coordinates {\pfllistederivspline} ;
        }%
      \ifboolKV[GraphicTikzCourbe]{Clip}{\end{scope}}{}%
    }%
    {%
      % Bornes sécurisées : on recule de h de chaque côté (semble OK)
      \xdef\pfldebutderiv{\xintfloateval{(\useKV[GraphicTikzCourbe]{Start})+\pflhderiv}}%
      \xdef\pflfinderiv  {\xintfloateval{(\useKV[GraphicTikzCourbe]{End})  -\pflhderiv}}%
      % Dérivée numérique centrée
      \xintdeffloatfunc pflnumderiv(x) :=  (#2(x+\pflhderiv) - #2(x-\pflhderiv)) / (2*\pflhderiv);%
      % Tracé
      \ifboolKV[GraphicTikzCourbe]{Clip}%
      {\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}%
      \IfEq{\pflnamecurve}{}%
        {%
          \draw[tkzgrphcurve,\pflstylecurve,{\useKV[GraphicTikzCourbe]{Color}}]
            plot[smooth] coordinates {%
              \xintthecoords\xintfloatexpr
              seq((x,pflnumderiv(x)),
              x=\pfldebutderiv..[\pflstepcurve]..\pflfinderiv,
              \pflfinderiv)
              \relax
            };%
        }%
        {%
          \draw[tkzgrphcurve,\pflstylecurve,{\useKV[GraphicTikzCourbe]{Color}},name path global=\pflnamecurve]
            plot[smooth] coordinates {%
              \xintthecoords\xintfloatexpr
              seq((x,pflnumderiv(x)),
              x=\pfldebutderiv..[\pflstepcurve]..\pflfinderiv,
              \pflfinderiv)
              \relax
            };%
        }%
        \ifboolKV[GraphicTikzCourbe]{Clip}{\end{scope}}{}%
        }%
}

\NewDocumentCommand\DrawPrimitive{ 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[GraphicTikzCourbe]%
  \setKV[GraphicTikzCourbe]{#1}%
  % Pas de tracé par défaut
  \IfStrEq{\pflstepcurve}{}%
    {\xdef\pflstepcurve{\xintfloateval{%
      ((\useKV[GraphicTikzCourbe]{Fin})-(\useKV[GraphicTikzCourbe]{Start}))/100}}}%
    {}%
  % Bornes sécurisées (comme pour \TracerDerivee)
  \xdef\pfldebutprim{\xintfloateval{(\useKV[GraphicTikzCourbe]{Start})+\pflstepcurve/10}}%
  \xdef\pflfinprim  {\xintfloateval{(\useKV[GraphicTikzCourbe]{End})  -\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[GraphicTikzCourbe]{Clip}%
    {\begin{scope}\clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});}{}%
  \IfEq{\pflnamecurve}{}%
    {%
      \draw[tkzgrphcurve,\pflstylecurve,{\useKV[GraphicTikzCourbe]{Color}}]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,pflnumprimitive(x)),
              x=\pfldebutprim..[\pflstepcurve]..\pflfinprim,
              \pflfinprim)
          \relax
        };%
    }%
    {%
      \path[draw,tkzgrphcurve,\pflstylecurve,{\useKV[GraphicTikzCourbe]{Color}},name path global=\pflnamecurve]
        plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,pflnumprimitive(x)),
              x=\pfldebutprim..[\pflstepcurve]..\pflfinprim,
              \pflfinprim)
          \relax
        };%
    }%
  \ifboolKV[GraphicTikzCourbe]{Clip}{\end{scope}}{}%
}

\NewDocumentCommand\DefineLstInterpol{ m O{\myinterpolist} }{%
  \def#2{#1}%
}

\NewDocumentCommand\DefineInterpoCurve{ O{} m }{%
  \restoreKV[GraphicTikzCourbe]%
  \setKV[GraphicTikzCourbe]{#1}%
  \begin{scope}
    \ifboolKV[GraphicTikzCourbe]{Trace}%
      {%
        \path[draw,tkzgrphcurve,{\useKV[GraphicTikzCourbe]{Color}},name path global=\pflnamecurve] plot[smooth,tension={\useKV[GraphicTikzCourbe]{Tension}}] coordinates {#2};
      }%
      {%
        \path[draw=none,tkzgrphcurve,{\useKV[GraphicTikzCourbe]{Color}},name path global=\pflnamecurve] plot[smooth,tension={\useKV[GraphicTikzCourbe]{Tension}}] coordinates {#2};
      }%
  \end{scope}
}

\NewDocumentCommand\DrawInterpoCurve{ O{} m }{%
  %2=liste
  \restoreKV[GraphicTikzCourbe]%
  \setKV[GraphicTikzCourbe]{#1}%
  \begin{scope}
    \draw[tkzgrphcurve,{\useKV[GraphicTikzCourbe]{Color}}] plot [smooth,tension={\useKV[GraphicTikzCourbe]{Tension}}] coordinates {#2} ;
  \end{scope}
}

\NewDocumentCommand\DefineLstSpline{ m O{\mysplinelst} }{%
  \def#2{#1}%
}

\newcommand\tkzextractcoeff[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[GraphicTikzSpline]{%
  Name=\def\pflsplinename{#1},%
  Coeffs=\def\pflsplinecoeffs{#1}
}

\setKVdefault[GraphicTikzSpline]{%
  Name=spline,%
  Color=black,%
  Coeffs=3,%
  Trace=false,%
  Alt=false
}

\NewDocumentCommand\GenerateSpline{ s m m O{\myspline} }{%
  %1=liste
  \setsepchar[.]{§./}%
  \readlist*\SPLlistepoints{#2}%
  %les données
  \def\tmpsplinenumdeb{1}
  \def\tmpsplinenumfin{\SPLlistepointslen}%
  \tkzextractcoeff{#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}{%
    \tkzextractcoeff{#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\DefineSplineCurve{ O{} m D<>{\myspline} }{%
  %1=liste
  \restoreKV[GraphicTikzSpline]%
  \setKV[GraphicTikzSpline]{#1}%
  \GenerateSpline{#2}{\pflsplinecoeffs}[#3]%
  \begin{scope}
    \ifboolKV[GraphicTikzSpline]{Trace}%
      {%
        \path[draw,tkzgrphcurve,{\useKV[GraphicTikzSpline]{Color}},name path global=\pflsplinename] #3 ;
      }%
      {%
        \path[draw=none,tkzgrphcurve,name path global=\pflsplinename] #3 ;
      }%
  \end{scope}
}

\NewDocumentCommand\DefineSpline{ O{} m D<>{\myspline} }{%old version
  %1=liste
  \restoreKV[GraphicTikzSpline]%
  \setKV[GraphicTikzSpline]{#1}%
  \GenerateSpline{#2}{\pflsplinecoeffs}[#3]%
  \begin{scope}
    \ifboolKV[GraphicTikzSpline]{Trace}%
      {%
        \path[draw,tkzgrphcurve,{\useKV[GraphicTikzSpline]{Color}},name path global=\pflsplinename] #3 ;
      }%
      {%
        \path[draw=none,tkzgrphcurve,name path global=\pflsplinename] #3 ;
      }%
  \end{scope}
}

\NewDocumentCommand\DrawSplineCurve{ O{} m D<>{\myspline} }{%
  %1=liste
  \restoreKV[GraphicTikzSpline]%
  \setKV[GraphicTikzSpline]{#1}%
  \ifboolKV[GraphiqueTikzSpline]{Alt}%
    {%
      \GenerateSpline*{#2}{\pflsplinecoeffs}[#3]%
    }%
    {%
      \GenerateSpline{#2}{\pflsplinecoeffs}[#3]%
    }%
  \begin{scope}
    \draw[tkzgrphcurve,{\useKV[GraphicTikzSpline]{Color}}] #3 ;
  \end{scope}
}

\NewDocumentCommand\DrawSpline{ O{} m D<>{\myspline} }{%old version
  %1=liste
  \restoreKV[GraphicTikzSpline]%
  \setKV[GraphicTikzSpline]{#1}%
  \ifboolKV[GraphicTikzSpline]{Alt}%
    {%
      \GenerateSpline*{#2}{\pflsplinecoeffs}[#3]%
    }%
    {%
      \GenerateSpline{#2}{\pflsplinecoeffs}[#3]%
    }%
  \begin{scope}
    \draw[tkzgrphcurve,{\useKV[GraphicTikzSpline]{Color}}] #3 ;
  \end{scope}
}

%===INTERSECTION & ANTÉCÉDENTS
\defKV[GraphicTikzIntersect]{%
  Name=\def\pflintercurves{#1}
}
\setKVdefault[GraphicTikzIntersect]{%
  Name=S,
  Disp=true,
  Color=black,
  DispLine=false,%
  Lines=false,%
  Style=o
}

\NewDocumentCommand\FindIntersections{ O{} m m D<>{\myt} }{%
  \restoreKV[GraphicTikzIntersect]%
  \setKV[GraphicTikzIntersect]{#1}%
  \path[name intersections={of=#2 and #3,name=\pflintercurves,total=\t}] \pgfextra{\xdef#4{\t}};
  \ifboolKV[GraphicTikzIntersect]{Disp}%
    {%
      \xintifboolexpr{#4 == 0}{}%
        {%
          \foreach \i in {1,...,#4}{%
            \ifboolKV[GraphicTikzIntersect]{Lines}%
              {%
                \draw[tkzgrphrange,{\useKV[GraphicTikzIntersect]{Color}}]let \p1 = (\pflintercurves-\i) in (\pflintercurves-\i) -- ({\x1},{\pflOy}) ;
              }%
              {}%
            \MarkPts*[Style={\useKV[GraphicTikzIntersect]{Style}},Color={\useKV[GraphicTikzIntersect]{Color}}]{(\pflintercurves-\i)}
            %\filldraw[{\useKV[GraphicTikzIntersect]{Color}}] (\pflintercurves-\i) circle[tkzgrphpointc] ;
          }
        }%
    }%
    {}%
}

\NewDocumentCommand\FindCounterimage{ O{} m m D<>{\myantec} }{%
  \restoreKV[GraphicTikzIntersect]%
  \setKV[GraphicTikzIntersect]{#1}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \ifboolKV[GraphicTikzIntersect]{DispLine}%
      {%
        \path[draw,{\useKV[GraphicTikzIntersect]{Color}},tkzgrphcurve,name path=tmpanteced] ({\pflxmin},{#3})--({\pflxmax},{#3}) ;
      }%
      {%
        \path[draw=none,tkzgrphcurve,name path=tmpanteced] ({\pflxmin},{#3})--({\pflxmax},{#3}) ;
      }%
    \path[name intersections={of=#2 and tmpanteced,name=\pflintercurves,total=\t}] \pgfextra{\xdef#4{\t}};
    \ifboolKV[GraphicTikzIntersect]{Disp}%
      {%
        \xintifboolexpr{#4 == 0}{}%
        {%
          \foreach \i in {1,...,#4}{%
            \MarkPts*[Style={\useKV[GraphicTikzIntersect]{Style}},Color={\useKV[GraphicTikzIntersect]{Color}}]{(\pflintercurves-\i)}
            %\filldraw[{\useKV[GraphicTikzIntersect]{Color}}] (\pflintercurves-\i) circle[tkzgrphpointc] ;
          }
        }%
      }%
      {}%
  \end{scope}
}

%====INTÉGRALES
%v2 avec modification de la clé [Type=...] ?
\defKV[GraphicTikzIntegr]{%
  Colors=\def\pfldomtikzcolors{#1},%
  Style=\def\pfldomtikzstyle{#1},%
  Opacity=\def\pfldomtikzopac{#1},%
  Hatch=\def\pfldomtikzhatch{#1},%
  Type=\def\pfldomtikztype{#1},%
  Step=\def\pflstepcurve{#1},%
  Bounds=\def\pflintbornes{#1},%
  Junction=\def\pfldomtikzjoin{#1},%
  NameInterpo=\def\pfldomtikznameinterpo{#1},%
  NameInterpoB=\def\pfldomtikznameinterpob{#1},%
  NameSpline=\def\pfldomtikznamespline{#1},%
  NameSplineB=\def\pfldomtikznamesplineb{#1}
}
\setKVdefault[GraphicTikzIntegr]{%
  Colors=gray,%
  Style=fill,%
  Opacity=0.5,%
  Hatch={north west lines},%
  Type=fct,%
  Step={},%
  Junction=bevel,%
  Bounds=abs,%
  Border=true,%
  Spline=false,%
  SplineB=false,%
  NameInterpo={\myinterpo},%
  NameInterpoB={\myinterpoB},%
  NameSpline={\myspline},%
  NameSplineB={\myplineB},%
  Tension=0.5,%
  TensionB=0.5
}

\NewDocumentCommand\DrawIntegral{ 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[GraphicTikzIntegr]% revenir au valeurs par défaut
  \setKV[GraphicTikzIntegr]{#1}% lit les arguments optionnels
  %les couleurs
  \IfSubStr{\pfldomtikzcolors}{/}%
    {%
      \StrCut{\pfldomtikzcolors}{/}{\pfldomtikzcolorbord}{\pfldomtikzcolorfond}
    }%
    {%
      \xdef\pfldomtikzcolorbord{\pfldomtikzcolors}\xdef\pfldomtikzcolorfond{\pfldomtikzcolors}
    }%
  \ifboolKV[GraphicTikzIntegr]{Border}%
    {%
      \tikzset{integralebordtikzstyle/.style={draw=\pfldomtikzcolorbord}}
    }%
    {%
      \tikzset{integralebordtikzstyle/.style={draw=none}}
    }%
  \IfStrEq{\pfldomtikzstyle}{hatch}%
    {%
      \tikzset{integraletikzstyle/.style={tkzgrphline,pattern=\pfldomtikzhatch,pattern color=\pfldomtikzcolorfond,line join=\pfldomtikzjoin}}
    }%
    {}%
  \IfStrEq{\pfldomtikzstyle}{fill}%
    {%
      \tikzset{integraletikzstyle/.style={tkzgrphline,fill=\pfldomtikzcolorfond,fill opacity=\pfldomtikzopac,line join=\pfldomtikzjoin}}
    }%
    {}%
  %extraction des infos x/y
  \IfStrEqCase{\pflintbornes}{%
    {abs}%
    {%
      \xdef\absnoeudA{#5}%
      \xdef\absnoeudB{#6}%
    }%
    {nodes}%
    {%
      \path #5;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudA{\xintfloateval{(\ConvertPtToCm{\macrox})/(\pflxunit)}}%
      \path #6;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudB{\xintfloateval{(\ConvertPtToCm{\macrox})/(\pflxunit)}}%
    }%
    {abs/node}%
    {%
      \xdef\absnoeudA{#5}%
      \path #6;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudB{\xintfloateval{(\ConvertPtToCm{\macrox})/(\pflxunit)}}%
    }%
    {node/abs}%
    {%
      \path #5;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\absnoeudA{\xintfloateval{(\ConvertPtToCm{\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,tkzgrphcurve,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[name intersections={of=#3 and tmpintbornea,name=YYY}] ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] ({\absnoeudA},{\pflOy})-- (YYY-1) ;
      \path[draw=none,tkzgrphcurve,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=#3 and tmpintborneb,name=ZZZ}] ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] ({\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[GraphicTikzIntegr]{Tension}}] coordinates {#3} -- ({\absnoeudB},{\pflOy}) -- cycle ;
      \end{scope}
      \path[draw=none,tkzgrphcurve,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[name intersections={of=tmpintbornea and \pfldomtikznameinterpo,name=YYY}] ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] ({\absnoeudA},{\pflOy})-- (YYY-1) ;
      \path[draw=none,tkzgrphcurve,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=tmpintborneb and \pfldomtikznameinterpo,name=ZZZ}] ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] ({\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,tkzgrphcurve,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,tkzgrphcurve,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[\pfldomtikzcolorbord,tkzgrphline] (YYYA-1)-- (ZZZA-1) ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] (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[GraphicTikzIntegr]{Tension}}] coordinates {#3} -- ({\absnoeudB},{\pflymin}) ;
        \clip ({\absnoeudA},{\pflymax}) -- plot [smooth,tension={\useKV[GraphicTikzIntegr]{TensionB}}] coordinates {#4} -- ({\absnoeudB},{\pflymax}) ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,tkzgrphcurve,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,tkzgrphcurve,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[\pfldomtikzcolorbord,tkzgrphline] (YYYA-1)-- (ZZZA-1) ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] (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,tkzgrphcurve,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[name intersections={of=tmpintbornea and #4,name=ZZZA}] ;
      \path[draw=none,tkzgrphcurve,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=tmpintborneb and #4,name=ZZZB}] ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] ({\absnoeudA},{\xintfloateval{subs(#3,x=\absnoeudA)}})-- (ZZZA-1) ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] ({\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,tkzgrphcurve,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[name intersections={of=tmpintbornea and #3,name=ZZZA}] ;
      \path[draw=none,tkzgrphcurve,name path=tmpintborneb] ({\absnoeudB},{\pflymin})--({\absnoeudB},{\pflymax}) ;
      \path[name intersections={of=tmpintborneb and #3,name=ZZZB}] ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] ({\absnoeudA},{\xintfloateval{subs(#4,x=\absnoeudA)}})-- (ZZZA-1) ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] ({\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[GraphicTikzIntegr]{TensionB}}] coordinates {#4} -- ({\absnoeudB},{\pflymax}) ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,tkzgrphcurve,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[draw=none,tkzgrphcurve,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[\pfldomtikzcolorbord,tkzgrphline] ({\absnoeudA},{\xintfloateval{subs(#3,x=\absnoeudA)}})-- (ZZZAA-1) ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] ({\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[GraphicTikzIntegr]{Tension}}] coordinates {#3} -- ({\absnoeudB},{\pflymin}) ;
        \filldraw[integraletikzstyle,integralebordtikzstyle,#2] ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
      \end{scope}
      \path[draw=none,tkzgrphcurve,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;
      \path[draw=none,tkzgrphcurve,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[\pfldomtikzcolorbord,tkzgrphline] ({\absnoeudA},{\xintfloateval{subs(#4,x=\absnoeudA)}})-- (ZZZAA-1) ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] ({\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[GraphicTikzIntegr]{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,tkzgrphcurve,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;%borne inf
      \path[draw=none,tkzgrphcurve,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[\pfldomtikzcolorbord,tkzgrphline] (YYYKAA-1)-- (ZZZKAA-1) ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] (YYYKBB-1)-- (ZZZKBB-1) ;
    }%
    {}%
  \IfStrEq{\pfldomtikztype}{spl/itp}%
    {%
      \begin{scope}
        \clip ({\absnoeudA},{\pflymin}) rectangle ({\absnoeudB},{\pflymax}) ;
        \clip ({\absnoeudA},{\pflymax}) -- plot [smooth,tension={\useKV[GraphicTikzIntegr]{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,tkzgrphcurve,name path=tmpintbornea] ({\absnoeudA},{\pflymin})--({\absnoeudA},{\pflymax}) ;%borne inf
      \path[draw=none,tkzgrphcurve,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[\pfldomtikzcolorbord,tkzgrphline] (YYYKAA-1)-- (ZZZKAA-1) ;
      \draw[\pfldomtikzcolorbord,tkzgrphline] (YYYKBB-1)-- (ZZZKBB-1) ;
    }%
    {}%
}

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

% %====STATS À 2 VARIABLES
\defKV[GraphicTikzRegLin]{%
  Rounds=\def\pflarrondisreglin{#1},
  Name=\def\pflnamereglin{#1},
  NameParab=\def\pflnameregquad{#1},
  Start=\def\pflreglinmin{#1},
  End=\def\pflreglinmax{#1}
}
\setKVdefault[GraphicTikzRegLin]{
  ColorScatter=black,
  ColorLine=black,
  ColorParab=black,
  Rounds={},
  Start={\pflxmin},
  End={\pflxmax},
  Name=reglin,%
  NameParab=quadreg,%
  DrawLine=false,%
  DrawParab=false,%
  Style=o
}

\NewDocumentCommand\DrawScatter{ O{} D<>{d} m m }{%
  \useKVdefault[GraphicTikzRegLin]%
  \setKV[GraphicTikzRegLin]{#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%
    \MarkPts*[Style={\useKV[GraphicTikzRegLin]{Style}},Color={\useKV[GraphicTikzRegLin]{ColorScatter}}]{(\tmpmavalx,\tmpmavaly)}%
  }
  %droite de régression
  \ifboolKV[GraphicTikzRegLin]{DrawLine}%
    {%
      %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[tkzgrphcurve,{\useKV[GraphicTikzRegLin]{ColorLine}},name path global=\pflnamereglin,samples=2,domain=\pflreglinmin:\pflreglinmax] plot (\x,{\tmpcoeffreglina*\x+\tmpcoeffreglinb}) ;
      \end{scope}
    }%
    {}%
  \ifboolKV[GraphicTikzRegLin]{DrawParab}%
    {%
      %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[tkzgrphcurve,{\useKV[GraphicTikzRegLin]{ColorParab}},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\DrawRegression{ O{} D<>{curvajust} 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}%
      \DefineFunction[#1,Trace]<#2>{\linrega*x+\linregb}%
    }%
    {}%
  \IfStrEq{#3}{quad}%
    {%
      \xintquadreg[round={#4}]{#5}{#6}%
      \DefineFunction[#1,Trace]<#2>{\quadrega*x^2+\quadregb*x+\quadregc}%
    }%
    {}%
  \IfStrEq{#3}{pow}%
    {%
      \xintpowreg[round={#4}]{#5}{#6}%
      \DefineFunction[#1,Trace]<#2>{\powrega*x^(\powregb)}%
    }%
    {}%
  \IfStrEq{#3}{expab}%
    {%
      \xintexpabreg[round={#4}]{#5}{#6}%
      \DefineFunction[#1,Trace]<#2>{\expabrega*(\expabregb)^x}%
    }%
    {}%
  \IfStrEq{#3}{hyp}%
    {%
      \xinthypreg[round={#4}]{#5}{#6}%
      \DefineFunction[#1,Trace]<#2>{\hyprega+(\hypregb)/x}%
    }%
    {}%
  \IfStrEq{#3}{log}%
    {%
      \xintlogreg[round={#4}]{#5}{#6}%
      \DefineFunction[#1,Trace]<#2>{\logrega+(\logregb)*log(x)}%
    }%
    {}%
  \IfStrEq{#3}{exp}%
    {%
      \xintexpreg[round={#4}]{#5}{#6}%
      \DefineFunction[#1,Trace]<#2>{exp(\exprega*x+\expregb)}%
    }%
    {}%
  \IfStrEq{#3}{expalt}%
    {%
      \xintexpreg[Alt,round={#4}]{#5}{#6}%
      \DefineFunction[#1,Trace]<#2>{\expregb*exp(\exprega*x)}%
    }%
    {}%
  \IfStrEq{#3}{cub}%
    {%
      \xintcubreg[round={#4}]{#5}{#6}%
      \DefineFunction[#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}%
      \DefineFunction[#1,Trace]<#2>{\expoffset+\expregoffb*exp(\expregoffa*x)}%
    }%
    {}%
}
\fi

%===IMAGES & ANTÉCÉDENTS
\defKV[GraphicTikzImg]{
  Colors=\def\pflimgcolors{#1},%
  Name=\def\pflantecednoms{#1}%
}

\setKVdefault[GraphicTikzImg]{
  Colors=black,%
  Lines=false,%
  Spline=false,%
  Name={},%
  Style=o
}

\NewDocumentCommand\DefineRange{ O{} m m }{%
  \useKVdefault[GraphicTikzImg]%
  \setKV[GraphicTikzImg]{#1}%
  \ifboolKV[GraphicTikzImg]{Spline}%
    {%
      \path[draw=none,tkzgrphcurve,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\DrawRanges{ O{} m m }{%
  \useKVdefault[GraphicTikzImg]%
  \setKV[GraphicTikzImg]{#1}%
  \IfSubStr{\pflimgcolors}{/}%
    {%
      \StrCut{\pflimgcolors}{/}{\pflimgcolorpt}{\pflimgcolorline}
    }%
    {%
      \xdef\pflimgcolorpt{\pflimgcolors}\xdef\pflimgcolorline{\pflimgcolors}
    }%
  \ifboolKV[GraphicTikzImg]{Spline}%
    {%
      \foreach \i in {#3}{%
        \path[draw=none,tkzgrphcurve,name path=tmpimage] ({\i},{\pflymin})--({\i},{\pflymax}) ;
        \path[name intersections={of=#2 and tmpimage,name=ZZ}] ;
        \ifboolKV[GraphicTikzImg]{Lines}%
          {%
            \draw[\pflimgcolorline,tkzgrphrange] let \p1 = (ZZ-1) in ({\x1},{\pflOy}) |- ({\pflOx},{\y1}) ;
          }%
          {}%
        \MarkPts*[Style={\useKV[GraphicTikzImg]{Style}},Color=\pflimgcolorpt]{(ZZ-1)}
        %\filldraw[\pflimgcolorpt] (ZZ-1) circle[radius=2pt] ;
      }
    }%
    {%
      \foreach \i in {#3}{%
        \xdef\tmpresimg{\xintfloateval{#2(\i)}}%
        \ifboolKV[GraphicTikzImg]{Lines}%
          {%
            \draw[\pflimgcolorline,tkzgrphrange] ({\i},{\pflOy}) |- ({\pflOx},{\tmpresimg}) ;
          }%
          {}%
        \MarkPts*[Style={\useKV[GraphicTikzImg]{Style}},Color=\pflimgcolorpt]{({\i},{\tmpresimg})}
        %\filldraw[\pflimgcolorpt] ({\i},{\tmpresimg}) circle[radius=2pt] ;
      }%
    }%
}

\NewDocumentCommand\DrawCounterimage{ O{} m m }{%avec le nom de la courbe...
  \useKVdefault[GraphicTikzImg]%
  \setKV[GraphicTikzImg]{#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,tkzgrphcurve,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[GraphicTikzImg]{Lines}%
          {%
            \draw[\pflimgcolorline,tkzgrphcounterimage] ({\pflxmin},{#3})--({\pflxmax},{#3}) ;
          }%
          {}%
        \foreach \i in {1,...,\tmptotanteced}{%
          \IfStrEq{\pflantecednoms}{}%
            {}%
            {%
              \coordinate (\pflantecednoms-\i) at (ZZ-\i) ;
            }%
          \ifboolKV[GraphicTikzImg]{Lines}%
            {%
              \draw[\pflimgcolorline,tkzgrphrange] let \p1 = (ZZ-\i) in (ZZ-\i) -- ({\x1},{\pflOy}) ;
            }%
            {}%
          \MarkPts*[Style={\useKV[GraphicTikzImg]{Style}},Color=\pflimgcolorpt]{(ZZ-\i)}
          %\filldraw[\pflimgcolorpt] (ZZ-\i) circle[radius=2pt] ;
        }%
      }%
  \end{scope}
}

%===NOMBRE DÉRIVÉ ET TANGENTE (EXPÉRIEMENTAL)
\NewDocumentCommand\CalcDerivate{ 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[GraphicTikzTgte]{%
  Colors=\def\pfltgttikzcolors{#1},%
  OffsetL=\def\pfltgttikzkl{#1},%
  OffsetR=\def\pfltgttikzkr{#1},%
  h=\def\pfltgttikzh{#1},%
  Direction=\def\pfltgttikzsens{#1},%
  Delta=\def\tmptgtedelta{#1}
}
\setKVdefault[GraphicTikzTgte]{%
  Colors=black,%
  OffsetL=1,%
  OffsetR=1,%
  DispPt=false,%
  Spline=false,%
  h=0.1,%
  Direction=lr,%
  Node=false,%
  Delta=0.01,%
  Style=o
}

\NewDocumentCommand\DrawTangent{ O{} m m D<>{} }{%
  \restoreKV[GraphicTikzTgte]%
  \setKV[GraphicTikzTgte]{#1}%
  %en fonction de la gestion de l'abscisse
  \ifboolKV[GraphicTikzTgte]{Node}%
    {%
      \path #3;
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\pfltgttikzx{\xintfloateval{(\ConvertPtToCm{\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[GraphicTikzTgte]{Spline}%
    {%
        \path[name path=tmpimage] ({\pfltgttikzx},{\pflymin})--({\pfltgttikzx},{\pflymax}) ;
        \path[name intersections={of=#2 and tmpimage,name=TANp}] ;
        \IfStrEq{\pfltgttikzsens}{lr}%
          {%
            \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}{l}%
          {%
            \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}{r}%
          {%
            \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{(\ConvertPtToCm{\macrox})/(\pflxunit)}}%
        \xdef\tzTANLLY{\xintfloateval{(\ConvertPtToCm{\macroy})/(\pflyunit)}}%
        \path (RRpoint);
        \pgfgetlastxy{\macrox}{\macroy}%
        \xdef\tzTANRRX{\xintfloateval{(\ConvertPtToCm{\macrox})/(\pflxunit)}}%
        \xdef\tzTANRRY{\xintfloateval{(\ConvertPtToCm{\macroy})/(\pflyunit)}}%
        \def\tztangentLFn{(\tzTANRRY-\tzTANLLY)/(\tzTANRRX-\tzTANLLX)*(\x-\tzTANLLX)+\tzTANLLY}%
        \begin{scope}
          \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
          \draw[tkzgrphline,\pfltgttikzline,domain=\tmptgtdeb:\tmptgtfin,samples=2,#4] plot (\x,{\tztangentLFn}) ;
        \end{scope}
    }%
    {%
      \IfStrEq{\pfltgttikzsens}{l}%
        {%
          \CalcDerivate*{#2}{\pfltgttikzx}{\pfltgttikzh}%
        }%
        {%
          \CalcDerivate{#2}{\pfltgttikzx}{\pfltgttikzh}%
        }%
      \begin{scope}
        \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
        \draw[tkzgrphline,\pfltgttikzline,#4] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,\TmpResNbDeriv*(x-(\pfltgttikzx))+#2(\pfltgttikzx)),x=\tmptgtdeb,\tmptgtfin)
          \relax
        };
      \end{scope}
    }%
  \ifboolKV[GraphicTikzTgte]{DispPt}%
    {%
      \ifboolKV[GraphicTikzTgte]{Spline}%
        {%
          \MarkPts*[Style={\useKV[GraphicTikzTgte]{Style}},Color=\pfltgttikzpoint]{(TANp-1)}
          %\filldraw[] (TANp-1) circle[tkzgrphpointc] ;
        }%
        {%
          \xdef\tmpimgtgt{\xintfloateval{#2(\pfltgttikzx)}}%
          \MarkPts*[Style={\useKV[GraphicTikzTgte]{Style}},Color=\pfltgttikzpoint]{({\pfltgttikzx},\tmpimgtgt)}
          %\filldraw[\pfltgttikzpoint] ({\pfltgttikzx},\tmpimgtgt) circle[tkzgrphpointc] ;
        }%
    }%
    {}%
}

%====loi normale
\defKV[GraphicTikzGaussienne]{%
  Step=\def\pflgaussstep{#1},%
  Name=\def\pflgaussname{#1}
}

\setKVdefault[GraphicTikzGaussienne]{%
  Name=gaussian,%
  Color=black,%
  Trace=false,%
  Step={},%
  Start={\pflxmin},%
  End={\pflxmax}
}

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

\NewDocumentCommand\DrawStandartDeviation{ O{} m }{%
  %1=options
  %2=mu
  %3=sigma
  \restoreKV[GraphicTikzGaussienne]%
  \setKV[GraphicTikzGaussienne]{#1}%
  \IfStrEq{\pflgaussstep}{}%
    {%
      \xdef\pflgaussstep{\xintfloateval{((\useKV[GraphicTikzGaussienne]{End})-(\useKV[GraphicTikzGaussienne]{Start}))/100}}%
    }%
    {}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \draw[tkzgrphcurve,{\useKV[GraphicTikzGaussienne]{Color}}]  plot[smooth] coordinates {%
      \xintthecoords\xintfloatexpr
      seq((x,#2),x={\useKV[GraphicTikzGaussienne]{Start}}..[\pflgaussstep]..{\useKV[GraphicTikzGaussienne]{End}},{\useKV[GraphicTikzGaussienne]{End}})
      \relax
    } ;
  \end{scope}
}

\NewDocumentCommand\DefineKhiSquared{ O{} D<>{khi} m }{%
  %1=options
  %2=mu
  %3=sigma
  \restoreKV[GraphicTikzGaussienne]%
  \setKV[GraphicTikzGaussienne]{#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[GraphicTikzGaussienne]{End})-(\useKV[GraphicTikzGaussienne]{Start}))/100}}%
  }%
  {}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \ifboolKV[GraphicTikzGaussienne]{Trace}%
      {%
        \path[draw,tkzgrphcurve,{\useKV[GraphicTikzGaussienne]{Color}},name path global=\pflgaussname] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphicTikzGaussienne]{Start}}..[\pflgaussstep]..{\useKV[GraphicTikzGaussienne]{End}},{\useKV[GraphicTikzGaussienne]{End}})
          \relax
        } ;
      }%
      {%
        \path[draw=none,tkzgrphcurve,name path global=\pflgaussname]  plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphicTikzGaussienne]{Start}}..[\pflgaussstep]..{\useKV[GraphicTikzGaussienne]{End}},{\useKV[GraphicTikzGaussienne]{End}})
          \relax
        } ;
      }%
  \end{scope}
}

\NewDocumentCommand\DrawKhiSquared{ O{} m }{%
  %1=options
  %2=mu
  %3=sigma
  \restoreKV[GraphicTikzGaussienne]%
  \setKV[GraphicTikzGaussienne]{#1}%
  \IfStrEq{\pflgaussstep}{}%
    {%
      \xdef\pflgaussstep{\xintfloateval{((\useKV[GraphicTikzGaussienne]{End})-(\useKV[GraphicTikzGaussienne]{Start}))/100}}%
    }%
    {}%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax});
    \draw[tkzgrphcurve,{\useKV[GraphicTikzGaussienne]{Color}}]  plot[smooth] coordinates {%
      \xintthecoords\xintfloatexpr
      seq((x,#2),x={\useKV[GraphicTikzGaussienne]{Start}}..[\pflgaussstep]..{\useKV[GraphicTikzGaussienne]{End}},{\useKV[GraphicTikzGaussienne]{End}})
      \relax
    } ;
  \end{scope}
}

%====droite
\defKV[GraphicTikzLine]{%
  Name=\def\pfldroitename{#1}
}

\setKVdefault[GraphicTikzLine]{%
  Slope=false,%
  Color=black,%
  Start={\pflxmin},%
  End={\pflxmax},%
  Name={}
}

\NewDocumentCommand\DrawLine{ O{} m m D<>{} }{%
  \restoreKV[GraphicTikzLine]%
  \setKV[GraphicTikzLine]{#1}%
  %1er point
  \path #2;%
  \pgfgetlastxy{\macrox}{\macroy}%
  \xdef\pfldtetikzxA{\xintfloateval{(\ConvertPtToCm{\macrox})/(\pflxunit)}}%
  \xdef\pfldtetikzyA{\xintfloateval{(\ConvertPtToCm{\macroy})/(\pflyunit)}}%
  %2ème point si besoin
  \ifboolKV[GraphicTikzLine]{Slope}%
    {%
      \xdef\pfldtepente{\xintfloateval{#3}}%
    }%
    {%
      \path #3;%
      \pgfgetlastxy{\macrox}{\macroy}%
      \xdef\pfldtetikzxB{\xintfloateval{(\ConvertPtToCm{\macrox})/(\pflxunit)}}%
      \xdef\pfldtetikzyB{\xintfloateval{(\ConvertPtToCm{\macroy})/(\pflyunit)}}%
      \xdef\pfldtepente{\xintfloateval{(\pfldtetikzyB-\pfldtetikzyA)/(\pfldtetikzxB-\pfldtetikzxA)}}%
    }%
  \begin{scope}
    \clip ({\pflxmin},{\pflymin}) rectangle ({\pflxmax},{\pflymax}) ;
    \xintifboolexpr{\pfldtetikzxA == \pfldtetikzxB}%
      {%
        \IfEq{\pfldroitename}{}%
          {%
            \draw[tkzgrphline,{\useKV[GraphicTikzLine]{Color}},#4] (\pfldtetikzxA,\pflymin) -- (\pfldtetikzxA,\pflymax) ;
          }%
          {%
            \draw[tkzgrphline,{\useKV[GraphicTikzLine]{Color}},#4,name path global=\pfldroitename] (\pfldtetikzxA,\pflymin) -- (\pfldtetikzxA,\pflymax) ;
          }%
      }%
      {%
        \IfEq{\pfldroitename}{}%
          {%
            \draw[tkzgrphline,{\useKV[GraphicTikzLine]{Color}},domain={\useKV[GraphicTikzLine]{Start}}:{\useKV[GraphicTikzLine]{End}},samples=2,#4] plot (\x,{\pfldtepente*(\x-\pfldtetikzxA)+\pfldtetikzyA}) ;
          }%
          {%
            \draw[tkzgrphline,{\useKV[GraphicTikzLine]{Color}},domain={\useKV[GraphicTikzLine]{Start}}:{\useKV[GraphicTikzLine]{End}},samples=2,name path global=\pfldroitename,#4] plot (\x,{\pfldtepente*(\x-\pfldtetikzxA)+\pfldtetikzyA}) ;
          }%
      }%
  \end{scope}
}

%====asymptote
\NewDocumentCommand\DrawAsymptote{ O{} m D<>{} }{%
  \restoreKV[GraphicTikzLine]%
  \setKV[GraphicTikzLine]{#1}%
  %tracé
  \draw[tkzgrphline,{\useKV[GraphicTikzLine]{Color}},#3] ({#2},{\pflymin})--({#2},{\pflymax}) ;
}

%====minmax
\defKV[GraphicTikzMinMax]{%
  Pas=\def\pflminmaxstep{#1},%
  Method=\def\pflminmaxmethode{#1},%
  Coeffs=\def\pflminmaxcoeffs{#1}
}
\setKVdefault[GraphicTikzMinMax]{%
  Start={\pflxmin},%
  End={\pflxmax},%
  Pas={},%
  Tension=0.5,%
  Method=function,%
  Coeffs=3
}

\NewDocumentCommand\FindMax{ O{} m O{c-max} }{%
  %1=clés
  %2=paramètres en fonction de [Methode]
  \restoreKV[GraphicTikzMinMax]%
  \setKV[GraphicTikzMinMax]{#1}%
  \IfStrEq{\pflstepcurve}{}%
    {%
      \xdef\pflminmaxstep{\xintfloateval{((\useKV[GraphicTikzMinMax]{End})-(\useKV[GraphicTikzMinMax]{Start}))/100}}%
    }%
    {}%
  \begin{scope}[bezier bounding box,local bounding box=bbtmpmax]
    \IfStrEq{\pflminmaxmethode}{function}%
      {%
        \path[draw=none,name path=curvetmpmax] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphicTikzMinMax]{Start}}..[\pflstepcurve]..{\useKV[GraphicTikzMinMax]{End}},{\useKV[GraphicTikzMinMax]{End}})
          \relax
        };
      }%
      {}%
    \IfStrEq{\pflminmaxmethode}{interpo}%
      {%
        \path[draw=none,name path=curvetmpmax] plot[smooth,tension={\useKV[GraphicTikzMinMax]{Tension}}] coordinates {#2};
      }%
      {}%
    \IfStrEq{\pflminmaxmethode}{spline}%
      {%
        \GenerateSpline{#2}{\pflminmaxcoeffs}[\tmpsplineminmax]%
        \path[draw=none,name path=curvetmpmax] \tmpsplineminmax ;
      }%
      {}%
    %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}] ;
    \coordinate (#3) at ($0.5*(#3-1)+0.5*(#3-2)+(0,0.25\pgflinewidth)$) ;
  \end{scope}
}

\NewDocumentCommand\FindMin{ O{} m O{c-min} }{%
  %1=clés
  %2=paramètres en fonction de [Methode]
  \restoreKV[GraphicTikzMinMax]%
  \setKV[GraphicTikzMinMax]{#1}%
  \IfStrEq{\pflstepcurve}{}%
    {%
      \xdef\pflminmaxstep{\xintfloateval{((\useKV[GraphicTikzMinMax]{End})-(\useKV[GraphicTikzMinMax]{Start}))/100}}%
    }%
    {}%
  \begin{scope}[bezier bounding box,local bounding box=bbtmpmin]
    \IfStrEq{\pflminmaxmethode}{function}%
      {%
        \path[draw=none,name path=curvetmpmin] plot[smooth] coordinates {%
          \xintthecoords\xintfloatexpr
          seq((x,#2(x)),x={\useKV[GraphicTikzMinMax]{Start}}..[\pflstepcurve]..{\useKV[GraphicTikzMinMax]{End}},{\useKV[GraphicTikzMinMax]{End}})
          \relax
        };
      }%
      {}%
    \IfStrEq{\pflminmaxmethode}{interpo}%
      {%
        \path[draw=none,name path=curvetmpmin] plot[smooth,tension={\useKV[GraphicTikzMinMax]{Tension}}] coordinates {#2};
      }%
      {}%
    \IfStrEq{\pflminmaxmethode}{spline}%
      {%
        \GenerateSpline{#2}{\pflminmaxcoeffs}[\tmpsplineminmax]%
        \path[draw=none,name path=curvetmpmin] \tmpsplineminmax ;
      }%
      {}%
    %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}] ;
    \coordinate (#3) at ($0.5*(#3-1)+0.5*(#3-2)+(0,-0.25\pgflinewidth)$) ;
  \end{scope}
}

%====TEXTES
\defKV[GraphicTikzNode]{%
  Color=\def\pflnodecol{#1},%
  Font=\def\pflnodefonte{#1},%
  Position=\def\pfnodepos{#1}
}
\setKVdefault[GraphicTikzNode]{%
  Color=black,%
  Start={\normalfont\normalsize},%
  Position={}
}
\NewDocumentCommand\DrawTxt{ O{} m m }{%
  \restoreKV[GraphicTikzNode]%
  \setKV[GraphicTikzNode]{#1}%
  \draw #2 node[tkzgrphnode,font=\pflnodefonte,text=\pflnodecol,\pfnodepos] {#3} ;
}

%====MONTE CARLO
\defKV[GraphicTikzmontecarlo]{%
  Colors=\def\graphtikzmccols{#1},%
  BoundsX=\def\graphtikzmcxbornes{#1},%
  BoundsY=\def\graphtikzmcybornes{#1}
}

\setKVdefault[GraphicTikzmontecarlo]{%
  Colors={blue/red},%
  BoundsX={\pflxmin,\pflxmax},%
  BoundsY={\pflymin,\pflymax}
}

\NewDocumentCommand\SimulateMonteCarlo{ O{} D<>{f} m O{\nbptsmcok} O{\nbptsmcko} }{%
  \restoreKV[GraphicTikzmontecarlo]%
  \setKV[GraphicTikzmontecarlo]{#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[\tmpMCcolOK] (\tmpMCrandX,\tmpMCrandY) circle[tkzgrphpointmc] ;
      }%
      {%
        \xdef#5{\xinteval{#5+1}}%
        \filldraw[\tmpMCcolKO] (\tmpMCrandX,\tmpMCrandY) circle[tkzgrphpointmc] ;
      }%
  }%
}

%====linear inequality [en]
\defKV[GraphiquetikzInegLinEN]{%
  opacity=\def\pflineglinopac{#1},%
  name=\def\pflineglinname{#1},%
  style=\def\pflineglintikzstyle{#1},%
  hatch=\def\pflineglintikzhatch{#1}
}

\setKVdefault[GraphiquetikzInegLinEN]{%
  opacity=0.25,%
  color=black,%
  style=hatch,%
  hatch={north west lines},%
  swap=false,%
  dashedifstrict=true
}

\NewDocumentCommand\LinearInequality{O{}D<>{f}mm}{%
  \restoreKV[GraphiquetikzInegLinEN]%
  \setKV[GraphiquetikzInegLinEN]{#1}%
  %style for filling... ?
  \IfStrEq{\pflineglintikzstyle}{hatch}%
    {%
      \tikzset{dominegallintikzstyle/.style={draw=none,pattern=\pflineglintikzhatch,pattern color={\useKV[GraphiquetikzInegLinEN]{color}},line join=bevel}}
    }%
    {}%
  \IfStrEq{\pflineglintikzstyle}{fill}%
    {%
      \tikzset{dominegallintikzstyle/.style={draw=none,fill={\useKV[GraphiquetikzInegLinEN]{color}},fill opacity=\pflineglinopac,line join=bevel}}
    }%
    {}%
  \ifboolKV[GraphiquetikzInegLinEN]{dashedifstrict}%
    {%
      \IfSubStr{#4}{=}%
        {%
          \tikzset{stylelinelinineq/.style={tkzgrphline}}%
        }%
        {%
          \tikzset{stylelinelinineq/.style={tkzgrphlinedashed}}%
        }%
    }%
    {%
      \tikzset{stylelinelinineq/.style={tkzgrphline}}%
    }%
  %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[GraphiquetikzInegLinEN]{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,{\useKV[GraphiquetikzInegLinEN]{color}}] ({-(\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,{\useKV[GraphiquetikzInegLinEN]{color}}] ({\pflxmin},{(-\coeffc-\coeffa*(\pflxmin))/(\coeffb)}) -- ({\pflxmax},{(-\coeffc-\coeffa*(\pflxmax))/(\coeffb)}) ;
      \end{scope}
    }%
}

%====ALIASES FR->EN (clés FR, conversion complète à venir...)
%---coniques
\NewCommandCopy\DrawEllipse\TracerEllipse
\NewCommandCopy\DrawParabola\TracerParabole
\NewCommandCopy\DrawHyperbola\TracerHyperbole
\NewCommandCopy\DisplayElementsEllipse\AfficherElementsEllipse
\NewCommandCopy\DisplayElementsParabola\AfficherElementsParabole
\NewCommandCopy\DisplayElementsHyperbola\AfficherElementsHyperbole
%---courbes paramétriques et polaires
\NewCommandCopy\DrawParamCurve\TracerCourbeParam
\NewCommandCopy\DefineParamCurve\DefinirCourbeParam
\NewCommandCopy\DrawPolarCurve\TracerCourbePol
\NewCommandCopy\DefinePolarCurve\DefinirCourbePol
%---voisinage / discontinuités
\NewCommandCopy\DisplayNeighborhood\AfficherVoisinage
\NewCommandCopy\DisplayDiscontinuities\AfficherPtsDiscont
%---stats / probas
\NewCommandCopy\DrawBinomialHisto\TracerHistoBinomiale
\NewCommandCopy\DrawScatterSeq\TracerNuageSuite
%---divers
\NewCommandCopy\DrawCurveECC\TracerCourbeECC
\NewCommandCopy\DrawWebRecurrence\TracerToileRecurrence
\NewCommandCopy\GenerateLagrangePolynomial\GenererPolynomeLagrange
\NewCommandCopy\MarkPtsLagrange\MarquerPtsLagrange

\endinput