Continuing with my struggle to deal with expansion issues, I am stuck on how to use an `\edef` properly. The code below with the switches set as:

```
%\def\ApplyColorToTitle{}
%\def\UseMathrmInTitle{}
\def\UseEdefInsteasOfDef{}

```

produces:

![enter image description here](https://i.stack.imgur.com/nZtSI.png)

but as soon as I attempt to apply color formatting of the title, or even use `\mathrm{}` (surprisingly using `\text{}` does not exhibit this problem) in the title I get compile errors if I attempt to use the `\edef`. That is, the following settings work:

```
\def\ApplyColorToTitle{}
\def\UseMathrmInTitle{}
%\def\UseEdefInsteasOfDef{}

```

and produce the desired result:

![enter image description here](https://i.stack.imgur.com/KlQT6.png)

However, I would like to be able to use this code with all the switches enabled:

```
\def\ApplyColorToTitle{}
\def\UseMathrmInTitle{}
\def\UseEdefInsteasOfDef{}

```

In this case I *thought* I needed to use a `\noexpand` on the formatting macro in the `\edef`:

```
\edef\FormattedTitle{\noexpand\FormatTitle{\Title}}

```

This `\noexpand` does work for the case of:

```
\def\ApplyColorToTitle{}
%\def\UseMathrmInTitle{}
\def\UseEdefInsteasOfDef{}

```

and hence I thought I was on the right track, but still fails with the use `\mathrm{}`.

Question:
---------

How do I use the `\edef` instead of a `\def` **and** allow for use of `\mathrm{}` along with the color formatting?

Note:
-----

* I have to admit I am not sure why I have the `\edef` here in the first place, but there must have been a case that was not working that got fixed when I switched to using an `\edef`. I realize that it is not a very good reason, but that is why I would prefer to continue to use the `\edef`. If the expansion gurus here see no reason to be using an `\edef` here and recommend that I just use the `\def` I will do that until I am able to provide a MWE that actually requires a `\edef`.
* I do need to use `\mathrm{}` instead of `\text{}` to ensure that the `th` is in roman font even if the title is wrapped in another formatting macro..

Code:
-----

```
%\def\ApplyColorToTitle{}
%\def\UseMathrmInTitle{}
\def\UseEdefInsteasOfDef{}

\documentclass{article}
\usepackage{xcolor}
\usepackage{amsmath}

\newcommand*{\Title}{}%
\newcommand*{\SetTitle}[1]{%
    \renewcommand*{\Title}{#1}%
}%

\ifdefined\ApplyColorToTitle
    \newcommand{\FormatTitle}[1]{\textbf{\textcolor{blue}{\boldmath#1}}}%
\else
    \newcommand{\FormatTitle}[1]{#1}%
\fi

\begin{document}
\ifdefined\UseMathrmInTitle
    \SetTitle{$n^{\mathrm{th}}$ Root}%
\else
    \SetTitle{$n^{\text{th}}$ Root}%
\fi

\ifdefined\UseEdefInsteasOfDef% Would prefer to use an edef
    \edef\FormattedTitle{\FormatTitle{\Title}}%
    % Thought that adding this \noexpand would do the trick as
    % it seems to alow for \ApplyColorToTitle being defined.
    %\edef\FormattedTitle{\noexpand\FormatTitle{\Title}}%
\else
    \def\FormattedTitle{\FormatTitle{\Title}}%
\fi

Title is: \FormattedTitle
\end{document}

```