突出显示 .bib 文件中的特定引用

突出显示 .bib 文件中的特定引用

我有以下示例 .tex 文件

\documentclass{article}
\usepackage{soul}

\begin{document}
    
This is the file \cite{kang2020energy,pilakkat2019improved,ram2020performance}

\bibliographystyle{IEEEtran}
\bibliography{abc}  
    
    \end{document}

.bib 文件如下

@article{kang2020energy,
    title={{Energy systems for climate change mitigation: A systematic review}},
    author={{Kang, Jia-Ning and Wei, Yi-Ming and Liu, Lan-Cui and Han, Rong and Yu, Bi-Ying and Wang, Jin-Wei}},
    journal={{Applied Energy}},
    volume={{263}},
    pages={{114602}},
    year={{2020}},
    publisher={{Elsevier}}
}
@article{pilakkat2019improved,
    title={An improved {P}\&{O} algorithm integrated with artificial bee colony for photovoltaic systems under partial shading conditions},
    author={Pilakkat, Deepthi and Kanthalakshmi, S},
    journal={Solar Energy},
    volume={178},
    pages={37--47},
    year={2019},
    publisher={Elsevier}
}
@article{ram2020performance,
    title={Performance enhancement of solar {P}{V} systems applying {P}\&{O} assisted Flower Pollination Algorithm ({F}{P}{A})},
    author={Ram, J Prasanth and Pillai, Dhanup S and Ghias, Amer MYM and Rajasekar, N},
    journal={Solar Energy},
    volume={199},
    pages={214--229},
    year={2020},
    publisher={Elsevier}
}

我想突出显示参考文献列表中的第二个参考文献。由于期刊要求,我不想更改参考文献的颜色,而是特别想突出显示完整的参考文献。我该怎么做?

答案1

我将首先描述哪些命令必须添加到序言中(两种变体,w/wo natbib),然后描述如何使用它们。

如果你或文档类(如 elsarticle)加载natbib将下列几行添加到序言中。

\newcommand\highlightReference[1]{%
  \expandafter\newcommand\csname highlightReference-#1\endcsname{}%
}
\usepackage{xpatch}
\makeatletter
\xapptocmd\@lbibitem{\hlbibitem{#2}}{}{}
\makeatother
\def\hlbibitem#1 #2\par{%
  \expandafter\ifx\csname highlightReference-#1\endcsname\relax
    #2\par
  \else
    \highlight{#2}\par
  \fi
}

否则,使用 LaTeX 的原生书目处理, 在序言中添加以下几行:

\newcommand\highlightReference[1]{%
  \expandafter\newcommand\csname highlightReference-#1\endcsname{}%
}
\let\oldbibitem\bibitem
\def\bibitem#1 #2\par{%
  \expandafter\ifx\csname highlightReference-#1\endcsname\relax
    \oldbibitem{#1}#2\par
  \else
    \oldbibitem{#1}\highlight{#2}\par
  \fi
}

然后定义命令 \highlight{...}您希望突出显示参考文献的方式。要为其加下划线,请使用

\usepackage{soul}
\newcommand\highlight[1]{\ul{#}}

如果要使用黄色背景突出显示,请使用

\usepackage{color,soul}
\newcommand\highlight[1]{\hl{#1}}

如果要通过用红色字体突出显示单词,请使用

\usepackage{color}
\newcommand\highlight[1]{\textcolor{red}{#1}}

最后一种解决方案是最稳定的,因为soul如果突出显示的文本包含某些命令(错误“重建失败”),包可能会遇到麻烦。

最后,指出哪些 bib 条目应该突出显示\highlightReference{KEY}通过为每个引用添加命令,并KEY在命令中使用标签\cite


例如:文档类article、参考书目样式IEEEtran、黄色背景

在此处输入图片描述

\documentclass{article}
\newcommand\highlightReference[1]{%
  \expandafter\newcommand\csname highlightReference-#1\endcsname{}%
}
\let\oldbibitem\bibitem
\def\bibitem#1 #2\par{%
  \expandafter\ifx\csname highlightReference-#1\endcsname\relax
    \oldbibitem{#1}#2\par
  \else
    \oldbibitem{#1}\highlight{#2}\par
  \fi
}
\usepackage{color,soul}
\newcommand\highlight[1]{\hl{#1}}
\begin{document}

This is the file \cite{kang2020energy,pilakkat2019improved,ram2020performance}

\highlightReference{pilakkat2019improved}
\bibliographystyle{IEEEtran}
\bibliography{abc}  

\end{document}

elsarticle示例:带有选项的文档类authoryear,参考书目样式abbrvnat,下划线

在此处输入图片描述

\documentclass[authoryear]{elsarticle}
\newcommand\highlightReference[1]{%
  \expandafter\newcommand\csname highlightReference-#1\endcsname{}%
}
\usepackage{xpatch}
\makeatletter
\xapptocmd\@lbibitem{\hlbibitem{#2}}{}{}
\makeatother
\def\hlbibitem#1 #2\par{%
  \expandafter\ifx\csname highlightReference-#1\endcsname\relax
    #2\par
  \else
    \highlight{#2}\par
  \fi
}
\usepackage{soul}
\newcommand\highlight[1]{\ul{#1}}
\begin{document}

This is the file \cite{kang2020energy,pilakkat2019improved,ram2020performance}

\highlightReference{pilakkat2019improved}
\bibliographystyle{abbrvnat}
\bibliography{abc}  

\end{document}

article示例:带有包natbib和选项的文档类authoryear、参考书目样式plainnat、红色文本

在此处输入图片描述

\documentclass{article}
\usepackage[authoryear]{natbib}
\newcommand\highlightReference[1]{%
  \expandafter\newcommand\csname highlightReference-#1\endcsname{}%
}
\usepackage{xpatch}
\makeatletter
\xapptocmd\@lbibitem{\hlbibitem{#2}}{}{}
\makeatother
\def\hlbibitem#1 #2\par{%
  \expandafter\ifx\csname highlightReference-#1\endcsname\relax
    #2\par
  \else
    \highlight{#2}\par
  \fi
}
\usepackage{color}
\newcommand\highlight[1]{\textcolor{red}{#1}}
\begin{document}

This is the file \cite{kang2020energy,pilakkat2019improved,ram2020performance}

\highlightReference{pilakkat2019improved}
\bibliographystyle{plainnat}
\bibliography{abc}  

\end{document}

相关内容