使用 biblatex 根据 langid 字段更改作者顺序

使用 biblatex 根据 langid 字段更改作者顺序

我想更改参考书目中匈牙利语条目的某些方面,即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}

希瓦特科扎索克·科瓦奇·贝拉和《吻亚诺什》(2022 年)。一本有两位作者的匈牙利书。布达佩斯:Kiadó。史密斯(约翰)和莱斯利·泰勒(2022 年)。一本有两位作者的英文书。城市: 出版商。

根据您想要对其他名称格式进行的操作(例如“由......编辑”),为匈牙利名称定义新的 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} 

代码输出

相关内容