automake, % Automatically create glossary files when compiling
acronyms, % Allow the use of acronyms as a separate glossary type
abbreviations, % Allow the use of abbreviations as a separate glossary type
nonumberlist,record=hybrid,index,toc,indexcrossrefs,translate=babel, % TODO comment what each of these does
]{glossaries-extra}
%%% Multiple Columns (Abbreviations)
\usepackage{glossary-mcols}
\renewcommand{\abbreviationsname}{List of Abbreviations}% Change the default name of the abbreviations
\makeindex
% Specify the in-text glossary abbreviation style for each glossary type
\setabbreviationstyle{long-short}
\setabbreviationstyle[acronym]{long-short}% The first time an acronym is used in text, display it as <long> (<short>), e.g. "Network Time Protocol (NTP)"
% Load all glossary type entries from separate .bib files. Acronyms and abbreviations are input using @dual<acronym/abbreviation> entries which the code below duplicates and puts into 2 separate glossary types: 1) acronym/abbreviation and 2) main. The former populate the acronyms/abbreviations and the latter populates the main glossary.
% Main glossary
\GlsXtrLoadResources[
src={Glossary.bib},
sort={en-US}, % Default sorting
type=main, % Glossary type of main (primary) entries (e.g. @entry)
dual-sort={combine}, % TODO this should be working but it's not >_< it also doesn't work in \GlsXtrLoadResources for the main glossary where it might need to go instead
type=acronym, % Glossary type of main (primary) entries (e.g. @acronym)
dual-type=main, % Glossary type of dual (secondary) entries, dual entries are only created with @dual* entries in the .bib file
dual-abbrv-map={{long}, {name}}, % Map the long field in the @dualacronym entry to the name field used in the main glossary
abbreviation-sort-fallback={name}, % Sort entries by the long field (check this in .glstex by looking at the dual entry sort= values)
dual-sort={combine}, % TODO this should be working but it's not >_< it also doesn't work in \GlsXtrLoadResources for the main glossary where it might need to go instead
type=abbreviations, % Glossary type of main (primary) entries (e.g. @abbreviation)
dual-type=main, % Glossary type of dual (secondary) entries, dual entries are only created with @dual* entries in the .bib file
dual-abbrv-map={{long}, {name}}, % Map the long field in the @dualabbreviation entry to the name field used in the main glossary
abbreviation-sort-fallback={name}, % Sort entries by the long field (check this in .glstex by looking at the dual entry sort= values)
dual-sort={combine}, % TODO this should be working but it's not >_< it also doesn't work in \GlsXtrLoadResources for the main glossary where it might need to go instead
dual-sort-field={sort}, % TODO not working
]
% Another approach that uses just the normal @abbreviation and @acronym entries but doesn't format entries in the main glossary correctly
%\GlsXtrLoadResources[
% src={Glossary.bib},
% sort={en-US}, % Default sorting
% type=main, % Glossary type of main (primary) entries (e.g. @entry)
% type=abbreviations, % Glossary type of main (primary) entries (e.g. @abbreviation)
% secondary={en-US:long:main},
%]
\GlsXtrEnableIndexFormatOverride
\glsdefpostname{acronym}{ (\glsentryshort{\glscurrententrylabel})}% Add " (<short>) to acronym entries in the main glossary
\glsdefpostname{abbreviation}{ (\glsentryshort{\glscurrententrylabel})}% Add " (<short>) to abbreviation entries in the main glossary
% Define a new glossary style that outputs short and long fields from glossary entries in a description list environment
\newglossarystyle{shortlongglossary}{%
% Put glossary entries into a description environment
\renewenvironment{theglossary}{
\begin{multicols}{2}
\begin{description}
}{
\end{description}
\end{multicols}
}%
% Define which fields are output for each glossary entry
\renewcommand*{\glossentry}[2]{%
\item[\glstarget{##1}{\glsentryshort{##1}}]\glsentrylong{##1}% Each glossary entry is output as a description item in the format: \item[<short>] <long>
}%
}
% Adds acronym to index like:
% World Coordinate System (WCS), 67, 116
% Adds glossary to index like:
% photon, xii
\renewcommand*{\glsxtrautoindexentry}[1]{%
\ifglshasshort{#1}%
{\string\glsentrylong{#1} (\glsentryshort{#1})}%
{\string\glsentrylong{#1}}%
}
% use long form for the sort value in the index, if provided:
\renewcommand*{\glsxtrautoindexassignsort}[2]{%
\ifglshaslong{#2}%
{\glsletentryfield{#1}{#2}{long}}%
{\glsletentryfield{#1}{#2}{sort}}%
}
% OK, ACRONYM shows description, then short.
% Showshort first better.
% Shows both when desc=long, only one needed...
% OK, but me. XXX borken?
%\glsdefpostname{acronym}{TEST} % This outputs something after the name, e.g. NTPTEST
%\renewcommand*{\glsxtrpostdescacronym}{\glsentrylong{\glscurrententrylabel}} % This outputs something after the description