I want underlined text (or math) where the color of the underline is different from the color of the text (e.g. black text underlined by a red line). Therefore I tried the following code using the \uline from ulem-package:
\documentclass{article}
\usepackage{ulem}
\usepackage{xcolor}
\begin{document}
\color{red}\uline{\begingroup\color{black} a ä $a$ öü a a a aa a a a aa a a a aa a a a aa a a a aa a a a aa a a a aa a a a aa a a a aa a a a aa a a a a a aa a\endgroup}\color{black} gsgfsd
\end{document}
This produces an error message that \endgroup is missing :(
Why?
How can I fix this?

soulpackage has problems with non-English languages. I would prefereulem– Jakob Aug 05 '20 at 16:06ulemindicates that you can define the following macro for red underline (maybe also need to loadxcolor):\newcommand\reduline{\bgroup\markoverwith{\textcolor{red}{\rule[-0.5ex]{2pt}{0.4pt}}}\ULon}. I can do\reduline{\color{blue}abcde}, which gives blue text with red underline. – Alan Xiang Aug 05 '20 at 16:10