[Tex/LaTex] Extending underline up to the right side

soultext-decorations

I need to create command that underlines some given text that takes several lines. And the underline of the last line should be extended up to the right side of page. When I need just to underline multiline text I use \ul from soul package. But I couldn't find any trick to extend last line. Something like \ul{Last line\hfill\mbox{}} gives nothing. Using \soulregister{\hfill}{0} doesn't help, too. Even if I force line break, \hfill will be ignored, i.e. \ul{Last line\hfill\mbox{}\linebreak} gives line with huge space between Last and line and no space after line. The only way to get something close to desired that I've found is the following.

\documentclass{article}
\usepackage{soul}

\newcommand{\raisedrule}[1]{\leaders\hbox{\rule[#1]{1pt}{0.4pt}}\hfill}
\newcommand{\longunderline}[1]{\ul{#1}\raisedrule{-3.5pt}\mbox{}}
\soulregister{\hfill}{0}

\begin{document}
    \longunderline{Some long text. Some long text. Some long text. Some long text. Some long text. Some long text.}

    \longunderline{Some short text.}

    \ul{Oh, \hfill.}
\end{document}

However height of raise of rule may depend on text and there is some break between underline and rule after text. So my solution is really bad. Do you see something better?

More complex case when I need to make exact number of undelined lines, supposing that text is always short enough to fit into desired number of lines, but not always long enough, i.e. some lines may be completely blank. Any idea?

EDIT

Using ulem and \uline instead of soul and \ul allows to “underline” \hfill. However it gives new problem loosing hyphenation. More interesting that it is possible to “help” it to make hyphen.

\documentclass{article}
\usepackage{soul}
\usepackage{ulem}

\pagestyle{empty}
\soulregister{\hfill}{0}

\begin{document}
    \uline{Some long text. Some long text. Some long text. Some long text. Somelongword. Some long text.\hfill}

    \uline{Some long text. Some long text. Some long text. Some long text. Somelong\-word. Some long text.\hfill}

    \ul{Some long text. Some long text. Some long text. Some long text. Somelongword. Some long text.\hfill}
\end{document}

enter image description here

Middle version is what I want to get, but now it is needed to allow hyphen by hand.

EDIT 2

One more example. Here \uline makes overfull while \ul does not make neither overfull nor underfull.

\documentclass{article}
\usepackage{soul}
\usepackage{ulem}

\begin{document}
    \Huge
    \ul{Some long text. Some long text. Some long text. Some long text. Some long text. Some long text.}

    \uline{Some long text. Some long text. Some long text. Some long text. Some long text. Some long text.}
\end{document}

enter image description here

Best Answer

\documentclass{article}
\usepackage{soul}
\usepackage{linegoal}


\newcommand{\raisedrule}[1]{\rule[#1]{\linegoal}{0.45pt}}
\newcommand{\longunderline}[1]{\ul{#1}\raisedrule{-.75ex}}

\begin{document}
    \longunderline{Some long text. Some long text. Some long text. Some long text. Some long text. Some long text.}

    \longunderline{Some short text.}

    \longunderline{Oh,.}

    \longunderline{Last line}

    \longunderline{Some long text. Some long text. Some long text. Some long text. Somelongword. Some long text.}
\end{document}

enter image description here

This takes at least two compilation runs.