9
$\begingroup$

The Mathematica documentation says in Introduction to Dynamic under "Dynamic and Other Functions":

Manipulate in fact produces a combination of Dynamic, controls, and formatting constructs, not fundamentally different from what you can do yourself using these lower-level functions.

And in Advanced Dynamic Functionality under "Nested Dynamics" it says:

the output of Manipulate consists of a highly complex set of interrelated and nested Dynamic expressions

From other places (e.g. the documentation for Panel under "Properties & Relations" states "The Manipulate construct uses Panel"), I gather that

Manipulate[x + y, {x, 0, 9, 1}, {y, 0, 90, 10}]

works and looks a bit like

DynamicModule[{x, y},
 Panel[Column[{
    Grid[{{"x", Manipulator[Dynamic[x], {0, 9, 1}]},
      {"y", Manipulator[Dynamic[y], {0, 90, 10}]}
      }],
    Pane[
     Framed[Style[Dynamic[x + y], "Output"], FrameMargins -> 15, 
      Background -> White, FrameStyle -> LightGray]]
    }]
  ]
 ]
  • What code gets really generated for a Manipulate expression?
  • Where (in the documentation, or elsewhere) can I find that?
  • Can I somehow see or obtain the code generated for a specific Manipulate inside Mathematica?
$\endgroup$
2
  • $\begingroup$ maybe Trace[Manipulate[{}, {a, 0, 1}]] // Column? $\endgroup$
    – kglr
    Jul 10, 2021 at 22:23
  • $\begingroup$ I’m also curious about this. $\endgroup$
    – B flat
    Jul 10, 2021 at 23:54

1 Answer 1

7
$\begingroup$

It's a very broad question (too many controls, options, etc.), but one can find out what the output is equivalent to like this:

Manipulate[x + y, {x, 0, 9, 1}, {y, 0, 90, 10}] //
    MakeBoxes[#, StandardForm] & // First //
  ToExpression // InputForm

(*
DynamicModule[{
  x = 0, y = 0,
  Typeset`show = True,
  Typeset`bookmarkList = {},
  Typeset`bookmarkMode = "Menu",
  Typeset`animator,
  Typeset`animvar = 1,
  Typeset`name = "\"untitled\"",
  Typeset`specs = {{Hold[x], 0, 9, 1}, {Hold[y], 0, 90, 10}},
  Typeset`size = Automatic,
  Typeset`update = 0,
  Typeset`initDone = False,
  Typeset`skipInitDone = True},
 Dynamic[
  RawBoxes[
   Manipulate`ManipulateBoxes[1, StandardForm,
    "Variables" :> {x = 0, y = 0},
    "ControllerVariables" :> {}, 
    "OtherVariables" :> {Typeset`show, Typeset`bookmarkList, 
      Typeset`bookmarkMode, Typeset`animator, Typeset`animvar, 
      Typeset`name, Typeset`specs, Typeset`size, Typeset`update, 
      Typeset`initDone, Typeset`skipInitDone},
    "Body" :> x + y,
    "Specifications" :> {{x, 0, 9, 1}, {y, 0, 90, 10}},
    "Options" :> {},
    "DefaultOptions" :> {}]
   ],
  SingleEvaluation -> True],
 DynamicModuleValues :> {},
 Deinitialization :> None,
 UntrackedVariables :> {Typeset`size},
 SynchronousInitialization -> True,
 UnsavedVariables :> {Typeset`initDone}, 
 UndoTrackedVariables :> {Typeset`show, Typeset`bookmarkMode}]
*)

You can then execute the

Manipulate`ManipulateBoxes[ ...] // ToExpression // InputForm

which is held by Dynamic to see what gets created dynamically (it's long) when the Manipulate is running.

But there's a whole 'nother process for instantiating a DynamicModule in the FrontEnd that creates a unique module with unique DynamicModule variables. (When you copy/paste the output of Manipulate, you basically copy/paste the structure above. When the output form of it appears in the Front End, the instantiation process is invoked and you get an interactive Manipulate applet.

The "Tutorials" menu on the documentation page of Manipulate has links to the four introductory/advanced tutorials on Dynamic and Manipulate, which is the principal documentation. They are more of a user's manual than a complete technical documentation, however.

$\endgroup$

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.