%%
%% This is file `se2packages.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% se2thesis.dtx  (with options: `init')
%% se2packages.dtx  (with options: `package')
%% Copyright (C) 2022--2023 by Stephan Lukasczyk <tex@lukasczyk.me>
%% 
%% 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 work is "maintained" (as per LPPL maintenance status by
%%   Stephan Lukasczyk.
%% 
%% This work consists of the files se2thesis.dtx,
%%                                 se2thesis.ins,
%%                                 se2colors.dtx,
%%                                 se2fonts.dtx,
%%                                 se2packages.dtx,
%%                                 se2thesis-master-thesis-example.tex
%%           and the derived files se2thesis.pdf,
%%                                 se2thesis.cls,
%%                                 se2translations-english.trsl,
%%                                 se2translations-german.trsl,
%%                                 se2colors.sty,
%%                                 se2fonts.sty,
%%                                 se2packages.sty,
%%                                 se2thesis-master-thesis-example.bib, and
%%                                 se2thesis-master-thesis-example.pdf
\@ifundefined{ExplLoaderFileDate}
  { \RequirePackage{expl3} }
  {}
\@ifl@t@r\ExplLoaderFileDate{2020-01-09}
  {}
  {%
    \PackageError{se2colors}{Support package expl3 too old}
    {%
      You need to update your installation of the bundles 'l3kernel' and
      'l3packages'.\MessageBreak
      Loading~se2colors~will~abort!%
    }%
    \endinput
  }%
\providecommand \IfFormatAtLeastTF { \@ifl@t@r \fmtversion }
\ProvidesExplPackage {se2packages} {2024-04-20} {3.4.0}
  {Supporting packages for the se2thesis bundle}
\bool_new:N \l__slcd_packages_csquotes_bool
\bool_new:N \l__slcd_packages_booktabs_bool
\bool_new:N \l__slcd_packages_siunitx_bool
\bool_new:N \l__slcd_packages_minted_bool
\bool_new:N \l__slcd_packages_listings_bool
\tl_new:N \l__slcd_packages_biblatex_tl
\bool_new:N \l__slcd_packages_selnolig_bool
\bool_new:N \l__slcd_packages_luawidowcontrol_bool
\bool_new:N \l__slcd_packages_microtype_bool
\bool_new:N \l__slcd_packages_cleveref_bool
\bool_new:N \l__slcd_packages_all_bool
\keys_define:nn { seiipackages }
  {
    csquotes .bool_gset:N = \l__slcd_packages_csquotes_bool,
    csquotes .initial:n = true,
    nocsquotes .meta:n = {csquotes=false},

    booktabs .bool_gset:N = \l__slcd_packages_booktabs_bool,
    booktabs .initial:n = true,
    nobooktabs .meta:n = {booktabs=false},

    siunitx .bool_gset:N = \l__slcd_packages_siunitx_bool,
    siunitx .initial:n = false,

    minted .bool_gset:N = \l__slcd_packages_minted_bool,
    minted .initial:n = false,

    listings .bool_gset:N = \l__slcd_packages_listings_bool,
    listings .initial:n = false,

    biblatex .tl_gset:N = \l__slcd_packages_biblatex_tl,
    biblatex .initial:n = false,

    selnolig .bool_gset:N = \l__slcd_packages_selnolig_bool,
    selnolig .initial:n = true,
    noselnolig .meta:n = {selnolig=false},

    widowcontrol .bool_gset:N = \l__slcd_packages_luawidowcontrol_bool,
    widowcontrol .initial:n = false,
    nowidowcontrol .meta:n = {widowcontrol=false},

    microtype .bool_gset:N = \l__slcd_packages_microtype_bool,
    microtype .initial:n = true,
    nomicrotype .meta:n = {microtype=false},

    cleveref .bool_gset:N = \l__slcd_packages_cleveref_bool,
    cleveref .initial:n = false,

    all .bool_gset:N = \l__slcd_packages_all_bool,
    all .initial:n = false,
  }
\IfFormatAtLeastTF { 2022-06-01 }
  { \ProcessKeyOptions [ seiipackages ] }
  {
    \RequirePackage{ l3keys2e }
    \ProcessKeysOptions { seiipackages }
  }
\msg_set:nnnn { seiipackages } { conflicting-packages }
  { Setting~ both~ minted~ and~ listings~ to~ true~ is~ not~ possible. }
  { Choose~ either~ of~ them! }
\msg_new:nnn { seiipackages } { load-package }
  { se2packages~ loads~ the~ #1~ package now. }
\bool_lazy_and:nnT { \l__slcd_packages_minted_bool } { \l__slcd_packages_listings_bool }
  {
    \msg_error:nn { seiipackages } { conflicting-packages }
  }
\bool_if:NT \l__slcd_packages_all_bool
  {
    \bool_gset_true:N \l__slcd_packages_csquotes_bool
    \bool_gset_true:N \l__slcd_packages_booktabs_bool
    \bool_gset_true:N \l__slcd_packages_siunitx_bool
    \bool_gset_true:N \l__slcd_packages_minted_bool
    \bool_gset_false:N \l__slcd_packages_listings_bool
    \bool_gset_true:N \l__slcd_packages_selnolig_bool
    \bool_gset_true:N \l__slcd_packages_luawidowcontrol_bool
    \bool_gset_true:N \l__slcd_packages_microtype_bool
    \tl_gset:Nn \l__slcd_packages_biblatex_bool {true}
    \bool_gset_true:N \l__slcd_packages_cleveref_bool
  }
\bool_if:NT \l__slcd_packages_csquotes_bool
  {
    \msg_info:nnn { seiipackages } { load-package } { csquotes }
    \RequirePackage{fvextra}
    \RequirePackage{csquotes}
  }
\bool_if:NT \l__slcd_packages_booktabs_bool
  {
    \msg_info:nnn { seiipackages } { load-package } { booktabs }
    \RequirePackage{booktabs}
  }
\bool_if:NT \l__slcd_packages_siunitx_bool
  {
    \msg_info:nnn { seiipackages } { load-package } { siunitx }
    \RequirePackage[
      add-integer-zero=false,
      free-standing-units,
      group-minimum-digits=4,
      list-final-separator={, and },
      round-mode=figures,
      round-precision=3,
      separate-uncertainty=true,
      uncertainty-mode=separate,
    ]{siunitx}
  }
\bool_if:NT \l__slcd_packages_minted_bool
  {
    \msg_info:nnn { seiipackages } { load-package } { minted }
    \RequirePackage[newfloat=true]{minted}
    \setminted{
      autogobble,
      breaklines=true,
      fontsize=\footnotesize,
      frame=single,
      linenos=false,
      resetmargins=true,
      xleftmargin=1em,
      xrightmargin=1em,
    }
  }
\bool_if:NT \l__slcd_packages_listings_bool
  {
    \msg_info:nnn { seiipackages } { load-package } { listings }
    \RequirePackage{listings}
    \lstset{
      basicstyle=\footnotesize\ttfamily,
      breaklines=true,
      captionpos=t,
      extendedchars=true,
      frame=single,
      keywordstyle=\color{blue}\bfseries,
      showspaces=false,
      showtabs=false,
      showstringspaces=false,
      tabsize=2,
    }
  }
\bool_lazy_and:nnT { \l__slcd_packages_selnolig_bool } { \sys_if_engine_luatex_p: }
  {
    \IfFileExists { selnolig.sty }
      {
        \RequirePackage{selnolig}
      } {
        \msg:nnnn { seiipackages }
          { selnolig-not-available }
          { Could~ not~ find~ selnolig.sty }
          { You~ might~ want~ to~ install~ it~ for~ better~ ligatures~ control.}
        \msg_note:nn { seipackages } { selnolig-not-available }
      }
  }
\bool_lazy_and:nnT { \l__slcd_packages_luawidowcontrol_bool } { \sys_if_engine_luatex_p: }
  {
    \IfFileExists { lua-widow-control.sty }
      {
        \RequirePackage{lua-widow-control}
      } {
        \msg:nnnn { seiipackages }
          { lua-widow-control-not-available }
          { Could~ not~ find~ lua-widow-control.sty }
          {
            You~ might~ want~ to~ install~ it~ for~ better~ control~ over~
            widows~ and~ orphans.
          }
        \msg_note:nn { seipackages } { lua-widow-control-not-available }
      }
  }
\bool_if:NT \l__slcd_packages_microtype_bool
  {
    \msg_info:nnn { seiipackages } { load-package } { microtype }
    \RequirePackage{microtype}
    \bool_if:NF \l__slcd_packages_luawidowcontrol_bool
      {
        \clubpenalty=10000
        \widowpenalty=10000
        \displaywidowpenalty=10000
      }
    \SetExtraKerning{
      encoding = {OT1,T1,T2A,LY1,OT4,QX,T5,TS1,EU1,EU2}
    }{
      \textemdash = {167,167},
      — = {167,167}
    }
  }
\tl_if_eq:NnT \l__slcd_packages_biblatex_tl {alphabetic}
  {
    \msg_info:nnn { seiipackages } { load-package } { biblatex }
    \PassOptionsToPackage
      {
        backend=biber,
        backref=true,
        datamodel=software,
        giveninits=true,
        hyperref=auto,
        maxnames=100,
        minalphanames=3,
        sorting=nyt,
        style=alphabetic,
      } { biblatex }
      \RequirePackage{biblatex}
      \RequirePackage{software-biblatex}
      \ExecuteBibliographyOptions{
        halid=false,
        swhid=true,
        shortswhid=false,
        swlabels=true,
        vcs=true,
        license=true,
      }
  }

\bool_new:N \l__slcd_packages_biblatex_numeric_variants_bool
\tl_if_eq:NnT \l__slcd_packages_biblatex_tl {true}
  {
    \bool_gset_true:N \l__slcd_packages_biblatex_numeric_variants_bool
  }
\tl_if_eq:NnT \l__slcd_packages_biblatex_tl {numeric}
  {
    \bool_gset_true:N \l__slcd_packages_biblatex_numeric_variants_bool
  }

\bool_if:NT \l__slcd_packages_biblatex_numeric_variants_bool
  {
    \msg_info:nnn { seiipackages } { load-package } { biblatex }
    \PassOptionsToPackage
      {
        backend=biber,
        backref=true,
        citereset=chapter+,
        citetracker=context,
        giveninits=true,
        hyperref=auto,
        sorting=nyt,
        datamodel=acmdatamodel,
        style=acmnumeric,
      } { biblatex }
      \RequirePackage{biblatex}
      \RequirePackage{ragged2e}
      \RequirePackage[mark=arabic,shape=up,Ragged]{sidenotesplus}

      \newbibmacro{cite:authoryear}{%
        \printtext[labelnumberwidth]{%
          \usebibmacro{cite}%
        }%
        \setunit{\addspace}%
        \printnames{labelname}%
        \setunit{\labelnamepunct}\newblock%
        \usebibmacro{year}%
        \newunit%
        \printfield[title]{labeltitle}
      }

      \newrobustcmd*{\makebibmarginnote}[1]{%
        \sidenote*{\blxmkbibnote{foot}{#1}}}

      \DeclareCiteCommand{\maycite}[\makebibmarginnote]
        {\usebibmacro{prenote}}
        {\usebibmacro{citeindex}%
         \usebibmacro{cite:authoryear}}
        {\multicitedelim}
        {\usebibmacro{postnote}}

      \newcommand*{\cbx@savedcites}{}

      \newcommand*{\cbx@margcitewrap}[1]{%
        \global\let\cbx@savedcites\empty
        \mkbibbrackets{#1}%
        \cbx@savedcites
      }

      \DeclareCiteCommand{\margincite}[\cbx@margcitewrap]
        {\usebibmacro{prenote}}
        {\usebibmacro{citeindex}%
         \usebibmacro{cite}%
         \ifciteseen
           {}
           {\xappto\cbx@savedcites{\noexpand\maycite{\thefield{entrykey}}}}}
        {\multicitedelim}
        {\usebibmacro{postnote}}

      \DeclareMultiCiteCommand{\margincites}[\cbx@margcitewrap]{\margincite}{\multicitedelim}

      \DeclareAutoCiteCommand{margin}{\margincite}{\margincites}
      \ExecuteBibliographyOptions{autocite=margin}
      \newcommand{\bibliofont}{\footnotesize}
      \DeclareFieldFormat{titlecase}{#1}% Preserve capitalisation of titles
  }
\bool_if:NT \l__slcd_packages_cleveref_bool
  {
    \msg_info:nnn { seiipackages } { load-package } { cleveref }
    \AddToHook { begindocument/before }
      {
        \RequirePackage[capitalise]{cleveref}
        \Crefname{resq}{Research Question}{Research Questions}
        \Crefname{hyp}{Hypothesis}{Hypotheses}
      }
  }
