[Tex/LaTex] Ignoring an acronym that is only used once

glossaries

I am using the glossaries package only for its acronym capabilities, and I have one or two that are only used once in the document. For those acronyms, is there a way to only display the full text?

Specifically, the default is for \gls{dft} to display

density functional theory (DFT),

but I'd like it to only display

density functional theory

if the acronym is only used once.

Best Answer

If you want to get the long form of an acronym—independently of the selected acronym style and the context where the acronym is used—I think it's best to simply use \acrlong or \acl. Note that the latter command is only defined if the shortcuts option of the glossaries package is set.

Edit: Werner has pointed out in a comment to his answer that it is probably possible to extend the glossaries package such that acronyms are printed in a distinct way if they are used only once in the document. The following patch shows that this can indeed be done:

\documentclass{article}

\usepackage{etoolbox}
\usepackage{glossaries}[2011/04/12]

\makeatletter

\appto\newacronymhook{%
  \newbool{glo@\the\glslabeltok @usedonlyonce}% define an additional switch per acronym
}

\patchcmd{\@gls@}{%
  \glsunset{#2}%
}{% write appropriate information to the main auxiliary file
  \ifglsused{#2}{%
    \write\@auxout{\global\setbool{glo@#2@usedonlyonce}{false}}%
  }{%
    \write\@auxout{\global\setbool{glo@#2@usedonlyonce}{true}}%
  }%
  \glsunset{#2}%
}{}{}

\patchcmd{\@gls@}{%
  \glsentryfirst{#2}%
}{% print the long form of the acronym if the acronym is used only once
  \ifbool{glo@#2@usedonlyonce}{\glsentrylong{#2}}{\glsentryfirst{#2}}%
}{}{}

\makeatother

\newacronym{ANO}{ANO}{Acronym Number One}
\newacronym{ANT}{ANT}{Acronym Number Two}

\makeglossaries

\begin{document}

\printglossary

\noindent
\gls{ANO}, \gls{ANO}\\
\gls{ANT}

\end{document}

Obviously, you need two LaTeX runs to get everything right. Moreover, if you use not only \gls (\ac), but also \Gls (\Ac), \GLS, \glspl (\acp), \Glspl (\Acp) and \GLSpl you have to patch \@Gls@, \@GLS@, \@glspl@, \@Glspl@ and \@GLSpl@ in the same way as \@gls@.

The resulting output is:

Related Question