biblatex
根据style=alphabetic
作者数量,以某种方式根据作者姓名生成标签:(1)对于单个作者或“多个”作者,标签从第一个作者的姓氏开始;(2)对于“少数”作者,标签由所有作者的姓名首字母组成。
我想仅对情况 (2) 应用格式。具体来说,我想将标签设置为小写字母。
下面的代码实现了我所说的功能,但是它还将类型 (1) 标签设置为小写,因此它不是一个真正的解决方案。
\documentclass{article}
\begin{filecontents*}{\jobname.bib}
@document{one,
author = { Single Author },
}
@document{few,
author = { One and Two and Three Authors },
}
@document{many,
author = { One and Two and Three and Four Authors },
}
\end{filecontents*}
\usepackage[style=alphabetic,]{biblatex}
\addbibresource{\jobname.bib}
%---//
\DeclareLabelalphaTemplate{
\labelelement{
\field[final]{shorthand}
\field{label}
\field[strwidth=3,strside=left,ifnames=1]{labelname}
\field[lowercase,strwidth=1,strside=left]{labelname}
}
\labelelement{
\field[strwidth=2,strside=right]{year}
}
}
\DeclareFieldFormat{labelalpha}{\textsc{#1}}
%---\\
\begin{document}
\cite{one,few,many}
\printbibliography
\end{document}
作为参考,以下是 MWE 的输出与默认aplphabetic
样式的比较:
答案1
似乎\DeclareLabelalphaTemplate
在标签期间添加条件格式并不可行。不过,就您而言,这其实没有必要,事后应用格式就足够了(这可能无法适用于所有可能的用例,但在这里却适用)。
为了应用正确的格式,我们首先需要找出何时将标签设置为小写字母;如果有多个作者(单个作者的名字的部分会写出来,但不是用小写字母),并且作者不超过三个(对于四个或更多作者,我们得到第一个 + 等),情况就是这样的,所以以下逻辑应该可以解决问题:
\DeclareFieldFormat{labelalpha}{%
\ifboolexpr{
test {\ifnumgreater{\value{labelname}}{1}}
and not
test {\ifnumgreater{\value{labelname}}{3}}
}
{\textsc{#1}}
{#1}}
平均能量损失
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@document{one,
author = {Silvia T. Udent},
title = {Single Author},
year = {2001},
}
@document{two,
author = {William Riter and Anne Uthor},
title = {Two Authors},
year = {2002},
}
@document{three,
author = {Patricia Rofessor and Ronald E. Searcher and Silvia T. Udent},
title = {Three Authors},
year = {2003},
}
@document{four,
author = {William Riter and Anne Uthor and Patricia Rofessor and Ronald E. Searcher},
title = {Four Authors},
subtitle = {That Is: Many Authors},
year = {2004},
}
\end{filecontents*}
\usepackage[style=alphabetic]{biblatex}
\addbibresource{\jobname.bib}
\DeclareLabelalphaTemplate{
\labelelement{
\field[final]{shorthand}
\field{label}
\field[strwidth=3,strside=left,ifnames=1]{labelname}
\field[lowercase,strwidth=1,strside=left]{labelname}
}
\labelelement{
\field[strwidth=2,strside=right]{year}
}
}
\DeclareFieldFormat{labelalpha}{%
\ifboolexpr{
test {\ifnumgreater{\value{labelname}}{1}}
and not
test {\ifnumgreater{\value{labelname}}{3}}
}
{\textsc{#1}}
{#1}}
\begin{document}
\nocite{*}
\printbibliography
\end{document}