%%
\NeedsTeXFormat{LaTeX2e}
\def\fileversion{1.033}
\def\filedate{2022/01/31}
\ProvidesPackage{scholax}
    [\filedate\space v\fileversion]

\message{'scholax' v\fileversion, \filedate\space (msharpe) Style file for TeXGyreScholaX.}

\RequirePackage[LY1,T1]{fontenc}
\RequirePackage{textcomp}
\RequirePackage{ifthen,xstring,scalefnt}
\DeclareEncodingSubset{TS1}{TeXGyreScholaX-*}{0}
\RequirePackage{etoolbox}
\IfFileExists{mweights.sty}{\RequirePackage{mweights}}{}
\IfFileExists{fontaxes.sty}{
   \RequirePackage{fontaxes}
%    \fa@naming@exception{figures}{{superior}{proportional}}{Sup}
%    \fa@naming@exception{figures}{{superior}{tabular}}{Sup}
%    \def\sufigures{\@nomath\sufigures
%        \fontfigurestyle{superior}\selectfont}
%    \DeclareTextFontCommand{\textsu}{\sufigures}
%    \let\textsuperior\textsu


    \fa@naming@exception{figures}{{superior}{proportional}}{Sup}
    \fa@naming@exception{figures}{{superior}{tabular}}{Sup}
    \def\sufigures{\@nomath\sufigures%
        \fontfigurestyle{superior}\selectfont}
    \DeclareTextFontCommand{\textsu}{\sufigures}
    \let\textsuperior\textsu
	\let\nustyle\sufigures
	
    \fa@naming@exception{figures}{{inferior}{proportional}}{Inf}
    \fa@naming@exception{figures}{{inferior}{tabular}}{Inf}
    \def\infigures{\@nomath\infigures%
        \fontfigurestyle{inferior}\selectfont}
    \DeclareTextFontCommand{\textin}{\infigures}
    \let\textinferior\textin
    \let\destyle\infigures
%    \providecommand*{\textfrac}[2]{%
%    \raise \zcs@raisefrac \hbox{\textsu{##1}\kern \zcs@foresolidus \textfractionsolidus\kern \zcs@aftsolidus \textin{##2}}}
}{}


\IfFileExists{xkeyval.sty}{
    \newcommand*{\TeXGyreScholaX@scale}{1}
    \RequirePackage{xkeyval}
    \DeclareOptionX{scale}{\renewcommand*{\TeXGyreScholaX@scale}{##1}}
    \DeclareOptionX{scaled}{\renewcommand*{\TeXGyreScholaX@scale}{##1}}
}{
    \let\DeclareOptionX\DeclareOption
    \let\ExecuteOptionsX\ExecuteOptions
    \let\ProcessOptionsX\ProcessOptions
}
\let\orig@footnote=\thefootnote
\let\orig@makefnmark=\@makefnmark
\newif\ifzcs@KOMA
\@ifundefined{KOMAClassName}{}{\zcs@KOMAtrue}
\@ifundefined{ver@scrextend.sty}{}{\zcs@KOMAtrue}
\newif\if@zcs@sups


\newif\if@zcs@scosf
\def\useosf{\edef\TeXGyreScholaX@figurestyle{OsF}}
\@onlypreamble\useosf
\def\useproportional{\edef\TeXGyreScholaX@figurealign{}}
\@onlypreamble\useproportional
\newif\ifzcs@thrm

\def\zcs@foresolidus{.04em}
\def\zcs@aftsolidus{-.11em}
\def\zcs@raisefrac{.111em}
\edef\bfseries@rm{b}
\edef\mdseries@rm{m}
\def\zcs@spc{.278em}
\def\zcs@stretch{.139em}
\def\zcs@shrink{.093em}
\DeclareOptionX{spacing}{\gdef\zcs@spc{#1}}
\DeclareOptionX{stretch}{\gdef\zcs@stretch{#1}}
\DeclareOptionX{shrink}{\gdef\zcs@shrink{#1}}\DeclareOptionX{foresolidus}{\gdef\zcs@foresolidus{#1}}
\DeclareOptionX{aftsolidus}{\gdef\zcs@aftsolidus{#1}}
\DeclareOptionX{raisefrac}{\gdef\zcs@raisefrac{#1}}

\DeclareOptionX{theoremfont}{\zcs@thrmtrue}
\DeclareOptionX{scosf}{\@zcs@scosftrue}
\DeclareOptionX{sups}{\@zcs@supstrue}
\DeclareOptionX{lining}{\edef\TeXGyreScholaX@figurestyle{LF}}
\DeclareOptionX{lf}{\edef\TeXGyreScholaX@figurestyle{LF}}
\DeclareOptionX{oldstyle}{\useosf}
\DeclareOptionX{osf}{\useosf}
\DeclareOptionX{tabular}{\edef\TeXGyreScholaX@figurealign{T}}
\DeclareOptionX{p}{\useproportional}
\DeclareOptionX{proportional}{\useproportional}
\DeclareOptionX{mainfont}{
    \renewcommand{\familydefault}{\rmdefault}}
%\DeclareOption{tighter}{%
%\gdef\zpl@spc{.25em}\gdef\zpl@stretch{.125em}\gdef\zpl@shrink{.1em}}
\DeclareOptionX{looser}{%
\gdef\zcs@spc{.3em}\gdef\zcs@stretch{.2em}\gdef\zcs@shrink{.1em}}
\DeclareOptionX{loosest}{%
\gdef\zcs@spc{.333em}\gdef\zcs@stretch{.222em}\gdef\zcs@shrink{.111em}}

\ExecuteOptionsX{lining,tabular}
\ProcessOptionsX
\def\zcs@spacing{%
	\fontdimen2\font=\zcs@spc
	\fontdimen3\font=\zcs@stretch
	\fontdimen4\font=\zcs@shrink
}
\ExecuteOptionsX{tabular,lining,mainfont}
\ProcessOptionsX\relax

\DeclareRobustCommand{\lfstyle}{%
  \not@math@alphabet\lfstyle\relax
  \fontfamily{TeXGyreScholaX-LF}\selectfont %
}% to get lf
\DeclareRobustCommand{\tlfstyle}{%
  \not@math@alphabet\tlfstyle\relax
  \fontfamily{TeXGyreScholaX-TLF}\selectfont %
}% to get tlf
\DeclareRobustCommand{\osfstyle}{%
  \not@math@alphabet\osfstyle\relax
  \fontfamily{TeXGyreScholaX-OsF}\selectfont %
}% to get osf
\DeclareRobustCommand{\tosfstyle}{%
  \not@math@alphabet\tosfstyle\relax
  \fontfamily{TeXGyreScholaX-TOsF}\selectfont %
}% to get tosf
\DeclareRobustCommand{\textlf}[1]{%
  {\lfstyle #1}%
}% to get lf
\DeclareRobustCommand{\texttlf}[1]{%
  {\tlfstyle #1}%
}% to get tlf
\DeclareRobustCommand{\textosf}[1]{%
  {\osfstyle #1}%
}% to get osf
\DeclareRobustCommand{\texttosf}[1]{%
  {\tosfstyle #1}%
}% to get tosf
\if@zcs@scosf %
\DeclareRobustCommand{\textsc}[1]{%
{\fontfamily{TeXGyreScholaX-\TeXGyreScholaX@figurealign%
OsF}\fontshape{sc}\selectfont #1}%
}\fi% use OsF in small caps

\newcommand{\textfrac}[3][]{% e.g., \textfrac[1]{7}{8}
  \mbox{%
    \ifthenelse{\not\equal{#1}{}}%Test for integer portion [optional #1]
      {\textlf{#1}\kern.05em}{}%         
    \raise \zcs@raisefrac \hbox{%
    \textsu{#2}% numerator
    \StrRight{#2}{1}[\@digit@]%
    % look for  1, 2, 6, 7
    \ifcase\@digit@% 0
    \or%\kern.03em% 1
    \or%\kern.02em% 2
    \or\kern-.02em% 3
    \or\kern.01em% 4
    \or\kern-.01em% 5
    \or%\kern-.01em% 6
    \or\kern-.08em% 7
    \or%\kern-.08em% 8
    \or\kern-.04em% 9
    \fi%
    \kern\zcs@foresolidus{\fontencoding{TS1}\selectfont\char"2F}%
    \kern\zcs@aftsolidus%
    \StrLeft{#3}{1}[\@digit@]%
    % look for 1, 4, 7
    \ifcase\@digit@% 0
    \or%\kern -.02em% 1
    \or\kern .01em% 2
    \or% 3
    \or\kern -.08em% 4
    \or\kern -.01em% 5
    \or\kern -.04em% 6
    \or%\kern .02em% 7
    \fi%
    \textin{#3}%       denominator [#3]
  }% hbox
  }
}

\renewcommand*{\rmdefault}{TeXGyreScholaX-TLF} % always TLF in math
\renewcommand*{\familydefault}{\rmdefault}

\if@zcs@sups %
 \ifzcs@KOMA \else % not using a KOMA class
 \ifdefined\sufigures
  \def\f@@tn@te{footnote}
  \def\@makefnmark{%
    \ifx\@mpfn\f@@tn@te%not in a minipage
      \ifx\thefootnote\orig@footnote%
        \hbox{\sufigures\hspace*{.04em}\@thefnmark\hspace*{.04em}}%
      \else%
        \orig@makefnmark%
      \fi%
    \else%
      \orig@makefnmark%
    \fi}%
 \fi\fi%
\fi

\DeclareRobustCommand\thfamily
        {\not@math@alphabet\thfamily\relax
         \fontfamily\thdefault\selectfont}

%\show\th@plain
%\ifzcs@thrm
%	%\RequirePackage{amsmath,amsthm} % in case of theoremfont
%	\ifdefined\newtheoremstyle %amsthm and ntheorem, not theorem.sty
%		\@ifpackageloaded{ntheorem}\relax{%
%		\newtheoremstyle{plain}
%		{\medskipamount}   % ABOVESPACE, was \topsep
%    	{\medskipamount}   % BELOWSPACE, was \topsep
%    	{\thfamily}  % BODYFONT--\thfamily is defined to be \itshape with upright figures and punctuation
%    	{}       % INDENT (empty value is the same as 0pt)
%    	{\bfseries} % HEADFONT--you may want to add \tlfstyle so the number is tab lining, regardless of text figure selection
%    	{.}         % HEADPUNCT
%    	{5pt plus 1pt minus 1pt} % HEADSPACE
%    	{}          % CUSTOM-HEAD-SPEC\newtheorem{thm}{Theorem}[section]
%    	} % end @ifpackageloaded
%    \fi%
%\fi%}		


\AtEndPreamble{%
\renewcommand*{\rmdefault}%
 {TeXGyreScholaX-\TeXGyreScholaX@figurealign\TeXGyreScholaX@figurestyle}
\newcommand*{\thdefault}{zcsth-\TeXGyreScholaX@figurestyle}
\ifzcs@thrm
    \@ifundefined{theoremstyle}{}{%
    \theoremstyle{plain}
    \patchcmd{\th@plain}{\itshape}{\thfamily}{\message{Replaced itshape by thfamily in theorem style plain.}}{\message{Unable to replace itshape by thfamily in theorem style plain.}}
}
\fi
\normalfont}

\endinput