GeneralPage numbers to refs: Adding the word 'page' to pagebackref

LaTeX specific issues not fitting into one of the other forums of this category.
autonomouse
Posts: 6
Joined: Sun Jan 11, 2009 4:51 pm

Page numbers to refs: Adding the word 'page' to pagebackref

Post by autonomouse »

Hi,

I'm writing my Phd thesis and I want to include links from my references to the pages where they are cited.

I trawled the internet and found a way to do it using the hyperref package with pagebackref=true as shown here:

Code: Select all

\usepackage[pagebackref=true]{hyperref} % Produces hyperlinks and page numbers to refs 
\hypersetup{	pdfborder={0 0 0},    
		        colorlinks = false}% hyperref customisation
\usepackage{natbib}
The problem is that it just adds the page number preceded by a comma and nothing else, which is very confusing if the reference ends in numbers (say the volume and page numbers of the journal its from) anyway.

For example, I cited Wilson1983 on page 77 and in the references, it looks like this:

Wilson, C. J., Chang, H. T., and Kitai, S. T. (1983). Disfacilitation and long-lasting inhibition of neostriatal neurons in the rat. Exp Brain Res, 51(2):227–235. 6, 77

When I actually want it to look more like this:

Wilson, C. J., Chang, H. T., and Kitai, S. T. (1983). Disfacilitation and long-lasting inhibition of neostriatal neurons in the rat. Exp Brain Res, 51(2):227–235. 6 (page 77)

It's a very simple addition of the word 'page' before the number and maybe some brackets, but I can't seem to find a way to do it. The only thing remotely close is to set colorlinks = true and have the page number in red, but that wont look very professional in a thesis.

Any ideas?

Thanks!
Autonomouse

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Page numbers to refs: Adding the word 'page' to pagebackref

Post by gmedina »

Hi,

you could redefine \backref:

Code: Select all

\renewcommand*\backref[1]{\ifx#1\relax \else (page #1) \fi}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
autonomouse
Posts: 6
Joined: Sun Jan 11, 2009 4:51 pm

Page numbers to refs: Adding the word 'page' to pagebackref

Post by autonomouse »

you could redefine \backref:
\renewcommand*\backref[1]{\ifx#1\relax \else (page #1) \fi}
Wow - I should have posted here about 3 hours ago and saved myself a lot of fruitless googling.

Thanks a lot, gmedina.

Would you mind just explaining what you did there though please? It works, but I've no idea how...
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Page numbers to refs: Adding the word 'page' to pagebackref

Post by gmedina »

autonomouse wrote:...Would you mind just explaining what you did there though please? It works, but I've no idea how...
No problem. The only argument of \backref consists of a a comma separated list of backref references. The redefinition I made simply tests if backreferences exist, and if so, it then adds the word "page" and encloses "page" and the the \backref's argument (the list) in parenthesis.

More information on formatting the backreferences list can be found in the backref documentation.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
autonomouse
Posts: 6
Joined: Sun Jan 11, 2009 4:51 pm

Re: Page numbers to refs: Adding the word 'page' to pagebackref

Post by autonomouse »

many thanks
autonomouse
Posts: 6
Joined: Sun Jan 11, 2009 4:51 pm

Re: Page numbers to refs: Adding the word 'page' to pagebackref

Post by autonomouse »

Oh sorry, one more thing...

At the minute it says "(page 1)" or "(page 1, 2, 3,4)" etc, but can you think of a way to make it use "page" when there's one ref, but "pages" when there's more than one, and also, which might be a bit harder, if there are multiple contiguous numbers is there a way to make it say "(pages 1-4)", for example?

Thanks again!
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Page numbers to refs: Adding the word 'page' to pagebackref

Post by gmedina »

autonomouse wrote:...At the minute it says "(page 1)" or "(page 1, 2, 3,4)" etc, but can you think of a way to make it use "page" when there's one ref, but "pages" when there's more than one,...
In this case you can use the \backrefalt hook as described in the documentation that I already linked to. Take a look at the following simple example:

Code: Select all

\documentclass{article}
\usepackage[pagebackref=true]{hyperref}
\hypersetup{   pdfborder={0 0 0},   
              colorlinks = false}
\renewcommand*{\backreflastsep}{, }
\renewcommand*{\backreftwosep}{, }
\renewcommand*{\backref}[1]{}
\renewcommand*{\backrefalt}[4]{%
  \ifcase #1 %
    No citations.% use \relax if you do not want the "No citations" message
  \or
    (page #4).%
  \else
    (pages #4).%
  \fi%
}

\begin{document}

\cite{b}
\newpage

\cite{a},...,\cite{b}
\newpage

\cite{b}

\begin{thebibliography}{9}
\bibitem{a} Dummy bib-reference one

\bibitem{b} Dummy bib-reference two

\bibitem{c} Dummy bib-reference three

\end{thebibliography}

\end{document}
autonomouse wrote:...and also, which might be a bit harder, if there are multiple contiguous numbers is there a way to make it say "(pages 1-4)", for example?...
At the present time, I don't know how to easily achieve this.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
autonomouse
Posts: 6
Joined: Sun Jan 11, 2009 4:51 pm

Re: Page numbers to refs: Adding the word 'page' to pagebackref

Post by autonomouse »

Amazing - thanks
ionica
Posts: 3
Joined: Thu Jul 16, 2009 10:22 pm

Re: Page numbers to refs: Adding the word 'page' to pagebackref

Post by ionica »

Wow! I spent quite some time trying to get this to work, but I could not figure it out. With your code it looks amazing. I registered just to say thanks: Thank you so much!
pvmeel
Posts: 3
Joined: Fri Jul 17, 2009 11:53 pm

Re: Page numbers to refs: Adding the word 'page' to pagebackref

Post by pvmeel »

First of all let me say thanks to gmedina for the addition of "page/pages" to the backref's. It looks so much better now!!

But I have another question. I use multiple references: \citep{ref1, ref2, ref3} made possible by the 'natbib' package. In the biblio however, only ref3 gets the backrefs, the first refs don't (the \citep works fine though). Is this an error and if not, do you know a solution?
Post Reply