[Tex/LaTex] Error: Reconstruction failed for \hl (highlighted) newcommand text

emphasishighlightingmacrossoul

Sorry if this has been asked before. I could not find an answer to this problem yet. I'm finding some issues when highlighting text defined by newcommand:

\documentclass{article}
\usepackage{color,soul}
\newcommand{\etal}{\emph{et al.}}
\begin{document}
\hl{A statement \etal}
\end{document}

gives error Package soul Error: Reconstruction failed.

Surprisingly, \hl{A statement \emph{et al.}} works just fine.

What am I doing wrong? Is there anything I can do to fix this? Using \emph{et al.} instead of \etal is not my preferred solution, since sometimes I just want to highlight text that's already there.
This answer doesn't solve the problem either, since \hl{A statement {\etal}} returns the same error. I've checked this other solution, but I'm not sure how to use it for my own defined command…

Thanks!

Best Answer

The soul analyzes the macro arguments of \hl and the related soul macros. All font switching macros like \emph and \bf (the later being outdated, of course) are 'registered' to prevent soul to analyze them but to execute them immediately ('expand') in order to perform the highlighting after this expansion.

\hl{A statement \emph{et al.}} 

works since \emph is registered already, but \etal is not. This can be done however with

\soulregister\etal7

will enable \etal for soul usage, 'abusing' the \soulregister feature a little bit. The documentation does not reveal that 7 is possible.

\documentclass{article}
\usepackage{color,soul}
\newcommand{\etal}{\emph{et al.}}

\soulregister{\etal}{7}
\begin{document}

\hl{A statement \emph{et al.}}


\hl{A statement \etal}
\end{document}

enter image description here