\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{plex-mono}
    [2018/08/01  (Bob Tennent) Style file for IBMPlexMono fonts]

\RequirePackage{ifxetex,ifluatex,xkeyval,textcomp}

\newif\ifplexmono@otf 
\ifxetex
  \plexmono@otftrue
\else\ifluatex
  \plexmono@otftrue
\else  % [pdf]LaTeX
  \plexmono@otffalse
\fi\fi

\ifplexmono@otf
  \RequirePackage{fontspec}
  \def\plexmono@medstyle{Regular}
  \def\plexmono@boldstyle{Bold}
\else % type1
  \RequirePackage{fontenc,fontaxes,mweights}
  \def\bfseries@tt{b}
  \def\mdseries@tt{m}
  \def\plexmono@figurestyle{LF}
  \def\plexmono@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*{\IBMPlexMono@scale}{1}
\DeclareOptionX{scale}{\renewcommand*{\IBMPlexMono@scale}{#1}}

\newif\ifplexmono@ligatures \plexmono@ligaturestrue


\DeclareOptionX{type1}{\plexmono@otffalse}

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

\ProcessOptionsX\relax


\ifplexmono@otf
  \def\plexmono@regular{Regular}
  \ifxetex\XeTeXtracingfonts=1\fi
  \ifplexmono@ligatures
    \defaultfontfeatures{
          Ligatures = TeX ,
          Scale     = \IBMPlexMono@scale ,
          Extension = .otf }
  \else
    \defaultfontfeatures{
          Scale     = \IBMPlexMono@scale ,
          Extension = .otf }
  \fi
  \setmonofont 
      [ UprightFont    = *-\plexmono@medstyle ,
        ItalicFont     = *-\ifx\plexmono@medstyle\plexmono@regular 
                              Italic
                           \else\plexmono@medstyle Italic\fi ,
        BoldFont       = *-\plexmono@boldstyle , 
        BoldItalicFont = *-\plexmono@boldstyle Italic ]
      {IBMPlexMono}
  \newfontfamily\plexmono
        [ UprightFont    = *-\plexmono@medstyle ,
          ItalicFont     = *-\ifx\plexmono@medstyle\plexmono@regular 
                              Italic
                           \else\plexmono@medstyle Italic\fi ,
          BoldFont       = *-\plexmono@boldstyle , 
          BoldItalicFont = *-\plexmono@boldstyle Italic ]
        {IBMPlexMono}

\else % type1
  \def\plexmonofamily{IBMPlexMono-\plexmono@figurealign\plexmono@figurestyle}
  \newcommand*\plexmono{\fontfamily{\plexmonofamily}\selectfont}
  \def\ttdefault{\plexmonofamily}
\fi

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

\endinput
