# Hyperref and ulem commands cannot be combined

Some hyperref commands do not mix well with ulem commands. Compiling this MWE

\documentclass{article}

\usepackage[normalem]{ulem}
\usepackage{hyperref}

\begin{document}
\sout{\hypertarget{label}{text}}
\end{document}


results in the following error:

! Undefined control sequence.

l.7 \sout{\hypertarget{label}{text}}


Same applies if we replace sout with other ulem commands such as uwave or xout. Is there any solution to this problem? It is nice to use strike-through to symbolize deleted text (Latexdiff does this if the proper option is specified)

Package ulem has restrictions, what can be used inside the argument. Thus \hypertarget cannot be used directly.

It can be protected via \mbox:

\sout{\mbox{\hypertarget{...}{...}}


Or a better solution, would be to switch \sout with \hypertarget:

\hypertarget{label}{\sout{text}}


Complete example:

\documentclass{article}

\usepackage[normalem]{ulem}
\usepackage{hyperref}

\begin{document}
\sout{\mbox{\hypertarget{label}{text}}}
\hypertarget{label2}{\sout{text2}}
\end{document}


• Great! What is the disadvantage of the mbox wrapping? In my particular use case, and given that latexdiff is the one wrapping differences with a custom command, using \sout{\mbox is the only possibility. – user3120046 Aug 1 '14 at 21:47
• oh well I see that mbox-contained text might go over the page margins...life is hard ;-) – user3120046 Aug 1 '14 at 22:29