2

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},%
  text={#3\glsadd{#2}},%
  description={#5},%
  #1
  }%
  \newacronym{#2}{#3\glsadd{main-#2}}{#4}
}

\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.

enter image description here

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

\newcommand*{\newdualentry}[5][]{%
  \newglossaryentry{main-#2}{name={#4},%
  text={#3\glsadd{#2}},%
  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.

2

\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{\glsxtrpostlinkacronym}{\glsadd{main-\glslabel}}

\newcommand*{\newdualentry}[5][]{%
  \newglossaryentry{main-#2}{name={#4},%
  text={#3\glsadd{#2}},%
  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}
\renewcommand{\glsxtrpostlinkacronym}{}

\printglossaries
\end{document}

image of glossaries

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{\glsxtrpostlinkdualacronym}{\glsadd{main-\glslabel}}

\newcommand*{\newdualentry}[5][]{%
  \newglossaryentry{main-#2}{name={#4},%
  text={#3\glsadd{#2}},%
  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}
\renewcommand{\glsxtrpostlinkdualacronym}{}

\printglossaries
\end{document}
  • 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? – languitar Aug 18 '17 at 8:12
  • This error appears as soon as I defined the post-link command. – languitar Aug 18 '17 at 8:12
  • 1
    @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? – Nicola Talbot Aug 18 '17 at 12:40
  • Yikes, I see the issue. I have also acronyms, which do not have an accompanying full entry in the glossary. So I would need some way to restrict the link magic only to acronyms defined with the dual command. – languitar Aug 18 '17 at 14:09
  • I have updated the question to include such a case. – languitar Aug 18 '17 at 14:13

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.