# Can't include \url within \hl from soul package

I am wanting to include a link within some highlighted text. The highlighting is currently being performed by the soul package but the following example shows it returns a bunch of warnings and fails to render the link:

\documentclass{book}

% Package used for highlighting
\usepackage{soul}

\usepackage[ps2pdf]{hyperref}
\usepackage[anythingbreaks]{breakurl}

\begin{document}

\end{document}


Package hyperref Warning: Rerun to get /PageLabels entry.

! Undefined control sequence. l.14 Complains when link is within highlight: \hl { Highlight link \url{http...

Any idea how I can get links to appear within the \hl command?

The \url command is fragile. The following works.

\documentclass{book}

% Package used for highlighting
\usepackage{soul}

\usepackage{hyperref}
\usepackage[anythingbreaks]{breakurl}

\begin{document}

Complains when link is within highlight: \hl{ Highlight link \protect\url{http://google.co.uk/} }

\end{document}

• Thanks but when I add text after the link the highlighting disappears. \hl{ Highlight link \protect\url{http://google.co.uk/} after } – A Dark Divided Gem Jul 29 '16 at 15:14
• You're right; I'm out of my depth. – JPi Jul 29 '16 at 15:30
• That makes both of us! I have updated my question to include text after the link to be more indicative of the environment the solution will be used within. – A Dark Divided Gem Jul 29 '16 at 15:38

It seems wrapping the robust \hbox command round the \url command prevents the fragility of the url command from interfering with the hl command. This does mean the URL cannot break between lines but this will have to do for now, unless anyone can find a better solution.

\documentclass{book}

% Package used for highlighting
\usepackage{soul}