比较包含受保护宏的宏定义的正确方法,例如 bibnamedelima

比较包含受保护宏的宏定义的正确方法,例如 bibnamedelima

\partnamefamily我正在尝试将作者姓名的内容与biblatex存储在另一个宏中的手动定义进行比较,我们称之为\family,使用\ifdefequal

所以我有

  • Lastname比较时没有发现问题
  • Compound~Lastname会产生问题,因为~被转换为\bibnamedelima存储在内部的宏。因此名称Compound\bibnamedelima Lastname改为。在进行定义比较时,这是不一样的。

\bibnamedelima我认为发生的问题与名称包含不间断空格 ( ) 时出现的受保护宏有关~。如果名称没有由比较处理的特殊分隔符,则biblatex比较可以正常工作。但是,当发生这种情况时,我无法比较它。我的解决方案是

  • 尝试将其展开,然后将展开的字符串或宏与\partnamefamily它进行比较。但是没有成功。我猜是因为受保护的宏\bibnamedelima
  • 尝试通过替换来比较宏,但这也不起作用。

我寻找一种使用受保护的宏来扩展宏的方法(例如取消保护(扩展) \protected 宏(或“命令名称后的空格”)宏调用之前扩展参数),但没有帮助。此外,尝试将其转换为字符串,但没有成功。

有没有办法直接比较这两个宏?

这是一个显示我的问题的例子

% !BIB program = biber
\documentclass{article}
\usepackage[backend=biber, giveninits=true]{biblatex}
\begin{filecontents}{\jobname.bib}
@InProceedings{identifier1,
  Title                    = {Some Awesome Title},
  Author                   = {One~Two, Author and Three, Author},
  Booktitle                = {Some Book about the Future},
  Year                     = {2042},
  Pages                    = {1--42}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\newcommand*{\name}[1]{%
  \def\lastname{#1}}
\name{}
\renewcommand{\mkbibnamefamily}[1]{%
  % I have a complex expression here, so I was using the \ifboolexpr
  \ifboolexpr{ test {\ifdefequal{\lastname}{\namepartfamily}} }
  {(F)\mkbibbold{#1}}{(NF)#1}%
}
\begin{document}
\nocite{*}
\name{One~Two}% not found due to ~, as biblatex convert ~ to \bibnamedelima
\printbibliography
\name{One\bibnamedelima Two}% found due to \bibnamedelima instead of ~
\printbibliography
% found as it is not using any delim
\name{Three}
\printbibliography
\end{document}

答案1

您可以暂时重新定义\bibnamedelima~回到一个简单的空间。

\makeatletter
\renewcommand{\mkbibnamefamily}[1]{%
  \begingroup
    \def\bibnamedelima{ }%
    \def~{ }%
    \edef\adn@tmp@lastname{\lastname}%
    \edef\adn@tmp@namepartfamily{\namepartfamily}%
    % I have a complex expression here, so I was using the \ifboolexpr
    \ifboolexpr{ test {\ifcsequal{adn@tmp@lastname}{adn@tmp@namepartfamily}} }
      {(F)\mkbibbold{#1}}
      {(NF)#1}%
  \endgroup
}
\makeatother

特别是你现在可以使用更容易消化的

\name{One Two}

这类似于奥黛丽的回答使用 biblatex 将特定作者设为粗体,那里的答案考虑了更多的biblatex分隔符,但总体思路是一样的。

平均能量损失

\documentclass{article}
\usepackage[backend=biber, giveninits=true]{biblatex}
\begin{filecontents}{\jobname.bib}
@InProceedings{identifier1,
  Title                    = {Some Awesome Title},
  Author                   = {One~Two, Author and Three, Author},
  Booktitle                = {Some Book about the Future},
  Year                     = {2042},
  Pages                    = {1--42}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\newcommand*{\name}[1]{%
  \def\lastname{#1}}
\name{}

\makeatletter
\renewcommand{\mkbibnamefamily}[1]{%
  \begingroup
    \def\bibnamedelima{ }%
    \def~{ }%
    \edef\adn@tmp@lastname{\lastname}%
    \edef\adn@tmp@namepartfamily{\namepartfamily}%
    % I have a complex expression here, so I was using the \ifboolexpr
    \ifboolexpr{ test {\ifcsequal{adn@tmp@lastname}{adn@tmp@namepartfamily}} }
      {(F)\mkbibbold{#1}}
      {(NF)#1}%
  \endgroup
}
\makeatother

\begin{document}
\nocite{*}

\name{One~Two}
\printbibliography

\name{One\bibnamedelima Two}
\printbibliography

\name{One Two}
\printbibliography

\name{Three}
\printbibliography
\end{document}

在此处输入图片描述

相关内容