將參考書目 biblatex 中包含空格的名稱加粗

將參考書目 biblatex 中包含空格的名稱加粗

我正在實施提出的第一個解決方案這裡在 biblatex 參考書目中對名稱進行粗體選擇。

我遇到的問題是名稱中包含空格“”。那麼該解決方案不適用。例子Le Texier

@article{schindlerHowFarPeople2022,
  title = {How Far Do People Travel to Use Urban Green Space? {{A}} Comparison of Three {{European}} Cities},
  author = {Schindler, Mirjam and Le Texier, Marion and Caruso, Geoffrey},
  date = {2022-04-01},
  journaltitle = {Applied Geography},
  volume = {141},
  pages = {102673},
  doi = {10.1016/j.apgeog.2022.102673},
}

我根據建議的解決方案中給出的示例形成了過濾器:

    \forcsvlist{\listadd\boldnames} %this is the model of filter
      {{Herrmann, Wolfgang~A.}, {Herrmann, W.~A.}, {Herrmann, Wolfgang\bibnamedelima A.},
      {Herrmann, W\bibinitperiod\bibinitdelim A\bibinitperiod}}
   \forcsvlist{\listadd\boldnames} %this is my implementation of the filter
      {{Le Texier, Marion}, {Le~Texier, Marion}, {Le Texier, M.}, {Texier, M\bibinitperiod}}

過濾器適用於所有作者姓名,但不適用於包含空格的特定名稱。

答案1

在基於字串的方法中,帶有空格的名稱可能會很棘手。如果你檢查該.bbl文件,你會看到 Biber 生成

    {{hash=31cbf23407084cad2911631ec94eba70}{%
       family={Le\bibnamedelima Texier},
       familyi={L\bibinitperiod\bibinitdelim T\bibinitperiod},
       given={Marion},
       giveni={M\bibinitperiod}}}%

這就是所有biblatex看到的,所以你必須使用Le\bibnamedelima Texier而不是Le Texier

\forcsvlist{\listadd\boldnames}
  {{Le\bibnamedelima Texier, Marion}, {Le\bibnamedelima Texier, M\bibinitperiod}}

其作用原理如以下 MWE 所示

\documentclass{article}
\usepackage{biblatex}
\usepackage{xpatch}

\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

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


\forcsvlist{\listadd\boldnames}
  {{Le\bibnamedelima Texier, Marion}, {Le\bibnamedelima Texier, M\bibinitperiod}}

\begin{filecontents}{\jobname.bib}
@article{schindlerHowFarPeople2022,
  title        = {How Far Do People Travel to Use Urban Green Space?
                  A Comparison of Three {European} Cities},
  author       = {Schindler, Mirjam and Le Texier, Marion
                  and Caruso, Geoffrey},
  date         = {2022-04-01},
  journaltitle = {Applied Geography},
  volume       = {141},
  pages        = {102673},
  doi          = {10.1016/j.apgeog.2022.102673},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

% just for demonstration
\ExecuteBibliographyOptions{maxnames=99,giveninits}
\DeclareNameAlias{default}{family-given/given-family}

\begin{document}
\nocite{schindlerHowFarPeople2022}
\printbibliography
\end{document}

辛德勒,M.,M.勒特克西爾,G.卡魯索。 「人們要走多遠才能使用城市綠地?三個歐洲城市的比較」。請參閱:應用地理學 141(2022 年 4 月 1 日),第 14 頁。 102673.doi:10.1016/j.apgeog.2022.102673。


像這樣的問題就是為什麼我熱烈推薦基於哈希的方法,如我的答案使用 biblatex 將特定作者加粗

這將如下所示,您可以在其中傳遞名稱,\addboldnames就像將其寫入.bib檔案中一樣。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[backend=biber,style=numeric]{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*{\ifhashinboldlist}{%
  \xifinlist{\thefield{hash}}{\nhblx@boldhashes}}
\makeatother

\newcommand*{\mkboldifhashinlist}[1]{%
  \ifhashinboldlist
    {\mkbibbold{#1}}
    {#1}}

\DeclareNameWrapperFormat{boldifhashinlist}{%
  \renewcommand*{\mkbibcompletename}{\mkboldifhashinlist}%
  #1}

\DeclareNameWrapperAlias{sortname}{default}
\DeclareNameWrapperAlias{default}{boldifhashinlist}

\addboldnames{{Le Texier, Marion}}

\begin{filecontents}{\jobname.bib}
@article{schindlerHowFarPeople2022,
  title        = {How Far Do People Travel to Use Urban Green Space?
                  A Comparison of Three {European} Cities},
  author       = {Schindler, Mirjam and Le Texier, Marion
                  and Caruso, Geoffrey},
  date         = {2022-04-01},
  journaltitle = {Applied Geography},
  volume       = {141},
  pages        = {102673},
  doi          = {10.1016/j.apgeog.2022.102673},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
\nocite{schindlerHowFarPeople2022}
\printbibliography
\end{document}

米賈姆·辛德勒、瑪麗昂·勒·特克西爾和傑弗裡·卡魯索。 「人們要走多遠才能使用城市綠地?三個歐洲城市的比較」。請參閱:應用地理學 141(2022 年 4 月 1 日),第 14 頁。 102673.doi:10.1016/j.apgeog.2022.102673。

相關內容