\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{plex-serif}
    [2023/09/30  (Bob Tennent) Style file for IBMPlexSerif fonts]

\RequirePackage{ifxetex,ifluatex,xkeyval,textcomp}

\newif\ifplexserif@otf 
\ifxetex
  \plexserif@otftrue
\else\ifluatex
  \plexserif@otftrue
\else  % [pdf]LaTeX
  \plexserif@otffalse
\fi\fi


\newcommand*{\IBMPlexSerif@scale}{1}
\DeclareOptionX{scale}{\renewcommand*{\IBMPlexSerif@scale}{#1}}

\newif\ifplexserif@text \plexserif@textfalse
\newif\ifplexserif@textmd \plexserif@textmdfalse
\newif\ifplexserif@semibold \plexserif@semiboldfalse
\newif\ifplexserif@medium \plexserif@mediumfalse
\newif\ifplexserif@thin \plexserif@thinfalse
\newif\ifplexserif@light \plexserif@lightfalse
\newif\ifplexserif@extralight \plexserif@extralightfalse


\DeclareOptionX{type1}{\plexserif@otffalse}

\DeclareOptionX{thin}{\plexserif@thintrue}
\DeclareOptionX{t}{\plexserif@thintrue}
\DeclareOptionX{extralight}{\plexserif@extralighttrue}
\DeclareOptionX{el}{\plexserif@extralighttrue}
\DeclareOptionX{light}{\plexserif@lighttrue}
\DeclareOptionX{l}{\plexserif@lighttrue}
\DeclareOptionX{text}{\plexserif@texttrue}
\DeclareOptionX{tx}{\plexserif@texttrue}
\DeclareOptionX{textmd}{\plexserif@textmdtrue}
\DeclareOptionX{txmd}{\plexserif@textmdtrue}
\DeclareOptionX{medium}{\plexserif@mediumtrue}
\DeclareOptionX{m}{\plexserif@mediumtrue}
\DeclareOptionX{semibold}{\plexserif@semiboldtrue}
\DeclareOptionX{sb}{\plexserif@semiboldtrue}

\ProcessOptionsX\relax

\ifplexserif@otf
  \RequirePackage{fontspec}
  \def\plexserif@medstyle{Regular}
  \ifplexserif@thin\def\plexserif@medstyle{Thin}
  \else\ifplexserif@light\def\plexserif@medstyle{Light}
  \else\ifplexserif@extralight\def\plexserif@medstyle{ExtraLight}
  \else\ifplexserif@text\def\plexserif@medstyle{Text}
  \else\ifplexserif@textmd\def\plexserif@medstyle{Medium}
  \fi\fi\fi\fi\fi
  \def\plexserif@boldstyle{Bold}
  \ifplexserif@semibold\def\plexserif@boldstyle{SemiBold}
  \else\ifplexserif@medium\def\plexserif@boldstyle{Medium}
  \fi\fi
\else % type1
  \RequirePackage{fontenc,fontaxes,mweights}
  \def\mdseries@rm{m}
  \ifplexserif@thin\def\mdseries@rm{ul}
  \else\ifplexserif@light\def\mdseries@rm{l}
  \else\ifplexserif@extralight\def\mdseries@rm{el}
  \else\ifplexserif@textmd\def\mdseries@rm{text}
  \fi\fi\fi\fi

  \def\bfseries@rm{b}
  \ifplexserif@semibold\def\bfseries@rm{sb}
  \else\ifplexserif@text\def\bfseries@rm{text}
  \else\ifplexserif@medium\def\bfseries@rm{medium}
  \fi\fi\fi

  \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
\fi

\ifplexserif@otf
  \def\plexserif@regular{Regular}
  \defaultfontfeatures{
        Ligatures = TeX ,
        Scale     = \IBMPlexSerif@scale ,
        Extension = .otf }
   \setmainfont 
      [ UprightFont    = *-\plexserif@medstyle ,
        ItalicFont     = *-\ifx\plexserif@medstyle\plexserif@regular 
                              Italic
                           \else\plexserif@medstyle Italic\fi ,
        BoldFont       = *-\plexserif@boldstyle , 
        BoldItalicFont = *-\plexserif@boldstyle Italic ]
      {IBMPlexSerif}
  \newfontfamily\plexserif
        [ UprightFont    = *-\plexserif@medstyle ,
          ItalicFont     = *-\ifx\plexserif@medstyle\plexserif@regular 
                              Italic
                           \else\plexserif@medstyle Italic\fi ,
          BoldFont       = *-\plexserif@boldstyle , 
          BoldItalicFont = *-\plexserif@boldstyle Italic ]
        {IBMPlexSerif}

\else % type1
  \def\plexseriffamily{IBMPlexSerif-TLF}
  \newcommand*\plexserif{\fontfamily{\plexseriffamily}\selectfont}
  \def\rmdefault{\plexseriffamily}
  \def\seriesdefault{\mdseries@rm}
\fi


\newcommand*\plexseriflgr{\fontencoding{LGR}\fontfamily{IBMPlexSerif-TLF}\selectfont} % even for otf

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

\endinput
