Biblatex 多作者注释

Biblatex 多作者注释

我使用注释功能在 biblatex 中突出显示某些作者:

\documentclass{article}
\usepackage{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@MISC{test,
  AUTHOR    = {Last1, First1 and Last2, First2 and Last3, First3},
  AUTHOR+an = {2=highlight},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\renewcommand*{\mkbibnamegiven}[1]{%
  \ifitemannotation{highlight}
    {\textbf{#1}}
    {#1}}

\renewcommand*{\mkbibnamefamily}[1]{%
  \ifitemannotation{highlight}
    {\textbf{#1}}
    {#1}}

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

\end{document}

我想添加另一个注释,例如highlightB以粗体和红色突出显示,可以用作现有注释的替代highlight

\ifitemannotation{highlightB}我尝试了两种方法中的附加方法\mkbibnamegiven\mkbibnamefamily但无法使其正常工作。我该怎么做?

答案1

您必须嵌套注释测试。请注意,我习惯\mkbibcompletename一次性格式化完整名称,而不是为所有名称部分重新定义宏。

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{xcolor}

\usepackage[style=authoryear, backend=biber]{biblatex}

\renewcommand*{\mkbibcompletename}[1]{%
  \ifitemannotation{highlight}
    {\textbf{#1}}
    {\ifitemannotation{highlightB}
       {\textcolor{red}{#1}}
       {#1}}}

\begin{filecontents}{\jobname.bib}
@misc{example1,
  title     = {Mock Title},
  author    = {Albert Einstein},
  author+an = {1=highlight},
  year      = {2019},
}
@misc{example2,
  title     = {Mock Turtle},
  author    = {Anne Elk},
  author+an = {1=highlightB},
  year      = {2020},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}


\begin{document}
\cite{sigfridsson,example1,example2}
\printbibliography
\end{document}

爱因斯坦用粗体表示,麋鹿用红色表示

相关内容