\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{atkinson}
    [2025/11/20 Supports Atkinson Hyperlegible fonts for all LaTeX engines.]

\RequirePackage{ifxetex,ifluatex,xkeyval,textcomp}

\newif\ifatkinson@otf 
\ifxetex
  \atkinson@otftrue
\else\ifluatex
  \atkinson@otftrue
\else  % [pdf]LaTeX
  \atkinson@otffalse
\fi\fi

\newif\ifatkinson@tabular \atkinson@tabularfalse
\newif\ifatkinson@default \atkinson@defaultfalse
\newif\ifatkinson@semibold \atkinson@semiboldfalse
\newif\ifatkinson@extrabold \atkinson@extraboldfalse
\newif\ifatkinson@medium  \atkinson@mediumfalse
\newif\ifatkinson@light  \atkinson@lightfalse
\newif\ifatkinson@extralight  \atkinson@extralightfalse
\newif\ifatkinson@mono  \atkinson@monotrue


\newcommand*{\atkinsn@scale}{1}
\DeclareOptionX{scaled}{\renewcommand*{\atkinsn@scale}{#1}}
\DeclareOptionX{scale}{\renewcommand*{\atkinsn@scale}{#1}}

\DeclareOptionX{sfdefault}{\atkinson@defaulttrue}
\DeclareOptionX{type1}{\atkinson@otffalse}
\DeclareOptionX{semibold}{\atkinson@semiboldtrue}
\DeclareOptionX{extrabold}{\atkinson@extraboldtrue}
\DeclareOptionX{medium}{\atkinson@mediumtrue}
\DeclareOptionX{light}{\atkinson@lighttrue}
\DeclareOptionX{extralight}{\atkinson@extralighttrue}
\DeclareOptionX{t}{\atkinson@tabulartrue}
\DeclareOptionX{nomono}{\atkinson@monofalse}


\ProcessOptionsX\relax

\ifatkinson@otf

  \def\atkinson@boldstyle{Bold}
  \ifatkinson@semibold\def\atkinson@boldstyle{SemiBold}\fi
  \ifatkinson@extrabold\def\atkinson@boldstyle{ExtraBold}\fi
  \def\atkinson@regstyle{Regular}
  \ifatkinson@medium\def\atkinson@regstyle{Medium}\fi
  \ifatkinson@light\def\atkinson@regstyle{Light}\fi
  \ifatkinson@extralight\def\atkinson@regstyle{ExtraLight}\fi

\else % type1

  \def\bfseries@sf{b}
  \ifatkinson@semibold\def\bfseries@sf{sb}\fi
  \ifatkinson@extrabold\def\bfseries@sf{eb}\fi
  \def\mdseries@sf{m}
  \ifatkinson@medium\def\mdseries@sf{medium}\fi
  \ifatkinson@light\def\mdseries@sf{l}\fi
  \ifatkinson@extralight\def\mdseries@sf{el}\fi
  \ifatkinson@mono
    \def\bfseries@tt{b}
    \ifatkinson@semibold\def\bfseries@tt{sb}\fi
    \ifatkinson@extrabold\def\bfseries@tt{eb}\fi
    \def\mdseries@tt{m}
    \ifatkinson@medium\def\mdseries@tt{medium}\fi
    \ifatkinson@light\def\mdseries@tt{l}\fi
    \ifatkinson@extralight\def\mdseries@tt{el}\fi
  \fi

\fi

\ifatkinson@otf
  \ifatkinson@tabular
    \def\atkinson@figurealign{Monospaced} 
  \else
    \def\atkinson@figurealign{Proportional} 
  \fi
\else % type1
  \ifatkinson@tabular
    \def\atkinson@figurealign{T}
  \else
    \def\atkinson@figurealign{}
  \fi


\fi


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

\ifatkinson@otf
  \def\atkinson@regular{Regular}
  \defaultfontfeatures{
        Ligatures = TeX ,
        Scale     = \atkinsn@scale ,
        Extension = .otf }
    \setsansfont
        [ Numbers = {\atkinson@figurealign},
          UprightFont    = *-\atkinson@regstyle ,
          ItalicFont     = *-\atkinson@regstyle Italic,
          BoldFont       = *-\atkinson@boldstyle ,
          BoldItalicFont = *-\atkinson@boldstyle Italic ,
        ]
        {AtkinsonHyperlegibleNext}
  \ifatkinson@mono
    \setmonofont
        [ UprightFont    = *-\atkinson@regstyle ,
          ItalicFont     = *-\atkinson@regstyle Italic,
          BoldFont       = *-\atkinson@boldstyle ,
          BoldItalicFont = *-\atkinson@boldstyle Italic ,
        ]
        {AtkinsonHyperlegibleMono}
  \fi
  % grab current family in case of subsequent change:
  \let\atkinsonfamily\sfdefault  
  \ifatkinson@default\renewcommand*\familydefault{\atkinsonfamily}\fi
  \newfontfamily\atkinson
        [ Numbers = {\atkinson@figurealign},
          UprightFont    = *-\atkinson@regstyle ,
          ItalicFont     = *-\atkinson@regstyle Italic,
          BoldFont       = *-\atkinson@boldstyle ,
          BoldItalicFont = *-\atkinson@boldstyle Italic ,
        ]
        {AtkinsonHyperlegibleNext}
    \newfontfamily\atkinsonlf
        [ Numbers = {Proportional},
          UprightFont    = *-\atkinson@regstyle ,
          ItalicFont     = *-\atkinson@regstyle Italic,
          BoldFont       = *-\atkinson@boldstyle ,
          BoldItalicFont = *-\atkinson@boldstyle Italic ,
        ]
        {AtkinsonHyperlegibleNext}
    \newfontfamily\atkinsontlf
        [ Numbers = {Monospaced},
          UprightFont    = *-\atkinson@regstyle ,
          ItalicFont     = *-\atkinson@regstyle Italic,
          BoldFont       = *-\atkinson@boldstyle ,
          BoldItalicFont = *-\atkinson@boldstyle Italic ,
        ]
        {AtkinsonHyperlegibleNext}

\else % type1
  \def\atkinsonfamily{atkinsn-\atkinson@figurealign LF}
  \newcommand*\atkinson{\fontfamily{\atkinsonfamily}\selectfont}
  \def\sfdefault{\atkinsonfamily}
  \ifatkinson@default\edef\familydefault{\sfdefault}\edef\seriesdefault{\mdseries@sf}\fi
  \DeclareTextFontCommand\atkinsontlf{\fontfamily{atkinsn-TLF}\selectfont}
  \DeclareTextFontCommand\atkinsonlf{\fontfamily{atkinsn-LF}\selectfont}

  \ifatkinson@mono\def\ttdefault{atkinsnmono-TLF}\fi
     

\fi

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

\endinput
