\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{plex-sans}
    [2019/04/23  (Bob Tennent) Style file for IBMPlexSans fonts]

\RequirePackage{ifxetex,ifluatex,xkeyval,textcomp}

\newif\ifplexsans@otf 
\ifxetex
  \plexsans@otftrue
\else\ifluatex
  \plexsans@otftrue
\else  % [pdf]LaTeX
  \plexsans@otffalse
\fi\fi

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

\newif\ifplexsans@sfdefault \plexsans@sfdefaultfalse
\newif\ifplexsans@condensed \plexsans@condensedfalse
\newif\ifplexsans@thin \plexsans@thinfalse
\newif\ifplexsans@extralight \plexsans@extralightfalse
\newif\ifplexsans@light \plexsans@lightfalse
\newif\ifplexsans@textmd \plexsans@textmdfalse
\newif\ifplexsans@text \plexsans@textfalse
\newif\ifplexsans@mediumbold \plexsans@mediumboldfalse
\newif\ifplexsans@semibold \plexsans@semiboldfalse

\DeclareOptionX{type1}{\plexsans@otffalse}
\DeclareOptionX{sfdefault}{\plexsans@sfdefaulttrue}
\DeclareOptionX{condensed}{\plexsans@condensedtrue}

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


\ProcessOptionsX\relax

\ifplexsans@otf
  \RequirePackage{fontspec}
\else % type1
  \RequirePackage{fontenc,fontaxes,mweights}
  \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

\ifplexsans@otf

  \def\plexsans@medstyle{Regular}
  \ifplexsans@thin\def\plexsans@medstyle{Thin}
  \else\ifplexsans@extralight\def\plexsans@medstyle{ExtraLight}
  \else\ifplexsans@light\def\plexsans@medstyle{Light}
  \else\ifplexsans@textmd\def\plexsans@medstyle{Text}\fi\fi\fi\fi
  \def\plexsans@boldstyle{Bold}
  \ifplexsans@text\def\plexsans@boldstyle{Text}
  \else\ifplexsans@mediumbold\def\plexsans@boldstyle{Medium}
  \else\ifplexsans@semibold\def\plexsans@boldstyle{SemiBold}\fi\fi\fi

\else % type1
  
  \ifplexsans@condensed
    \def\mdseries@sf{condensed}
    \ifplexsans@thin\def\mdseries@sf{thincondensed}
    \else\ifplexsans@extralight\def\mdseries@sf{extralightcondensed}
    \else\ifplexsans@light\def\mdseries@sf{lightcondensed}
    \else\ifplexsans@textmd\def\mdseries@sf{text}\fi\fi\fi\fi
    \def\bfseries@sf{boldcondensed}
    \ifplexsans@text\def\bfseries@sf{textcondensed}
    \else\ifplexsans@mediumbold\def\bfseries@sf{mediumcondensed}
    \else\ifplexsans@semibold\def\bfseries@sf{semiboldcondensed}\fi\fi\fi
  \else
    \def\mdseries@sf{regular}
    \ifplexsans@thin\def\mdseries@sf{thin}
    \else\ifplexsans@extralight\def\mdseries@sf{extralight}
    \else\ifplexsans@light\def\mdseries@sf{light}
    \else\ifplexsans@textmd\def\mdseries@sf{text}\fi\fi\fi\fi
    \def\bfseries@sf{bold}
    \ifplexsans@text\def\bfseries@sf{text}
    \else\ifplexsans@mediumbold\def\bfseries@sf{medium}
    \else\ifplexsans@semibold\def\bfseries@sf{semibold}\fi\fi\fi
  \fi
\fi

\ifplexsans@otf
  \def\plexsans@regular{Regular}
  \ifxetex\XeTeXtracingfonts=1\fi
  \defaultfontfeatures{
      Ligatures = TeX ,
      Scale     = \IBMPlexSans@scale ,
      Extension = .otf }
  \ifplexsans@condensed
     \setsansfont 
        [ UprightFont    = *-\plexsans@medstyle ,
          ItalicFont     = *-\ifx\plexsans@medstyle\plexsans@regular 
                                Italic
                             \else\plexsans@medstyle Italic\fi ,
          BoldFont       = *-\plexsans@boldstyle , 
          BoldItalicFont = *-\plexsans@boldstyle Italic ]
        {IBMPlexSansCondensed}
  \else
     \setsansfont 
        [ UprightFont    = *-\plexsans@medstyle ,
          ItalicFont     = *-\ifx\plexsans@medstyle\plexsans@regular 
                                Italic
                             \else\plexsans@medstyle Italic\fi ,
          BoldFont       = *-\plexsans@boldstyle , 
          BoldItalicFont = *-\plexsans@boldstyle Italic ]
        {IBMPlexSans}
  \fi
  \let\plexsansfamily\sfdefault
  \ifplexsans@sfdefault\renewcommand*\familydefault{\plexsansfamily}\fi
  \newfontfamily\plexsans
      [ UprightFont    = *-\plexsans@medstyle ,
        ItalicFont     = *-\ifx\plexsans@medstyle\plexsans@regular 
                              Italic
                           \else\plexsans@medstyle Italic\fi ,
        BoldFont       = *-\plexsans@boldstyle , 
        BoldItalicFont = *-\plexsans@boldstyle Italic ]
        {IBMPlexSans}
  \newfontfamily\plexsanscondensed
      [ UprightFont    = *-\plexsans@medstyle ,
        ItalicFont     = *-\ifx\plexsans@medstyle\plexsans@regular 
                              Italic
                           \else\plexsans@medstyle Italic\fi ,
        BoldFont       = *-\plexsans@boldstyle , 
        BoldItalicFont = *-\plexsans@boldstyle Italic ]
        {IBMPlexSansCondensed}

\else % type1
  \def\plexsansfamily{IBMPlexSans-TLF}
  \newcommand*\plexsans{%
    \def\mdseries@sf{regular}
    \ifplexsans@thin\def\mdseries@sf{thin}
    \else\ifplexsans@extralight\def\mdseries@sf{extralight}
    \else\ifplexsans@light\def\mdseries@sf{light}
    \else\ifplexsans@textmd\def\mdseries@sf{text}\fi\fi\fi\fi
    \def\bfseries@sf{bold}
    \ifplexsans@text\def\bfseries@sf{text}
    \else\ifplexsans@mediumbold\def\bfseries@sf{medium}
    \else\ifplexsans@semibold\def\bfseries@sf{semibold}\fi\fi\fi
    \sffamily
  }
  \newcommand*\plexsanscondensed{%
    \def\mdseries@sf{condensed}
    \ifplexsans@thin\def\mdseries@sf{thincondensed}
    \else\ifplexsans@extralight\def\mdseries@sf{extralightcondensed}
    \else\ifplexsans@light\def\mdseries@sf{lightcondensed}
    \else\ifplexsans@textmd\def\mdseries@sf{text}\fi\fi\fi\fi
    \def\bfseries@sf{boldcondensed}
    \ifplexsans@text\def\bfseries@sf{textcondensed}
    \else\ifplexsans@mediumbold\def\bfseries@sf{mediumcondensed}
    \else\ifplexsans@semibold\def\bfseries@sf{semiboldcondensed}\fi\fi\fi
    \sffamily
  }   
  \renewcommand*\sfdefault{\plexsansfamily} 
  \ifplexsans@sfdefault\edef\familydefault{\sfdefault}\edef\seriesdefault{\mdseries@sf}\fi
\fi

\newcommand*\plexsanslgr{\fontencoding{LGR}\fontfamily{IBMPlexSans-TLF}\selectfont} % even for otf

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

\endinput
