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 in the text. The solution given to this question on this website works for me. But adding \usepackage{hyperref} before \usepackage{glossaries} makes it not work anymore (the output is "The glossary starts on page ??"). How can I reference the page the glossary is on while also using the hyperref package?

\documentclass{book}

\usepackage{hyperref}

\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 question
    
With the hyperref package you can use \autopageref{main} instead of page~\pageref{main}. –  mhp Mar 28 '12 at 8:38
add comment

3 Answers

up vote 5 down vote accepted

I’d suggest the following simple solution based on redefining \glossarypreamble:

\documentclass{book}

\usepackage{hyperref}

\usepackage{glossaries}

\makeglossaries

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

\renewcommand*{\glossarypreamble}{%
  \label{\currentglossary}%
}

\begin{document}

Some text about \gls{electrolyte}.

The glossary starts on \autopageref{main}.

\printglossaries

\end{document}

Alternatively, you could load the glossaries package with

\usepackage[numberedsection=autolabel]{glossaries}

In this case, the glossary sections are numbered, though.

share|improve this answer
    
This works, thanks! –  debbie Mar 28 '12 at 17:28
    
Thanks mhp. This way the reference displays as "page XX". Is there a way to omit the word "page" and just display the page number? –  mmm Jul 13 '12 at 9:51
1  
@mmm: Simply use \pageref instead of \autopageref. –  mhp Jul 13 '12 at 12:18
    
Thanks. I noticed I'm referencing the first glossary this way. I added two additional glossaries using \newglossary in my document - can those be referenced separately? –  mmm Jul 13 '12 at 12:37
1  
@mmm: The label is added to each defined glossary. So, \pageref{acronym} etc. should work, too. –  mhp Jul 13 '12 at 12:58
add comment

You have to create a mark for referencing and this can be done by \phantomsection

\documentclass{book}
\usepackage{hyperref}
\usepackage{glossaries}
\makeglossaries
%-------------------------------------------------------
\newglossaryentry{electrolyte}{name=electrolyte,%
    description={solution able to conduct electric current}}
%-------------------------------------------------------
\begin{document}
Some text about \gls{electrolyte}.
The glossary starts on page~\pageref{glossaries}.
\cleardoublepage
\phantomsection <------------------- here
\label{glossaries}<-----------------and here
\printglossaries
%-------------------------------------------------------
\end{document}

enter image description here

The Glossary page looks like this:

enter image description here

share|improve this answer
    
Fabulous, this is perfect. Thanks! –  debbie Mar 28 '12 at 6:21
    
For me, the actual glossary start at page 5 in your example. –  lockstep Mar 28 '12 at 6:24
    
@lockstep, I do not understand. I get it at page 3. Pl. see the picture. –  Harish Kumar Mar 28 '12 at 6:48
    
Whoops, sorry I'm pretty new to this. Your solution works, but I think I'm going to mark one of the others as "the answer" just because they allow you to reference the main glossary and the acronyms separately, so it seems a bit better. Unless I can select more than one green check mark? Thank you for your help. –  debbie Mar 28 '12 at 17:26
add comment

For a solution that works with hyperref and (as my original one) does without modifications in the document body, you have to patch \@p@glossarysection instead of \@glossarysection.

\documentclass{book}

\usepackage{hyperref}

\usepackage{glossaries}
\makeglossaries

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@p@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
    
This works, thank you so much for the help. I'm going to mark mhp's answer as my "selected answer", just because it does the same thing but seems a little simpler. Unless I can select more than one answer. Thank you! –  debbie Mar 28 '12 at 17:27
    
@debbie It's up to you which answer to accept, but you can (and should) upvote all "helpful" answers -- note that upvoting is different from accepting. –  lockstep Mar 28 '12 at 17:31
    
OK, thanks for the tip. I'm pretty new to all this. –  debbie Mar 28 '12 at 17:33
add comment

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.