1
$\begingroup$

Good evening,

I am interested in creating a Notebook with specific instructions in an automatic fashion using, say, Python. For example, I would like to generate the file NewNote.nb (a genuine Mathematica Notebook, and not merely a .nb file) with the instruction

Print[2+2]

so that, after running my Python program, I could open NewNote.nb as I open a regular Notebook, and run it as a regular Notebook, thus getting the output 4, as expected. I do not want to run the Notebook in an automated way: all I want is to create it in such automated way.

The problem I am facing, however, is that a Mathematica Notebook has lots of internal cache informations; and if I generate a .nb file without them, it will not work as a genuine Mathematica Notebook.

Any ideas?

Thanks in advance

$\endgroup$

closed as off-topic by Szabolcs, MarcoB, Kuba Mar 4 at 22:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "The question is out of scope for this site. The answer to this question requires either advice from Wolfram support or the services of a professional consultant." – MarcoB, Kuba
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ It is not true because this notebook will work: Export[ "test.nb", "Notebook[{Cell[BoxData[\"Print[2+2]\"], \"Input\"]}]", "Text" ] even though no cache was added. Now, how to do this in Python is off topic here. $\endgroup$ – Kuba Mar 4 at 22:12
  • 2
    $\begingroup$ "a Mathematica Notebook has lots of internal cache informations; and if I generate a .nb file without them, it will not work as a genuine Mathematica Notebook." This is absolutely not true. When notebooks are generated this way (as expressions), a cache is never created. $\endgroup$ – Szabolcs Mar 4 at 22:15
  • $\begingroup$ Hi, thanks for the replies. But the reason I specifically used the word 'genuine Notebook' was to make clear that the kinds of Notebooks you are talking about are not the kind of Notebooks I am interested in. You are right: the Notebooks you are talinkg about (the ones without cache) work. That is, you can run them, and obtain the desired output. However, if after running them, you now decide to save them, and then open them a second time, they will look awful. And this precisely because they are not recognized by Mathematica as genuine Notebooks, but as mere .nb files. $\endgroup$ – Duarte Mar 5 at 9:27
  • $\begingroup$ @Duarte What you say is simply not true. The cache is not needed. If your notebook does not work, that has nothing to do with the cache not being present. If you don't understand why your notebook does not work, then post a minimal broken example notebook and we will let you know what's wrong with it. $\endgroup$ – Szabolcs Mar 5 at 11:06
  • $\begingroup$ Again I disagree! You are right: the cache is not needed for you to run the notebook. True. But now try and save this notebook, after you runned it. It will look a mess!, with things like "Out[1]=..." and "During evaluation of In[1]:= " etc. $\endgroup$ – Duarte Mar 5 at 11:21

Browse other questions tagged or ask your own question.