2

I am currently proofreading a document and want to highlight some sentences. Unfortunately, I haven't found a highlighting package that can both

  1. Preserve linebreaks
  2. Highlight text produced by macros, especially \cite and the macros from siunitx such as \SI

Using the changes package, linebreaks do not work (changes uses internally a colorbox). However, with soul, the macros do not work. In the end, I would like to use highlight from changes, since it combines nicely with a comment function. By replacing the colorbox using

\renewcommand{\colorbox}[2]{\colorlet{tmpcolor}{#1}\sethlcolor{tmpcolor}\hl{#2}}

I am able to "patch" the highlight command to use soul. For using \cite with soul I can use soulregister as pointed out in How to make \hl (highlighting) to automatically place incompatible commands in \mbox?. However, this approach does not work for \SI. The \SI command, however, works, if it is surrounded by braces. But this is not an option for me, since I am not responsible for writing the original text. Including a preamble, however, is fine.

How can I do highlighting without having to change the text (aside from preambles and the surrounding command)? Ideally I would not need to include a separate entry for each macro, but it would be acceptable for me to do so. To some extent, crude hacks (such as redefining \SI) would be ok as well.

MWE using changes

\documentclass[11pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{changes}

\begin{document}
After the introduction, \highlight{this part of the sentence is quite long and contains a unit (\SI{5}{\ns}) and a citation~\cite{myref}.} How do I highlight it?
\end{document}

MWE using soul (with braces around SI)

\documentclass[11pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{color}
\usepackage{soul}

\soulregister\cite7
%\soulregister\SI7 %Does not work

\begin{document}
After the introduction, \highlight{this part of the sentence is quite long and contains a unit ({\SI{5}{\ns}}) and a citation~\cite{myref}.} How do I highlight it?
\end{document}
1
2

Place macro in their own group and use \hl from the soul package.

\documentclass[11pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{changes}
\usepackage{soul}
\begin{document}
After the introduction, \hl{this part of the sentence is quite 
long and contains a unit ({\SI{5}{\ns}}) and a citation~{\cite{myref}}.} 
How do I highlight it?
\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.