灵感来自这个问题关于如何使用 biblatex 将简历中的一组姓名加粗。
moewe 的回答为此实现了名称哈希。我想知道如何推广此解决方案,以便您可以拥有任意数量的名称集,并使用它们执行任意操作。
实际用例可能是在简历中,你想要:
- 全文加粗你自己的名字,并且
- 用星号标记研究生姓名,如“家庭,给定*”或“给定家庭*”,以及
- 在本科生姓名后面加上加号标记,例如“Family,Given+”或“Given Family+”。
因此,从用户的角度来看,文档可能看起来像这样:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[backend=biber,style=numeric]{biblatex}
\addbibresource{biblatex-examples.bib}
\addboldnames{{Sigfridsson, Emma},{Vizedom, Monika B.}}
%%% New command?
\addstarnames{Donald E. Knuth,Philipp Jaff{\'e}} % <-- we could just build the * into the command
\appendtonamelist{*}{Donald E. Knuth,Philipp Jaff{\'e}} % <-- or maybe there's a general hook to append something to a name?
\begin{document}
\fullcite{sigfridsson}
\fullcite{knuth:ct:a}
\fullcite{vizedom:related}
\resetboldnames\addboldnames{Donald E. Knuth}
\fullcite{knuth:ct:a}
\resetboldnames\addboldnames{Philipp Jaff{\'e}}
\fullcite{jaffe}
\end{document}
我正在寻找如何定义类似\addstarnames
或\appendtonamelist
上述的内容。
答案1
通过一些改变使事情变得更加灵活,您可以生成任意名称哈希列表以供检查。
基本上唯一的变化是https://tex.stackexchange.com/a/416416/35864是引入一个参数来允许为不同事物提供单独的名称列表。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[backend=biber,style=numeric]{biblatex}
\addbibresource{biblatex-examples.bib}
\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@writenametobibfor}[2]{%
\stepcounter{nhblx@name}%
\edef\nhblx@tmp@nocite{%
\noexpand\AfterPreamble{%
\noexpand\setbox0\noexpand\vbox{%
\noexpand\def\noexpand\nhblx@nametype{#1}%
\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{#2}}, %
options = {dataonly=true},}%
}%
}
\AtEndDocument{%
\closeout\nhblx@bibfile}
\addbibresource{\nhblx@bibfile@name}
\newcommand*{\nhblx@boldhashes}{}
\DeclareNameFormat{nhblx@hashextract}{%
\xifinlistcs{\thefield{hash}}{nhblx@namelist@\nhblx@nametype}
{}
{\listcsxadd{nhblx@namelist@\nhblx@nametype}{\thefield{hash}}}}
\DeclareCiteCommand{\nhblx@getmethehash}
{}
{\printnames[nhblx@hashextract][1-999]{author}}
{}
{}
% add names to a certain highlight list
% [<list name>]{<name_1>,...,<name_n>}
\newcommand*{\addhlnames}[1][bold]{%
\forcsvlist{\nhblx@writenametobibfor{#1}}}
% clear name list
% [<list name>]
\newcommand*{\resethlnames}[1][bold]{%
\csdef{nhblx@namelist@#1}{}}
% check if current name (as identified by hash field) is in name list
% [<list name>]{<true>}{<false>}
\newcommand*{\ishlname}[1][bold]{%
\xifinlistcs{\thefield{hash}}{nhblx@namelist@#1}}
\makeatother
\newcommand*{\mkhlname}[1]{%
\ishlname[bold]
{\mkbibbold{#1}}
{#1}%
\ishlname[star]
{*}
{}%
\ishlname[plus]
{\textsuperscript{+}}
{}}
\DeclareNameWrapperFormat{highlightname}{%
\renewcommand*{\mkbibcompletename}{\mkhlname}%
#1}
\DeclareNameWrapperAlias{sortname}{default}
\DeclareNameWrapperAlias{default}{highlightname}
\addhlnames[bold]{{Sigfridsson, Emma},{Vizedom, Monika B.}}
\addhlnames[star]{Donald E. Knuth}
\addhlnames[plus]{Ulf Ryde}
\begin{document}
\fullcite{sigfridsson}
\fullcite{knuth:ct:a}
\fullcite{vizedom:related}
\fullcite{knuth:ct:a}
\fullcite{jaffe}
\end{document}