% \iffalse meta-comment
%
% File: arsenal.dtx
% Copyright 2023 by Boris Veytsman
%
% It 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
%
%    https://www.latex-project.org/lppl.txt
%
%<*driver>
\documentclass{l3doc}
\usepackage[default]{arsenal}
\usepackage{natbib, booktabs}
\usepackage[tableposition=top]{caption}
\urlstyle{rm}
\begin{document}
  \RecordChanges
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
% \GetFileInfo{arsenal.sty}
% \title{\pkg{arsenal}---\LaTeX\ support of Arsenal fonts by Andrij Shevchenko}
% \date{\fileversion, \filedate}
% \author{Boris
% Veytsman\thanks{\href{mailto:borisv@lk.net}{borisv@lk.net},
% \href{mailto:boris@varphi.com}{boris@varphi.com}}}
% \maketitle
% \begin{abstract}
%   Arsenal is the font created by Andrij Shevchenko.  It won
%   Ukrainian Type Design Competition `Mystetsky Arsenal' in 2011.
%   This package provides \LaTeX\ support for it and matching math
%   fonts.
% \end{abstract}
% \tableofcontents
% \begin{documentation}
%
%\section{User manual}
%\label{sec:ug}
%
% 
%\subsection{Introduction}
%\label{sec:ug-intro}
%
% In 2011 the Ukrainian Type Design Competition ``Mystetsky Arsenal''
% (\url{http://www.ukrainian-type.com/about/}) was won by the font by
% Andrij Shevchenko.  The competiton was aimed at the creation of a
% modern practical font based on Ukrainian traditions.  The winner is
% remarkable for its clarity and clean shapes.
%
% Later the font was extended by Alexei Vanyashin \& cyreal.org, Nhung
% Nguyen, and Marc Foley (see
% \url{https://github.com/alexeiva/Arsenal}).  The font now supports a
% large number of languages with Latin and Cyrillic alphabet, it has
% real small caps, historic forms, swash capitals and many other
% features.  
%
% This package provides
% \LaTeX\ interface for the font and optionally math support.
%
% Since the font it in \textsc{otf} format, you do need a Unicode
% engine like \XeTeX\ or Lua\TeX\ to use it.  
%
%
%\subsection{Package options}
%\label{sec:ug-options}
%
% \begin{variable}{default, sfdefault, math, scale, Scale}
%   \changes{v0.2}{2023/09/04}{Added arsenal+kpsans value for math option}
%   The options for the package use the key-value interface.
%   The part |=true| for the boolean options can be dropped.
%
%   The following options are recognized:
%   \begin{description}
%   \item[default] whether to make Arsenal the main font of the
%     document, either |true| (the default) or |false|.
%   \item[sfdefault] whether to make Arsenal the sans serif font of your
%     document, either |true| or |false| (the default).
%   \item[math] whether to enable math support.  The currently
%     recognized options are |none|, |arsenal+kpsans|, |kpsans|, and
%     |iwona|.  The meaning is the following:
%     \begin{description}
%     \item[arsenal+kpsans] Use native font for math, adding missing
%       letter from the \textsc{otf} version of KpSans
%       font~\citep{kpfonts-otf}.  Unfortunately this option presently
%       does not work properly with \XeTeX, using wrong font
%       dimensions resulting in rather bad spacing.
%     \item[kpsans] Use \textsc{otf} version of KpSans
%       font~\citep{kpfonts-otf} for math.
%     \item[iwona] Use use \pkg{iwonamath}~\citep{iwonamath} for math.
%     \item[none] Do not define math fonts, leaving the math setup to the user.
%     \end{description}
%     The default depends on whether Arsenal is your main font and
%     which engine is used:
%     \begin{enumerate}
%     \item If Arsenal is the main font, and \XeTeX\ is used, then
%       |iwona|.
%     \item If Arsenal is the main font, and Lua\TeX\ is used, then
%     |arsenal+kpsans|. 
%     \item If Arsenal is not your main font, then |none|.
%     \end{enumerate}
% \item[scale] the scale for the font, by default 0.89.  The option
% |Scale| is a synonym.
%   \end{description}
% \end{variable}
%
%
%\subsection{Font features}
%\label{sec:ug-families}
%
% \begin{function}{\arsenalfamily, \textarsenal}
%   \begin{syntax}
%     \cs{arsenalfamily} \meta{text}
%     \cs{textarsenal}\Arg{text}
%   \end{syntax}
%   The font provides the commands \cs{arsenalfamily} and
%   \cs{textarsenal} for selecting the font.  Alternatively, the NFSS
%   commands \cs{fontfamily}|{arsenal}|\cs{selectfont} can be used to
%   select Arsenal family.
% \end{function}
%
% The font has normal and \textit{italic} shapes, as well as bolded
% \textbf{bold} and \textbf{\itshape bold italic}. It has
% \textsc{Small Caps}, \textsc{\itshape Italic Small Caps},
% \textsc{\bfseries Bold Small Caps} and \textsc{\bfseries\itshape
% Bold Italic Small Caps}.  They are selected by the standard \LaTeX\
% commands.  
%
% \begin{function}{\swshape, \textsw}
%   The font has Swash shape, selected by the commands \cs{swshape}
%   and \cs{textsw}.  There are both normal and bold versions:
%   \textsw{SWASH}, \textsw{\bfseries Bold SWASH}.  Moreover, there is
%   an italic version \textsw{\itshape SWASH},
%   \textsw{\bfseries\itshape Bold SWASH}, and even a small caps
%   version \textsw{\scshape Swash}, \textsw{\scshape\bfseries Bold
%   Swash}.
% 
% \end{function}
%
% The font has other features, such are two alternate forms and
% historic style.  They can be selected by the
% \pkg{fontspec}~\citep{fontspec} commands like
% |\addfontfeatures{Style=Historic}| or
% |\addfontfeautures{Alternate=1}|.  
%
%
%
%\subsection{Special symbols in text}
%\label{sec:chars}
%
% \begin{function}{
%   \texthryvnia,
%   \texttugrik,
%   \texttenge,
%   \textruble
% }
% The font has common currency characters, like \cs{textdollar}
% (\textdollar), \cs{textyen} (\textyen), \cs{textsterling}
% (\textsterling), \cs{texteuro} (\texteuro).  It also defines several
% less common currency characters:
%   \cs{texthryvnia} (\texthryvnia),
%   \cs{texttugrik} (\texttugrik),
%   \cs{texttenge} (\texttenge),
%   \cs{textruble} (\textruble).
% \end{function}
%
% \begin{function}{
%   \textaldine,
%   \textsmilewhite,
%   \textsmileblack
% }
% The font has \cs{textnumero} sign: \textnumero. It also defines some
% less common characters:
%   \cs{textaldine} (\textaldine),
%   \cs{textsmilewhite} (\textsmilewhite)
%   \cs{textsmileblack} (\textsmileblack).
% \end{function}
%
%
%\subsection{Math support}
%\label{sec:ug-math}
%   \changes{v0.2}{2023/09/04}{Added a section about math support}
%
% The support of math is presently experimental.  We offer several
% options, as discussed above in Section~\ref{sec:ug-options}.  Iwona font
% matches Arsenal in color and sizes, but some letters and proportions
% are different from those for Arsenal.  KpSans seems to be slightly
% darker.  The option of taking Latin letters from Arsenal and the
% missing symbols from KpSans is attractive, but is currently
% recommended for Lua\TeX\ only, since the font parameters seem to be
% misinterpreted by the \XeTeX\ engine.
%
%
% As discussed in \pkg{kpsans} documentation, if you use this package
% (options |kpsans| and |arsenal+kpsans|), do \emph{not} use
% \pkg{amssymb}.  The corresponding symbols are reimplemented in
% \pkg{kpsans}, and (almost) all \pkg{amssymb} commands are available
% by default when one of these options is chosen.  
%
% \end{documentation}
% \clearpage
%
% \begin{implementation}
%
% \section{Implementation}
% \label{sec:impl}
%
% 
%
%\subsection{Setting up}
%\label{sec:settingup}
%
%
% 
% First, we declare who we are:
%    \begin{macrocode}
%<@@=arsenal>
%<*package>
\ProvidesExplPackage {arsenal}
{2023-09-05} {v0.2}
{Arsenal font by Andrij Shevchenko}
%    \end{macrocode}
%
%
%\subsection{Options}
%\label{sec:options}
%
% \begin{variable}{
%   default,
%   sfdefault,
%   math,
%   scale,
%   Scale,
%   \l_@@_default_bool,
%   \l_@@_sfdefault_bool,
%   \l_@@_math_tl,
%   \l_@@_scale_tl,
% }
%    \begin{macrocode}
\tl_new:N \l_@@_math_tl
\keys_define:nn {arsenal}
{
  default .bool_set:N = \l_@@_default_bool,
  default .default:n = true,
  sfdefault .bool_set:N = \l_@@_sfdefault_bool,
  sfdefault .default:n = true,
  math .choices:nn = {none, arsenal+kpsans, kpsans, iwona}
  {\tl_set_eq:NN \l_@@_math_tl \l_keys_choice_tl },
  scale .tl_set:N = \l_@@_scale_tl,
  Scale .tl_set:N = \l_@@_scale_tl,
}
\keys_set:nn { arsenal }
{
  default=true,
  sfdefault = false,
  scale = 0.89,
}
\tl_clear:N \l_@@_math_tl
%    \end{macrocode}
% \end{variable}
%
% Processing options
%    \begin{macrocode}
\IfFormatAtLeastTF { 2022-06-01 }
  { \ProcessKeyOptions [ arsenal ] }
  {
    \RequirePackage { l3keys2e }
    \ProcessKeysOptions { arsenal }
  }
%    \end{macrocode}
% And setting up math
%    \begin{macrocode}
\tl_if_empty:NT \l_@@_math_tl
{
  \bool_if:NTF \l_@@_default_bool
  {
    \sys_if_engine_xetex:TF
    {
      \tl_set:Nn \l_@@_math_tl {iwona}
    }
    {
      \tl_set:Nn \l_@@_math_tl {arsenal+kpsans}
    }
  }
  {
    \tl_set:Nn \l_@@_math_tl {none}
  }
}
%    \end{macrocode}
%
%
%\subsection{Setting up font}
%\label{sec:font}
%
%    \begin{macrocode}
\RequirePackage{fontspec}
\newfontfamily\arsenalfamily{Arsenal-Regular.otf}
[
  NFSSFamily=arsenal,
  Ligatures=TeX,
  Scale=\l_@@_scale_tl,
  ItalicFont = Arsenal-Italic.otf,
  BoldFont = Arsenal-Bold.otf,
  BoldItalicFont = Arsenal-BoldItalic.otf,
  SwashFont = Arsenal-Regular.otf,
  SwashFeatures={Style=Swash},
  BoldSwashFont = Arsenal-Bold.otf,
  BoldSwashFeatures={Style=Swash},
  FontFace = {m}{itsw}{Font = Arsenal-Italic.otf, Style=Swash},
  FontFace = {b}{itsw}{Font = Arsenal-BoldItalic.otf, Style=Swash},
]
%    \end{macrocode}
%
% Checking whether we want the font to be default
%    \begin{macrocode}
\bool_if:NT \l_@@_default_bool
{
  \renewcommand\rmdefault{arsenal}
}

\bool_if:NT \l_@@_sfdefault_bool
{
  \renewcommand\sfdefault{arsenal}
}
%    \end{macrocode}
%
% \begin{macro}{\textarsenal}
%    \begin{macrocode}
\DeclareTextFontCommand{\textarsenal}{\arsenalfamily}
%    \end{macrocode}
% \end{macro}
%
% Swash changing rules
%    \begin{macrocode}
\DeclareFontShapeChangeRule {sw}{it}  {itsw}  {it}
\DeclareFontShapeChangeRule {it}{sw}  {itsw}  {sw}
%    \end{macrocode}
%
% Special characters, absent in the default
% \begin{macro}{
%   \texthryvnia,
%   \texttugrik,
%   \texttenge,
%   \textruble
% }
% Currency symbols
%    \begin{macrocode}
\DeclareUnicodeSymbol{\texthryvnia}       {"20B4}
\DeclareUnicodeSymbol{\texttugrik}        {"20AE}
\DeclareUnicodeSymbol{\texttenge}         {"20B8}
\DeclareUnicodeSymbol{\textruble}         {"20BD}
%    \end{macrocode}
%   
% \end{macro}
%
% \begin{macro}{
%   \textaldine,
%   \textsmilewhite,
%   \textsmileblack
% }
%  Other symbols
%    \begin{macrocode}
\DeclareUnicodeSymbol{\textaldine}        {"2767}
\DeclareUnicodeSymbol{\textsmilewhite}    {"263A}
\DeclareUnicodeSymbol{\textsmileblack}    {"263B}
%    \end{macrocode}
% \end{macro}
%
%
%\subsection{Math}
%\label{sec:math}
%
% Iwona is simple\ldots
%    \begin{macrocode}
\tl_new:N \l_@@_tmp_tl
\tl_if_eq:NnT \l_@@_math_tl {iwona}
{
  \tl_set:Nn \l_@@_tmp_tl {\fp_to_tl:n {\l_@@_scale_tl * 1.1}}
  \RequirePackage[Scale=\l_@@_tmp_tl, condensed, light]{iwonamath}
}
%    \end{macrocode}
%
% \changes{v0.2}{2023/09/04}{Separate scaling for upper and lowercase
% for kpsans}
% Now kpsans, see~\citep{kpfonts-otf}.  We adjust separately
% upper and lower cases\ldots 
%    \begin{macrocode}
\tl_if_eq:NnT \l_@@_math_tl {kpsans}
{
  \tl_set:Ne \l_@@_tmp_tl {\fp_to_tl:n {\l_@@_scale_tl * 1.1}}
  \RequirePackage[symbols]{kpfonts-otf}
  \setmathfont{KpMath-Sans.otf}[
  Scale=\l_@@_tmp_tl,
  BoldFont=KpMath-SansBold.otf]

  \setmathfont{KpMath-Sans.otf}[
  range={cal,bfcal},
  RawFeature=+ss01,
  Scale=\l_@@_tmp_tl,
  BoldFont=KpMath-SansBold.otf]
  
  \setmathfont{KpMath-Sans.otf}[
  range={
    scr/{Latin},
    bfscr/{Latin},
    frak/{Latin},
    bffrak/{Latin},
    up/{Latin, Greek, misc},
    bb/{Latin, Greek, misc},
    it/{Latin, Greek, misc},
    bbit/{Latin, Greek, misc},
    tt/{Latin, Greek, misc},
    sfup/{Latin, Greek, misc},
    sfit/{Latin, Greek, misc},
    bfup/{Latin, Greek, misc},
    bfit/{Latin, Greek, misc},
    bfsfup/{Latin, Greek, misc},
    bfsfit/{Latin, Greek, misc},
  },
  Scale=\fp_to_tl:n {\l_@@_tmp_tl * 0.9},
  BoldFont=KpMath-SansBold.otf]
}
%    \end{macrocode}
%
%   \changes{v0.2}{2023/09/04}{Added the warining about using
%   arsenal+kpsans with \XeTeX}
% And arsenal+kpsans.  We again adjust separately upper and lower cases\ldots
%    \begin{macrocode}
\tl_if_eq:NnT \l_@@_math_tl {arsenal+kpsans}
{
  \sys_if_engine_xetex:T
  {
    \ClassWarningNoLine{arsenal}{Option~ arsenal+kpsans~ may~ not~ work~
      with~ XeTeX~ engine.~  Please~ use~ lualatex}
  }
  \tl_set:Ne \l_@@_tmp_tl {\fp_to_tl:n {\l_@@_scale_tl * 1.1}}
  \RequirePackage[symbols]{kpfonts-otf}

  \setmathfont{KpMath-Sans.otf}[
  Scale=\l_@@_tmp_tl,
  BoldFont=KpMath-SansBold.otf]

  \setmathfont{KpMath-Sans.otf}[
  range={cal/{Latin},bfcal/{Latin}},
  RawFeature=+ss01,
  Scale=\fp_to_tl:n {\l_@@_tmp_tl * 0.9},
  BoldFont=KpMath-SansBold.otf]

  \setmathfont{KpMath-Sans.otf}[
  range={
    scr/{Latin, num},
    bfscr/{Latin, num},
    frak/{Latin, num},
    bffrak/{Latin, num},
    up/{Greek, misc, num},
    bb/{Latin, Greek, misc, num},
    it/{Greek, misc, num},
    bbit/{Greek, misc, num},
    tt/{Greek, misc, num},
    sfup/{Greek, misc, num},
    sfit/{Greek, misc, num},
    bfup/{Greek, misc, num},
    bfit/{Greek, misc, num},
    bfsfup/{Greek, misc, num},
    bfsfit/{Greek, misc, num},
  },
  Scale=\fp_to_tl:n {\l_@@_tmp_tl * 0.9},
  BoldFont=KpMath-SansBold.otf]
  
  
  \setmathfont{Arsenal-Regular.otf}[
  range={
    up/{Latin, latin, num},
    tt/{Latin, latin, num},
    sfup/{Latin, latin, num},
    bfup/{Latin, latin, num},
    bfsfup/{Latin, latin, num},
  },
  Scale=\l_@@_scale_tl,
  BoldFont=Arsenal-Bold.otf]

  \setmathfont{Arsenal-Italic.otf}[
  range={
    it/{Latin, latin, num},
    bbit/{Latin, latin, num},
    sfit/{Latin, latin, num},
    bfit/{Latin, latin, num},
    bfsfit/{Latin, latin, num},
  },
  Scale=\l_@@_scale_tl,
  BoldFont=Arsenal-BoldItalic.otf]


}      
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% \end{implementation}
%
% \bibliography{arsenal}
% \bibliographystyle{plainnat}
%
%
% \PrintIndex
% \PrintChanges