Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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}
share|improve this answer
    
Thanks! It works, but I had to add the numberedsection=autolabel option to \usepackage{glossaries}. –  daniel kullmann Jan 5 '12 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 '12 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? –  daniel kullmann Jan 5 '12 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 '12 at 21:13
    
I'm using memoir documentclass, so maybe that is the reason it works for me. –  daniel kullmann Jan 5 '12 at 21:20
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.