17

I am using the glossaries package a lot in my thesis. There are some entries which appear very frequently throughout the whole document. I would like to disable hyperlinking for these entries but keep it for all other entries.

I have tried putting \glsdisablehyper just before the frequent entries to no avail.

1
  • 4
    \glsdisablehyper worked for me, oddly enough.
    – user2699
    Feb 26, 2019 at 20:30

3 Answers 3

14

For these "frequently appearing" entries use the starred versions of glossaries' user commands (e.g. \gls*) which suppress hyperlinks.

\documentclass{article}

\usepackage{hyperref}

\usepackage{glossaries}
\makeglossaries

\newglossaryentry{electrolyte}{name=electrolyte,
    description={solution able to conduct electric current}}

\newglossaryentry{pi}{name={\ensuremath{\pi}},
    description={ratio of circumference of circle to its diameter},sort=pi}

\begin{document}

Some text about \gls{electrolyte} and \gls*{pi}.

\printglossaries

\end{document}
1
  • 11
    Is there anyway to disable them (from the command definition?), as I don't want to go through the document and change them all. Thanks for the answer by the way Aug 17, 2011 at 1:32
16

If you upgrade to the latest version of glossaries (v4.09 at time of writing), you can hook into the mechanism that sets the default value of the hyper key when using an entry. Here's a simple example that just disables the hyperlink for a specific entry (ut):

\documentclass{article}

\usepackage[colorlinks]{hyperref}

\usepackage{glossaries}
\makeglossaries

% dummy entries copied from example-glossaries-brief.tex

\newglossaryentry{lorem}{name={lorem},description={ipsum}}

\newglossaryentry{dolor}{name={dolor},description={sit}}

\newglossaryentry{amet}{name={amet},description={consectetuer}}

\newglossaryentry{adipiscing}{name={adipiscing},description={elit}}

\newglossaryentry{ut}{name={ut},description={purus}}

\newglossaryentry{elit}{name={elit},description={vestibulum}}


\renewcommand*{\glslinkcheckfirsthyperhook}{%
 \ifdefstring\glslabel{ut}%
 {\setkeys{glslink}{hyper=false}}%
 {}%
}

\begin{document}

Use the entries: \gls{lorem}, \gls{dolor}, \gls{amet},
\gls{adipiscing}, \gls{ut}, \gls{elit}.

Use the entries again: \gls{lorem}, \gls{dolor}, \gls{amet},
\gls{adipiscing}, \gls{ut}, \gls{elit}.

Force the hyperlink on: \gls+{ut} or \gls[hyper=true]{ut}.

\printglossaries

\end{document}

This produces:

Image of resulting document

For a more generalised solution, you could have a list of all the labels of entries that shouldn't have a hyperlink (using, for example, the internal list macros provided by etoolbox) or you could use, say, the user1 key when defining the entry to identify it as one that shouldn't have a hyperlink. For example:

\documentclass{article}

\usepackage[colorlinks]{hyperref}

\usepackage{glossaries}
\makeglossaries

% dummy entries copied from example-glossaries-brief.tex

\newglossaryentry{lorem}{name={lorem},description={ipsum}}

\newglossaryentry{dolor}{name={dolor},description={sit},user1={off}}

\newglossaryentry{amet}{name={amet},description={consectetuer},user1={off}}

\newglossaryentry{adipiscing}{name={adipiscing},description={elit}}

\newglossaryentry{ut}{name={ut},description={purus},user1={off}}

\newglossaryentry{elit}{name={elit},description={vestibulum}}


\renewcommand*{\glslinkcheckfirsthyperhook}{%
 % Get the value of the user1 field
 \glsletentryfield{\thisvalue}{\glslabel}{useri}%
 % Test this value
 \ifdefstring\thisvalue{off}%
 {\setkeys{glslink}{hyper=false}}%
 {}%
}

\begin{document}

Use the entries: \gls{lorem}, \gls{dolor}, \gls{amet},
\gls{adipiscing}, \gls{ut}, \gls{elit}.

Use the entries again: \gls{lorem}, \gls{dolor}, \gls{amet},
\gls{adipiscing}, \gls{ut}, \gls{elit}.

Force the hyperlink on: \gls+{ut} or \gls+{dolor}.

\printglossaries

\end{document}

This produces:

Image of resulting document

Another possibility is to allow the hyperlink on first use and then disable it for subsequent use:

\documentclass{article}

\usepackage[colorlinks]{hyperref}

\usepackage{glossaries}
\makeglossaries

% dummy entries copied from example-glossaries-brief.tex

\newglossaryentry{lorem}{name={lorem},description={ipsum}}

\newglossaryentry{dolor}{name={dolor},description={sit},user1={off}}

\newglossaryentry{amet}{name={amet},description={consectetuer},user1={off}}

\newglossaryentry{adipiscing}{name={adipiscing},description={elit}}

\newglossaryentry{ut}{name={ut},description={purus},user1={off}}

\newglossaryentry{elit}{name={elit},description={vestibulum}}


\renewcommand*{\glslinkcheckfirsthyperhook}{%
  \ifglsused{\glslabel}
  {%
    % Get the value of the user1 field
    \glsletentryfield{\thisvalue}{\glslabel}{useri}%
    % Test this value
    \ifdefstring\thisvalue{off}%
   {\setkeys{glslink}{hyper=false}}%
   {}%
  }%
  {}%
}

\begin{document}

Use the entries: \gls{lorem}, \gls{dolor}, \gls{amet},
\gls{adipiscing}, \gls{ut}, \gls{elit}.

Use the entries again: \gls{lorem}, \gls{dolor}, \gls{amet},
\gls{adipiscing}, \gls{ut}, \gls{elit}.

Force the hyperlink on: \gls+{ut} or \gls+{dolor}.

\printglossaries

\end{document}

This produces:

Image of resulting document

Edit: A simpler method is provided with the glossaries-extra extension package. With this package you can assign a category to each entry. The default value is general but can be overridden through the use of the category key. This is just a label (avoid special characters) used to identify particular groups of entries independent of the identifiers type and parent. (For example, \newabbreviation sets the category to abbreviation and \newacronym sets the category to acronym.)

Categories can have associated attributes. The nohyper attribute indicates that the hyperlink should default to off for those entries. For example, I can have a common category (indicating common terms) that has the nohyper attribute on:

\documentclass{article}

\usepackage[colorlinks]{hyperref}

\usepackage{glossaries-extra}
\makeglossaries

\glssetcategoryattribute{common}{nohyper}{true}

% dummy entries copied from example-glossaries-brief.tex

\newglossaryentry{lorem}{name={lorem},description={ipsum}}

\newglossaryentry{dolor}{name={dolor},description={sit},category={common}}

\newglossaryentry{amet}{name={amet},description={consectetuer},category={common}}

\newglossaryentry{adipiscing}{name={adipiscing},description={elit}}

\newglossaryentry{ut}{name={ut},description={purus},category={common}}

\newglossaryentry{elit}{name={elit},description={vestibulum}}

\begin{document}

Use the entries: \gls{lorem}, \gls{dolor}, \gls{amet},
\gls{adipiscing}, \gls{ut}, \gls{elit}.

Use the entries again: \gls{lorem}, \gls{dolor}, \gls{amet},
\gls{adipiscing}, \gls{ut}, \gls{elit}.

Force the hyperlink on: \gls+{ut} or \gls+{dolor}.

\printglossaries

\end{document}
1

You can define during the creation of the acronym/glossaryentry if the page numbers shall be listed in the end by setting the nonumber option to true. Using glossaries-extra this could look like this:

\newabbreviation[nonumberlist=true]{foo}{Foo}{Foo description}
\longnewglossaryentry{bar}{name={Bar},nonumberlist=true}{Bar description}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .