我正在用 Latex 写一篇硕士论文,但我对默认的引用选项不满意。我发现这篇有用的文章可以定义我自己的引用命令:https://tex.stackexchange.com/a/1690。在我尝试重新定义之前,我一直很成功\citeauthor
。我想\citeauthor
在作者姓名上添加指向我的参考书目的超链接。以下是我尝试的:
\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}
这是我的.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
}
错误信息如下:
! Package biblatex Error: Bibliography macro 'citeauthor' undefined.
但是,如果我\citeauthor
不重新定义它就使用它,代码就会运行。
欢迎提供仅引用带有超链接的名称的解释和其他解决方案。
感谢您的时间!
答案1
添加\printtext[bibhyperref]{...}
定义\citeauthor
:
\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}