[Tex/LaTex] LaTeX glossary reference problem

glossarieshyperrefpage-numbering

In my master thesis, I use the glossaries package to keep track of all my abbreviations and symbols. To differ between the two, I made two different glossaries. One using the standard abbreviation package and one I defined myself, the symbol list (I used my own style because I needed four columns, one for the symbol, one for the units, one for the description and one for the pages).

I also use both a Roman and an Arabic numbering. When I click a reference in the (symbol) glossary, it redirects correctly to the location in the text. But when I click the (symbol) reference in the text, it redirects to the first page (instead of the correct location in the symbol list).

However, for the abbreviation list it does work correctly. The error must be in the definition of my new style. Even when you remove the change in numbering, it still redirects to the first page.

hyperrefname doesn't seem to solve the problem. How can I fix it?

I included a minimal working example (MWE) that you can run using all the packages and a Perl compiler.

\documentclass[a4paper]{book}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=Maroon, citecolor=ForestGreen, filecolor=magenta, urlcolor=magenta, hypertexnames=false}

%% Glossary properties
\usepackage[nomain,acronym,toc,section]{glossaries}
\newglossary{symbol}{sbl}{smb}{Symbols}
\usepackage{array}
\makeglossaries
\usepackage[xindy]{imakeidx}
\makeindex

%% My own glossary to display the units
\newglossarystyle{tabx4col}{%
% Put the glossary in a longtable environment:
\renewenvironment{theglossary}%
{\begin{longtable}{@{}p{0.12\textwidth}@{}p{0.12\textwidth}@{}p{0.56\textwidth}rp{0.15\textwidth}}}%
{\end{longtable}}%
\renewcommand*{\glossaryentryfield}[5]{%
\glstarget{\textbf{##1}}{\textbf{##2}}% Name
 & $[$\glsentryuseri{##1}$]$% Units
 & ##3% Description
 & ##5% Page list
        \\% end of row
}%
%% Nothing between groups:
\renewcommand*{\glsgroupskip}{}%
}

%% Abbreviations
\newacronym{abr1}{ABR1}{Abbreviation 1}
\newacronym{abr2}{ABR2}{Abbreviation 2}

%% Symbols
\newglossaryentry{sym1}
{%
  type=symbol,
  name={\ensuremath{\alpha}},
  description={The first symbol, with a very long description that spans multiple lines},
  user1={kg},
  sort=alpha
}
\newglossaryentry{sym2}
{%
  type=symbol,
  name={\ensuremath{\beta}},
  description={the second symbol},
  user1={m},
  sort=beta
}

\begin{document}
\pagenumbering{roman}
\tableofcontents
{\let\cleardoublepage\clearpage
    \chapter*{List of abbreviations and symbols}
    \addcontentsline{toc}{chapter}{List of abbreviations and Symbols}
    \printglossary[type=\acronymtype,title=Abbreviations,toctitle=Abbreviations]
    \printglossary[type=symbol,style=tabx4col]
}
\chapter{Introduction}
\pagenumbering{arabic}
\gls{abr1} \gls{abr2} \gls{sym1} \gls{sym2}
\chapter{First chapter}
\gls{abr1} \gls{abr2} \gls{sym1} \gls{sym2}
\end{document}

Best Answer

The test file generates multiple warnings from hyperref along the lines:

pdfTeX warning (dest): name{glo:sym1} has been referenced but does not exist, 
replaced by a fixed one

which is somewhat cryptic, but with glossaries this can mean that something has gone wrong with glossaries hyperlink target mechanism. The non-existence of this link is what's causing the hyperlink to take you to the first page of the document. The command \glstarget sets up this hyperlink in the glossary style. The first argument must be the entry's label, and here's the problem:

\glstarget{\textbf{##1}}{\textbf{##2}}% Name

The \textbf in the first argument is confusing the target mechanism. You just need to remove it to get rid of the problem:

\glstarget{##1}{\textbf{##2}}% Name