LaTeX forum ⇒ Theses, Books, Title pagesHyperref not going to the right place. Topic is solved

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

Hyperref not going to the right place.

Postby CMP » Thu Mar 26, 2020 4:34 am

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] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass[12pt,openany,letterpaper]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[round,sort,comma]{natbib}
  4. \newcounter{bibcount}
  5. \usepackage{hyperref,url}
  6. \usepackage{color}
  7. \usepackage[english]{babel}
  8. \usepackage[autostyle, english = american]{csquotes}
  9.  
  10. \newcommand{\red}{\color[rgb]{1,0,0}}
  11. \hypersetup{,colorlinks=true,allcolors=red}
  12.  
  13. \setlength\bibindent{10cm}
  14. \makeatletter
  15. \patchcmd{\@lbibitem}%
  16. {\item[}%
  17. {\item[\hfill\stepcounter{bibcount}{[\thebibcount]}}%
  18. {}%
  19. {}
  20. \patchcmd{\@lbibitem}%
  21. {\hfil \NAT@anchor {#2}{\NAT@num }]}%
  22. {]}
  23. {}
  24. {}
  25. \setlength{\bibhang}{2.00\parindent}
  26. \renewcommand\NAT@bibsetup[1]{%
  27. \setlength{\leftmargin}{\bibhang}%
  28. \setlength{\itemindent}{-\parindent}%
  29. \setlength{\itemsep}{\bibsep}%
  30. \setlength{\parsep}{\z@}}
  31. \makeatother
  32.  
  33. \bibliographystyle{unsrtnat}
  34.  
  35. \begin{document}
  36.  
  37. \vspace*{\fill}
  38. \begingroup
  39. \begin{center}
  40.  
  41. {\LARGE
  42. {\bf Title Page} \\[20pt]
  43. }
  44.  
  45. {\LARGE
  46. {\sc Spring 2020}
  47. }
  48.  
  49. \vspace{5cm}
  50.  
  51. {\LARGE
  52. {\LaTeX} Note
  53. }
  54.  
  55. \vspace{5cm}
  56.  
  57. {\LARGE
  58. {\em COVID--19}
  59. }
  60. \end{center}
  61. \endgroup
  62. \vspace*{\fill}
  63.  
  64. \newpage
  65.  
  66. \chapter{Chapter 1}
  67.  
  68. \section{Section 1}
  69.  
  70. Markov Chains \cite{n97}
  71.  
  72. \section{Section 2}
  73.  
  74. A graduate text in Mathematics \cite{ds14}
  75.  
  76. \chapter{Chapter 2}
  77.  
  78. \section{Section 1}
  79.  
  80. Probability and Measure Theory, \cite{MR1810041}.
  81.  
  82. \chapter{Chapter 3}
  83.  
  84. Algebra, \cite{MR1034353}.
  85.  
  86. \clearpage
  87. \bibliography{ref}
  88. \thispagestyle{plain}
  89. \pagestyle{plain} \thispagestyle{plain}
  90.  
  91. \end{document}


The corresponding ref.bib file is as below:

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. @book {MR1810041,
  2. AUTHOR = {Ash, Robert B.},
  3. TITLE = {Probability and Measure Theory},
  4. EDITION = {Second},
  5. NOTE = {With contributions by Catherine Dol{\'e}ans-Dade},
  6. PUBLISHER = {Harcourt/Academic Press, Burlington, MA},
  7. YEAR = {2000},
  8. PAGES = {xii+516},
  9. ISBN = {0-12-065202-1},
  10. MRCLASS = {28-01 (60-01)},
  11. MRNUMBER = {1810041},
  12. }
  13.  
  14. @article {MR1034353,
  15. AUTHOR = {Hungerford, Thomas W.},
  16. TITLE = {A counterexample in {G}alois theory},
  17. JOURNAL = {Amer. Math. Monthly},
  18. FJOURNAL = {American Mathematical Monthly},
  19. VOLUME = {97},
  20. YEAR = {1990},
  21. NUMBER = {1},
  22. PAGES = {54--57},
  23. ISSN = {0002-9890},
  24. MRCLASS = {12F10},
  25. MRNUMBER = {1034353},
  26. URL = {https://doi.org/10.2307/2324007},
  27. }
  28.  
  29. @book {n97,
  30. AUTHOR = {Norris, J. R.},
  31. TITLE = {Markov Chains},
  32. PUBLISHER = {Cambridge University Press},
  33. YEAR = {1997},
  34. DOI = {10.1017/CBO9780511810633},
  35. }
  36.  
  37. @book {ds14,
  38. AUTHOR = {Stroock, Daniel W.},
  39. TITLE = {An Introduction to Markov Processes},
  40. PUBLISHER = {Springer, Berlin, Heidelberg},
  41. EDITION = {Second},
  42. YEAR = {2014},
  43. ISBN = {978-3642405228},
  44. PAGES = {IX+275},
  45. DOI = {10.1007/978-3-642-40523-5},
  46. }


For example, when we click on "Ash (2000)" [img]
Ash.png
[/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!
Attachments
Ash.png
Ash.png (6.68 KiB) Viewed 319 times

User avatar
Ijon Tichy
Posts: 269
Joined: Mon Dec 24, 2018 10:12 am

Postby Ijon Tichy » Thu Mar 26, 2020 9:48 am

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:
Code: [Select all] [Expand/Collapse] [Download] (snapshottest.log)
  1. pdfTeX warning (dest): name{cite.MR1034353} has been referenced but does not exist, replaced by a fixed one
  2.  
  3. pdfTeX warning (dest): name{cite.MR1810041} has been referenced but does not exist, replaced by a fixed one
  4.  
  5. pdfTeX warning (dest): name{cite.ds14} has been referenced but does not exist, replaced by a fixed one
  6.  
  7. 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:
  1. \begin{filecontents*}{\jobname.bib}
  2. @book {MR1810041,
  3. AUTHOR = {Ash, Robert B.},
  4. TITLE = {Probability and Measure Theory},
  5. EDITION = {Second},
  6. NOTE = {With contributions by Catherine Dol{\'e}ans-Dade},
  7. PUBLISHER = {Harcourt/Academic Press, Burlington, MA},
  8. YEAR = {2000},
  9. PAGES = {xii+516},
  10. ISBN = {0-12-065202-1},
  11. MRCLASS = {28-01 (60-01)},
  12. MRNUMBER = {1810041},
  13. }
  14.  
  15. @article {MR1034353,
  16. AUTHOR = {Hungerford, Thomas W.},
  17. TITLE = {A counterexample in {G}alois theory},
  18. JOURNAL = {Amer. Math. Monthly},
  19. FJOURNAL = {American Mathematical Monthly},
  20. VOLUME = {97},
  21. YEAR = {1990},
  22. NUMBER = {1},
  23. PAGES = {54--57},
  24. ISSN = {0002-9890},
  25. MRCLASS = {12F10},
  26. MRNUMBER = {1034353},
  27. URL = {https://doi.org/10.2307/2324007},
  28. }
  29.  
  30. @book {n97,
  31. AUTHOR = {Norris, J. R.},
  32. TITLE = {Markov Chains},
  33. PUBLISHER = {Cambridge University Press},
  34. YEAR = {1997},
  35. DOI = {10.1017/CBO9780511810633},
  36. }
  37.  
  38. @book {ds14,
  39. AUTHOR = {Stroock, Daniel W.},
  40. TITLE = {An Introduction to Markov Processes},
  41. PUBLISHER = {Springer, Berlin, Heidelberg},
  42. EDITION = {Second},
  43. YEAR = {2014},
  44. ISBN = {978-3642405228},
  45. PAGES = {IX+275},
  46. DOI = {10.1007/978-3-642-40523-5},
  47. }
  48. \end{filecontents*}
  49. \documentclass[12pt,openany,letterpaper]{book}
  50. \usepackage[T1]{fontenc}
  51. \usepackage[round,sort,comma]{natbib}
  52. \newcounter{bibcount}
  53. \usepackage{color}
  54. \usepackage[english]{babel}
  55. \usepackage[autostyle, english = american]{csquotes}
  56. \usepackage{hyperref}% url is already loaded by hyperref, that should be
  57. % loaded as (almos) last package
  58.  
  59. \newcommand{\red}{\color[rgb]{1,0,0}}
  60. \hypersetup{,colorlinks=true,allcolors=red}
  61.  
  62. \setlength\bibindent{10cm}
  63. \makeatletter
  64. \patchcmd{\@lbibitem}%
  65. {\item[}%
  66. {\item[\hfill\stepcounter{bibcount}{[\thebibcount]}}%
  67. {}%
  68. {}
  69. \patchcmd{\@lbibitem}%
  70. {\hfil \NAT@anchor {#2}{\NAT@num }]}%
  71. {\hyper@natanchorstart{#2\@extra@b@citeb}\hyper@natanchorend]}% only hyper anchor generation
  72. {}
  73. {}
  74. \setlength{\bibhang}{2.00\parindent}
  75. \renewcommand\NAT@bibsetup[1]{%
  76. \setlength{\leftmargin}{\bibhang}%
  77. \setlength{\itemindent}{-\parindent}%
  78. \setlength{\itemsep}{\bibsep}%
  79. \setlength{\parsep}{\z@}}
  80. \makeatother
  81.  
  82. \bibliographystyle{unsrtnat}
  83.  
  84. \begin{document}
  85.  
  86. \begin{titlepage}\centering% use titlepage for title pages
  87. \vspace*{\fill}
  88.  
  89. {\LARGE
  90. {\bfseries Title Page} \\[20pt]% \bf is deprecated
  91. }
  92.  
  93. {\LARGE
  94. {\scshape Spring 2020}% \sc is deprecated
  95. \par% End paragraph before end of \LARGE
  96. }
  97.  
  98. \vspace{5cm}
  99.  
  100. {\LARGE
  101. {\LaTeX} Note
  102. \par% End paragraph before end of \LARGE
  103. }
  104.  
  105. \vspace{5cm}
  106.  
  107. {\LARGE
  108. {\em COVID--19}
  109. \par% End paragraph before end of \LARGE
  110. }
  111. \vspace*{\fill}
  112. \end{titlepage}
  113.  
  114. \chapter{First Chapter}
  115.  
  116. \section{Section 1}
  117.  
  118. Markov Chains \cite{n97}
  119.  
  120. \section{Section 2}
  121.  
  122. A graduate text in Mathematics \cite{ds14}
  123.  
  124. \chapter{Second Chapter}
  125.  
  126. \section{Section 1}
  127.  
  128. Probability and Measure Theory, \cite{MR1810041}.
  129.  
  130. \chapter{Chapter 3}
  131.  
  132. Algebra, \cite{MR1034353}.
  133.  
  134. \clearpage
  135. \bibliography{\jobname}
  136.  
  137. \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.

CMP
Posts: 9
Joined: Thu Aug 22, 2019 8:33 pm

Postby CMP » Thu Mar 26, 2020 11:43 pm

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


Return to “Theses, Books, Title pages”

Who is online

Users browsing this forum: No registered users and 2 guests