I have a complex notebook with one cell that contains a bunch of initial definitions, several modules, and finally a Manipulate object. For a simple example take

(* Some initial definitions *)
a = 2;
(* Some modules *)
f[x_] = Module[{}, x + 1];
(* Output of Manipulate *)
show[] = Module[{}, Manipulate[f[x], {x, 1, 10}]];

I can evaluate this cell and call show[] to display the Manipulate object. However, I would like to give this program to someone who

  • has a functioning installation of Mathematica on their computer
  • does not have the slightest clue how to use Mathematica,

hence I would like to give them a file (.nb or other, if necessary accompanied by further files) such that they

  1. Click on said file to open it in Mathematica
  2. after which the initialization code in the first cell gets evaluated automatically and
  3. the Manipulate object with the slider and output is shown to them, whereas
  4. they do not see any of the code.

I thought that this must be a pretty common and straightforward problem, but after two hours of googling without a satisfying result I would like to ask:

What is the easiest way to achieve this with Mathematica? Or if its not entirely possible, how can I get closest to such a standalone type of notebook?

Can I, for example, outsource all code into an external file and run it automatically when opening the notebook file?

  • 1
    $\begingroup$ I've done it for class, but perhaps for smaller apps than yours. I've used SaveDefinitions -> True and Initialization :> (long code). I've also used local variables to store data: {{problems, {"Prob 1", "Prob 2",...}, ControlType -> None}. These get initialized when the DynamicModule is instantiated. I haven't initialized from an external file/package. I'd think it would be possible unless there's a time constraint that is exceeded. The Demonstrations Project consists of all Manipulate apps with no code. $\endgroup$
    – Michael E2
    Aug 20 '21 at 14:25
  • 1
    $\begingroup$ In addition to the above, I would then double-click on the cell bracket around the manipulate only, and then it will hid the code. I’ve done this for a number of files that I have sent to students. $\endgroup$
    – MassDefect
    Aug 20 '21 at 20:44
  • $\begingroup$ Thanks for the ideas. What I did in the end was to put almost all of the code into a separate file. Then added an initialization cell which loads the external code and displays the Manipulate item, minimize that initialization cell, and insert a big button which starts the evaluation of the initialization cell. This is working quite well for my purpose. $\endgroup$
    – André
    Sep 8 '21 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.