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

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

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

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.