3

I'm writing a paper where I have a lot of acronyms. Some are mentioned all the time whereas others only a few. I read that it is possible to create a new glossary and to place all the acronyms that I don't want to show in that list.

I was wondering, though, if there is a way to automate the addition or exclusion of acronyms to the list that is shown based on how often they're used. For example let's say I define

\newacronym{am}{AM}{Additive Manufacturing}
\newacronym{osrx}{OSIRIS-REx}{Origins, Spectral Interpretation, Resource Identification, Security, Regolith Explorer}

and two lists, shown_acronyms and hidden_acronyms. In my text I use \gls{am} 10 times whereas \gls{osrx} only twice. Is there a way to make Latex check how many times each one is used and add them to the appropriate list when compiling the document?

  • Thanks but no, that's not what I'm looking for, I'm not showing the list of pages for each acronym. What I would like to do is make it so that an acronym that is mentioned less than 4 times is not shown in the list of acronyms. – enea19 Jun 20 '18 at 8:13
2

You can use the entry counting mechanism with the glossaries-extra extension package. The following is adapted from sample-entrycount.tex that's provided with glossaries-extra:

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage{glossaries-extra}

\makeglossaries

\setabbreviationstyle[acronym]{short-long}

\GlsXtrEnableEntryCounting
 {acronym}% list of categories to use entry counting
 {3}% trigger value (only add to glossary if count > 3)

\newacronym{html}{HTML}{hypertext markup language}
\newacronym{xml}{XML}{extensible markup language}
\newacronym{css}{CSS}{cascading style sheet}

\newacronym{am}{AM}{Additive Manufacturing}
\newacronym{osrx}{OSIRIS-REx}{Origins, Spectral Interpretation, Resource Identification, Security, Regolith Explorer}

\begin{document}

Used once: \gls{html}.

Used twice: \gls{xml} and \gls{xml}.

Used three times: \gls{css} and \gls{css} and \gls{css}.

Used four times: \gls{am} and \gls{am} and \gls{am} and \gls{am}.

Used five times: \gls{osrx} and \gls{osrx} and \gls{osrx} and 
\gls{osrx} and \gls{osrx}.

\printglossaries
\end{document}

image of document

The document build (assuming the file is called myDoc.tex) is:

pdflatex myDoc
pdflatex myDoc
makeglossaries myDoc
pdflatex myDoc

(replace pdflatex as appropriate).

Note that the terms that aren't included only show the long form. This can be adapted if required by redefining the \cglsformat set of commands (described in section 14.1 of the glossaries user manual).

For example, to display the long form followed by the short form in parentheses:

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage{glossaries-extra}

\makeglossaries

\setabbreviationstyle[acronym]{short-long}

\GlsXtrEnableEntryCounting
 {acronym}% list of categories to use entry counting
 {3}% trigger value (only add to glossary if count > 3)

\renewcommand*{\cglsformat}[2]{%
  \ifglshaslong{#1}%
  {\glsentrylong{#1}#2 (\glsentryshort{#1})}% abbreviation
  {\glsentryfirst{#1}#2}% regular term
}

\renewcommand*{\cGlsformat}[2]{%
  \ifglshaslong{#1}%
  {\Glsentrylong{#1}#2 (\glsentryshort{#1})}% abbreviation
  {\Glsentryfirst{#1}#2}% regular term
}

\renewcommand*{\cglsplformat}[2]{%
  \ifglshaslong{#1}%
  {\glsentrylongpl{#1}#2 (\glsentryshortpl{#1})}% abbreviation
  {\glsentryfirstplural{#1}#2}% regular term
}

\renewcommand*{\cGlsplformat}[2]{%
  \ifglshaslong{#1}%
  {\Glsentrylongpl{#1}#2 (\glsentryshortpl{#1})}% abbreviation
  {\Glsentryfirstplural{#1}#2}% regular term
}

\newacronym{html}{HTML}{hypertext markup language}
\newacronym{xml}{XML}{extensible markup language}
\newacronym{css}{CSS}{cascading style sheet}

\newacronym{am}{AM}{Additive Manufacturing}
\newacronym{osrx}{OSIRIS-REx}{Origins, Spectral Interpretation, Resource Identification, Security, Regolith Explorer}

\begin{document}

Used once: \gls{html}.

Used twice: \gls{xml} and \gls{xml}.

Used three times: \gls{css} and \gls{css} and \gls{css}.

Used four times: \gls{am} and \gls{am} and \gls{am} and \gls{am}.

Used five times: \gls{osrx} and \gls{osrx} and \gls{osrx} and 
\gls{osrx} and \gls{osrx}.

\printglossaries
\end{document}

image of document with long (short) form showed for each instance of the terms that aren't referenced more times than the trigger value

Each of these formatting commands has the label as the first argument and the insert material (provided by the final optional argument of commands like \gls) as the second argument. I've used \ifglshaslong to check if the entry has a long form. This allows a mixture of abbreviations and general terms. If you know that the count mechanism is only being applied to abbreviations, you can skip the check.

Note that these formatting commands are applied on each instance of a reference where the total reference count on the previous run doesn't exceed the trigger value for that term.

Explicitly unsetting or resetting the first use flag with commands like \glsunset, \glsreset, \glsunsetall or \glsresetall will upset the count. (The reset commands reset the count to 0.)

  • Your glossaries support is so fantastic, every question gets an answer of @NicolaTalbot. Perfect. Thank you very much. – Bobyandbob Jun 20 '18 at 11:19
  • Thank you so so much, that is exactly what I was looking for! – enea19 Jun 21 '18 at 6:30
  • I have a further question, if I may. I'm still relatively new to Latex and I'm not sure how to change the \cglsformat commands so that both long and short forms are shown irrespective of whether the acronym is included in the list or not. – enea19 Jul 2 '18 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.