4

Based on some experimenting and some reading (here on http://tex.stackexchange.com) I might have solved first issue I had. I have kept a strikeout-version of the first issue so that people have a change to correct me if my solution is faulty (see update from 2013-11-04 16:25:35Z below). Please feel free to let me know if the striked out text is utterly confusing to read.

I am using the biblatex package–with natbib capabilities–and the hyperref package, using the (Author, Year) style citations, and pdflatex as the engine.

I have run into two one issues.

First, \citeyear{} and the custom-made command \citejournal{}, thanks to Gonzalo Medina's answer (with the help of Audrey), do not produce clickable hyperlinks (see screenshot below this ¶).

enter image description here

It kinda makes sense to my why \citejournal{} does not work, but I do not understand why \citeyear{} doesn't work. According to the reference manual for the biblatex package (p. 88 [PDF link!]) "[t]he text commands (\citeauthor, \citeyear, etc.) are […] supported." Also, the hyperref should work, as long as the transformations of citations into clickable hyperlinks is support by the selected citation style (p. 47 in the reference manual for the biblatex package [PDF link!]).

I got the \citetitle{} and \citeauthor{} working with the help of this (\citetitle{}) and this (\citeauthor{}) answer, both by Audrey. I tried reproducing Audrey's method for \citeyear{} and \citejournal{}, but I got stuck.

Can anyone show me how I get the \citeyear{} and maybe the custom-made command \citejournal{} to create a link to the biography? (see below for reproducible example).

Furthermore, the second issue, from this beautiful example from Audrey I realized that it is possible to fix the links to include the postnote and bracket so that it is not only the year that is clickable but the whole parenthesis. I've tried reproducing his example, but I cannot get this to work with biblatex. Any suggestions to how I can expand the clickable hyperlinks?

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}

\usepackage[backend=bibtex,
style=authoryear, natbib=true, 
        ]{biblatex}

\usepackage{hyperref}
\hypersetup{pdfborderstyle={/S/U/W 1}}

% thanks to https://tex.stackexchange.com/a/26684/22939
\DeclareCiteCommand{\citejournal}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \usebibmacro{journal}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citebooktitle}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \usebibmacro{booktitle}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeintitle}% Based on \citetitle from biblatex.def
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexfield{indextitle}}
     {}%
   \iffieldundef{journaltitle}
     {\iffieldundef{booktitle}
        {\iffieldundef{maintitle}
          {\printfield[citetitle]{labeltitle}}% Behave like \citetitle if no "main" title
          {\printtext[maintitle]{\printfield[titlecase]{maintitle}}}}
        {\printtext[booktitle]{\printfield[titlecase]{booktitle}}}}
     {\printtext[journaltitle]{\printfield[titlecase]{journaltitle}}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}


%  Thanks to [Audrey](https://tex.stackexchange.com/a/108349/22939)
\DeclareCiteCommand{\citetitle}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexfield{indextitle}}
     {}%
   \printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}


%  Thanks to [Audrey](https://tex.stackexchange.com/a/75916/22939)
  \DeclareCiteCommand{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printtext[bibhyperref]{\printnames{labelname}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}


\begin{filecontents}{bibfile.bib}
@article{einstein,
  author =       "Albert Einstein",
  title =        "{Zur Elektrodynamik bewegter K{\"o}rper}. ({German})
                 [{On} the electrodynamics of moving bodies]",
  journal =      "Annalen der Physik",
  volume =       "322",
  number =       "10",
  pages =        "891--921",
  year =         "1905",
  DOI =          "http://dx.doi.org/10.1002/andp.19053221004"
}

@book{latexcompanion,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The \LaTeX\ Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}
\end{filecontents}


\addbibresource{bibfile}

\begin{document}

\noindent
cite: \cite{einstein}, \cite{latexcompanion} \\
citet: \citet{einstein}, \citet[see][p. 20]{einstein} \\
multi citet: \citet{latexcompanion,einstein} \\
citep: \citep{einstein}, \citep[see][p. 20]{latexcompanion} \\
multi citep: \citep{latexcompanion,einstein} \\
citetext, citealp: \citetext{see \citealp{latexcompanion}, or even better \citealp{einstein}} \\
citeauthor: \citeauthor{einstein}, \citeauthor{latexcompanion} \\
citeyear: \citeyear{einstein}, \citeyear{latexcompanion} \\
citetitle: \citetitle{einstein} and \citetitle{latexcompanion} \\
citejournal: \citejournal{einstein}\\

\medskip

\printbibliography

\end{document}

Update 2013-11-04 16:07:35Z

I have written this update to \DeclareCiteCommand{\citejournal}

\DeclareCiteCommand{\citejournal}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexfield{journal}}
     {}%
   \printtext[bibhyperref]{\printfield[journal]{journaltitle}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}  

I've not updated the initial code I posted as I don't full understand––to say the least––what I am doing, but the above code seem to work.

Update 2013-11-04 16:25:35Z

Encouraged by moewe's comments I have reproduced the \DeclareCiteCommand{\citejournal} for the \DeclareCiteCommand{\citeyear}. As follows,

\DeclareCiteCommand{\citeyear}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexfield{year}}
     {}%
   \printtext[bibhyperref]{\printfield[journal]{year}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}  

Again, I have not updated the initial code I posted as I don't really understand what I am doing yet, but the above code seem to work.

  • Regarding your update: this is exactly what you can do with all the commands you mentioned in the first part of your question, just wrap the \print... part in a \printtext[bibhyperref]{...} command. This prints the text given in the argument as expected but adds the click-able hyperlink to the bibliography :entry. (Though I would not bother with the \ifciteindex thing: It was not there in the initial definition of the \citejournal command and does nothing for hyperlinks.) – moewe Nov 4 '13 at 17:10
  • Regarding your second question: Expansion of the link might be doable with quite a lot of redefinitions. Though I noticed that in Audrey's natbib code in the linked answer post and prenote were in fact not hyperlinked. I don't think that adding the pre and postnote in a seamless link will be very easy to achieve (a quite "choppy" version, however, is easily implemented but certainly not pleasing to the eye.). – moewe Nov 4 '13 at 17:15
  • A (not so) short comment on \DeclareCiteCommand{\citeyear}: You seem to have missed the \citeyear part (the braces are empty). Once again I would advise against the \ifcitenindex part (and the following {\indexfield{year}} as well as the empty pair of braces {}). Instead of \printtext[bibhyperref]{\printfield[journal]{year}} you could and should simply use \printfield[bibhyperref]{year} (or \printtext[bibhyperref]{\printfield{year}}). The journal does not do anything meaningful in this case (it tells biblatex to format the year as a journaltitle). – moewe Nov 4 '13 at 18:49
  • @moewe, regarding the \ifciteindex, the reason I included the \ifciteindex in my code-update suggestion is that it was included in both answers from @Audrey, found here (\citetitle{}) and here (\citeauthor{}). As I wrote above I don't fully understand––to say the least––what I am doing, but Audrey seem to know what he's doing (I suspect he is the Audrey Boruvka who coauthored the biblatex package). Would you expand on your reasons for not including it? – Eric Fail Nov 5 '13 at 10:23
  • @moewe, thank you for pointing out that I forgot \citeyear in \DeclareCiteCommand{}. – Eric Fail Nov 5 '13 at 12:58