# Page number of glossary while using hyperref

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}

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

\printglossaries

\end{document}

-
With the hyperref package you can use \autopageref{main} instead of page~\pageref{main}. – mhp Mar 28 '12 at 8:38

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}

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.

-
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
@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
@mmm: The label is added to each defined glossary. So, \pageref{acronym} etc. should work, too. – mhp Jul 13 '12 at 12:58

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}
The glossary starts on page~\pageref{glossaries}.
\cleardoublepage
\phantomsection <------------------- here
\label{glossaries}<-----------------and here
\printglossaries
%-------------------------------------------------------
\end{document}


The Glossary page looks like this:

-
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

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}