% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: pdflatex

\documentclass{report}

\usepackage[T1]{fontenc}
\usepackage{relsize}
\usepackage{etoolbox}
\usepackage[colorlinks,linkcolor=magenta]{hyperref}
\usepackage{glossaries-extra}

% If you get any undefined control sequences or undefined
% style errors, make sure you have the latest versions of
% glossaries-extra.sty and glossaries.sty

\makeglossaries

% This command is used for short forms for styles
% that don't have a designated command:
\renewcommand{\glsabbrvdefaultfont}[1]{\textsf{#1}}

% This command is used on first use for short forms
% for styles that don't have a designated command:
%\renewcommand{\glsfirstabbrvdefaultfont}[1]{\textsf{#1}}

% This command is used for long forms for styles
% that don't have a designated command:
\renewcommand{\glslongdefaultfont}[1]{\textsf{#1}}

% This command is used on first use for long forms
% for styles that don't have a designated command:
%\renewcommand{\glsfirstlongdefaultfont}[1]{\textsf{#1}}

% These commands are used by the '-hyphen' styles.
% For example, to switch to small-caps for the short form:
%\renewcommand{\glsabbrvhyphenfont}{\glsabbrvscfont}
%\renewcommand{\glsxtrhyphensuffix}{\glsxtrscsuffix}
% and emphasize the long form
%\renewcommand{\glslonghyphenfont}{\emph}

\renewcommand{\glsxtrabbrvfootnote}[2]{%
  \footnote{\glshyperlink[\glsfmtshort{#1}]{#1}: #2}%
}

\glssetcategoryattribute{long-hyphen-short-hyphen}{markwords}{true}
\glssetcategoryattribute{long-hyphen-postshort-hyphen}{markwords}{true}
\glssetcategoryattribute{long-hyphen-short-hyphen-desc}{markwords}{true}
\glssetcategoryattribute{long-hyphen-postshort-hyphen-desc}{markwords}{true}
\glssetcategoryattribute{short-hyphen-long-hyphen}{markwords}{true}
\glssetcategoryattribute{short-hyphen-postlong-hyphen}{markwords}{true}
\glssetcategoryattribute{short-hyphen-long-hyphen-desc}{markwords}{true}
\glssetcategoryattribute{short-hyphen-postlong-hyphen-desc}{markwords}{true}
\glssetcategoryattribute{long-hyphen-noshort-desc-noreg}{markwords}{true}
\glssetcategoryattribute{long-hyphen-noshort-noreg}{markwords}{true}

\newcommand{\stylelist}{}

\newcommand{\teststyle}[1]{%
 \listadd{\stylelist}{#1}%
 \setabbreviationstyle[#1]{#1}%
 \newabbreviation[category=#1,%
  %sort={#1},% order by style name
  user1={user text}%
 ]{sample-#1}{short}{long form}%
 \csdef{glsxtrpostdesc#1}{ [style: #1]}%
}

\newcommand{\testdescstyle}[1]{%
 \listadd{\stylelist}{#1}%
 \setabbreviationstyle[#1]{#1}%
 \newabbreviation[category=#1,%
  %sort={#1},% order by style name
  user1={user text},%
  description={sample description}]{sample-#1}{short}{long form}%
 \csdef{glsxtrpostdesc#1}{ [style: #1]}%
}

\teststyle{long-short}
\teststyle{short-long}
%\teststyle{footnote}% synonym: short-footnote
\teststyle{short-footnote}
%\teststyle{postfootnote}% synonym: short-postfootnote
\teststyle{short-postfootnote}
%\teststyle{short}% synonym: short-nolong
\teststyle{short-nolong}
\teststyle{short-nolong-noreg}
\teststyle{nolong-short}
\teststyle{nolong-short-noreg}
%\teststyle{long}% synonym: long-noshort
\teststyle{long-noshort}
\teststyle{long-noshort-noreg}
\teststyle{long-only-short-only}
\teststyle{long-short-sc}
\teststyle{short-sc-long}
%\teststyle{short-sc}% synonym: short-sc-nolong
\teststyle{short-sc-nolong}
\teststyle{nolong-short-sc}
\teststyle{long-noshort-sc}
%\teststyle{long-sc}% deprecated synonym of long-noshort-sc
\teststyle{short-sc-footnote}
%\teststyle{footnote-sc}% deprecated synonym of short-sc-footnote
\teststyle{short-sc-postfootnote}
%\teststyle{postfootnote-sc}% deprecated synonym of short-sc-postfootnote
\teststyle{long-short-sm}
\teststyle{short-sm-long}
%\teststyle{short-sm}% synonym: short-sm-nolong
\teststyle{short-sm-nolong}
\teststyle{nolong-short-sm}
%\teststyle{long-sm}% deprecated synonym of long-noshort-sm
\teststyle{long-noshort-sm}
\teststyle{short-sm-footnote}
%\teststyle{footnote-sm}% deprecated synonym of short-sm-footnote
\teststyle{short-sm-postfootnote}
%\teststyle{postfootnote-sm}% deprecated synonym of short-sm-postfootnote
\teststyle{long-short-em}
\teststyle{long-em-short-em}
\teststyle{short-em-long}
\teststyle{short-em-long-em}
\teststyle{short-em-nolong}
%\teststyle{short-em}% synonym: short-em-nolong
\teststyle{nolong-short-em}
\teststyle{long-noshort-em}
%\teststyle{long-em}% deprecated synonym of long-noshort-em
\teststyle{long-em-noshort-em}
\teststyle{long-em-noshort-em-noreg}
\teststyle{short-em-footnote}
%\teststyle{footnote-em}% deprecated synonym of short-em-footnote
\teststyle{short-em-postfootnote}
%\teststyle{postfootnote-em}% deprecated synonym of short-em-postfootnote
\teststyle{long-short-user}
\teststyle{long-postshort-user}
\teststyle{short-long-user}
\teststyle{short-postlong-user}
\teststyle{long-hyphen-short-hyphen}
\teststyle{long-hyphen-postshort-hyphen}
\teststyle{short-hyphen-long-hyphen}
\teststyle{short-hyphen-postlong-hyphen}
\teststyle{long-hyphen-noshort-noreg}

\testdescstyle{long-short-desc}
\testdescstyle{short-long-desc}
%\teststyle{footnote-desc}% synonym: short-footnote-desc
\testdescstyle{short-footnote-desc}
%\teststyle{postfootnote-desc}% synonym: short-postfootnote-desc
\testdescstyle{short-postfootnote-desc}
%\testdescstyle{short-desc}% synonym: short-nolong-desc
\testdescstyle{short-nolong-desc}
\testdescstyle{short-nolong-desc-noreg}
%\testdescstyle{long-desc}% synonym: long-noshort-desc
\testdescstyle{long-noshort-desc}
\testdescstyle{long-noshort-desc-noreg}
\testdescstyle{long-only-short-only-desc}
\testdescstyle{long-short-sc-desc}
\testdescstyle{short-sc-long-desc}
%\testdescstyle{short-sc-desc}% synonym: short-sc-nolong-desc
\testdescstyle{short-sc-nolong-desc}
\testdescstyle{long-noshort-sc-desc}
%\testdescstyle{long-desc-sc}% deprecated synonym of long-noshort-sc-desc
\testdescstyle{short-sc-footnote-desc}
\testdescstyle{short-sc-postfootnote-desc}
\testdescstyle{long-short-sm-desc}
\testdescstyle{short-sm-long-desc}
%\testdescstyle{short-sm-desc}% synonym: short-sm-nolong-desc
\testdescstyle{short-sm-nolong-desc}
\testdescstyle{long-noshort-sm-desc}
%\testdescstyle{long-desc-sm}% deprecated synonym of long-noshort-sm-desc
\testdescstyle{short-sm-footnote-desc}
\testdescstyle{short-sm-postfootnote-desc}
\testdescstyle{long-short-em-desc}
\testdescstyle{long-em-short-em-desc}
\testdescstyle{short-em-long-desc}
\testdescstyle{short-em-long-em-desc}
%\testdescstyle{short-em-desc}% synonym: short-em-nolong-desc
\testdescstyle{short-em-nolong-desc}
\testdescstyle{long-noshort-em-desc}
%\testdescstyle{long-desc-em}% deprecated synonym of long-noshort-em-desc
\testdescstyle{short-em-footnote-desc}
\testdescstyle{short-em-postfootnote-desc}
\testdescstyle{long-em-noshort-em-desc}
\testdescstyle{long-em-noshort-em-desc-noreg}
\testdescstyle{long-short-user-desc}
\testdescstyle{long-postshort-user-desc}
\testdescstyle{short-long-user-desc}
\testdescstyle{short-postlong-user-desc}
\testdescstyle{long-hyphen-short-hyphen-desc}
\testdescstyle{long-hyphen-postshort-hyphen-desc}
\testdescstyle{short-hyphen-long-hyphen-desc}
\testdescstyle{short-hyphen-postlong-hyphen-desc}
\testdescstyle{long-hyphen-noshort-desc-noreg}

\newcommand{\marg}[1]{\{\textnormal{\emph{#1}}\}}
\pagestyle{headings}

\makeatletter
\renewcommand{\l@section}{\@dottedtocline {1}{1.5em}{3.3em}}
\makeatother

\begin{document}
\pagenumbering{roman}
This is a test document demonstrating abbreviation styles
provided by the \textsf{glossaries-extra} package. Hyperlinks
are shown in 
\makeatletter
\textcolor{\@linkcolor}{\@linkcolor}.
\makeatother

Some of the styles just use the default formatting commands (which don't
change the font). To make the default setting clearer, this document has done:
\begin{verbatim}
\renewcommand{\glslongdefaultfont}[1]{\textsf{#1}}
\renewcommand{\glsabbrvdefaultfont}[1]{\textsf{#1}}
\end{verbatim}
So any text in this document that's rendered in sans-serif would normally not have any font
change implemented.

Each test entry is defined using 
\begin{verbatim}
 \newabbreviation[category=#1,user1={user text}]%
  {sample-#1}{short}{long form}%
\end{verbatim}
for the non\texttt{-desc} styles or
\begin{verbatim}
 \newabbreviation[category=#1,user1={user text},%
  description={sample description}]%
 {sample-#1}{short}{long form}%
\end{verbatim}
for the \texttt{-desc} styles (where \verb|#1| is the style label).
Note that many of the entries will have duplicate sort values, so
don't build this with \texttt{xindy}. You can change the ordering
in the glossary to that it's sorted according to the style name
by changing the above definitions to:
\begin{verbatim}
 \newabbreviation[category=#1,user1={user text},sort={#1}]%
  {sample-#1}{short}{long form}%
 \newabbreviation[category=#1,user1={user text},sort={#1},%
  description={sample description}]%
 {sample-#1}{short}{long form}%
\end{verbatim}

To assist with distinguishing between the various styles, 
the post-description hook (used after displaying the description in
the glossary) is set to \verb*| [style: #1]| for all categories,
and the footnote command \verb|\glsxtrabbrvfootnote| has been
redefined to include the short form hyperlinked to the glossary.

The test entries that use the \texttt{-hyphen} styles have had the
\texttt{markwords} attribute set. This is designed to trigger
compound word hyphenation if the inserted text (through the final
optional argument of \verb|\gls|) starts with a hyphen.

\tableofcontents

\pagenumbering{arabic}
\chapter{First Use}
First use of \verb|\gls|.

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\gls{\thislabel}.\glspar}

\chapter{Next Use}
Next use of \verb|\gls|.

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\gls{\thislabel}.\glspar}

\chapter{First Use With Insert}
First use of \texttt{\string\gls\marg{label}[-insert]}. The conditional
\verb|\ifglsxtrinsertinside| is used by some styles to 
determine whether or not to include the inserted material
inside the font changing command used by the style.
The default is: \ifglsxtrinsertinside true\else false\fi.

In this test chapter, each entry is reset, then displayed with
\begin{verbatim}
\glsxtrinsertinsidefalse
\end{verbatim}
then reset and displayed with 
\begin{verbatim}
\glsxtrinsertinsidetrue
\end{verbatim}
(following the semi-colon). Some styles may only obey this
conditional for particular commands. (For example, the inline
commands like \verb|\glsxtrfull| may behave differently to 
commands like \verb|\gls|.)

Some of the styles just use the default font commands (which don't
change the font) so there's no noticeable difference. To make the
differences more noticeable this document has done:
\begin{verbatim}
\renewcommand{\glslongdefaultfont}[1]{\textsf{#1}}
\renewcommand{\glsabbrvdefaultfont}[1]{\textsf{#1}}
\end{verbatim}

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glsreset{\thislabel}\glsxtrinsertinsidefalse
\gls{\thislabel}[-insert];
\glsreset{\thislabel}\glsxtrinsertinsidetrue
\gls{\thislabel}[-insert].\glspar}

\chapter{Next Use With Insert}
Next use of \texttt{\string\gls\marg{label}[-insert]}.

In this test chapter, each entry is displayed
with \verb|\glsxtrinsertinsidefalse| and then displayed with
\verb|\glsxtrinsertinsidetrue| 
(following the semi-colon). Some styles don't check this
conditional.

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glsxtrinsertinsidefalse
\gls{\thislabel}[-insert];
\glsxtrinsertinsidetrue
\gls{\thislabel}[-insert].\glspar}

\chapter{Full Form}
Full form using \verb|\glsxtrfull| (inline full style).
This may differ from the display form used by \verb|\gls|
on first use, depending on the style.

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glsxtrfull{\thislabel}.\glspar}

\chapter{Short Form}
Short form using \verb|\glsxtrshort|.
This may differ from the display form used by \verb|\gls|
on subsequent use, depending on the style.

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glsxtrshort{\thislabel}.\glspar
}

\chapter{Long Form}
Long form using \verb|\glsxtrlong|.

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glsxtrlong{\thislabel}.\glspar}

\chapter{Full Form With Insert}
Full form using \texttt{\string\glsxtrfull\marg{label}[-insert]} (inline full style).
In this test chapter, each entry is displayed
with \verb|\glsxtrinsertinsidefalse| and then displayed with
\verb|\glsxtrinsertinsidetrue| 
(following the semi-colon).

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glsxtrinsertinsidefalse
\glsxtrfull{\thislabel}[-insert];
\glsxtrinsertinsidetrue
\glsxtrfull{\thislabel}[-insert].\glspar}

\chapter{Short Form With Insert}
Short form using \texttt{\string\glsxtrshort\marg{label}[-insert]}.

In this test chapter, each entry is displayed
with \verb|\glsxtrinsertinsidefalse| and then displayed with
\verb|\glsxtrinsertinsidetrue| 
(following the semi-colon).

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glsxtrinsertinsidefalse
\glsxtrshort{\thislabel}[-insert];
\glsxtrinsertinsidetrue
\glsxtrshort{\thislabel}[-insert].\glspar}

\chapter{Long Form With Insert}
Long form using \texttt{\string\glsxtrlong\marg{label}[-insert]}.
Note that the \texttt{hyphen} styles with the \texttt{markwords}
attribute don't adjust in this case.

In this test chapter, each entry is displayed
with \verb|\glsxtrinsertinsidefalse| and then displayed with
\verb|\glsxtrinsertinsidetrue| 
(following the semi-colon).

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glsxtrinsertinsidefalse
\glsxtrlong{\thislabel}[-insert];
\glsxtrinsertinsidetrue
\glsxtrlong{\thislabel}[-insert].\glspar}

\chapter{First Form}
First form using \verb|\glsfirst|. This may be different
from the first use of \verb|\gls| depending on the style.

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glsfirst{\thislabel}.\glspar}

\chapter{Text Form}
Text form using \verb|\glstext|. This may be different
from the subsequent use of \verb|\gls| depending on the style.

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glstext{\thislabel}.\glspar}

\chapter{First Form With Insert}
First form using \texttt{\string\glsfirst\marg{label}[-insert]}.
This is different from the first use of \verb|\gls|
as can be seen by the location of the inserted material.
(There's no check for the conditional 
\verb|\ifglsxtrinsertinside|.) In general it's best not
to use \verb|\glsfirst| with abbreviations. Use either
\verb|\gls| (possibly with a reset) or \verb|\glsxtrfull|.

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glsfirst{\thislabel}[-insert].\glspar}

\chapter{Text Form With Insert}
Text form using \texttt{\string\glstext\marg{label}[-insert]}.
This doesn't check for the conditional 
\verb|\ifglsxtrinsertinside|.

\forglsentries{\thislabel}{\glscategory{\thislabel}:
\glstext{\thislabel}[-insert].\glspar}

\chapter{Summary}

\renewcommand{\do}[1]{\section{#1}
First use \texttt{\string\gls\marg{label}}:
\glsreset{sample-#1}\gls{sample-#1}.\par\noindent
Next use \texttt{\string\gls\marg{label}}: \gls{sample-#1}.\par\noindent
First use \texttt{\string\gls\marg{label}[-insert]}: 
\glsreset{sample-#1}\gls{sample-#1}[-insert].\par\noindent
Next use \texttt{\string\gls\marg{label}[-insert]}: 
\gls{sample-#1}[-insert].\par\noindent
\texttt{\string\glsxtrfull\marg{label}[-insert]}: 
\glsxtrfull{sample-#1}[-insert].\par\noindent
\texttt{\string\glsxtrshort\marg{label}[-insert]}: 
\glsxtrshort{sample-#1}[-insert].\par\noindent
\texttt{\string\glsxtrlong\marg{label}[-insert]}: 
\glsxtrlong{sample-#1}[-insert].\par\noindent
Name: \glsentryname{sample-#1}.\par\noindent
Sort: \texttt{\glsentrysort{sample-#1}}.\par\noindent
Description: \glsentrydesc{sample-#1}.\par
}

\dolistloop{\stylelist}
\printglossaries
\end{document}
