\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{plex-sans}
    [2018/08/01  (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

\ifplexsans@otf
  \RequirePackage{fontspec}
  \def\plexsans@medstyle{Regular}
  \def\plexsans@boldstyle{Bold}
\else % type1
  \RequirePackage{fontenc,fontaxes,mweights}
  \def\bfseries@sf{b}
  \def\mdseries@sf{m}
  \def\plexsans@figurestyle{LF}
  \def\plexsans@figurealign{T}
  \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

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

\newif\ifplexsans@sfdefault \plexsans@sfdefaultfalse
\newif\ifplexsans@condensed \plexsans@condensedfalse

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

\DeclareOptionX{thin}{\edef\mdseries@sf{t}\def\plexsans@medstyle{Thin}}
\DeclareOptionX{t}{\edef\mdseries@sf{t}\def\plexsans@medstyle{Thin}}
\DeclareOptionX{extralight}{\edef\mdseries@sf{el}\def\plexsans@medstyle{ExtraLight}}
\DeclareOptionX{el}{\edef\mdseries@sf{el}\def\plexsans@medstyle{ExtraLight}}
\DeclareOptionX{light}{\edef\mdseries@sf{l}\def\plexsans@medstyle{Light}}
\DeclareOptionX{l}{\edef\mdseries@sf{l}\def\plexsans@medstyle{Light}}
\DeclareOptionX{textmd}{\edef\mdseries@sf{tx}\def\plexsans@medstyle{Text}}
\DeclareOptionX{txmd}{\edef\mdseries@sf{tx}\def\plexsans@medstyle{Text}}
\DeclareOptionX{text}{\edef\bfseries@sf{tx}\def\plexsans@boldstyle{Text}}
\DeclareOptionX{tx}{\edef\bfseries@sf{tx}\def\plexsans@boldstyle{Text}}
\DeclareOptionX{medium}{\edef\bfseries@sf{mb}\def\plexsans@boldstyle{Medium}}
\DeclareOptionX{m}{\edef\bfseries@sf{mb}\def\plexsans@boldstyle{Medium}}
\DeclareOptionX{semibold}{\edef\bfseries@sf{sb}\def\plexsans@boldstyle{SemiBold}}
\DeclareOptionX{sb}{\edef\bfseries@sf{sb}\def\plexsans@boldstyle{SemiBold}}


\ProcessOptionsX\relax


\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-\plexsans@figurealign\plexsans@figurestyle}
  \def\plexsanscondensedfamily{IBMPlexSansCondensed-\plexsans@figurealign\plexsans@figurestyle}
  \newcommand*\plexsans{\fontfamily{\plexsansfamily}\selectfont}
  \newcommand*\plexsanscondensed{\fontfamily{\plexsanscondensedfamily}\selectfont}
  \ifplexsans@condensed
    \def\sfdefault{\plexsanscondensedfamily}
  \else
    \def\sfdefault{\plexsansfamily}
  \fi
  \ifplexsans@sfdefault\edef\familydefault{\sfdefault}\fi
\fi



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

\endinput
