# BibLaTex: Adding a non-hyperlinked authoryear block before each bibliography entry

I would like to add an [Author(s) Year] block at the beginning of every citation, exactly as described in this question: Adding an [AuthorYear] block at the beginning of bibliography entries.

I used the very code given in the accepted answer to that question. However, in addition, I want my citations to be hyperlinked, and therefore use the package hyperref. The following is a minimal working example which demonstrates my problem:

\documentclass{article}

% Adding a yearauthor block in bibliohraphy: https://tex.stackexchange.com/a/11856/42810
\usepackage[backend=bibtex,citestyle=authoryear,bibstyle=authortitle,sorting=nyt,dashed=false,maxcitenames=2]{biblatex}

\newcounter{mymaxcitenames}
\AtBeginDocument{%
\setcounter{mymaxcitenames}{\value{maxnames}}%
}

\renewbibmacro*{begentry}{%
\printtext[brackets]{%
\begingroup
\defcounter{maxnames}{\value{mymaxcitenames}}%
\printnames{labelname}%
\setunit{\nameyeardelim}%
\usebibmacro{cite:labelyear+extrayear}%
\endgroup
}%
\addspace%
}

\DeclareNameAlias{sortname}{first-last}

% Use hyperref to hyperlink citations
\usepackage[dvipsnames]{xcolor}
\usepackage[hyperindex=true]{hyperref}
\hypersetup{colorlinks=true,linkcolor=Blue,citecolor=BrickRed}

\begin{filecontents}{\jobname.bib}
@article{foo,
author    = {Grace Murray Hopper},
title     = {The Education of a Computer},
journal   = {{IEEE} Annals of the History of Computing},
volume    = {9},
number    = {3/4},
pages     = {271--281},
year      = {1987}
}
\end{filecontents}

\bibliography{\jobname}

\begin{document}

Here is a citation: \cite{foo}.

\printbibliography

\end{document}


This produces the following:

As you can see, the authoryear block in the bibliography contains a hyperlink to itself. I do not want this hyperlink, although I do want the hyperlink in the running text (i.e., before the bibliograpy). How can I remove the hyperlink from the authoryear block in the bibliography?

• Is the hyperlink really that bad? Sep 26 '16 at 19:49
• For me, yes. :) There has to be some way around this? Sep 26 '16 at 19:52
• Yes, there definitely is. But I thought it might be easier to talk you out of it than to find the solution. ;-)But alas, ... let me see what I can do. Sep 26 '16 at 19:52

## 1 Answer

We only need to make the bibhyperref format do nothing in the "introductory" block. To this end we insert \DeclareFieldFormat{bibhyperref}{##1}% (the double # is necessary because we are already within a macro definition) into the redefinition of begentry

\renewbibmacro*{begentry}{%
\printtext[brackets]{%
\begingroup
\DeclareFieldFormat{bibhyperref}{##1}%
\defcounter{maxnames}{\value{mymaxcitenames}}%
\printnames{labelname}%
\setunit{\nameyeardelim}%
\usebibmacro{cite:labelyear+extrayear}%
\endgroup
}%
\addspace%
}


This gives the desired result

\documentclass{article}

% Adding a yearauthor block in bibliohraphy: http://tex.stackexchange.com/a/11856/42810
\usepackage[backend=bibtex,citestyle=authoryear,bibstyle=authortitle,sorting=nyt,dashed=false,maxcitenames=2]{biblatex}

\newcounter{mymaxcitenames}
\AtBeginDocument{%
\setcounter{mymaxcitenames}{\value{maxnames}}%
}

\renewbibmacro*{begentry}{%
\printtext[brackets]{%
\begingroup
\DeclareFieldFormat{bibhyperref}{##1}%
\defcounter{maxnames}{\value{mymaxcitenames}}%
\printnames{labelname}%
\setunit{\nameyeardelim}%
\usebibmacro{cite:labelyear+extrayear}%
\endgroup
}%
\addspace%
}

\DeclareNameAlias{sortname}{first-last}

% Use hyperref to hyperlink citations
\usepackage[dvipsnames]{xcolor}
\usepackage[hyperindex=true]{hyperref}
\hypersetup{colorlinks=true,linkcolor=Blue,citecolor=BrickRed}

\begin{filecontents}{\jobname.bib}
@article{foo,
author    = {Grace Murray Hopper},
title     = {The Education of a Computer},
journal   = {{IEEE} Annals of the History of Computing},
volume    = {9},
number    = {3/4},
pages     = {271--281},
year      = {1987}
}
\end{filecontents}

\bibliography{\jobname}

\begin{document}
Here is a citation: \cite{foo}.

\printbibliography
\end{document}


• Note that nowadays Biber is the preferred backend (BibTeX does not support the full set of biblatex features). Starting from version 3.3 of bibaltex \DeclareNameAlias{sortname}{first-last} should be replaced by \DeclareNameAlias{sortname}{given-family}. \bibliography{\jobname} can (should) be replaced by \addbibresource{\jobname.bib} (note that this includes the file ending). Sep 26 '16 at 20:02