Theses, Books, Title pagesHyperref not going to the right place.

Classicthesis, Bachelor and Master thesis, PhD, Doctoral degree
Post Reply
CMP
Posts: 13
Joined: Thu Aug 22, 2019 8:33 pm

Hyperref not going to the right place.

Post by CMP »

I am managing Bibliography via "natbib" package but eventually when I click on the cited reference in the main document then it does not direct to the proper number in the Bibliography section. But it just go back to the front page.

Here is my MWE:

Code: Select all

\documentclass[12pt,openany,letterpaper]{book}
\usepackage[T1]{fontenc}
\usepackage[round,sort,comma]{natbib}
\newcounter{bibcount}
\usepackage{hyperref,url}
\usepackage{color}
\usepackage[english]{babel}
\usepackage[autostyle, english = american]{csquotes}

\newcommand{\red}{\color[rgb]{1,0,0}}
\hypersetup{,colorlinks=true,allcolors=red}

\setlength\bibindent{10cm}
\makeatletter
\patchcmd{\@lbibitem}%
{\item[}%
{\item[\hfill\stepcounter{bibcount}{[\thebibcount]}}%
{}%
{}
\patchcmd{\@lbibitem}%
{\hfil \NAT@anchor {#2}{\NAT@num }]}%
{]}
{}
{}
\setlength{\bibhang}{2.00\parindent}
\renewcommand\NAT@bibsetup[1]{%
	\setlength{\leftmargin}{\bibhang}%
	\setlength{\itemindent}{-\parindent}%
	\setlength{\itemsep}{\bibsep}%
	\setlength{\parsep}{\z@}}
\makeatother

\bibliographystyle{unsrtnat}

\begin{document}

\vspace*{\fill}
\begingroup
\begin{center}

{\LARGE
    {\bf Title Page} \\[20pt]
}

{\LARGE
    {\sc Spring 2020}
}

\vspace{5cm}

{\LARGE
    {\LaTeX} Note
}

\vspace{5cm}

{\LARGE
    {\em COVID--19}
}
\end{center}
\endgroup
\vspace*{\fill}

\newpage 

\chapter{Chapter 1} 

\section{Section 1} 

Markov Chains \cite{n97}

\section{Section 2}

A graduate text in Mathematics \cite{ds14} 

\chapter{Chapter 2} 

\section{Section 1} 

Probability and Measure Theory, \cite{MR1810041}.

\chapter{Chapter 3} 

Algebra, \cite{MR1034353}.

\clearpage 
\bibliography{ref}
\thispagestyle{plain}
\pagestyle{plain} \thispagestyle{plain}

\end{document}
The corresponding ref.bib file is as below:

Code: Select all

@book {MR1810041,
    AUTHOR = {Ash, Robert B.},
     TITLE = {Probability and Measure Theory},
   EDITION = {Second},
      NOTE = {With contributions by Catherine Dol{\'e}ans-Dade},
 PUBLISHER = {Harcourt/Academic Press, Burlington, MA},
      YEAR = {2000},
     PAGES = {xii+516},
      ISBN = {0-12-065202-1},
   MRCLASS = {28-01 (60-01)},
  MRNUMBER = {1810041},
}

@article {MR1034353,
AUTHOR = {Hungerford, Thomas W.},
TITLE = {A counterexample in {G}alois theory},
JOURNAL = {Amer. Math. Monthly},
FJOURNAL = {American Mathematical Monthly},
VOLUME = {97},
YEAR = {1990},
NUMBER = {1},
PAGES = {54--57},
ISSN = {0002-9890},
MRCLASS = {12F10},
MRNUMBER = {1034353},
URL = {https://doi.org/10.2307/2324007},
}

@book {n97, 
    AUTHOR = {Norris, J. R.},
     TITLE = {Markov Chains}, 
 PUBLISHER = {Cambridge University Press},
      YEAR = {1997},
       DOI = {10.1017/CBO9780511810633},
}

@book {ds14, 
   AUTHOR = {Stroock, Daniel W.},
    TITLE = {An Introduction to Markov Processes}, 
PUBLISHER = {Springer, Berlin, Heidelberg},
  EDITION = {Second}, 
     YEAR = {2014},
     ISBN = {978-3642405228},
    PAGES = {IX+275},
    DOI = {10.1007/978-3-642-40523-5},
}
For example, when we click on "Ash (2000)" [img]
Ash.png
Ash.png (6.68 KiB) Viewed 10626 times
[/img]on page 3 it should go to #3 in the Bibliography section but instead the document pop up to the first page.

I am wondering what is going wrong here and how to fix it.

Thank you!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Hyperref not going to the right place.

Post by Ijon Tichy »

What happened is, that you're patch removed \NAT@anchor, which not only prints the your-year label but also adds the hyper anchor. That they are missing is reported in the log-file:
pdfTeX warning (dest): name{cite.MR1034353} has been referenced but does not exist, replaced by a fixed one

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

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

pdfTeX warning (dest): name{cite.n97} has been referenced but does not exist, replaced by a fixed one
After re-adding at least the hyper anchor generation from NAT@anchor, the links are correct:
\begin{filecontents*}{\jobname.bib}
    @book {MR1810041,
        AUTHOR = {Ash, Robert B.},
         TITLE = {Probability and Measure Theory},
       EDITION = {Second},
          NOTE = {With contributions by Catherine Dol{\'e}ans-Dade},
     PUBLISHER = {Harcourt/Academic Press, Burlington, MA},
          YEAR = {2000},
         PAGES = {xii+516},
          ISBN = {0-12-065202-1},
       MRCLASS = {28-01 (60-01)},
      MRNUMBER = {1810041},
    }
     
    @article {MR1034353,
    AUTHOR = {Hungerford, Thomas W.},
    TITLE = {A counterexample in {G}alois theory},
    JOURNAL = {Amer. Math. Monthly},
    FJOURNAL = {American Mathematical Monthly},
    VOLUME = {97},
    YEAR = {1990},
    NUMBER = {1},
    PAGES = {54--57},
    ISSN = {0002-9890},
    MRCLASS = {12F10},
    MRNUMBER = {1034353},
    URL = {https://doi.org/10.2307/2324007},
    }
     
    @book {n97, 
        AUTHOR = {Norris, J. R.},
         TITLE = {Markov Chains}, 
     PUBLISHER = {Cambridge University Press},
          YEAR = {1997},
           DOI = {10.1017/CBO9780511810633},
    }
     
    @book {ds14, 
       AUTHOR = {Stroock, Daniel W.},
        TITLE = {An Introduction to Markov Processes}, 
    PUBLISHER = {Springer, Berlin, Heidelberg},
      EDITION = {Second}, 
         YEAR = {2014},
         ISBN = {978-3642405228},
        PAGES = {IX+275},
        DOI = {10.1007/978-3-642-40523-5},
    }
\end{filecontents*}
\documentclass[12pt,openany,letterpaper]{book}
\usepackage[T1]{fontenc}
\usepackage[round,sort,comma]{natbib}
\newcounter{bibcount}
\usepackage{color}
\usepackage[english]{babel}
\usepackage[autostyle, english = american]{csquotes}
\usepackage{hyperref}% url is already loaded by hyperref, that should be
                     % loaded as (almos) last package

\newcommand{\red}{\color[rgb]{1,0,0}}
\hypersetup{,colorlinks=true,allcolors=red}

\setlength\bibindent{10cm}
\makeatletter
\patchcmd{\@lbibitem}%
{\item[}%
{\item[\hfill\stepcounter{bibcount}{[\thebibcount]}}%
{}%
{}
\patchcmd{\@lbibitem}%
{\hfil \NAT@anchor {#2}{\NAT@num }]}%
{\hyper@natanchorstart{#2\@extra@b@citeb}\hyper@natanchorend]}% only hyper anchor generation
{}
{}
\setlength{\bibhang}{2.00\parindent}
\renewcommand\NAT@bibsetup[1]{%
    \setlength{\leftmargin}{\bibhang}%
    \setlength{\itemindent}{-\parindent}%
    \setlength{\itemsep}{\bibsep}%
    \setlength{\parsep}{\z@}}
\makeatother

\bibliographystyle{unsrtnat}

\begin{document}

\begin{titlepage}\centering% use titlepage for title pages
\vspace*{\fill}

{\LARGE
    {\bfseries Title Page} \\[20pt]% \bf is deprecated
}

{\LARGE
  {\scshape Spring 2020}% \sc is deprecated
  \par% End paragraph before end of \LARGE
}

\vspace{5cm}

{\LARGE
    {\LaTeX} Note
  \par% End paragraph before end of \LARGE
}

\vspace{5cm}

{\LARGE
    {\em COVID--19}
  \par% End paragraph before end of \LARGE
}
\vspace*{\fill}
\end{titlepage}

\chapter{First Chapter} 

\section{Section 1} 

Markov Chains \cite{n97}

\section{Section 2}

A graduate text in Mathematics \cite{ds14} 

\chapter{Second Chapter} 

\section{Section 1} 

Probability and Measure Theory, \cite{MR1810041}.

\chapter{Chapter 3} 

Algebra, \cite{MR1034353}.

\clearpage 
\bibliography{\jobname}

\end{document}
BTW: IMHO such mixture of author-year style in the text and numeric style in the bibliography does not make much sense. Because, if the numbers in the bibliography are not referenced, they are superfluously. And searching for the correct entry in the bibliography is hard, because the distance between name and year is not only wide but also differs from entry to entry. So if you are not forced to use such a mixture, I would recommend to use either a author-year style of a numeric one but not such a mixture.

BTW: Usage of biblatex + biber would not only allow to use UTF-8 also for the bib-file but mostly provide much more features and configurability without bst-hacking. Because of this, in our days, it is often recommended to use biblatex and biber instead of natbib and BibTeX.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
CMP
Posts: 13
Joined: Thu Aug 22, 2019 8:33 pm

Hyperref not going to the right place.

Post by CMP »

Thank you very much, Ijon Tichy!

It really solved my problem.

I do not use author-year citation in the document and numbers at the end in my research.
But usually for class room materials, I use it just for simplicity to talk about
the materials in some references by referring to the number.

I greatly appreciate for all the additional comments you made there including hacking issue.

One more request, could you please recommend me an excellent reference book(s)
which could be very helpful to keep in our shelve and make it handy whenever we
need?

Thanks aagain!

CMP
Post Reply