1

I try to highlight large paragraph of text, where there are various other macros such as \cite, \SI, \ref, etc. in between.

If I do something like the following:

\hl{the duration is \SI{4}{\second} as shown in Figure~\ref{fig:fig1} \citep{Doe2015}}

The text would truncate at "is", or even cannot compile sometimes.

Is there a way to write a macro like this:

\DeclareRobustCommand{\robusthl}[1]{
    \ifnotmacro\hl{#1}\fi}

Thank you so much!

2
1

Protect the offending commands in \mbox. On the other hand, underlining should be avoided as much as possible.

\documentclass{article}

\usepackage{soul,siunitx,natbib}
\soulregister{\ref}{1}
\soulregister{\citep}{1}

\begin{document}

\hl{the duration is \mbox{\SI{4}{\second}} as shown in
Figure~\mbox{\ref{fig:fig1}} \mbox{\citep{Doe2015}}}

\begin{figure}\caption{X}\label{fig:fig1}\end{figure}

\begin{thebibliography}{1}

\bibitem[Doe(2015)]{Doe2015} A paper

\end{thebibliography}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.