我需要提交我的作品。出版商有以下要求。使用作者年份引用法。
对于有 2 位作者的作品,所有引用均包含两位作者;对于有 3 至 5 位作者的作品,在第一次引用时包含所有作者,并在后续引用中使用第一作者姓名和“et al.”:对于有 6 位或更多作者的作品,所有引用均使用第一作者姓名和“et al.”。
在我的文档中
我有以下设置。
\usepackage[style=authoryear-comp, giveninits, hyperref=auto, uniquename=mininit, maxbibnames=99, maxcitenames=5, url=false, doi=false, backend=biber,sortcites, sorting=nyt]{biblatex}
\DeclareNameAlias{author}{last-first}
\DefineBibliographyStrings{english}{
page = {\ifbibliography{}{\adddot}},
pages = {\ifbibliography{}{\adddot}},
}
我意识到 maxcitenames=5 应该是这样的
\如果第一次遇到则大于 2 且小于 6 则为 5 但如果不是第一次遇到则为 1 但如果只有 2 则始终为 2 等等
我还需要将页面格式化为(第 3-4 页),除非这是参考书目中的最后一个字段,否则请保持原样
我对 if 语句感到困惑,并且不理解语法结构
我没有创建标签 pagination、maxcitenames 和 if 的代表。这些可能与这个问题相关。
感谢您的帮助
答案1
选项的值(min|max)(bib|cite)?names
只能是大于或等于一的整数,它们不能包含条件,并且您不能有条件地设置选项(不过,您可以手动设置相应的计数器,该选项的作用也仅限于此,但它会将值传递到后端,在后端,该值可能与唯一性和标签计算相关)在文档内(此时您知道您是第一次引用还是后续引用)。您必须在没有这些选项帮助的情况下实现该行为。
一个自然的方法是apa.cbx
,第 98-177 页
% Can't do this with the built-in printnames format as APA requires truncation
% and disambiguation only after first cite
% We either use uniquelist or minnames for truncation. If uniquelist isn't
% defined, we fall back on minnames
%
% \printnames does different things depending on whether the format you are
% calling is the default for the name field or is a custom format:
%
% max/minnames truncation is done before calling the format so we have
% to do \printnames[format][-\value{listtotal}]{field} to ensure we get
% all of the names in the list to work on here
%
% Explicit "and others" is dealt with in labelname:doname via a custom name:andothers
\DeclareNameFormat{labelname}{%
% First set the truncation point
\ifthenelse{\value{uniquelist}>1}
{\numdef\cbx@min{\value{uniquelist}}}
{\numdef\cbx@min{\value{minnames}}}%
% Always print the first name and the second if there are only two since
% "et al" must always be plural
\ifboolexpr{test {\ifnumcomp{\value{listcount}}{=}{1}}
or test {\ifnumcomp{\value{listtotal}}{=}{2}}}
{\usebibmacro{labelname:doname}%
{\namepartfamily}%
{\namepartfamilyi}%
{\namepartgiven}%
{\namepartgiveni}%
{\namepartprefix}%
{\namepartprefixi}%
{\namepartsuffix}%
{\namepartsuffixi}}
% We are looking at name >=3
% If the list is 6 or more names or we have seen citation before, potential truncation
{\ifboolexpr{test {\ifnumcomp{\value{listtotal}}{>}{5}}
or test {\ifciteseen}}
% Less than the truncation point, print normally
{\ifnumcomp{\value{listcount}}{<}{\cbx@min + 1}
{\usebibmacro{labelname:doname}%
{\namepartfamily}%
{\namepartfamilyi}%
{\namepartgiven}%
{\namepartgiveni}%
{\namepartprefix}%
{\namepartprefixi}%
{\namepartsuffix}%
{\namepartsuffixi}}
{}%
% At potential truncation point ...
\ifnumcomp{\value{listcount}}{=}{\cbx@min + 1}
% but enforce plurality of et al - only truncate here if there is at
% least one more element after the current potential truncation point
% so that "et al" covers at least two elements.
{\ifnumcomp{\value{listcount}}{<}{\value{listtotal}}
{\printdelim{andothersdelim}\bibstring{andothers}}
{\usebibmacro{labelname:doname}%
{\namepartfamily}%
{\namepartfamilyi}%
{\namepartgiven}%
{\namepartgiveni}%
{\namepartprefix}%
{\namepartprefixi}%
{\namepartsuffix}%
{\namepartsuffixi}}}
{}%
% After truncation point, do not print name
\ifnumcomp{\value{listcount}}{>}{\cbx@min + 1}
{\relax}%
{}}%
% We are looking at name >=3
% Name list is < 6 names or we haven't seen this citation before, print normally
{\usebibmacro{labelname:doname}%
{\namepartfamily}%
{\namepartfamilyi}%
{\namepartgiven}%
{\namepartgiveni}%
{\namepartprefix}%
{\namepartprefixi}%
{\namepartsuffix}%
{\namepartsuffixi}}}}
本质上,样式确保始终调用\printnames{labelname}
as\printnames[labelname][-\value{listtotal}]{labelname}
以始终获取所有名称,而不管任何maxnames
截断。然后,名称格式会遍历不同的情况,并且仅在您希望看到的情况下在列表中打印名称。它还考虑到该uniquelist
功能并确保等指的是多位作者,因此它比人们最初想象的要复杂一些。
一个更简单的版本可以忽略这些细微差别,并与 一起工作,authoryear-comp
如下所示。与默认版本相比,cite
和bibmacros 的修改仅在于的交换。宏保留名称格式的原始定义,而不包含 的代码textcite
\printnames{labelname}
\printnames[labelname][-\value{listtotal}]{labelname}
labelname:indiv
labelname
等。
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear-comp,
maxcitenames=2, mincitenames=1, maxbibnames=999,
citetracker, backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\DeclareNameFormat{labelname}{%
\ifboolexpr{test {\ifnumcomp{\value{listcount}}{=}{1}}
or test {\ifnumcomp{\value{listtotal}}{=}{2}}}
{\usebibmacro{labelname:indiv}}
{\ifboolexpr{test {\ifnumcomp{\value{listtotal}}{>}{5}}
or test {\ifciteseen}}
{\ifnumcomp{\value{listcount}}{=}{2}
{\printdelim{andothersdelim}\bibstring{andothers}}
{}}
{\usebibmacro{labelname:indiv}}}}
\newbibmacro{labelname:indiv}{%
\ifcase\value{uniquename}%
\usebibmacro{name:family}
{\namepartfamily}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}%
\or
\ifuseprefix
{\usebibmacro{name:given-family}
{\namepartfamily}
{\namepartgiveni}
{\namepartprefix}
{\namepartsuffixi}}
{\usebibmacro{name:given-family}
{\namepartfamily}
{\namepartgiveni}
{\namepartprefixi}
{\namepartsuffixi}}%
\or
\usebibmacro{name:given-family}
{\namepartfamily}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}%
\fi
}
\makeatletter
\renewbibmacro*{cite}{%
\iffieldundef{shorthand}
{\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
{\usebibmacro{cite:label}%
\setunit{\printdelim{nonameyeardelim}}%
\usebibmacro{cite:labeldate+extradate}%
\usebibmacro{cite:reinit}}
{\iffieldequals{namehash}{\cbx@lasthash}
{\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
\(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
{\setunit{\addcomma}%
\usebibmacro{cite:extradate}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:labeldate+extradate}%
\savefield{labelyear}{\cbx@lastyear}}}
{\printnames[labelname][-\value{listtotal}]{labelname}%
\setunit{\printdelim{nameyeardelim}}%
\usebibmacro{cite:labeldate+extradate}%
\savefield{namehash}{\cbx@lasthash}%
\savefield{labelyear}{\cbx@lastyear}}}}
{\usebibmacro{cite:shorthand}%
\usebibmacro{cite:reinit}}%
\setunit{\multicitedelim}}
\renewbibmacro*{textcite}{%
\iffieldequals{namehash}{\cbx@lasthash}
{\iffieldundef{shorthand}
{\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
\(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
{\setunit{\addcomma}%
\usebibmacro{cite:extradate}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:labeldate+extradate}%
\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}%
\printdelim{nonameyeardelim}\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\usebibmacro{cite:labeldate+extradate}}
{\usebibmacro{cite:shorthand}}}
{\printnames[labelname][-\value{listtotal}]{labelname}%
\setunit{%
\global\booltrue{cbx:parens}%
\printdelim{nameyeardelim}\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\iffieldundef{shorthand}
{\iffieldundef{labelyear}
{\usebibmacro{cite:label}}
{\usebibmacro{cite:labeldate+extradate}}%
\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
\begin{document}
\cite{sigfridsson,aksin,companion,herrmann}
\cite{sigfridsson,aksin,companion,herrmann}
\printbibliography
\end{document}
但是,您对所需输出的描述完全符合 APA 规则,并且您的其余设置也让我怀疑您想要非常接近(即使不是完全符合)的 APA 样式。因此,也许您最好使用
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=apa, backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\cite{sigfridsson,aksin,companion,herrmann}
\cite{sigfridsson,aksin,companion,herrmann}
\printbibliography
\end{document}
一个警告:biblatex-apa
尽可能接近地实现 APA 样式biblatex
(可能甚至与 LaTeX 总体而言,APA 样式的另一种 LaTeX 实现是基于 BibTeX 的apacite
),这意味着它非常复杂,不像标准样式那样容易定制。因此,如果您不需要 APA 样式,您可以将其用作biblatex-apa
基础,但根据您的需求,实现所需的修改可能比在标准样式中更棘手。