### Acceptably Nonterrible Revision Control for Mathematica

#### by Danielle Fong

I discovered today, to my amazement and horror, that the otherwise exceptionally advanced and useful Mathematica 7 has only a single level of undo in its notebooks. And no redo.

Furthermore, the lone autosave feature, hidden deep, is triggered upon every cell evaluation. Every time you evaluate something in a notebook, it will save the file – overwriting the last version.

I spent an hour looking to see what was the matter. I was convinced that it must be my own obtuseness causing me not the find or see or properly use the actual undo function there present. Instead, I found several newgroup threads in which people exclaim their amazement that such vital features as multiple undo and revision control hadn’t made it in, and apologists of various employ, Wolframites and others, who wrote back about the academic difficulty inherent in making multi-level notebook undos for notebooks fed with dynamic data.

I’ve got news for you Wolfram Research. *It doesn’t matter.* What people care about is their input data. What people don’t want about is destroyed work – the product of their labor, channeled through from their mind and out through their fingers, typed into little, nicely formatted cells. Almost everything else can be reconstructed from that input. The cases in which the inability of a simple multilevel undo to capture changes in dynamic data could possibly destroy work make up a fraction of a percent. Catastrophic hard disk failure is more likely.

I checked for a while to see if anyone found a solution more advanced than to manually save often, and use standard revision control. I couldn’t find anything.

Thus, I present my complete hack of a solution. It seems to work acceptably well — as in, I think I can rely on it to save my work, most of the time, if it really came down to it. But use at your own risk:

1. Get Dropbox. (getdropbox.com) This is a file sharing and revision control system that’s built right into the operating system, Windows, Mac OS X, Linux. One creates a folder, shares it over Dropbox, and every file in it is mirrored, automatically, on their servers. In particular, they keep track of revisions: so far as I can tell, every saved file is queued to be uploaded.

2. Enable Autosave. One can set this for the current notebook by evaluating the following line: `SetOptions[SelectedNotebook[], NotebookAutoSave -> True].`

This setting persists across saves.

3. Now every time one evaluates a cell, the notebook is saved. Further, while the file is apparently overwritten locally, the revision history (which I believe is, in most cases in full,) has been uploaded to Dropbox, or queued by the client.

4. To recover a revision, one can check the revision history in the Dropbox web interface.

5. Standard diff facilities are less useful, because the notebook files are highly structured. However, there’s a structured diff built into Mathematica, Notebook Diff in the AuthorTools package. One loads the package by evaluating `<< AuthorTools``

. One can run this command `NotebookDiff[nb1,nb2]`

, where nb1 and nb2 are either notebook objects or their filenames with full paths.

This seems to work well enough for now. In the meantime, Wolfram Research, get your act together! You are driving people crazy.

I am also putting together a way to use the Units` package throughout (much more of) Mathematica, in particular, in conditionals and numerical functions. In practical engineering it could often be said that converting units is one’s primary occupation. For this reason the units package came to me with extreme promise. Built into the algebra package as it was, it could be used, in an extremely simple way, to check dimensional and unit consistency. However, it is not natively compatible with numerical functions: one cannot plot expressions including units, or expect results from comparison operators, and they can’t be used with functions like Max and Abs, or within the solver for numerical differential equations. It would be so wonderful if it could. I think I’ve figured out a way forward there, but we’ll see. The basic idea is to set to 1 all base units in a particular unit system — SI or CGS. This is likely to work for mechanics, however due to the differences in how the CGS and SI systems define electromagnetic quantities, making it work well for electromechanics is either a subtle project, or a doomed one. [Edit: David Park’s ExtendUnits package appears to do exactly this. It’s $30, though. http://home.comcast.net/~djmpark/UnitsPage.html%5D

Also, I don’t know if anyone’s really following this, but we’re not working on vehicles specifically anymore; LightSail is directing itself towards energy storage as a first product. Our website is woefully out of date. Vehicles or vehicle systems may be a further product and direction of ours, but by focusing on energy storage we can really prove out the core technology without the additional hassles of becoming an automotive company.

You’re absolutely correct, multi-level undo in Mathematica is long overdue. On the other hand, I’ve been a Mathematica user for 13 years and there’s only been a handful of times when I would have actually used multi-level undo in Mathematica if it were there. I’m a little curious what you’re usage patterns are that rely so heavily on this feature…

I find it more useful to keep most every input I evaluate. When I want to make minor changes I do so in place. For larger changes I use Command-L (Copy Input from Above) to duplicate the input then modify it as necessary.

My usage pattern so far is to author a rather involved computational model, with descriptive text and mathematics interspersed between in the form of a scientific paper. In essence, I use it as a programming language and word editor. In both, undo is practically a necessity.

hey Rob, while I was looking for a solution, I’ve found this :))

http://undo-for-mathematica.alaifari.com/

This seems to be one of those issues where WRI is out of touch with its users — from threads it seems that undo has not been implemented because they are still working out how to roll back the state of the kernel…hopefully upcoming version 7 has some kind of compromise

Thank you, this is very helpful. Has the situation changed between the time this essay was written and v8?

Not to my knowledge, except for the use of wolfram workbench, which avoids some of this problem but eliminates the notebook interface, unfortunately.

you all should take a look here, maybe it is will change something with the UNDO in mathematica

http://undo-for-mathematica.alaifari.com/

This is really terrible. We only want undo for the text we enter, I don’t care about the kernel state. (read e.g. http://forums.wolfram.com/mathgroup/archive/2009/Mar/msg00985.html ). I guess you could also fake an undo with git and running an external command “git commit” right after the autosave/every time a cell is evaluated.This might be more reliable than hoping for Dropbox to save your file before you change it again.

[…] an important code snippet, it is pretty much gone forever. A really cool workaround I found here involves storing all of my Mathematica notebooks in a Dropbox folder that has automatic versioning […]