[Tex/LaTex] Underline colored text with linebreak

colorline-breakingulemunderline

I would like to underline colored text with a black line, and preserve line breaking. My best solution so far is using \uline from the ulem package. However, I cannot get my desired result. My attempts are:

\documentclass{article}
\usepackage{ulem}
\usepackage{color}

\begin{document}

This is a long text. This is a long text. 
\color{red}\uline{This is underlined text. 
This is underlined text. This is underlined text.}\color{black} 
This is a long text. This is a long text. 

This is a long text. This is a long text. 
\uline{\color{red}This is underlined text. 
This is underlined text. \color{black}} 
This is a long text. This is a long text. 

This is a long text. This is a long text. 
\textcolor{red}{\uline{This is underlined text. 
This is underlined text. }} 
This is a long text. This is a long text. 

This is a long text. This is a long text. 
\uline{\textcolor{red}{This is underlined text. 
This is underlined text. }} 
This is a long text. This is a long text. 

\end{document}

enter image description here

As you can see, every attempt has a flaw.

Is there a solution to this? Many thanks!

EDIT:

I am now using the cloze package, which does not have the shortcomings above and has not let me down yet. It is definitely an option for everyone who can switch to LuaLaTeX.

Best Answer

If it is just a command that gives red text underlined with black line, then this might work

\newcommand\reduline{\bgroup\color{red}\markoverwith
{\textcolor{black}{\rule[-0.5ex]{2pt}{0.4pt}}}\ULon}

If not, don't get your hopes up too hight, things get complicated when you parse in the way \ulem does.

BTW: who is even using underlining these days?