\ProvidesPackage{librebaskerville}[%
   2022/09/17 (Bob Tennent)  Supports LibreBaskerville fonts for all LaTeX engines. ] 

\RequirePackage{ifxetex,ifluatex,textcomp}

\newif\iflibrebaskerville@ttf
\ifxetex
  \librebaskerville@ttftrue
\else\ifluatex
  \librebaskerville@ttftrue
\else  % [pdf]LaTeX
  \librebaskerville@ttffalse
\fi\fi

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

\DeclareOptionX{type1}{\librebaskerville@ttffalse}

\ProcessOptionsX\relax

\iflibrebaskerville@ttf
  \RequirePackage{fontspec}
\else
  \RequirePackage{fontenc,fontaxes}
\fi

\iflibrebaskerville@ttf
  \defaultfontfeatures{
     Ligatures = TeX ,
     Extension = .ttf ,
     Scale = \LibreBskvl@scale,
  }
  \setmainfont
      [ UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-Bold , 
        BoldItalicFont = LibreBskvl-BoldItalic,
        ]
      {LibreBaskerville}
  \newfontfamily\librebaskerville
      [ UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-Bold , 
        BoldItalicFont = LibreBskvl-BoldItalic,
        ]
      {LibreBaskerville}
  \providecommand\sufigures{\addfontfeatures{VerticalPosition=Superior}}


\else % type1

  \fa@naming@exception{figures}{{superior}{proportional}}{Sup}
  \fa@naming@exception{figures}{{superior}{tabular}}{Sup}
  \providecommand\sufigures{\@nomath\sufigures\fontfigurestyle{superior}\selectfont}
  \def\librebaskervillefamily{LibreBskvl-LF}
  \renewcommand*\rmdefault{\librebaskervillefamily}
  \newcommand*\librebaskerville{\fontfamily{\librebaskervillefamily}\selectfont}

\fi
\DeclareTextFontCommand{\textsu}{\sufigures}

% turn off defaults in case other fonts are selected:
\iflibrebaskerville@ttf
  \defaultfontfeatures{}
\fi

\endinput

