# glossaries dual entries: prevent page from acronym list appearing in glossary number list

As a follow up to this question: when using the newdualentry command provided as an example in the glossaries package, how do I prevent the number list of the glossary entry to contain the page where the acronym list references the glossary entry.

MWE:

\documentclass{article}

\usepackage{hyperref}
\usepackage[acronym]{glossaries-extra}
\RestoreAcronyms

\newcommand*{\newdualentry}[5][]{%
\newglossaryentry{main-#2}{name={#4},%
description={#5},%
#1
}%
}

\newdualentry{svm}% label
{SVM}% abbreviation
{support vector machine}% long form
{Statistical pattern recognition technique}% description
\newacronym{FOO}{FOO}{This should still work}

\makeglossaries

\begin{document}

\gls{svm}. Also \gls{FOO}.

\newpage

\GlsXtrSetDefaultGlsOpts{noindex}

\printglossaries
\end{document}


The "support vector machine" entry in the glossary shall only have page 1 in its number list and the other acronym without accompanying glossary entry should still be usable.

What I have tried was the following rewrite of the command definition:

\newcommand*{\newdualentry}[5][]{%
\newglossaryentry{main-#2}{name={#4},%
description={#5},%
#1
}%
\newacronym{#2}{\gls[noindex=true]{main-#2}}{#4}
}


However, with this version, the long entry doesn't appear at all and it kills the automatic linking of page numbers.

\glsadd doesn't recognise the noindex key. (The purpose of \glsadd is to index without generating any text, so noindex doesn't make sense in this context.) This means that any instance of \glsadd that ends up in the glossary (through the short form appearing in the entry's name field) won't be affected by \GlsXtrSetDefaultGlsOpts{noindex}.

In this case a better approach would be to move \glsadd to the post-link hook which is done after commands like \gls. \newacronym sets the category to acronym by default, so the post-link hook is \glsxtrpostlinkacronym. (\newglossaryentry sets category to general by default, so the post-link hook for the main-svm entry is \glsxtrpostlinkgeneral instead.) Within the post-link hook, you can reference the entry label with \glslabel.

Then just redefine \glsxtrpostlinkacronym to do nothing before the glossaries in the event that \gls{svm} is used in any of the descriptions.

Modified MWE:

\documentclass{article}

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

\newcommand*{\newdualentry}[5][]{%
\newglossaryentry{main-#2}{name={#4},%
description={#5},%
#1
}%
\newacronym{#2}{#3}{#4}
}

\newdualentry{svm}% label
{SVM}% abbreviation
{support vector machine}% long form
{Statistical pattern recognition technique}% description

\makeglossaries

\begin{document}

\gls{svm}.

\newpage

\GlsXtrSetDefaultGlsOpts{noindex}

\printglossaries
\end{document}


If you have non-dual entries, you could set the category in \newdualentry to something other than the default acronym. For example:

\documentclass{article}

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

\setabbreviationstyle[dualacronym]{short}% change as appropriate

\newcommand*{\newdualentry}[5][]{%
\newglossaryentry{main-#2}{name={#4},%
description={#5},%
#1
}%
\newacronym[category=dualacronym]{#2}{#3}{#4}
}

\newdualentry{svm}% label
{SVM}% abbreviation
{support vector machine}% long form
{Statistical pattern recognition technique}% description

\newacronym{ex}{EX}{example}

\makeglossaries

\begin{document}

\gls{svm}. \gls{ex}.

\newpage

\GlsXtrSetDefaultGlsOpts{noindex}

• Thanks, this works well in my isolated test case. But I can't get this working in my main document. There, I get an error everytime I try to use an acronym with \gls: "Glossary entry main-XXX' has not been defined.". I can't find the difference. Porting over all special settings to example here doesn't produce this error. Any idea? Aug 18, 2017 at 8:12
• @languitar The post-link command is the place where \glsadd{main-XXX} is occurring. In your \newdualentry command, check that the first argument of \newglossaryentry (main-#2) matches the #2 label in \newacronym. Other things to check: are the definitions all in the preamble (or \input in the preamble)? Do you have nested link-text? Does the XXX part match the argument of \gls? What happens if you try doing \glsadd{main-XXX}` directly in your document? Aug 18, 2017 at 12:40