kks32 / phd-thesis-template

A LaTeX / XeLaTeX / LuaLaTeX PhD thesis template for Cambridge University Engineering Department (CUED)
http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/ThesisStyle/
MIT License
834 stars 399 forks source link

Add backreference to bibliography #67

Closed rozsasarpi closed 8 years ago

rozsasarpi commented 8 years ago

Hi all,

I would like to have back-reference from a bibliography entry to the pages where it has appeared.

I was experimenting with \usepackage[backref=page]{hyperref} in the preamble but it does not work (option clash) since hyperref options are specified earlier (not in the preamble). I would highly appreciate if someone could let me know how to get back-referencing with the template.

Thanks in advance.

tabias commented 8 years ago

as read in the link, it seems you require to use biblatex with [backref=page] option. \usepackage[backref=page]{biblatex} together with custombib

Closest approximation I can make: thesis.pdf

case67.tar.gz

procedure

Replace the entry starting at line 115 in preamble.tex from:

% Add `custombib' in the document class option to use this section \ifuseCustomBib \RequirePackage[square, sort, numbers, authoryear]{natbib} % CustomBib

to

\ifuseCustomBib \RequirePackage[square, sort, numbers, authoryear]{natbib} % CustomBib \usepackage{hypernat} \usepackage{etoolbox} \makeatletter \patchcmd{\BR@backref}{\newblock}{\newblock(page~}{}{} \patchcmd{\BR@backref}{\par}{)\par}{}{} \makeatother

\renewcommand{\backrefxxx}[3]{(page \hyperlink{page.#1}{#1})} % sourced from : https://tex.stackexchange.com/questions/36307/formatting-back-references-in-bibliography

add custombib to your documentclass options (thesis.tex):

 \documentclass[a4paper,12pt,numbered, print, times,custombib]{Classes/PhDThesisPSnPDF}

and change the entry in the Classes/PhDThesisPSnPDF.cls entry starting @ line 610 until the URL Package and Definition entry line with :

%*** Print / Online **** % Defines a print / online version to define page-layout and hyperrefering

% Moved below other usepackage definitions to fix PDFLaTeX footnote warning % Based on the suggestion by John Plaice

\ifsetDVI \special{papersize=\the\paperwidth,\the\paperheight} \RequirePackage[unicode=true,backref=page]{hyperref} % extra option dvips \else \RequirePackage[unicode=true,backref=page]{hyperref} \pdfpagewidth=\the\paperwidth \pdfpageheight=\the\paperheight \fi

\if@print % For Print version \hypersetup{ final=true, plainpages=false, pdfstartview=FitV, pdftoolbar=true, pdfmenubar=true, bookmarksopen=true, bookmarksnumbered=true, breaklinks=true, linktocpage, colorlinks=true, linkcolor=black, urlcolor=black, citecolor=black, backref=page, anchorcolor=black } \ifsetCustomMargin % Margin to be define in preamble using geometry package \else \ifsetDVI % Odd and Even side Margin for binding and set viewmode for PDF \RequirePackage[dvips,paper=\PHD@papersize,hmarginratio=1:1, vmarginratio=1:1,scale=0.75,bindingoffset=5mm]{geometry} \else \RequirePackage[pdftex,paper=\PHD@papersize,hmarginratio=1:1, vmarginratio=1:1,scale=0.75,bindingoffset=5mm]{geometry} \fi \fi

\if@twoside \hypersetup{pdfpagelayout=TwoPageRight} \else \hypersetup{pdfpagelayout=OneColumn} \fi

\else % For PDF Online version \hypersetup{ final=true, plainpages=false, pdfstartview=FitV, pdftoolbar=true, pdfmenubar=true, bookmarksopen=true, bookmarksnumbered=true, breaklinks=true, linktocpage, colorlinks=true, linkcolor=blue, urlcolor=blue, citecolor=blue, backref=page, anchorcolor=green }

\ifsetCustomMargin % Margin to be define in preamble using geometry package \else % No Margin staggering on Odd and Even side \ifsetDVI \RequirePackage[paper=\PHD@papersize,hmarginratio=1:1, vmarginratio=1:1,scale=0.75]{geometry} % dvips \else \RequirePackage[pdftex,paper=\PHD@papersize,hmarginratio=1:1, vmarginratio=1:1,scale=0.75]{geometry} \fi \fi \hypersetup{pdfpagelayout=OneColumn} \fi

% Backward compatibility - setMargin is now replaced with customMargin \ifsetCustomMargin \setMarginfalse \else \setMargintrue \fi

this at least adds the page numbers to your reference list. You still have to figure out how to renew the number to page #nr set.

key points are the usage of hypernat, custombib and adding backref=page to the hypersetup in the class file.

rozsasarpi commented 8 years ago

Thank you very much! Without the line \renewcommand{\backrefxxx}[3]{(page \hyperlink{page.#1}{#1})}, it works for me. I do not understand why, but it does (I am new to latex).

backref

tabias commented 8 years ago

Glad to see it worked,

Could you post a minimal working example code? This way there is a future reference for possible implementation.

rozsasarpi commented 8 years ago

A working example is attached.

Short description how it worked for me (certainly not a robust nor general solution):

(1) Remove the numbered argument from documentclass. original: \documentclass[a4paper,12pt,times,numbered,print,index]{Classes/PhDThesisPSnPDF} new: \documentclass[a4paper,12pt,times,print,index,custombib]{Classes/PhDThesisPSnPDF} (2) Copy the code given by @tabias to the relevant files and locations. (3) Compile. (4) Compile again with line \renewcommand{\backrefxxx}[3]{(page \hyperlink{page.#1}{#1})} removed or commented.

backref2

phd-thesis-template-master-with-backref.zip

skmalviya commented 3 years ago

(For XeLatex)

I just changed this line:

\RequirePackage[unicode=true]{hyperref}

to:

\RequirePackage[unicode=true,backref=page]{hyperref}

@line no:602 in PhDThesisPSnPDF.cls file. It worked for me.