\citet 在 natbib=true 的情况下无法使用 biblatex

\citet 在 natbib=true 的情况下无法使用 biblatex

我正在撰写博士论文,并尝试在句子中引用参考文献,方式是作者姓氏后面加上括号中的年份:

单个作者

作者(年份)

或两位作者

作者 1 和作者 2(年份)

或两位以上作者

作者等(年份)

我尝试使用\citet,但即使使用 natbib 也无法使用。我收到以下错误

Package etoolbox Error: Boolean '\ifcbx:np' undefined.

我正在使用带有 natbib 的 biblatex 包,如下所示:

\usepackage[
  style=authoryear,
  natbib=true,
  backend=biber,
  dashed=false,
  isbn = false,
  doi = false,
  url = false,
  language=auto,
  sorting=nyt,  
  maxbibnames=99,
  maxcitenames=2,
  uniquelist=false,
  uniquename=false]{biblatex}  

以下是我正在使用的软件包

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{booktabs}
\usepackage{bm}
\usepackage{float}
\usepackage{subfig}
\usepackage{setspace}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[hyperfootnotes=false,english,colorlinks]{hyperref}
\usepackage{url}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{array}
\usepackage[normalem]{ulem}

我现在有一个例子

 For the former, \cite{basu2017} invoked the notion of a metric..

输出:

Basu et al., 2017

期望输出:

Basu et al. (2017)

我认为错误是由于使用此宏链接作者和年份而产生的

% long syntax to link both author & year in in-text citation
\makeatletter
\newbibmacro{cite:plabelyear+extradate}{%
  \iffieldundef{labelyear}{}
    {\clearfield{labelmonth}% don't want months in citations
     \clearfield{labelday}% don't want days in citations
     \clearfield{labelendmonth}% don't want months in citations
     \clearfield{labelendday}% don't want days in citations
     \iffieldsequal{labelyear}{labelendyear}% Don't want no-op year ranges
       {\clearfield{labelendyear}}
       {}%
     \iffieldundef{origyear}
       {}
       {\printorigdate%
        \setunit*{\addslash}}%
     \iffieldundef{related}
       {}
       {\iffieldequalstr{relatedtype}{reprintfrom}
         {\entrydata*{\thefield{related}}{\printlabeldateextra}%
          \setunit*{\addslash}}
         {}}%
     \printlabeldateextra}}

\renewbibmacro*{cite}{%
  \iffieldequals{fullhash}{\cbx@lasthash}
   {\setunit{\compcitedelim}%
    \printtext[bibhyperref]{%
      \usebibmacro{cite:plabelyear+extradate}}}%
   {\printtext[bibhyperref]{%
      \ifnameundef{labelname}
       {\usebibmacro{cite:noname}%
         \setunit{\printdelim{nameyeardelim}}%
         \usebibmacro{cite:plabelyear+extradate}%
         \savefield{fullhash}{\cbx@lasthash}}
       {\ifnameundef{shortauthor}
         {\printnames{labelname}}%
         {\cbx@apa@ifnamesaved
           {\printnames{shortauthor}}
           {\ifnameundef{groupauthor}
             {\printnames[labelname]{author}}
             {\printnames[labelname]{groupauthor}}%
            \addspace\printnames[sabrackets]{shortauthor}}}%
         \setunit{\printdelim{nameyeardelim}}%
        \usebibmacro{cite:plabelyear+extradate}%
        \savefield{fullhash}{\cbx@lasthash}}}}%
   \setunit{\multicitedelim}}

\renewbibmacro*{textcite}{%
  \iffieldequals{fullhash}{\cbx@lasthash}
    {\setunit{\compcitedelim}%
     \printtext[bibhyperref]{%
       \usebibmacro{cite:plabelyear+extradate}}}
    {%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
      \setunit{\compcitedelim}%
      \ifnameundef{labelname}
       {\iffieldundef{shorthand}%
         {\printtext[bibhyperref]{%
            \usebibmacro{cite:noname}}%
          \setunit{\ifbool{cbx:np}%
                   {\printdelim{nameyeardelim}}%
                   {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
          \printtext[bibhyperref]{%
            \usebibmacro{cite:plabelyear+extradate}}}
         {\printtext[bibhyperref]{%
            \usebibmacro{cite:shorthand}}}}
       {\printtext[bibhyperref]{%
          \ifnameundef{shortauthor}%
           {\printnames{labelname}}
           {\cbx@apa@ifnamesaved
             {\printnames{shortauthor}}
             {\ifnameundef{groupauthor}
               {\printnames[labelname]{author}}
               {\printnames[labelname]{groupauthor}}}}}%
        \setunit{\ifbool{cbx:np}
                  {\printdelim{nameyeardelim}}
                  {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
        \printtext[bibhyperref]{%
          \ifnameundef{shortauthor}
           {}
           {\cbx@apa@ifnamesaved
             {}
             {\printnames{shortauthor}\setunit{\printdelim{nameyeardelim}}}}%
          \usebibmacro{cite:plabelyear+extradate}}%
        \savefield{fullhash}{\cbx@lasthash}}}}
\makeatother

我应该如何修改上述内容才能使 \citet 工作?(\citep 工作)

答案1

您在序言中用于链接更多引文输出的附加代码与您选择的样式不兼容。(您拥有的代码看起来适用于 - 可能过时的版本 - biblatex-apa。)

我会接受链接区域比 略小,natbib然后继续使用它。但如果你绝对需要更大的链接区域,那么我建议你遵循超链接名称与 biblatex 作者年份 (biblatex 1.4b)为了style=authoryear,

答案2

我认为,当使用这种 biblatex 样式并将 natbib=true 链接到引文中的作者和年份时,即使对于包括所有其他 natbib 引文命令在内的所有错误也不会出现\citet,我们可以使用我从 @lockstep 使用的以下 bib 宏超链接名称与 biblatex 作者年份

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

\DeclareCiteCommand*{\cite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{citeyear}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

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

\DeclareCiteCommand*{\citep}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\usebibmacro{citeyear}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcite}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
  \printtext[bibhyperref]{ \usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citet}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{textcite}}}
  {\ifbool{cbx:parens}
     {\bibcloseparen\global\boolfalse{cbx:parens}}
     {}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}

相关内容