% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{report}

\usepackage[T1]{fontenc}
\usepackage[colorlinks]{hyperref}
\usepackage[nopostdot=false]{glossaries-extra}

\makeglossaries

% regular terms:

% (Version 1.04+) The following will make regular terms appear
% in sans-serif when used with \gls etc but won't affect the 
% abbreviations:

%\renewcommand*{\glsxtrregularfont}[1]{\textsf{#1}}

% or limit to just the "general" category:
%\renewcommand*{\glsxtrregularfont}[1]{%
% \glsifcategory{\glslabel}{general}{\textsf{#1}}{#1}}

% or limit to a particular attribute:

%\glssetcategoryattribute{general}{font}{sf}
%\glssetcategoryattribute{acronym}{font}{sf}

%\renewcommand*{\glsxtrregularfont}[1]{%
% \glsifattribute{\glslabel}{font}{sf}{\textsf{#1}}{#1}}

% or use the attribute to store the font control sequence name:

%\glssetcategoryattribute{general}{font}{textsf}
%\glssetcategoryattribute{acronym}{font}{emph}
%
%\renewcommand*{\glsxtrregularfont}[1]{%
%  \glshasattribute{\glslabel}{font}%
%  {\csuse{\glsgetattribute{\glslabel}{font}}{#1}}%
%  {#1}%
%}

% The following will make the first letter of the name upper case
% in the glossary for the general entries:
\glssetcategoryattribute{general}{glossname}{firstuc}

% The following will make the first letter of the description upper case
% in the glossary for the general entries:
\glssetcategoryattribute{general}{glossdesc}{firstuc}

% (version 1.04+) The following will make the description
% appear in italic in the glossary for general entries:

%\glssetcategoryattribute{general}{glossdescfont}{emph}

% (version 1.04+) The following will make the name
% appear in italic in the glossary for general entries:

%\glssetcategoryattribute{general}{glossnamefont}{emph}

\newglossaryentry{duck}{name=duck,%
  description={a waterbird with webbed feet}}

\newglossaryentry{parrot}{name=parrot,%
  description={mainly tropical bird with bright plumage}}

% acronyms:

% The following redefinition will add the provided text to the end of the
% description in the glossary.

\renewcommand*{\glsxtrpostdescacronym}{%
 \space(\textsc{acronym:} \glsentrylong{\glscurrententrylabel})%
}

% The following will make the first letter of the name upper case
% in the glossary for the acronym entries:
\glssetcategoryattribute{acronym}{glossname}{firstuc}

% The following will make the first letter of the description upper case
% in the glossary for the acronym entries:
\glssetcategoryattribute{acronym}{glossdesc}{firstuc}

% Enable tagging of initials. The second argument is the name of
% the command you want to use to tag initial letters. The
% command will be defined robustly and will only be activated
% in the glossary for the categories listed in the first
% argument.
% If the specified tagging command (\itag here) is used
% anywhere else it will just do its argument.
\GlsXtrEnableInitialTagging{acronym,abbreviation}{\itag}

\newacronym[description={a device that emits a narrow intense 
beam of light}]{laser}{laser}
{\itag{l}ight \itag{a}mplification by \itag{s}timulated 
\itag{e}mission of \itag{r}adiation}

\newacronym[description={a form of \gls{laser} generating a beam of
microwaves}]{maser}{maser}
{\itag{m}icrowave \itag{a}mplification by \itag{s}timulated 
\itag{e}mission of \itag{r}adiation}

\newacronym[description={a system for detecting the location and
speed of ships, aircraft, etc, through the use of radio waves}]{radar}{radar}
{\itag{ra}dio \itag{d}etection \itag{a}nd \itag{r}anging}

\newacronym[description={portable breathing apparatus for divers}]{scuba}{scuba}
{\itag{s}elf-\itag{c}ontained \itag{u}nderwater 
\itag{b}reathing \itag{a}pparatus}

% The following redefinition will add the provided text to the end of the
% description in the glossary.

\renewcommand*{\glsxtrpostdescabbreviation}{%
 \space (abbreviation)%
}

% The following will set the description in title case
% in the glossary for the abbreviations:
\glssetcategoryattribute{abbreviation}{glossdesc}{title}

% The following will convert the abbreviations to all capitals
% in the glossary:
\glssetcategoryattribute{abbreviation}{glossname}{uc}

% Use \textsc in the abbreviations:
\setabbreviationstyle{long-short-sc}

% Some other attributes you might want to try:

% Use 's (apostrophe s) for the plural suffix
% (only affects the short plural not the long plural)
%\glssetcategoryattribute{abbreviation}{aposplural}{true}

% Suppress the default suffix for the short plural.
% (Don't use with the above for the same category.)
%\glssetcategoryattribute{abbreviation}{noshortplural}{true}

% abbreviations:

\newabbreviation
 {html}% identifying label
 {html}% short form
 {\itag{h}yper\itag{t}ext \itag{m}arkup \itag{l}anguage}% long form

\newabbreviation
 {xml}% identifying label
 {xml}% short form
 {e\itag{x}tensible \itag{m}arkup \itag{l}anguage}% long form

\newabbreviation
 {svg}% identifying label
 {svg}% short form
 {\itag{s}calable \itag{v}ector \itag{g}raphics}% long form

\newabbreviation
 {svm}% identifying label
 {svm}% short form
 {\itag{s}upport \itag{v}ector \itag{m}achine}% long form

\title{Sample Document Illustrating the glossaries-extra Package}
\author{Nicola Talbot}

\begin{document}
\pagenumbering{alph}
\maketitle

\pagenumbering{roman}
\tableofcontents

\pagenumbering{arabic}
\chapter{Categories}

The \texttt{glossaries-extra} package provides an extra key called
\texttt{category}, which is used to assign a category to each entry.
For example, the category for the ``duck'' entry is:
\glscategory{duck}.

The category value is just a label, which needs to be expandable, so
make sure you avoid problematic characters in it.  You can test the
category with \verb|\glsifcategory|. 

The entry ``duck'' \glsifcategory{duck}{general}{is}{isn't} a
general entry.
The entry ``laser'' \glsifcategory{laser}{general}{is}{isn't} a
general entry.

A category can have attributes set. For example, both the
``general'' category and the ``acronym'' category have the attribute
``regular'' set to ``true''.

You can obtain the value of an attribute for a given category with
\begin{verbatim}
\glsgetcategoryattribute{category}{attribute}
\end{verbatim}
This does nothing if the category
or attribute aren't defined.

Category ``general'' has the attribute ``regular'' set to 
``\glsgetcategoryattribute{general}{regular}''.
Category ``acronym'' has the attribute ``regular'' set to 
``\glsgetcategoryattribute{acronym}{regular}''.
Category ``abbreviation'' has the attribute ``regular'' set to 
``\glsgetcategoryattribute{abbreviation}{regular}''.

You can test if a category has an attribute set to a given value
with
\begin{verbatim}
\glsifcategoryattribute{category}{attribute}{value}{true code}{false
code}
\end{verbatim}

Category ``general''
\glsifcategoryattribute{general}{regular}{true}{has}{doesn't have}
the ``regular'' attribute set to ``true''.
Category ``acronym''
\glsifcategoryattribute{acronym}{regular}{true}{has}{doesn't have}
the ``regular'' attribute set to ``true''.
Category ``abbreviation''
\glsifcategoryattribute{abbreviation}{regular}{true}{has}{doesn't have}
the ``regular'' attribute set to ``true''.

\chapter{Regular Terms}

By default glossary entries have the category ``general''.
For
example\glsforeachincategory{general}{\thistype}{\thislabel}{,
\gls{\thislabel}} have the category field set to ``general''.

Commands like \verb|\newabbreviation| and \verb|\newacronym| 
override this.

Regular terms are those entries whose category has the ``regular''
attribute set to ``true''. There's a convenient shortcut to
determine if an entry has a category with the ``regular'' attribute
set:
\begin{verbatim}
\glsifregular{entry-label}{true code}{false code}
\end{verbatim}

For example: \gls{duck} \glsifregular{duck}{is}{isn't} a regular
term; 
\gls{laser} \glsifregular{laser}{is}{isn't} a regular
term.

The regular attribute determines what \verb|\gls| (and plural and
case-changing variants) should do. A regular entry (even if
it's been defined using \verb|\newacronym| or
\verb|\newabbreviation|) uses the \texttt{first} (or
\texttt{firstplural}) key on first use and the \texttt{text}
(or \texttt{plural}) key on subsequent use.

An abbreviation whose category doesn't have the regular attribute
set to ``true'' will use the abbreviation style assigned
to that category for first and subsequent use, which will use
the values of the \texttt{long} (or \texttt{longplural})
and \texttt{short} (or \texttt{shortplural}) keys.
The first use of \verb|\gls| may or may not match \verb|\glsfirst|
for non-regular entries, depending on the abbreviation style.

\chapter{Abbreviations}

Abbreviations include acronyms, initialisms and contractions.
Some abbreviation styles may set category attributes.
For example, the ``short'' style sets the ``regular'' attribute for
the category used by the abbreviations with that style applied.
Whereas the ``long-short'' style will switch off the ``regular'' attribute
if it has previously been switched on.
Styles must be set before defining abbreviations, but you may set
different styles for different categories.

For example, by default the ``short'' style is set for abbreviations
with the ``acronym'' category using:
\begin{verbatim}
\setabbreviationstyle[acronym]{short}
\end{verbatim}
whereas the ``short-long'' style is set for abbreviations with the
``abbreviation'' category:
\begin{verbatim}
\setabbreviationstyle{long-short}
\end{verbatim}
(The optional argument defaults to ``abbreviation''.)

If no style has been set for a particular category, the style for the 
``abbreviation'' category is used instead.

\section{Acronyms}

An acronym is a word formed from the initial letters of other words. 
Since it's a word, an acronym is pronounced as a word rather than as
a series of letters. Examples of acronyms: \gls{laser}, \gls{maser},
\gls{radar} and \gls{scuba}.

Since acronyms are treated as words, the ``acronym'' category 
has the ``regular'' attribute set to ``true''. The default
abbreviation style for acronyms is ``short'', which doesn't expand
the entry on first use.

The description defaults to the long
form with the ``short'' style. This example document overrides
the default description by using the \texttt{description}
key in the optional argument of \verb|\newacronym|. This 
document also sets the post description hook
(\verb|\glsxtrpostdescacronym|) to insert the long form in
parentheses after the description when it's displayed in the glossary.

\section{Initialism}

Initialisms are formed from initial letters of words where the
letters are sounded out. Examples of initialisms: 
\gls{svm}, \gls{html}, \gls{svg} and \gls{xml}.

The \texttt{glossaries-extra} package sets the default abbreviation
style to \texttt{long-short}. This document has changed it to
\texttt{long-short-sc} (use small caps). Next use: 
\gls{svm}, \gls{html}, \gls{svg} and \gls{xml}.

Note that the acronyms (like \gls{laser}) don't use small caps.
This is because the acronyms and initialisms have separate styles
applied since they are in separate categories.

\section{Plurals}

The default plural for the short form is obtained by appending
the abbreviation plural suffix to the singular form. You can
override this on a per-entry basis using the \texttt{shortplural}
key in the optional argument of \verb|\newabbreviation|
(or \verb|\newacronym|) or you can prevent the suffix from
being added to all entries in a particular category (or categories)
by setting the \texttt{noshortplural} attribute to ``true'' for
the relevant category (before defining the entries).

Alternatively you can automatically insert an apostrophe before 
the plural suffix by setting the \texttt{aposplural} attribute to 
``true''. The \texttt{aposplural} attribute overrides the
\texttt{noshortplural} attribute.

Plurals: \glspl{svm}, \glspl{laser}.

\printglossaries

\end{document}
