0

I'm having trouble understanding part of the documentation for the soul package. I want to know the exact lower and upper positions of the produced colored rectangle when highlighting text via the \hl command. The documentation states that highlighting "is nothing else than overstriking with very thick lines" apparently of box height 2.5ex. I've been looking at sections 8.7-8.8 of the documentation.
https://ctan.mirrors.hoobly.com/macros/generic/soul/soul.pdf

When I compare highlighting via soul and blackouting via the censor package, the censor package blackouts text with default height and depth of 2.1 ex and -0.3ex respectively with a total box height of 2.4 ex.
https://mirrors.mit.edu/CTAN/macros/latex/contrib/censor/censor.pdf

I feel like there should be a way to highlight text with custom upper and lower bounds of the colored rectangle similar to how you can set the height and depth of the black box when blackouting via censor. E.g. \highlight{depth}{height}{text to be highlighted}.

Edit: I'm testing the following:

\begingroup
\sbox0{\heightof{\hl{abcdefghijklmnopqrstuvwxyz}}}
%width=\the\wd0\linebreak
height=\the\ht0\linebreak
depth=\the\dp0
\endgroup

1 Answer 1

1

If you trace through the source code, you'll be able to find out that \SOUL@hlpreamble uses \SOUL@stpreamble, which in turns calculates the depth by

\def\SOUL@stpreamble{%
    \dimen@\SOUL@ulthickness
    \dimen@i=-.5ex
    \advance\[email protected]\dimen@
    \edef\SOUL@uldepth{\the\dimen@i}%
    \let\SOUL@ulcolor\SOUL@stcolor
    \SOUL@ulpreamble
}

which means the box is made so that the center is 0.5ex above the baseline. Given that the box height is 2.5ex, this would mean the top is 0.5ex+1.25ex above the baseline and the bottom is 1.25ex-0.5ex below the baseline.

As for customizing the height, you could do something like

%! TEX program = lualatex
\documentclass{article}
\usepackage{xcolor}
\usepackage{soul}
\begin{document}

\begingroup
\setul{-2ex}{2ex}
\setulcolor{red}
\ul{test test test}
\endgroup

\ul{test test test}
\end{document}

output image

where the first -2ex is the depth (the top of the box is 2ex above the baseline) and the second 2ex is the height.

Alternatively if you just want to change the height of the box you could use How to customize the highlight height with soul - TeX - LaTeX Stack Exchange or math mode - Customizing highlighting from soul - TeX - LaTeX Stack Exchange

You must log in to answer this question.

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