8

I want to reference the glossary from within the text (I'm using the glossaries package). However, since the glossaries are produced using \printglossaries, I can't just put a \label command where it needs to be. Putting a \label command just before or just after the \printglossaries command doesn't work: It gives the wrong page number.

I browsed through the glossaries manual, but didn't find anything about labels or references.

1 Answer 1

5

Use the etoolbox package to patch glossaries' internal \@glossarysection macro.

EDIT: In case you were wondering what \@@glossaryseclabel is doing: If you load the glossaries package with the numberedsection=autolabel option, glossaries will a) be numbered b) feature an automatic label that uses the glossary type. In this case you could refer to the different glossaries with, e.g., \ref{main} or \pageref{acronym}. See section 2.2. of the glossaries manual for details. For unnumbered glossaries, use my hack below. (Naturally, \refwon't work correctly because there's no sectioning number to refer to, but \pageref will.)

\documentclass{book}

\usepackage{glossaries}
\makeglossaries

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@glossarysection}{%
  \@@glossaryseclabel%
}{%
  \@@glossaryseclabel%
  \label{\glsautoprefix\@glo@type}% "main" for main glossary, "acronym" for list of acronyms
}{}{}
\makeatother

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

\begin{document}

Some text about \gls{electrolyte}.

The glossary starts on page~\pageref{main}.

\printglossaries

\end{document}
7
  • Thanks! It works, but I had to add the numberedsection=autolabel option to \usepackage{glossaries}. Jan 5, 2012 at 9:55
  • @danielkullmann Please try again -- the whole point of my hack is to make at least \pageref work for unnumbered glossaries.
    – lockstep
    Jan 5, 2012 at 9:58
  • The new version works for me as well, but again only with numberedsection=autolabel. And my glossary is still unnumbered, maybe because I also have the option nonumberlist? Jan 5, 2012 at 21:09
  • @danielkullmann I tried again, but even with both options, my glossary is numbered. For now I suggest: If it works for you ... ;-)
    – lockstep
    Jan 5, 2012 at 21:13
  • I'm using memoir documentclass, so maybe that is the reason it works for me. Jan 5, 2012 at 21:20

You must log in to answer this question.

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