%% Baskervaldx.sty
%%
\NeedsTeXFormat{LaTeX2e}
\def\fileversion{1.075}
\def\filedate{2020/11/07}
\ProvidesPackage{Baskervaldx}
    [\filedate\space v\fileversion]
    
\message{`Baskervaldx' v\fileversion, \filedate\space  Style file for Baskervaldx, an `expertized' update of Baskervald (msharpe)}

\RequirePackage[LY1,T1]{fontenc}
\RequirePackage{textcomp}
\IfFileExists{mweights.sty}{\RequirePackage{mweights}}{}
\RequirePackage{etoolbox}
\RequirePackage{scalefnt}
\IfFileExists{fontaxes.sty}{
    \RequirePackage{fontaxes}
    \DeclareRobustCommand\swshape{\not@math@alphabet\swshape\relax
        \fontprimaryshape\itdefault\fontsecondaryshape\swdefault\selectfont}
    \fa@naming@exception{shape}{{n}{sw}}{nw}
    \fa@naming@exception{shape}{{it}{sw}}{sw}
    \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
}{}

\newcommand*{\Baskervaldx@scale}{1}
\IfFileExists{xkeyval.sty}{
    \RequirePackage{xkeyval}
    \DeclareOptionX{scale}{\renewcommand*{\Baskervaldx@scale}{##1}}
    \DeclareOptionX{scaled}{\renewcommand*{\Baskervaldx@scale}{##1}}
}{
    \let\DeclareOptionX\DeclareOption
    \let\ExecuteOptionsX\ExecuteOptions
    \let\ProcessOptionsX\ProcessOptions
}
\let\orig@footnote=\thefootnote
\let\orig@makefnmark=\@makefnmark
\def\useosf{\edef\Baskervaldx@figurestyle{OsF}}
\@onlypreamble\useosf
\def\bfseries@rm{b}
\def\mdseries@rm{m}
\newif\if@Baskervaldx@sups
\newif\if@Baskervaldx@sw
%\newif\ifBaskervaldx@babel
%\ifdefined\bbl@tempa \Baskervaldx@babeltrue\fi

\DeclareOptionX{lining}{\edef\Baskervaldx@figurestyle{LF}}
\DeclareOptionX{lf}{\edef\Baskervaldx@figurestyle{LF}}
\DeclareOptionX{oldstyle}{\useosf}
\DeclareOptionX{osf}{\useosf}
\DeclareOptionX{tabular}{\edef\Baskervaldx@figurealign{T}}
\DeclareOptionX{proportional}{\edef\Baskervaldx@figurealign{}}
\DeclareOptionX{p}{\edef\Baskervaldx@figurealign{}}
\DeclareOptionX{sups}{\@Baskervaldx@supstrue}
\DeclareOptionX{swash}{\@Baskervaldx@swtrue} % used in fd files
\ExecuteOptionsX{lining,tabular}
\ProcessOptionsX\relax

% Over-ride the latex definition of \textcircled
\def\textcircled#1{\hmode@bgroup
   \ooalign{%
      \hfil \raise .38ex\hbox {\usefont{T1}{Baskervaldx-TLF}{m}{sc}
      \ifnum\number`#1>64 \scalefont{.73}\else\scalefont{.54}\fi%
      \lowercase{#1}}\hfil \crcr
    \hfil\usefont{TS1}{Baskervaldx-TLF}{m}{n}\char79 \hfil% bigcircle
   }%
 \egroup}

%\DeclareTextCommand{\textcircled}{TS1}[1]{\hmode@bgroup
%   \ooalign{%
%      \hfil \raise .42ex\hbox {\fontencoding{T1}\fontseries{m}\fontshape{sc}\fontsize{8.7}{10}\selectfont \lowercase{#1}}\hfil \crcr
%     \textbigcircle   % textbigcircle
%   }%
% \egroup}

\DeclareRobustCommand{\lfstyle}{%
  \not@math@alphabet\lfstyle\relax
  \fontfamily{Baskervaldx-LF}\selectfont %
}% to get lf
\DeclareRobustCommand{\tlfstyle}{%
  \not@math@alphabet\tlfstyle\relax
  \fontfamily{Baskervaldx-TLF}\selectfont %
}% to get tlf
\DeclareRobustCommand{\osfstyle}{%
  \not@math@alphabet\osfstyle\relax
  \fontfamily{Baskervaldx-OsF}\selectfont %
}% to get osf
\DeclareRobustCommand{\tosfstyle}{%
  \not@math@alphabet\tosfstyle\relax
  \fontfamily{Baskervaldx-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

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

\if@Baskervaldx@sups %
 \ifdefined\sufigures
  \def\f@@tn@te{footnote}
  \def\@makefnmark{%
    \ifx\@mpfn\f@@tn@te%
      \ifx\thefootnote\orig@footnote%
        \hbox{\sufigures\hspace*{.04em}\@thefnmark\hspace*{.04em}}%
      \else%
        \orig@makefnmark%
      \fi
    \else%
      \orig@makefnmark%
    \fi}%
 \fi%
\fi



%\ifBaskervaldx@babel
%    \renewcommand*{\swdefault}{sw}
%	\renewcommand*{\rmdefault}%
%	{Baskervaldx-\Baskervaldx@figurealign\Baskervaldx@figurestyle}
%	\normalfont
%\else
	\AtEndPreamble{%
		\renewcommand*{\swdefault}{sw}
		\renewcommand*{\rmdefault}%
		{Baskervaldx-\Baskervaldx@figurealign\Baskervaldx@figurestyle}
		\normalfont}
%\fi
\endinput
