# Error when trying to color and underline

Here is my piece of code

\documentclass{article}
\usepackage{color,soul}
\begin{document}
\begin{quote}
\tt\
\ul{{\color{red}text}}.
\end{quote}
\end{document}


This simple piece of code generates a word "text" in red with an underline. However, if you just add a space after the word "text" or a space followed by a word, like

\documentclass{article}
\usepackage{color,soul}
\begin{document}
\begin{quote}
\tt\
\ul{{\color{red}text text}}.
\end{quote}
\end{document}


it will generate an error like

! Package soul Error: Reconstruction failed.

See the soul package documentation for explanation.
Type  H <return>  for immediate help.
...

l.9 \ul{{\color{red}text text}}
.


Can somebody tell me why is that? How can I do both color and underline but I can control the color of the underline?

• Try {\color{red}text} text inside \ul
– user31729
Jun 16, 2017 at 0:51
• ... and don't use the deprecated \tt command.
– user31729
Jun 16, 2017 at 1:00
• Your code compiles without problem, but it's clear that your example code differs from the error.
– Werner
Jun 16, 2017 at 1:07
• Can you fix your code to replicate the error? Otherwise this question is unclear.
– Werner
Jun 16, 2017 at 2:00
• I just added the piece that generates the error message. Jun 16, 2017 at 13:44

Grouping with \textcolor works:

\documentclass{article}
\usepackage{color,soul}
\begin{document}
\begin{quote}
\ttfamily
\ul{{\textcolor{red}{text}}}.
\end{quote}
\end{document}


The color of the underline can be controlled with \setulcolor:

\documentclass{article}
\usepackage{color,soul}
\begin{document}
\begin{quote}
\ttfamily
\setulcolor{cyan}
\ul{{\color{red}text}}.
\end{quote}
\end{document}


Or rewritten to move the color command out of \ul's argument:

\documentclass{article}
\usepackage{color,soul}
\begin{document}
\begin{quote}
\ttfamily
\setulcolor{cyan}%
\textcolor{red}{\ul{text}}.
\end{quote}
\end{document}

• In this case it also works using \ul{{\color{red}text}}...
– Werner
Jun 16, 2017 at 1:09