![如果其中包含一位特定作者,請更改參考書目中的“et al”](https://rvso.com/image/392335/%E5%A6%82%E6%9E%9C%E5%85%B6%E4%B8%AD%E5%8C%85%E5%90%AB%E4%B8%80%E4%BD%8D%E7%89%B9%E5%AE%9A%E4%BD%9C%E8%80%85%EF%BC%8C%E8%AB%8B%E6%9B%B4%E6%94%B9%E5%8F%83%E8%80%83%E6%9B%B8%E7%9B%AE%E4%B8%AD%E7%9A%84%E2%80%9Cet%20al%E2%80%9D.png)
我正在努力改變等。出現在參考書目中的情況是,在額外的(等人)作者中有一位作者,我試圖使用@LawrenceCrosby的答案在參考書目中加粗這裡
我的程式碼是:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{MyBibliography.bib}
@article{cite1,
author={Konstantinos Leledakis},
title={An Article},
year={2019},
journal={Some Journal}
}
@article{cite2,
author={Another Author and Konstantinos Leledakis},
title={A Book},
year={2017},
journal={A publisher}
}
@book{cite3,
author={Another SomeAuthor and One AnotherAuthor and SomeOther UnKnownAuthor and Konstantinos Leledakis},
title={A Book},
year={1988},
publisher={Someone}
}
@book{cite4,
author={Another Author and An UnknownAuthor and SomeOther UnKnownAuthor},
title={A Book},
year={2015},
publisher={A publisher}
}
\end{filecontents}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear-comp,maxnames=2, minnames=2]{biblatex}
\usepackage{etoolbox}
\DefineBibliographyStrings{english}{andothers={\ifthenelse{\boolean{bold}}{et~al(including Leledakis, K.)}{et~al}\adddot}}
\newboolean{bold}
\newcommand{\makeauthorbold}[1]{%
\setboolean{bold}{false}
\DeclareNameFormat{author}{%
\ifthenelse{\value{listcount}=1}
{%
{\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\setboolean{bold}{true}\mkbibbold{\namepartfamily\addcomma\addspace \namepartgiveni}}{\namepartfamily\addcomma\addspace \namepartgiveni}}
%
}{\ifnumless{\value{listcount}}{\value{liststop}}
{\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\setboolean{bold}{true}\mkbibbold{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni}}{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni}}
{\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\setboolean{bold}{true}\mkbibbold{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni\addcomma\isdot}}{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni\addcomma\isdot}}%
}
\ifthenelse{\value{listcount}<\value{liststop}}
{\addcomma\space}
}
}
%\makeauthorbold{Leledakis}
\DefineBibliographyStrings{english}{andothers={et~al}} % To translate "et al."
\ExecuteBibliographyOptions{firstinits=true, uniquename=init}
\addbibresource{MyBibliography.bib}
\renewcommand*{\nameyeardelim}{\addcomma\addspace} % Should add the comma, but somehow doesn't work
\begin{document}
\nocite{*}
\printbibliography
\end{document}
這有兩個問題:
- 如果我評論(我的意思是啟用)註解掉的命令
%\makeauthorbold{Leledakis}
並啟用它。結果來自:
(含一些 et~al)。
其中名稱已突出顯示,但 et~al。部分完全缺失。
PS:我也測試了程式碼,沒有進行任何更改,但它仍然缺少 et。等人。部分。
答案1
這\DeclareNameFormat{author}
是對原始名稱格式的修改,但仍有一些不足之處。
- 它無法處理“von”零件和“Jr.”零件。部分。
- 它無法處理“et al.”,因為它缺少對標準的呼叫
\usebibmacro{name:andothers}
。 - 在現代
biblatex
版本中,它甚至會因為語法錯誤而產生錯誤。 (最後一個\ifthenelse
缺少一個錯誤的分支。也可以看看https://github.com/plk/biblatex/issues/874.)
我建議您使用更強大的版本之一,使您的名字在建議中加粗使用 biblatex 將特定作者加粗。據我所知,沒有一個解決方案會加粗“等人”。如果它“包含”開箱即用的相關名稱,但我們可以添加它。
作為我正在使用的基礎我的答案它使用哈希值,但允許方便的介面來檢索它們。棘手的一點是檢查“et al.”是否是“et al.”。還包含要反白的名稱。我們透過循環遍歷 an 中的所有剩餘名稱來做到這一點,\indexnames
否則不列印任何內容。
\documentclass{article}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear-comp,
maxnames=2, minnames=2,
giveninits=true, uniquename=init]{biblatex}
\makeatletter
% setup for auxiliary bib file
\def\hlblx@bibfile@name{\jobname -boldnames.bib}
\newwrite\hlblx@bibfile
\immediate\openout\hlblx@bibfile=\hlblx@bibfile@name
\newcounter{hlblx@name}
\setcounter{hlblx@name}{0}
% write names to auxiliary bib file and push hash to bold list
\newcommand*{\hlblx@writenametobib}[1]{%
\stepcounter{hlblx@name}%
\edef\hlblx@tmp@nocite{%
\noexpand\AfterPreamble{%
\noexpand\setbox0\noexpand\vbox{%
\noexpand\hlblx@getmethehash{hlblx@name@\the\value{hlblx@name}}}}%
}%
\hlblx@tmp@nocite
\immediate\write\hlblx@bibfile{%
@misc{hlblx@name@\the\value{hlblx@name}, author = {\unexpanded{#1}}, %
options = {dataonly=true},}%
}%
}
\AtEndDocument{%
\closeout\hlblx@bibfile}
\addbibresource{\hlblx@bibfile@name}
% extract hashes from bib file
\newcommand*{\hlbxl@boldhashes}{}
\DeclareNameFormat{hlblx@hashextract}{%
\xifinlist{\thefield{hash}}{\hlbxl@boldhashes}
{}
{\listxadd{\hlbxl@boldhashes}{\thefield{fullhash}}}}
\DeclareCiteCommand{\hlblx@getmethehash}
{}
{\printnames[hlblx@hashextract][1-999]{author}}
{}
{}
% add and reset list of bold names
\newcommand*{\addboldnames}{\forcsvlist\hlblx@writenametobib}
\newcommand*{\resetboldnames}{\def\hlbxl@boldhashes{}}
\newcommand*{\mkboldifhashinlist}[1]{%
\xifinlist{\thefield{hash}}{\hlbxl@boldhashes}
{\mkbibbold{#1}}
{#1}}
\newtoggle{boldnameincluded}
\newbibmacro*{name:flagbold}{%
\def\do##1{\iffieldequalstr{hash}{##1}{\global\toggletrue{boldnameincluded}\listbreak}{}}%
\dolistloop{\hlbxl@boldhashes}%
}
\DeclareNameWrapperFormat{boldifhashinlist}{%
\renewcommand*{\mkbibcompletename}{\mkboldifhashinlist}%
#1}
\DeclareNameWrapperAlias{sortname}{default}
\DeclareNameWrapperAlias{default}{boldifhashinlist}
\DeclareIndexNameFormat{flagbold}{%
\usebibmacro{name:flagbold}}
\newcounter{boldflagcount}
\newcommand*{\mkbibboldandothers}[2]{%
\iftoggle{boldnameincluded}
{\mkbibbold{#2#1}}
{#2}}
\renewbibmacro*{name:andothers}{%
\ifboolexpr{
test {\ifnumequal{\value{listcount}}{\value{liststop}}}
and
test \ifmorenames
}
{\ifnumgreater{\value{liststop}}{1}
{\finalandcomma}
{}%
\global\togglefalse{boldnameincluded}%
\ifnumgreater{\value{listtotal}}{\value{listcount}}
{\defcounter{boldflagcount}{\value{listcount}+1}%
\expandafter\def\expandafter\hlblx@currname\expandafter{\currentname}%
\indexnames[flagbold][\the\value{boldflagcount}-\the\value{listtotal}]{\hlblx@currname}}%
{}%
\printdelim{andothersdelim}%
\bibstring[\mkbibboldandothers{ (incuding K.~Leledakis)}]{andothers}}
{}}
\makeatother
\addboldnames{Konstantinos Leledakis}
\begin{filecontents}{\jobname.bib}
@article{cite1,
author = {Konstantinos Leledakis},
title = {An Article},
year = {2019},
journal = {Some Journal},
}
@article{cite2,
author = {Another Author and Konstantinos Leledakis},
title = {A Book},
year = {2017},
journal = {A publisher},
}
@book{cite3,
author = {Another SomeAuthor and One AnotherAuthor
and SomeOther UnKnownAuthor and Konstantinos Leledakis},
title = {A Book},
year = {1988},
publisher = {Someone},
}
@book{cite4,
author = {Another Author and An UnknownAuthor
and SomeOther UnKnownAuthor},
title = {A Book},
year = {2015},
publisher = {A publisher},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
如果您想為您的履歷格式化出版物列表,您可能需要查看biblatex-publist
。
已編輯使用更優雅的版本來格式化完整的名稱。\DeclareNameWrapperFormat
和僅分別在 v3.12 (2018-10-30) 和 v3.13 (2019-08-17)\mkbibcompletename
中可用。biblatex
如果您使用的是舊版本,請參閱編輯歷史記錄biblatex
。