The soul package provides a useful command \hl for highlighting text.
However, \cite, \ref, and some other commands (maybe equations too) must be placed within an \mbox in order for \hl to work properly.
Is there any way to make this automatic? Meaning that to modify \hl (and other commands provided by soul) to put everything except plain text in an \mbox?
\documentclass[12pt]{article}
\usepackage{soul}
\begin{document}
\section{1}\label{sec}
This is to show that \textbackslash{hl} fails to highlight texts containing citations or reference!
\hl{ This is one line containing a citation \mbox{\cite{}}}
\hl{ This is one line containing a reference \mbox{\ref{sec}}}
\end{document}


\cite,\refand some inline equations are incompatible. Putting everything except a plain text in a\mboxwould not be a good idea since some commands need text wrapping! For a preliminary solution, maybe defining a list of incompatible commands and automatically place them inside an\mbox(if they are used in\hl) would help! – M.Reza Oct 18 '13 at 18:02\soulregister\ref{7}? – Robert Oct 18 '13 at 18:59\soulregister\X{7}, whereXis the command name,\hlencloses that command in braces. – M.Reza Oct 18 '13 at 20:08