% This package is provided 'as is' in the event that someone
% wants to compile the documentation that comes with my packages.
% It is not intended for any other purpose, although you may freely
% copy the code here to another file and modify it for your own purposes.
% There's no guarantee that it will work with other packages.
%
%  Copyright 2022-2025 Nicola Talbot
% 
%  This work may be distributed and/or modified under the
%  conditions of the LaTeX Project Public License, either version 1.3
%  of this license of (at your option) any later version.
%  The latest version of this license is in
%    http://www.latex-project.org/lppl.txt
%  and version 1.3 or later is part of all distributions of LaTeX
%  version 2005/12/01 or later.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{nlctuserguide}[2025/11/24 v1.16 (NLCT)]

\newcommand{\summarymarginpar}[1]{\marginpar{#1}}
\newcommand\summaryregularloc[1]{}
\newcommand*{\summaryloc}[1]{\summarylocbox{#1}}

\DeclareOption{summaryregularloc}{% new v1.15
 \let\summarymarginpar\@gobble
 \let\summaryloc\@gobble
 \let\summaryregularloc\@firstofone
}

\DeclareOption{summarymarginloc}{% new v1.15
 \renewcommand\summarymarginpar{\marginpar}%
 \renewcommand\summaryloc{\summarylocbox}%
 \let\summaryregularloc\@gobble
}

\newcommand{\nlctdoc@loadxr}{}
\DeclareOption{xr}{\renewcommand{\nlctdoc@loadxr}{\RequirePackage{xr-hyper}}}

\newcommand{\nlct@ns@ref@cs}{\vref}

\newcommand{\nlctnovref}{\renewcommand{\nlct@ns@ref@cs}{\ref}}
\newcommand{\nlctusevref}{\renewcommand{\nlct@ns@ref@cs}{\vref}}

\DeclareOption{vref}{\nlctusevref}
\DeclareOption{novref}{\nlctnovref}
\newif\ifnlctdoc@symgroup
\nlctdoc@symgrouptrue

\DeclareOption{atsymgroup}{\nlctdoc@symgrouptrue}
\DeclareOption{noatsymgroup}{\nlctdoc@symgroupfalse}

\newcommand{\nlctdocatnum}[1]{%
 \nlctdoc@symgrouptrue\renewcommand{\@nlctdoc@atnum}{#1}%
 \ifluatex
   \renewcommand{\bibglsothergroup}{\nlctdocsymbolgrouplabel}%
   \renewcommand{\bibglsothergrouptitle}{\nlctdocsymbolgrouptitle}%
 \fi
}
\newcommand{\@nlctdoc@atnum}{630000}

\DeclareOption{deephierarchy}{\setcounter{secnumdepth}{5}}

\newcommand{\nlct@definesymbols}{%
  \nlct@definefontsymbols
}

\newcommand{\nlct@definefontsymbols}{%
% requires stix or boisk
 \newrobustcmd{\tabsym}{%
  \BeginAccSupp{method=hex,unicode,ActualText=21B9}%
  \ensuremath{\barleftarrowrightarrowbar}%
  \EndAccSupp{}%
 }
% requires stix
 \newrobustcmd{\upsym}{%
  \BeginAccSupp{method=hex,unicode,ActualText=2B71}%
  \ensuremath{\baruparrow}%
  \EndAccSupp{}%
 }
}

\newcommand{\nlct@definetikzsymbols}{%
  \RequirePackage{tikz}%
  \usetikzlibrary{arrows.meta}%
  \newsavebox\tabsbox
  \sbox\tabsbox{%
   \resizebox{!}{8pt}{%
   \begin{tikzpicture}[thick]
   \draw[arrows={Bar[width=8pt]Triangle[width=6pt,length=5pt]-}]
     (0,0) -- (14pt,0);
   \draw[arrows={-Triangle[width=6pt,length=5pt]Bar[width=8pt]}]
     (0,-7pt) -- (14pt,-7pt);
   \end{tikzpicture}%
   }%
  }
  \newrobustcmd{\tabsym}{%
   \BeginAccSupp{method=hex,unicode,ActualText=21B9}%
   \thinspace
   \usebox\tabsbox
   \thinspace
   \EndAccSupp{}%
  }%
  \newrobustcmd{\upsym}{%
   \BeginAccSupp{method=hex,unicode,ActualText=2B71}%
   \begin{tikzpicture}
   \draw[arrows={-To[width=6pt,length=5pt]Bar[width=8pt]}]
   (0,0) -- (0,2ex);
   \end{tikzpicture}
   \EndAccSupp{}%
  }%
}

\DeclareOption{fontsymbols}{%
  \renewcommand{\nlct@definesymbols}{%
    \nlct@definefontsymbols
  }%
}

\DeclareOption{tikzsymbols}{%
  \renewcommand{\nlct@definesymbols}{%
    \nlct@definetikzsymbols
  }%
}

\newcommand{\nlct@indexmarks}{}
\newcommand{\nlctpostindexname}[1]{}

\DeclareOption{noindexmarks}{\renewcommand{\nlct@indexmarks}{}}

\DeclareOption{indexmarks}{%
 \renewcommand{\nlct@indexmarks}{%
   \@ifpackageloaded{scrbase}%
   {%
     \RequirePackage{scrlayer-scrpage}%
     \lofoot[\nlctindexfirstmark]{\nlctindexfirstmark}%
     \lofoot[\nlctindexfirstmark]{\nlctindexfirstmark}%
     \refoot[\nlctindexlastmark]{\nlctindexlastmark}%
     \rofoot[\nlctindexlastmark]{\nlctindexlastmark}%
     \renewcommand{\nlctpostindexname}[1]{\glsxtrbookindexmarkentry{##1}}%
   }%
   {}%
 }%
}

% default options:
\PassOptionsToPackage{
 record=nameref,
 indexcounter,
 floats,
 symbols,
 accsupp,
 nosuper,
 stylemods={mcols,bookindex,topic,longextra}
}{glossaries-extra}

\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{glossaries-extra}}

\ProcessOptions

\RequirePackage{iftex}
\RequirePackage{etoolbox}

\nlct@indexmarks
\nlct@definesymbols

\newcommand{\nlct@ifattachsupported}[2]{#2}
\newcommand{\nlct@doifattachsupported}[1]{\nlct@ifattachsupported{#1}{}}

\ifPDFTeX
  \RequirePackage[T1]{fontenc}
  \renewcommand{\nlct@ifattachsupported}[2]{#1}

  % \strong is provided by fontspec
  \providecommand*{\strong}[1]{\textbf{#1}}

\else
  \RequirePackage{fontspec}
  % v1.11 changed font from Linux Libertine O to Liberation
  \setmainfont{FreeSerif}
  \setsansfont{FreeSans}[Scale=.9]
  \setmonofont{FreeMono}[Scale=1.1]

  \ifluatex
     \newcommand{\nlctdocsymbolgrouplabel}[3]{%
      #3\directlua{if '#2'=='\@nlctdoc@atnum' then tex.print("@") else tex.print("glssymbols") end}}
     \newcommand{\nlctdocsymbolgrouptitle}[3]{%
      \directlua{if '#2'=='\@nlctdoc@atnum' then tex.print("@") else tex.print("\\glssymbolsgroupname") end}}

     \ifnlctdoc@symgroup
       \newcommand{\bibglsothergroup}{\nlctdocsymbolgrouplabel}
       \newcommand{\bibglsothergrouptitle}{\nlctdocsymbolgrouptitle}
     \else
       \newcommand{\bibglsothergroup}[3]{glssymbols}
       \newcommand{\bibglsothergrouptitle}[3]{\glssymbolsgroupname}
     \fi

    \renewcommand{\nlct@ifattachsupported}[2]{#1}
    \RequirePackage{luatex85}% need \pdfxform for attachfile
  \fi
\fi

\RequirePackage{fontawesome}
\RequirePackage{twemojis}
\RequirePackage{pifont}
\RequirePackage{amsfonts}
\RequirePackage{textcomp}
\RequirePackage{array}
\RequirePackage{upquote}
\RequirePackage{etoolbox}
\RequirePackage{hologo}
\RequirePackage{varioref}
\RequirePackage{xcolor}

\newcommand*{\nlct@doifkoma}[1]{\nlct@ifkoma{#1}{}}
\newcommand*{\nlct@ifkoma}[2]{#2}

\@ifclassloaded{scrreprt}{\let\nlct@ifkoma\@firstoftwo}
{
 \@ifclassloaded{scrartcl}{\let\nlct@ifkoma\@firstoftwo}
 {\@ifclassloaded{scrbook}{\let\nlct@ifkoma\@firstoftwo}{}}
}

\nlct@doifkoma{%
 \RequirePackage{scrhack}
 \ifnum\c@secnumdepth>3
   \RedeclareSectionCommand[beforeskip=10pt plus -2pt minus -1pt,
    afterskip=1sp plus -1sp minus 1sp]{paragraph}
 \fi
 \ifnum\c@secnumdepth>4
   \RedeclareSectionCommand[beforeskip=10pt plus -2pt minus -1pt,
    afterskip=1sp plus -1sp minus 1sp]{subparagraph}
 \fi
}

\RequirePackage[breakable,skins,listings]{tcolorbox}
\nlctdoc@loadxr
\RequirePackage{hyperref}
\hypersetup{hidelinks}

\RequirePackage{mfirstuc}[2022/10/14]

% Requires glossaries-extra v1.49+
\RequirePackage{glossaries-extra}[2022/10/14]
\nlct@doifattachsupported{\RequirePackage{attachfile}}

\renewcommand{\thepart}{\Roman{part}}
\renewcommand{\theHpart}{\Roman{part}}

\newglossary*{index}{\indexname}

\newcommand*{\thispackagename}{\jobname}
\newcommand*{\thispackage}{\styfmt{\thispackagename}}
\newcommand*{\examplesdir}{\jobname-examples}
\newcommand{\nlct@v@version}{}
\newcommand{\nlct@version}{}
\newcommand{\nlct@date}{}
\ExplSyntaxOn
\NewDocumentCommand \versiondate { m m }
{
 \tl_set:Nx \nlct@version { \tl_trim_spaces:n { #1 } }
 \tl_set:Nx \nlct@date { \tl_trim_spaces:n { #2 } }
 \tl_if_empty:NF \nlct@version
 {
   \tl_set:Nx \nlct@v@version { version ~ \nlct@version }
 }
 \tl_if_empty:NF \nlct@date
 {
   \tl_put_right:Nx  \nlct@v@version { ~ \nlct@date }
 }
 \date{\nlct@v@version}
}
\ExplSyntaxOff

\newcommand{\htmlavailable}{This document is also available as
\href{\jobname.html}{HTML (\filefmt{\jobname.html})}.}

\ExplSyntaxOn
\renewcommand{\title}[1]{\gdef\@title{#1}\hypersetup{pdftitle={\text_purify:n{#1}}}}
\ExplSyntaxOff

 \newrobustcmd{\visiblespace}{%
   \texttt{\verbvisiblespace}%
 }

\newcommand{\TeXLive}{\TeX\ Live}
\newcommand{\MikTeX}{Mik\TeX}

\newrobustcmd*{\texdocref}[1]{%
 \begin{terminal}\href{https://www.tug.org/texdoc/}{texdoc} #1\end{terminal}\noindent\ignorespaces}

% \tugboat{title}{year}{volume}{number}{pdf}
\newrobustcmd{\tugboat}[5]{\href{https://tug.org/TUGboat/tb#2-#4/#5}{\qt{#1}
\emph{TUGboat}, Volume~#3 (#2), No.~#4}}

\newrobustcmd{\urlfootref}[2]{\href{#1}{#2}\glsxtrdopostpunc{\footnote{\url{#1}}}}
\MFUexcl{\urlfootref}

\newrobustcmd{\texfaq}[2]{\href{https://texfaq.org/#1}{#2}}
\MFUexcl{\texfaq}

\newrobustcmd*{\CTANpkg}[1]{%
 \href{https://ctan.org/pkg/#1}{CTAN}%
 \glsxtrdopostpunc{\footnote{\href{https://ctan.org/pkg/#1}{\nolinkurl{ctan.org/pkg/#1}}}}%
}
\MFUexcl{\CTANpkg}

\newcommand*{\ctanmirrordocnofn}[2]{%
 \href{http://mirrors.ctan.org/#1.pdf}{#2}%
}

\newrobustcmd*{\ctanmirrornofn}[2]{%
 \href{http://mirrors.ctan.org/#1}{#2}%
}
\MFUexcl{\ctanmirrornofn}

\newrobustcmd*{\ctanmirror}[2]{%
 \href{http://mirrors.ctan.org/#1}{#2}%
 \glsxtrdopostpunc{\footnote{\href{http://mirrors.ctan.org/#1}{\nolinkurl{mirrors.ctan.org/#1}}}}%
}
\MFUexcl{\ctanmirror}

\newrobustcmd*{\ctanref}[2]{\href{https://ctan.org/#1}{#2}%
 \glsxtrdopostpunc{\footnote{\href{https://ctan.org/#1}{\nolinkurl{ctan.org/#1}}}}%
}
\MFUexcl{\ctanref}

\newrobustcmd*{\ctanpkg}[1]{\href{https://ctan.org/pkg/#1}{\nolinkurl{ctan.org/pkg/#1}}}
\MFUexcl{\ctanpkg}

\newrobustcmd*{\ctanpkgmirror}[2]{%
 \href{http://mirrors.ctan.org/pkg/#1}{#2}%
 \glsxtrdopostpunc{\footnote{\href{http://mirrors.ctan.org/pkg/#1}{\nolinkurl{mirrors.ctan.org/pkg/#1}}}}%
}
\MFUexcl{\ctanpkgmirror}

\newrobustcmd*{\ctansupportmirror}[2]{%
 \href{http://mirrors.ctan.org/support/#1}{#2}%
 \glsxtrdopostpunc{\footnote{\href{http://mirrors.ctan.org/support/#1}{\nolinkurl{mirrors.ctan.org/support/#1}}}}%
}
\MFUexcl{\ctansupportmirror}

\newrobustcmd{\texseref}[2]{\href{https://tex.stackexchange.com/#1}{#2}%
 \glsxtrdopostpunc{\footnote{\href{http://tex.stackexchange.com/#1}{\nolinkurl{tex.stackexchange.com/#1}}}}%
}
\MFUexcl{\texseref}

\newrobustcmd*{\dickimawhrefnofn}[2]{%
 \href{https://www.dickimaw-books.com/#1}{#2}%
}
\MFUexcl{\dickimawhrefnofn}

\newrobustcmd*{\dickimawhref}[2]{%
 \href{https://www.dickimaw-books.com/#1}{#2}%
 \glsxtrdopostpunc{\protect\footnote{\href{https://www.dickimaw-books.com/#1}{\nolinkurl{dickimaw-books.com/#1}}}}%
}
\MFUexcl{\dickimawhref}

\newcommand*{\blog}[2]{%
 \dickimawhref{blog/#1}{#2}%
}
\MFUexcl{\blog}

\newcommand*{\gallery}[1]{%
 \dickimawhref{gallery}{#1}%
}
\MFUexcl{\gallery}

\newcommand*{\galleryurl}[1]{%
 \dickimawhrefnofn{gallery/#1}{\nolinkurl{dickimaw-books.com/gallery/#1}}%
}
\MFUexcl{\galleryurl}

\newcommand*{\galleryref}[2]{%
 \dickimawhref{gallery/#1}{#2}%
}
\MFUexcl{\galleryref}

\newcommand*{\gallerytopic}[1]{%
 \dickimawhref{gallery/\##1}{\styfmt{#1} gallery}%
}
\MFUexcl{\gallerytopic}

\newcommand*{\gallerypage}[2]{%
 \galleryref{index.php?label=#1}{#2}%
}
\MFUexcl{\gallerypage}

\newcommand*{\faqspkg}[1]{%
 \dickimawhref{faq.php?category=#1}{\styfmt{#1} FAQ}%
}
\MFUexcl{\faqspkg}

\newcommand*{\faqpage}[2]{%
 \dickimawhref{faq.php?category=#1}{#2}%
}
\MFUexcl{\faqspage}

\newcommand*{\faqitem}[2]{%
 \dickimawhref{faq.php?itemlabel=#1}{#2}%
}
\MFUexcl{\faqitem}

\newcommand*{\menufmt}[1]{\textsf{#1}}
\newcommand*{\menusep}{\,\ding{220}\,}
\newrobustcmd*{\menu}[1]{%
  \def\nlct@menusep{}%
  \menufmt
  {%
    \@for\@menu@item:=#1\do{%
      \nlct@menusep\@menu@item
      \let\nlct@menusep\menusep
    }%
  }%
}

\newcommand{\refslistsep}{, }
\newcommand{\refslistlastsep}{ \& }

\newcommand*{\@refslist}[4]{%
 \bgroup
  \renewcommand{\DTLlistformatitem}{\ref}%
  \renewcommand*{\DTLlistformatsep}{#2}%
  \renewcommand*{\DTLlistformatlastsep}{#3}%
  #1\DTLformatlist{#4}%
 \egroup
}

\newcommand*{\s@refslist}[4]{%
 \bgroup
  \renewcommand{\DTLlistformatitem}{\ref*}%
  \renewcommand*{\DTLlistformatsep}{#2}
  \renewcommand*{\DTLlistformatlastsep}{#3}%
  #1\DTLformatlist{#4}%
 \egroup
}

\newcommand*{\@ref@numname}[1]{\ref{#1} (\nameref{#1})}
\newcommand*{\s@ref@numname}[1]{\ref*{#1} (\nameref*{#1})}

\newcommand*{\@numname@refslist}[4]{%
 \bgroup
  \let\DTLlistformatitem\@ref@numname
  \renewcommand*{\DTLlistformatsep}{#2}%
  \renewcommand*{\DTLlistformatlastsep}{#3}%
  #1\DTLformatlist{#4}%
 \egroup
}

\newcommand*{\s@numname@refslist}[4]{%
 \bgroup
  \let\DTLlistformatitem\s@ref@numname
  \renewcommand*{\DTLlistformatsep}{#2}%
  \renewcommand*{\DTLlistformatlastsep}{#3}%
  #1\DTLformatlist{#4}%
 \egroup
}


\newcommand{\sectionrefprefix}{\S}
\newrobustcmd{\sectionref}{\@ifstar\s@sectionref\@sectionref}
\MFUblocker{\sectionref}

\newcommand*{\@sectionref}[1]{\sectionrefprefix\ref{#1}}
\newcommand*{\s@sectionref}[1]{\sectionrefprefix\ref*{#1}}

\newcommand{\Sectionrefprefix}{\S}
\newrobustcmd{\Sectionref}{\@ifstar\s@Sectionref\@sectionref}

\newcommand*{\@Sectionref}[1]{\Sectionrefprefix\ref{#1}}
\newcommand*{\s@Sectionref}[1]{\Sectionrefprefix\ref*{#1}}

\MFUaddmap{\sectionref}{\Sectionref}
\MFUaddmap{\sectionrefprefix}{\Sectionrefprefix}

\newcommand{\sectionsrefprefix}{\S\S}
\newrobustcmd{\sectionsref}{%
 \@ifstar
  {\s@refslist{\sectionsrefprefix}{\refslistsep}{\refslistlastsep}}%
  {\@refslist{\sectionsrefprefix}{\refslistsep}{\refslistlastsep}}%
}
\MFUblocker{\sectionsref}

\newcommand{\Sectionsrefprefix}{\S\S}
\newrobustcmd{\Sectionsref}{%
 \@ifstar
  {\s@refslist{\Sectionsrefprefix}{\refslistsep}{\refslistlastsep}}%
  {\@refslist{\Sectionsrefprefix}{\refslistsep}{\refslistlastsep}}%
}
\MFUaddmap{\sectionsref}{\Sectionsref}
\MFUaddmap{\sectionsrefprefix}{\Sectionsrefprefix}

\newcommand{\tablerefprefix}{Table~}
\newcommand{\Tablerefprefix}{Table~}

\newrobustcmd*{\tableref}{\@ifstar\s@tableref\@tableref}
\newrobustcmd*{\Tableref}{\@ifstar\s@Tableref\@Tableref}

\newcommand*{\@tableref}[1]{\tablerefprefix\nlct@ns@ref@cs{#1}}
\newcommand*{\s@tableref}[1]{\tablerefprefix\ref*{#1}}

\newcommand*{\@Tableref}[1]{\Tablerefprefix\nlct@ns@ref@cs{#1}}
\newcommand*{\s@Tableref}[1]{\Tablerefprefix\ref*{#1}}

\MFUaddmap{\tableref}{\Tableref}

\newcommand{\tablesrefprefix}{tables~}
\newcommand{\Tablesrefprefix}{Tables~}

\newrobustcmd{\tablesref}{%
 \@ifstar
  {\s@refslist{\tablesrefprefix}{\refslistsep}{\refslistlastsep}}%
  {\@refslist{\tablesrefprefix}{\refslistsep}{\refslistlastsep}}%
}

\newrobustcmd{\Tablesref}{%
 \@ifstar
  {\s@refslist{\Tablesrefprefix}{\refslistsep}{\refslistlastsep}}%
  {\@refslist{\Tablesrefprefix}{\refslistsep}{\refslistlastsep}}%
}
\MFUaddmap{\tablesref}{\Tablesref}

\newcommand{\figurerefprefix}{figure~}
\newcommand{\Figurerefprefix}{Figure~}

\newrobustcmd*{\figureref}{\@ifstar\s@figureref\@figureref}
\newrobustcmd*{\Figureref}{\@ifstar\s@Figureref\@Figureref}

\newcommand*{\@figureref}[1]{\figurerefprefix\nlct@ns@ref@cs{#1}}
\newcommand*{\s@figureref}[1]{\figurerefprefix\ref*{#1}}

\newcommand*{\@Figureref}[1]{\Figurerefprefix\nlct@ns@ref@cs{#1}}
\newcommand*{\s@Figureref}[1]{\Figurerefprefix\ref*{#1}}

\MFUaddmap{\figureref}{\Figureref}

\newcommand{\figuresrefprefix}{figures~}
\newcommand{\Figuresrefprefix}{Figures~}

\newrobustcmd{\figuresref}{%
 \@ifstar
  {\s@refslist{\figuresrefprefix}{\refslistsep}{\refslistlastsep}}%
  {\@refslist{\figuresrefprefix}{\refslistsep}{\refslistlastsep}}%
}

\newrobustcmd{\Figuresref}{%
 \@ifstar
  {\s@refslist{\Figuresrefprefix}{\refslistsep}{\refslistlastsep}}%
  {\@refslist{\Figuresrefprefix}{\refslistsep}{\refslistlastsep}}%
}
\MFUaddmap{\figuresref}{\Figuresref}

\providecommand{\examplerefprefix}{Example~}
\providecommand{\Examplerefprefix}{Example~}

\newrobustcmd*{\exampleref}{\@ifstar\s@exampleref\@exampleref}
\newcommand*{\@exampleref}[1]{\examplerefprefix\nlct@ns@ref@cs{#1}}
\newcommand*{\s@exampleref}[1]{\examplerefprefix\ref*{#1}}

\newrobustcmd*{\examplenameref}[1]{\exampleref{#1} (\nameref{#1})}

\newrobustcmd*{\Exampleref}{\@ifstar\s@Exampleref\@Exampleref}
\newcommand*{\@Exampleref}[1]{\Examplerefprefix\nlct@ns@ref@cs{#1}}
\newcommand*{\s@Exampleref}[1]{\Examplerefprefix\ref*{#1}}

\MFUaddmap{\exampleref}{\Exampleref}

\newcommand{\examplesrefprefix}{examples~}
\newcommand{\Examplesrefprefix}{Examples~}

\newrobustcmd{\examplesref}{%
 \@ifstar
  {\s@refslist{\examplesrefprefix}{\refslistsep}{\refslistlastsep}}%
  {\@refslist{\examplesrefprefix}{\refslistsep}{\refslistlastsep}}%
}

\newrobustcmd{\examplesnameref}{%
 \@ifstar
  {\s@numname@refslist{\examplesrefprefix}{\refslistsep}{\refslistlastsep}}%
  {\@numname@refslist{\examplesrefprefix}{\refslistsep}{\refslistlastsep}}%
}

\newrobustcmd{\Examplesref}{%
 \@ifstar
  {\s@refslist{\Examplesrefprefix}{\refslistsep}{\refslistlastsep}}%
  {\@refslist{\Examplesrefprefix}{\refslistsep}{\refslistlastsep}}%
}
\MFUaddmap{\examplesref}{\Examplesref}

\newrobustcmd{\mExampleref}[1]{\Exampleref{#1}\examplemarginref{#1}}
\newrobustcmd{\mexampleref}[1]{\exampleref{#1}\examplemarginref{#1}}

\newcommand{\exmarginfont}{\color{black}\footnotesize}% v1.12

\newrobustcmd{\examplemarginref}[1]{%
 \marginpar{\exmarginfont\hyperref[#1]{\codesym}\ref{#1}\plabel{#1-backref}}%
}

\newcommand*{\plabel}[2][]{\protected@edef\@currentlabelname{#1}\label{#2}}
\newcommand*{\pref}[2][]{on page~\pageref{#2}}
\newcommand*{\phyperref}[2]{\hyperref[#2]{#1} on page~\pageref{#2}}

\newcommand*{\dash}{\,---\,}
\newcommand{\Slash}{\,\slash\,}% v1.11

\newcommand*{\tick}{\ding{51}}

\newcommand*{\yes}{\ding{52}}
\newcommand*{\no}{\ding{56}}

\newrobustcmd{\advantagefmt}[1]{\textcolor{green}{#1}}
\newrobustcmd{\disadvantagefmt}[1]{\textcolor{red}{#1}}

\newcommand*{\proyes}{\advantagefmt{\yes}}
\newcommand*{\prono}{\disadvantagefmt{\no}}
 
\newcommand*{\conyes}{\disadvantagefmt{\yes}}
\newcommand*{\conno}{\advantagefmt{\no}}

\newcommand{\unlimited}{$\infty$}

{\catcode`\^^I12\relax
\gdef\nlctliteraltabchar{^^I}
}

\newcommand{\fnsymmark}[1]{\rlap{#1}}

\newcommand{\asteriskmarker}{\textasteriskcentered}
\newcommand{\daggermarker}{\textdagger}
\newcommand{\doubledaggermarker}{\textdaggerdbl}
\newcommand{\sectionmarker}{\textsection}
\newcommand{\lozengemarker}{$\lozenge$}
\newcommand{\pilcrowmarker}{\textparagraph}
\newcommand{\hashmarker}{\#}
\newcommand{\referencemarker}{{\fontfamily{cmr}\selectfont\textreferencemark}}
\newcommand{\vdoubleasteriskmarker}{\shortstack{*\\[-1.5ex]*}}
\newcommand{\starmarker}{$\star$}
\newcommand{\florettemarker}{\ding{94}}

\newcommand{\fnsymmarker}[1]{%
  \ifcase#1\relax
  \or \asteriskmarker 
  \or \daggermarker
  \or \doubledaggermarker 
  \or \sectionmarker
  \or \lozengemarker
  \or \pilcrowmarker
  \or \hashmarker
  \or \referencemarker
  \or \vdoubleasteriskmarker
  \or \starmarker
  \or \florettemarker
  \else
    \number#1
  \fi
}

\newrobustcmd*{\fnsym}{\@ifstar\s@fnsym\@fnsym}

\newcommand{\@fnsym}[1]{%
 \tablefnmark
 {%
   \fnsymmark
   {%
     \fnsymmarker{#1}%
   }%
 }%
}

\newcommand{\s@fnsym}[1]{%
 \tablefnmark
 {%
   \fnsymmarker{#1}%
 }%
}

\newcommand{\tablefns}[1]{\par
 \parbox{0.8\linewidth}
 {\raggedright
   \smallskip\hrulefill\par\smallskip
   \par#1%
 }\par
}

\newcommand*{\tablefnmark}[1]{\textsuperscript{#1}}
\newcommand{\tablefnfmt}[1]{{\footnotesize#1\par}}
\newrobustcmd{\tablefntext}[2]{\tablefnfmt{\tablefnmark{#1}#2}}
\newrobustcmd{\fnsymtext}[2]{\tablefntext{\fnsymmarker{#1}}{#2}}

\newcommand{\settabcolsep}[1]{\setlength{\tabcolsep}{#1}}

\newcommand*{\docref}[2]{#1 (\href{#2.pdf}{\nolinkurl{#2.pdf}})}
\newcommand*{\qtdocref}[2]{\qt{#1} (\href{#2.pdf}{\nolinkurl{#2.pdf}})}

% \altdocref{text}{pdf}{html}
\newcommand*{\altdocref}[3]{#1 (\href{#2.pdf}{\nolinkurl{#2.pdf}})}

% \xrsectionref{label}{html file}{html title}
\newcommand*{\xrsectionref}[3]{Section~\ref{#1}}

\newcommand{\deflist@item}[1]{\item[]#1}
\newenvironment{itemdesc}{\par\nobreak\ignorespaces}{\ignorespacesafterend}

\newenvironment{deflist}
 {\begin{description}\let\itemtitle\deflist@item}
 {\end{description}\ignorespacesafterend}


\newcommand*{\warningsym}{\faExclamationTriangle}
\newcommand*{\warningtext}{Warning}
\newcommand*{\warningdesc}{a warning}

\newcommand*{\importantsym}{\faInfo}
\newcommand*{\importanttext}{Important}
\newcommand*{\importantdesc}{an important message}

\newcommand*{\informationsym}{\faInfoCircle}
\newcommand*{\informationtext}{Information}
\newcommand*{\informationdesc}{prominent information}

\newcommand*{\definitionsym}{\faThumbTack}
\newcommand*{\definitiontext}{Definition}
\newcommand*{\definitiondesc}{the syntax and usage of a command,
environment or option etc}

\newcommand*{\valuesettingsym}{\faSliders}
\newcommand*{\valuesettingtext}{Setting}
\newcommand*{\valuesettingdesc}{an option that takes a value}

\newcommand*{\novaluesettingsym}{\faBars}
\newcommand*{\novaluesettingtext}{Valueless Setting}
\newcommand*{\novaluesettingdesc}{an option that doesn't take a value}

\newcommand*{\toggleonsettingsym}{\faToggleOn}
\newcommand*{\toggleonsettingtext}{Toggle (On)}
\newcommand*{\toggleonsettingdesc}{a boolean option that is initially true}

\newcommand*{\toggleoffsettingsym}{\faToggleOff}
\newcommand*{\toggleoffsettingtext}{Toggle (Off)}
\newcommand*{\toggleoffsettingdesc}{a boolean option that is initially false}

\newcommand*{\optionvaluesym}{\faTag}
\newcommand*{\optionvaluetext}{Option Value Definition}
\newcommand*{\optionvaluedesc}{the definition of an option value}

\newcommand*{\countersym}{\textnumero}
\newcommand*{\countertext}{Counter}
\newcommand*{\counterdesc}{a counter is being described}

\definecolor{banned}{rgb}{0.8,0,0}

\newrobustcmd{\deprecatedorbannedfmt}[1]{\textcolor{banned}{#1}}

\newcommand*{\deprecatedsym}{\deprecatedorbannedfmt{\faTrashO}}
\newcommand*{\deprecatedtext}{Deprecated}
\newcommand*{\deprecateddesc}{a command, environment or option that
is now deprecated}

\newcommand*{\bannedsym}{\deprecatedorbannedfmt{\faBan}}
\newcommand*{\bannedtext}{Don't use}
\newcommand*{\banneddesc}{a command, environment or option that
should not be used with \thispackage}

\newcommand*{\terminalsym}{\faTerminal}
\newcommand*{\terminaltext}{Terminal}
\newcommand*{\terminaldesc}{a command-line application invocation
that needs to be entered into a
\href{https://www.dickimaw-books.com/latex/novices/html/terminal.html}{terminal
or command prompt}}

\newcommand*{\codesym}{\faFileTextO}
\newcommand*{\codetext}{Input}
\newcommand*{\codedesc}{\LaTeX\ code to insert into your document}

\newrobustcmd*{\badcodesym}{\faFileTextO\llap{\deprecatedorbannedfmt{\scriptsize\faBan}}}
\newcommand*{\badcodetext}{Problematic Input}
\newcommand*{\badcodedesc}{problematic code which should be avoided}

\newrobustcmd*{\unicodesym}{\faFileO\llap{\textsl{\tiny Uni}}}
\newcommand*{\unicodetext}{Unicode Input}
\newcommand*{\unicodedesc}{code that requires a native Unicode
engine (\XeLaTeX\ or \LuaLaTeX)}

\newcommand*{\resultsym}{\faFilePdfO}
\newcommand*{\resulttext}{Result}
\newcommand*{\resultdesc}{how the example code should appear in the PDF}

\newcommand*{\transcriptsym}{\twemoji{1f50e}}
\newcommand*{\transcripttext}{Transcript}
\newcommand*{\transcriptdesc}{Text in a transcript or log file or written to STDOUT or STDERR}

\newcommand*{\symbolentry}[1]{%
  @icon{sym.#1,name={\expandafter\expandonce\csname #1text\endcsname},^^J
    symbol={\expandafter\noexpand\csname #1sym\endcsname},^^J
    description={\expandafter\expandonce\csname #1desc\endcsname}^^J
  }^^J
}

\newcommand*{\symboldefinitions}{%
  \symbolentry{warning}
  \symbolentry{important}
  \symbolentry{information}
  \symbolentry{definition}
  \symbolentry{optionvalue}
  \symbolentry{valuesetting}
  \symbolentry{novaluesetting}
  \symbolentry{toggleonsetting}
  \symbolentry{toggleoffsetting}
  \symbolentry{counter}
  \symbolentry{deprecated}
  \symbolentry{banned}
  \symbolentry{terminal}
  \symbolentry{transcript}
  \symbolentry{code}
  \symbolentry{badcode}
  \symbolentry{unicode}
  \symbolentry{result}
}

\newlength\boxtitleshift
\setlength{\boxtitleshift}{-2.5mm}

\newcounter{icon}
\newcommand*{\icon}[1]{\stepcounter{icon}\glssymbol[counter=icon]{sym.#1}}
\newcommand*{\icontext}[1]{\stepcounter{icon}\glstext[counter=icon]{sym.#1}}

\newtcolorbox{warning}[1][]{breakable,
 before upper={\parindent12pt\noindent},
 title={\icon{warning}},
 coltitle=red,colbacktitle=red!20!white,
 colframe=red,colback=red!5!white,
 enhanced,attach boxed title to top right={yshift=\boxtitleshift},#1}

\newtcolorbox{important}[1][]{breakable,title={\icon{important}},
 before upper={\parindent12pt\noindent},
 coltitle=red,colbacktitle=red!20!white,
 colframe=red,colback=red!5!white,
 enhanced,attach boxed title to top right={yshift=\boxtitleshift},#1}

\newtcolorbox{information}[1][]{breakable,title={\icon{information}},
 before upper={\parindent12pt\noindent},
 coltitle=teal,colbacktitle=teal!20!white,
 colframe=teal,colback=teal!5!white,
 enhanced,attach boxed title to top right={yshift=\boxtitleshift},#1}

\definecolor{defbackground}{rgb}{1,1,0.75}
\definecolor{optiondefbackground}{rgb}{1,1,0.89}
\definecolor{optionvaluedefbackground}{rgb}{1,1,0.96}

\newcommand{\nlctdefaultafter}{\par\noindent\ignorespacesafterend}

\newcommand{\nlctpinnedafter}{\nlctdefaultafter} % v1.11
\newcommand{\nlctpinnedbefore}{\allowbreak\par\noindent} % v1.11

\newtcolorbox{pinnedbox}[1][]{unbreakable,title={\icon{definition}},
 coltitle=black,colbacktitle=defbackground,
 colframe=black,colback=defbackground,halign=flush left,
 enhanced,attach boxed title to top right={yshift=\boxtitleshift},
 after={\nlctpinnedafter},before={\nlctpinnedbefore},
 #1
}

\newcommand{\nlctdefnafter}{\nopagebreak\nlctdefaultafter} % v1.11
\newcommand{\nlctdefnbefore}{\allowbreak\par\noindent} % v1.11

\newtcolorbox{defnbox}[1][]{unbreakable,
 colframe=black,colback=defbackground,halign=flush left,
 after={\nlctdefnafter},before={\nlctdefnbefore},
 #1
}

\newcommand{\nlctsettingsafter}{\nopagebreak\nlctdefaultafter} % v1.11
\newcommand{\nlctsettingsbefore}{\allowbreak\par\noindent} % v1.11

\newtcolorbox{settingsbox}[1][]{title={\icon{valuesetting}},unbreakable,
 coltitle=black,colbacktitle=defbackground!20!white,
 colframe=black,colback=defbackground!20!white,halign=flush left,
 enhanced,attach boxed title to top right={yshift=\boxtitleshift},
 after={\nlctsettingsafter}, before={\nlctsettingsbefore},
 #1
}

\newtcolorbox{terminal}{unbreakable,title={\icon{terminal}},
 colframe=black,
 enhanced,attach boxed title to top right={yshift=\boxtitleshift},
 after={\nlctdefaultafter},
 halign=flush left,fontupper=\ttfamily,before upper={\frenchspacing\obeylines}
}

\newtcolorbox{transcript}{unbreakable,title={\icon{transcript}},
 colframe=black,
 enhanced,attach boxed title to top right={yshift=\boxtitleshift},
 after={\nlctdefaultafter},
 halign=flush left,fontupper=\ttfamily,before upper={\frenchspacing\obeylines}
}

\newcommand{\code@cmd}[1]{\char`\\ #1}
\newcommand{\cmd}[1]{\texttt{\code@cmd{#1}}}
\newcommand{\code@cbeg}[1]{\cmd{begin}\marg{#1}}
\newcommand{\code@cend}[1]{\cmd{end}\marg{#1}}
{\obeylines\newcommand{\code@comment}[1]{%
 \mbox{\textcolor{comment}{\glspercentchar\ #1}}\@ifnextchar
{}{\par}}\global\let\code@comment\code@comment\newcommand{\code@comment@dbsp}[1]{%
 \mbox{\textcolor{comment}{\glspercentchar\ #1}}\@ifnextchar
{}{\par}\dbspace}\global\let\code@comment@dbsp\code@comment@dbsp}
\newcommand{\araraline}[1]{\glspercentchar\ arara: #1}
\newcommand{\araracont}{\araraline{-\/-> }}

\newcommand{\commentnl}[1]{\comment{#1}\nl}

\newcommand*{\setupcodeenvfmts}{%
 \let\cbeg\code@cbeg
 \let\cend\code@cend
 \let\comment\code@comment
 \let\commentdbsp\code@comment@dbsp
 \def\nl{\mbox{}\newline}%
 \def\nlsp{\nl\null\space}%
 \def\dbspace{\mbox{}\space\space}%
 \def\dbdbspace{\dbspace\dbspace}%
 \def\dbdbdbspace{\dbspace\dbspace\dbspace}%
 \def\nldbsp{\nl\null\dbspace}%
 \def\nldbdbsp{\nl\null\dbdbspace}%
 \def\nldbdbdbsp{\nl\null\dbdbdbspace}%
 \renewcommand*{\envfmt}[1]{##1}%
 \renewcommand*{\styfmt}[1]{##1}%
 \renewcommand*{\clsfmt}[1]{##1}%
 \renewcommand*{\ctrfmt}[1]{##1}%
 \renewcommand*{\csfmtfont}[1]{\textcolor{cs}{##1}}%
 \let\fmtorcode\@secondoftwo
 \let\code\@firstofone
}

\newcommand*{\initcodeenv}{%
 \GlsXtrStartUnsetBuffering
 \setupcodeenvfmts
 \obeylines\frenchspacing\@vobeyspaces
 \parindent\z@\parfillskip\@flushglue
}

\newcommand{\codefont}{\ttfamily}

% inline
\newcommand{\code}[1]{\texorpdfstring{\@code{#1}}{#1}}
\newrobustcmd{\@code}[1]{{\setupcodeenvfmts\codefont\obeyspaces #1}}
\newcommand{\smcode}[1]{\@code{\small #1}}

\definecolor{codebackground}{gray}{0.95}

\newtcolorbox{codebox}[1][]{title={\icon{code}},
 enhanced,breakable,attach boxed title to top right={yshift=\boxtitleshift},
 halign=flush left,fontupper=\codefont,colback=codebackground,
  before upper={%
  \preto\glslinkpresetkeys{\setkeys{glslink}{format=glsignore}}%
  \initcodeenv
  },
  after upper={\GlsXtrDiscardUnsetBuffering},
  after={\nlctdefaultafter},
  #1
}

\newtcolorbox{codebox*}[1][]{title={\icon{code}},
 enhanced,breakable,
 attach boxed title to top right={yshift=\boxtitleshift},
 halign=flush left,fontupper=\codefont,colback=codebackground,
  before upper={\initcodeenv},
  after upper={\GlsXtrDiscardUnsetBuffering},
  after={\nlctdefaultafter},
  #1
}

\newenvironment{badcodebox}%
{\begin{codebox}[title={\icon{badcode}}]}
{\end{codebox}\noindent\ignorespacesafterend}

\newenvironment{unicodebox}%
{\begin{codebox}[title={\icon{unicode}}]}
{\end{codebox}\noindent\ignorespacesafterend}

\newtcolorbox{compactcodebox}[1][]{%
  halign=flush left,fontupper=\codefont,colback=codebackground,
  before upper={%
  \renewcommand{\glslinkpresetkeys}{\setkeys{glslink}{format=glsignore}}%
  \initcodeenv},
  after upper={\GlsXtrDiscardUnsetBuffering},
  after={\nlctdefaultafter},
  #1
}

\newtcolorbox{compactcodebox*}[1][]{%
  halign=flush left,fontupper=\codefont,colback=codebackground,
  before upper={\initcodeenv},
  after upper={\GlsXtrDiscardUnsetBuffering},
  after={\nlctdefaultafter},
  #1
}

\newcommand*{\result@attachtag}{}

\newtcolorbox{resultbox}[1][]{title={\icon{result}},
 coltitle=black,colbacktitle=white,
 colframe=black,colback=white,
 after={\nlctdefaultafter},
 enhanced,breakable,attach boxed title to top right={yshift=\boxtitleshift},#1}

\newtcolorbox{coderesult}[1][]{skin=bicolor,
title={\icon{code} \icon{result}},
attach boxed title to top center={yshift=\boxtitleshift},
sidebyside,
sidebyside align=top,
colbacklower=white,
fontupper=\codefont,
before upper={%
\renewcommand{\glslinkpresetkeys}{\setkeys{glslink}{format=glsignore}}%
  \initcodeenv},
after upper={\GlsXtrDiscardUnsetBuffering},
halign upper=flush left,halign lower=justify,
valign upper=top,valign lower=top,
before lower={\let\nlct@ex@title@attachments\nlct@ex@narrow@title@attachments},
after lower={\noindent},
#1
}

\newtcolorbox{coderesult*}[1][]{skin=bicolor,
title={\icon{code} \icon{result}},
attach boxed title to top center={yshift=\boxtitleshift},
sidebyside,
sidebyside align=top,
colbacklower=white,
fontupper=\codefont,
before upper={\initcodeenv},
after upper={\GlsXtrDiscardUnsetBuffering},
after lower={\noindent},
valign upper=top,valign lower=top,
halign upper=flush left,halign lower=justify,
#1
}

\newenvironment{unicoderesult}%
{\begin{coderesult}[title={\icon{unicode} \icon{result}}]}
{\end{coderesult}\noindent\ignorespacesafterend}

\newenvironment{unicoderesult*}%
{\begin{coderesult*}[title={\icon{unicode} \icon{result}}]}
{\end{coderesult*}\noindent\ignorespacesafterend}


\newcommand*{\summarylocfont}{\footnotesize}
\newcommand*{\summarylocinnersep}{.3333em}
\newcommand*{\summarylocwidth}{\marginparwidth-.6666em}

\definecolor{summaryloc}{rgb}{.75,.936,1} % LightBlue1

\newcommand*{\summarylocbox}[1]{%
 \ifdefempty\summarylocwidth
 {%
   \tikz[baseline=(N.base)] 
    \node[fill=summaryloc,rounded corners,font=\summarylocfont] (N) {#1};%
 }%
 {%
   \smash
   {%
     \tikz[baseline=(N.west)] 
      \node[anchor=west,
        outer sep=0pt,
        inner sep=\summarylocinnersep,
        fill=summaryloc,
        text width=\summarylocwidth,
        align=flush left,
        rounded corners,font=\summarylocfont
      ] (N) {#1};%
   }%
 }%
}

\ifdef\@ptsize
{
  \ifboolexpr{ test {\ifdefstring\@ptsize{1}} 
            or test {\ifdefstring\@ptsize{11}} 
            or test {\ifdefstring\@ptsize{11pt}} 
             }
  {%
    \newcommand{\@nlct@example@fontsize}{11pt}%
  }
  {
     \ifboolexpr{ test {\ifdefstring\@ptsize{2}} or test {\ifdefstring\@ptsize{12}} }
     {%
       \newcommand{\@nlct@example@fontsize}{12pt}%
     }
     {
       \newcommand{\@nlct@example@fontsize}{10pt}
     }
   }
}
{
  \newcommand{\@nlct@example@fontsize}{10pt}
}

\newcommand{\@nlct@example@clsname}{article}

\newcommand{\@nlct@example@fontsize@prefix}{}

\newcommand{\@nlct@update@example@fontsize@prefix}{%
  \ifdefstring{\@nlct@example@clsname}{scrreport}
  {\renewcommand{\@nlct@example@fontsize@prefix}{fontsize=}}%
  {%
    \ifdefstring{\@nlct@example@clsname}{scrbook}
    {\renewcommand{\@nlct@example@fontsize@prefix}{fontsize=}}%
    {%
      \ifdefstring{\@nlct@example@clsname}{scrarticle}
      {\renewcommand{\@nlct@example@fontsize@prefix}{fontsize=}}%
      {%
        \renewcommand{\@nlct@example@fontsize@prefix}{}
      }%
    }%
  }%
}

\newcommand{\setexamplefontsize}[1]{%
  \renewcommand{\@nlct@example@fontsize}{#1pt}%
  \ifnum#1>12\relax
    \renewcommand{\@nlct@example@clsname}{extarticle}%
  \else
    \ifnum#1<10\relax
      \renewcommand{\@nlct@example@clsname}{extarticle}%
    \else
      \renewcommand{\@nlct@example@clsname}{article}%
    \fi
  \fi
}

\newcommand*{\nlct@create@example@preamble}{%
 \string\documentclass[\@nlct@example@fontsize@prefix\@nlct@example@fontsize]{\@nlct@example@clsname}^^J%
 \string\pagestyle{\@nlct@example@pagestyle}^^J}
\newcommand*{\setexamplepreamble}[1]{\edef\create@example@preamble{\detokenize{#1}^^J}}
\newcommand*{\addtoexamplepreamble}[1]{\eappto\create@example@preamble{\detokenize{#1}^^J}}

\newwrite\nlct@exampleout

\define@choicekey{nlctexample}{fontsize}%
 {8,9,10,11,12,14,17,20}%
 {\setexamplefontsize{#1}}

\define@key{nlctexample}{class}{\renewcommand{\@nlct@example@clsname}{#1}}

\newcommand{\@nlct@example@pagestyle}{empty}
\define@key{nlctexample}{pagestyle}{\renewcommand{\@nlct@example@pagestyle}{#1}}

\define@key{nlctexample}{graphicsopts}{%
 \renewcommand*{\create@example@graphicsopts}{#1}}
\newcommand*{\create@example@graphicsopts}{}

\define@key{nlctexample}{pages}{%
 \renewcommand*{\create@example@pages}{#1}}
\newcommand*{\create@example@pages}{}

\define@key{nlctexample}{pagesep}{%
 \renewcommand*{\create@example@pages@sep}{#1}}
\newcommand{\create@example@pages@sep}{1em}

\define@key{nlctexample}{pagesperrow}{%
 \renewcommand*{\create@example@pages@perrow}{#1}}
\newcommand{\create@example@pages@perrow}{\@nlct@num}

\define@key{nlctexample}{tex}{\renewcommand*{\create@example@tex}{#1}}
\newcommand*{\create@example@tex}{arara --working-directory \examplesdir}

\newcommand*{\nlct@create@example@precls}{%
 \glspercentchar\space arara\string: pdflatex^^J%
 \glspercentchar\space arara\string: pdfcrop^^J%
}

\define@key{nlctexample}{arara}{%
 \ifdefstring{\examplesdir}{.}%
 {\renewcommand*{\create@example@tex}{arara}}%
 {\renewcommand*{\create@example@tex}{arara --working-directory \examplesdir}}%
 \renewcommand*{\nlct@create@example@precls}{}%
 \@for\nlct@thisitem:=#1\do{%
  \eappto\nlct@create@example@precls{\glspercentchar\space arara\string:
     \expandafter\detokenize\expandafter{\nlct@thisitem}^^J}%
 }%
}

\providecommand{\examplename}{Example}
\let\Examplename\examplename

\newcommand*{\example@attachdesc}{\Examplename\space \theexample}

\define@key{nlctexample}{description}{%
 \renewcommand*{\example@attachdesc}{#1}%
}

\newcommand*{\example@title}{}

\define@key{nlctexample}{title}{%
 \renewcommand*{\example@title}{#1}%
}

\newcommand{\nlctpostexampletitle}{\par}

\define@choicekey{nlctexample}{titleskip}%
 [\nlct@titleskip@val\nlct@titleskip@nr]%
 {none,thin,small,medium}%
 {%
   \ifcase\nlct@titleskip@nr\relax
    \renewcommand{\nlctpostexampletitle}{\endgraf}%
   \or
    \renewcommand{\nlctpostexampletitle}{\vspace{1pt plus 1pt}\endgraf}%
   \or
    \renewcommand{\nlctpostexampletitle}{\smallskip\endgraf}%
   \or
    \renewcommand{\nlctpostexampletitle}{\medskip\endgraf}%
   \fi
 }

\newcommand{\example@do@label}{%
 \ifdefempty\nlct@example@label
 {}%
 {%
  \ifdefempty\example@title{}%
   {\protected@edef\@currentlabelname{\example@title}}%
  \label{\nlct@example@label}%
  \example@do@extag
 }%
}
\newcommand{\example@label@info}{}
\newcommand{\nlct@example@label}{}

\define@key{nlctexample}{label}{%
 \renewcommand{\example@label@info}{\glspercentchar\space Label: "#1"^^J}%
 \renewcommand*{\nlct@example@label}{#1}%
}

\define@boolkey{nlctexample}[nlct@exampleimg@]{border}[true]{}% v1.16+
\nlct@exampleimg@borderfalse

\newcommand{\nlct@exampleimgencap}[1]{%
 \ifnlct@exampleimg@border
  {\setbox \@tempboxa \hbox {#1}%
   \fboxsep\z@\@frameb@x\relax}%
 \else
   \hbox{#1}%
 \fi
}

\define@boolkey{nlctexample}[nlct@exampleimg@]{solofirst}[true]{}% v1.16+
\nlct@exampleimg@solofirstfalse

\newcommand{\create@example@totalwidth}{\linewidth}

\define@key{nlctexample}{totalwidth}{% v1.16+
 \renewcommand*{\create@example@totalwidth}{#1}%
}

% v1.11+
\newcommand{\example@do@extag}{}

\newcommand{\nlctextag}[1]{%
 \protected@write\@auxout{}{\string\nlctdoc@extag{#1}{\nlct@example@label}}%
}

\ExplSyntaxOn
\newcommand{\nlctdoc@extag}[2]{
 \clist_map_inline:nn { #1 }
  {
    \seq_if_exist:cF { g__nlctdoc_example_tag_ ##1 _seq }
     {
       \seq_new:c { g__nlctdoc_example_tag_ ##1 _seq }
     }
   \seq_gput_right:cn { g__nlctdoc_example_tag_ ##1 _seq } { #2 }
 }
}

\int_new:N \l_nlctdoc_extag_item_threshold_int
\int_set:Nn \l_nlctdoc_extag_item_threshold_int { 4 }

% Syntax: \exampletagref{tag}{trailing punctuation}
\NewDocumentCommand \exampletagref { m m }
{
  \seq_if_exist:cTF { g__nlctdoc_example_tag_ #1 _seq }
   {
     \seq_if_empty:cTF { g__nlctdoc_example_tag_ #1 _seq }
      {
        ??\PackageWarning { nlctuserguide }
        { No ~ labels ~ found ~ for ~ tag ~ `#1' }
      }
      {
        \exp_args:Ncx
         \__nlctdoc_examplerefs:Nnn
          { g__nlctdoc_example_tag_ #1 _seq }
          { \seq_count:c { g__nlctdoc_example_tag_ #1 _seq } }
          { #2 }
      }
   }
   {
     ??\PackageWarning { nlctuserguide }
     { No ~ reference ~ found ~ for ~ tag ~ `#1' }
   }
}
\cs_new:Nn \__nlctdoc_examplerefs:Nnn
{
  \int_compare:nNnTF { #2 } = { \c_one_int }
   {
     \exp_args:Nx \examplenameref { \seq_item:Nn #1 { \c_one_int } } #3
   }
   {
     \int_compare:nNnTF
      { #2 } < { \l_nlctdoc_extag_item_threshold_int }
     {
       \exp_args:Nx \examplesnameref { \seq_use:Nn #1 { , } } #3
     }
     {
        \exampletagrefprelist
        \begin{itemize}
          \seq_map_indexed_inline:Nn #1
          {
            \item \ref{ ##2 }
              \exampletagreflistpretitle
              \nameref{ ##2 }
            \int_compare:nNnTF
              { ##1 } = { #2 }
            { #3 } { \exampletagreflistsep }
          }
        \end{itemize}
     }
   }
}
\ExplSyntaxOff
\newcommand{\exampletagreflistsep}{;}
\newcommand{\exampletagreflistpretitle}{. }
\newcommand{\exampletagrefprelist}{the following examples:}

\define@key{nlctexample}{tag}{%
  \renewcommand{\example@do@extag}{\nlctextag{#1}}%
}

\newcommand{\nlct@exbacklink}{}
\define@key{nlctexample}{link}{%
 \renewcommand{\nlct@exbacklink}{#1}%
}

\newcounter{example}

\newcommand{\exampleattachtexicon}{\faPaperclip\textsuperscript\faFileTextO}
\newcommand{\exampleattachpdficon}{\faPaperclip\textsuperscript\faFilePdfO}
\newcommand{\exampledownloadtexicon}{\faDownload\textsuperscript\faFileTextO}
\newcommand{\exampledownloadpdficon}{\faDownload\textsuperscript\faFilePdfO}

\newcommand{\codepar}{\par\mbox{}\par}

\newcommand{\glscmd}[1]{\glsentrytext{#1}}

\newcommand{\nlctexamplelets}{%
 \let\gls\glsentrytext
 \let\glssymbol\glsentrysymbol
 \let\glscmd\glsentrytext
 \let\env\@firstofone
 \let\ctr\@firstofone
 \let\texorpdfstring\@secondoftwo
 \let\glsxtrtitleorpdforheading\@thirdofthree
 \def\starredcs##1{\glsentrytext{##1}*}%
 \def\cmd##1{\glsbackslash##1}%
 \def\csfmt##1{\glsbackslash##1}%
 \def\cbeg##1{\glsbackslash begin{##1}}%
 \def\cend##1{\glsbackslash end{##1}}%
 \def\comment##1{\glspercentchar\space ##1^^J}%
 \def\commentnl##1{\glspercentchar\space ##1^^J}%
 \def\commentdbsp##1{\glspercentchar\space ##1^^J\dbspace}%
 \def\%{\glspercentchar}%
 \edef\#{\expandafter\@gobble\string\#}%
% v1.10:
 \edef\${\expandafter\@gobble\string\$}%
 \edef\_{\expandafter\@gobble\string\_}%
 \def\-{}%
 \def\codepar{^^J^^J}%
 \def\marg##1{\glsopenbrace##1\glsclosebrace}%
 \def\oarg##1{[##1]}%
% v1.11:
 \def\nl{^^J}%
 \def\nlsp{^^J\space}%
 \def\dbspace{\space\space}%
 \def\dbdbspace{\dbspace\dbspace}%
 \def\dbdbdbspace{\dbspace\dbspace\dbspace}%
 \def\nldbsp{^^J\dbspace}%
 \def\nldbdbsp{^^J\dbdbspace}%
 \def\nldbdbdbsp{^^J\dbdbdbspace}%
 \let\tabsym\nlctliteraltabchar
 \let\visiblespace\space
}

\newcommand{\@create@example@write}{\@create@example@write@detok}

\newcommand{\createexamplefirstline}{%
  \nlct@ifattachsupported
  {\glspercentchar\space This file is embedded in \jobname.pdf \nlct@v@version^^J}%
  {\glspercentchar\space This file is an example from \jobname.pdf \nlct@v@version^^J}%
}

\newcommand{\@create@example@write@detok}[2]{%
  \immediate\write\nlct@exampleout{%
    \createexamplefirstline
    \glspercentchar\space \Examplename\space \theexample\space\example@title^^J%
    \example@label@info
    \nlct@create@example@precls
    \nlct@create@example@preamble
    \detokenize{#1}^^J\string\begin{document}^^J\detokenize{#2}^^J%
    \string\end{document}}%
}

\newcommand{\@create@example@write@nodetok}[2]{%
 {\nlctexamplelets\immediate\write\nlct@exampleout{%
    \createexamplefirstline
    \glspercentchar\space \Examplename\space \theexample\space\example@title^^J%
    \example@label@info
    \nlct@create@example@precls\nlct@create@example@preamble
    #1^^J\string\begin{document}^^J#2^^J%
    \string\end{document}}%
 }%
}

\newcommand{\example@image}[2][]{%
  \settowidth{\dimen@}{\expandafter\includegraphics\expandafter
    [\create@example@graphicsopts,#1]{#2}}%
  \ifdim\dimen@>\linewidth\preto\create@example@graphicsopts{width=\linewidth,}\fi
  \s@example@image[#1]{#2}%
}

\newcommand{\s@example@image}[2][]{%
  \vtop
  {%
   \vskip0pt
   \nlct@exampleimgencap{\expandafter\includegraphics\expandafter
    [\create@example@graphicsopts,#1]{#2}}%
  }%
}

\newcommand{\nlctexampleimagelist}{%
 \examplesdir/\nlct@example@filebasename-crop.pdf,%
 \examplesdir/\nlct@example@filebasename.pdf%
}

\newcommand{\exampleimagerow}[1]{%
 \par\noindent\makebox[\linewidth][c]{#1}\par
}

\ExplSyntaxOn
\tl_new:N \l__nlctdoc_imagerow_tl
\tl_new:N \l__nlctdoc_imagewarning_tl
\int_new:N \l__nlctdoc_page_int
\dim_new:N \l__nlctdoc_imagewidth_dim
\seq_new:N \l__nlctdoc_page_seq

\newcommand{\nlct@include@exampleimage}{% v1.16 rewritten
  \tl_set:Nn \l__nlctdoc_imagewarning_tl
    {
      \PackageWarning{nlctuserguide}%
        {Missing ~ example ~ file ~ `\nlct@example@filebasename.pdf'}
        [missing ~ \nlct@example@filebasename.pdf]
    }
  \clist_map_function:NN
    \nlctexampleimagelist 
    \__nlctdoc_include_example_image:n
  \l__nlctdoc_imagewarning_tl
}

\cs_new:Nn \__nlctdoc_include_example_image:n
 {
   \IfFileExists { #1 }
   {
     \tl_if_empty:NTF \create@example@pages
      {
        \example@image { #1 }
      }
      {
        \seq_set_from_clist:NN \l__nlctdoc_page_seq \create@example@pages
        \edef \@nlct@num { \seq_count:N \l__nlctdoc_page_seq }
        \tl_if_empty:NT \create@example@graphicsopts
         {
           \dim_set:Nn \l__nlctdoc_imagewidth_dim
            {
               \create@example@totalwidth
               -\create@example@pages@sep
                   * ( \create@example@pages@perrow - \c_one_int )
            }
           \legacy_if:nT { nlct@exampleimg@border }
            {
              \dim_sub:Nn \l__nlctdoc_imagewidth_dim
               { 2 \fboxrule * \create@example@pages@perrow }
            }
           \dim_set:Nn \l__nlctdoc_imagewidth_dim
             { \l__nlctdoc_imagewidth_dim / \create@example@pages@perrow }
           \edef\create@example@graphicsopts{width=
             \dim_use:N \l__nlctdoc_imagewidth_dim }
         }
        \tl_clear:N \l__nlctdoc_imagerow_tl
        \int_zero:N \l__nlctdoc_page_int
        \def \nlct@image@file { #1 }
        \seq_map_indexed_function:NN
          \l__nlctdoc_page_seq
          \__nlctdoc_include_example_image_page:nn
        \tl_if_empty:NF \l__nlctdoc_imagerow_tl
         {
           \exp_args:NV \exampleimagerow \l__nlctdoc_imagerow_tl
         }
      }
     \tl_clear:N \l__nlctdoc_imagewarning_tl
     \clist_map_break:
   }
   { }
 }

\cs_new:Nn \__nlctdoc_include_example_image_page:nn
 {
   \int_if_zero:nF { \l__nlctdoc_page_int }
    {
      \tl_put_right:Nn \l__nlctdoc_imagerow_tl
       {
         \hspace { \create@example@pages@sep }
       }
    }
   \tl_put_right:Ne \l__nlctdoc_imagerow_tl
     {
       \exp_not:N \s@example@image [ page = #2 ] { \nlct@image@file }
     }
   \int_incr:N \l__nlctdoc_page_int
   \bool_lazy_and:nnT
     { \legacy_if_p:n { nlct@exampleimg@solofirst } }
     { \int_compare_p:nNn { #1 } = { \c_one_int } }
    {
      \int_set:Nn \l__nlctdoc_page_int { \create@example@pages@perrow }
    }
   \int_compare:nNnF
     { \l__nlctdoc_page_int } < { \create@example@pages@perrow }
    {
       \int_zero:N \l__nlctdoc_page_int
       \exp_args:NV \exampleimagerow \l__nlctdoc_imagerow_tl
       \tl_clear:N \l__nlctdoc_imagerow_tl
    }
 }

\ExplSyntaxOff

% \createexample[options]{preamble code}{document code}
\newcommand{\createexample}{%
 \@nlct@update@example@fontsize@prefix
 \@ifstar
 {\let\@create@example@write\@create@example@write@nodetok \@createexample}%
 {\let\@create@example@write\@create@example@write@detok \@createexample}}

\newcommand{\listofexamplesname}{List of Examples}
\newcommand{\listofexampleslabel}{\label{sec:listofexamples}}
% v1.11:
\newcommand{\listofexamplesheader}{%
\par
If an example shows the icon \exampleattachtexicon\ then the source
code is embedded in the PDF as an attachment. If your PDF viewer
supports attachments, you can extract the self-contained example
file to try it out for yourself. Alternatively, you can click on the
download icon \exampledownloadtexicon\ which will try downloading
the example source code from your closest CTAN mirror, but make sure
that this user manual matches the version on CTAN first. You can
also try using:
\texdocref{-l \jobname-example\meta{nnn}} 
where \meta{nnn} is the example number zero-padded to three digits
to find out if the example files are installed on your device.\par
\bigskip
}

\ifdef\chapter
{
  \ifdef\titlepagestyle{\renewcommand{\titlepagestyle}{empty}}{}
  \pagenumbering{alph}

  \newcommand{\listofexamples}{%
   \@ifstar{\chapter*{\listofexamplesname}\@starttoc{loe}}%
   {\chapter{\listofexamplesname}\listofexampleslabel\listofexamplesheader\@starttoc{loe}}}
}
{
  \newcommand{\listofexamples}{%
   \@ifstar{\section*{\listofexamplesname}\@starttoc{loe}}%
   {\section{\listofexamplesname}\listofexampleslabel\listofexamplesheader\@starttoc{loe}}}
}

\newcommand{\l@example}{\l@table}

\newcommand\nlctexamplefilebasename{%
 \jobname-example\ifnum\c@example<10 00\else \ifnum\c@example<100 0\fi\fi\the\c@example}%

\newcommand{\nlctexampledisablecmds}{}

\newcommand{\nlctexampletag}{\Examplename~\theexample}

\newcommand{\nlctbacklink}[1]{%
 \ifdefempty\nlct@exbacklink
 {%
   \ifdefempty\nlct@example@label{}%
   {%
    \ifcsdef{r@\nlct@example@label-backref}%
    {\hyperref[\nlct@example@label-backref]{\upsym}}%
    {}%
   }%
 }%
 {\hyperref[\nlct@exbacklink]{\upsym}}%
 #1%
}

\NewDocumentCommand\nlctexampletitlefmt{m}{%
  \nlctexampletitlefont
  \raggedright\exhyphenpenalty 0 % space intended
  \nlctbacklink{\nlctexampletag}\ifstrempty{#1}{}{: #1}\par
}

\newcommand{\nlct@ex@notboxed@title@attachments}[2]{% v1.16
  \nlctexampletitlefmt{#1}\hfill\mbox{#2}%
}

\newcommand{\nlct@ex@title@attachments}[2]{%
   \nlctexampletitlebox{#1}\hfill#2%
}

\newcommand{\nlct@ex@narrow@title@attachments}[2]{%
  \nlctexampletitlefmt{#1}\hfill#2%
}

\NewDocumentCommand\nlctexampletitlebox{m}{% v1.16 removed optional argument
 \parbox[t]{0.8\linewidth}{\nlctexampletitlefmt{#1}}%
}

\newcommand{\nlctexampletagattachfont}{\small}
\newcommand{\nlctexampletitlefont}{\nlctexampletagattachfont}
\newcommand{\nlctexampleenvtitlefont}{\bfseries\large}

\newcommand{\addtolistofexamples}[1]{%
 \addcontentsline{loe}{example}{\protect\numberline{\theexample}#1}%
}

\newif\ifnlctattachpdf
\nlctattachpdffalse

\newif\ifnlctdownloadlinks
\nlctdownloadlinkstrue
\newcommand*{\nlctdownloadlink}[1]{http://mirrors.ctan.org/macros/latex/contrib/\thispackagename/#1}

\newcommand{\@loe@disable@cmds}{%
  \def\dequals{\protect\dequals}%
  \def\dhyphen{\protect\dhyphen}%
  \def\dslash{\protect\dslash}%
  \def\dunderscore{\protect\dunderscore}%
  \def\cmd##1{\protect\csfmt{##1}}%
  \def\code##1{\protect\code{##1}}%
  \def\optfmt##1{\protect\optfmt{##1}}%
  \def\styfmt##1{\protect\styfmt{##1}}%
  \def\clsfmt##1{\protect\clsfmt{##1}}%
  \def\envfmt##1{\protect\envfmt{##1}}%
  \def\appfmt##1{\protect\appfmt{##1}}%
}

\ExplSyntaxOn
\newcommand{\example@filesize}[1]{
 \file_size:n { \examplesdir / \nlct@example@filebasename #1 }
}
\newcommand{\example@filetimestamp}[1]{
 \file_timestamp:n { \examplesdir / \nlct@example@filebasename #1 }
}
\newcommand\nlct@run[1]{ 
  \sys_if_shell_unrestricted:TF
   { \sys_shell_now:e { #1 } }
   {
     \PackageInfo { nlctuserguide }
     {
       Not ~ running ~ ` #1 ' \MessageBreak
       Unrestricted ~ shell ~ not ~ enabled. ~ 
       Execute ~ outside ~ of ~ TeX ~ and ~ rerun
     }
   }
}
\ExplSyntaxOff

\newcommand\@createexample@disablecmds{%
  \def\cmd##1{\string\\##1}%
  \let\glscmd\cmd
  \let\code\@firstofone
  \let\optfmt\@firstofone
  \let\styfmt\@firstofone
  \let\clsfmt\@firstofone
  \let\envfmt\@firstofone
  \let\appfmt\@firstofone
  \let\opt\@firstofone
  \let\app\@firstofone
  \let\sty\@firstofone
  \let\cls\@firstofone
  \let\glslink\@secondoftwo
  \let\texorpdfstring\@secondoftwo
  \let\codebackslash\glsbackslash
  \let\-\@empty
  \def\TeX{TeX}%
  \def\LaTeX{LaTeX}%
  \def\dequals{=}%
  \def\dhyphen{-}%
  \def\dslash{/}%
  \def\dunderscore{\_}%
  \def\newline{^^J}%
  \nlctexampledisablecmds
}

\newcommand{\@createexample}[3][]{%
 \begin{minipage}[t]{\linewidth}%
  \raggedright
  \refstepcounter{example}%
  \setkeys{nlctexample}{#1}%
  \example@do@label
  \let\nlct@org@cmd\cmd
  \def\cmd##1{\csfmt{##1}}%
  \def\glscmd##1{\noexpand\glsfmttext{##1}}%
  \protected@edef\example@tex@title{\example@title}%
  \@loe@disable@cmds
  \addtolistofexamples{\example@title}%
  \@createexample@disablecmds
  \protected@edef\example@pdf@title{\example@title}%
  \protected@edef\example@attachdesc{\example@attachdesc}%
  \def\cmd##1{\glsbackslash ##1}%
  \protected@edef\example@title{\example@title}%
  \let\cmd\nlct@org@cmd
  \xdef\nlct@example@filebasename{\nlctexamplefilebasename}%
  \immediate\openout\nlct@exampleout=\examplesdir/\nlct@example@filebasename.tex
  \@create@example@write{#2}{#3}%
  \immediate\closeout\nlct@exampleout
  \nlct@run{\create@example@tex\space\nlct@example@filebasename.tex}%
  \nlct@ifattachsupported
  {%
    \bgroup
    \nlct@ex@title@attachments
    {\example@tex@title}%
    {%
      \nlctexampletagattachfont
      \textattachfile[mimetype={application/x-tex},
        author={\@pdfauthor},color={0 0 0},
        size={\example@filesize{.tex}},
        created={\example@filetimestamp{.tex}},
        modified={\example@filetimestamp{.tex}},
        subject={\example@pdf@title\space (source code)},
        description={\example@attachdesc\space (source code)}]%
        {\examplesdir/\nlct@example@filebasename.tex}{\exampleattachtexicon}%
      \ifnlctdownloadlinks
       \space
       \href{\nlctdownloadlink{\examplesdir/\nlct@example@filebasename.tex}}{\exampledownloadtexicon}
      \fi
      \ifnlctattachpdf
        \IfFileExists{\examplesdir/\nlct@example@filebasename.pdf}
        {%
           \space
           \textattachfile[mimetype={application/pdf},
            author={\@pdfauthor},color={0 0 0},
            size={\example@filesize{.pdf}},
            created={\example@filetimestamp{.pdf}},
            modified={\example@filetimestamp{.pdf}},
            subject={\example@pdf@title\space (PDF)},
            description={\example@attachdesc\space (PDF)}]%
           {\examplesdir/\nlct@example@filebasename.pdf}{\exampleattachpdficon}%
        }%
        {}%
        \ifnlctdownloadlinks
         \space
         \href{\nlctdownloadlink{\examplesdir/\nlct@example@filebasename.pdf}}{\exampledownloadpdficon}
        \fi
      \else
        \ifnlctdownloadlinks
         \space
         \href{\nlctdownloadlink{\examplesdir/\nlct@example@filebasename.pdf}}{\exampledownloadpdficon}
        \fi
      \fi
    }%
    \nlctpostexampletitle
    \egroup\noindent
  }%
  {%
    \nlctexampletitlebox{\example@tex@title}\hfill
   \ifnlctdownloadlinks
    \href{\nlctdownloadlink{\examplesdir/\nlct@example@filebasename.tex}}{\exampledownloadtexicon}
    \quad
    \href{\nlctdownloadlink{\examplesdir/\nlct@example@filebasename.pdf}}{\exampledownloadpdficon}
    \nlctpostexampletitle
    \egroup\noindent
   \fi
  }
  \nlct@include@exampleimage
  \par
  \end{minipage}%
}

\newenvironment{example}[2]{%
  \par\vskip10pt\noindent
  \refstepcounter{example}\label{#2}%
  {%
    \def\cmd##1{\csfmt{##1}}%
    \let\nlctexampletitlefont\nlctexampleenvtitlefont
    \nlctexampletitlefmt{#1}%
  }%
  {%
    \@loe@disable@cmds
    \addtolistofexamples{#1}%
  }%
  \nopagebreak\par\vskip10pt\nopagebreak
}
{%
  \nopagebreak\begin{center}\rule{2in}{1pt}\end{center}%
}

\ExplSyntaxOn
% place example in flowfram.sty static frame:
\tl_new:N \l__nlctdoc_contents_tl
\NewDocumentCommand \createresultexampleindynamicframe { s o m m m }
{
  \group_begin:
   \__nlctdoc_create_result_conts:nnn { #2 } { #4 } { #5 }
   \IfBooleanTF { #1 }
    {
      \exp_args:NNnV
      \setdynamiccontents * { #3 } \l__nlctdoc_contents_tl
    }
    {
      \exp_args:NnV
      \setdynamiccontents { #3 } \l__nlctdoc_contents_tl
    }
  \group_end:
}

\cs_new:Nn \__nlctdoc_create_result_conts:nnn
 {
  \@nlct@update@example@fontsize@prefix
  \IfValueT { #1 }
   {
     \setkeys { nlctexample } { #1 }
   }
  \tl_set:Nn \l__nlctdoc_contents_tl
    {
      \icon{result} \quad 
      \refstepcounter { example }
    }
  \legacy_if:nTF { nlct@exampleimg@border }
   {
     \tl_put_right:Nn \l__nlctdoc_contents_tl
      {
        \nlct@exampleimg@bordertrue
      }
   }
   {
     \tl_put_right:Nn \l__nlctdoc_contents_tl
      {
        \nlct@exampleimg@borderfalse
      }
   }
  \legacy_if:nTF { nlct@exampleimg@solofirst }
   {
     \tl_put_right:Nn \l__nlctdoc_contents_tl
      {
        \nlct@exampleimg@solofirsttrue
      }
   }
   {
     \tl_put_right:Nn \l__nlctdoc_contents_tl
      {
        \nlct@exampleimg@solofirstfalse
      }
   }
  \tl_if_empty:NF \nlct@example@label
   {
     \tl_if_empty:NF \example@title
      {
        \tl_put_right:Ne \l__nlctdoc_contents_tl
          {
            \exp_not:N \def \exp_not:N \@currentlabelname { \example@title }
          }
      }
     \tl_put_right:Ne \l__nlctdoc_contents_tl
      {
        \exp_not:N \label { \nlct@example@label }
      }
     \tl_put_right:NV \l__nlctdoc_contents_tl
       \example@do@extag
   }
  \let \nlct@org@cmd \cmd
  \def \cmd##1 {\csfmt{##1}}
  \def \glscmd##1 {\noexpand\glsfmttext{##1}}
  \protected@edef \example@tex@title { \example@title }
  \@loe@disable@cmds
  \tl_put_right:Ne \l__nlctdoc_contents_tl
   {
     \exp_not:N \addtolistofexamples { \example@title }
   }
  \@createexample@disablecmds
  \protected@edef\example@pdf@title{\example@title}%
  \protected@edef\example@attachdesc{\example@attachdesc}%
  \def\cmd##1{\glsbackslash ##1}%
  \protected@edef\example@title{\example@title}%
  \let\cmd\nlct@org@cmd
  \stepcounter {example}
  \xdef\nlct@example@filebasename{\nlctexamplefilebasename}%
  \immediate\openout\nlct@exampleout=\examplesdir/\nlct@example@filebasename.tex \relax
  \@create@example@write@nodetok { #2 } { #3 }
  \immediate\closeout\nlct@exampleout
  \nlct@run { \create@example@tex \space \nlct@example@filebasename.tex }
  \tl_put_right:Ne \l__nlctdoc_contents_tl
   {
     \exp_not:N \def \exp_not:N \nlct@example@filebasename { \nlct@example@filebasename }
     \exp_not:N \def \exp_not:N \create@example@pages { \create@example@pages }
     \exp_not:N \def \exp_not:N \create@example@pages@sep
       { \exp_not:V \create@example@pages@sep }
     \exp_not:N \def \exp_not:N \create@example@pages@perrow
       { \exp_not:V \create@example@pages@perrow }
     \exp_not:N \def \exp_not:N \create@example@graphicsopts
       { \exp_not:V \create@example@graphicsopts }
     \exp_not:N \def \exp_not:N \create@example@totalwidth
       { \exp_not:V \create@example@totalwidth }
     \exp_not:N \def \exp_not:N \nlct@exbacklink
       { \nlct@exbacklink }
     \exp_not:N \def \exp_not:N \nlct@example@label
       { \nlct@example@label }
   }
  \nlct@ifattachsupported
   {
     \tl_put_right:Ne \l__nlctdoc_contents_tl
      {
         \exp_not:N \nlct@ex@notboxed@title@attachments
         { \example@tex@title }
         {
            \exp_not:N \nlctexampletagattachfont
            \exp_not:N \textattachfile
              [
               mimetype={application/x-tex},
               author={\@pdfauthor},color={0 ~ 0 ~ 0},
               size={\example@filesize{.tex}},
               created={\example@filetimestamp{.tex}},
               modified={\example@filetimestamp{.tex}},
               subject={\example@pdf@title\space (source code)},
               description={\example@attachdesc\space (source code)}
              ]
              { \examplesdir/\nlct@example@filebasename.tex}
              { \exp_not:N \exampleattachtexicon}
            \ifnlctdownloadlinks
              \space
              \exp_not:N \href
                {
                  \nlctdownloadlink
                    { \examplesdir / \nlct@example@filebasename.tex }
                }
                { \exp_not:N \exampledownloadtexicon }
            \fi
            \ifnlctattachpdf
              \exp_not:N \IfFileExists
                { \examplesdir / \nlct@example@filebasename.pdf }
              {
                 \space
                 \exp_not:N \textattachfile
                  [mimetype={application/pdf},
                   author={\@pdfauthor},color={0 ~ 0 ~ 0},
                   size={\example@filesize{.pdf}},
                   created={\example@filetimestamp{.pdf}},
                   modified={\example@filetimestamp{.pdf}},
                   subject={\example@pdf@title\space (PDF)},
                   description={\example@attachdesc\space (PDF)}
                  ]
                  { \examplesdir/\nlct@example@filebasename.pdf }
                  { \exp_not:N \exampleattachpdficon }
              }
              { }
              \ifnlctdownloadlinks
               \space
               \exp_not:N \href
                 {
                   \exp_not:N \nlctdownloadlink
                    { \examplesdir/\nlct@example@filebasename.pdf }
                 }
                 { \exp_not:N \exampledownloadpdficon }
              \fi
            \else
              \ifnlctdownloadlinks
               \space
               \exp_not:N \href
                 {
                   \exp_not:N \nlctdownloadlink
                     { \examplesdir/\nlct@example@filebasename.pdf }
                 }
                 { \exp_not:N \exampledownloadpdficon }
              \fi
            \fi
            \exp_not:N \nlctpostexampletitle
         }
      }
   }
   {
     \tl_put_right:Ne \l__nlctdoc_contents_tl
      {
        \exp_not:N \nlctexampletitlebox 
          { \example@tex@title }
        \exp_not:N \hfill
        \ifnlctdownloadlinks
          \exp_not:N \href
            {
              \exp_not:N \nlctdownloadlink
                 { \examplesdir/\nlct@example@filebasename.tex }
            }
            { \exp_not:N \exampledownloadtexicon }
          \exp_not:N \quad
          \exp_not:N \href
            {
              \exp_not:N \nlctdownloadlink
                { \examplesdir/\nlct@example@filebasename.pdf }
            }
            { \exp_not:N \exampledownloadpdficon }
          \exp_not:N \nlctpostexampletitle
        \fi
      }
   }
  \tl_put_right:Nn \l__nlctdoc_contents_tl
   {
     \par \noindent
     \nlct@include@exampleimage
   }
  \addtocounter {example} { -1 }
 }

\ExplSyntaxOff


\renewcommand{\fps@figure}{htbp}

% put break before dash to avoid confusion with a hyphen
\newcommand{\dhyphen}{%
 \texorpdfstring
 {\discretionary{}{}{}\texttt{-}}%
 {-}%
}

% Redefine \- (used in entry names) so that hyphenation in command names, 
% switches, options etc., uses a serif hyphen to reduce confusion with an 
% actual hyphen in the code.
\renewrobustcmd{\-}{%
 \discretionary
 {{\rmfamily\char\ifnum\hyphenchar\font<0
  \defaulthyphenchar\else\hyphenchar\font\fi
 }}%
 {}{}%
}

\newcommand{\dequals}{%
 \texorpdfstring
 {\discretionary{}{}{}\texttt{=}\discretionary{}{}{}}%
 {=}%
}

\newcommand{\dcomma}{%
 \texorpdfstring
 {\texttt{,}\discretionary{}{}{}}%
 {,}%
}

\newcommand{\dcolon}{%
 \texorpdfstring
 {\texttt{:}\discretionary{}{}{}}%
 {:}%
}

\newcommand{\dfullstop}{%
 \texorpdfstring
 {\texttt{.}\discretionary{}{}{}}%
 {.}%
}

\newcommand{\dunderscore}{%
 \texorpdfstring
 {\discretionary{}{}{}\texttt{\_}\discretionary{}{}{}}%
 {\_}%
}

\newcommand{\dslash}{% v1.16
 \texorpdfstring{\slash}{/}%
}

\newcommand\dsb{\dunderscore}

\pdfstringdefDisableCommands{%
  \def\dhyphen{-}%
  \def\dslash{/}%
  \def\dcolon{:}%
  \def\dcomma{,}%
  \def\dequals{=}%
  \def\dfullstop{.}%
  \def\dunderscore{\_}%
  \let\-\empty
  \let\csfmtfont\@firstofone
  \let\NoCaseChange\@firstofone
}

\definecolor{cs}{rgb}{.328,.436,.1} % dark green
\definecolor{styopt}{rgb}{.408,.132,.545} % DarkOrchid4
\definecolor{csopt}{rgb}{.408,.132,.545} % DarkOrchid4
\definecolor{comment}{rgb}{0.37,0.37,0.37}% grey

\definecolor{style1}{rgb}{.32,.545,.545} % DarkSlateGray4
\definecolor{style2}{rgb}{.21,.392,.545} % SteelBlue4
\definecolor{style3}{rgb}{0,0,.545} % Blue4
\definecolor{style4}{rgb}{.332,.1,.545} % Purple4
\definecolor{style5}{rgb}{.28,.235,.545} % SlateBlue4
\definecolor{style6}{rgb}{.545,.352,.17} % Tan4

\newcommand{\sidenote}[1]{\leavevmode\marginpar{\footnotesize#1}}

\newcommand*{\csfmtfont}[1]{\ifmmode \mbox{\texttt{#1}}\else\texttt{#1}\fi}
\newcommand*{\csfmtcolourfont}[1]{\texttt{\textcolor{cs}{#1}}}

\newcommand*{\csfmt}[1]{\csfmtfont{\codebackslash #1}}
\newcommand*{\cspuncfmt}[1]{\csfmt{#1}} % v1.11

\MFUblocker{\csfmt}% v1.11
\MFUblocker{\cspuncfmt}% v1.11

\newcommand{\codebackslash}{\texorpdfstring{\char`\\}{\string\\}}

\newcommand{\csmetafmt}[3]{%
 \texorpdfstring
  {\csfmt{#1\ifstrempty{#1}{}{\-}\meta{#2}\ifstrempty{#3}{}{\-}#3}}%
  {\string\\#1\string<#2\string>#3}%
}
\newcommand{\csmetametafmt}[5]{%
 \texorpdfstring{\csfmt{#1\meta{#2}#3\meta{#4}#5}}{\string\\#1\string<#2\string>#3\string<#4\string>#5}%
}

\newcommand{\starredcs}[1]{\gls{#1}[\csfmtfont{*}]}
\newcommand{\starredenv}[1]{\gls{env.#1}[\envfmt{*}]} % v1.11

\newcommand{\thectr}[1]{\glslink{ctr.#1}{\csfmt{the#1}}} % v1.11
\newcommand{\theHctr}[1]{\glslink{ctr.#1}{\csfmt{theH#1}}} % v1.11

% v1.13
\ExplSyntaxOn

\cs_new:Nn \__nlctdoc_glscsname:nnn
 {
   \glslink [ #1 ] { #2 } { \csfmtfont { #3 } }
 }
\tl_new:N \l__nlctdoc_label_tl
\NewDocumentCommand \glscsname { O{} m }
 {
   \group_begin:
    \cs_set:Npn \_ { }
    \tl_set:Ne \l__nlctdoc_label_tl { #2 }
    \exp_args:NNnV
   \group_end:
     \__nlctdoc_glscsname:nnn
     { #1 }
     \l__nlctdoc_label_tl
     { #2 } 
 }

\ExplSyntaxOff

% v1.11
\NewDocumentCommand{\predcs}{O{}m}{%
  \glsxtrifhasfield{explsuffix}{#2}%
  {%
    \let\explsuffix\glscurrentfieldvalue
    \gls[#1]{#2}%
  }%
  {\gls[#1]{#2}}%
}

\NewDocumentCommand{\condcsT}{O{}m}{%
  {%
   \def\explTFsuffix{T}%
   \gls[#1]{#2}%
  }%
}

\NewDocumentCommand{\condcsF}{O{}m}{%
  {%
    \def\explTFsuffix{F}%
    \gls[#1]{#2}%
  }%
}

\newcommand*{\@expfunclink}[3]{\glslink[#3]{#2}{\csfmt{#1}}}

\NewDocumentCommand{\expfunc}{O{}mm}{%
  \ifglsentryexists{#2}%
  {%
    \glsxtrifhasfield{base}{#2}%
    {%
      \expandafter\@expfunclink\expandafter{\glscurrentfieldvalue:#3}{#2}{#1}%
    }%
    {%
      \gls[#1]{#2}%
    }%
  }%
  {\gls[#1]{#2:#3}}%
}

\glsxtraddlabelprefix{dual.}
\glsxtraddlabelprefix{idx.}
\glsxtraddlabelprefix{idx.sym.}
\glsxtraddlabelprefix{}

\newcommand{\idx}{\dgls}
\newcommand{\idxpl}{\dglspl}
\newcommand{\Idx}{\dGls}
\newcommand{\Idxpl}{\dGlspl}
\newcommand{\idxc}{\dglslink}
\newdglsfield{name}{\idxn}
\newdglsfield{first}{\idxf}

\newcommand{\optionlistprefix}{opt.}
\newcommand{\optionlistitemformat}[1]{\glsentrytext{#1}}
\newcommand{\optionlisttag}{Option}
\newcommand{\optionlisttags}{Options}

\newrobustcmd{\option}[1]{%
 \glslink{\optionlistprefix#1}%
 {\optionlisttag\glsxtrtaggedlistsep\optionlistitemformat{\optionlistprefix#1}}%
}

\newrobustcmd{\optionsto}[2]{%
 \optionlisttags\glsxtrtaggedlistsep
 \glslink{\optionlistprefix#1}%
 {\optionlistitemformat{\optionlistprefix#1}}%
 \thinspace\textendash\thinspace
 \glslink{\optionlistprefix#2}%
 {\optionlistitemformat{\optionlistprefix#2}}%
}

\newrobustcmd{\options}[1]{%
  {\def\andname{and}%
   \let\glsseeitemformat\optionlistitemformat
   \glsxtrtaggedlist{\optionlisttag}{\optionlisttags}{\optionlistprefix}{#1}%
  }%
}

\newrobustcmd{\optionsor}[1]{%
  {\def\andname{or}%
   \let\glsseeitemformat\optionlistitemformat
   \glsxtrtaggedlist{\optionlisttag}{\optionlisttags}{\optionlistprefix}{#1}%
  }%
}

\newcommand*{\stytext}[1]{\glsfmttext{pkg.#1}}
\newcommand*{\clstext}[1]{\glsfmttext{cls.#1}}
\newcommand*{\opttext}[1]{\glsfmttext{opt.#1}}
\newcommand*{\envtext}[1]{\glsfmttext{env.#1}}
\newcommand*{\ctrtext}[1]{\glsfmttext{ctr.#1}}
\newcommand*{\actext}[1]{\glsfmttext{dual.#1}}
\newcommand*{\exttext}[1]{\glsfmttext{ext.#1}}
\newcommand*{\apptext}[1]{\glsfmttext{app.#1}}
\newcommand*{\switchtext}[1]{\glsfmttext{switch.#1}}

\glsxtrnewgls{pkg.}{\sty}
\glsxtrnewgls{cls.}{\cls}
\glsxtrnewgls{opt.}{\opt}
\glsxtrnewgls{env.}{\env}
\glsxtrnewgls{ctr.}{\ctr}
\glsxtrnewgls{dual.}{\ac}
\glsxtrnewgls[format=glsignore]{ext.}{\ext}
\glsxtrnewgls{app.}{\app}
\glsxtrnewgls{switch.}{\switch}
\glsxtrnewgls{idx.mod.}{\cmdmod}

\newdglsfield{symbol}{\sym}

\newcommand{\optval}[2]{%
 \texorpdfstring
  {\gls{opt.#1}\optfmt{\dequals#2}}%
  {\glsentrytext{opt.#1}=#2}%
}

\newcommand{\optvalm}[2]{%
 \texorpdfstring
  {\gls{opt.#1}\optfmt{\dequals\marg{#2}}}%
  {\glsentrytext{opt.#1}=\marg{#2}}%
}

\newcommand{\opteqvalref}[2]{%
 \texorpdfstring
  {\gls!{opt.#1}\optfmt{\dequals}\gls{optval.#1.#2}}%
  {\glsentrytext{opt.#1}=\glsentrytext{optval.#1.#2}}%
}

\newcommand{\optvalref}[2]{%
 \texorpdfstring
  {\gls{optval.#1.#2}}%
  {\glsentrytext{optval.#1.#2}}%
}

\newcommand{\optvalrefeq}[3]{%
 \texorpdfstring
  {\gls{optval.#1.#2}\optfmt{\dequals#3}}%
  {\glsentrytext{optval.#1.#2}=#3}%
}

\newcommand{\childoptval}[3]{%
 \texorpdfstring
  {\gls{optval.#1.#2}\optfmt{\dequals#3}}%
  {\glsentrytext{optval.#1.#2}=#3}%
}

\newcommand{\qt}[1]{\texorpdfstring{``#1''}{"#1"}}
\newcommand{\qtt}[1]{\qt{\,\texttt{#1}\,}}

\newcommand{\booktitle}[1]{\emph{#1}}

\newcommand*{\fmtorcode}[2]{#1{#2}}

\newcommand*{\appfmt}[1]{\texorpdfstring{\texttt{#1}}{#1}}
\newcommand*{\styfmt}[1]{\texorpdfstring{\textsf{#1}}{#1}}
\newcommand*{\clsfmt}[1]{\texorpdfstring{\textsf{#1}}{#1}}
\newcommand*{\envfmt}[1]{\texorpdfstring{\textsf{#1}}{#1}}
\newcommand*{\optfmt}[1]{\texorpdfstring{\texttt{#1}}{#1}}
\newcommand*{\csoptfmt}[1]{\texorpdfstring{\textcolor{cs}{\optfmt{#1}}}{#1}}
\newcommand*{\styoptfmt}[1]{\texorpdfstring{\textcolor{styopt}{\optfmt{#1}}}{#1}}
\newcommand*{\clsoptfmt}[1]{\texorpdfstring{\textcolor{styopt}{\optfmt{#1}}}{#1}}
\newcommand*{\ctrfmt}[1]{\texorpdfstring{\textsf{#1}}{#1}}

\edef\longswitch{\string-\/\string-}
\edef\pdflongswitch{\string-\string-}

\newcommand*{\longargfmt}[1]{%
 \texorpdfstring{\texttt{\longswitch #1}}{\pdflongswitch#1}%
}

\newcommand*{\shortargfmt}[1]{\texorpdfstring{\texttt{-#1}}{\string-#1}}

% \defsemanticcmd[colour]{cs}{font-cs}{prefix}
\newcommand*{\defsemanticcmd}[4][]{%
  \ifstrempty{#1}%
  {%
    \ifstrempty{#3}%
    {%
      \newcommand#2[1]{#4##1}%
    }
    {%
      \newcommand#2[1]{\texorpdfstring{\fmtorcode#3{#4##1}}{#4##1}}%
    }%
  }%
  {%
    \ifstrempty{#3}%
    {%
      \newcommand#2[1]{\texorpdfstring{{\color{#1}#4##1}}{#4##1}}%
    }%
    {%
      \newcommand#2[1]{\texorpdfstring{\fmtorcode#3{\color{#1}#4##1}}{#4##1}}%
    }%
  }%
}

\newcommand{\faded}[1]{\texorpdfstring{\textcolor{gray}{#1}}{#1}}

\newrobustcmd*{\texmeta}[1]{{\normalfont$\langle$\emph{#1}$\rangle$}}

\newcommand*{\meta}[1]{%
 \texorpdfstring{\ifmmode\text{\texmeta{#1}}\else\texmeta{#1}\fi}{\string<#1\string>}%
}

\newcommand*{\oarg}[1]{\discretionary{}{}{}[#1]}
\newcommand*{\oargm}[1]{\oarg{\meta{#1}}}
\newcommand*{\oargnobr}[1]{\discretionary{}{}{}\mbox{[#1]}}% v1.12

% To prevent lonely [ and ] from upsetting the syntax highlighter:
\newrobustcmd*{\nlctopensqbracket}{[}
\newrobustcmd*{\nlctclosesqbracket}{]}

% To prevent lonely ( and ) from upsetting the syntax highlighter:
\newrobustcmd*{\nlctopenparen}{(}
\newrobustcmd*{\nlctcloseparen}{)}

\newcommand*{\marg}[1]{\texorpdfstring
 {\discretionary{}{}{}\char`\{#1\char`\} \discretionary{}{}{}}%
 {\{#1\}}%
}

\newcommand*{\margm}[1]{\marg{\meta{#1}}}

\newcommand*{\metaboolean}{\meta{boolean}}
\newcommand*{\keyval}{\meta{key}\dequals\meta{value}}
\newcommand*{\keyvallist}{\meta{key\dequals value list}}

\newcommand*{\keyeqvalue}[2]{#1=#2}
\newcommand*{\keyeqvaluem}[2]{#1=\marg{#2}}

\newcommand*{\file}[1]{%
 \texorpdfstring
 {\gls{file.#1}}%
 {#1}%
}

\newcommand{\homedir}{\string~}% v1.11
\newcommand{\homefilefmt}[1]{\filefmt{\homedir\slash#1}}

\newcommand*{\filefmt}[1]{\texorpdfstring{\texttt{#1}}{#1}}
\newcommand*{\extfmt}{\filefmt}

% \metafilefmt{prefix}{val}{suffix} -> prefix<val>suffix
\newcommand*{\metafilefmt}[3]{%
  \filefmt{#1}\discretionary{}{}{}\meta{#2}\discretionary{}{}{}\filefmt{#3}%
}

% \metametafilefmt{prefix}{val1}{mid}{val2}{suffix} ->
% prefix<val1>mid<val2>suffix
\newcommand*{\metametafilefmt}[5]{%
  \filefmt{#1}\discretionary{}{}{}\meta{#2}\discretionary{}{}{}\filefmt{#3}%
  \discretionary{}{}{}\meta{#4}\discretionary{}{}{}\filefmt{#5}%
}

\newcommand*{\BibTeX}{\hologo{BibTeX}}
\newcommand*{\eTeX}{\hologo{eTeX}}
\newcommand*{\XeLaTeX}{\hologo{XeLaTeX}}
\newcommand*{\LuaLaTeX}{\hologo{LuaLaTeX}}
\newcommand*{\pdfLaTeX}{\hologo{pdfLaTeX}}
\newcommand*{\LuaTeX}{\hologo{LuaTeX}}
\newcommand*{\XeTeX}{\hologo{XeTeX}}
\newcommand*{\pdfTeX}{\hologo{pdfTeX}}

\ifdef\GlsXtrSetPlusModifier
{\GlsXtrSetPlusModifier{format=glsnumberformat}}{}

\ifdef\GlsXtrSetAltModifier
{\GlsXtrSetAltModifier{!}{format=glsignore}}{}

\newcommand{\@@mainmatteronly@op}[1]{%
 \glsxtrtitleorpdforheading{#1}{}{}%
}
\newcommand{\@mainmatteronly}[1]{%
 \texorpdfstring{\protect\@@mainmatteronly{#1}}{}%
}
\let\mainmatteronly\@mainmatteronly
\let\@@mainmatteronly\@@mainmatteronly@op

\ifdef\frontmatter
{
 \appto\frontmatter{%
   \GlsXtrSetDefaultNumberFormat{glsignore}%
   \let\mainmatteronly\@gobble
   \let\@@mainmatteronly\@gobble
   \renewcommand\@chapapp{\chaptername}% v1.16
  }
}
{%
}

\ifdef\mainmatter
{
  \appto\mainmatter{%
    \GlsXtrSetDefaultNumberFormat{glsnumberformat}%
    \let\mainmatteronly\@mainmatteronly
    \let\@@mainmatteronly\@@mainmatteronly@op
  }
}
{}

\ifdef\backmatter
{
  \appto\backmatter{%
   \def\theHchapter{backmatter.\arabic{chapter}}%
   \setupglossaries{numberedsection=nolabel}}%
 }
{}

\ifdef\appendix
{
  \ifdef\chapter
  {
    \appto\appendix{%
      \renewcommand{\Hy@chapapp}{chapter}%
    }
  }
  {}
}
{}

\ifdef\abstract
{}
{
 \providecommand{\abstractname}{Abstract}
 \newenvironment{abstract}{\begin{center}\textbf{\abstractname}\end{center}\quotation}{\endquotation}
}

\newcommand{\cmddefbookmarkleveloffset}{1}

\newcommand*{\setcounterlevels}[2]{%
 \edef\cmddefbookmarklevel{\number\numexpr#1+\cmddefbookmarkleveloffset }%
 \def\cmddefcounter{#2}%
 \let\pkgdefbookmarklevel\cmddefbookmarklevel
 \def\pkgdefcounter{#2}%
 \let\clsdefbookmarklevel\cmddefbookmarklevel
 \def\clsdefcounter{#2}%
 \def\currentcounterlevel{#1}%
 \def\currentcounter{#2}%
}

\ifdef\chapter
{
  \nlct@ifkoma
   {
      \AddtoDoHook{heading/preinit/chapter}{\setcounterlevels{0}{chapter}}
   }
   {
     \preto\chapter{\setcounterlevels{0}{chapter}}
   }
  \setcounterlevels{0}{chapter}
}
{
  \setcounterlevels{1}{section}
}

\nlct@ifkoma
 {
   \AddtoDoHook{heading/preinit/part}{\setcounterlevels{-1}{part}}
   \AddtoDoHook{heading/preinit/section}{\setcounterlevels{1}{section}}
   \AddtoDoHook{heading/preinit/subsection}{\setcounterlevels{2}{subsection}}
   \AddtoDoHook{heading/preinit/subsubsection}{\setcounterlevels{3}{subsubsection}}
   \AddtoDoHook{heading/preinit/paragraph}{\setcounterlevels{4}{paragraph}}
   \AddtoDoHook{heading/preinit/subparagraph}{\setcounterlevels{4}{subparagraph}}
 }
 {
  \preto\part{\setcounterlevels{-1}{part}}
  \preto\section{\setcounterlevels{1}{section}}
  \preto\subsection{\setcounterlevels{2}{subsection}}
  \preto\subsubsection{\setcounterlevels{3}{subsubsection}}
  \preto\paragraph{\setcounterlevels{4}{paragraph}}
  \preto\subparagraph{\setcounterlevels{4}{subparagraph}}
 }

\newcommand{\mainfmt}[1]{\glsnumberformat{#1}}

% \createtarget{label}{text}
\newcommand*{\createtarget}[2]{%
 \glstarget{#1}{#2}\xGlsXtrSetField{#1}{target}{\glolinkprefix #1}%
}

\renewcommand*{\GlsXtrStandaloneEntryName}[1]{%
  \createtarget{#1}{\glossentryname{#1}}%
}

\renewcommand*{\GlsXtrStandaloneEntryOther}[2]{%
  \createtarget{#1}{\glossentrynameother{#1}{#2}}%
}

% \targetorhyperlink{label}{text}
\newcommand*{\targetorhyperlink}[2]{%
 \glsxtrifhasfield*{target}{#1}%
 {%
   \glshyperlink[{#2}]{#1}%
 }%
 {%
   \createtarget{#1}{#2}%
 }%
}

\newcommand*{\linkedentryname}[1]{%
 {\setkeys{printgloss}{target=true}\targetorhyperlink{#1}{\glossentryname{#1}}}%
}

\newrobustcmd{\aliasref}[1]{\glshyperlink{#1}}
\newrobustcmd{\initvalref}[1]{\ifglsentryexists{#1}{\glshyperlink{#1}}{\cmd{#1}}}
\newrobustcmd{\initvalopt}[2]{%
 \ifstrempty{#1}%
 {\ifglsentryexists{opt.#2}{\glshyperlink{opt.#2}}{\optfmt{#2}}}%
 {\ifglsentryexists{opt.#1.#2}{\glshyperlink{opt.#1.#2}}{\optfmt{#2}}}%
}

\newcommand*{\optvaldefcounter}{}

\newcommand*{\inlineidxdef}[1]{%
 \mainmatteronly{\mainglsadd{idx.#1}{}}%
 \glsxtrglossentry{idx.#1}%
}

\newcommand*{\Inlineidxdef}[1]{%
 \bgroup
   \let\glossentryname\Glossentryname
   \mainmatteronly{\mainglsadd{idx.#1}{}}%
   \glsxtrglossentry{idx.#1}%
 \egroup
}

% v1.09: added idx. prefix to \glsunset
\newrobustcmd*{\inlineidxfdef}[1]{%
 \mainmatteronly{\mainglsadd{idx.#1}{}}%
 \glsxtrglossentryother{}{idx.#1}{first}%
 \glsunset{idx.#1}%
}

% v1.09: added idx. prefix to \glsunset
\newrobustcmd*{\inlineidxpdef}[1]{%
 \mainmatteronly{\mainglsadd{idx.#1}{}}%
 \glsxtrglossentryother{}{idx.#1}{plural}%
 \glsunset{idx.#1}%
}

\newrobustcmd*{\inlineswitchdef}[1]{%
 \mainmatteronly{\mainglsadd{switch.#1}{}}%
 \glsxtrglossentry{switch.#1}%
}

\newrobustcmd*{\inlineglsdef}[2][cmddef]{%
 \mainglsadd{#2}{#1}%
 \glsxtrglossentry{#2}%
}

\newrobustcmd*{\inlineoptdef}[2][optdef]{%
 \mainglsadd{opt.#2}{#1}%
 \glsxtrglossentry{opt.#2}%
}

% v1.10
\newrobustcmd*{\inlinepkgdef}[2][pkgdef]{%
 \mainglsadd{pkg.#2}{#1}%
 \glsxtrglossentry{pkg.#2}%
}

% v1.11
\newrobustcmd*{\inlinefiledef}[2][filedef]{%
 \mainglsadd{file.#2}{#1}%
 \glsxtrglossentry{file.#2}%
}

% v1.11
\newrobustcmd*{\inlineappdef}[2][appdef]{%
 \mainglsadd{app.#2}{#1}%
 \glsxtrglossentry{app.#2}%
}

\newcommand*{\mainglsadd}[3][]{%
 \glsxtrifhasfield{alias}{#2}%
 {\glsadd[#1]{#2}}%
 {%
   \ifstrempty{#3}%
   {\def\mainglsaddcounter{}}%
   {%
     \ifcsdef{#3counter}%
     {\letcs\mainglsaddcounter{#3counter}}%
     {\let\mainglsaddcounter\currentcounter}%
   }%
   \ifdefempty\mainglsaddcounter{}{\glsadd[counter=\mainglsaddcounter,format=mainfmt]{#2}}%
   \glsadd[format=mainfmt,#1]{#2}%
 }%
}

% standalone targets
\newcommand{\entrydefsection}{\section}
\newcommand{\entrysec}[2][\entrydefsection]{%
  #1{\glsxtrglossentry{#1}%
     \glsxtrtitleorpdforheading{\mainglsadd{#1}{entrydef}}{}{}}%
}

% doesn't display any text but creates the target and principle
% location
\newrobustcmd{\maindef}[2][]{%
 \glsdoifexists{#2}%
 {%
   \mainglsadd[#1]{#2}{maindef}\createtarget{#2}{\strut}%
 }%
}

\newrobustcmd*{\cmddef}{\@ifstar\s@cmddef\@cmddef}
\newcommand*{\@cmddef}[2][]{%
 \vskip 1sp plus 2ex\relax
 \pdfbookmark[\cmddefbookmarklevel]{\glsentryname{#2}}{csdef.#2}%
 \nopagebreak\s@cmddef[#1]{#2}%
 \nopagebreak\ignorespaces
}

\newcommand*{\cmdnotefmt}[1]{\mbox{#1}}

\newcommand*{\cmddefsyntax}[2]{%
 \mainglsadd[#1]{#2}{cmddef}%
 \texttt{\glsxtrglossentry{#2}\syntax{#2}}%
}

\newcommand*{\optdefsyntax}[2]{%
 \mainglsadd[#1]{opt.#2}{optdef}%
 \texttt{\glsxtrglossentry{opt.#2}
 \glsxtrifhasfield{syntax}{opt.#2}{\dequals\glscurrentfieldvalue}{}}%
}

\newcommand{\summarytagfill}{\space\allowbreak\mbox{}\nolinebreak\hfill}% v1.12

\newcommand{\@cmddef@init}{%
 \let\csfmtfont\@firstofone
 \def\cmdfont##1{\textbf{\texttt{##1}}}%
 \def\explTFsuffix{\@explboolsyntaxfmt{TF}}%
}

\newcommand*{\s@cmddef}[2][]{%
 \def\cmdtitle{\icon{definition}}%
 \def\postnote{}%
 \ifnotdefaultstatus{#2}{\def\cmdtitle{\statussym}\def\postnote{\hfill\statustext}}{}%
 \begin{pinnedbox}[title=\cmdtitle]
 \@cmddef@init
 \gathermodifiers{#2}%
 \gathervariants{#2}%
 \cmddefsyntax{#1}{#2}%
 \def\tagsep{\summarytagfill}%
 \ifdefempty\nlctmodifierlist
  {%
   \ifdefempty\nlctvariantlist
    {}%
    {\tagsep\summarytagfmt{\nlctvarianttag}\nlctvariantlist\relax
     \let\tagsep\space
    }%
  }%
  {\tagsep\summarytagfmt{\nlctmodifiertag}\nlctmodifierlist\relax
   \let\tagsep\space
  }%
 \glsxtrifhasfield{initvalue}{#2}
  {\tagsep\summarytagfmt{initial}\texttt{\glscurrentfieldvalue}}%
  {}%
 \ifdefempty\nlctmodifierglslist{}%
 {\@for\@nlct@label:=\nlctmodifierglslist\do
  {\par\cmddefsyntax{#1}{\@nlct@label}}}%
 \glsxtrifhasfield{explsuffix}{#2}%
  {%
    \let\explsuffix\glscurrentfieldvalue
    \let\explTFsuffix\relax
    \let\TFsyntax\relax
    \par\texttt{\glsentryname{#2}%
    \syntax{#2}}%
  }%
  {}%
 \glsxtrifhasfield*{note}{#2}%
 {%
   \ifx\cmdnotefmt\@gobble
     \ifdefempty\postnote{}{\preto\postnote{\hfill}}%
   \else
     \par\hfill\cmdnotefmt\glscurrentfieldvalue
     \ifdefempty\postnote{}{\preto\postnote{\space}}%
   \fi
 }%
 {\ifdefempty\postnote{}{\preto\postnote{\hfill}}}%
 \postnote
 \end{pinnedbox}%
 \noindent\ignorespaces
}

\newcommand{\gathermodifiers}[1]{%
 \protected@edef\nlctcmddeflabel{#1}%
 \def\nlctmodifiertag{}%
 \def\nlctmodifierlist{}%
 \def\nlctmodifierglslist{}%
 \glsxtrforcsvfield*{#1}{modifiers}{\cmddefmodifierhandler}%
}

\newcommand{\cmddefmodifierhandler}[1]{%
  \ifglsentryexists{\nlctcmddeflabel#1}%
  {%
    \ifdefempty\nlctmodifierglslist
    {\eappto\nlctmodifierglslist{\nlctcmddeflabel#1}}%
    {\eappto\nlctmodifierglslist{,\nlctcmddeflabel#1}}%
  }%
  {%
    \ifdefempty\nlctmodifierlist
    {\def\nlctmodifiertag{modifier}}%
    {\def\nlctmodifiertag{modifiers}\appto\nlctmodifierlist{ }}%
    \ifglsentryexists{idx.mod.#1}%
    {\eappto\nlctmodifierlist{\noexpand\gls{idx.mod.#1}}}%
    {\eappto\nlctmodifierlist{#1}}%
  }%
}

\newcommand{\gathervariants}[1]{%
 \protected@edef\nlctcmddeflabel{#1}%
 \def\nlctvarianttag{}%
 \def\nlctvariantlist{}%
 \def\nlctvariantglslist{}%
 \glsxtrforcsvfield*{#1}{variants}{\cmddefvarianthandler}%
}

\newcommand{\cmddefvarianthandler}[1]{%
  \ifglsentryexists{\nlctcmddeflabel:#1}%
  {%
    \ifdefempty\nlctvariantglslist
    {\eappto\nlctvariantglslist{\nlctcmddeflabel#1}}%
    {\eappto\nlctvariantglslist{,\nlctcmddeflabel#1}}%
  }%
  {%
    \ifdefempty\nlctvariantlist
    {\def\nlctvarianttag{variant}}%
    {\def\nlctvarianttag{variants}\appto\nlctvariantlist{ }}%
    \eappto\nlctvariantlist{\noexpand\code{#1}}%
  }%
}

\newrobustcmd*{\envdef}{\@ifstar\s@envdef\@envdef}
\newcommand*{\@envdef}[2][]{%
 \pdfbookmark[\cmddefbookmarklevel]{\glsentryname{env.#2}}{env.#2}%
 \nopagebreak\s@envdef[#1]{#2}%
}

\newsavebox\entrynamebox

\newcommand{\enventryname}[1]{%
 \createtarget{#1}%
 {%
   \texttt
   {%
     \sbox\entrynamebox
     {%
       \csfmt{begin}%
       \marg{\glossentryname{#1}}%
       \glsxtrifhasfield{syntax}{#1}{\glscurrentfieldvalue}{}%
       \meta{content}\csfmt{end}\marg{\glsentryname{#1}}%
     }%
     \settowidth\dimen@{\usebox\entrynamebox}%
     \ifdim\dimen@>0.8\linewidth
       \csfmt{begin}%
       \marg{\glossentryname{#1}}%
       \glsxtrifhasfield{syntax}{#1}{\glscurrentfieldvalue}{}%
       \endgraf\meta{content}\endgraf\csfmt{end}\marg{\glsentryname{#1}}%
     \else
       \usebox\entrynamebox
     \fi
   }%
 }%
}

\newcommand*{\s@envdef}[2][]{%
 \def\envtitle{\icon{definition}}%
 \def\postnote{}%
 \ifnotdefaultstatus{env.#2}{\def\envtitle{\statussym}\def\postnote{\statustext}}{}%
 \begin{pinnedbox}[title=\envtitle]
 \let\GlsXtrStandaloneEntryName\enventryname
 \def\envfmt##1{\textbf{\texttt{##1}}}%
 \mainglsadd[#1]{env.#2}{cmddef}%
 \glsxtrglossentry{env.#2}%
 \glsxtrifhasfield*{note}{env.#2}%
 {%
   \ifx\cmdnotefmt\@gobble
     \ifdefempty\postnote{}{\preto\postnote{\hfill}}%
   \else
     \par\hfill\cmdnotefmt\glscurrentfieldvalue
     \ifdefempty\postnote{}{\preto\postnote{\space}}%
   \fi
 }%
 {\ifdefempty\postnote{}{\preto\postnote{\hfill}}}%
 \postnote
 \end{pinnedbox}%
 \noindent\ignorespaces
}

\newrobustcmd*{\pkgdef}{\@ifstar\s@pkgdef\@pkgdef}
\newcommand*{\@pkgdef}[2][]{%
 \pdfbookmark[\pkgdefbookmarklevel]{\glsentryname{pkg.#2}.sty}{pkgdef.#2}%
 \nopagebreak\s@pkgdef[#1]{#2}%
}

\newcommand{\pkgentryname}[1]{%
 \createtarget{#1}%
 {%
   \texttt
   {%
     \csfmt{usepackage}%
     \glsxtrifhasfield{syntax}{#1}{[\glscurrentfieldvalue]}{}%
     \marg{\glossentryname{#1}}%
   }%
 }%
}

\newcommand{\pkgnotefmt}[1]{#1}

\newcommand*{\s@pkgdef}[2][]{%
 \def\pkgtitle{\icon{definition}}%
 \def\postnote{}%
 \ifnotdefaultstatus{pkg.#2}{\def\pkgtitle{\statussym}\def\postnote{\statustext}}{}%
 \begin{pinnedbox}[title=\pkgtitle]
 \let\GlsXtrStandaloneEntryName\pkgentryname
 \def\styfmt##1{\textbf{\texttt{##1}}}%
 \mainglsadd[#1]{pkg.#2}{pkgdef}%
 \glsxtrglossentry{pkg.#2}%
 \glsxtrifhasfield*{note}{pkg.#2}%
 {%
   \ifx\pkgnotefmt\@gobble
     \ifdefempty\postnote{}{\preto\postnote{\hfill}}%
   \else
     \par\hfill\pkgnotefmt\glscurrentfieldvalue
     \ifdefempty\postnote{}{\preto\postnote{\space}}%
   \fi
 }%
 {\ifdefempty\postnote{}{\preto\postnote{\hfill}}}%
 \postnote
 \end{pinnedbox}%
 \noindent\ignorespaces
}

\newrobustcmd*{\clsdef}{\@ifstar\s@clsdef\@clsdef}
\newcommand*{\@clsdef}[2][]{%
 \pdfbookmark[\clsdefbookmarklevel]{\glsentryname{cls.#2}.sty}{clsdef.#2}%
 \nopagebreak\s@clsdef[#1]{#2}%
}

\newcommand{\clsentryname}[1]{%
 \createtarget{#1}%
 {%
   \texttt
   {%
     \csfmt{documentclass}%
     \glsxtrifhasfield{syntax}{#1}{[\glscurrentfieldvalue]}{}%
     \marg{\glossentryname{#1}}%
   }%
 }%
}

\newcommand*{\s@clsdef}[2][]{%
 \def\clstitle{\icon{definition}}%
 \def\postnote{}%
 \ifnotdefaultstatus{cls.#2}{\def\clstitle{\statussym}\def\postnote{\statustext}}{}%
 \begin{pinnedbox}[title=\clstitle]
 \let\GlsXtrStandaloneEntryName\clsentryname
 \def\clsfmt##1{\textbf{\texttt{##1}}}%
 \mainglsadd[#1]{cls.#2}{clsdef}%
 \glsxtrglossentry{cls.#2}%
 \glsxtrifhasfield*{note}{cls.#2}%
 {%
   \ifx\pkgnotefmt\@gobble
    \ifdefempty\postnote{}{\preto\postnote{\hfill}}%
   \else
    \par\hfill\pkgnotefmt\glscurrentfieldvalue
    \ifdefempty\postnote{}{\preto\postnote{\space}}%
   \fi
 }%
 {\ifdefempty\postnote{}{\preto\postnote{\hfill}}}%
 \postnote
 \end{pinnedbox}%
 \noindent\ignorespaces
}

\ExplSyntaxOn
\newcommand*{\defaultoptdefbookmarklevel}{ \int_eval:n { \currentcounterlevel + \c_one_int } }
\ExplSyntaxOff
\newcommand*{\optdefbookmarklevel}{\defaultoptdefbookmarklevel}

\newrobustcmd*{\optiondef}{\@ifstar\s@optiondef\@optiondef}

\NewDocumentCommand{\@optiondef}{ t+ o m }{%
 \IfBooleanTF{#1}%
 {%
   \edef\optdefbookmarklevel{\defaultoptdefbookmarklevel}%
 }%
 {%
   \IfValueTF{#2}%
   {%
     \edef\optdefbookmarklevel{\number#2}%
   }%
   {%
     \glsifcategory{opt.#3}{commandoption}%
     {%
       \edef\optdefbookmarklevel{\number\numexpr\cmddefbookmarklevel+1 }%
     }%
     {%
       \edef\optdefbookmarklevel{\defaultoptdefbookmarklevel}%
     }%
   }%
 }%
 \glsdoifexists{opt.#3}% v1.16
 {%
   \pdfbookmark[\optdefbookmarklevel]{\glsentryname{opt.#3}}{optdef.#3}%
 }%
 \nopagebreak\s@optiondef{#3}%
}

\newcommand{\optnotefmt}[1]{#1}

\newcommand{\optiondefhook}{}% v1.11

\newcommand*{\s@optiondef}[1]{%
  \bgroup
  \optiondefhook
  \getinitordefval{opt.#1}%
  \def\postnote{}%
  \ifnotdefaultstatus{opt.#1}%
  {\appto\settingstitle{\statussym}\def\postnote{\statustext}}%
  {}%
  \begin{settingsbox}[title=\settingstitle,
    colback=optiondefbackground,
    colbacktitle=optiondefbackground
  ]%
   \def\optfmt##1{\textbf{\texttt{##1}}}%
   \mainglsadd{opt.#1}{optdef}\glsxtrglossentry{opt.#1}%
   \glsxtrifhasfield{syntax}{opt.#1}{\texttt{=\glscurrentfieldvalue}}{}%
   \ifdefempty\initordefval{}{\summarytagfill\initordefval}%
   \glsxtrifhasfield*{note}{opt.#1}%
   {%
     \ifx\optnotefmt\@gobble
       \ifdefempty\postnote{}{\preto\postnote{\hfill}}%
     \else
       \par\hfill\optnotefmt\glscurrentfieldvalue
       \ifdefempty\postnote{}{\preto\postnote{\space}}%
     \fi
   }%
   {\ifdefempty\postnote{}{\preto\postnote{\hfill}}}%
   \postnote
  \end{settingsbox}%
  \egroup
  \noindent\ignorespaces
}

\newrobustcmd*{\optionvaldef}{\@ifstar\s@optionvaldef\@optionvaldef}

\newcommand*{\@optionvaldef}[2]{%
 \edef\optvaldefbookmarklevel{\number\numexpr\optdefbookmarklevel+1 }%
 \pdfbookmark[\optvaldefbookmarklevel]{\glsentryname{optval.#1.#2}}{optvaldef.#1.#2}%
 \nopagebreak\s@optionvaldef{#1}{#2}%
}

\newcommand*{\s@optionvaldef}[2]{%
  \begin{settingsbox}[title={\icon{optionvalue}},
    colback=optionvaluedefbackground,
    colbacktitle=optionvaluedefbackground
   ]%
   \def\optfmt##1{\textbf{\texttt{##1}}}%
   \mainglsadd{optval.#1.#2}{optvaldef}%
   \gls!{opt.#1}\dequals\glsxtrglossentry{optval.#1.#2}%
   \def\summary@sep{\hfill}%
   \glsxtrifhasfield*{alias}{optval.#1.#2}%
   {%
     \summary@sep\summarytagfmt{alias}%
     \expandafter\aliasref\expandafter{\glscurrentfieldvalue}%
     \def\summary@sep{ }%
   }{}%
   \ifnotdefaultstatus{optval.#1.#2}{\summary@sep\statussym}{}%
   \glsxtrifhasfield{note}{optval.#1.#2}%
   {%
     \ifx\optnotefmt\@gobble
     \else
       \par\hfill\optnotefmt\glscurrentfieldvalue
     \fi
   }{}%
  \end{settingsbox}%
  \noindent\ignorespaces
}

\newrobustcmd*{\inlineoptionvaldef}[2]{%
 \bgroup
  \ttfamily
  \mainglsadd{optval.#1.#2}{optvaldef}%
  \textbf{\glsxtrglossentry{optval.#1.#2}}%
  \glsxtrifhasfield{syntax}{optval.#1.#2}{\dhyphen\glscurrentfieldvalue}{}%
  \ifnotdefaultstatus{optval.#1.#2}{~\statussym}{}%
  :\space
  \glsxtrifhasfield{alias}{optval.#1.#2}%
  {%
    Synonym of \expandafter\aliasref\expandafter{\glscurrentfieldvalue}.%
  }%
  {% 
    \glossentrydesc{optval.#1.#2}\glspostdescription
    \glsxtrifhasfield{seealso}{optval.#1.#2}%
    {%
      See also \glsxtrseelist{\glscurrentfieldvalue}.%
    }%
    {}% 
  }%
 \egroup
}

\newcommand{\appnotefmt}[1]{#1}

\newrobustcmd*{\appdef}[1]{%
  \getinitordefval{app.#1}%
  \def\postnote{}%
  \begin{terminal}%
   \def\appfmt##1{\textbf{##1}}%
   \mainglsadd{app.#1}{appdef}\glsxtrglossentry{app.#1}%
   \glsxtrifhasfield{syntax}{app.#1}{\space \glscurrentfieldvalue}{}%
   \glsxtrifhasfield*{note}{app.#1}%
   {%
     \ifx\appnotefmt\@gobble
       \ifdefempty\postnote{}{\preto\postnote{\hfill}}%
     \else
       \par\hfill\appnotefmt\glscurrentfieldvalue
       \ifdefempty\postnote{}{\preto\postnote{\space}}%
     \fi
   }%
   {\ifdefempty\postnote{}{\preto\postnote{\hfill}}}%
   \postnote
  \end{terminal}%
  \noindent\ignorespaces
}

\newrobustcmd*{\switchdef}[1]{%
  \getinitordefval{switch.#1}%
  \def\postnote{}%
  \ifnotdefaultstatus{switch.#1}%
  {\appto\settingstitle{\statussym}\def\postnote{\statustext}}%
  {}%
  \begin{settingsbox}[title={\settingstitle}]%
   \mainglsadd{switch.#1}{switchdef}\glsxtrglossentry{switch.#1}%
   \glsxtrifhasfield{syntax}{switch.#1}{\space \glscurrentfieldvalue}{}%
   \glsxtrifhasfield*{note}{switch.#1}%
   {%
     \ifx\switchnotefmt\@gobble
       \ifdefempty\postnote{}{\preto\postnote{\hfill}}%
     \else
       \par\hfill\switchnotefmt\glscurrentfieldvalue
       \ifdefempty\postnote{}{\preto\postnote{\space}}%
     \fi
   }%
   {\ifdefempty\postnote{}{\preto\postnote{\hfill}}}%
   \postnote
  \end{settingsbox}%
  \noindent\ignorespaces
}

\newrobustcmd{\mirrorsamplefile}[1]{%
 \ctanmirrornofn{macros/latex/contrib/\thispackagename/\filedownloadsubpath/#1}{\nolinkurl{#1}}%
}

\newcommand{\filedownloadsubpath}{samples/}
\newcommand{\filedownloadlink}[1]{\href{\nlctdownloadlink{\filedownloadsubpath #1}}{\faDownload}}
\newcommand{\filetag}[1]{\faFileO\ifnlctdownloadlinks\filedownloadlink{#1}\fi\ }
\newcommand*{\filedef}[1]{%
  \par\medskip
  \bgroup
  \raggedright
  \filetag{#1}%
  \ttfamily
  \mainglsadd{file.#1}{filedef}%
  \glsxtrglossentry{file.#1}%
  \egroup
  \par\medskip\ignorespaces
}

\newrobustcmd*{\summarytagfmt}[1]{\textnormal{\em #1:}~}

\newcommand*{\getinitordefval}[1]{%
  \let\currentsyntax\@empty
  \def\settingstitle{\icon{valuesetting}}%
  \def\initordefval{}%
  \glsxtrifhasfield*{alias}{#1}%
  {%
    \edef\initordefval{\summarytagfmt{alias}%
      \noexpand\aliasref{\expandonce\glscurrentfieldvalue}%
      \noexpand\global\noexpand\let\noexpand\do@alias\noexpand\@secondoftwo
    }%
  }%
  {}%
  \glsxtrifhasfield*{syntax}{#1}%
  {%
    \let\currentsyntax\glscurrentfieldvalue
    \glsxtrifhasfield*{defaultvalue}{#1}%
    {%
      \ifdefempty\initordefval{}{\appto\initordefval{; }}%
      \eappto\initordefval{\summarytagfmt{default}%
        \noexpand\optfmt{\expandonce\glscurrentfieldvalue}}%
    }%
    {}%
    \glsxtrifhasfield*{initvalue}{#1}%
    {%
      \ifdefempty\initordefval{}{\appto\initordefval{; }}%
      \eappto\initordefval{\summarytagfmt{initial}% 
        \noexpand\optfmt{\expandonce\glscurrentfieldvalue\relax}}%
      \ifx\currentsyntax\metaboolean
        \ifdefstring\glscurrentfieldvalue{true}
        {%
          \def\settingstitle{\icon{toggleonsetting}}%
        }%
        {%
          \ifdefstring\glscurrentfieldvalue{false}
          {%
             \def\settingstitle{\icon{toggleoffsetting}}%
          }%
          {}%
        }%
      \fi
    }%
    {%
      %\ifdefempty\initordefval{}{\appto\initordefval{; }}%
      %\appto\initordefval{\textit{initial:} none}%
    }%
  }%
  {\def\settingstitle{\icon{novaluesetting}}}%
}

\newcommand*{\ctrdefbookmarklevel}{\cmddefbookmarklevel}

\newrobustcmd*{\ctrdef}{\@ifstar\s@ctrdef\@ctrdef}

\newcommand*{\@ctrdef}[1]{%
 \let\ctrdefbookmarklevel\cmddefbookmarklevel
 \pdfbookmark[\ctrdefbookmarklevel]{#1}{ctrdef.#1}%
 \nopagebreak\s@ctrdef{#1}%
}

\newcommand*{\s@ctrdef}[1]{%
  \def\settingstitle{\icon{counter}}%
  \ifnotdefaultstatus{ctr.#1}%
  {\appto\settingstitle{\statussym}\def\postnote{\statustext}}%
  {}%
  \begin{pinnedbox}[title=\settingstitle]%
   \def\ctrfmt##1{\textbf{\texttt{##1}}}%
   \mainglsadd{ctr.#1}{ctrdef}\glsxtrglossentry{ctr.#1}%
   \glsxtrifhasfield*{note}{ctr.#1}%
   {%
     \ifx\cmdnotefmt\@gobble
       \ifdefempty\postnote{}{\preto\postnote{\hfill}}%
     \else
       \par\hfill\cmdnotefmt\glscurrentfieldvalue
       \ifdefempty\postnote{}{\preto\postnote{\space}}%
     \fi
   }%
   {\ifdefempty\postnote{}{\preto\postnote{\hfill}}}%
   \postnote
  \end{pinnedbox}%
  \noindent\ignorespaces
}

% Defining .bib entries

\newwrite\nlctuserguidebib

\newcommand{\glsbibwriteentry}[3]{%
 {%
   \edef\dhyphen{\string-}\let\-\empty\let\dsb\empty
   \def\dslash{/}%
   \edef\dcolon{\string:}% v1.16
   \protected@edef\entrylabel{#2}%
   \let\dhyphen\empty\let\dsb\dunderscore
   \def\dslash{\slash}%
   \def\dcolon{\protect\dcolon}%
   \immediate\write\nlctuserguidebib{@#1{\entrylabel#3}}%
 }%
}

\newcommand{\glsbibwritefield}[2]{,^^J#1={\detokenize{#2}}}

\glsaddstoragekey{modifiers}{}{\modifiers}
\glsaddstoragekey{variants}{}{\variants}
\glsaddstoragekey{base}{}{\fnbase}
\glsaddstoragekey{fnsuffix}{}{\fnsuffix}
\glsaddstoragekey{explsuffix}{}{\explsuffixfield}
\glsaddstoragekey{syntax}{}{\syntax}
\glsaddstoragekey{defaultvalue}{}{\optdefval}
\glsaddstoragekey{initvalue}{}{\optinitval}
\glsaddstoragekey{status}{default}{\entrystatus}
\glsaddstoragekey{note}{}{\note}
\glsaddstoragekey{providedby}{}{\providedbyinfo}
\glsaddstoragekey{pdftitlecasename}{}{\pdftitlecasename}
\glsaddstoragekey{extra}{}{\glsextra}

\glsaddstoragekey{defaultkeys}{}{\defaultkeys}

\renewcommand{\glslinkpresetkeys}{%
 \glsxtrifhasfield*{defaultkeys}{\glslabel}
 {\expandafter\setupglslink\expandafter{\glscurrentfieldvalue}}%
 {}%
}

\newcommand{\conditionsyntax}{ \meta{true}\csfmt{else} \meta{false}\csfmt{fi}}

\newrobustcmd{\@explboolsyntaxfmt}[1]{\underline{\emph{#1}}}

\newcommand{\explsuffix}{}
\newcommand{\explTFsuffix}{TF}
\newcommand{\TFsyntax}{\margm{true} \margm{false}}

\newrobustcmd{\initvalnotefmt}[1]{\textrm{\em #1}}

\newcommand{\nlctuserguidebibextrapreamble}{}

\newcommand*{\nlctuserguidegls}[2][]{%
 \bgroup
  \let\field\glsbibwritefield
  \def\common{\field{defaultkeys}{format=glsignore}}%
  \def\syntax{\glsbibwritefield{syntax}}%
  \def\parent{\glsbibwritefield{parent}}%
  \def\inpackage##1{\glsbibwritefield{parent}{pkg.##1}}%
  \def\inclass##1{\glsbibwritefield{parent}{cls.##1}}%
  \def\inapp##1{\glsbibwritefield{parent}{app.##1}}%
  \def\providedby{\glsbibwritefield{providedby}}%
  \def\name{\glsbibwritefield{name}}%
  \def\desc{\glsbibwritefield{description}}%
  \def\defval{\glsbibwritefield{defaultvalue}}%
  \def\defvalempty{\glsbibwritefield{defaultvalue}{\initvalnotefmt{empty}}}%
  \def\initval{\glsbibwritefield{initvalue}}%
  \def\initvalvaries{\glsbibwritefield{initvalue}{\initvalnotefmt{varies}}}%
  \def\initvalempty{\glsbibwritefield{initvalue}{\initvalnotefmt{empty}}}%
  \def\initvalcs##1{\glsbibwritefield{initvalue}{\initvalref{##1}}}%
  \def\initvalopt##1##2{\glsbibwritefield{initvalue}{\initvalopt{##1}{##2}}}%
  \def\note{\glsbibwritefield{note}}%
  \def\deprecated{\glsbibwritefield{status}{deprecated}}%
  \def\banned{\glsbibwritefield{status}{banned}}%
  \def\deprecatedbanned{\glsbibwritefield{status}{deprecatedbanned}}%
  \def\gpunc##1##2{\glsbibwriteentry{punctuation}{idx.##1}{##2}}%
  \def\gidx##1##2{\glsbibwriteentry{index}{idx.##1}{\field{name}{##1}##2}}%
  \def\gidxpl##1##2{\glsbibwriteentry{indexplural}{idx.##1}{\field{text}{##1}##2}}%
  \def\gfile##1##2{\glsbibwriteentry{file}{file.##1}{\field{name}{\filefmt{##1}}##2}}%
  \def\gfilemeta##1##2##3##4{\glsbibwriteentry{file}{file.##1##2##3}{\field{name}{\metafilefmt{##1}{##2}{##3}}##4}}%
  \def\gfilemetameta##1##2##3##4##5##6{\glsbibwriteentry{file}{file.##1##2##3##4##5}{\field{name}{\metametafilefmt{##1}{##2}{##3}{##4}{##5}}##6}}%
  \def\gext##1##2{\glsbibwriteentry{fileformat}{ext.##1}{\field{parent}{fileformat}\field{name}{\extfmt{##1}}##2}}%
  \def\gcmd##1##2{\glsbibwriteentry{command}{##1}{\field{name}{\csfmt{##1}}##2}}%
  \def\gcmdpunc##1##2##3{\glsbibwriteentry{command}{##1}{\field{name}{\cspuncfmt{##2}}##3}}%
  \def\gcond##1##2{\glsbibwriteentry{command}{##1}{\field{name}{\csfmt{##1}}\syntax{\conditionsyntax}##2}}%
  \def\gexplcond##1##2##3{\glsbibwriteentry{command}{##1:##2}{\field{name}{\csfmt{##1\explsuffix:##2\explTFsuffix}}##3}}%
  \def\gexplpred##1##2##3{\glsbibwriteentry{command}{##1:##2}{\field{name}{\csfmt{##1\explsuffix:##2\explTFsuffix}}\field{explsuffix}{\dsb p}##3}}%
  \def\gfn##1##2##3##4{\glsbibwriteentry{command}{##1}{\field{name}{\csfmt{##1:##2}}\field{variants}{##3}\field{fnsuffix}{##2}\field{base}{##1}##4}}%
  \def\gfnsuffix##1##2##3##4{\glsbibwriteentry{command}{##1:##2}{\field{name}{\csfmt{##1:##2}}\field{variants}{##3}\field{fnsuffix}{##2}\field{base}{##1}##4}}%
  \def\gcmdmeta##1##2##3##4{\glsbibwriteentry{command}{##1##2##3}{\field{name}{\csmetafmt{##1}{##2}{##3}}##4}}%
  \def\gcmdmetameta##1##2##3##4##5##6{\glsbibwriteentry{command}{##1##2##3##4##5}{\field{name}{\csmetametafmt{##1}{##2}{##3}{##4}{##5}}##6}}%
  \def\gmod##1##2{\glsbibwriteentry{punctuation}{idx.mod.##1}{##2}}%
  \def\gcmds##1##2{\glsbibwriteentry{command}{##1}{\field{name}{\csfmt{##1}}\field{modifiers}{*}##2}}%
  \def\gcmdsp##1##2{\glsbibwriteentry{command}{##1}{\field{name}{\csfmt{##1}}\field{modifiers}{*,+}##2}}%
  \def\gpunccmd##1##2##3{\glsbibwriteentry{punctuation}{##1}{\field{name}{\csfmt{##2}}##3}}%
  \def\gpkg##1##2{\glsbibwriteentry{package}{pkg.##1}{\field{name}{\styfmt{##1}}##2}}%
  \def\gmodule##1##2{\glsbibwriteentry{module}{pkg.##1}{\field{name}{\styfmt{##1}}##2}}%
  \def\gcls##1##2{\glsbibwriteentry{class}{cls.##1}{\field{name}{\clsfmt{##1}}##2}}%
  \def\genv##1##2{\glsbibwriteentry{environment}{env.##1}{\field{name}{\envfmt{##1}}##2}}%
  \def\gctr##1##2{\glsbibwriteentry{counter}{ctr.##1}{\field{name}{\ctrfmt{##1}}##2}}%
  \def\gopt##1##2{\glsbibwriteentry{option}{opt.##1}{\field{name}{\optfmt{##1}}##2}}%
  \def\gcsopt##1##2{\glsbibwriteentry{commandoption}{opt.##1}{\field{name}{\csoptfmt{##1}}##2}}%
  \def\gcsboolopt##1##2{\glsbibwriteentry{commandoption}{opt.##1}%
   {\field{name}{\csoptfmt{##1}}\syntax{\meta{boolean}}\defval{true}##2}}%
  \def\gstyopt##1##2{\glsbibwriteentry{packageoption}{opt.##1}{\field{name}{\styoptfmt{##1}}##2}}%
  \def\gstyboolopt##1##2{\glsbibwriteentry{packageoption}{opt.##1}%
    {\field{name}{\styoptfmt{##1}}\syntax{\meta{boolean}}\defval{true}##2}}%
  \def\gclsopt##1##2{\glsbibwriteentry{classoption}{opt.##1}{\field{name}{\clsoptfmt{##1}}##2}}%
  \def\gclsboolopt##1##2{\glsbibwriteentry{classoption}{opt.##1}%
   {\field{name}{\clsoptfmt{##1}}\syntax{\meta{boolean}}\defval{true}##2}}%
  \def\goptval##1##2##3{\glsbibwriteentry{optionvalue}{optval.##1.##2}{\field{name}{\optfmt{##2}}\field{parent}{opt.##1}##3}}%
  \def\goptmetaval##1##2##3{\glsbibwriteentry{optionvalue}{optval.##1.##2}{\field{name}{\meta{##2}}\field{parent}{opt.##1}##3}}%
  \def\gapp##1##2{\glsbibwriteentry{application}{app.##1}{\field{name}{\appfmt{##1}}##2}}%
  \def\glongswitch##1##2{\glsbibwriteentry{switch}{switch.##1}{\field{name}{\longargfmt{##1}}##2}}%
  \def\gshortswitch##1##2{\glsbibwriteentry{switch}{switch.##1}{\field{name}{\shortargfmt{##1}}##2}}%
  \def\glongswitchpunc##1##2{\glsbibwriteentry{switchpunctuation}{switch.##1}{\field{name}{\longargfmt{##1}}##2}}%
  \def\gshortswitchpunc##1##2{\glsbibwriteentry{switchpunctuation}{switch.##1}{\field{name}{\shortargfmt{##1}}##2}}%
  \def\gterm{\glsbibwriteentry{term}}%
  \def\gtermabbr##1##2##3##4{\glsbibwriteentry{termabbreviation}%
   {##1}{\field{short}{##2}\field{long}{##3}##4}}%
  \def\gtermacr##1##2##3##4{\glsbibwriteentry{termacronym}%
   {##1}{\field{short}{##2}\field{long}{##3}##4}}%
  \def\gabbr##1##2##3##4{\glsbibwriteentry{dualindexabbreviation}%
   {##1}{\field{short}{##2}\field{long}{##3}##4}}%
  \def\gacr##1##2##3##4{\glsbibwriteentry{acronym}%
   {##1}{\field{short}{##2}\field{long}{##3}##4}}%
  \immediate\openout\nlctuserguidebib=\jobname-gls.bib\relax
  \immediate\write\nlctuserguidebib{\glspercentchar\space Encoding: UTF-8}
  \immediate\write\nlctuserguidebib{@preamble{"\string\providecommand*{\string\csfmt}[1]{\string\glsbackslash\string\glsbackslash\glshashchar1}^^J
    \string\providecommand*{\string\cspuncfmt}[1]{\string\glsbackslash\glshashchar1}^^J
    \string\providecommand{\string\dhyphen}{-}^^J
    \string\providecommand{\string\dslash}{/}^^J
    \string\providecommand{\string\longargfmt}{--}^^J
    \string\providecommand{\string\shortargfmt}{-}^^J
    \nlctuserguidebibextrapreamble"}}
  \immediate\write\nlctuserguidebib{\symboldefinitions}
  \glsbibwriteentry{indexplural}{fileformat}{\glsbibwritefield{text}{file format}}
  #2%
  \immediate\closeout\nlctuserguidebib 
 \egroup
 \nlctuserguideloadgls{#1}%
}

\glsdefpostdesc{dualindexabbreviation}{.}

% Abbreviations with a description:
\setabbreviationstyle[termabbreviation]{long-short-desc}
% Common abbreviations (no full form on first use) with a description:
\setabbreviationstyle[termacronym]{short-nolong-desc}

\renewcommand{\glsxtrshortdescname}{%
  \protect\glslongfont{\the\glslongtok}%
  \protect\glsxtrfullsep{\the\glslabeltok}%
  \protect\glsxtrparen{\protect\glsabbrvfont{\the\glsshorttok}}%
}

\newcommand{\nlctuserguidecustomentryaliases}{}

\newcommand{\nlctuserguideignoredpuncrules}{%
 \glshex 00AD\string;% soft hyphen
 \glshex 2010\string;% hyphen
 \glshex 2011\string;% non-breaking hyphen
 \glshex 2012\string;% figure dash
 \glshex 2013\string;% en dash
 \glshex 2014\string;% em dash
 \glshex 2015\string;% horizontal bar
 \glshex 2212\string=\glshex 207B\string=\glshex 208B% minus sign
 \string;\string'\glshex 005C\string'% backslash
}

% ASCII hyphen in non-ignored subset:

\newcommand{\nlctuserguidepuncrules}{%
 \glsxtrgeneralpuncmarksrules
 \string<\glsxtrgeneralpuncaccentsrules
 \string<\glsxtrgeneralpuncquoterules
 \string<\glsxtrgeneralpuncbracketrules
 \string<\glshex 00A7% section sign
 \string<\glshex 00B6% pilcrow sign
 \string<\glshex 00A9% copyright sign
 \string<\glshex 00AE% registered sign
 \string<\glsxtrcurrencyrules
 \string< \string'\glshex 002A\string'% asterisk
 \string<\string'\glshex 0026\string'% ampersand
 \string<\string'\glshex 0023\string'% hash sign
 \string<\string'\glshex 0025\string'% percent sign
 \string<\string'\string-\string'% ASCII hyphen
 \string<\string'\glshex 002B\string'% plus sign
  \string=\glshex 207A\string=\glshex 208A% super/subscript plus sign
 \string<\glshex 00B1% plus-minus sign
 \string<\glshex 00F7% division sign
 \string<\glshex 00D7% multiplication sign
 \string<\string'\glshex 003C\string'% less-than sign
 \string<\string'\glshex 003D\string'% equals sign
 \string<\string'\glshex 003E\string'% greater-than sign
 \string<\glshex 00AC% not sign
 \string<\string'\glshex 007C\string'% vertical bar (pipe)
 \string<\glshex 00A6% broken bar 
 \string<\glshex 00B0% degree sign
 \string<\glshex 00B5% micron sign
}
\newcommand{\nlctuserguidepreletterrules}{\string<\string'\glshex 0040\string'}
\newcommand{\nlctuserguideletterrules}{\glsxtrGeneralLatinIrules}
\newcommand{\nlctuserguideextrarules}{\string< \glsxtrMathItalicGreekIrules}

\renewcommand*{\glsxtrresourceinit}{\GlsXtrResourceInitEscSequences}

\BibGlsOptions{shift-zero-sections}% v1.16 (requires bib2gls v4.7+)

\newcommand{\nlctuserguideloadgls}[1]{%
  \GlsXtrLoadResources[src=\jobname-gls,
   break-at-not-match={original entrytype=(switchpunctuation|punctuation|command)},
   sort={custom},
   sort-rule={\glsxtrIgnorableRules
   ;\glsxtrcombiningdiacriticrules
   ;\nlctuserguideignoredpuncrules
   \string< \nlctuserguidepuncrules 
   \string< \glshex 2423 % visible space
   \string< \glsxtrdigitrules 
   \string< \glsxtrfractionrules
   \nlctuserguidepreletterrules
   \string< \nlctuserguideletterrules
   \nlctuserguideextrarules},
   selection={recorded and deps and see not also},
   entry-type-aliases={
     commandoption=index,
     packageoption=index,
     classoption=index,
     term=dualindexentry,
     termabbreviation=dualindexabbreviation,
     termacronym=dualindexabbreviation,
     fileformat=index,
     file=index,
     command=index,
     package=index,
     module=index,
     class=index,
     environment=index,
     counter=index,
     option=index,
     optionvalue=index,
     application=index,
     switch=index,
     punctuation=symbol,
     switchpunctuation=symbol,
     icon=symbol,
     \nlctuserguidecustomentryaliases
   },
   assign-fields=
    {
      sort = name + "¯" + extra ,
      pdftitlecasename = \INTERPRET { \FIRSTUC { name } }
        [ entrytype->original =/term|index/ ] ,
      pdftitlecasename = name  
    },
   category={same as original entry},
   dual-category={same as primary},
   combine-dual-locations={primary},
   type=index,dual-type=main,
   dual-field,
   primary-location-formats=mainfmt,
   save-primary-locations=retain,
   primary-loc-counters=match,
   save-loclist=false,
   post-description-dot=check,
   description-case-change=firstuc,
   loc-counters={chapter,section,subsection,subsubsection,page,figure,table,wrglossary},
   save-child-count,save-root-ancestor,
   symbol-sort-fallback=name,
   not-match={original entrytype=(icon|nonindexed)},
   labelify-replace={{\string\\-}{}},
   labelify={alias},
   #1
  ]%
  \GlsXtrLoadResources[src=\jobname-gls,
   entry-type-aliases={icon=symbol},
   unknown-entry-alias={index},
   match={original entrytype=icon},
   description-case-change=firstuc,
   post-description-dot=check,
   save-locations=false,
   type=symbols,
   symbol-sort-fallback=name]
}

% Glossaries, index, summaries etc

\newcommand{\statusdeprecatedsym}{\icon{deprecated}}
\newcommand{\statusdeprecatedtext}{\icontext{deprecated}}
\newcommand{\statusbannedsym}{\icon{banned}}
\newcommand{\statusbannedtext}{\icontext{banned}}
\newcommand{\statusdeprecatedbannedsym}{\statusdeprecatedsym\statusbannedsym}
\newcommand{\statusdeprecatedbannedtext}{\statusdeprecatedtext\ \statusbannedtext}
\newcommand{\statusdefaultsym}{}
\newcommand{\statusdefaulttext}{}
\newcommand{\statussym}{}
\newcommand{\statustext}{}

\newcommand{\ifnotdefaultstatus}[3]{%
 \protected@edef\currentstatus{\entrystatus{#1}}%
 \letcs\statussym{status\currentstatus sym}%
 \letcs\statustext{status\currentstatus text}%
 \ifglsentryexists{#1}%
 {\ifdefstring\currentstatus{default}{#3}{#2}}%
 {#3}%
}

\newcommand*{\statushook}[1]{\ifnotdefaultstatus{#1}{~\statussym}{}}

\newcommand*{\setwidestnamehook}[1]{%
 \ifglshasparent{#1}{}%
 {%
   \settowidth{\dimen@}{\glstreenamefmt{\glsentryname{#1}\quad}}%
   \ifdim\dimen@>\gls@tmplen
     \gls@tmplen=\dimen@
     \eglssetwidest{\glsentryname{#1}\quad}%
   \fi
 }%
 \advance\totalterms by 1\relax
}

\newcommand*{\settermshook}[1]{%
 \advance\totalterms by 1\relax
 \typeout{Preprocessing term `#1' (\number\totalterms)}%
 \eglsupdatewidest{\glsentryname{#1}}%
}

\newcommand*{\printabbrs}[1][]{%
 \glsxtrifemptyglossary{abbreviations}{}%
 {%
   \typeout{Printing abbreviations}%
   \printunsrtglossary*
   [type=abbreviations,style=alttree,title=\abbreviationsname,label=abbreviations,nonumberlist,#1]%
   {%
     \gls@tmplen=0pt\relax
     \totalterms=0\relax
     \glssetwidest{}%
     \let\printunsrtglossaryentryprocesshook\settermshook
     \def\printunsrtglossarypredoglossary{\entrycountprehook\totalterms}%
     \let\glsextrapostnamehook\glsaddterm
   }%
 }%
}

\NewDocumentCommand \printicons { O{} }
{%
 \typeout{Printing icons}%
 \printunsrtglossary[type=symbols,style=long-sym-desc,groups=false,label=symbols,#1]%
}

\newcount\totalterms

\newcommand{\termslocfmt}[1]{\hyperit{#1}}
\newcommand{\glsaddterm}[1]{\typeout{Adding Term `#1'}\glsadd[format=termslocfmt]{#1}}

\newcommand*{\printterms}[1][]{%
 \ifglossaryexists{abbreviations}{\printabbrs}{}%
 \glsxtrifemptyglossary{symbols}{}{\printicons}%
 \printmain[#1]%
}
% v1.14 added \printmain
\newcommand*{\printmain}[1][]{%
 \glsxtrifemptyglossary{main}{}%
 {
   \typeout{Printing main}%
   \printunsrtglossary*[type=main,style=topic,nonumberlist,label=glossary,#1]%
   {%
     \gls@tmplen=0pt\relax
     \totalterms=0\relax
     \glssetwidest{}%
     \let\printunsrtglossaryentryprocesshook\settermshook
     \def\printunsrtglossarypredoglossary{\entrycountprehook\totalterms}%
     \glssetcategoryattribute{term}{glossname}{firstuc}%
     \glssetcategoryattribute{termabbreviation}{glossname}{firstuc}%
     \let\glstopicMarker\glsaddterm
   }%
 }%
}

%\newcommand{\bibglsprimary}[2]{%
 %\ifcase #1\or p.~\else pp.~\fi
 %#2%
%}

\newcommand{\seclocfmt}[2]{#1}

\newcommand{\glsxtrchapterlocfmt}{\seclocfmt}
\newcommand{\glsxtrsectionlocfmt}{\seclocfmt}
\newcommand{\glsxtrsubsectionlocfmt}{\seclocfmt}
\newcommand{\glsxtrsubsubsectionlocfmt}{\seclocfmt}
\newcommand{\glsxtrparagraphlocfmt}{\seclocfmt}
\newcommand{\glsxtrsubparagraphlocfmt}{\seclocfmt}

\newcommand{\glsxtrtablelocfmt}{\seclocfmt}
\newcommand{\glsxtrfigurelocfmt}{\seclocfmt}

\newcommand*{\locationgroupmarkerchapter}{\S}
\newcommand*{\locationgroupmarkersection}{\S}
\newcommand*{\locationgroupmarkersubsection}{\S}
\newcommand*{\locationgroupmarkersubsubsection}{\S}
\newcommand*{\locationgroupmarkerparagraph}{\S}
\newcommand*{\locationgroupmarkersubparagraph}{\S}

\newcommand*{\locationgroupmarkertable}{\Tablerefprefix}
\newcommand*{\locationgroupmarkertables}{\Tablesrefprefix}
\newcommand*{\locationgroupmarkerfigure}{\Figurerefprefix}
\newcommand*{\locationgroupmarkerfigures}{\Figuresrefprefix}

\newcommand*{\locationgroupmarkerpage}{p.~}
\newcommand*{\locationgroupmarkerpages}{pp.~}

\newcommand{\bibglslocationgroupsep}{; }

\newcommand{\locationgroupencapchapter}[1]{\textcolor{teal}{\bfseries#1}}
\newcommand{\locationgroupencapsection}{\locationgroupencapchapter}
\newcommand{\locationgroupencapsubsection}{\locationgroupencapchapter}
\newcommand{\locationgroupencapsubsubsection}{\locationgroupencapchapter}
\newcommand{\locationgroupencapparagraph}{\locationgroupencapchapter}
\newcommand{\locationgroupencapsubparagraph}{\locationgroupencapchapter}

\newcommand{\bibglslocationgroup}[3]{%
  \csuse{locationgroupencap#2}% 
  {%
    \ifcsdef{locationgroupmarker#2}%
    {\ifcase#1
     \or
       \csuse{locationgroupmarker#2}% 
     \else
       \ifcsdef{locationgroupmarker#2s}%
       {\csuse{locationgroupmarker#2s}}%
       {%
         \csuse{locationgroupmarker#2}% 
         \csuse{locationgroupmarker#2}% 
       }%
     \fi
    }%
    {}%
    #3%
  }%
}

\newcommand{\summaryentrypackagebookmark}[2]{%
 \expandafter\pdfbookmark\expandafter[#1]{\glsentryname{#2}}{summary.#2}%
}

\newcommand{\summaryentryclassbookmark}[2]{%
 \expandafter\pdfbookmark\expandafter[#1]{\glsentryname{#2}}{summary.#2}%
}

\newcommand{\summaryentrypackage}[1]{%
  \let\styfmt\texttt
  \csfmt{usepackage}%
  \glsxtrifhasfield{syntax}{#1}{[\glscurrentfieldvalue]}{}%
  \marg{\textbf{\linkedentryname{#1}}}%
}

\newcommand{\summaryentryclass}[1]{%
  \let\clsfmt\texttt
  \csfmt{documentclass}%
  \glsxtrifhasfield{syntax}{#1}{[\glscurrentfieldvalue]}{}%
  \marg{\textbf{\linkedentryname{#1}}}
}

\newcommand{\summaryentryenvironment}[1]{%
  \let\envfmt\texttt
  \csfmt{begin}\marg{\textbf{\linkedentryname{#1}}}%
  \syntax{#1}%
  \gathermodifiers{#1}%
  \ifdefempty\nlctmodifierlist{}
  {%
    \summarytagfill\summarytagfmt{\nlctmodifiertag}\nlctmodifierlist
    \gdef\summaryentry@post@fill{\quad }%
  }%
}

\newcommand{\summaryentrycommand}[1]{%
 \bgroup
  \def\explTFsuffix{\@explboolsyntaxfmt{TF}}%
  \textbf{\linkedentryname{#1}}%
  \syntax{#1}%
  \glsxtrifhasfield{initvalue}{#1}%
  {%
    \summarytagfill\summarytagfmt{initial}\glscurrentfieldvalue
    \gdef\summaryentry@post@fill{\quad }%
  }%
  {%
    \gathermodifiers{#1}%
    \ifdefempty\nlctmodifierlist
    {%
      \gathervariants{#1}%
      \ifdefempty\nlctvariantlist
      {}%
      {%
        \summarytagfill\summarytagfmt{\nlctvarianttag}\nlctvariantlist
        \gdef\summaryentry@post@fill{\quad }%
      }%
    }%
    {%
      \summarytagfill\summarytagfmt{\nlctmodifiertag}\nlctmodifierlist
      \gdef\summaryentry@post@fill{\quad }%
    }%
  }%
  \glsxtrifhasfield{explsuffix}{#1}%
  {%
    \let\explsuffix\glscurrentfieldvalue
    \let\explTFsuffix\relax
    \let\TFsyntax\relax
    \par\glossentryname{#1}%
    \syntax{#1}%
  }%
  {}%
 \egroup
}

\newcommand{\summaryentrypackageoption}{\summaryentryoption}
\newcommand{\summaryentryclassoption}{\summaryentryoption}
\newcommand{\summaryentrycommandoption}{\summaryentryoption}
\newcommand{\summaryentryenvironmentoption}{\summaryentryoption}

\newcommand{\genericsummaryentryoption}[2][]{%
  \getinitordefval{#2}%
  \def\optiontag{#1}%
  \textbf{\linkedentryname{#2}}%
  \ifdefempty\currentsyntax{}{\dequals\currentsyntax}%
  \summarytagfill
  \textrm{\ifdefempty\initordefval{}{\initordefval}%
   \ifdefempty\optiontag{}{ \optiontag}}%
  \gdef\summaryentry@post@fill{ }%
  \let\do@alias\@secondoftwo
}

\newcommand{\summaryentryoption}[1]{%
  \getinitordefval{#1}%
  \textbf{\linkedentryname{#1}}%
  \ifdefempty\currentsyntax{}{\dequals\currentsyntax}%
  \summarytagfill
  \textrm{\ifdefempty\initordefval{}{\initordefval}%
   \ifdefempty\settingstitle{}{ \settingstitle}}%
  \gdef\summaryentry@post@fill{ }%
}

\newcommand{\summaryentryoptionvalue}[1]{%
  \glsxtrifhasfield{parent}{#1}{\glsentrytext{\glscurrentfieldvalue}\dequals}{}%
  \textbf{\linkedentryname{#1}}%
}

\newcommand{\summarylocfmt}[1]{\hyperit{#1}}
\newcommand{\summarysubitemindent}{3em}
\newcommand{\providedbyfmt}[1]{\textsf{\footnotesize \mbox{#1}}}

\newif\ifshowsummarytopgroupheaders
\showsummarytopgroupheaderstrue

\newif\ifshowsummarysubgroupheaders
\showsummarysubgroupheaderstrue

\newcommand*{\summarynotefmt}[1]{{\small(#1)}}

\newcommand{\summaryentryskip}{\par\bigskip\par}

\newcommand{\summarypredesc}{%
 \nopagebreak\summarypar\nopagebreak
}

\newcommand{\rootsummarypar}{\par}
\newcommand{\childsummarypar}{\par}

\newglossarystyle{summary}
{%
  \renewenvironment{theglossary}%
  {%
   \setlength{\parindent}{0pt}%
   \setlength{\parskip}{0pt plus 0.3pt}%
   \raggedbottom
   \def\entryskip{\def\entryskip{\summaryentryskip}}%
   \ifdefstring{\@@glossarysec}{chapter}%
   {%
     \hypersetup{bookmarksdepth=2}%
     \ifnum\c@secnumdepth>0\relax
      \setcounter{secnumdepth}{0}%
     \fi
     \ifnum\c@tocdepth>0\relax
      \setcounter{tocdepth}{0}%
     \fi
     \def\summarysec{\section}%
     \def\summarysecnumdepth{0}%
     \ifshowsummarytopgroupheaders
       \def\summarysubsec{\subsection}%
       \def\summarysubsecnumdepth{1}%
     \else
       \def\summarysubsec{\section}%
       \def\summarysubsecnumdepth{0}%
     \fi
   }%
   {%
     \hypersetup{bookmarksdepth=3}%
     \ifnum\c@secnumdepth>1\relax
       \setcounter{secnumdepth}{1}%
     \fi
     \ifnum\c@tocdepth>1\relax
       \setcounter{tocdepth}{1}%
     \fi
     \def\summarysec{\subsection}%
     \def\summarysecnumdepth{1}%
     \ifshowsummarytopgroupheaders
       \def\summarysubsec{\subsubsection}%
       \def\summarysubsecnumdepth{2}%
     \else
       \def\summarysubsec{\subsection}%
       \def\summarysubsecnumdepth{1}%
     \fi
   }%
   \let\summary@hasgroupheading\@secondoftwo
   \let\summary@hassubgroupheading\@secondoftwo
  }%
  {\par}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupheading}[1]{%
    \ifshowsummarytopgroupheaders
      \glsxtrgetgrouptitle{##1}{\glsxtr@grptitle}%
      \summarysec[\texorpdfstring{\glossarytoctitle: \glsxtr@grptitle}{\glsxtr@grptitle}]{\glsxtr@grptitle}%
      \label{summary.##1}%
      \def\entryskip{\def\entryskip{\summaryentryskip}}%
      \let\summary@hasgroupheading\@firstoftwo
    \else
      \let\summary@hasgroupheading\@secondoftwo
    \fi
  }%
  \renewcommand*{\glssubgroupheading}[4]{%
    \let\summary@hassubgroupheading\@secondoftwo
    \ifshowsummarysubgroupheaders
      \ifnum##2=1\relax
        \glsxtrgetgrouptitle{##4}{\glsxtr@grptitle}%
        \summarysubsec[\texorpdfstring{\glossarytoctitle: \glsxtr@grptitle}{\glsxtr@grptitle}]{\glsxtr@grptitle}%
        \def\entryskip{\def\entryskip{\summaryentryskip}}%
        \let\summary@hassubgroupheading\@firstoftwo
      \fi
    \fi
  }%
  \renewcommand*{\glossentry}[2]{\subglossentry{0}{##1}{##2}}%
  \renewcommand{\subglossentry}[3]{%
    \def\initordefval{}%
    \edef\@this@category{\glscategory{##2}}%
    \entryskip
    \par\allowbreak
    \def\summaryentry@post@fill{\hfill}%
    \ifnum##1=0\relax
      \ifcsdef{summaryentry\@this@category bookmark}%
      {%
        \summary@hasgroupheading
        {\edef\@summary@bookmarklevel{\the\numexpr\summarysecnumdepth+2}}%
        {\edef\@summary@bookmarklevel{\the\numexpr\summarysecnumdepth+1}}%
        \csuse{summaryentry\@this@category bookmark}{\@summary@bookmarklevel}{##2}%
      }%
      {}%
    \else
    \ifnum##1=1\relax
        \ifcsdef{summaryentry\@this@category bookmark}%
        {%
          \summary@hassubgroupheading
          {\edef\@summary@bookmarklevel{\the\numexpr\summarysubsecnumdepth+2}}%
          {\edef\@summary@bookmarklevel{\the\numexpr\summarysubsecnumdepth+1}}%
          \csuse{summaryentry\@this@category bookmark}{\@summary@bookmarklevel}{##2}%
        }%
        {}%
      \fi
    \fi
    \def\summarypar{\rootsummarypar}%
    \ifnum##1=0\relax
     \ifstrempty{##3}%
     {\let\summary@do@loc\@empty}%
     {\edef\summary@do@loc{\noexpand\makebox[0pt][l]{\noexpand\rule{\the\textwidth}{0pt}\unexpanded{\summaryloc{##3}}}}}%
     \begin{defnbox}\summary@do@loc
      \glsadd[format=summarylocfmt]{##2}%
      \ifnotdefaultstatus{##2}{\statussym~}{}%
      \texttt
      {%
        \ifcsdef{summaryentry\@this@category}
        {%
          \csuse{summaryentry\@this@category}{##2}%
        }%
        {%
          \textbf{\linkedentryname{##2}}%
          \syntax{##2}%
        }%
      }%
      \glsxtrifhasfield*{providedby}{##2}%
      {\summaryentry@post@fill\providedbyfmt{\glscurrentfieldvalue}%
       \def\summaryentry@post@fill{\linebreak[1]\hfill}%
      }%
      {}%
      \glsxtrifhasfield{note}{##2}%
      {\summaryentry@post@fill\summarynotefmt\glscurrentfieldvalue}{}%
     \end{defnbox}%
    \else
      \ifnum##1>1\relax
        \hangindent\summarysubitemindent\relax
        \parindent\summarysubitemindent\relax
        \def\summarypar{\childsummarypar\hangindent\summarysubitemindent\relax
          \parindent\summarysubitemindent\relax}%
      \fi
      \glsadd[format=summarylocfmt]{##2}%
      \glsxtrifhasfield*{alias}{##2}%
      {\let\do@alias\@firstoftwo
       \let\aliasval\glscurrentfieldvalue
      }%
      {\let\do@alias\@secondoftwo}%
      \texttt
      {%
        \ifcsdef{summaryentry\@this@category}
        {%
          \csuse{summaryentry\@this@category}{##2}%
        }%
        {%
          \textbf{\linkedentryname{##2}}%
          \syntax{##2}%
        }%
      }%
      \ifstrempty{##3}{}{\summarymarginpar{\summaryloc{##3}}}%
      \do@alias
      {%
        \summaryentry@post@fill
        \summarytagfmt{alias}%
        \expandafter\aliasref\expandafter{\aliasval}%
        \let\summaryentry@post@fill\space
      }%
      {}%
      \ifnotdefaultstatus{##2}%
      {\summaryentry@post@fill
        \glsxtrifhasfield{useri}{##2}{\glscurrentfieldvalue~}{}\statussym
        \glsxtrifhasfield*{providedby}{##2}%
        {\space\providedbyfmt{\glscurrentfieldvalue}}{}%
      }%
      {%
        \glsxtrifhasfield{useri}{##2}%
        {\summaryentry@post@fill\glscurrentfieldvalue}{}%
        \glsxtrifhasfield*{providedby}{##2}%
        {\space\providedbyfmt{\glscurrentfieldvalue}}{}%
      }%
      \glsxtrifhasfield{note}{##2}{\summarypar\hfill\summarynotefmt\glscurrentfieldvalue}{}%
    \fi
    \summarypredesc
    \glossentrydesc{##2}\glspostdescription
    \ifstrempty{##3}{}{\space\summaryregularloc{##3}}%
    \par
    \hangindent0pt\parindent0pt\relax
  }%
  \renewcommand*{\glsgroupskip}{}%
}

\newcount\totalcmds
\newcount\totalenvs
\newcount\totalpkgopts
\newcount\totalclsopts

\newcommand*{\summaryhook}[1]{%
 \def\summaryhookdoskip{\printunsrtglossaryskipentry}%
 \glsifcategory{#1}{command}%
 {\ifglshasdesc{#1}{\advance\totalcmds by 1\relax\let\summaryhookdoskip\relax}{}}%
 {%
   \glsifcategory{#1}{environment}%
   {%
     \ifglshasdesc{#1}%
     {\global\advance\totalenvs by 1\glsxtrcopytoglossary*{#1}{envlist}}%
     {}%
   }%
   {%
     \glsifcategory{#1}{packageoption}%
     {%
       \ifglshasdesc{#1}%
       {%
         \global\advance\totalpkgopts by 1\relax
         \glsxtrifhasfield{parent}{#1}%
         {%
           \expandafter\GlsXtrIfInGlossary\expandafter
             {\glscurrentfieldvalue}{pkgoptlist}{}%
           {%
             \glsxtrcopytoglossary*{\glscurrentfieldvalue}{pkgoptlist}%
           }%
         }%
         {}%
         \glsxtrcopytoglossary*{#1}{pkgoptlist}%
       }%
       {}%
     }%
     {%
       \glsifcategory{#1}{classoption}%
       {%
         \ifglshasdesc{#1}%
         {%
           \global\advance\totalclsopts by 1\relax
           \glsxtrifhasfield{parent}{#1}%
           {%
             \expandafter\GlsXtrIfInGlossary\expandafter
               {\glscurrentfieldvalue}{clsoptlist}{}%
             {\glsxtrcopytoglossary*{\glscurrentfieldvalue}{clsoptlist}}%
           }%
           {}%
           \glsxtrcopytoglossary*{#1}{clsoptlist}%
         }%
         {}%
       }%
       {%
         \glsifcategory{#1}{optionvalue}%
         {%
           \glsxtrifhasfield{parent}{#1}%
           {%
             \let\@currentparent\glscurrentfieldvalue
             \expandafter\GlsXtrIfInGlossary\expandafter
               {\@currentparent}{clsoptlist}%
             {\glsxtrcopytoglossary*{#1}{clsoptlist}}%
             {%
               \expandafter\GlsXtrIfInGlossary\expandafter
                 {\@currentparent}{pkgoptlist}%
               {\glsxtrcopytoglossary*{#1}{pkgoptlist}}%
               {%
                 \expandafter\GlsXtrIfInGlossary\expandafter
                   {\@currentparent}{envlist}%
                 {\glsxtrcopytoglossary*{#1}{envlist}}%
                 {%
                   \glsifcategory{\@currentparent}{command}%
                   {\ifglshasdesc{#1}{\let\summaryhookdoskip\relax}{}}{}%
                 }%
               }%
             }%
           }%
           {}%
         }%
         {}%
       }%
     }%
   }%
 }%
 \summaryhookdoskip
}

\newcommand{\entrycountprehook}[1]{%
  \ifnum#1<21\relax
    \let\glsgroupheading\@gobble
    \glsnogroupskiptrue
  \fi
}

\provideignoredglossary{envlist}%
\provideignoredglossary{pkgoptlist}%
\provideignoredglossary{clsoptlist}%

\newcommand*{\printcmdenvsummary}{% new v1.15
  % Command list
  \printunsrtglossary*[type=index,style=summary,title=Command Summary,
   label={cmdsummary}]%
  {%
    \renewcommand{\GlsXtrLocationField}{primarylocations}%
    \let\printunsrtglossaryentryprocesshook\summaryhook
    \def\printunsrtglossarypredoglossary{\entrycountprehook\totalcmds}%
  }%
  % Environment list
   \glsxtrifemptyglossary{envlist}{}%
   {%
     \printunsrtglossary*
      [type=envlist,style=summary,title=Environment Summary,
      label={envsummary}]
      {%
        \let\printunsrtglossaryentryprocesshook\@gobble
        \def\printunsrtglossarypredoglossary{\entrycountprehook\totalenvs}%
      }%
  }%
}

\newcommand*{\printclsstysummary}{% new v1.15
   % Class option list
   \glsxtrifemptyglossary{clsoptlist}{}%
   {%
     \printunsrtglossary*[type=clsoptlist,style=summary,title=Class Option Summary,
      label={clsoptsummary}]%
     {%
       \def\printunsrtglossarypredoglossary{\entrycountprehook\totalclsopts}%
       \showsummarytopgroupheadersfalse
     }%
   }%
   % Package option list
   \glsxtrifemptyglossary{pkgoptlist}{}%
   {%
     \printunsrtglossary*
       [type=pkgoptlist,style=summary,title=Package Option Summary,
        label={styoptsummary}]%
     {%
       \def\printunsrtglossarypredoglossary{\entrycountprehook\totalpkgopts}%
       \showsummarytopgroupheadersfalse
     }%
   }%
}

\newcommand*{\printsummary}{%
 \printcmdenvsummary
 \printclsstysummary
}

\newcommand*{\printcommandoptionsprocesshook}[2]{%
  \ifdefstring#2{#1}%
  {}%
  {%
   \glsxtrifhasfield*{rootancestor}{#2}%
   {\ifdefstring\glscurrentfieldvalue{#1}{}{\printunsrtglossaryskipentry}}%
   {\printunsrtglossaryskipentry}%
  }%
}

\newcommand*{\printcommandoptions}[2][]{%
 \glsdoifexistsorwarn{#2}%
 {%
   \printunsrtglossary*[type=index,style=summary,nogroupskip,
     label={#2-options},
     title={\glsentryname{#2} Options},
     #1]%
   {%
     \renewcommand{\GlsXtrLocationField}{primarylocations}%
     \def\printunsrtglossaryentryprocesshook{\printcommandoptionsprocesshook{#2}}%
      \def\printunsrtglossarypredoglossary{\let\glsgroupheading\@gobble}%
   }%
 }%
}

\newcommand*{\printcommonoptionsprocesshook}[2]{%
 \glsxtrifhasfield*{rootancestor}{#2}%
 {\ifdefstring\glscurrentfieldvalue{#1}{}{\printunsrtglossaryskipentry}}%
 {\printunsrtglossaryskipentry}%
}

\newcommand*{\printcommonoptions}[2][]{%
 \glsdoifexistsorwarn{#2}%
 {%
   \printunsrtglossary*[type=index,style=summary,nogroupskip,
     label={#2-optionsummary},
     title={\texorpdfstring{\glsxtrfieldtitlecase{#2}{name}}{\pdftitlecasename{#2}} Summary},
     leveloffset={-1},#1]%
   {%
     \preto\glossarypreamble{\glsadd[format=summarylocfmt]{#2}\createtarget{#2}{\strut}}%
     \ifglshasdesc{#2}%
     {%
       \appto\glossarypreamble{%
         \def\glscurrententrylabel{#2}%
         \glossentrydesc{#2}\glspostdescription
         \glspar\medskip\glspar}%
     }{}%
     \renewcommand{\GlsXtrLocationField}{primarylocations}%
     \def\printunsrtglossaryentryprocesshook{\printcommonoptionsprocesshook{#2}}%
      \def\printunsrtglossarypredoglossary{\let\glsgroupheading\@gobble}%
   }%
 }%
}

\newcount\totalindexitems

\newcommand{\filteremptylocation}[1]{%
  \glsxtrifhasfield*{location}{#1}
  {\advance\totalindexitems by 1}% has location field
  {%
    \GlsXtrIfHasNonZeroChildCount*{#1}%
    {\advance\totalindexitems by 1}%
    {\printunsrtglossaryskipentry}%
  }%
}

\ExplSyntaxOn
\cs_if_exist:NT \glsxtrbookindexsubsubitem
{
 \renewcommand{\glsxtrbookindexsubsubitem}[1]{
  \glstreeitem \hspace* { \dim_eval:n { #10 pt + 10pt } }
 }
}
\ExplSyntaxOff

% v1.11:
\newcommand{\nlctindexfirstmark}{}
\newcommand{\nlctindexlastmark}{}
\newcommand\nlctprebookindex{}
\newcommand\nlctindexmarkfmt[1]{{\small#1}}

\newcommand*{\printuserguideindex}[1][]{%
 \printunsrtglossary*[label=index,type=index,target=false,title=\indexname,style=bookindex,#1]%
 {%
   \renewcommand{\nlctindexfirstmark}{%
     \nlctindexmarkfmt\glsxtrbookindexfirstmark}%
   \renewcommand{\nlctindexlastmark}{%
     \nlctindexmarkfmt\glsxtrbookindexlastmark}%
   \renewcommand\glsextrapostnamehook[1]{%
     \statushook{##1}%
     \glsxtrifhasfield{extra}{##1}{ (\glscurrentfieldvalue)}{}%
   }%
   \renewcommand*{\glsxtrbookindexprelocation}[1]{%
     \glsxtrifhasfield{location}{##1}%
     {\,\textcolor{lightgray}{\dotfill}\,}%
     {}%
   }%
   \renewcommand*\glsxtrbookindexname[1]{%
     \linkedentryname{##1}\nlctpostindexname{##1}}%
   \renewcommand*{\glsxtrbookindexsubname}[1]{\linkedentryname{##1}}%
   \let\printunsrtglossaryentryprocesshook\filteremptylocation
   \def\printunsrtglossarypredoglossary{%
    \nlctprebookindex
    \ifnum\totalindexitems<21\relax
     \renewcommand*{\glsxtrbookindexmulticolsenv}{multicols*}%
    \fi}%
  \nlctguideindexinitpostnamehooks
 }%
}

\newcommand{\nlctguideindexinitpostnamehooks}{%
  \glsdefpostname{environment}{ environment}%
  \glsdefpostname{package}{ package}%
  \glsdefpostname{class}{ class}%
  \glsdefpostname{counter}{ counter}%
  \glsdefpostname{acronym}{\acrpostnamehook}%
  \glsdefpostname{abbreviation}{\abbrpostnamehook}%
  \glsdefpostname{termabbreviation}{\abbrpostnamehook}%
  \glsdefpostname{dualindexabbreviation}{\abbrpostnamehook}%
}

\newcommand{\acrpostnamehook}{}

\newrobustcmd{\abbrpostnamehook}{%
 \ifglshaslong\glscurrententrylabel
 {\space (\glsfmtlong{\glscurrententrylabel})}
 {%
   \glsxtrifhasfield{\GlsXtrDualField}{\glscurrententrylabel}%
   {%
     \ifglshaslong\glscurrentfieldvalue
     {\space (\expandafter\glsfmtlong\expandafter{\glscurrentfieldvalue})}%
     {}%
   }%
   {}%
 }%
}

\endinput
