% \iffalse meta-comment
%
% File: se2fonts.dtx Copyright (C) 2022--2024 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 "se2thesis 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/se2p/se2thesis
%
% for those people who are interested.
%
% ---------------------------------------------------------------------
%
%<*driver>
\documentclass{l3doc}
% The next line is needed so that \GetFileInfo will be able to pick up
% version data.
\usepackage{se2fonts}

\usepackage[UKenglish]{babel}
\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage{hvlogos}

\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{se2fonts.sty}
%
% \title{^^A
%   \pkg{se2fonts}---Font Definitions for the \pkg{se2thesis} Bundle^^A
%   \thanks{This file describes \fileversion, last revised \filedate.}^^A
% }
%
% \author{^^A
%   Stephan Lukasczyk^^A
%   \thanks{^^A
%     E-mail: \href{mailto:stephan@dante.de}{stephan@dante.de}^^A
%   }^^A
% }
%
% \date{Released \filedate}
%
% \maketitle
%
% \begin{documentation}
%
% \section{The \pkg{se2fonts} package}\label{sec:doc-se2fonts}
%
% The \pkg{se2fonts} package sets the fonts of the document.
% In the first version of the bundle, we were running to use Hermann Zaph's
% \emph{Palatino}, \emph{Helvetica}, and \emph{Neo Euler} fonts.
% However, we figured out that they are not part of a standard \LaTeX{}
% installation, and thus required manual work by the user to install them.
% Furthermore, loading the fonts did not always work in a correct way.
%
% Thus, we decided to rethink this decision and---as a consequence---now use
% different fonts that are part of a recent standard \LaTeX{} installation:
% we use the \emph{Libertinus} fonts\footnote{
%   \href{https://github.com/alerque/libertinus}{https://github.com/alerque/libertinus}
% } for serif, sans-serif, and math typesetting
% and the \emph{Inconsolata} font\footnote{
%   \href{http://levien.com/type/myfonts/inconsolata.html}{http://levien.com/type/myfonts/inconsolata.html}
% } as a monospaced font.
%
% \emph{Please note:} this change might affect they way your documents look,
% and also might affect paragraph and line breaks!
%
% If you are using \LuaTeX{},
% fonts are expected to be present as open-type fonts;
% using \pdfLaTeX{} will fallback to Type-1 fonts.
%
% \emph{Please note:} the package does not support \XeTeX{}!
%
% The following options are defined by the \pkg{se2fonts} package
% to influence the selection of the fonts.
%
% The following list provides examples for each of the fonts:
% \begin{itemize}
%   \item {\fontspec{LibertinusSerif}An example text in Libertinus Serif}
%   \item {\fontspec{LibertinusSans}An example text in Libertinus Sans}
%   \item {\fontspec{InconsolataLGCNerdFont}An example text in Inconsolata}
% \end{itemize}
%
% The package provides additional helper functions
% that are also available to the user.
%
% \begin{function}{\pdftexengine, \xetexengine, \luatexengine}
%   \begin{syntax}
%     \cmd{\pdftexengine}
%     \cmd{\xetexengine}
%     \cmd{\luatexengine}
%   \end{syntax}
%   These commands alias the built-in \LaTeX3{} macros
%   \cs{sys_if_engine_pdftex_p:},
%   \cs{sys_if_engine_xetex_p:}, and
%   \cs{sys_if_engine_luatex_p:}.
%   They can be used to check which engine the user is currently running.
% \end{function}
%
% \begin{function}{\ifengineTF, \ifengineT, \ifengineF}
%   \begin{syntax}
%     \cmd{\ifengineTF} \marg{engine} \marg{then block} \marg{else block}
%     \cmd{\ifengineT} \marg{engine} \marg{then block}
%     \cmd{\ifengineF} \marg{engine} \marg{then block}
%   \end{syntax}
%   Allows to execute code based on the running engine.
%   The base variant \cs{ifengineTF} expects the user to specify a condition,
%   which can be built of combinations of the \cs{pdftexengine},
%   \cs{xetexengine}, and \cs{luatexengine} macros,
%   followed by the code that will be executed if the condition holds
%   and the code that will be executed if the condition does not hold.
%
%   For convenience,
%   we provide the variants \cs{ifengineT} and \cs{ifengineF}
%   that allow to omit an empty then or else branch, respectively.
% \end{function}
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{se2fonts} implementation}
%
% Start the \pkg{DocStrip} guards.
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% Identify the internal prefix (\LaTeX3 \pkg{DocStrip} convention): only
% internal material in this \emph{submodule} should be used directly.
%    \begin{macrocode}
%<@@=slcd_fonts>
%    \end{macrocode}
%
% Identify the package and give the overall version information.
%    \begin{macrocode}
\ProvidesExplPackage {se2fonts} {2024-09-19} {4.3.4}
  {A font-selection support package for the se2thesis bundle}
%    \end{macrocode}
%
% \subsection{Load-time options}
%
% The package does not have any load-time options; the formerly defined option
% to set the font mode was removed with \pkg{se2thesis} version 4.0.0.
%
% \subsection{Helper macros}
%
% Define a warning message of users of \pdfLaTeX{} that not all features of the
% fonts are available and that they should consider using \LuaTeX{} instead.
%    \begin{macrocode}
\msg_new:nnnn { seiifonts } { pdflatex-used }
  { You~ are~ using~ pdfLaTeX~ with~ the~ se2fonts~ packages.}
  {
    While~ this~ works~ some~ font~ features~ are~ not~ available,~ consider~ 
    using~ lualatex~ instead.
  }
%    \end{macrocode}
%
% \begin{macro}{\pdftexengine, \xetexengine, \luatexengine}
%   We define several alias macros to identify which engine the user is running.
%    \begin{macrocode}
\cs_new_eq:NN \pdftexengine \sys_if_engine_pdftex_p:
\cs_new_eq:NN \xetexengine \sys_if_engine_xetex_p:
\cs_new_eq:NN \luatexengine \sys_if_engine_luatex_p:
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifengineTF, \ifengineT, \ifengineF}
%   True, if the engine used matches the given first argument.
%    \begin{macrocode}
\NewExpandableDocumentCommand \ifengineTF { mmm }
  {
    \bool_if:nTF { #1 } { #2 } { #3 }
  }
\NewExpandableDocumentCommand \ifengineT { mm }
  {
    \bool_if:nT { #1 } { #2 } 
  }
\NewExpandableDocumentCommand \ifengineF { mm }
  {
    \bool_if:nF { #1 } { #2 }
  }
%    \end{macrocode}
% \end{macro}
%
% The package is not tested with \XeTeX{}, thus we provide an error to the user
% and stop the execution if they want to use the package with \XeTeX.
%    \begin{macrocode}
\ifengineT { \xetexengine }
  {
    \msg_new:nnnn { seiifonts } { xetex-not-supported }
      { XeTeX~ is~ not~ supported~ by~ the~ se2fonts~ package. }
      { Switch~ to~ pdfTeX~ or~ (preferably)~ LuaTeX. }
    \msg_error:nn { seiifonts } { xetex-not-supported }
  }
%    \end{macrocode}
%
% \subsection{Font loading}
%
% Load the \pkg{mismath} package, which itself loads \pkg{mathtools} and
% transitively \pkg{amsmath} \emph{before} \pkg{unicode-math}.
%    \begin{macrocode}
\RequirePackage{mismath}
%    \end{macrocode}
%
% Depending on the engine used by the user,
% we can use \pkg{fontspec} for loading fonts.
%    \begin{macrocode}
\ifengineTF { \luatexengine }
  {
%    \end{macrocode}
%
% If the user uses \LuaTeX{}, load \pkg{fontspec} and \pkg{unicode-math}.
%    \begin{macrocode}
    \RequirePackage{fontspec}
    \PassOptionsToPackage{math-style=ISO,bold-style=ISO}{unicode-math}
    \RequirePackage{unicode-math}
%    \end{macrocode}
%
% To make sure the scaling of the fonts matches, we let \pkg{fontspec} do this
% matching based on the lower-case characters.
%    \begin{macrocode}
    \defaultfontfeatures{ Scale = MatchLowercase }
    \defaultfontfeatures[\rmfamily]{ Scale = 1 }
%    \end{macrocode}
%
% Load the respective \pkg{libertinus-otf} package and omit the monospaced font.
%    \begin{macrocode}
    \PassOptionsToPackage{mono=false}{libertinus-otf}
    \RequirePackage{libertinus-otf}
%    \end{macrocode}
%
% Load the \emph{Inconsolata Nerd Font} monospaced font.
%    \begin{macrocode}
    \RequirePackage{inconsolata-nerd-font}
%    \end{macrocode}
%
%    \begin{macrocode}
  } {
%    \end{macrocode}
%
% The user does not use \LuaTeX{}, thus fallback to T1 fonts.
%    \begin{macrocode}
    \msg_warning:nn { seiifonts } { pdflatex-used }
    \PassOptionsToPackage{T1}{fontenc}
    \PassOptionsToPackage{scaled=0.9,varl}{inconsolata}
    \PassOptionsToPackage{mono=false}{libertinus-type1}
    \RequirePackage{fontenc}
    \RequirePackage{inconsolata}
    \RequirePackage{libertinus-type1}
  }
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \end{implementation}
%
% \PrintIndex
