Below is a piece of my code I have trouble with:

Clear[z1hyp, claim, μ0]
z1hyp[] := Manipulate[claim,
  Control@{{μ0, 0, 
     Control@{{claim, "=", 
        "Claim: \!\(\*SubscriptBox[\(μ\), \(0\)]\)"}, {"=", 
        "≠", "≥", "≤", "<", ">"}, 
       ControlType -> PopupMenu}}},
  {{xbar, 0, "Sample Mean, \!\(\*OverscriptBox[\(x\), \(-\)]\)"}, 
  {{σ, 1, "Population Std., σ"}, InputField},
  {{n, 10, "Sample Size, n"}, InputField},
  {{α, 0.05, "Alpha, α"}, InputField},
  LocalizeVariables -> True]

The nested Controls doesn't seem to localize the variable name claim.

In general, Manipulate[{var1, var2}, Control@{{var1, init1, Control@{{var2, init2, "lbl"}}}}] doesn't localize var2. LocalizeVariables and DynamicModule don't seem to help here.

My question is, why is this happening?


1 Answer 1


You can use Dynamic on the variable to be localized in a DynamicModule:

Clear[z1hyp, claim, \[Mu]0];
z1hyp[] := DynamicModule[{claim}, Manipulate[claim,
   {{\[Mu]0, 0,
        {claim, "=", "Claim: \!\(\*SubscriptBox[\(\[Mu]\), \(0\)]\)"},
        {"=", "\[NotEqual]", "\[GreaterEqual]", "\[LessEqual]", "<", 
        ControlType -> PopupMenu
    }, InputField},
   {{xbar, 0, "Sample Mean, \!\(\*OverscriptBox[\(x\), \(-\)]\)"}, 
   {{\[Sigma], 1, "Population Std., \[Sigma]"}, InputField},
   {{n, 10, "Sample Size, n"}, InputField},
   {{\[Alpha], 0.05, "Alpha, \[Alpha]"}, InputField}]];

{Dynamic[claim], z1hyp[]}

This happens because the Manipulate outside only localizes what you give it as firsts of its arguments, which is var1, whereas var2 appears as part of the label of var1, so it's impossible for Manipulate to know that you also want var2 to be localized. We have to explicitly localize var2.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.