5

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.
<recently read> \put@me@back 

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)

2 Answers 2

5

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}

Result

2
  • 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. Aug 1, 2014 at 21:47
  • oh well I see that mbox-contained text might go over the page margins...life is hard ;-) Aug 1, 2014 at 22:29
1

Yes, very old question, but just seeing it now. A new version of ulem.sty (April 2020) will fix this problem.

The offending part of \hypertarget was \penalty, which caused \sout to close one box and start another, with the penalty between them. This causes \hypertarget to lose track of its local context. But the penalty used was 10000 (no break) so ulem can skip processing such penalties completely.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .