\ProvidesPackage{mintspirit}[%
   2022/09/21 (Bob Tennent)  Supports MintSpirit fonts for all LaTeX engines. ] 

\RequirePackage{ifxetex,ifluatex,textcomp}

\newif\ifmintspirit@otf

\ifxetex
  \mintspirit@otftrue
\else\ifluatex
  \mintspirit@otftrue
\else  % [pdf]LaTeX
  \mintspirit@otffalse
\fi\fi

\newif\ifmintspirit@default \mintspirit@defaultfalse
\newif\ifmintspirit@lining \mintspirit@liningfalse
\newif\ifmintspirit@tabular \mintspirit@tabularfalse

\newcommand*{\MintSpirit@scale}{1}  
\RequirePackage{xkeyval}
\DeclareOptionX{scaled}{\renewcommand*{\MintSpirit@scale}{#1}}
\DeclareOptionX{scale}{\renewcommand*{\MintSpirit@scale}{#1}}

\DeclareOptionX{type1}{\mintspirit@otffalse}

\DeclareOptionX{default}{\mintspirit@defaulttrue}
\DeclareOptionX{sfdefault}{\mintspirit@defaulttrue}

\DeclareOptionX{lining}[true]{%
\@nameuse{if#1}%
  \mintspirit@liningtrue
\else
  mintspirit@liningfalse
\fi
}
\DeclareOptionX{lf}[true]{%
\@nameuse{if#1}%
  \mintspirit@liningtrue
\else
  mintspirit@liningfalse
\fi
}
\DeclareOptionX{oldstyle}[true]{%
\@nameuse{if#1}%
  \mintspirit@liningfalse
\else
  \mintspirit@liningtrue
\fi
}

\DeclareOptionX{osf}[true]{%
\@nameuse{if#1}%
  \mintspirit@liningfalse
\else
  \mintspirit@liningtrue
\fi
}

\DeclareOptionX{tabular}[true]{%
\@nameuse{if#1}%
  \mintspirit@tabulartrue
\else
  mintspirit@tabularfalse
\fi
}

\DeclareOptionX{tab}[true]{%
\@nameuse{if#1}%
  \mintspirit@tabulartrue
\else
  mintspirit@tabularfalse
\fi
}

\DeclareOptionX{proportional}[true]{%
\@nameuse{if#1}%
  \mintspirit@tabularfalse
\else
  \mintspirit@tabulartrue
\fi
}

\DeclareOptionX{prop}[true]{%
\@nameuse{if#1}%
  \mintspirit@tabularfalse
\else
  \mintspirit@tabulartrue
\fi
}

\ProcessOptionsX\relax


\ifmintspirit@otf
  \RequirePackage{fontspec}
\else
  \RequirePackage{fontenc,fontaxes}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                            %
% for some reason, Tabular Lining <-> Proportional Lining !! %
%                                                            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ifmintspirit@otf

  \defaultfontfeatures{
     Ligatures = TeX ,
     Extension = .otf ,
     Scale     = \MintSpirit@scale ,
  }

  \ifmintspirit@lining
    \ifmintspirit@tabular
      \setsansfont
          [ Numbers = {Proportional,Lining},
            UprightFont    = *-Regular ,
            ItalicFont     = *-Italic ,
            BoldFont       = *-Bold , 
            BoldItalicFont = *-BoldItalic ]
          {MintSpirit}
    \else
      \setsansfont
          [ Numbers = {Monospaced,Lining},
            UprightFont    = *-Regular ,
            ItalicFont     = *-Italic ,
            BoldFont       = *-Bold , 
            BoldItalicFont = *-BoldItalic ]
          {MintSpirit}
    \fi
  \else
    \ifmintspirit@tabular
      \setsansfont
          [ Numbers = {Monospaced,OldStyle},
            UprightFont    = *-Regular ,
            ItalicFont     = *-Italic ,
            BoldFont       = *-Bold , 
            BoldItalicFont = *-BoldItalic ]
          {MintSpirit}
    \else
      \setsansfont
          [ Numbers = {Proportional,OldStyle},
            UprightFont    = *-Regular ,
            ItalicFont     = *-Italic ,
            BoldFont       = *-Bold , 
            BoldItalicFont = *-BoldItalic ]
          {MintSpirit}
    \fi
  \fi

  % grab current family in case of subsequent change:
  \let\mintspiritfamily\sfdefault  
  \ifmintspirit@default\renewcommand*\familydefault{\mintspiritfamily}\fi

  \newfontfamily\tlstyle
        [ Numbers = {Proportional,Lining},
        UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-Bold , 
        BoldItalicFont = *-BoldItalic ]
      {MintSpirit}

  \newfontfamily\tostyle
        [ Numbers = {Monospaced,OldStyle},
        UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-Bold , 
        BoldItalicFont = *-BoldItalic ]
      {MintSpirit}

  \newfontfamily\plstyle
        [ Numbers = {Monospaced,Lining},
        UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-Bold , 
        BoldItalicFont = *-BoldItalic ]
      {MintSpirit}

  \newfontfamily\postyle
        [ Numbers = {Proportional,OldStyle},
        UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-Bold , 
        BoldItalicFont = *-BoldItalic ]
      {MintSpirit}


  \providecommand\useosf{%
    \defaultfontfeatures{
       Ligatures = TeX ,
       Extension = .otf ,
       Scale     = \MintSpirit@scale ,
    }
    \ifmintspirit@tabular
      \setsansfont
          [ Numbers = {Monospaced,OldStyle},
            UprightFont    = *-Regular ,
            ItalicFont     = *-Italic ,
            BoldFont       = *-Bold , 
            BoldItalicFont = *-BoldItalic ]
          {MintSpirit}
    \else
      \setsansfont
          [ Numbers = {Proportional,OldStyle},
            UprightFont    = *-Regular ,
            ItalicFont     = *-Italic ,
            BoldFont       = *-Bold , 
            BoldItalicFont = *-BoldItalic ]
          {MintSpirit}
    \fi
    \defaultfontfeatures{}
  }

  \providecommand\sufigures{\addfontfeatures{VerticalPosition=Superior}}  
  \providecommand\infigures{\addfontfeatures{VerticalPosition=ScientificInferior}}  

\else % type1

  \ifmintspirit@lining
    \ifmintspirit@tabular
      \def\mintspiritfamily{MintSpirit-LF}
    \else
      \def\mintspiritfamily{MintSpirit-TLF}
    \fi
  \else
    \ifmintspirit@tabular
      \def\mintspiritfamily{MintSpirit-TOsF}
    \else
      \def\mintspiritfamily{MintSpirit-OsF}
    \fi
  \fi
  \renewcommand*\sfdefault{\mintspiritfamily}
  \ifmintspirit@default\edef\familydefault{\sfdefault}\fi

  \providecommand*\mintspirit{\fontfamily{\mintspiritfamily}\selectfont}
  \providecommand*\tlstyle{\fontfamily{MintSpirit-LF}\selectfont}
  \providecommand*\tostyle{\fontfamily{MintSpirit-TOsF}\selectfont}
  \providecommand*\plstyle{\fontfamily{MintSpirit-TLF}\selectfont}
  \providecommand*\postyle{\fontfamily{MintSpirit-OsF}\selectfont}


  \fa@naming@exception{figures}{{inferior}{proportional}}{Inf}
  \fa@naming@exception{figures}{{inferior}{tabular}}{Inf}
  \fa@naming@exception{figures}{{superior}{proportional}}{Sup}
  \fa@naming@exception{figures}{{superior}{tabular}}{Sup}
  \providecommand\sufigures{\@nomath\sufigures\fontfigurestyle{superior}\selectfont}
  \providecommand\infigures{\@nomath\infigures\fontfigurestyle{inferior}\selectfont}

\fi

\DeclareTextFontCommand{\textpl}{\plstyle}
\DeclareTextFontCommand{\textpo}{\postyle}
\DeclareTextFontCommand{\texttl}{\tlstyle}
\DeclareTextFontCommand{\textto}{\tostyle}

\DeclareTextFontCommand{\textsu}{\sufigures}
\DeclareTextFontCommand{\textin}{\infigures}

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

\endinput

