2
\usepackage{soulutf8}
\begin{document}
\hl{ AAAA {\ul{AAAA}} AAAA} 
\end{document} 

fails:

! Package soul Error: Reconstruction

\underline works but I don't seem to be able to change its color and spacing like \setulcolor{gray} and \setul{1pt}{} for \ul, and it's default space is too ugly for what I'm doing.

1

2 Answers 2

5

With lualatex and the new lua-ul package the following works fine:

\documentclass{article}
\usepackage{luacolor}
\usepackage[soul]{lua-ul}
\begin{document}
\hl{AAAA \ul{AAAA} AAAA}
\end{document}

enter image description here

1
  • 1
    AFAIK, this approach allows you basically all formatings that you may want to, such as font coloring+highliting+striking out, at the same time! Commented Jan 13, 2023 at 18:07
0

The soulutf8 package loads the soul package and adds utf8 support. The following code is based on the soul documentation, § 22 Nested soul commands:

\documentclass{article}
\usepackage{xcolor}
\usepackage{soulutf8}
\begin{document}
\newbox\mybox
\sbox\mybox{ \ul{AAAA} }
\hl{ AAAA {\usebox\mybox} AAAA} 
\end{document}

Result:

enter image description here

The basic idea is that you put the inner text in a box, which computes the underlining, and then call this box in the outer text. If you try to do it directly the two simultaneous size computations become problematic.

Related questions with the same problem but different (and easier to use!) solutions:

Mixing underline and strike-out

Follow-up: Underline + strike-through using soul

2
  • Interesting solution! Too bad the boxes don't respect the text margins.
    – Raphael
    Commented Mar 2, 2018 at 14:05
  • 1
    They don't :) You could try the tikz solution in the first link for multiline text. Side note: in general underlining and highlighting does not look very nice, maybe you can use different markup? Except maybe for work in progress documents, but in that case there are other useful packages like todonotes.
    – Marijn
    Commented Mar 2, 2018 at 15:00

You must log in to answer this question.

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