1

I'm writing a master thesis with Latex but I am not satisfied with the default citation options. I found this helpful post to define my own commands of citations: https://tex.stackexchange.com/a/1690. I was quite successful until I tried to redefine \citeauthor. I want \citeauthor to put a hyperlink on the author name toward my bibliography. Here is what I tried :

\documentclass{report}

\usepackage[backend=bibtex,style=authoryear]{biblatex}
\bibliography{bib_mre_citeauthor.bib}
\usepackage{hyperref} 

\DeclareCiteCommand{\citeauthor}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\usebibmacro{citeauthor}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\begin{document}

I would like to cite (\citeauthor{government_of_canada_archived_2009}), with %
the author name only and with an hyperlink from the name to the bibliography. % 
As you can see, I did the exact same thing with parencite, which put, by %
default, only a hyperlink on the date, and it works perfectly %
\parencite{government_of_canada_archived_2009}. \\

\printbibliography

\end{document}

Here is my .bib document:

@online{government_of_canada_archived_2009,
    title = {{ARCHIVED} - Environment and Climate Change Canada - Pollution and Waste - Chlorofluorocarbon},
    url = {https://www.ec.gc.ca/toxiques-toxics/Default.asp?lang=En&n=98E80CC6-1&xml=10C1D91B-A55E-45C2-92F2-8AA562BD3ED7},
    abstract = {Information about Chlorofluorocarbon},
    author = {{Government of Canada}},
    urldate = {2019-02-22},
    date = 2009
}

Here is the error message:

! Package biblatex Error: Bibliography macro 'citeauthor' undefined.

However, if I use \citeauthor without redefining it, the code runs.

Explanations and other solutions to cite only the name with an hyperlink are welcome.

Thank you for your time!

Stefan Pinnow
  • 29,535

1 Answers1

1

Adding \printtext[bibhyperref]{...} to the \citeauthor definition:

\documentclass{report}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@online{government_of_canada_archived_2009,
    title = {{ARCHIVED} - Environment and Climate Change Canada - Pollution and Waste - Chlorofluorocarbon},
    url = {https://www.ec.gc.ca/toxiques-toxics/Default.asp?lang=En&n=98E80CC6-1&xml=10C1D91B-A55E-45C2-92F2-8AA562BD3ED7},
    abstract = {Information about Chlorofluorocarbon},
    author = {{Government of Canada}},
    urldate = {2019-02-22},
    date = 2009
}
\end{filecontents*}  

\usepackage[style=authoryear]{biblatex}
\bibliography{\jobname.bib}
\usepackage{hyperref} 

\DeclareCiteCommand{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printtext[bibhyperref]{\printnames{labelname}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}



\begin{document}

I would like to cite (\citeauthor{government_of_canada_archived_2009}), with %
the author name only and with an hyperlink from the name to the bibliography. % 
As you can see, I did the exact same thing with parencite, which put, by %
default, only a hyperlink on the date, and it works perfectly %
\parencite{government_of_canada_archived_2009}. \\

\printbibliography

\end{document}