% \iffalse meta-comment
%
% File: inconsolata-nerd-font.dtx Copyright (C) 2023 Stephan Lukasczyk
%
% 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
%
% This file is part of the "inconsolata-nerd-font bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% The released version of this bundle is available from CTAN.
%
% ------------------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
%    https://github.com/stephanlukasczyk/inconsolata-nerd-font
%
% for those people who are interested.
%
% ------------------------------------------------------------------------------
%
%<*driver>
\documentclass{l3doc}
\usepackage{libertinus-otf}
\usepackage{hvlogos}
% The next line is needed so that \GetFileInfo will be able to pick up version
% data.
\usepackage{inconsolata-nerd-font}
\begin{document}
  \RecordChanges
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \DoNotIndex{
%   \endinput,
%   \ExplFileDate,
%   \ExplLoaderFileDate,
%   \fmtversion,
%   \l_keys_choice_tl,
%   \keys_define:nn,
%   \keys_set:nn,
%   \MessageBreak,
%   \PackageError,
%   \ProcessKeyOptions,
%   \ProcessKeysOptions,
%   \providecommand,
%   \@ifl@t@r,
%   \@ifpackagelater,
%   \@ifundefined,
%   \tl_clear:N,
%   \tl_if_empty:NTF,
%   \tl_if_eq:NnTF,
%   \tl_new:N,
%   \tl_put_right:Nn,
%   \tl_set:Nn,
%   \tl_set_eq:NN,
% }
%
% \GetFileInfo{inconsolata-nerd-font.sty}
%
% \title{^^A
%   \pkg{inconsolata-nerd-font}---Support package to use the Inconsolata^^A
%   Nerd Font TrueType fonts^^A
% }
%
% \author{^^A
%   Stephan Lukasczyk^^A
%   \thanks{^^A
%     E-mail: \href{mailto:stephan@dante.de}{stephan@dante.de}^^A
%   }
% }
%
% \date{\fileversion, \filedate}
%
% \maketitle
%
% \begin{abstract}
%   Inconsolata is a monospaced font designed by Raph Levien.
%   It is already available via the \pkg{inconsolata} package.
%   However, that package provides a pretty old version of the font;
%   Additionally, the Nerd Font project extended the font by a huge amount of
%   additional glyphs.
%   This package provides the font itself
%   and a convenient interface to load the font for the
%   \XeLaTeX{} and \LuaLaTeX{} engines.
% \end{abstract}
%
% \tableofcontents
%
% \begin{documentation}
%
% \section{User Manual}\label{sec:doc}
%
% The Inconsolata font is a monospaced font designed by Raph Levien.
% Its current version is available from the Google Fonts project.\footnote{%
%   \href{https://github.com/googlefonts/Inconsolata}{github.com/googlefonts/Inconsolata}
% }
% There exists an extension of this font by the Nerd Font project,\footnote{%
%   \href{https://www.nerdfonts.com/}{www.nerdfonts.com/}
% }
% which adds a huge amount of additional glyphs,
% especially useful for developers,
% to the original font.
% The extended version is available from GitHub.\footnote{
%   \href{https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/Inconsolata}{github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/Inconsolata}
% }
% This package provides the TrueType font files
% and a convenient way to use the font
% with the \XeTeX{} or \LuaTeX{} engines.
%
% This user guide gives a brief introduction into the possibilities
% provided by the \pkg{inconsolata-nerd-font} package.
%
% \subsection{License}\label{sec:doc-license}
%
% Permission is granted to copy, distribute, and/or modify this software under
% the terms of the \LaTeX{} Project Public License~(LPPL), version~1.3c or
% later~(\href{https://www.latex-project.org/lppl.txt}{https://www.latex-project.org/lppl.txt}).
% The software has the status \enquote{maintained}.
%
% The font files bundled with the package (\texttt{InconsolataNerdFont*.ttf})
% are licensed under the terms of the SIL Open Font License~(LPPL),
% version~1.1~(\href{http://scripts.sil.org/OFL}{http://scripts.sil.org/OFL}).
%
% \subsection{Helper Macros}\label{sec:doc-helper}
%
% The following macro is not strictly part of the package.
% It is actually defined by recent \LaTeX{} kernels.
% However, to make the package compatible with older kernels, too,
% we provide it, if it is not yet defined.
%
% The macro's purpose is to check whether the used \LaTeX{} format
% is at least from the given date
% and allows to execute code depending on the result of the check.
% \begin{function}{\IfFormatAtLeastTF}
%   \begin{syntax}
%     \cs{IfFormatAtLeastTF} \marg{date} \marg{true} \marg{false}
%   \end{syntax}
%   We define this macro to execute code depending on the \LaTeX{} format date.
%   The macro is only defined if it is not already part of the \LaTeX{} kernel,
%   which it is for recent versions of the kernel.
% \end{function}
%
% \subsection{Package Arguments}\label{sec:doc-arguments}
%
% The \pkg{inconsolata-nerd-font} package provides the following
% load-time options.
% \begin{variable}{variant}
%   \begin{syntax}
%     variant = \meta{choice}
%   \end{syntax}
%   Specifies which variant of the font shall be used, must be one of
%   |default|, |mono|, or |propo|, where |default| is the default value.
%
%   The |mono| variant is limited to only mono-spaced characters,
%   the |default| variant provides bigger icons (around 1.5 times the width of a
%   normal character),
%   the |propo| variant provides proportional symbols,
%   which might be suitable, e.g., for presentations.
% \end{variable}
%
% \begin{variable}{scale, Scale}
%   \begin{syntax}
%     scale = \marg{factor}
%     Scale = \marg{factor}
%   \end{syntax}
%   Set the scaling of the font.
%   See the \pkg{fontspec} documentation for more details.
%   The default value is |MatchLowercase| to match the height of the lower-case
%   character of the default main font of your document.
% \end{variable}
%
% \subsection{Font Macros}\label{sec:doc-macros}
%
% While the package sets the default mono-spaced font
% to the selected variant of the Inconsolata Nerd Font,
% the package provides six additional macros for convenience,
% one pair of each variant of the font.
%
% \begin{function}{\inconsolatanffamily}
%   \begin{syntax}
%     \cs{inconsolatanffamily}
%   \end{syntax}
%   A font family for the Inconsolata Nerd Font,
%   the default variant provided by this package.
% \end{function}
% \begin{function}{\inconsolatanfmonofamily}
%   \begin{syntax}
%     \cs{inconsolatanfmonofamily}
%   \end{syntax}
%   A font family for the Inconsolata Nerd Font,
%   the mono variant provided by this package.
% \end{function}
% \begin{function}{\inconsolatanfpropofamily}
%   \begin{syntax}
%     \cs{inconsolatanfpropofamily}
%   \end{syntax}
%   A font family for the Inconsolata Nerd Font,
%   the propo variant provided by this package.
% \end{function}
%
% \begin{function}{\textinconsolatanf}
%   \begin{syntax}
%     \cs{textinconsolatanf} \marg{text}
%   \end{syntax}
%   A convenience macro to typeset a short |text| using the default
%   Inconsolata Nerd Font variant.
% \end{function}
% \begin{function}{\textinconsolatanfmono}
%   \begin{syntax}
%     \cs{textinconsolatanfmono} \marg{text}
%   \end{syntax}
%   A convenience macro to typeset a short |text| using the mono
%   Inconsolata Nerd Font variant.
% \end{function}
% \begin{function}{\textinconsolatanfpropo}
%   \begin{syntax}
%     \cs{textinconsolatanfpropo} \marg{text}
%   \end{syntax}
%   A convenience macro to typeset a short |text| using the propo
%   Inconsolata Nerd Font variant.
% \end{function}
%
% The following sentence uses the \cs{textinconsolatanf}
% to typeset the words \enquote{an example} using Inconsolata Nerd Font:
% Just \textinconsolatanf{an example} sentence.
%
% \end{documentation}
%
% \clearpage
%
% \begin{implementation}
%
% \section{Implementation}\label{impl:pkg}
%
% Start the \pkg{DocStrip} guards.
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
% Identify the internal prefix (\LaTeX3 \pkg{DocStrip} convention): only
% internal matrial in this \emph{module} should be used directly.
%    \begin{macrocode}
%<@@=slcd_inf>
%    \end{macrocode}
% Load only the essential support (\pkg{expl3}) \enquote{up-front}, and only
% if required.
%    \begin{macrocode}
\@ifundefined{ExplLoaderFileDate}
  { \RequirePackage{expl3} }
  {}
%    \end{macrocode}
% Make sure that the version of \pkg{l3kernel} in use is sufficiently new.
% We use \cs{ExplFileDate} as \cs{@ifpackagelater} does not work for
% pre-loaded \pkg{expl3} in the absence of the package.
%    \begin{macrocode}
\@ifl@t@r\ExplLoaderFileDate{2020-01-09}
  {}
  {%
    \PackageError{inconsolata-nerd-font}{Support package expl3 too old}
    {%
      You need to update your installation of the bundles 'l3kernel' and
      'l3packages'.\MessageBreak
      Loading~inconsolata-nerd-font~will~abort!%
    }%
    \endinput
  }%
%    \end{macrocode}
%
% \begin{macro}{\IfFormatAtLeastTF}
%   This macro is not present in older kernels, thus we use the \LaTeXe{}
%   mechanism as this is correct for this case.
%    \begin{macrocode}
\providecommand \IfFormatAtLeastTF { \@ifl@t@r \fmtversion }
%    \end{macrocode}
% \end{macro}
%
% Identify the package and give the overall version information.
%    \begin{macrocode}
\ProvidesExplPackage {inconsolata-nerd-font} {2023-09-12} {0.2}
  {Support package to use the Inconsolata Nerd Font TrueType fonts}
%    \end{macrocode}
%
% \subsection{Options}\label{sec:impl-options}
%
% Define the options for the package.
% \begin{variable}{
%   variant,
%   scale,
%   Scale,
%   \l_@@_variant_tl,
%   \l_@@_scale_tl,
% }
%    \begin{macrocode}
\tl_new:N \l_@@_variant_tl

\keys_define:nn { inconsolatanerdfont }
  {
    variant .choices:nn = { default, mono, propo } {
      \tl_set_eq:NN \l_@@_variant_tl \l_keys_choice_tl
    },

    scale .tl_set:N = \l_@@_scale_tl,
    Scale .tl_set:N = \l_@@_scale_tl,
  }

\keys_set:nn { inconsolatanerdfont }
  {
    variant = default,
    scale = MatchLowercase,
  }
\tl_clear:N \l_@@_variant_tl
%    \end{macrocode}
% \end{variable}
%
% Process the options
%    \begin{macrocode}
\IfFormatAtLeastTF { 2022-06-01 }
  { \ProcessKeyOptions [ inconsolatanerdfont ] }
  {
    \RequirePackage { l3keys2e }
    \ProcessKeysOptions { inconsolatanerdfont }
  }
%    \end{macrocode}
% and set up the default variant if it was not yet chosen
%    \begin{macrocode}
\tl_if_empty:NT \l_@@_variant_tl
  {
    \tl_set:Nn \l_@@_variant_tl { default }
  }
%    \end{macrocode}
%
% \subsection{Load the Font}\label{sec:impl-load}
%
% We require the \pkg{fontspec} package.
%    \begin{macrocode}
\RequirePackage{fontspec}
%    \end{macrocode}
%
% Define and set a helper variable for the respective font name suffix
%    \begin{macrocode}
\tl_new:N \l_@@_font_name_tl
\tl_set:Nn \l_@@_font_name_tl {InconsolataNerdFont}
\tl_if_eq:NnTF \l_@@_variant_tl { mono }
  { \tl_put_right:Nn \l_@@_font_name_tl {Mono} }
  {
    \tl_if_eq:NnT \l_@@_variant_tl { propo }
      { \tl_put_right:Nn \l_@@_font_name_tl {Propo} }
  }
%    \end{macrocode}
%
% Define a font family for the three fonts and commands for easier usage
% \begin{macro}{
%   \inconsolatanffamily,
%   \inconsolatanfmonofamily,
%   \inconsolatanfpropofamily,
%   \textinconsolatanf,
%   \textinconsolatanfmono,
%   \textinconsolatanfpropo,
% }
%    \begin{macrocode}
\newfontfamily\inconsolatanffamily{InconsolataNerdFont-Regular.ttf}[
  BoldFont    = InconsolataNerdFont-Bold.ttf,
  FakeStretch = {0.9},
  NFSSFamily  = inconsolatanf,
  Scale       = \l_@@_scale_tl,
]
\newfontfamily\inconsolatanfmonofamily{InconsolataNerdFontMono-Regular.ttf}[
  BoldFont    = InconsolataNerdFontMono-Bold.ttf,
  FakeStretch = {0.9},
  NFSSFamily  = inconsolatanfmono,
  Scale       = \l_@@_scale_tl,
]
\newfontfamily\inconsolatanfpropofamily{InconsolataNerdFontPropo-Regular.ttf}[
  BoldFont    = InconsolataNerdFontPropo-Bold.ttf,
  FakeStretch = {0.9},
  NFSSFamily  = inconsolatanfpropo,
  Scale       = \l_@@_scale_tl,
]

\DeclareTextFontCommand{\textinconsolatanf}{\inconsolatanffamily}
\DeclareTextFontCommand{\textinconsolatanfmono}{\inconsolatanffamilymono}
\DeclareTextFontCommand{\textinconsolatanfpropo}{\inconsolatanffamilypropo}
%    \end{macrocode}
% \end{macro}
%
% Now we can actually load the font
%    \begin{macrocode}
\setmonofont{\l_@@_font_name_tl}[
  BoldFont    = *-Bold,
  Extension   = .ttf,
  FakeStretch = {0.9},
  Scale       = \l_@@_scale_tl,
  UprightFont = *-Regular,
]
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \end{implementation}
%
% \PrintIndex
% \PrintChanges