1

(I use Mathematica 9.0.1 on OS X 10.10.2.)

Suppose I have a notebook in which I make some definitions and assignments.

a = 108
b[x_] := 4x + 8
c = Interpolation[{15, 16, 23, 42}]

Then it is straightforward to save these definitions to a text file:

Save["filename.txt", {a, b, c}]

produces a text file filename.txt containing

a = 4

b[x_] := 8*x

c = InterpolatingFunction[{{1, 4}}, {4, 3, 0, {4}, {4}, 0, 0, 0, 0,
          Automatic}, {{1, 2, 3, 4}}, {{15}, {16}, {23}, {42}}, {Automatic}]

But is there a way to produce exactly the above content, not in a text file, but in an ".nb" file?

(Note that the obvious first guess, just changing the extension of the filename I specify in the Save command from ".txt" to ".nb", does not seem to work. Mathematica still treats the file as a text file, rather than a notebook file, it just now has a deceptive file extension.)

thecommexokid
  • 1,335
  • 8
  • 17

1 Answers1

3
a = 108
b::usage = "test usage msg"
b[x_] := 4 x + 8
c = Interpolation[{15, 16, 23, 42}]

As pointed by OP, the direct usage of FullDefinition produces boxes that are not realy useful. I don't know how to convert them easily without this tiny undocumented function [1], [2]:

Save["test.m", {a, b, c}]

CreateDocument @ Cell[#, "Input"] &@
 First @ FrontEndExecute @ 
   UndocumentedTestFEParserPacket[Import["test.m", "Text"], False]

enter image description here


Old answer, not so handy, in edit history.

Kuba
  • 136,707
  • 13
  • 279
  • 740