\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{SourceCodePro}
    [2025/04/07 (autoinst)  Style file for SourceCodePro fonts.]

\RequirePackage{xkeyval}
\newcommand*{\SourceCodePro@scale}{1}
\DeclareOptionX{scale}{\renewcommand*{\SourceCodePro@scale}{#1}}
\DeclareOptionX{scaled}{\renewcommand*{\SourceCodePro@scale}{#1}}

\DeclareOptionX{lining}{\edef\SourceCodePro@figurestyle{LF}}
\DeclareOptionX{oldstyle}{\edef\SourceCodePro@figurestyle{OsF}}
\DeclareOptionX{tabular}{\edef\SourceCodePro@figurealign{T}}
\edef\SourceCodePro@figurestyle{OsF}
\edef\SourceCodePro@figurealign{T}

\DeclareOptionX{mainfont}{
    \renewcommand{\familydefault}{\ttdefault}
}
\DeclareOptionX{black}{\edef\bfseries@tt{black}}
\DeclareOptionX{semibold}{\edef\bfseries@tt{semibold}}
\DeclareOptionX{bold}{\edef\bfseries@tt{bold}}
\DeclareOptionX{medium}{\edef\mdseries@tt{medium}}
\DeclareOptionX{regular}{\edef\mdseries@tt{regular}}

\ProcessOptionsX\relax

\RequirePackage[T1,LY1,T2A]{fontenc}
\RequirePackage{textcomp}
\RequirePackage{ifthen}
\RequirePackage{mweights}

\IfFileExists{fontaxes.sty}{
    \RequirePackage{fontaxes}
    \fa@naming@exception{figures}{{superior}{proportional}}{Sup}
    \fa@naming@exception{figures}{{superior}{tabular}}{Sup}
    \def\supfigures{\@nomath\supfigures
        \fontfigurestyle{superior}\selectfont}
    \let\sufigures\supfigures
    \DeclareTextFontCommand{\textsup}{\supfigures}
    \let\textsu\textsup
    \let\textsuperior\textsup
    \let\@oldtextsuperscript\textsuperscript
    \def\textsuperscript{\@ifstar\@oldtextsuperscript\textsup}
    \def\@makefnmark{%
        \mbox{\footnotemarkfont\textsuperscript{\@thefnmark}}}
    \@ifundefined{ftntm@font}%
        {\let\footnotemarkfont\normalfont}%
        {\let\footnotemarkfont\ftntm@font}

    \fa@naming@exception{figures}{{numerators}{proportional}}{Numr}
    \fa@naming@exception{figures}{{numerator}{proportional}}{Numr}
    \fa@naming@exception{figures}{{numerators}{tabular}}{Numr}
    \fa@naming@exception{figures}{{numerator}{tabular}}{Numr}

    \fa@naming@exception{figures}{{denominators}{proportional}}{Dnom}
    \fa@naming@exception{figures}{{denominator}{proportional}}{Dnom}
    \fa@naming@exception{figures}{{denominators}{tabular}}{Dnom}
    \fa@naming@exception{figures}{{denominator}{tabular}}{Dnom}

}{}

%   Here we implement the scale=MatchLowercase option.
%   If this is given, we must compute the correct value of
%   the "\SourceCodePro@scale" parameter before loading the .fd files;
%   but to determine that value we of course need the font's x-height.
%   To avoid triggering the loading of .fd files,
%   we use plain TeX's \font primitive to load the testfont.
%   We then compute the ratio of the current x-height to our font's x-height;
%   this is the "\SourceCodePro@scale" we will pass to the .fd files.
\ifthenelse{\equal{\SourceCodePro@scale}{MatchLowercase}}
    {   \newlength{\SourceCodePro@currentx}
        \settoheight{\SourceCodePro@currentx}{x}
        \newlength{\SourceCodePro@xheight}
        \settoheight{\SourceCodePro@xheight}
            {{\font\testfont=SourceCodePro-Regular-tosf-ot1 at \f@size pt\testfont x}}
        \renewcommand*{\SourceCodePro@scale}
            {\strip@pt\dimexpr\number\numexpr\number\dimexpr\SourceCodePro@currentx\relax*65536/\number\dimexpr\SourceCodePro@xheight\relax\relax sp\relax}}
    {}

\renewcommand*
    {\ttdefault}
    {SourceCodePro-\SourceCodePro@figurealign\SourceCodePro@figurestyle}

\endinput
