括号内超链接引用宏

括号内超链接引用宏

我正在使用下面的宏来覆盖 \cite{} 命令,以便突出显示/超链接整个引用。

\cite 命令给出“Smith, 2000”形式的引文。 \textcite{} 命令给出“Smith (2000)”形式的引文。 如何添加命令以得到“(Smith, 2000)”和“(Smith, 2000, p. 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}}}

答案1

感谢,感谢应得的。OP 中的代码来自 Audrey超链接名称与 biblatex 作者年份 (biblatex 1.4b)

\parencite你可以通过修改命令本身并引入一个新的宏来获得链接的括号

\newbibmacro*{parencite}{%
  \printtext[citehyperref]{%
    \DeclareFieldAlias{citehyperref}{noformat}%
    \iffirstcitekey
      {\bibopenparen}{}%
    \ifnumequal{\value{citecount}}{1}
      {\usebibmacro{prenote}}{}%
    \usebibmacro{cite}%
    \ifnumequal{\value{citecount}}{\value{citetotal}}
      {\usebibmacro{postnote}}{}%
    \iflastcitekey
      {\bibcloseparen}{}}}

\DeclareCiteCommand{\parencite}
  {}
  {\usebibmacro{citeindex}%
   \usebibmacro{parencite}}
  {\multicitedelim}
  {}

\DeclareMultiCiteCommand{\parencites}{\parencite}{\setunit{\multicitedelim}}

我们基本上将括号从包装器移到 bibmacro 本身,允许它们链接到正确的条目,但代价是必须检查是否始终打印括号。

平均能量损失

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[style=authoryear]{biblatex}
\usepackage{hyperref}

\addbibresource{biblatex-examples.bib}

\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}}}

\newbibmacro*{parencite}{%
  \printtext[citehyperref]{%
    \DeclareFieldAlias{citehyperref}{noformat}%
    \iffirstcitekey
      {\bibopenparen}{}%
    \ifnumequal{\value{citecount}}{1}
      {\usebibmacro{prenote}}{}%
    \usebibmacro{cite}%
    \ifnumequal{\value{citecount}}{\value{citetotal}}
      {\usebibmacro{postnote}}{}%
    \iflastcitekey
      {\bibcloseparen}{}}}

\DeclareCiteCommand{\parencite}
  {}
  {\usebibmacro{citeindex}%
   \usebibmacro{parencite}}
  {\multicitedelim}
  {}

\DeclareMultiCiteCommand{\parencites}{\parencite}{\setunit{\multicitedelim}}

\begin{document}
\cite{sigfridsson} and \parencite{sigfridsson} and \textcite{sigfridsson}

\cite{geer,worman} and \parencite{geer,worman} and \textcite{geer,worman}

\cite{knuth:ct:a,knuth:ct:b,knuth:ct:c} and \parencite{knuth:ct:a,knuth:ct:b,knuth:ct:c} and \textcite{knuth:ct:a,knuth:ct:b,knuth:ct:c}

\parencites{geer}{worman} and \parencites{knuth:ct:a}{knuth:ct:b}{knuth:ct:c}

\printbibliography
\end{document}

MWE 的引用部分

相关内容