自动突出显示参考书目中的名称不适用于中间名首字母

自动突出显示参考书目中的名称不适用于中间名首字母

我一直在想办法自动在参考书目中突出显示我的名字。我想我可以只比较名字和\namepartgiven姓氏\namepartfamily,但没有突出显示任何内容。问题的根源似乎namepartgiven与我指定的名字不同。最初我以为这是由于\bibnamedelima,但事实似乎并非如此。下面是一个最小的工作示例。

\begin{filecontents*}{test.bib}
@inproceedings{hattimare2022maruna,
    title        = {Maruna Bot: An Extensible Retrieval-Focused Framework for Task-Oriented Dialogues},
    author       = {Hattimare, Amit and Dharawat, Arkin and Khan, Yelman and Lien, Yen-Chieh and Samarinas, Chris and Wei, George Z. and Yang, Yulin and Zamani, Hamed},
    author+an    = {6=highlight;},
    year         = 2022,
    booktitle    = {Alexa Prize TaskBot Challenge Proceedings},
    url          = {https://www.amazon.science/alexa-prize/proceedings/maruna-bot-an-extensible-retrieval-focused-framework-for-task-oriented-dialogues}
}
\end{filecontents*}

\documentclass{article}

\usepackage[ % BibLaTeX
    sorting=ydnt, % Sorts entries by year (descending order), name, title
    style=verbose,
    doi=false,
    isbn=true,
    url=false,
    eprint=false,
    backref = false, % include back references in bibliography
    maxcitenames=3, % affects only the citations in the document body
    maxbibnames=99, % affects only the bibliography, pass 99 to print all
    hyperref=true,
    block=none,
    backend=biber % {Options: bibtex, biber}
    ]{biblatex}
\usepackage{etoolbox}
    
\def\bibnamedelima{ }

\makeatletter
\newcommand*{\name}[2]{\def\@firstname{#1}\def\@lastname{#2}}
\newcommand*{\firstname}[1]{\def\@firstname{#1}}
\newcommand*{\lastname}[1]{\def\@lastname{#1}}

\renewcommand*{\mkbibnamefamily}[1]{%
  \ifboolexpr{ test {\ifdefstrequal{\namepartgiven}{\@firstname}}
               and
               test {\ifdefstrequal{\namepartfamily}{\@lastname}}}
    {\textbf{#1}}%
    {#1}%
}

\renewcommand*{\mkbibnamegiven}[1]{%
  \ifboolexpr{ test {\ifdefstrequal{\namepartgiven}{\@firstname}}
               and
               test {\ifdefstrequal{\namepartfamily}{\@lastname}}}
    {\textbf{#1}}%
    {#1}%
}
\makeatother
\name{George Z.}{Wei}. % My name should be highlighted, but it isn't????
                       % I narrowed it down to the first name (\namepartgiven), but not sure why it doesn't work
    
\addbibresource{test.bib}

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

谁能向我解释为什么这没有突出显示我的名字以及如何解决这个问题?

答案1

Biblatex 在将名称分配给\namepartgiven。如果姓名由多个元素组成(这里是名字和首字母),则会插入各种格式命令来处理空格、句号、连字符等(请参阅Biblatex 手册,第 3.12.1 节通用命令和钩子)。此处名称存储为George\bibnamedelima Z.。该\bibnamedelima宏默认定义为具有高惩罚的空格,这意味着 LaTeX 将尝试不在该位置插入换行符。

因此,最简单的解决方案是直接与这个预处理字符串进行比较,即保持 MWE 不变,只更改

\name{George\bibnamedelima Z.}{Wei}

结果:

在此处输入图片描述

要检查预处理期间发生的情况,您可以向任一宏定义添加调试行\mkbibname,例如:

\renewcommand*{\mkbibnamegiven}[1]{%
  \typeout{\meaning\namepartgiven}
  \ifboolexpr{ test {\ifdefstrequal{\namepartgiven}{\@firstname}}
               and
               test {\ifdefstrequal{\namepartfamily}{\@lastname}}}
    {\textbf{#1}}%
    {#1}%
}

添加的行将\typeout{\meaning\namepartgiven}(针对每个名称分别)的定义打印\namepartgiven到终端和日志文件。

答案2

如果您想对名称部分进行字符串比较,您需要考虑到后端可能会对名称应用一些后期处理,因此结果与预期略有不同。

在这种情况下,问题确实是\bibnamedelima。但是,解决方案不是重新定义\bibnamedelima。解决方案是预期它存在并相应地更改比较字符串。这一切都在玛丽金回答

不过,我想建议一种更方便的方法。这种方法在我的答案使用 biblatex 将特定作者设为粗体。我们的想法是让 Biber 处理所有这些名称规范化,并以通常的格式在 LaTeX 级别输入名称。

\documentclass{article}

\usepackage[
  backend=biber,
  style=verbose,
  sorting=ydnt,
  maxcitenames=3,
  maxbibnames=99,
  doi=false,
  isbn=true,
  url=false,
  eprint=false,
  backref = false,
  block=none,
]{biblatex}
    

\makeatletter
\def\nhblx@bibfile@name{\jobname -nhblx.bib}
\newwrite\nhblx@bibfile
\immediate\openout\nhblx@bibfile=\nhblx@bibfile@name

\immediate\write\nhblx@bibfile{%
  @comment{Auto-generated file}\blx@nl}

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

\newcommand*{\nhblx@writenametobib}[1]{%
  \stepcounter{nhblx@name}%
  \edef\nhblx@tmp@nocite{%
    \noexpand\AfterPreamble{%
      \noexpand\setbox0\noexpand\vbox{%
        \noexpand\nhblx@getmethehash{nhblx@name@\the\value{nhblx@name}}}}%
  }%
  \nhblx@tmp@nocite
  \immediate\write\nhblx@bibfile{%
    @misc{nhblx@name@\the\value{nhblx@name}, author = {\unexpanded{#1}}, %
          options = {dataonly=true},}%
  }%
}

\AtEndDocument{%
  \closeout\nhblx@bibfile}

\addbibresource{\nhblx@bibfile@name}

\newcommand*{\nhblx@boldhashes}{}
\DeclareNameFormat{nhblx@hashextract}{%
  \xifinlist{\thefield{hash}}{\nhblx@boldhashes}
    {}
    {\listxadd{\nhblx@boldhashes}{\thefield{hash}}}}

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

\newcommand*{\addboldnames}{\forcsvlist\nhblx@writenametobib}
\newcommand*{\resetboldnames}{\def\nhblx@boldhashes{}}

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

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

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

\addboldnames{George Z. Wei}


\begin{filecontents*}{\jobname.bib}
@inproceedings{hattimare2022maruna,
  title     = {Maruna Bot: An Extensible Retrieval-Focused Framework
               for Task-Oriented Dialogues},
  author    = {Hattimare, Amit and Dharawat, Arkin and Khan, Yelman
               and Lien, Yen-Chieh and Samarinas, Chris and Wei, George Z.
               and Yang, Yulin and Zamani, Hamed},
  year      = 2022,
  booktitle = {Alexa Prize TaskBot Challenge Proceedings},
  url       = {https://www.amazon.science/alexa-prize/proceedings/maruna-bot-an-extensible-retrieval-focused-framework-for-task-oriented-dialogues}
}
\end{filecontents*}
\addbibresource{\jobname.bib}

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

“Hattimare, Amit、Arkin Dharawat、Yelman Khan、Yen-Chieh Lien、Chris Samarinas、George Z. Wei、Yulin Yang 和 Hamed Zamani。“Maruna Bot:面向任务的对话的可扩展检索框架”。在:Alexa Prize TaskBot 挑战赛论文集。2022 年。”“George Z. Wei”以粗体突出显示。


请注意,此处提供的解决方案以及 Marijn 的答案中的解决方案不使用author+an = {6=highlight;},原始 MWE 中的名称注释。

如果您已经为所有相关字段添加了名称注释,则可以按如下方式使用它们,而无需进行任何进一步的名称或哈希比较。

\documentclass{article}

\usepackage[
  backend=biber,
  style=verbose,
  sorting=ydnt,
  maxcitenames=3,
  maxbibnames=99,
  doi=false,
  isbn=true,
  url=false,
  eprint=false,
  backref = false,
  block=none,
]{biblatex}


\newcommand*{\mkboldifhighlight}[1]{%
  \ifitemannotation{highlight}
    {\mkbibbold{#1}}
    {#1}}

\DeclareNameWrapperFormat{boldifhighlight}{%
  \renewcommand*{\mkbibcompletename}{\mkboldifhighlight}%
  #1}

\DeclareNameWrapperAlias{sortname}{default}
\DeclareNameWrapperAlias{default}{boldifhighlight}


\begin{filecontents*}{\jobname.bib}
@inproceedings{hattimare2022maruna,
  title     = {Maruna Bot: An Extensible Retrieval-Focused Framework
               for Task-Oriented Dialogues},
  author    = {Hattimare, Amit and Dharawat, Arkin and Khan, Yelman
               and Lien, Yen-Chieh and Samarinas, Chris and Wei, George Z.
               and Yang, Yulin and Zamani, Hamed},
  author+an = {6=highlight;},
  year      = 2022,
  booktitle = {Alexa Prize TaskBot Challenge Proceedings},
  url       = {https://www.amazon.science/alexa-prize/proceedings/maruna-bot-an-extensible-retrieval-focused-framework-for-task-oriented-dialogues}
}
\end{filecontents*}
\addbibresource{\jobname.bib}

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

相关内容