\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{plex-mono}
    [2023/09/30  (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


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

\newif\ifplexmono@ligatures \plexmono@ligaturestrue

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

\DeclareOptionX{type1}{\plexmono@otffalse}

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

\ProcessOptionsX\relax

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

  \def\bfseries@tt{b}
  \ifplexmono@semibold\def\bfseries@tt{sb}
  \else\ifplexmono@text\def\bfseries@tt{text}
  \else\ifplexmono@medium\def\bfseries@tt{medium}
  \fi\fi\fi
\fi

\ifplexmono@otf
  \def\plexmono@regular{Regular}
  \ifplexmono@ligatures
    \defaultfontfeatures{
          Ligatures = TeX ,
          HyphenChar=None,
          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-TLF}
  \newcommand*\plexmono{\fontfamily{\plexmonofamily}\selectfont}
  \def\ttdefault{\plexmonofamily}
\fi

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

\endinput
