%!TEX root=template.tex

%% ----------------------------------------------------------------------------
%%  novathesis — glossary-xltabular.sty
%% ----------------------------------------------------------------------------
%%
%% Version 8.4.0 (2026-09-27)
%% Copyright (C) 2004-26 by João M. Lourenço <joao.lourenco@fct.unl.pt>
%% Departamento de Informática (www.di.fct.unl.pt)
%% Faculdade de Ciências e Tecnologia (www.fct.unl.pt)
%% Universidade NOVA de Lisboa (www.unl.pt)
%%
%% Glossary styles using xltabular (based on glossary-xltabular by Nicola Talbot).
%% ----------------------------------------------------------------------------

\ProvidesPackage{glossary-xltabular}[2020/12/22 v1.0]
\typeout{NT FILE StyFiles/glossary-xltabular.sty}%


%%=======================================================================
%% PACKAGE REQUIREMENTS
%%=======================================================================

% xltabular already loads longtable (and tabularx), so it is the only
% requirement needed here.
\RequirePackage{xltabular}


%%=======================================================================
%% LAYOUT SETUP & LENGTHS
%%=======================================================================

\@ifundefined{glsdescwidth}{%
  \newlength\glsdescwidth
  \setlength{\glsdescwidth}{0.6\hsize}
}{}

\@ifundefined{glspagelistwidth}{%
  \newlength\glspagelistwidth
  \setlength{\glspagelistwidth}{0.1\hsize}
}{}


%%=======================================================================
%% BASE STYLES
%%=======================================================================

\newglossarystyle{xltabular}{%
  \renewenvironment{theglossary}
     {\edef\LAYOUT{\expanded{@{}\option{/novathesis/glossaries/layout}@{}}}%
      \expandafter\xltabular\expandafter{\expandafter\linewidth\expandafter}\expandafter{\LAYOUT}}
     {\endxltabular}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupheading}[1]{%
    \multicolumn{2}{@{}l@{}}{\bfseries\glsgetgrouptitle{##1}}\tabularnewline
  }%
  \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
  }%
  \renewcommand{\subglossentry}[3]{%
     &
     \glssubentryitem{##2}%
     \glstarget{##2}{\strut}\glossentrydesc{##2}\glspostdescription\space
     ##3\tabularnewline
  }%
  \ifglsnogroupskip
    \renewcommand*{\glsgroupskip}{}%
  \else
    \renewcommand*{\glsgroupskip}{ & \tabularnewline}%
  \fi
}

\newglossarystyle{xltabularonethree}{%
  \setglossarystyle{xltabular}%
  \renewenvironment{theglossary}{%
    \xltabular{\linewidth}{>{\raggedright\arraybackslash}p{0.25\linewidth}X}}{\endxltabular}%
}

\newglossarystyle{xltabularborder}{%
  \setglossarystyle{xltabular}%
  \renewenvironment{theglossary}{%
    \xltabular{\linewidth}{|l|X|}}{\endxltabular}%
  \renewcommand*{\glossaryheader}{\hline\endhead\hline\endfoot}%
}

\newglossarystyle{xltabularheader}{%
  \setglossarystyle{xltabular}%
  \renewcommand*{\glossaryheader}{%
    \bfseries \entryname & \bfseries \descriptionname\tabularnewline\endhead}%
}

\newglossarystyle{xltabularheaderborder}{%
  \setglossarystyle{xltabularborder}%
  \renewcommand*{\glossaryheader}{%
    \hline\bfseries \entryname & \bfseries
    \descriptionname\tabularnewline\hline
    \endhead
    \hline\endfoot}%
}


%%=======================================================================
%% 3-COLUMN STYLES
%%=======================================================================

\newglossarystyle{xltabular3col}{%
  \renewenvironment{theglossary}%
    {\xltabular{\linewidth}{lXp{\glspagelistwidth}}}%
    {\endxltabular}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupheading}[1]{%
    \multicolumn{3}{@{}l@{}}{\bfseries\glsgetgrouptitle{##1}}\tabularnewline
  }%
  \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1} & ##2\tabularnewline
  }%
  \renewcommand{\subglossentry}[3]{%
     &
     \glssubentryitem{##2}%
     \glstarget{##2}{\strut}\glossentrydesc{##2} &
     ##3\tabularnewline
  }%
  \ifglsnogroupskip
    \renewcommand*{\glsgroupskip}{}%
  \else
    \renewcommand*{\glsgroupskip}{ & & \tabularnewline}%
  \fi
}

\newglossarystyle{xltabular3colborder}{%
  \setglossarystyle{xltabular3col}%
  \renewenvironment{theglossary}%
    {\xltabular{\linewidth}{|l|X|p{\glspagelistwidth}|}}%
    {\endxltabular}%
  \renewcommand*{\glossaryheader}{\hline\endhead\hline\endfoot}%
}

\newglossarystyle{xltabular3colheader}{%
  \setglossarystyle{xltabular3col}%
  \renewcommand*{\glossaryheader}{%
    \bfseries\entryname&\bfseries\descriptionname&
    \bfseries\pagelistname\tabularnewline\endhead}%
}

\newglossarystyle{xltabular3colheaderborder}{%
  \setglossarystyle{xltabular3colborder}%
  \renewcommand*{\glossaryheader}{%
    \hline
    \bfseries\entryname&\bfseries\descriptionname&
    \bfseries\pagelistname\tabularnewline\hline\endhead
    \hline\endfoot}%
}


%%=======================================================================
%% 4-COLUMN STYLES
%%=======================================================================

\newglossarystyle{xltabular4col}{%
  \renewenvironment{theglossary}%
    {\xltabular{\linewidth}{llll}}%
    {\endxltabular}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupheading}[1]{%
    \multicolumn{4}{@{}l@{}}{\bfseries\glsgetgrouptitle{##1}}\tabularnewline
  }%
  \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1} &
    \glossentrysymbol{##1} &
    ##2\tabularnewline
  }%
  \renewcommand{\subglossentry}[3]{%
     &
     \glssubentryitem{##2}%
     \glstarget{##2}{\strut}\glossentrydesc{##2} &
     \glossentrysymbol{##2} & ##3\tabularnewline
  }%
  \ifglsnogroupskip
    \renewcommand*{\glsgroupskip}{}%
  \else
    \renewcommand*{\glsgroupskip}{ & & & \tabularnewline}%
  \fi
}

\newglossarystyle{xltabular4colheader}{%
  \setglossarystyle{xltabular4col}%
  \renewcommand*{\glossaryheader}{%
    \bfseries\entryname&\bfseries\descriptionname&
    \bfseries \symbolname&
    \bfseries\pagelistname\tabularnewline\endhead}%
}

\newglossarystyle{xltabular4colborder}{%
  \setglossarystyle{xltabular4col}%
  \renewenvironment{theglossary}%
    {\xltabular{\linewidth}{|l|l|l|l|}}%
    {\endxltabular}%
  \renewcommand*{\glossaryheader}{\hline\endhead\hline\endfoot}%
}

\newglossarystyle{xltabular4colheaderborder}{%
  % Build on the *bordered* 4-column style, matching xltabularheaderborder ->
  % xltabularborder and xltabular3colheaderborder -> xltabular3colborder.
  % (This used to inherit the unbordered xltabular4col and re-declare the
  % bordered column spec by hand, which worked only by duplication.)
  \setglossarystyle{xltabular4colborder}%
  \renewcommand*{\glossaryheader}{%
    \hline\bfseries\entryname&\bfseries\descriptionname&
    \bfseries \symbolname&
    \bfseries\pagelistname\tabularnewline\hline\endhead
    \hline\endfoot}%
}


%%=======================================================================
%% ALTERNATIVE 4-COLUMN STYLES
%%=======================================================================

\newglossarystyle{altxltabular4col}{%
   \setglossarystyle{xltabular4col}%
  \renewenvironment{theglossary}%
    {\xltabular{\linewidth}{lXll}}%
    {\endxltabular}%
}

\newglossarystyle{altxltabular4colheader}{%
  \setglossarystyle{xltabular4colheader}%
  \renewenvironment{theglossary}%
    {\xltabular{\linewidth}{lXll}}%
    {\endxltabular}%
}

\newglossarystyle{altxltabular4colborder}{%
   \setglossarystyle{xltabular4colborder}%
  \renewenvironment{theglossary}%
    {\xltabular{\linewidth}{|l|X|l|l|}}%
    {\endxltabular}%
}

\newglossarystyle{altxltabular4colheaderborder}{%
  \setglossarystyle{xltabular4colheaderborder}%
  \renewenvironment{theglossary}%
    {\xltabular{\linewidth}{|l|X|l|l|}}%
    {\endxltabular}%
}

\endinput
