我想修改 BibLaTeX 的引用宏以便:
- 对于第一次引用,如果作者数量少于 5 人,则不管作者数量如何,都将其全部打印出来。
- 在所有其他情况下,请遵循正常的 APA 引用样式。
这是我目前所拥有的。它通过第一次打印出所有作者部分起作用,但似乎\ifthenelse
总是评估为真并执行第一个分支(即,无论如何都打印出所有作者)
\documentclass[stu, 12pt, biblatex]{apa7}
% APA citation style
\usepackage{csquotes}
\usepackage{hyperref}
\addbibresource{cite.bib}
\usepackage{xpatch}
\xpatchbibmacro{cite}{\printnames{labelname}}%
{%
\ifciteseen{%
\printnames{labelname}%
}{%
\ifthenelse{\value{listtotal} < 6}{%
\printnames[][-\value{listtotal}]{labelname}%
}{%
\printnames{labelname}%
}%
}%
}
{}{}
\title{Test}
\author{Author}
\affiliation{Affiliation}
\course{Course}
\professor{Professor}
\duedate{\today}
\begin{document}
\maketitle
Researches had shown that \TeX\ is the best program \autocite{1Author}, \autocite{2Authors}, \autocite{3Authors}, \autocite{4Authors}, \autocite{5Authors}, \autocite{6Authors}
Researches had shown that \TeX\ is the best program again \autocite{1Author}, \autocite{2Authors}, \autocite{3Authors}, \autocite{4Authors}, \autocite{5Authors}, \autocite{6Authors}
\printbibliography
\end{document}
这是 Bib 文件
@book{6Authors,
title = {6 authors},
author = {Cao, Mina and Anish, Pruitt and Lulu, Douglas and Zahra, Sing and Wesley, Smith and Anish, Pruitt},
}
@book{5Authors,
title = {5 authors},
author = {Mina, Goyal and Anish, Pruitt and Lulu, Douglas and Zahra, Sing and Wesley, Smith},
}
@book{4Authors,
title = {4 authors},
author = {Lulu, Douglas and Anish, Pruitt and Mina, Goyal and Zahra, Sing},
}
@book{3Authors,
title = {3 authors},
author = {Wesley, Smith and Anish, Pruitt and Mina, Goyal},
}
@book{2Authors,
title = {2 authors},
author = {Zahra, Sing and Mina, Cao},
}
@book{1Author,
title = {1 author},
author = {Anish, Pruitt},
}
答案1
文档biblatex
中提到listtotal
(在第 189 页的描述中\printnames
,重点是我的):
每当
\printnames
处理\printlist
列表时,可以通过四个计数器访问有关当前状态的信息:计数器listtotal
保存当前列表中的项目总数,[...]。这些计数器旨在用于列表格式化指令。也可以在和的listtotal
第二个可选参数中使用。\printnames
\printlist
请注意,这些计数器是列表格式指令的本地计数器,在其他地方使用时不会保存有意义的值。对于每个列表,还有一个同名的计数器,用于保存相应列表中的项目总数。例如,计数器author
保存列表中的项目总数author
。这些计数器与 listtotal 类似,但它们也可以独立于列表格式指令使用。
因此,在\ifthenelse
(这不是列表格式指令)中listtotal
,计数器没有有意义的值。相反,您必须使用计数器labelname
来获取中的条目数labelname
:
\documentclass[stu, 12pt, biblatex]{apa7}
% APA citation style
\usepackage{csquotes}
\usepackage{hyperref}
\addbibresource{cite.bib}
\usepackage{xpatch}
\xpatchbibmacro{cite}{\printnames{labelname}}%
{%
\ifciteseen{%
\printnames{labelname}%
}{%
\ifthenelse{\value{labelname} < 6}{%
\printnames[][-\value{listtotal}]{labelname}%
}{%
\printnames{labelname}%
}%
}%
}
{}{}
\title{Test}
\author{Author}
\affiliation{Affiliation}
\course{Course}
\professor{Professor}
\duedate{\today}
\begin{document}
\maketitle
Researches had shown that \TeX\ is the best program \autocite{1Author}, \autocite{2Authors}, \autocite{3Authors}, \autocite{4Authors}, \autocite{5Authors}, \autocite{6Authors}
Researches had shown that \TeX\ is the best program again \autocite{1Author}, \autocite{2Authors}, \autocite{3Authors}, \autocite{4Authors}, \autocite{5Authors}, \autocite{6Authors}
\printbibliography
\end{document}