biblatex 中的两种样式,带有 textcite、作者(年份)和(作者,年份)

biblatex 中的两种样式,带有 textcite、作者(年份)和(作者,年份)

我正在使用biblatex以下命令,这些命令使用\textcite{}命令生成作者(年份)类型的引用。但是,有些地方我需要(作者,年份)类型的引用。我该怎么做?谢谢。

\documentclass{article}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear,maxcitenames=2]{biblatex}

%This part is for citation style textcite
\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \ifboolexpr{ ( not test {\iffieldundef{prenote}} and
                  test {\ifnumequal{\value{citecount}}{1}} ) or
                ( not test {\iffieldundef{postnote}} and
                  test {\ifnumequal{\value{citecount}}{\value{citetotal}}} ) }
     {\usebibmacro{textcite}}
     {\printtext[bibhyperref]{% Apply citation link to bibmacro output
        \DeclareFieldAlias{bibhyperref}{default}% Prevent nested hyperlinks
        \usebibmacro{textcite}%
        \ifbool{cbx:parens}{\bibcloseparen\global\boolfalse{cbx:parens}}{}}}}
  {\ifbool{cbx:parens}{\bibcloseparen\global\boolfalse{cbx:parens}}{}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}

答案1

使用authoryear引用样式,\parencite使用宏\nameyeardelim来存储引用中名称和年份之间的内容。

authoryear.cbx中,cite命令\parencite定义如下:

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

并且在biblatex.def, 我们发现

\newcommand*{\nameyeardelim}{\addspace}

您可以定义自己的 cite 命令,在作者和年份之间放置逗号,并将所有内容放在括号中,例如通过重新定义\nameyeardelim

\DeclareCiteCommand{\myparencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\def\nameyeardelim{\addcomma\addspace}%
   \usebibmacro{citeindex}%
   \usebibmacro{cite}%
   \def\nameyeardelim{\addspace}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

通过在打印此引文后改\nameyeardelim回简单\addspace,我们可以避免干扰其他引文。

使用filecontents包生成一个完整的示例,结果如下

\documentclass{article}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear]{biblatex}
\addbibresource{\jobname.bib}

%This part is for citation style textcite
\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \ifboolexpr{ ( not test {\iffieldundef{prenote}} and
                  test {\ifnumequal{\value{citecount}}{1}} ) or
                ( not test {\iffieldundef{postnote}} and
                  test {\ifnumequal{\value{citecount}}{\value{citetotal}}} ) }
     {\usebibmacro{textcite}}
     {\printtext[bibhyperref]{% Apply citation link to bibmacro output
        \DeclareFieldAlias{bibhyperref}{default}% Prevent nested hyperlinks
        \usebibmacro{textcite}%
        \ifbool{cbx:parens}{\bibcloseparen\global\boolfalse{cbx:parens}}{}}}}
  {\ifbool{cbx:parens}{\bibcloseparen\global\boolfalse{cbx:parens}}{}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}

\DeclareCiteCommand{\myparencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\def\nameyeardelim{\addcomma\addspace}%
   \usebibmacro{citeindex}%
   \usebibmacro{cite}%
   \def\nameyeardelim{\addspace}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}

@article{test,
  title={something},
  author={someone},
  journal={some journal},
  year={2013}
}

\end{filecontents}

\begin{document}
\textcite{test}
\parencite{test}
\myparencite{test}
\textcite{test}
\end{document}

这导致

编译的pdf

因此\myparencite{test}在作者和年份之间加一个逗号。

相关内容