# Remove Line Breaks and Underline Text

I'm writing a thesis template that follows a style guide. According to the guide, the title of the document needs to appear in several places. In some places, the title text must be broken into several lines and in other places it must be underlined.

Ideally the user of the template would only need to input the title once while defining the best way to break the text into multiple lines. For a title input this way, I'm having trouble removing the line breaks and applying the underlining without screwing up the text somehow. This is what I have so far.

\documentclass{article}
\usepackage[normalem]{ulem}

\newcommand{\removelinebreaks}[1]{%
\begingroup\def\\{\relax}#1\endgroup}

\newcommand{\Title}[1]{\gdef\TheTitleField{\removelinebreaks{#1}}}

\Title{This Is A Long Title\\
That Should Be Broken\\
Up Into Several Lines\\
Lets Add A Few Lines \\
To Make This Even Longer
}

\begin{document}

\TheTitleField

\vspace{1in}

\uline{\TheTitleField}

\end{document}


What's the best way to remove the line breaks and apply underlining such that the text will break where it supposed to?

Do you mean something like this?

\documentclass{article}
\usepackage[normalem]{ulem}
\newcommand{\removelinebreaks}[1]{%
\def\\{\relax}#1}
\newcommand{\Title}[1]{\gdef\OrigTitle{#1}}
\def\TitleUline{\uline{\OrigTitle}}
\def\TitleRLB{\removelinebreaks{\OrigTitle}}
\makeatletter
\def\TitleUlineRLB{%
\def\\{\relax}%
\protected@edef\tmp{\OrigTitle}%
\expandafter\uline\expandafter{\tmp}%
}
\makeatother
\begin{document}
\Title{This Is A Long Title\\
That Should Be Broken\\
Up Into Several Lines\\
Lets Add A Few Lines \\
To Make This Even Longer
}

\TitleRLB% remove line breaks

\vspace{1cm}
\TitleUline% underline

\vspace{1cm}
\TitleUlineRLB% underline and remove line breaks
\end{document}