Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6949165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:55:06+00:00 2026-05-27T13:55:06+00:00

I am using Leonid’s macro method ( see here ) to help me manage

  • 0

I am using Leonid’s macro method (see here) to help me manage the control variables layout of Manipulate.

But I found that from within a macro, I am not able to use another macro defined elsewhere. So I am wondering if there is a way to use a macro from within another macro?

To explain the question, I will first show a very simple Manipulate using a one level macro, then I will show the problem, by trying to use a macro from within another.

Manipulate[Text["ok"],

 Evaluate@With[{

    x = Function[{},  (*----> macro x *)
      TabView[{
        "x" -> "working on x"
        }], HoldAll
      ],

    y = Function[{}, (*----> macro y *)
      TabView[{
        "y" -> "working on y"
        }], HoldAll
      ]
    },(*WITH*)

   (* now use the above macros *)
   Grid[{
     {SetterBar[Dynamic[choice], {1, 2}]},
     {Dynamic[Which[choice == 1, x[], choice == 2, y[]] ]}
     }]

   ],
 {{choice, 1}, None},
 ContentSize -> 300

 ]

enter image description here

Now add a macro for a checkbox, and then try to use it from inside the ‘x’ macro above:

Manipulate[Text[“ok”],

 Evaluate@With[{

    checkBox = Function[{}, Checkbox[Dynamic[c]], HoldAll],

    x = Function[{},
      TabView[{
        "x" -> checkBox[] (*=====> DOES NOT WORK, did not bind *)
        }], HoldAll
      ],

    y = Function[{},
      TabView[{
        "y" -> "working on y"
        }], HoldAll
      ]
    },(*WITH*)

   Grid[{
     {SetterBar[Dynamic[choice], {1, 2}]},
     {Dynamic[Which[choice == 1, x[], choice == 2, y[]] ]}
     }]

   ],
 {{choice, 1}, None},
 {{c, True}, None},
 ContentSize -> 300

 ]

We see it did not work. The ‘x’ macro did not ‘see’ the checkbox macro.

enter image description here

But if I add the code for the checkbox directly inside the ‘x’ macro, it will of course work:

Manipulate[Text["ok"],

 Evaluate@With[{

    x = Function[{},
      TabView[{
        "x" -> Checkbox[Dynamic[c]]  (* add the definition directly *)
        }], HoldAll
      ],

    y = Function[{},
      TabView[{
        "y" -> "working on y"
        }], HoldAll
      ]
    },(*WITH*)

   Grid[{
     {SetterBar[Dynamic[choice], {1, 2}]},
     {Dynamic[Which[choice == 1, x[], choice == 2, y[]] ]}
     }]

   ],
 {{choice, 1}, None},
 {{c, True}, None},
 ContentSize -> 300

 ]

enter image description here

So, the question is: Is it possible to use the checkbox macro above from inside the ‘x’ macro?

To make it is easier, I am NOT passing any arguments to the macros. I am simply using a macro as a ‘short hand’ name for a piece of larger code fragment (the control variable definition) as shown above.

This is only to make it easier for me to layout the UI by moving only the macro name around, instead of moving the larger piece of code which the macro defines. Since there is no GUI builder for Manipulate, this method helps when one has lots of controls to manage.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:55:07+00:00Added an answer on May 27, 2026 at 1:55 pm

    This is because you need a nested With in this case. You can not use the declaration of one variable in another one in the same declaration list in With. Here is the simplified version of your problem:

    In[3]:= With[{a=b,c=f[a]},g[c]]
    Out[3]= g[f[a]]
    

    This is what you need instead:

    In[5]:= 
    With[{a=b},
      With[{c=f[a]},g[c]]]
    
    Out[5]= g[f[b]]
    

    in your case, checkBox plays the role of a, and x plays the role of c.

    The topic of how to make a version of With that would allow such consecutive bindings, was discussed several times on Mathgroup and here at SO. Here is my implementation of such a construct:

    ClearAll[LetL];
    SetAttributes[LetL, HoldAll];
    LetL /: Verbatim[SetDelayed][lhs_, rhs : HoldPattern[LetL[{__}, _]]] :=
       Block[{With}, Attributes[With] = {HoldAll};
         lhs := Evaluate[rhs]];
    LetL[{}, expr_] := expr;
    LetL[{head_}, expr_] := With[{head}, expr];
    LetL[{head_, tail__}, expr_] := 
      Block[{With}, Attributes[With] = {HoldAll};
         With[{head}, Evaluate[LetL[{tail}, expr]]]];
    

    If you are willing to use it, all you have to do is to change With to LetL in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using online interfaces to a version control system is a nice way to have
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
Using the variables extension, I want to change the background color of a cell
Using a Microsoft version of SQL, here's my simple query. If I query a
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using Xcode4.2.1, with a basic PhoneGap template based app. (I say template, but I
Using the current request I can get the URL hostname with: HttpContext.Current.Request.Url.Host But -
Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
V 8.04. This is in the context of Manipulate use only. Here is a
Using ruby(1.8.7) , rails(2.3.8) , rspec(1.3.1) and rspec-rails(1.3.3) how do I test a method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.