Use \LetLtxMacro with a \Macro* (starred variant)

If I use:

\LetLtxMacro{\MacroToUse}{\FormatText}


then using \MacroToUse invokes \FormatText exactly as desired. But, how do use this construct to invoke \FormatText*?

The MWE below yields:

but the desired output is the two lines being identical.

Code:

\documentclass{article}
\usepackage{xcolor}
\usepackage{xparse}

\usepackage{letltxmacro}

\newcommand*{\FormatColor}{}%
\NewDocumentCommand{\FormatText}{s m}{%
\IfBooleanTF{#1}{%
\def\FormatColor{red}%
}{%
\def\FormatColor{blue}%
}%
\textcolor{\FormatColor}{#2}%
}%

\begin{document}
\FormatText{one}
\FormatText*{two}

\newcommand{\MacroToUse}{}%

\LetLtxMacro{\MacroToUse}{\FormatText}%
\MacroToUse{one}
\LetLtxMacro{\MacroToUse}{\FormatText*}%
\MacroToUse{two}
\end{document}

-
I think your questions can be used as model for all. very nice –  texenthusiast May 21 '13 at 22:46
\LetLtxMacro and, in general, all patching commands should not be used with macros defined with xparse facilities. In this case \def\MacroToUse{\FormatText*} is more than sufficient. There's no reason for using \LetLtxMacro here. –  egreg May 21 '13 at 22:46
So you don't want to use \MacroToUse*? –  Werner May 21 '13 at 22:47
@Werner: Have a complex piece of code that I would prefer to not duplicate, or repackage in another macro. it currently calls the starred variant, so would be really nice if I could select to use the starred or no starred variant, and then not have to think about it later in the code. –  Peter Grill May 21 '13 at 22:51
You can create an auxiliary macro \newcommand*{\FormatTextStar}{\FormatText*} for which \LetLtxMacro{\MacroToUse}{\FormatTextStar} would work... –  Werner May 21 '13 at 23:02

This is a place where \LetLtxMacro should not be used.

\documentclass{article}
\usepackage{xcolor}
\usepackage{xparse}

\usepackage{letltxmacro}

\newcommand*{\FormatColor}{}%
\NewDocumentCommand{\FormatText}{s m}{%
\IfBooleanTF{#1}{%
\def\FormatColor{red}%
}{%
\def\FormatColor{blue}%
}%
\textcolor{\FormatColor}{#2}%
}%

\begin{document}
\FormatText{one}
\FormatText*{two}

\newcommand{\MacroToUse}{\FormatText}
\MacroToUse{one}

\renewcommand{\MacroToUse}{\FormatText*}
\MacroToUse{two}
\end{document}


Using \let or its more powerful sibling \LetLtxMacro is basically for when you want to save the meaning of a macro in order to redefine it or, in general, when the other macro can change its meaning afterwards and you want to have its original meaning available, perhaps to restore it.

Here you never modify \FormatText, so there's no need to save its meaning.

If you're worrying about the arguments, don't. When TeX sees

\MacroToUse{two}


in the code above, it will look up the current meaning of \MacroToUse and, since it ia a macro, replace it with the replacement text. So at this stage it will be presented with

\FormatText*{two}


which is just what's needed.

In any case, you can't use

\LetLtxMacro{\foo}{\baz*}


assuming that \baz has a *-variant. The second argument to \LetLtxMacro should be a single token, and \baz* is two tokens. The * doesn't make part of the macro's name.

-