How can glossaries handle the article 'a' or 'an' before abbreviations?

You can test if an entry has been used:

\documentclass{article}
\usepackage{glossaries}
\newacronym{fbi}{FBI}{Federal Bureau of Investigation}
\begin{document}
Fox Mulder is \ifglsused{fbi}{an}{a} \gls{fbi} special agent educated at Oxford
who believes in the existence of extraterrestrials and a
government conspiracy to hide the truth regarding them.

Dana Scully is \ifglsused{fbi}{an}{a} \gls{fbi} special agent, a medical doctor,
and scientist who is Mulder's partner. In contrast to his
credulity, Scully is a skeptic, basing her beliefs on
scientific explanations.
\end{document}

enter image description here


You can use glossaries-prefix which is supplied with the glossaries package:

\documentclass{article}
\usepackage{glossaries-prefix}
\newacronym[
    prefixfirst={a\ },% prefix used on first use
    prefix={an\ }% prefix used on subsequent use
]
{fbi}{FBI}{Federal Bureau of Investigation}
\begin{document}
Fox Mulder is \pgls{fbi} special agent educated at Oxford
who believes in the existence of extraterrestrials and a
government conspiracy to hide the truth regarding them.

Dana Scully is \pgls{fbi} special agent, a medical doctor,
and scientist who is Mulder's partner. In contrast to his
credulity, Scully is a skeptic, basing her beliefs on
scientific explanations.
\end{document}

Fox Mulder is a Federal Bureau of Investigation (FBI) special agent educated at Oxford who believes in the existence of extraterrestrials and a government conspiracy to hide the truth regarding them. Dana Scully is an FBI special agent, a medical doctor, and scientist who is Mulder’s partner. In contrast to his credulity, Scully is a skeptic, basing her beliefs on scientific explanations.

The glossaries-prefix package loads glossaries and adds four new keys: prefix, prefixplural, prefixfirst and prefixfirstplural. You can determine if the prefix field has been provided for a particular entry with \ifglshasprefix{label}{true}{false}. This tests if the prefix field is empty. There are similar commands for the other prefix fields.

The command \pgls¹ has the same syntax as \gls and performs the same test as in Ulrike's answer, so \pgls{fbi} is essentially the same as

\ifglsused{fbi}{\glsentryprefix{fbi}}{\glsentryprefixfirst{fbi}}\gls{fbi}

but is more convenient to use.

Note that there's no space automatically inserted between the prefix and \gls to allow for things like prefix={l'} in French. If you want a second set of prefixes, then you'll have to add the fields manually using \glsaddkey and define a command similar to \pgls.


¹ Similarly for the upper case and plural variants. See the glossaries user manual for the complete list of provided commands.