In a longer document I have places where I need to enforce the usage of defined abbreviations with e.g. \acrshort
(tikz pictures) and want to profit of the link to the glossary capabilities.
Furthermore I use \gls
in my text.
In the acronym glossary I would like to only give the page number of the first occurence using indexonlyfirst
.
How may I avoid that EACH usage of \acrshort
is listed instead ?
MWE is taken with slide modifications from printglossary acronym, display only the first appearance of arcshort in glossary where my point has not been conclusivly answered:
\documentclass{article}
\usepackage{hyperref}
\usepackage[toc,indexonlyfirst]{glossaries}
\makeglossaries
\newacronym{sdk}{SDK}{Software Development Kit}
\begin{document}
Test \acrshort{sdk}
\newpage
Test \acrshort{sdk}.
\newpage
Test \acrshort{sdk}\newpage
Test \newpage
Test \acrshort{sdk}\newpage
Test \newpage
Test \newpage
Test \acrshort{sdk}\newpage
Test \acrshort{sdk}\newpage
\printglossaries%y[type=\acronymtype]
\end{document}
Best Answer
I think this may be easier to do with the extension package
glossaries-extra
. This provides extra keys and a more flexible abbreviation interface. Abbreviations are defined using\newabbreviation[
options]{
label}{
short}{
long}
but to assist users who have pre-existingglossaries
code,\newacronym
is redefined to use this new interface, so\newacronym[
options]
is now equivalent to\newabbreviation[category=acronym,
options]
, but the style now needs to be set using\setabbreviationstyle[acronym]
instead of\setacronymstyle
. The short and long forms are now accessed using\glsxtrshort
and\glsxtrlong
. The original\acrshort
and\acrlong
commands may still be used, but they don't work properly if the document has multiple abbreviation styles. (The baseglossaries
package only allows one abbreviation style.)The extension package also provides a new key
noindex
which can be used in the optional argument of commands like\gls
. We can therefore take advantage of these new features to redefine\acrshort
in terms of\glsxtrshort
with thenoindex
key automatically set:Now none of your
\acrshort
commands will perform any indexing (unless this setting is overridden using\acrshort[noindex=false]
.Here's a modified version of your MWE. I've added a couple of
\gls
commands for comparison:The glossary now only has two entries in the location list for
sdk
.These correspond to the two instances of
\gls{sdk}
. These can be dealt with through theindexonlyfirst
package option:or to only apply this option to entries that have the
category
set toacronym
(which is done by\newacronym
):Note that the
indexonlyfirst
setting will overridenoindex=false
in commands like\gls
(but you can still usenoindex=false
for commands like\acrshort
).You can still use the
acronym
package option withglossaries-extra
with the glossary type identified by
\acronymtype
(and\printacronyms
as a shortcut for\printglossary[type=\acronymtype]
, or you can use theabbreviations
package option:with
\printabbreviations
(the glossary type is can be identified using\glsxtrabbrvtype
).Here's the updated MWE:
This produces the glossary: