使用宏在 bibentry 中查找和替换文本

使用宏在 bibentry 中查找和替换文本

我希望能够显示参考书目条目,但我想突出显示其中的某些部分,特别是某些作者,但不是全部。到目前为止,我能够在文本中间创建 bib 条目,并且我还可以查找和替换文本(从这里)。但是,当我尝试查找并替换 bib 条目的文本时,它不起作用。

这是我的示例 bib tex 文件:

\begin{filecontents}{mybib.bib}
{

@InProceedings{pcl,
  author    = {Radu Bogdan Rusu and Steve Cousins},
  title     = {{3D is here: Point Cloud Library (PCL)}},
  booktitle = {{IEEE International Conference on Robotics and Automation (ICRA)}},
  month     = {May 9-13},
  year      = {2011},
  address   = {Shanghai, China}
  }
@misc{opencv,
  title={Open Source Computer Vision Library},
  author={Itseez},
  year={2015},
  howpublished = {\url{https://github.com/itseez/opencv}}
  }
@manual{opencv_manual,
  title = {The OpenCV Reference Manual},
  organization = {Itseez},
  edition = {2.4.9.0},
  month = {April},
  year = {2014},
  notes = {See \url{http://opencv.org/}}
  }
}

\end{filecontents}   

\documentclass{article}
\usepackage{natbib}
\usepackage{bibentry}
\usepackage{hyperref}
\usepackage{etoolbox}
\nobibliography*

% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\newcommand{\searchreplace}[3]{\patchcmd{#1}{#2}{#3}{}{}}
\newcommand{\bibelement}[1]
{
    \begin{NoHyper}% In my real project I need the bibentry package to work with hyperref package.
        \bibentry{#1}
    \end{NoHyper}
} 
\newcommand{\bibelementhighlight}[2]
{
    %\searchreplace{\bibelement{#1}}{#2}{\textbf{#2}}
    \newcommand{\auxbibliography}{\bibelement{#1}}
    First time: \auxbibliography \\
    \searchreplace{\auxbibliography}{#2}{\textbf{#2}}
    Second time: \auxbibliography
}

\begin{document}

\newcommand{\afgfgft}{Rusu, R. B. and Cousins, S.}
\afgfgft \\
\searchreplace{\afgfgft}{Rusu, R. B.}{\textbf{Rusu, R. B.}}
\afgfgft

Here are some citations for articles: \cite{pcl} and \cite{opencv} and \bibelement{opencv_manual} and the one which I want to highlight:
\begin{itemize}
    \item \bibelementhighlight{pcl}{Rusu}
\end{itemize}


\bibliographystyle{apalike}
\bibliography{mybib.bib}

\end{document}

当我编译此代码时,我得到以下内容(请注意,还添加了绘图和文本来解释我想要得到的内容): 在此处输入图片描述

Rusu除了第二次显示 bibelement的替换之外,其他一切都正常。经过一番折腾,我认为这可能是因为\bibitem在字符串替换后被扩展了。有人能给我提示如何解决这个问题吗?

相关内容