如何使用 biblatex 特别强调作者(而不是将其加粗)

如何使用 biblatex 特别强调作者(而不是将其加粗)

有没有办法给特定的作者加下划线(而不是像这里提供的代码片段那样将其加粗):

\newcommand*{\mkboldifhashinlist}[1]{%
  \xifinlist{\thefield{hash}}{\nhblx@boldhashes}
    {\mkbibbold{#1}}
    {#1}}
\makeatother

受到以下答案的启发:

编辑1

因此,我尝试在代码中实现答案,但出现错误

%https://tex.stackexchange.com/questions/73136/make-specific-author-bold-using-biblatex/416416#416416
%https://tex.stackexchange.com/questions/602723/making-specific-author-bold-using-biblatex/602735?noredirect=1#comment1511845_602735
\documentclass[british]{article}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{enumitem}
\usepackage{color}
\usepackage{soul}
\usepackage{import}
\usepackage{soul}

\setlist[enumerate]{itemsep=0mm}
\usepackage{geometry}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 right=20mm,
 top=20mm,
 }

\usepackage[backend=biber,style=authoryear,maxcitenames=2,maxbibnames=50,firstinits=true,uniquelist=false,uniquename=init,isbn=false,doi=false,useprefix=true]{biblatex}

%\usepackage{biblatex}

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

\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}}
    {\ul{#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}

\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist 
\newtoggle{myrefs}
\newcommand{\myref}[1]{\iftoggle{myrefs}{\underline{#1}}{#1}}

\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},
}

@MISC{test3,
  AUTHOR    = {Last4, First4 and Last3, First3 and Last1, First1 and Last2, First2},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\DeclareLabeldate[online]{%
  \field{date}
  \field{year}
  \field{eventdate}
  \field{origdate}
  \field{urldate}
}
\usepackage[dvipsnames]{xcolor}
\definecolor{myblue}{RGB}{0, 32, 255}
\usepackage[colorlinks]{hyperref}
\hypersetup{
    colorlinks,
    filecolor=magenta,
    linkcolor=blue,
    urlcolor=myblue,
    final
}
\usepackage{titlesec}

\titleformat{\section}
{\normalfont\large\bfseries}{\thesection}{0.8em}{}[{\titlerule[0.8pt]}]
\titleformat{\subsection}
  {\normalfont\normalsize\bfseries}{\thesubsection}{0.8em}{}
\titleformat{\subsubsection}
  {\normalfont\normalsize\bfseries}{\thesubsubsection}{0.8em}{}
\begin{document}

\title{ \vspace{-2.5cm} \textbf{Publications - Eric Buffle, MD-PhD}\vspace{-0.6cm}}
%\date{\today}
\date{\vspace{-5ex}}
\maketitle
\nocite{*}

\addboldnames{{Last2, First2}}

\begin{enumerate}
  \item \fullcite{test1}
   \item \fullcite{test2}
  \item \fullcite{test3}
\end{enumerate}

\end{document}

我收到以下错误

LaTeX Warning: No \author given.

! Argument of \etb@ifdefmacro has an extra }.
<inserted text>
                \par
l.149   \item \fullcite{test1}

?

答案1

引用代码中使名称加粗的部分是\mkbibbold{#1},您可以将其替换为带下划线的代码#1

请注意,大多数 TeX 下划线实现在处理复杂参数时都会出现问题,并且通常不允许在复杂参数中使用换行符(如果它们可以工作的话)。如果您能让它们工作并且不介意下划线名称不会换行,您可以尝试使用标准的\underline{#1}, soul's \ul{#1}, ulem's \uline{#1}(加载ulem时选择normalem避免\emph-italics 变成下划线)。

据我所知,唯一允许换行且通常接受所有类型输入的“安全”下划线实现是lua-ul's \underLine{#1}。但这需要 LuaLaTeX。

相关内容