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}

アインシュタインは太字、エルクは赤字

関連情報