如果参考书目中包含一位特定作者,请更改“et al”

如果参考书目中包含一位特定作者,请更改“et al”

我正在尝试更改参考书目中出现的 et~al。在这种情况下,在额外的(et~al)作者中有一位作者,我正尝试使用@LawrenceCrosby 的答案在参考书目中将其加粗这里

我的代码是:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{MyBibliography.bib}
  @article{cite1,
    author={Konstantinos Leledakis},
    title={An Article},
    year={2019},
    journal={Some Journal}
  }
  @article{cite2,
    author={Another Author and Konstantinos Leledakis},
    title={A Book},
    year={2017},
    journal={A publisher}
  }
  @book{cite3,
    author={Another SomeAuthor and One AnotherAuthor and SomeOther UnKnownAuthor and Konstantinos Leledakis},
    title={A Book},
    year={1988},
    publisher={Someone}
    }
  @book{cite4,
    author={Another Author and An UnknownAuthor and SomeOther UnKnownAuthor},
    title={A Book},
    year={2015},
    publisher={A publisher}
  }
\end{filecontents}

\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear-comp,maxnames=2, minnames=2]{biblatex}
\usepackage{etoolbox}


\DefineBibliographyStrings{english}{andothers={\ifthenelse{\boolean{bold}}{et~al(including Leledakis, K.)}{et~al}\adddot}}


\newboolean{bold}
\newcommand{\makeauthorbold}[1]{%
  \setboolean{bold}{false}
  \DeclareNameFormat{author}{%
    \ifthenelse{\value{listcount}=1}
    {%
      {\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\setboolean{bold}{true}\mkbibbold{\namepartfamily\addcomma\addspace \namepartgiveni}}{\namepartfamily\addcomma\addspace \namepartgiveni}}
      %
    }{\ifnumless{\value{listcount}}{\value{liststop}}
        {\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\setboolean{bold}{true}\mkbibbold{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni}}{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni}}
        {\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\setboolean{bold}{true}\mkbibbold{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni\addcomma\isdot}}{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni\addcomma\isdot}}%
      }
    \ifthenelse{\value{listcount}<\value{liststop}}
    {\addcomma\space}
  }
}

%\makeauthorbold{Leledakis}


\DefineBibliographyStrings{english}{andothers={et~al}} % To translate "et al."

\ExecuteBibliographyOptions{firstinits=true, uniquename=init}

\addbibresource{MyBibliography.bib}
\renewcommand*{\nameyeardelim}{\addcomma\addspace} % Should add the comma, but somehow doesn't work

\begin{document}
\nocite{*}

\printbibliography
\end{document}

这有两个问题:

  1. 如果我注释掉(我的意思是启用)注释掉的命令%\makeauthorbold{Leledakis}并启用它。结果如下:

在此处输入图片描述

(包含一些 et~al)变成:

在此处输入图片描述

其中名称已经突出显示,但是 et~al. 部分完全缺失。

附言:我也测试了没有我所做的更改的代码,但它仍然缺少 et. al. 部分。

答案1

\DeclareNameFormat{author}是对原始名称格式的修改,但仍有一些不足之处。

  1. 它不能处理“von”部分和“Jr.”部分。
  2. 它无法处理“et al.”,因为它缺少对标准的调用\usebibmacro{name:andothers}
  3. 在现代biblatex版本中,它甚至会因语法错误而产生错误。(最后一个\ifthenelse缺少一个错误的分支。另请参阅https://github.com/plk/biblatex/issues/874

我建议你使用更强大的版本之一,以使你的名字加粗使用 biblatex 将特定作者设为粗体据我所知,如果“包含”开箱即用的相关名称,则没有任何解决方案会将“et al.”加粗,但我们可以添加它。

作为我使用的基础我的答案它使用哈希,但允许使用方便的接口来检索它们。棘手的是检查“et al.”是否也包含要突出显示的名称。我们通过循环遍历所有剩余的名称来做到这一点,\indexnames否则不会打印任何内容。

\documentclass{article}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear-comp,
            maxnames=2, minnames=2,
            giveninits=true, uniquename=init]{biblatex}

\makeatletter
% setup for auxiliary bib file
\def\hlblx@bibfile@name{\jobname -boldnames.bib}
\newwrite\hlblx@bibfile
\immediate\openout\hlblx@bibfile=\hlblx@bibfile@name

\newcounter{hlblx@name}
\setcounter{hlblx@name}{0}

% write names to auxiliary bib file and push hash to bold list
\newcommand*{\hlblx@writenametobib}[1]{%
  \stepcounter{hlblx@name}%
  \edef\hlblx@tmp@nocite{%
    \noexpand\AfterPreamble{%
      \noexpand\setbox0\noexpand\vbox{%
        \noexpand\hlblx@getmethehash{hlblx@name@\the\value{hlblx@name}}}}%
  }%
  \hlblx@tmp@nocite
  \immediate\write\hlblx@bibfile{%
    @misc{hlblx@name@\the\value{hlblx@name}, author = {\unexpanded{#1}}, %
          options = {dataonly=true},}%
  }%
}

\AtEndDocument{%
  \closeout\hlblx@bibfile}

\addbibresource{\hlblx@bibfile@name}

% extract hashes from bib file
\newcommand*{\hlbxl@boldhashes}{}
\DeclareNameFormat{hlblx@hashextract}{%
  \xifinlist{\thefield{hash}}{\hlbxl@boldhashes}
    {}
    {\listxadd{\hlbxl@boldhashes}{\thefield{fullhash}}}}

\DeclareCiteCommand{\hlblx@getmethehash}
  {}
  {\printnames[hlblx@hashextract][1-999]{author}}
  {}
  {}

% add and reset list of bold names
\newcommand*{\addboldnames}{\forcsvlist\hlblx@writenametobib}
\newcommand*{\resetboldnames}{\def\hlbxl@boldhashes{}}

\newcommand*{\mkboldifhashinlist}[1]{%
  \xifinlist{\thefield{hash}}{\hlbxl@boldhashes}
    {\mkbibbold{#1}}
    {#1}}

\newtoggle{boldnameincluded}
\newbibmacro*{name:flagbold}{%
  \def\do##1{\iffieldequalstr{hash}{##1}{\global\toggletrue{boldnameincluded}\listbreak}{}}%
  \dolistloop{\hlbxl@boldhashes}%
}

\DeclareNameWrapperFormat{boldifhashinlist}{%
  \renewcommand*{\mkbibcompletename}{\mkboldifhashinlist}%
  #1}

\DeclareNameWrapperAlias{sortname}{default}
\DeclareNameWrapperAlias{default}{boldifhashinlist}

\DeclareIndexNameFormat{flagbold}{%
  \usebibmacro{name:flagbold}}

\newcounter{boldflagcount}
\newcommand*{\mkbibboldandothers}[2]{%
  \iftoggle{boldnameincluded}
    {\mkbibbold{#2#1}}
    {#2}}

\renewbibmacro*{name:andothers}{%
  \ifboolexpr{
    test {\ifnumequal{\value{listcount}}{\value{liststop}}}
    and
    test \ifmorenames
  }
    {\ifnumgreater{\value{liststop}}{1}
       {\finalandcomma}
       {}%
     \global\togglefalse{boldnameincluded}%
     \ifnumgreater{\value{listtotal}}{\value{listcount}}
       {\defcounter{boldflagcount}{\value{listcount}+1}%
        \expandafter\def\expandafter\hlblx@currname\expandafter{\currentname}%
        \indexnames[flagbold][\the\value{boldflagcount}-\the\value{listtotal}]{\hlblx@currname}}%
       {}%
     \printdelim{andothersdelim}%
     \bibstring[\mkbibboldandothers{ (incuding K.~Leledakis)}]{andothers}}
    {}}
\makeatother


\addboldnames{Konstantinos Leledakis}


\begin{filecontents}{\jobname.bib}
@article{cite1,
  author  = {Konstantinos Leledakis},
  title   = {An Article},
  year    = {2019},
  journal = {Some Journal},
}
@article{cite2,
  author  = {Another Author and Konstantinos Leledakis},
  title   = {A Book},
  year    = {2017},
  journal = {A publisher},
}
@book{cite3,
  author    = {Another SomeAuthor and One AnotherAuthor
               and SomeOther UnKnownAuthor and Konstantinos Leledakis},
  title     = {A Book},
  year      = {1988},
  publisher = {Someone},
}
@book{cite4,
  author    = {Another Author and An UnknownAuthor
               and SomeOther UnKnownAuthor},
  title     = {A Book},
  year      = {2015},
  publisher = {A publisher},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

作者 A. 和 **K. Leledakis** (2017)。“一本书”。在:一家出版商。//作者 A.、A. UnknownAuthor 等 (2015)。一本书。一家出版商。//**Leledakis, K.** (2019)。“一篇文章”。在:某本期刊。//某作者 A.、O. AnotherAuthor 等(包括 K. Leledakis)** (1988)。一本书。某人。

如果你想要为你的简历格式化一份出版物列表,你可能需要看看biblatex-publist

編輯使用更优雅的版本来格式化完整名称。\DeclareNameWrapperFormat\mkbibcompletename仅分别在 v3.12 (2018-10-30) 和 v3.13 (2019-08-17) 中可用biblatex。如果您使用的是旧版本的,请参阅编辑历史biblatex

相关内容