(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.)