![使用 biblatex 根据 langid 字段更改作者顺序](https://linux22.com/image/453245/%E4%BD%BF%E7%94%A8%20biblatex%20%E6%A0%B9%E6%8D%AE%20langid%20%E5%AD%97%E6%AE%B5%E6%9B%B4%E6%94%B9%E4%BD%9C%E8%80%85%E9%A1%BA%E5%BA%8F.png)
我想更改参考书目中匈牙利语条目的某些方面,即langid = {magyar}
在 bib 文件中标记为。根据 langid 字段更改参考书目外观在以下情况下效果很好,例如:
% no comma between family and given name if langid is magyar
\renewcommand{\revsdnamepunct}{%
\ifboolexpr{%
test {\iffieldequalstr{langid}{magyar}}%
}{}{,\space}%
}
% book title is in italics if langid is magyar
\DeclareFieldFormat[book]{title}{
\ifboolexpr{%
test {\iffieldequalstr{langid}{magyar}}}{\emph{#1}}{#1}}
使用下面的代码,我可以将作者的顺序改为先姓氏,然后名字,我希望这是匈牙利名字的顺序,但这会修改所有名字的顺序,而不仅仅是匈牙利名字的顺序:
\DeclareNameAlias{sortname}{family-given}
因此,我想引入与上述示例相同的条件,即只有那些名字才应该langid={magyar}
在 bib 文件中具有家庭给定的顺序,但这会出现错误:
\DeclareNameAlias{sortname}{
\ifboolexpr{%
test {\iffieldequalstr{langid}{magyar}}}{family-given}{given-family}}}
! Missing \endcsname inserted.
<to be read again>
\begingroup
l.45 ...id}{magyar}}}{family-given}{given-family}}
}
?
我怎样才能将匈牙利语条目的作者顺序更改为按家庭给出的顺序?
完整最小示例:
\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{hungarian}
\usepackage[backend=biber,
bibstyle=authoryear,citestyle=authoryear-comp,
sorting=nyt,
maxbibnames=10,maxcitenames=2]{biblatex}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@Book{KovacsKiss2022,
author = {Kovács, Béla and János Kiss},
date = {2022},
title = {A {Hungarian} book with two authors},
location = {Budapest},
publisher = {Kiadó},
langid = {magyar},
}
@Book{Smith2022,
author = {Smith, John and Leslie Taylor},
date = {2022},
title = {An {English} book with two authors},
publisher = {Publisher},
address = {City},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\renewcommand{\revsdnamepunct}{%
\ifboolexpr{%
test {\iffieldequalstr{langid}{magyar}}%
}{}{,\space}%
}
\DeclareFieldFormat[book]{title}{
\ifboolexpr{%
test {\iffieldequalstr{langid}{magyar}}}{\emph{#1}}{#1}}
\DeclareNameAlias{sortname}{family-given}
\DeclareNameAlias{sortname}{
\ifboolexpr{%
test {\iffieldequalstr{langid}{magyar}}}{family-given}{given-family}}}
\begin{document}
\nocite{Smith2022,KovacsKiss2022}
\printbibliography[heading=subbibliography]
\end{document}
答案1
\DeclareNameAlias
仅允许您选择现有的名称格式。它不允许使用复杂的逻辑,您需要使用\DeclareNameFormat
。
我们以 的定义为基础family-given/given-family
,该定义可以在biblatex.def
(第 910-940 页)。由于格式已经将列表中的名字反转为按家庭给定的顺序,我们只需添加一个测试,如果条目是匈牙利语,也要这样做。
请注意,如果\iffieldequalstr
这是您测试的唯一条件,则不需要将其包装在\ifboolexpr
.中\ifboolexpr
,只有当您想用“或”或“与”组合多个测试时才需要加入。
\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{hungarian}
\usepackage[
backend=biber,
style=authoryear-comp,
maxbibnames=10, maxcitenames=2,
]{biblatex}
\renewcommand{\revsdnamepunct}{%
\iffieldequalstr{langid}{magyar}
{}
{\addcomma\space}}
\DeclareFieldFormat[book]{title}{%
\iffieldequalstr{langid}{magyar}
{\emph{#1}}
{#1}}
\DeclareNameAlias{sortname}{family-given/given-family:hungarian}
\DeclareNameFormat{family-given/given-family:hungarian}{%
\ifboolexpr{
test {\ifnumequal{\value{listcount}}{1}}
or test {\iffieldequalstr{langid}{magyar}}}
{\ifgiveninits
{\usebibmacro{name:family-given}
{\namepartfamily}
{\namepartgiveni}
{\namepartprefix}
{\namepartsuffix}}
{\usebibmacro{name:family-given}
{\namepartfamily}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}}%
\ifboolexpe{%
test {\ifdefvoid\namepartgiven}
and
test {\ifdefvoid\namepartprefix}}
{}
{\usebibmacro{name:revsdelim}}}
{\ifgiveninits
{\usebibmacro{name:given-family}
{\namepartfamily}
{\namepartgiveni}
{\namepartprefix}
{\namepartsuffix}}
{\usebibmacro{name:given-family}
{\namepartfamily}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}}}%
\usebibmacro{name:andothers}}
\begin{filecontents*}{\jobname.bib}
@Book{KovacsKiss2022,
author = {Kovács, Béla and János Kiss},
date = {2022},
title = {A {Hungarian} book with two authors},
location = {Budapest},
publisher = {Kiadó},
langid = {magyar},
}
@Book{Smith2022,
author = {Smith, John and Leslie Taylor},
date = {2022},
title = {An {English} book with two authors},
publisher = {Publisher},
address = {City},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{Smith2022,KovacsKiss2022}
\printbibliography[heading=subbibliography]
\end{document}
根据您想要对其他名称格式进行的操作(例如“由......编辑”),为匈牙利名称定义新的 bibmacro 并根据具体情况切换使用该 bibmacro 可能会更优雅。
如果您想要支持匈牙利和非匈牙利名称列表,则可能需要采用不同的方法。nametemplates
可以在这里提供帮助(但也可能有点过度):Bibtex/Biber:如何使用埃塞俄比亚惯例引用作者?。
答案2
可能有更优雅的方法来做到这一点(所以我会等待一段时间才接受这个作为答案),但你可以把你的条件放在里面以这种方式\AtEveryBibitem
选择别名:sortname
\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{hungarian}
\usepackage[backend=biber,
bibstyle=authoryear,citestyle=authoryear-comp,
sorting=nyt,
maxbibnames=10,maxcitenames=2]{biblatex}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@Book{KovacsKiss2022,
author = {Kovács, Béla and János Kiss},
date = {2022},
title = {A {Hungarian} book with two authors},
location = {Budapest},
publisher = {Kiadó},
langid = {magyar},
}
@Book{Smith2022,
author = {Smith, John and Leslie Taylor},
date = {2022},
title = {An {English} book with two authors},
publisher = {Publisher},
address = {City},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\renewcommand{\revsdnamepunct}{%
\ifboolexpr{%
test {\iffieldequalstr{langid}{magyar}}%
}{}{,\space}%
}
\DeclareFieldFormat[book]{title}{
\ifboolexpr{%
test {\iffieldequalstr{langid}{magyar}}}{\emph{#1}}{#1}}
\DeclareNameAlias{sortname}{family-given}
\AtEveryBibitem{
\iffieldequalstr{langid}{magyar}
{\DeclareNameAlias{sortname}{given-family}}
{\DeclareNameAlias{sortname}{family-given}}
}
\begin{document}
\nocite{Smith2022,KovacsKiss2022}
\printbibliography[heading=subbibliography]
\end{document}