It seems the vim front end is too old. I'm wondering if it is
worthwhile to install it.
http://library.wolfram.com/infocenter/MathSource/2584/
Anyway, I'm trying to use vim to edit mathematica file. But it seems
the .nb files are full of something like
Notebook[{
Cell[BoxData[
RowBox[{
These things are not readable in the text mode. I'm wondering how to
get rid of these things. How does people usually do when editing
mathematica files with vim?
Thanks,
Peng
--David
... and they are not ment to be...
> How does people usually do when editing
> mathematica files with vim?
editing "mathematica files" with any text editor is usually done with
files in mathematica package format, that is ASCII files that contain
mathematica InputForm. Notebook files are not really ment to be edited
with something else than the mathematica frontend and are not ment to be
human readable although you can actually do both...
> I'm wondering how to get rid of these things.
you don't. What you can do is to make all the cells in a notebook to be
InitializationCells (Cell -> Properties -> InitializationCell). When you
then save the file, you will be asked whether you want to automatically
create a package file. If you answer yes, a file with extension .m will
be created which you then can edit with vim, if you want. Still there
will be some unfriendly formatting, e.g. a greek alpha will look like
this: \[Alpha]. So if you really want to do this, you better get rid of
anything that's non-ASCII...
On the other hand I would really recommend to reflect what the pros and
cons are to write mathematica code with an ASCII editor. It is an
absolutley underrated advantage to be able to write formulas in a
mathematical notation to avoid typos. I have just by accident found an
error in a formula in years old code by just pasting it into the front
end: someone interchanged a ^ for a *, which is something you hardly see
in a multi-line ASCII-art formula, but will immediatly see in
StandardForm in a notebook.
hth,
albert
Obviously, notebook (.nb) files are meant to be viewed and edited with
the Mathematica front end, and not with a text editor. "Those things"
are what make up a notebook file, you cannot "get rid of them". Of
course you can view an .nb file with Vim (they are structured plain text
files, and not binary), but that is like viewing a HTML page with a text
editor instead of a browser.
You can type Mathematica expressions into a text file, and then load and
evaluate them with Get[]. This is how packages work.
For interactive work, just use the Mathematica front end.
Note that you can copy information from notebooks to .m files.
David Bailey
http://www.dbaileyconsultancy.co.uk
You should realize that Mathematica notebook files are much more
complicated than what you see when looking at them with Mathematica's
front end user interface. You normally do not see all the low-level
code, but if you do a "Cell/Show Expression" menu command for any
highlighted cell(s) you will see the low level code that actually
makes up the cell as you see it. You can also see it if you edit the
file with any text editor, but you need to be very careful editing
this low level code and don't ever try to edit a file with vim/vi that
Mathematica has open.
It is very easy to break this low level code and very prone to making
errors unless you are VERY careful. All the commands you see in vim/vi
or any text editor can be looked up in Mathematica's Help window if
you are curious. In general I have found it not worthwhile editing the
low level code, but occasionally this code has gotten corrupted and
the only recourse was to edit it in vim/vi and attempt to fix it - but
only as a last resort.
-Bob