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.

Raphael
  • 564

2 Answers2

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

Ulrike Fischer
  • 327,261
  • 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! – Rubem Pacelli Jan 13 '23 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

Marijn
  • 37,699
  • Interesting solution! Too bad the boxes don't respect the text margins. – Raphael Mar 02 '18 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 Mar 02 '18 at 15:00