The problem is that Manipulate
localizes its variables. It does this lexically, that is, the variables that appear in the actual text of the code body are localized, but not the ones that might appear when the code is evaluated. So the t
in replacement
is different than the t
in the Manipulate
. Sometimes it is important to keep the variables localized, so it is usually better (less bug-prone) to avoid applying Evaluate
to the body, just in case the variables are given global values at some point in the kernel session.
One alternative is to construct the expression within Manipulate
:
Manipulate[Plot[a[t] /. replacement, {r, 0, 1}],
{t, 1, 2},
{{replacement, {a[t] -> r}}, ControlType -> None}]
Another is to construct them as functions and pass the Manipulate
parameters:
replacement[t_] := {a[t] -> r};
Manipulate[Plot[a[t] /. replacement[t], {r, 0, 1}], {t, 1, 2}]
Or all parameters:
replacement[a_, t_, r_] := {a[t] -> r};
Manipulate[Plot[a[t] /. replacement[a, t, r], {r, 0, 1}], {t, 1, 2}]