[Tex/LaTex] Underline just words, not the space between them

formattingsoulspacingtext-decorations

I need to typeset a sentence such that just the words are underlined, and not the space between the words.
Using the \underline will include the spaces between the words. I could do it with something like

\underline{The} \underline{quick} \underline{brown} \underline{fox} \underline{jumped} \underline{over} \underline{the} \underline{lazy} \underline{dog}

but it is too tedious and a painful thing to do.
Also, the above line produces what is intended, but the spacing of the underline from the words is uneven. It would be really helpful if this is addressed in the answer as well. The above line produces this:
enter image description here

Is there a package or something easier to achieve this?

Best Answer

Let's make soul work less:

\documentclass{article}
\usepackage{xparse,soul}

\ExplSyntaxOn
\NewDocumentCommand{\ulns}{m}
 {
  \seq_set_split:Nnn \l_tmpa_seq { ~ } { #1 }
  \seq_map_inline:Nn \l_tmpa_seq { \ul{##1}~ } \unskip
 }
\ExplSyntaxOff

\begin{document}

\ulns{The quick brown fox jumped} over the lazy dog.

\end{document}

Basically, the argument is split at spaces; every fragment is fed to \ul and a space is added. The last one is removed by \unskip.

enter image description here