Customizing highlighting from soul
Add some more to the depth (and the thickness), also setting \lineskip
to zero. Note that this changes the interline space, but there's no way that I know for convincing soul
and \hl
to cover something that exceeds the stated depth for the underline (the background color is realized as underlining with a very thick rule).
\documentclass[a8paper, landscape]{scrartcl}
\usepackage{soul}
\usepackage[svgnames]{xcolor}
\sethlcolor{LightBlue}
\makeatletter
\def\SOUL@hlpreamble{%
\setul{\dimexpr\dp\strutbox+2pt}{\dimexpr\ht\strutbox+\dp\strutbox+2pt\relax}
\let\SOUL@stcolor\SOUL@hlcolor
\SOUL@stpreamble
}
\makeatother
\begin{document}
\setlength{\lineskip}{0pt}
This is some \hl{highlighted text with a formula $q=\frac{p}{r}$.
Notice how nicely it is highlighted.}
Writting something more fancy, say, \hl{$|a|=\inf_{\overline{f}=a}|f|$,
gives an obvious gap problem.}
\end{document}
Don't use \hl
in your final document.
Related videos on Youtube
Lukas
Updated on August 01, 2022Comments
-
Lukas over 1 year
I am using the following customization from make soul highlight span lines for the
\hl
fromsoul
to get rid of the gaps between the highlighted zones:\documentclass[a8paper, landscape]{scrartcl} \usepackage{soul} \usepackage[svgnames]{xcolor} \sethlcolor{LightBlue} \makeatletter \def\SOUL@hlpreamble{% \setul{\dp\strutbox}{\dimexpr\ht\strutbox+\dp\strutbox\relax} \let\SOUL@stcolor\SOUL@hlcolor \SOUL@stpreamble } \makeatother \begin{document} This is some \hl{highlighted text with a formula $q=\frac{p}{r}$. Notice how nicely it is highlighted.} Writting something more fancy, say, \hl{$|a|=\inf_{\overline{f}=a}|f|$, gives an obvious gap problem.} \end{document}
Which produces
However, if there are symbols that extend below/above too much, the
\hl
does not fully highlight the gap, as the above example shows. I tried to fiddle with the\setul
part but nothing seems to give a good result. I also tried to\smash
the inf construction, but then the line below just overlaps with the one above.What would be the right setup to highlight that gap?
-
Lukas almost 7 yearsThanks for the answer. What do you mean by "Don't use
\hl
in your final document" ? Is there a better method to do this kind of highlighting without usingsoul
?