23

I am submitting a revised manuscript to a journal (Medical Physics), and the journal requires that changes that are made in the revised manuscript should be highlighted. I've been attempting to use the soul package with the \hl command, but it seems that there is a known bug where you can't highlight citations. (You get a compilation error.) I have found some workarounds, but they don't seem to work for multiple citations like this: \cite{rockafellar1997convex,rudin1992nonlinear}. Also, the workarounds seem ugly, and I don't want to submit a latex file contaminated with ugly hacks for highlighting that the editors will not understand.

How do people handle this? It must be a common issue.

Should I just highlight the pdf using Adobe Acrobat and then submit a highlighted version of the pdf along with my latex file? I'm not sure that the journal will accept that -- they may want to receive just one manuscript that has the highlighting built in, rather than a manuscript and a separate pdf with highlighting.

Here is a minimal working example:

\documentclass[aapm,graphicx,preprint,showkeys]{revtex4-1} 
\usepackage{amsmath,amssymb,enumitem,mathtools}
\usepackage{xcolor}
\usepackage{soul}

\begin{document}

\hl{This text is highlighted}.

Here's a citation \cite{rockafellar1997convex,rudin1992nonlinear}.

%\hl{ Highlighting a citation causes a compilation error \cite{rockafellar1997convex,rudin1992nonlinear}. }

\begin{thebibliography}{10}

\bibitem{rockafellar1997convex}
R.T. Rockafellar.
\newblock {\em Convex analysis}.
\newblock Number~28. Princeton university press, 1997.

\bibitem{rudin1992nonlinear}
L.~Rudin, S.~Osher, and E.~Fatemi.
\newblock Nonlinear total variation based noise removal algorithms.
\newblock {\em Physica D: Nonlinear Phenomena}, 60(1):259--268, 1992.

\end{thebibliography}

\end{document}
6
  • Pragmatic solution: Just use another, less fragile sort of highlighting, e.g., text color: \renewcommand{\hl}[1]{\color{red}#1}.
    – Daniel
    Commented Oct 26, 2016 at 9:29
  • @Daniel Thanks, very helpful. This command seems to change the color of all text in the manuscript after the command is given. Do I also need a separate command to switch back to the normal text color? Would you mind submitting an answer to show exactly how you would fix the MWE?
    – littleO
    Commented Oct 26, 2016 at 9:44
  • @Daniel There should be a pair of braces to limit the effect of \color: \renewcommand{\hl}[1]{{\color{red}#1}}.
    – gernot
    Commented Oct 26, 2016 at 9:52
  • @gernot: Upps, you're right of course. Hasty comments :-)
    – Daniel
    Commented Oct 26, 2016 at 15:24
  • @littleO: Added corrected version as an answer
    – Daniel
    Commented Oct 26, 2016 at 15:38

3 Answers 3

17

I don't know your other reasons for using the soul package, but doesn't the xcolor package suffice? Moreover, if I read the author's instructions correctly, you can also choose to use just a different text color.

Here are some possibilities for highlighting. Changing the background color usually entails some limitations, like boxes that don't wrap or restrictions on what can be put inside the highlighted area; but citations work with all approaches.

\documentclass[aapm,graphicx,preprint,showkeys]{revtex4-1} 
\usepackage{amsmath,amssymb,enumitem,mathtools}
\usepackage{xcolor}
\newcommand\hl[1]{\colorbox{yellow}{\textcolor{red}{#1}}}
\newcommand\hlbreakable[1]{\textcolor{red}{#1}}
\usepackage[most]{tcolorbox}
\newtcolorbox{highlighted}{colback=yellow,coltext=red,breakable}
\usepackage{lipsum}
\begin{document}

\hl{This text is highlighted.}

\hl{Highlighting a citation causes no compilation error \cite{rockafellar1997convex,rudin1992nonlinear}.}

\hlbreakable{Highlighting a citation causes no compilation error \cite{rockafellar1997convex,rudin1992nonlinear}.
\lipsum}

\begin{highlighted}
Highlighting a citation causes no compilation error \cite{rockafellar1997convex,rudin1992nonlinear}.
\lipsum
\end{highlighted}

\begin{thebibliography}{10}
\bibitem{rockafellar1997convex}
  R.T. Rockafellar.
  \newblock {\em Convex analysis}.
  \newblock Number~28. Princeton university press, 1997.
\bibitem{rudin1992nonlinear}
  L.~Rudin, S.~Osher, and E.~Fatemi.
  \newblock Nonlinear total variation based noise removal algorithms.
  \newblock {\em Physica D: Nonlinear Phenomena}, 60(1):259--268, 1992.
\end{thebibliography}
\end{document}

enter image description here enter image description here

enter image description here enter image description here

enter image description here

Edit: It may be more convenient to define the \hlbreakable command as an environment, since \begin-\end pairs are easier to trace than pairs of braces.

\newenvironment{hlbreakable}%
  {\color{red}}%
  {}
...
\begin{hlbreakable}
Highlighting a citation causes no compilation error \cite{rockafellar1997convex,rudin1992nonlinear}.
\lipsum
\end{hlbreakable}
10
  • \colorboxes cannot wrap, can they?
    – Daniel
    Commented Oct 26, 2016 at 9:31
  • Thanks, this is very helpful, but I agree with @Daniel's comment that \colorboxes can't wrap. Suppose that I want to highlight an entire paragraph. What would be a nice way to do that?
    – littleO
    Commented Oct 26, 2016 at 9:40
  • Thank you. Would you mind providing an example that shows your first suggestion: "Either don't use background color and replace \textcolor by the \color declaration" ?
    – littleO
    Commented Oct 26, 2016 at 9:53
  • Also, how would you remove the black border around the highlighted text?
    – littleO
    Commented Oct 26, 2016 at 10:13
  • Thank you, that was super helpful! "Moreover, if I read the author's instructions correctly, you can also choose to use just a different text color." I think this is the simplest solution for my situation, together with the \hlbreakable command you provided.
    – littleO
    Commented Oct 26, 2016 at 10:18
17

You only need the "soul" and "color" packages for this to work. Inside the "\hl{...}" command, instead of just putting in "\cite{...}", type "\mbox{\cite{...}}". This should do it.

Without the color/xcolor it will only underline instead of adding the yellow background.

5
  • You should post a minimal document showing whether this works for multiple citations. Commented May 16, 2019 at 7:17
  • 5
    Upvoted this because it is the only response that works with \hl Commented Dec 24, 2020 at 18:26
  • Although this isn't throwing the compilation error, the highlight changes from yellow background to a simple underlined version..
    – momo
    Commented Jun 15, 2022 at 5:18
  • Okay, we need both soul as well as color package for the yellow background to work. Upvoted.
    – momo
    Commented Jun 15, 2022 at 5:20
  • This solution may lead to overfull hboxes due to prevented line breaks within citations. Commented Jul 16 at 21:15
5

A pragmatic solution would be to use some other, less intrusive implementation of highlighting. In the following, I define the \hl command to just switch the text color to red (slightly toned for better readability):

\documentclass{article} 
\usepackage{amsmath,amssymb,enumitem,mathtools}
\usepackage{xcolor}

\newcommand\hl[1]{%
  \bgroup
  \hskip0pt\color{red!80!black}%
  #1%
  \egroup
}

\begin{document}

\hl{This text is highlighted}.

Here's a citation \cite{rockafellar1997convex,rudin1992nonlinear}.

\hl{ Highlighting a citation does no longer cause a compilation error and even  works across line breaks \cite{rockafellar1997convex,rudin1992nonlinear}.}

\begin{thebibliography}{10}

\bibitem{rockafellar1997convex}
R.T. Rockafellar.
\newblock {\em Convex analysis}.
\newblock Number~28. Princeton university press, 1997.

\bibitem{rudin1992nonlinear}
L.~Rudin, S.~Osher, and E.~Fatemi.
\newblock Nonlinear total variation based noise removal algorithms.
\newblock {\em Physica D: Nonlinear Phenomena}, 60(1):259--268, 1992.

\end{thebibliography}

\end{document}

This simple approach looks less fancy, but has a lot of advantages: It works over most content (headings, tables, formulas, ...), is more printer-friendly and – taking the viewpoint of the reviewer – a lot more friendly for the reviewer's eye.

3
  • +1 though red often comes out black on monochrome printers so another colour might work better (you can't assume your reviewer will work on screen or have easy access to a colour printer)
    – Chris H
    Commented Oct 26, 2016 at 15:41
  • A downvote about a year later? I wonder what was the reason for that...
    – Daniel
    Commented Jun 30, 2017 at 21:34
  • Anyway to make it incorporate footnotes? PS citations don't work for me.
    – andrea m.
    Commented May 27, 2021 at 8:10

You must log in to answer this question.

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