我正在尝试实现以下示例这张答案海报由 Audrey 提供如下:
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{xpatch}% or use http://tex.stackexchange.com/a/40705
\usepackage[style=authoryear, sorting=ynt, backend=biber, maxbibnames=99]{biblatex}
\begin{filecontents}{\jobname.bib}
@MISC{test1,
AUTHOR = {Last1, First1 and Last2, First2 and Last3, First3},
}
@MISC{test2,
AUTHOR = {Last2, First2 and Last3, First3 and Last1, First1},
}
\end{filecontents}
\addbibresource{\jobname.bib}
%\addbibresource{publications.bib}
\setlength\bibitemsep{1.5\itemsep}
\newbibmacro*{name:bold}[2]{%
\edef\blx@tmp@name{\expandonce#1, \expandonce#2}%
\def\do##1{\ifdefstring{\blx@tmp@name}{##1}{\bfseries\listbreak}{}}%
\dolistloop{\boldnames}}
\newcommand*{\boldnames}{}
\makeatother
\xpretobibmacro{name:family}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:given-family}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:family-given}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:delim}{\begingroup\normalfont}{}{}
\xapptobibmacro{name:family}{\endgroup}{}{}
\xapptobibmacro{name:given-family}{\endgroup}{}{}
\xapptobibmacro{name:family-given}{\endgroup}{}{}
\xapptobibmacro{name:delim}{\endgroup}{}{}
% just for demonstration
\ExecuteBibliographyOptions{maxnames=99,giveninits}
\DeclareNameAlias{default}{family-given/given-family}
\begin{document}
\nocite{*}
\renewcommand*{\boldnames}{}
\forcsvlist{\listadd\boldnames}
{{Last2, First2} }
\printbibliography[heading=none]
\end{document}
但是作者的名字并没有以粗体显示于 pdf 输出中。
我究竟做错了什么?
编辑
我尝试了@moewe 给出的答案,但收到以下错误消息
LaTeX Warning: File `try9.bib' already exists on the system.
Not generating it from this source.
(/usr/local/texlive/2019/texmf-dist/tex/latex/biblatex/lbx/british.lbx
(/usr/local/texlive/2019/texmf-dist/tex/latex/biblatex/lbx/english.lbx))
Package biblatex Warning: Conflicting options.
(biblatex) '<namepart>inits' conflicts with 'uniquename=full'.
(biblatex) Setting 'uniquename=init' on input line 81.
(./try9.aux)
No file try9.bbl.
LaTeX Warning: Citation 'nhblx@name@1' on page 1 undefined on input line 84.
LaTeX Warning: Empty bibliography on input line 85.
(./try9.aux)
LaTeX Warning: There were undefined references.
Package biblatex Warning: Please (re)run Biber on the file:
(biblatex) try9
(biblatex) and rerun LaTeX afterwards.
)
No pages of output.
Transcript written on try9.log.
编辑2
我将该行编辑如下:
\usepackage[style=authoryear, sorting=ynt, backend=biber, maxbibnames=99, uniquename=init]{biblatex}
运行biber try9
然后pdflatex try9
(try9.tex
文件的名称在哪里)但收到以下错误消息
LaTeX Warning: File `try9.bib' already exists on the system.
Not generating it from this source.
(/usr/local/texlive/2019/texmf-dist/tex/latex/biblatex/lbx/british.lbx
(/usr/local/texlive/2019/texmf-dist/tex/latex/biblatex/lbx/english.lbx))
(./try9.aux) (./try9.bbl)
! LaTeX Error: Command \mkbibcompletename undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.84 \addboldnames{{Last2, First2}}
?
! LaTeX Error: Command \mkbibcompletename undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.85 \printbibliography[heading=none]
?
! LaTeX Error: Command \mkbibcompletename undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.85 \printbibliography[heading=none]
?
[1{/usr/local/texlive/2019/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./try9.aux) ){/usr/local/texlive/2019/texmf-dist/fonts/enc/dvips/cm-super/cm-s
uper-t1.enc}</usr/local/texlive/2019/texmf-dist/fonts/type1/public/cm-super/sfr
m1000.pfb>
Output written on try9.pdf (1 page, 12913 bytes).
Transcript written on try9.log.
答案1
这里有两个问题。
\makeatletter
定义之前缺少代码name:bold
。应该是\makeatletter \newbibmacro*{name:bold}[2]{% \edef\blx@tmp@name{\expandonce#1, \expandonce#2}% \def\do##1{\ifdefstring{\blx@tmp@name}{##1}{\bfseries\listbreak}{}}% \dolistloop{\boldnames}} \newcommand*{\boldnames}{} \makeatother
这种比较名称的方法是基于字符串的。这意味着您必须以与输出相同的格式提供要突出显示的名称。由于代码强制使用 来显示名字首字母
giveninits
,因此您还需要使用首字母形式。请注意.
被 替换为\bibinitperiod
。填写 时需要考虑到这一点\boldnames
。\forcsvlist{\listadd\boldnames}{{Last2, F\bibinitperiod}}
毫不奇怪,我会借此机会推销我的答案到使用 biblatex 将特定作者设为粗体。该答案使用基于哈希的方法来比较名称,这通常比基于字符串的方法更可靠、更稳定。代码有点长,因为我们需要一种方法让 Biber 为我们生成哈希值。
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear, sorting=ynt, backend=biber, maxbibnames=99]{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}
% just for demonstration
\ExecuteBibliographyOptions{maxnames=99,giveninits}
\DeclareNameAlias{default}{family-given/given-family}
\setlength\bibitemsep{1.5\itemsep}
\begin{filecontents}{\jobname.bib}
@MISC{test1,
AUTHOR = {Last1, First1 and Last2, First2 and Last3, First3},
}
@MISC{test2,
AUTHOR = {Last2, First2 and Last3, First3 and Last1, First1},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\addboldnames{{Last2, First2}}
\printbibliography[heading=none]
\end{document}