超链接名称与 biblatex 作者年份 (biblatex 1.4b)

超链接名称与 biblatex 作者年份 (biblatex 1.4b)

我是新来的,所以我不确定这是否是表达我的问题的正确方式:

我使用 biblatex 软件包,采用作者年份格式,并希望引文中的链接包含作者姓名和括号。答案在超链接名称与 biblatex 作者年份完全符合我的要求,但似乎该解决方案与最新的 biblatex 版本 1.4b 不兼容。有人能帮我将代码适配到最新的 biblatex 版本吗?

答案1

以下代码为大多数引用命令超链接了整个引用标签。超链接包括+\textcite周围的括号,除非有前注或后注。在这种情况下,链接仅适用于+ 。labelyearextrayearlabelyearextrayear

\documentclass{report}
\usepackage[style=authoryear]{biblatex}
\usepackage{hyperref}

% Just for demo
\ExecuteBibliographyOptions{maxcitenames=1}

\DeclareFieldFormat{citehyperref}{%
  \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
  \bibhyperref{#1}}

\DeclareFieldFormat{textcitehyperref}{%
  \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
  \bibhyperref{%
    #1%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}}}

\savebibmacro{cite}
\savebibmacro{textcite}

\renewbibmacro*{cite}{%
  \printtext[citehyperref]{%
    \restorebibmacro{cite}%
    \usebibmacro{cite}}}

\renewbibmacro*{textcite}{%
  \ifboolexpr{
    ( not test {\iffieldundef{prenote}} and
      test {\ifnumequal{\value{citecount}}{1}} )
    or
    ( not test {\iffieldundef{postnote}} and
      test {\ifnumequal{\value{citecount}}{\value{citetotal}}} )
  }
    {\DeclareFieldAlias{textcitehyperref}{noformat}}
    {}%
  \printtext[textcitehyperref]{%
    \restorebibmacro{textcite}%
    \usebibmacro{textcite}}}

\renewcommand{\baselinestretch}{1.2}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\addbibresource{biblatex-examples.bib}
\begin{document}
\null\vfill
\textbf{Single citations}

Filler text \parencite{aristotle:poetics}. Filler text \parencite{kant:ku} \\
Filler text \parencite[See][23]{aristotle:poetics}.
Filler text \parencite[1--10]{kant:ku}. \\
\textcite{aristotle:poetics} and \textcite{kant:ku}.
\textcite[e.g.][]{aristotle:poetics} and \textcite[10]{kant:ku}. \\
Filler text.\footcite[23]{aristotle:poetics} Filler text.\footcite[1--10]{aristotle:rhetoric}
Filler text.\footnote{\smartcite[10--15]{companion}}

\textbf{Unqualified citation lists}

\textcite{aristotle:poetics,aristotle:rhetoric} \\
\textcite[e.g.][]{aristotle:poetics,aristotle:rhetoric} \\
\textcite[10--15]{aristotle:poetics,aristotle:rhetoric} \\
\textcite[e.g.][10--15]{aristotle:poetics,aristotle:rhetoric} \\
\parencite[See][for example]{aristotle:poetics,aristotle:rhetoric}

\textbf{Qualified citation lists}

\textcites{aristotle:poetics}{aristotle:rhetoric} \\
\textcites(See)(){aristotle:poetics}[cf.][]{aristotle:rhetoric} \\
\textcites(See)()[10]{aristotle:poetics}[10]{aristotle:rhetoric} \\
\textcites(See)()[10--15]{aristotle:poetics}[cf.][10]{aristotle:rhetoric} \\
\textcites(See)()[e.g.][10--15]{aristotle:poetics}[cf.][10]{aristotle:rhetoric} \\
\parencites(See)()[10--15]{aristotle:poetics}[cf.][10]{aristotle:rhetoric}

\textbf{Mix of qualified and unqualified citation lists}

\textcites(See)()[e.g.][]{aristotle:poetics}[10]{bertram,companion} \\
\textcites[e.g.][]{aristotle:poetics,aristotle:rhetoric}[10]{companion} \\
\textcites[10]{aristotle:poetics,aristotle:rhetoric}[cf.][]{bertram} \\
\textcites[15]{aristotle:poetics}[cf.][10]{bertram,companion}

\printbibliography
\end{document}

这是使用 biblatex 2.6 或更早版本应获得的输出。此解决方案也适用于更高版本,其中\textcite和 朋友使用and字符串作为最终引用分隔符。

在此处输入图片描述

相关内容