Here is a simple (and useless) Manipulate example :
Manipulate[a*a*a,{a, {{1, 1}, {2, 2}, {3, 3}}}, ControlType -> PopupMenu]
Now, I want the control a to be labelled "Ha! Ha! Ha!".
The documented way to do it is to replace the control a by the triple {a, initialvalue, "label"}
so that for instance the following will work :
Manipulate[a*a*a,{{a, {1, 1}, "Ha! Ha! Ha!"}, {{1, 1}, {2, 2}, {3, 3}}},
ControlType -> PopupMenu]
The point is that I want to give a label, but I do not want, in general, to have to provide an initial value (I am happy with the default initial value, which seems to be the first element of the list that follows the control name). Although initial values and labels are unrelated concepts, I could not find anything in the documentation that allows the user to give a label without having to give an initial value.
If one just removes the initial value, say replacing the 3 element list {a,{1,1},"Ha! Ha! Ha!"}
by the 2 element list {a,"Ha! Ha! Ha!"}
, one does not get the expected result because Mathematica interprets "Ha! Ha! Ha!"
as an initial value, not as a label.
Trying to replace the initial value by Null
, None
, or Nothing
, will also fail.
However I found, experimentally, that repeating the name of the control works: in other words I replaced Manipulate[expr,{u,list]}
by Manipulate[expr,{{u,u,"uname"},list}]
.
For instance Manipulate[a*a*a,{{a, a, "Ha! Ha! Ha!"}, {{1, 1}, {2, 2}, {3, 3}}}, ControlType -> PopupMenu]
indeed gives me what I want.
However, this feature is not documented, and I am afraid that the trick could fail with a more complicated example (or in a later version of Mathematica). Am I missing something obvious ? Any idea ?
{{a, a,..},...}
initializesa
toa
(beforea
gets any value). This is, I think, implied in the docs. I used it here to initial a symbolz
to itself to prevent it being given the default initialization value0
, so thatz
could be used to construct a function in theInitialization
option. I usually do this when I want a function symbol to be localized byManpulate
. $\endgroup$