我使用 Biblatex 和 authoryear-icomp 引用格式。该\textcite{ref}
命令打印出姓氏(年份),即 Groenig(2000),但我希望它给出名字姓氏(年份),即 Peter Groenig(2000)。
如您所见,此自定义不仅涉及格式化,还涉及从.bib
文件中检索新信息。我希望所有其他引用命令(例如\parencite
)保持其原始行为。
我怎样才能做到这一点 ?
答案1
我们authoryear-icomp
需要修改 bibmacrotextcite
以使用名称格式first-last
而不是labelname
格式,我们可以通过重新定义整个宏来实现
\makeatletter
\renewbibmacro*{textcite}{%
\iffieldequals{namehash}{\cbx@lasthash}
{\iffieldundef{shorthand}
{\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
\(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
{\setunit{\addcomma}%
\usebibmacro{cite:extrayear}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:labelyear+extrayear}%
\savefield{labelyear}{\cbx@lastyear}}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:shorthand}%
\global\undef\cbx@lastyear}}
{\ifnameundef{labelname}
{\iffieldundef{shorthand}
{\usebibmacro{cite:label}%
\setunit{%
\global\booltrue{cbx:parens}%
\addspace\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
{\usebibmacro{cite:ibid}}
{\usebibmacro{cite:labelyear+extrayear}}}
{\usebibmacro{cite:shorthand}}}
{\printnames[first-last]{labelname}%<----- this is the modification
\setunit{%
\global\booltrue{cbx:parens}%
\addspace\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\iffieldundef{shorthand}
{\iffieldundef{labelyear}
{\usebibmacro{cite:label}}
{\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
{\usebibmacro{cite:ibid}}
{\usebibmacro{cite:labelyear+extrayear}}}%
\savefield{labelyear}{\cbx@lastyear}}
{\usebibmacro{cite:shorthand}%
\global\undef\cbx@lastyear}}%
\stepcounter{textcitecount}%
\savefield{namehash}{\cbx@lasthash}}%
\setunit{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\textcitedelim}}
\makeatother
或者使用xpatch
包装如下
\xpatchbibmacro{textcite}
{\printnames{labelname}}
{\printnames[first-last]{labelname}}
{}
{}
MWE(使用xpatch
)
\documentclass{article}
\usepackage[style=authoryear-icomp,backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage{xpatch}
\xpatchbibmacro{textcite}
{\printnames{labelname}}
{\printnames[first-last]{labelname}}
{}
{}
\begin{document}
Lorem \textcite{geer} ipsum \textcite{worman} dolor \textcite{sigfridsson}.
Lorem \cite{geer} ipsum \cite{worman} dolor \cite{sigfridsson}.
\printbibliography
\end{document}
这种修改不能完全适用于所有其他样式,因为\textcite
与其他命令不同,它使用各种不同的方式实现。然而,让\printnames{labelname}
指令使用first-last
名称格式的基本思想几乎总是正确的。