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

\RequirePackage{ifxetex,ifluatex,textcomp}

\newif\ifcrimson@otf
\ifxetex
  \crimson@otftrue
\else\ifluatex
  \crimson@otftrue
\else  % [pdf]LaTeX
  \crimson@otffalse
\fi\fi

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

\newif\ifcrimson@semibold  \crimson@semiboldfalse

\DeclareOptionX{type1}{\crimson@otffalse}
\DeclareOptionX{semibold}{\crimson@semiboldtrue}
\DeclareOptionX{sb}{\crimson@semiboldtrue}
\DeclareOptionX{bold}{\crimson@semiboldfalse}

\ProcessOptionsX\relax

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

\ifcrimson@otf
  \def\crimson@boldstyle{Bold}
  \ifcrimson@semibold\def\crimson@boldstyle{Semibold}\fi

\else % type1

  \def\bfseries@rm{b}
  \ifcrimson@semibold\def\bfseries@rm{sb}\fi

  \def\mdseries@rm{m}
\fi


\ifcrimson@otf
  \defaultfontfeatures{
     Ligatures = TeX ,
     Scale = \Crimson@scale,
     Extension = .otf ,
  }
  \setmainfont
      [ UprightFont    = *-Roman ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-\crimson@boldstyle , 
        BoldItalicFont = *-\crimson@boldstyle Italic ]
      {Crimson}
  \newfontfamily\crimson
      [ UprightFont    = *-Roman ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-\crimson@boldstyle , 
        BoldItalicFont = *-\crimson@boldstyle Italic ]
      {Crimson}
  \newfontfamily\crimsonsemibold
      [ UprightFont    = *-Semibold ,
        ItalicFont     = *-SemiboldItalic ,
        BoldFont       = *-Semibold , 
        BoldItalicFont = *-SemiboldItalic ]
      {Crimson}

\else % type1

  \def\crimson@family{Crimson-TLF}
  \renewcommand*\rmdefault{\crimson@family}
  \newcommand*\crimson{\fontfamily{\crimson@family}\selectfont}
  \def\crimsonsemibold{\fontfamily{\crimson@family}\fontseries{sb}\selectfont}

\fi

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

\endinput

