10

I encountered an issue when using the backref=page option of the hyperref package together with the natbib package with the options square,sort&compress,numbers.
If the natbib package compresses a range of references, the middle references does not show the backreference after compiling (latex,bibtex,latex,latex).

See the following short example:

\documentclass{article}  
\usepackage[square,sort&compress,numbers]{natbib}  
\usepackage[backref=page]{hyperref}

\begin{document}  
\cite{foo,bar,hole}

\begin{thebibliography}{ab}  
\bibitem{foo} foo

\bibitem{bar} bar

\bibitem{hole} hole

\end{thebibliography}  
\end{document}
0

3 Answers 3

11

Make the following patch to natbib.sty:

--- natbib.sty.old 2009-07-23 10:44:10.000000000 -0400
+++ natbib.sty  2009-11-01 17:07:53.309765500 -0500
@@ -408,6 +408,7 @@
         \@ifnum{\NAT@nm=\@tempcnta}{%
          \@ifnum{\NAT@merge>\@ne}{}{\NAT@last@yr@mbox}%
         }{%
+           \Hy@backout{\@citeb\@extra@b@citeb}%
           \advance\@tempcnta by\@ne
           \@ifnum{\NAT@nm=\@tempcnta}{%
             \ifx\NAT@last@yr\relax

I have reported this to the authors of hyperref and natbib. Heiko (author of hyperref) wants this to be fixed in natbib, because this is too deeply buried in the natbib code for him to feel comfortable patching it. Patrick (author of natbib) has not responded to my emails....

4
  • Wouldn't \@ifundefined{Hy@backout}{}{\@citeb\@extra@b@citeb}} make it work even without hyperref?
    – egreg
    Nov 22, 2011 at 23:17
  • 1
    @egreg, that doesn't seem right. Maybe you mean \@ifundefined{Hy@backout}{}{\Hy@backout{\@citeb\@extra@b@citeb}}?
    – Lev Bishop
    Nov 23, 2011 at 15:04
  • Yes, of course; I forgot a bit.
    – egreg
    Nov 23, 2011 at 15:43
  • 1
    it's probably easiest to just use the hypernat package
    – levinalex
    Jan 21, 2014 at 21:02
4

There's the hypernat package that includes the patch from Lev Bishop's answer

\usepackage{hypernat} 

and you should be good.

1
  • this solves the question. Maybe we should mark this answer as solution?
    – Hug
    Sep 16, 2014 at 9:59
1

Delete the auxiliary files. Supress the option sort&compress and then compile your document as many times as needed in order to generate the citations with their back references; then, add the sort&compress option and compile once more to sort and compress the citation list.

4
  • Hmm, this is a very inconvenient workaround as I have to do so whenever I run bibtex, but thanks anyway.
    – user4276
    Mar 16, 2011 at 18:15
  • @adw: it is not so inconvenient (although I understand what you mean): load natbib like this: First line:\usepackage[square,numbers%,sort&compress% Second line: ]{natbib} process your document. running (pdf)latex+bibtex+(pdf)latex+(pdf)latex, now uncomment out the option (delete the leftmost %) and run (pdf)latex once more. Mar 16, 2011 at 20:35
  • 2
    This approach can cause problems. If adding the sort&compress changes the pagination (which it certainly can) then you would need to run latex several times for those pagination updates to propagate through to the pagebackrefs (not to mentions table of contents, list of figures, index, \pageref{}, etc.)
    – Lev Bishop
    Nov 23, 2011 at 15:07
  • @LevBishop: you're right. Nov 23, 2011 at 17:06

You must log in to answer this question.