4

I have the following sample .tex file

\documentclass{article}
\usepackage{soul}

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

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

The .bib file goes like this

@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}
}

I want to highlight second reference in the reference list. Due to journal requirements, I dont want to change the color of references, rather I specifically want to highlight the complete reference. How can I do that?

3
  • No, that uses biblatex, whereas I am using bibtex. Also, that particular link relates to sorting
    – ShJ
    Commented Jul 27, 2021 at 15:04
  • I want to use something which performs same function as \hl{} for a particular reference which is written via bibtex
    – ShJ
    Commented Jul 27, 2021 at 17:47
  • No please, this link does not give the solution to that. It just says to change the color of reference to any other color
    – ShJ
    Commented Jul 28, 2021 at 2:19

1 Answer 1

9
+50

I'll first describe which commands have to be added to the preamble (two variants, w/wo natbib), and then how to use them.

If you or the document class (like elsarticle) loads natbib, add the following lines to the preamble.

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

Otherwise, with the native bibliography handling of LaTeX, add the following lines to the preamble:

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

Then define the command \highlight{...} the way you want to have your references highlighted. To underline them, use

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

If you want to highlight by a yellow background, use

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

If you want to highlight by typesetting the words in red, use

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

The last solution is the most stable one, since the soul package may get into troubles if the highlighted text contains certain commands (error 'reconstruction failed').

Finally, indicate which bib entries should be highlighted by adding commands \highlightReference{KEY} for every reference, with KEY being the label you also use in the \cite command.


Example: document class article, bibliography style IEEEtran, yellow background

enter image description here

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

Example: document class elsarticle with option authoryear, bibliography style abbrvnat, underlined

enter image description here

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

Example: document class article with package natbib and option authoryear, bibliography style plainnat, red text

enter image description here

\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}
11
  • I dont want to underline, I want to highlight during revision of paper
    – ShJ
    Commented Aug 11, 2021 at 15:06
  • 1
    @ShJ I have modified the code to make the highlighting explicit, with examples showing underlining as well as coloring the background in yellow.
    – gernot
    Commented Aug 11, 2021 at 18:11
  • 1
    @ShJ If you put something into an \mbox command, it will not break across lines, so it is not a surprise that such lines will stick out to the other column (and beyond). I'm afraid there is no general solution, as long as you want to use background coloring. I have added a third option to my answer, coloring the text in red. This should work more reliably than the soul package. Otherwise, if you absolutely need background coloring and the soul package, you have to find out which command in your bibliography leads to the failed reconstruction, and try to do without it.
    – gernot
    Commented Aug 20, 2021 at 14:10
  • 1
    @gernot, strangely this does not seem to work under elsarticle, that's a shame becuase it's a very good idea. Any way to overcome this issue? thanks
    – umby
    Commented Jun 26, 2023 at 14:35
  • 1
    @umby Sorry, I missed your comment. Probably too late for you: I've added a solution for documents using natbib, like elsarticle.
    – gernot
    Commented Mar 7 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .