
我使用註釋功能在 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}