1

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?

5
  • 1
    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.
    – fanchyna
    Jun 16, 2017 at 13:44

1 Answer 1

4

Grouping with \textcolor works:

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

Result

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}

Result

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}
1
  • In this case it also works using \ul{{\color{red}text}}...
    – Werner
    Jun 16, 2017 at 1:09

You must log in to answer this question.

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