# How to prevent Manipulate from using localized names in its frame label?

In short, the following Mathematica code

Manipulate[
Plot[a Sin[x], {x, -Pi, Pi}],
{a, -1, 1},
FrameLabel -> TraditionalForm[y == a Sin[x]]]


produces a plot with the (obviously wrong) label

$\textrm{y}=\textrm{a}\$\$\sin(\textrm{x})$.

I am trying to use this in a function which plots and automatically labels other functions, so separating the manipulated variable somehow in the label is not an option.

• Try using TraditionalForm[y == Dynamic[a] Sin[x]] instead. – Karsten 7. Aug 23 '16 at 0:52
• I am trying to use this in a function which plots and automatically labels other functions, so separating the manipulated variable somehow in the label is not an option. – Fibonacci Aug 23 '16 at 0:55
• What do you want the label to look like? What about TraditionalForm[y == "a" Sin[x]]? – Karsten 7. Aug 23 '16 at 0:58
• I think it's unclear what would be obviously right.... – Michael E2 Aug 23 '16 at 1:17
• FrameLabel -> (TraditionalForm[y == a Sin[x]] /. a -> ToString[a]) works. – Fibonacci Aug 23 '16 at 4:25

If using an other, modified input expression for TraditionalForm is not an option and you want the label to look like

TraditionalForm[y == a Sin[x]]


then using a replacement rule, that will replace a with a is an alternative

Manipulate[Plot[a Sin[x], {x, -Pi, Pi}], {a, -1, 1},


This approach also works in usage scenarios like

Table[
With[{expr = expr},
Manipulate[Plot[expr, {x, -Pi, Pi}], {a, -1, 1},
a -> ToString[a, TraditionalForm])]], {expr, {a Sin[x], a Cos[a x]}}] // Column


or

TabView[Table[
With[{expr = expr},
Manipulate[Plot[expr, {x, -Pi, Pi}], {a, -1, 1},
a -> ToString[a, TraditionalForm])]], {expr, {a Sin[x], a Cos[a x]}}]]


Manipulate automatically wraps 1st argument in DynamicModule with the variables defined in its control specifications as the localized dynamic variables. But expressions in its options list are not so treated. So you have to manually make them dynamic.

Manipulate[
Plot[a Sin[x], {x, -Pi, Pi}],
{a, -1, 1},
FrameLabel -> Dynamic @ TraditionalForm @ Style[y == a Sin[x], 14]]


Your question isn't clear about how you actually expected the label to look so perhaps what you really want is this;

Manipulate[
Plot[a Sin[x], {x, -Pi, Pi}],
{a, -1, 1},
FrameLabel -> TraditionalForm @ Style[y == "a" Sin[x], 14]]


If you require the internal localized variable name to be delocalized programatically, then it can be done by

SetAttributes[delocalize, HoldFirst]
delocalize[symbl_Symbol] :=
First @ StringSplit[SymbolName[Unevaluated @ symbl], "\$"]

Manipulate[
Plot[a Sin[x], {x, -Pi, Pi}],
{a, -1, 1},
FrameLabel -> TraditionalForm @ Style[y == delocalize[a] Sin[x], 14]]