%%%
% Conversion
%%%
\def\filedateConversion{2025/05/27}%
\def\fileversionConversion{0.1a}%
\message{-- \filedateConversion\space v\fileversionConversion}%

\setKVdefault[ClesConversion]{Longueur,Aire=false,Vol=false,Masse=false,Capa=false,Sans=false,Complete={},Coef=2}%

\newlength{\PfCConversionLongueur}%

\makeatletter
\NewDocumentCommand\PfC@ChoixUniteD{m}{%
  \IfStrEqCase{#1}{%
    {G}{\DeclareSIUnit{\TempoPrefixeD}{\giga}\edef\PfC@ExposantD{9}}%
    {M}{\DeclareSIUnit{\TempoPrefixeD}{\mega}\edef\PfC@ExposantD{6}}%
    {t}{\DeclareSIUnit{\TempoPrefixeD}{\tonne}\edef\PfC@ExposantD{6}}%
    {q}{\DeclareSIUnit{\TempoPrefixeD}{\quintal}\edef\PfC@ExposantD{5}}%
    {k}{\DeclareSIUnit{\TempoPrefixeD}{\kilo}\edef\PfC@ExposantD{3}}%
    {h}{\DeclareSIUnit{\TempoPrefixeD}{\hecto}\edef\PfC@ExposantD{2}}%
    {da}{\DeclareSIUnit{\TempoPrefixeD}{\deca}\edef\PfC@ExposantD{1}}%
    {u}{\DeclareSIUnit{\TempoPrefixeD}{}\edef\PfC@ExposantD{0}}%
    {d}{\DeclareSIUnit{\TempoPrefixeD}{\deci}\edef\PfC@ExposantD{-1}}%
    {c}{\DeclareSIUnit{\TempoPrefixeD}{\centi}\edef\PfC@ExposantD{-2}}%
    {m}{\DeclareSIUnit{\TempoPrefixeD}{\milli}\edef\PfC@ExposantD{-3}}%
    {µ}{\DeclareSIUnit{\TempoPrefixeD}{\micro}\edef\PfC@ExposantD{-6}}%
    {n}{\DeclareSIUnit{\TempoPrefixeD}{\nano}\edef\PfC@ExposantD{-9}}%
  }%
}%

\NewDocumentCommand\PfC@ChoixUniteA{m}{%
  \IfStrEqCase{#1}{%
    {G}{\DeclareSIUnit{\TempoPrefixeA}{\giga}\edef\PfC@ExposantA{9}}%
    {M}{\DeclareSIUnit{\TempoPrefixeA}{\mega}\edef\PfC@ExposantA{6}}%
    {t}{\DeclareSIUnit{\TempoPrefixeA}{\tonne}\edef\PfC@ExposantA{6}}%
    {q}{\DeclareSIUnit{\TempoPrefixeA}{\quintal}\edef\PfC@ExposantA{5}}%
    {k}{\DeclareSIUnit{\TempoPrefixeA}{\kilo}\edef\PfC@ExposantA{3}}%
    {h}{\DeclareSIUnit{\TempoPrefixeA}{\hecto}\edef\PfC@ExposantA{2}}%
    {da}{\DeclareSIUnit{\TempoPrefixeA}{\deca}\edef\PfC@ExposantA{1}}%
    {u}{\DeclareSIUnit{\TempoPrefixeA}{}\edef\PfC@ExposantA{0}}%
    {d}{\DeclareSIUnit{\TempoPrefixeA}{\deci}\edef\PfC@ExposantA{-1}}%
    {c}{\DeclareSIUnit{\TempoPrefixeA}{\centi}\edef\PfC@ExposantA{-2}}%
    {m}{\DeclareSIUnit{\TempoPrefixeA}{\milli}\edef\PfC@ExposantA{-3}}%
    {µ}{\DeclareSIUnit{\TempoPrefixeA}{\micro}\edef\PfC@ExposantA{-6}}%
    {n}{\DeclareSIUnit{\TempoPrefixeA}{\nano}\edef\PfC@ExposantA{-9}}%
  }%
}%

\NewDocumentCommand\Convertir{somm}{%
  \useKVdefault[ClesConversion]%
  \setKV[ClesConversion]{#2}%
  \StrBefore{#3}{>}[\PfC@PrefixeDepart]%
  \StrBehind{#3}{>}[\PfC@PrefixeArrivee]%
  \PfC@ChoixUniteD{\PfC@PrefixeDepart}%
  \PfC@ChoixUniteA{\PfC@PrefixeArrivee}%
  \ifboolKV[ClesConversion]{Aire}{%
    \DeclareSIUnit{\TempoAvant}{\square}%
    \DeclareSIUnit{\TempoBase}{\meter}%
    \edef\PfC@ConvExposant{2}%
  }{\ifboolKV[ClesConversion]{Vol}{%
      \DeclareSIUnit{\TempoAvant}{\cubic}%
      \DeclareSIUnit{\TempoBase}{\meter}%
      \edef\PfC@ConvExposant{3}%
    }{%
      \DeclareSIUnit{\TempoAvant}{}%
      \edef\PfC@ConvExposant{1}%
    }%
  }%
  \ifboolKV[ClesConversion]{Masse}{%
    \setKV[ClesConversion]{Longueur=false}%
    \DeclareSIUnit{\TempoBase}{\gram}%
  }{}%
  \ifboolKV[ClesConversion]{Capa}{%
    \setKV[ClesConversion]{Longueur=false}%
    \DeclareSIUnit{\TempoBase}{\liter}%
  }{}%
  \ifboolKV[ClesConversion]{Longueur}{%
    \DeclareSIUnit{\TempoBase}{\meter}%
  }{}%
  \ensuremath{%
    \IfBooleanTF{#1}{%
      \IfStrEq{\PfC@PrefixeDepart}{t}{\DeclareSIUnit{\TempoBase}{\relax}}{}\IfStrEq{\PfC@PrefixeDepart}{q}{\DeclareSIUnit{\TempoBase}{\relax}}{}
      \SI{#4}{\TempoAvant\TempoPrefixeD\TempoBase}
      \IfStrEq{\PfC@PrefixeDepart}{t}{\DeclareSIUnit{\TempoBase}{\gram}}{}\IfStrEq{\PfC@PrefixeDepart}{q}{\DeclareSIUnit{\TempoBase}{\gram}}{}
      =
      \IfStrEq{\PfC@PrefixeArrivee}{t}{\DeclareSIUnit{\TempoBase}{\relax}}{}\IfStrEq{\PfC@PrefixeArrivee}{q}{\DeclareSIUnit{\TempoBase}{\relax}}{}
      \ifemptyKV[ClesConversion]{Complete}{\PointsSuspension[\useKV[ClesConversion]{Coef}]{\fpeval{#4*(10**((\PfC@ExposantD-(\PfC@ExposantA))*\PfC@ConvExposant))}}}{\setlength{\PfCConversionLongueur}{\useKV[ClesConversion]{Complete}}\pointilles[\PfCConversionLongueur]}~\si{\TempoAvant\TempoPrefixeA\TempoBase}
      \IfStrEq{\PfC@PrefixeArrivee}{t}{\DeclareSIUnit{\TempoBase}{\gram}}{}\IfStrEq{\PfC@PrefixeArrivee}{q}{\DeclareSIUnit{\TempoBase}{\gram}}{}
    }{%
      \ifboolKV[ClesConversion]{Sans}{%
        \IfStrEq{\PfC@PrefixeDepart}{t}{\DeclareSIUnit{\TempoBase}{\relax}}{}\IfStrEq{\PfC@PrefixeDepart}{q}{\DeclareSIUnit{\TempoBase}{\relax}}{}
        \SI{#4}{\TempoAvant\TempoPrefixeD\TempoBase}
        \IfStrEq{\PfC@PrefixeDepart}{t}{\DeclareSIUnit{\TempoBase}{\gram}}{}\IfStrEq{\PfC@PrefixeDepart}{q}{\DeclareSIUnit{\TempoBase}{\gram}}{}
        =
        \IfStrEq{\PfC@PrefixeArrivee}{t}{\DeclareSIUnit{\TempoBase}{\relax}}{}\IfStrEq{\PfC@PrefixeArrivee}{q}{\DeclareSIUnit{\TempoBase}{\relax}}{}
        \num{\fpeval{#4*(10**((\PfC@ExposantD-(\PfC@ExposantA))*\PfC@ConvExposant))}}~\pointilles[25pt]
        \IfStrEq{\PfC@PrefixeArrivee}{t}{\DeclareSIUnit{\TempoBase}{\gram}}{}\IfStrEq{\PfC@PrefixeArrivee}{q}{\DeclareSIUnit{\TempoBase}{\gram}}{}
      }{%
        \IfStrEq{\PfC@PrefixeDepart}{t}{\DeclareSIUnit{\TempoBase}{\relax}}{}\IfStrEq{\PfC@PrefixeDepart}{q}{\DeclareSIUnit{\TempoBase}{\relax}}{}
        \SI{#4}{\TempoAvant\TempoPrefixeD\TempoBase}
        \IfStrEq{\PfC@PrefixeDepart}{t}{\DeclareSIUnit{\TempoBase}{\gram}}{}\IfStrEq{\PfC@PrefixeDepart}{q}{\DeclareSIUnit{\TempoBase}{\gram}}{}
        =
        \IfStrEq{\PfC@PrefixeArrivee}{t}{\DeclareSIUnit{\TempoBase}{\relax}}{}\IfStrEq{\PfC@PrefixeArrivee}{q}{\DeclareSIUnit{\TempoBase}{\relax}}{}
        \SI{\fpeval{#4*(10**((\PfC@ExposantD-(\PfC@ExposantA))*\PfC@ConvExposant))}}{\TempoAvant\TempoPrefixeA\TempoBase}
        \IfStrEq{\PfC@PrefixeArrivee}{t}{\DeclareSIUnit{\TempoBase}{\gram}}{}\IfStrEq{\PfC@PrefixeArrivee}{q}{\DeclareSIUnit{\TempoBase}{\gram}}{}
      }%
    }%
  }%
}%

\makeatother