I can edit a notebook within the mathematica front end and then Save As
a .m
file, which produces output like this:
(* ::Package:: *)
(* ::Section::Closed:: *)
(*Preliminaries*)
(* ::Input:: *)
(*ClearAll["Global`*"]*)
(* ::Text:: *)
(*Some text here.*)
(* ::Input:: *)
(*u[d_,v_]:=v-t d;*)
(*Solve[u[x,v1]==u[1-x,v2],x][[1]];*)
(*x/.%;*)
(*x[v1_,v2_]=%;*)
The same thing is a .nb
file looks like this:
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 9.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 157, 7]
NotebookDataLength[ 1786, 74]
NotebookOptionsPosition[ 1395, 55]
NotebookOutlinePosition[ 1750, 71]
CellTagsIndexPosition[ 1707, 68]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[CellGroupData[{
Cell["Preliminaries", "Section"],
Cell[BoxData[
RowBox[{"ClearAll", "[", "\"\<Global`*\>\"", "]"}]], "Input"],
Cell["Some text here.", "Text"],
Cell[BoxData[{
RowBox[{
RowBox[{
RowBox[{"u", "[",
RowBox[{"d_", ",", "v_"}], "]"}], ":=",
RowBox[{"v", "-",
RowBox[{"t", " ", "d"}]}]}], ";"}], "\n",
RowBox[{
RowBox[{
RowBox[{"Solve", "[",
RowBox[{
RowBox[{
RowBox[{"u", "[",
RowBox[{"x", ",", "v1"}], "]"}], "==",
RowBox[{"u", "[",
RowBox[{
RowBox[{"1", "-", "x"}], ",", "v2"}], "]"}]}], ",", "x"}], "]"}], "[",
RowBox[{"[", "1", "]"}], "]"}], ";"}], "\n",
RowBox[{
RowBox[{"x", "/.", "%"}], ";"}], "\n",
RowBox[{
RowBox[{
RowBox[{"x", "[",
RowBox[{"v1_", ",", "v2_"}], "]"}], "=", "%"}], ";"}]}], "Input"]
}, Closed]]
},
WindowSize->{740, 840},
WindowMargins->{{4, Automatic}, {Automatic, 4}},
FrontEndVersion->"9.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (November 20, \
2012)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[579, 22, 32, 0, 80, "Section"],
Cell[614, 24, 76, 1, 22, "Input"],
Cell[693, 27, 31, 0, 30, "Text"],
Cell[727, 29, 652, 23, 80, "Input"]
}, Closed]]
}
]
*)
(* End of internal cache information *)
Whilst the fact that everything in the .m
file gets put inside of a comment seems kind of odd, this format has the significant advantage that the result is a readable and editable plain text file. Moreover, I can load the .m
file back into the mathematica front end and interact with it as normal. This also leaves all of my formatted section headings etc. as they would be in the .nb
file.
This leads me to ask: what are the advantages to saving in the proprietary .nb
format when one can store code and formatted text in a human readable .m
file that also works interactively within the Mathematica front end?