2

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}
2

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-existing glossaries 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 base glossaries 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 the noindex key automatically set:

\renewcommand*{\acrshort}[1][]{\glsxtrshort[noindex,#1]}

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:

\documentclass{article}

\usepackage{hyperref}
\usepackage{glossaries-extra}
\makeglossaries

\setabbreviationstyle[acronym]{long-short}

\newacronym{sdk}{SDK}{Software Development Kit}

\renewcommand*{\acrshort}[1][]{\glsxtrshort[noindex,#1]}

\begin{document}
Test \acrshort{sdk}
\newpage
Test \acrshort{sdk}.
\newpage
Test \acrshort{sdk}\newpage
Test \newpage
Test \acrshort{sdk}\newpage
Test [gls] \gls{sdk}
\newpage
Test \newpage
Test [gls] \gls{sdk}
\newpage
Test \newpage
Test \acrshort{sdk}\newpage
Test \acrshort{sdk}\newpage
\printglossaries
\end{document}

The glossary now only has two entries in the location list for sdk.

image of glossary

These correspond to the two instances of \gls{sdk}. These can be dealt with through the indexonlyfirst package option:

\usepackage[indexonlyfirst]{glossaries-extra}

or to only apply this option to entries that have the category set to acronym (which is done by \newacronym):

\glssetcategoryattribute{acronym}{indexonlyfirst}{true}

Note that the indexonlyfirst setting will override noindex=false in commands like \gls (but you can still use noindex=false for commands like \acrshort).

You can still use the acronym package option with glossaries-extra

\usepackage[acronym]{glossaries-extra}

with the glossary type identified by \acronymtype (and \printacronyms as a shortcut for \printglossary[type=\acronymtype], or you can use the abbreviations package option:

\usepackage[abbreviations]{glossaries-extra}

with \printabbreviations (the glossary type is can be identified using \glsxtrabbrvtype).

Here's the updated MWE:

\documentclass{article}

\usepackage{hyperref}
\usepackage[abbreviations]{glossaries-extra}
\makeglossaries

\glssetcategoryattribute{acronym}{indexonlyfirst}{true}

\setabbreviationstyle[acronym]{long-short}

\newacronym{sdk}{SDK}{Software Development Kit}

\renewcommand*{\acrshort}[1][]{\glsxtrshort[noindex,#1]}

\begin{document}
Test \acrshort{sdk}
\newpage
Test \acrshort{sdk}.
\newpage
Test \acrshort{sdk}\newpage
Test \newpage
Test \acrshort{sdk}\newpage
Test [gls] \gls{sdk}
\newpage
Test \newpage
Test [gls] \gls{sdk}
\newpage
Test \newpage
Test \acrshort{sdk}\newpage
Test \acrshort{sdk}\newpage

\printabbreviations
\end{document}

This produces the glossary:

image of glossary

| improve this answer | |
  • Thank you very much for the extensive answer. I will make myself familiar with the glossaries-extra packge. – 4reigner Jul 11 '16 at 14:48

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.