%%%%
% Scratch
%%%%
\def\filedateScratch{2026/04/22}%
\def\fileversionScratch{0.1a}%
\message{-- \filedateScratch\space v\fileversionScratch}%
%
\newlength{\longbarreheight}
\setlength{\longbarreheight}{2.1ex+3pt}

\newlength{\longbarredepth}
\setlength{\longbarredepth}{0.9ex+3pt}
\def\longbarre{\vrule height\longbarreheight depth\longbarredepth width0pt}%

\def\barre{\vrule height2.1ex depth.9ex width0pt}%
\def\demibarre{\vrule height1.4ex depth.6ex width0pt}%

\setKVdefault[Scratch]{ModeleCouleur=5,Impression=false,Numerotation=false,Echelle=1,Naturel=false,Dys=false,Largeur={},White=false}%

\NewDocumentEnvironment{Scratch}{o +b}{%
  \useKVdefault[Scratch]%
  \setKV[Scratch]{#1}%
  \ifPfCPfMScratchDys\relax\setKV[Scratch]{Dys}\fi
  \mplibforcehmode%
  \ifboolKV[Scratch]{Naturel}{}{\myfontScratch}%
  \begin{mplibcode}%
    defaultcolormodel:=\useKV[Scratch]{ModeleCouleur};
    boolean Naturel,ScratchDys,Tauxprint;
    Naturel=\useKV[Scratch]{Naturel};
    Echelle=\useKV[Scratch]{Echelle};
    Tauxprint=\useKV[Scratch]{White};
    if Naturel: input PfCPseudo; print:=true; else: input PfCScratchMinimal;input PfCScratch; print:=\useKV[Scratch]{Impression}; fi;
    picture vide;
    vide=OvalNb("\phantom{100}");
    if Tauxprint:coefprint:=1 fi;
    NumeroteLignes:=\useKV[Scratch]{Numerotation};%
    if \useKV[Scratch]{Dys}:
      print:=true;
      Echelle:=1;
    fi;
    if defaultcolormodel=7:
      cmykcolor white,White,CoulLignes;
      coefprint:=1-coefprint;
      White=(0,0,0,1);
      white=(0,0,0,0);
      CoulLignes=(0,0,0,1);
    fi;
    #2;%
    \ifemptyKV[Scratch]{Largeur}{}{%
      toto=\mpdim{\useKV[Scratch]{Largeur}};
      Echelle:=toto/abs(lrcorner currentpicture - llcorner currentpicture);  
    }
    if Echelle<>1:
      picture recap;%
      recap:=currentpicture scaled Echelle;%
      currentpicture:=nullpicture;%
      draw recap;%
    fi;
  \end{mplibcode}%
}{}%

\NewDocumentCommand\ScratchEnLigne{sO{}m}{%
  \useKVdefault[Scratch]%
  \setKV[Scratch]{#2}%
  \IfBooleanTF{#1}{%
    \raisebox{-\PfCScratchDepth}{%
      \begin{Scratch}[Echelle=\fpeval{(\PfCScratchHeight+\PfCScratchDepth)/1cm},#2]%
        Placer #3;
      \end{Scratch}%
    }%  
  }{%
    \raisebox{\fpeval{-0.5\height+0.3ex*\useKV[Scratch]{Echelle}}pt}{%
      \begin{Scratch}[#2]
        Placer #3;
      \end{Scratch}%
    }%
  }%
}%