Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
Welcome to tex.sx. I marked down your code. Enclose code in backticks `like this` or use the 101010 button to mark text. –  Seamus Mar 16 '11 at 15:49
add comment

3 Answers

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....

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

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.

share|improve this answer
    
Hmm, this is a very inconvenient workaround as I have to do so whenever I run bibtex, but thanks anyway. –  user4276 Mar 16 '11 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. –  Gonzalo Medina Mar 16 '11 at 20:35
1  
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 '11 at 15:07
    
@LevBishop: you're right. –  Gonzalo Medina Nov 23 '11 at 17:06
add comment

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

\usepackage{hypernat} 

and you should be good.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.