%% lato.sty
%% Copyright 2019 Mohamed El Morabity
%
% This work may be distributed and/or modified under the conditions of the LaTeX
% Project Public License, either version 1.3 of this license or (at your option)
% any later version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt and version 1.3 or later is part of all
% distributions of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Mohamed El Morabity
%
% This work consists of all files listed in manifest.txt.


\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{lato}[2019/06/20 Style file for Lato.]

\RequirePackage{fontaxes}
\RequirePackage{ifluatex}
\RequirePackage{ifxetex}
\RequirePackage{xkeyval}

\newif\iflato@otf
\ifxetex
  \lato@otftrue
\else
  \ifluatex
    \lato@otftrue
  \else
    \lato@otffalse
  \fi
\fi

\newif\iflato@lining
\newif\iflato@tabular

\newif\iflato@default
\lato@defaultfalse

\newif\iflato@defaultsans
\lato@defaultsansfalse

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

\DeclareOptionX{default}{\lato@defaulttrue}
\DeclareOptionX{defaultsans}{\lato@defaultsanstrue}
\DeclareOptionX{lining}{\lato@liningtrue}
\DeclareOptionX{oldstyle}{\lato@liningfalse}
\DeclareOptionX{tabular}{\lato@tabulartrue}
\DeclareOptionX{proportional}{\lato@tabularfalse}
\DeclareOptionX{type1}{\lato@otffalse}

\ExecuteOptionsX{tabular,lining}
\ProcessOptionsX
\relax

\iflato@tabular
  \newcommand*{\lato@figurewidth@otf}{Monospaced}
  \newcommand*{\lato@figurewidth@pfb}{T}
\else
  \newcommand*{\lato@figurewidth@otf}{Proportional}
  \newcommand*{\lato@figurewidth@pfb}{}
\fi
\iflato@lining
  \newcommand*{\lato@figurestyle@otf}{Lining}
  \newcommand*{\lato@figurestyle@pfb}{LF}
\else
  \newcommand*{\lato@figurestyle@otf}{OldStyle}
  \newcommand*{\lato@figurestyle@pfb}{OsF}
\fi

\newcommand*{\lato@familyprefix}{lato}
\newcommand*{\lato@family}[1]{\lato@familyprefix-#1}
\newcommand*{\latofamily}{\lato@family{\lato@figurewidth@pfb\lato@figurestyle@pfb}}

\iflato@otf
  \RequirePackage{fontspec}

  \ifxetex
    \XeTeXtracingfonts=1
  \fi

  \newcommand*{\lato@otf@features}{%
    Extension=.ttf,%
    Ligatures={TeX,Common},%
    Scale=\lato@scale,%
    FontFace={ul}{n}{*-Hairline},%
    FontFace={ul}{it}{*-HairlineItalic},%
    FontFace={el}{n}{*-Thin},%
    FontFace={el}{it}{*-ThinItalic},%
    FontFace={l}{n}{*-Light},%
    FontFace={l}{it}{*-LightItalic},%
    UprightFont={*-Regular},%
    ItalicFont={*-Italic},%
    FontFace={mb}{n}{*-Medium},%
    FontFace={mb}{it}{*-MediumItalic},%
    FontFace={sb}{n}{*-Semibold},%
    FontFace={sb}{it}{*-SemiboldItalic},%
    FontFace={b}{n}{*-Bold},%
    FontFace={b}{it}{*-BoldItalic},%
    BoldFont={*-Bold},%
    BoldItalicFont={*-BoldItalic},%
    FontFace={eb}{n}{*-Heavy},%
    FontFace={eb}{it}{*-HeavyItalic},%
    FontFace={ub}{n}{*-Black},%
    FontFace={ub}{it}{*-BlackItalic}%
  }

  % Define family for each figure style/width, with corresponding
  % NFSS family, for fontaxes support
  \newfontfamily{\lato@otf@TLF}[%
    \lato@otf@features,%
    Numbers={Monospaced,Lining},%
    NFSSFamily=\lato@family{TLF}%
  ]{Lato}
  \newfontfamily{\lato@otf@LF}[%
    \lato@otf@features,%
    Numbers={Proportional,Lining},%
    NFSSFamily=\lato@family{LF}%
  ]{Lato}
  \newfontfamily{\lato@otf@TOsF}[%
    \lato@otf@features,%
    Numbers={Monospaced,OldStyle},%
    NFSSFamily=\lato@family{TOsF}%
  ]{Lato}
  \newfontfamily{\lato@otf@OsF}[%
    \lato@otf@features,%
    Numbers={Proportional,OldStyle},%
    NFSSFamily=\lato@family{OsF}%
  ]{Lato}

  \expandafter\let\expandafter\lato\csname lato@otf@\lato@figurewidth@pfb\lato@figurestyle@pfb\endcsname

  % Legacy compatibility
  \newfontfamily{\flafamily}[%
    \lato@otf@features,%
    Numbers={Monospaced,Lining},%
    NFSSFamily=fla%
  ]{Lato}

  \iflato@defaultsans
    \setsansfont[%
      \lato@otf@features,%
      Numbers={\lato@figurewidth@otf,\lato@figurestyle@otf},%
    ]{Lato}
  \fi
  \iflato@default
    \setmainfont[%
      \lato@otf@features,%
      Numbers={\lato@figurewidth@otf,\lato@figurestyle@otf},%
    ]{Lato}
  \fi
\else
  \newcommand*{\lato}{\fontfamily{\latofamily}\selectfont}
  % Legacy compatibility
  \newcommand*{\flafamily}{\fontfamily{lato-TLF}\selectfont}

  \iflato@defaultsans
    \renewcommand*{\sfdefault}{\latofamily}
  \fi
  \iflato@default
    \renewcommand*{\familydefault}{\latofamily}
  \fi
\fi

\endinput
