[Tex/LaTex] Highlight anything in LaTeX article

highlighting

I'm looking for a package/command that will highlight anything I wrap with it. Currently the closest thing I've found is soul but it has many shortcomings:

  • No sectioning highlighting
  • No automatic footnotes highlighting
  • No \cite highlighting unless wrapped in an \mbox{}
  • No \citep highlighting

Here's an example article where these points can be seen:

\documentclass{article}
\usepackage{hyperref}
\hypersetup{colorlinks=true, urlcolor=blue, citecolor=cyan, pdfborder={0 0 0},}
\usepackage{soul}
\usepackage{natbib}
\bibliographystyle{plainnat}

\begin{document}

\section{\hl{Title of a section}}

This is a line with no highlighting done.\\
\hl{This is a line where a citation \citep{Knuth86} appears.}
\hl{This is a line with a footnote\footnote{And this is the footnote that should also be automatically highlighted.} which I want highlighted.}

\bibliography{biblio}

\end{document}

where the biblio.bib file looks like:

@ARTICLE{Knuth86,
   author = {Knuth, D. E.},
    title = "{The TeXbook}",
    year = 1986,
}

If you try to compile it with the usual:

pdflatex "%f" && bibtex "%e" && pdflatex "%f" && pdflatex "%f"

command, it will fail for all the reasons I gave above. Isn't there something that just works?


Edit

The accepted answer comes close but after finding out about latexdiff (http://www.ctan.org/pkg/latexdiff) I actually switched to using that app instead of manually highlighting text.

Best Answer

This is only a partial solution and it doesn't really work across linebreaks well, but if you replace the highlight commands with

\usepackage{tcolorbox}
\newtcbox{\hl}[1][yellow]{on line, arc=7pt,colback=#1!10!white,colframe=#1!50!black,
  before upper={\rule[-3pt]{0pt}{10pt}},boxrule=1pt, boxsep=0pt,left=6pt,
  right=6pt,top=2pt,bottom=2pt}

then I think that the highlighting almost works the way that the OP wants it to:

enter image description here

The main issue is that the \footnote does not appear at all. (The OP might also complain about \citep but as the package specifications for this seem to be missing I just used \usepackage[numbers]{natbib} and carried on.)

You can get the footnote to display properly, with the required highlighting, by manually using \footnotemark and \footnotetext:

\hl{This is a line with a footnote\footnotemark which I want highlighted.}
\footnotetext{\hl{And this is the footnote that should also be 
      automatically highlighted.}}

This now produces the missing footnote:

enter image description here

The OP no doubt would prefer the footnotes to be cared for automatically. I think that this should be possible to arrange, although multiple footnotes in a section of highlighted text might cause problems. I don't have time to do this now but if no one else has found a solution I will try and look at this tomorrow.

Related Question