% \iffalse meta-comment
%
% File: Chivo.dtx
% Copyright (C) 2016 Arash Esbati <esbati'at'gmx.de>
%
% This work may be distributed and/or modified under the conditions
% of the LaTeX Project Public License (LPPL), either version 1.3c of
% this license or (at your option) any later version.  The latest
% version of this license is in the file:
%
%    http://www.latex-project.org/lppl.txt
%
% \fi
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{Chivo}
%<package>  [2016/05/05 v1.0 Support for Chivo fonts (AE)]
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage[familydefault]{Chivo}
\usepackage[utf8]{inputenc}
\usepackage[OT1,LY1,T1]{fontenc}
\usepackage[scaled=1.09]{zlmtt}
\usepackage{textcomp}
\usepackage{fonttable,lipsum}
\usepackage[scaled=1.09]{zlmtt}
\usepackage[activate]{microtype}
\linespread{1.04}
\usepackage{hypdoc}
\newcommand*\pkg[1]{\textsf{#1}}
\DisableCrossrefs
\RecordChanges
\setlength\hfuzz{15pt}
\hbadness=7000
\frenchspacing
\raggedbottom
\makeatletter
\renewcommand\section{\@startsection{section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\normalfont\sffamily\Large\bfseries}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\normalfont\sffamily\large\bfseries}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\normalfont\sffamily\normalsize\bfseries}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
  {3.25ex \@plus1ex \@minus.2ex}%
  {-1em}%
  {\normalfont\sffamily\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{\parindent}%
  {3.25ex \@plus1ex \@minus .2ex}%
  {-1em}%
  {\normalfont\sffamily\normalsize\bfseries}}
\renewcommand\@makefntext[1]{%
  \@setpar{%
    \@@par \@tempdima=\hsize
    \advance\@tempdima by -1.5em\relax
    \parshape \@ne 1.5em \@tempdima
  }%
  \par \parindent=\z@ \noindent %
  \hb@xt@ \z@{\hss \hb@xt@ 1.5em{\@thefnmark.\hss}}%
  #1%
}
\makeatother
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{97}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \GetFileInfo{\jobname.sty}
%
% \MakeShortVerb{\"}
%
% \changes{v1.0}{2016/05/01}{Initial version}
%
% \title{Using \textsf{Chivo} fonts with LaTeX\thanks{This file has
% version number \fileversion, last revised \filedate.}}
% \author{Arash Esbati}
% \date{\filedate}
% \maketitle
%
% \begin{abstract}
%   \noindent
%   This package provides the necessary files to use the
%   \textsf{Chivo} fonts with LaTeX.  \textsf{Chivo} is a set of eight
%   fonts provided by Héctor Gatti \& Omnibus-Type Team under the Open
%   Font License (OFL).
% \end{abstract}
%
% \tableofcontents \clearpage
%
% \section{Introduction}
% \label{sec:introduction}
%
% \textsf{Chivo}\footnote{Copyright \textcopyright\ 2011--2015,
% Omnibus-Type (\url{http://www.omnibus-type.com})} is a set of eight
% fonts created by Héctor Gatti \& Omnibus-Type Team and provided by
% Omnibus-Type under the SIL Open Font License, Version 1.1.  From the
% web page:
% \begin{quote}\sffamily
%   ``\textsf{Chivo} is a grotesque typeface.  The strength of
%   \textsf{Chivo} makes it ideal for highlights and headlines.
%   \textsf{Chivo} Regular's elegance is ideal for combining with
%   \textsf{Chivo} Black's strength and for continuous reading
%   settings.''
% \end{quote}
%
% The fonts were obtained from Omni-Type web
% page\footnote{\url{http://http://omnibus-type.com/fonts/chivo.php}}.
% (v1.003, 8~fonts, 335~glyphs each).
%
% \section{Installation}
% \label{sec:installation}
%
% I suggest you use MikTeX or TeXlive and wait until the fonts are
% distributed for your TeX installation via their package manager.
%
% \section{Usage}
% \label{sec:usage}
%
% The fonts can be used with traditional (pdf)TeX engine and newer
% XeTeX and LuaTeX engines which can access OTF fonts directly.  They
% are described below.  In general, this bundle tries not to be smart
% and loads only \pkg{kvoptions.sty}, \pkg{mweights.sty} or
% \pkg{fontspec.sty}, depending on the used engine.  As the result,
% some work must be done by the user.
%
%
% \subsection{Engine independent options}
% \label{sec:engine-indep-opti}
%
% A package \pkg{Chivo.sty} is provided which can be loaded in the
% preamble as usual:
% \begin{quote}
%   "\usepackage{Chivo}"
% \end{quote}
% Loading the package changes the document's sans serif font to
% \textsf{Chivo}.  The package offers some options.
%
% \DescribeMacro{regular\,\textbar\,light}%
% The default font series is set with one of "regular" or "light"~--
% "regular" is the default.  Note that these options are defined as
% complementary ones.  Setting one option to `false' sets the other
% one automatically to `true', i.e.
% \begin{quote}
%   "\usepackage[regular = false]{Chivo}" \\
%   \mbox{} \quad or                      \\
%   "\usepackage[light   = true] {Chivo}"
% \end{quote}
% have the same effect.
%
% \DescribeMacro{bold\,\textbar\,black}%
% The default bold series is set with one of "bold" or "black"~--
% "bold" is the default.  Again, these options are complementary as
% well.
%
% \DescribeMacro{familydefault}%
% The main font of a document can be switched to \textsf{Chivo} with
% package option "familydefault" or "familydefault=true", e.g.:
% \begin{quote}
%   "\usepackage[familydefault]{Chivo}"
% \end{quote}
%
% \DescribeMacro{opentype\,\textbar\,type1}%
% If the automatic engine detection fails, it can be specified by the
% user with one of "opentype" or "type1".  Note that these option do
% not take a boolean value "true" or "false".
%
% \subsection{(pdf)LaTeX specific option}
% \label{sec:under-pdflatex}
%
% \DescribeMacro{scale}%
% The size of the \textsf{Chivo} fonts can be adjusted with the
% "scale" option, e.g.:
% \begin{quote}
%   "\usepackage[scale=0.97]{Chivo}"
% \end{quote}
%
% OT1, LY1, T1 and TS1 encodings are supported.  \pkg{Chivo.sty}
% does not load the respective packages, it is up to user to load
% them, e.g.:
% \begin{quote}
%   "\usepackage[T1]{fontenc}" \\
%   "\usepackage{Chivo}"       \\
%   "\usepackage{textcomp}"
% \end{quote}
%
% \subsection{XeLaTeX and LuaLaTeX specific options}
% \label{sec:under-xelat-lual}
%
% These engines can access OTF fonts directly.  The standard interface
% for this purpose is
% \pkg{fontspec.sty}\footnote{\url{http://ctan.org/pkg/fontspec}}.
% \pkg{Chivo.sty} detects if XeLaTeX or LuaLaTeX is used and based on
% options given by \texttt{regular\textbar light} and/or
% \texttt{bold\textbar black}, it uses \cmd{\defaultfeature} to define
% "Chivo" and passes it to "\setsansfont", e.g.:
% \begin{quote}
%   "\defaultfontfeatures[Chivo]"              \\
%   "  {"                                      \\
%   "    Extension      = .otf              ," \\
%   "    BoldFont       = Chivo-Black       ," \\
%   "    ItalicFont     = Chivo-LightItalic ," \\
%   "    BoldItalicFont = Chivo-BlackItalic ," \\
%   "    UprightFont    = Chivo-Light"         \\
%   "  }"                                      \\
%   "\AtBeginDocument{\setsansfont{Chivo}}"
% \end{quote}
%
% The "scale" package option does not work with \pkg{fontspec.sty}.
% This and any other \pkg{fontspec.sty} option can be set with
% \cmd{\defaultfeature+}, e.g.:
% \begin{quote}
%   "\usepackage{fontspec}"            \\
%   "\usepackage{Chivo}"               \\
%   "\defaultfontfeatures+[Chivo]"     \\
%   "  {"                              \\
%   "    Ligatures = TeX            ," \\
%   "    Scale     = MatchLowercase ," \\
%   "    Color     = blue"             \\
%   "  }"
% \end{quote}
%
% \clearpage
%
% \section{OT1 encoding font table}
% \label{sec:ot1-font-table}
%
% \xfonttable{OT1}{Chivo-TLF}{m}{n}
%
% \clearpage
%
% \section{LY1 encoding font table}
% \label{sec:ly1-font-table}
%
% \xfonttable{LY1}{Chivo-TLF}{m}{n}
%
% \section{T1 encoding font table}
% \label{sec:t1-font-table}
%
% \xfonttable{T1}{Chivo-TLF}{m}{n}
%
% \section{TS1 encoding font table}
% \label{sec:ts1-font-table}
%
% \xfonttable{TS1}{Chivo-TLF}{m}{n}
%
% \clearpage
%
% \section{Text samples}
% \label{sec:text-samples}
%
% \subsection*{Regular}
% \lipsum[1]\lipsum*[2] \quad 1234567890
%
% \subsection*{Italic}
% {\itshape\lipsum[1]\lipsum*[2] \quad 1234567890}
%
% \subsection*{Bold}
% {\bfseries\lipsum[1]\lipsum*[2] \quad 1234567890}
%
% \subsection*{Bold italic}
% {\bfseries\itshape\lipsum[1]\lipsum*[2] \quad 1234567890}
%
% \subsection*{Black}
% {\fontseries{k}\selectfont\lipsum[1]\lipsum*[2] \quad 1234567890}
%
% \subsection*{Black italic}
% {\fontseries{k}\selectfont\itshape\lipsum[1]\lipsum*[2] \quad 1234567890}
%
% \subsection*{Light}
% {\fontseries{l}\selectfont\lipsum[1]\lipsum*[2] \quad 1234567890}
%
% \subsection*{Light italic}
% {\fontseries{l}\selectfont\itshape\lipsum[1]\lipsum*[2] \quad 1234567890}
%
% \StopEventually{^^A
%   \PrintChanges
% }
%
% \clearpage
%
% \section{Implementation}
% \label{sec:implementation}
%
% Font support files are generated by "autoinst", invoked with:
% \begin{verbatim}
% autoinst                \
%   --encoding=OT1,T1,LY1 \
%   --ts1                 \
%   --sanserif            \
%   --defaultlining       \
%   --defaulttabular      \
%   --nooldstyle          \
%   --noproportional      \
%   --nosmallcaps         \
%   --noswash             \
%   --notitling           \
%   --nosuperiors         \
%   --noinferiors         \
%   --fractions           \
%   --noornaments         \
%   --noupdmap            \
%   --verbose             \
% Chivo-*.otf
% \end{verbatim}
% \vspace{-\baselineskip}
%
% We don't use the \pkg{Chivo.sty} generated by "autoinst" and use our
% version instead.
%
% \subsection{Chivo.sty}
% \label{sec:chivo.sty}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% First, we need a switch to know which engine is used:
%    \begin{macrocode}
\newif\ifChivo@otf
\ifdefined\XeTeXinterchartoks % we are in XeTeX
  \Chivo@otftrue
\else
  \ifdefined\directlua        % we are in LuaTeX
    \Chivo@otftrue
  \fi
\fi
%    \end{macrocode}
%
% Load the packages we rely on:
% \pkg{fontspec.sty}\footnote{\url{https://www.ctan.org/pkg/fontspec}}
% or
% \pkg{mweights.sty}\footnote{\url{https://www.ctan.org/pkg/mweights}}:
%    \begin{macrocode}
\ifChivo@otf
  \RequirePackage{fontspec}
\else
  \RequirePackage{mweights}
\fi
%    \end{macrocode}
%
% We use
% \pkg{kvoptions}\footnote{\url{https://www.ctan.org/pkg/kvoptions}}
% for our purposes:
%    \begin{macrocode}
\RequirePackage{kvoptions}
%    \end{macrocode}
% Setup the keyval options:
%    \begin{macrocode}
\SetupKeyvalOptions{%
  family = Chivo  ,
  prefix = Chivo@
}
%    \end{macrocode}
%
% The basic strategy for font related keys is to declare them as
% complementary options.
%    \begin{macrocode}
\DeclareBoolOption{regular}
\DeclareComplementaryOption{light}{regular}
\DeclareBoolOption{bold}
\DeclareComplementaryOption{black}{bold}
%    \end{macrocode}
%
% "scale" key is special: With (pdf)LaTeX, it is a string option, with
% XeLaTeX and LuaLaTeX, it is a void option and generates a warning.
%    \begin{macrocode}
\ifChivo@otf
  \DeclareVoidOption{scale}{\relax}
\else
  \DeclareStringOption[1.0]{scale}
\fi
%    \end{macrocode}
%
% "familydefault" switches the default font to \textsf{Chivo}.
%    \begin{macrocode}
\DeclareBoolOption{familydefault}
%    \end{macrocode}
%
% The next 2 are for users where the automatic engine detection might
% fail.
%    \begin{macrocode}
\DeclareVoidOption{opentype}{\Chivo@otftrue}
\DeclareVoidOption{type1}{\Chivo@otffalse}
%    \end{macrocode}
%
% Execute the default options and process them.
%    \begin{macrocode}
\setkeys{Chivo}{regular,bold}
\ProcessKeyvalOptions{Chivo}
%    \end{macrocode}
%
% Definition for "regular" and "light" keys for traditional engines:
%    \begin{macrocode}
\ifChivo@otf \else
  \ifChivo@regular
    \def\mdseries@sf{m}
  \else
    \def\mdseries@sf{l}
  \fi
\fi  
%    \end{macrocode}
%
% Definition for "bold" and "black" keys for traditional engines:
%    \begin{macrocode}
\ifChivo@otf \else
  \ifChivo@bold
    \def\bfseries@sf{b}
  \else
    \def\bfseries@sf{k}
  \fi
\fi  
%    \end{macrocode}
%
% For XeLaTeX/LuaLaTeX, we define the font features depending on the
% given package options:
%    \begin{macrocode}
\ifChivo@otf
  \ifChivo@regular
    \ifChivo@bold
      \defaultfontfeatures[Chivo]
        {
          Extension      = .otf              ,
          BoldFont       = Chivo-Bold        ,
          ItalicFont     = Chivo-Italic      ,
          BoldItalicFont = Chivo-BoldItalic  ,
          UprightFont    = Chivo-Regular
        }
    \else
      \defaultfontfeatures[Chivo]
        {
          Extension      = .otf              ,
          BoldFont       = Chivo-Black       ,
          ItalicFont     = Chivo-Italic      ,
          BoldItalicFont = Chivo-BlackItalic ,
          UprightFont    = Chivo-Regular
        }
    \fi
  \else
    \ifChivo@bold
      \defaultfontfeatures[Chivo]
        {
          Extension      = .otf              ,
          BoldFont       = Chivo-Bold        ,
          ItalicFont     = Chivo-LightItalic ,
          BoldItalicFont = Chivo-BoldItalic  ,
          UprightFont    = Chivo-Light
        }
    \else
      \defaultfontfeatures[Chivo]
        {
          Extension      = .otf              ,
          BoldFont       = Chivo-Black       ,
          ItalicFont     = Chivo-LightItalic ,
          BoldItalicFont = Chivo-BlackItalic ,
          UprightFont    = Chivo-Light
        }
    \fi
  \fi
\fi
%    \end{macrocode}
%
% Switch the sans serif font to \textsf{Chivo}; the fonts provide
% only tabular lining figures.  With \pkg{fontspec}, we delay the
% \cmd{\setsansfont} until "AtBeginDocument" so that user can provide
% additional features with \cmd{\defaultfontfeatures+}.
%    \begin{macrocode}
\ifChivo@otf
  \AtBeginDocument{%
    \setsansfont{Chivo}%
  }
\else
  \renewcommand*{\sfdefault}{Chivo-TLF}
\fi
%    \end{macrocode}
%
% Switch the default font if the respective key is given:
%    \begin{macrocode}
\ifChivo@familydefault
  \renewcommand*{\familydefault}{\sfdefault}
  \ifChivo@otf\else
    \ifChivo@regular \else
      \edef\seriesdefault{\mdseries@sf}
    \fi
    \ifChivo@bold \else
      \edef\bfdefault{\bfseries@sf}
    \fi
  \fi
\fi
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \Finale
%
\endinput
%
% Local Variables:
% mode: doctex
% TeX-master: t
% End:
