1

I'm currently modifying the Masters/Doctoral Thesis template found here. However, it only highlights the year in a citation like (Smith 2016). I would like both "Smith" and "2016" to be part of the link. I have added a MWE below. It includes the main tex file, the cls file and the bib file. What should be changed?

main.tex

\documentclass[11pt]{MastersDoctoralThesis}
\usepackage[backend=bibtex,style=authoryear,natbib=true]{biblatex}
\addbibresource{adam.bib}

\begin{document}

This is in \cite{smith2016}.

\end{document}  

MastersDoctoralThesis.cls

\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\newcommand{\classname}{MastersDoctoralThesis}
\ProvidesClass{\classname}[2015/11/08 v1.2 LaTeXTemplates.com]
\providecommand{\baseclass}{book}

\RequirePackage{etoolbox}
\RequirePackage{xparse}
\LoadClass{\baseclass}

\RequirePackage{hyperref}
\hypersetup{
    bookmarksopen=true,
    bookmarksopenlevel=0,
    hypertexnames=false,
    colorlinks=true, 
    citecolor=blue, 
    linkcolor=blue, 
    urlcolor=blue, 
    pdfstartview={FitV},
    unicode,
    breaklinks=true,
}
\endinput

adam.bib

@article{smith2016,
    author={John Smith},
    year={2016}
}

PDF Output

enter image description here

Adam_G
  • 816
  • It is better to post a full minimal working example that starts with a \documentclass command, has a minimal preamble and then \begin{document}...\end{document}. Unless the problem is a compilation error, the code should compile and be as small as possible to demonstrate your problem. This makes it much easier for people to help you --- and much ore likely that they will! –  Feb 09 '16 at 23:35
  • Thanks. I've added an MWE. These files should all compile on another machine – Adam_G Feb 10 '16 at 01:44
  • 5
  • Thanks @moewe. Can I put that in my cls file, or does it have to go in main.tex? – Adam_G Feb 10 '16 at 14:55
  • You can put that in your .cls file if you wish, but then you need to make sure that biblatex is loaded. Note also that this exact solution will only works absolutely smoothly with the authoryear style. It can also go into the preamble of your .tex file. – moewe Feb 10 '16 at 15:01
  • Thanks. I just wanted to keep my main.tex file clean, and used primarily for organizing the doc. It's a Masters thesis, and uses a separate tex file for each chapter. Will that change anything? – Adam_G Feb 10 '16 at 15:04
  • It shouldn't be a problem, I don't think. It can definitely go into the preamble of your (main) document. Whether it should go into a .cls depends on what your .cls is supposed to do. If it is just for this (and maybe a few other) special documents, than it is fine I suppose; if you want to make the .cls re-usable (with other bibliography styles) and allow for more flexibility, moving the code there might not be that good an idea after all. – moewe Feb 10 '16 at 15:11
  • Let me know how it worked out for you and if we can close this question as a duplicate of hyperlink name with biblatex authoryear (biblatex 1.4b). – moewe Feb 10 '16 at 15:32
  • I'm having trouble with this. I keep getting the error "Option clash for package biblatex." – Adam_G Feb 10 '16 at 16:24
  • That suggests you are loading biblatex twice (i.e. you have \usepackage[...]{biblatex} twice in total), load it only once. – moewe Feb 10 '16 at 17:03
  • The content you are stating to be MastersDoctoralThesis.cls is not the file. Please see the license at the beginning of the class file. – Johannes_B Feb 11 '16 at 17:04
  • @moewe I got rid of usepackage{biblatex} in main.tex, and in the cls file just have \RequirePackage[style=authoryear]{biblatex}. It compiles, but appears as '(smith2016)', the cite key, rather than the proper format. – Adam_G Feb 12 '16 at 02:34
  • If you load \RequirePackage[style=authoryear]{biblatex} instead of \usepackage[backend=bibtex,style=authoryear,natbib=true]{biblatex} as you did before you are requesting the Biber back-end and are not using BibTeX any more, you need to adapt your compilation sequence please read bibtex vs. biber and biblatex vs. natbib, Biblatex with Biber: Configuring my editor to avoid undefined citations. – moewe Feb 12 '16 at 06:57
  • Please note that as Johannes commented from a license point of view you must not change the .cls file without changing its name. I would also be against moving biblatex code (and even the call to \usepackage{biblatex}) to a multi-purpose .cls such as this, if you insist on keeping your preamble short (why?) you can externalise it to a personal .tex or .sty file you can later load. But don't change the .cls file. – moewe Feb 12 '16 at 07:00
  • Any news here? Does the solution linked to above work for you now? Or did any other problems creep up? – moewe Feb 14 '16 at 10:05
  • Sorry, I've been traveling. I will tackle this this afternoon and report back. – Adam_G Feb 14 '16 at 15:12
  • I moved the code to my main.tex file. This gets rid of the errors. However, the citations are still showing up as the cite key, e.g. "smith2016" rather than being formatted. – Adam_G Feb 14 '16 at 19:29
  • Got things up and running! I guess I hadn't compiled my bibtex file in the current setup. I had thought TexStudio does that automatically. This question helped. http://tex.stackexchange.com/questions/63852/question-mark-instead-of-citation-number – Adam_G Feb 14 '16 at 20:04

0 Answers0