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

\usepackage[docdef]{glossaries-extra}

\makeglossaries

\begin{document}

\printglossaries

This is a sample document testing the use of document definitions
for those who are happy to accept all the associated drawbacks
of not following the advice in the glossaries manual about
defining all your entries in the preamble. Use it at your own
peril.

\newglossaryentry{sample}{name=sample,description={an example}}
\newglossaryentry{sample2}{name={another sample},
 description={another example},see={sample}}
\newabbreviation{ab}{AB}{sample abbreviation}

Use \gls{sample2}.

Use \gls{ab}.
\end{document}
