Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
Upvoting the question to reward the OP for his participation in the useful comment dialog, ending with his endorsement of @cfr 's analysis. –  Ethan Bolker Aug 20 at 12:53
    
Thanks @EthanBolker :) –  Gabriel Aug 20 at 12:58

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
The OP no doubt would prefer the footnotes to be cared for automatically, I would :) I'll keep the question open until tomorrow then. Thank you! –  Gabriel Aug 19 at 16:48
    
Andrew: please see edited answer, I've added the natbib package. –  Gabriel Aug 19 at 18:02
    
@Gabriel Sorry, the idea that I had for extending this doesn't work. Worse than this, my proposed solution is fundamentally flawed because it does not cope with line breaks in the highlighted text. Given this I think that that the only honourable thing to do is for me to delete my answer. I will do this once you have had a chance to read this comment. –  Andrew Aug 20 at 6:06
    
Please don't delete your answer, it came very close of being a complete answer to the question and it got enough votes to ensure people found it useful. As I said in a cmmt above I'm accepting your answer and I'll present a caveat in the original question mentioning latexdiff. –  Gabriel Aug 20 at 11:43
2  
@Gabriel Thanks, I leave it up then. I am a big fan of latexdiff as well. It works particularly well when combined with git for version (and collaborator:) control. –  Andrew Aug 20 at 12:14

You need to be careful of stomach commands in section titles, use the optional argument. This works. You also have an issue with \citep{} from "natbib", which you missed from your MWE.

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

\begin{document}

\section[title of section]{\hl{Title of a section}}

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

\begin{thebibliography}{1}
\bibitem{Knuth86} D.E. Knuth, The TeXbook, 1986
\end{thebibliography}

\end{document}

Check this article for some very goods tips, about hyperref's commands.

share|improve this answer
    
Adding [] before the section title works in getting it highlighted, thanks. As for the rest I don't know if I might be missing something but the \protect command makes a bit of a mess by changing how anything beyond the \hl{} that follows is handled. Also what I want is to not have to jump through these loops in order to get \hl to work. I want a command that will just work without needing any extra commands. –  Gabriel Aug 19 at 18:07
    
@Gabriel The "I want a command that will just work without needing any extra commands" part, is not possible. What you asking actually is typographically abhorent and unsurprising no-one has spent time to develop it. You might have a bit of better luck with XelaTeX and fontspec, but again is not instant cream soda. –  Yiannis Lazarides Aug 19 at 18:30
    
Yiannis: the not possible part Im' pretty sure it's not true. LaTeX is a programming language and I see no reason why this command could not exist. The typographically abhorent bit I can understand but I'm not after such a command to use in finished documents. This would be useful when one needs to highlight changes say to show a co-author quickly what has changed in a new version of an article/chapter/etc. –  Gabriel Aug 19 at 18:36
    
And still my issue with \protect remains. If I use \hl{This is a line where a citation \protect\cite{Knuth86} appears.} it will prevent appears from being highlighted even though it is wrapped inside the \hl command. –  Gabriel Aug 19 at 18:38
2  
@Gabriel This is surely an XY problem. There are much easier and more efficient ways to manage this workflow than the one you are looking for. You should not be marking up your changes manually in the first place. (I assume you are not editing the original .tex file but even so.) Use something like latexdiff to create a document highlighting the changes. If you really want to highlight them manually, then doing so in the PDF probably is the easiest solution. –  cfr Aug 20 at 0:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.