Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can a notebook be saved without including the front end version?

If you open a .nb file, you'll see something like

FrontEndVersion -> "9.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (November 20, 2012)"

close to the end of the Notebook expression. I would like to simply not have this option.

Use case: Mathematica will issue a warning when opening a notebook that was created in a newer version (for example when using version 8 to open a notebook created in version 9). This applies to palettes as well. When distributing a palette (such as the SE image uploader) to people with both version 8 and version 9, I need to make sure that the palette doesn't have FrontEndVersion that indicates version 9, otherwise people with v8 get a warning. I would like to keep the flexibility to generate the palette in v9 though, and just test with v8 occasionally.

My current options are either editing out the version info manually from the .nb or generating the palette only with v8.

share|improve this question
Isn't there an option to switch this message off? Possibly "InsufficientVersionWarning" ? – Mike Honeychurch Dec 18 '12 at 20:45
Maybe there is, but I don't want to switch it off for all people who install the palette. Anyway, until I find a good solution that I fully trust, I'll keep using 8 to generate the palette. – Szabolcs Dec 18 '12 at 20:55
This is a very good question. By the way: I installed the latest palette on MMA8 and it worked very well, even with GraphicsGrid. – magma Dec 19 '12 at 9:28

Start by saving the notebook the usual way. In the following examples I'll save it to "/tmp/test.nb".

Direct approach Read in the notebook as text and change $Version into something suitable:

rawnb = Import["/tmp/test.nb", {"Text", "String"}];
    $Version -> "1996 \[LongDash] Microsoft FrontPage 97 (version 2)"],
  {"Text", "String"}];

This has the advantage that you can fool it into thinking it's made with whatever version you want, for instance make it into "8.0 for Linux x86 (64-bit) (October 10, 2011)" even when saving from v9

Limitations: If you actually want your version string in the notebook somewhere this will replace that too.

Roundabout half-working approach

Open a new notebook and run the following:

nb = NotebookGet[NotebookOpen["/tmp/test.nb"]];
Put[DeleteCases[nb, FrontEndVersion -> _], "/tmp/test.nb"]

It will give a warning about file being modified, ignore that or save to a different file, close "test.nb" without saving.

This has some limitations, for starters it just removes everything looking like FrontEndVersion->_ and doesn't care if it's not in the metadata, and it doesn't work with all notebooks.

It could be improved by making it a palette that does everything automatically.

share|improve this answer
I tried something like this, but it usually breaks the notebook. The reason is that the InputForm of e.g. a RowBox looks like this: RowBox[{"1", "+", "1"}] --> \(1+1\). The front end won't parse this in a .nb. – Szabolcs Dec 18 '12 at 17:00
@Szabolcs I was just playing around with Notebook* looking functions, I'll dig some more – ssch Dec 18 '12 at 17:01
Wait ... maybe I was wrong and Put behaves differently than other export functions. – Szabolcs Dec 18 '12 at 17:02
Yes, unfortunately it does break more complex notebooks ... try e.g. with the image uploader palette. – Szabolcs Dec 18 '12 at 17:07
@ssch: I think you could make the text replacement somewhat more robust by using e.g. StartOfLine ~~ "FrontEndVersion" ~~ WhitespaceCharacter ... ~~ "->" ~~ WhitespaceCharacter ... ~~ "\"" ~~ $Version ~~ "\"" ~~ WhitespaceCharacter ... ~~ "," ~~ WhitespaceCharacter ... ~~ EndOfLine -> "" , where you could of course replace this with another version option, too... – Albert Retey Dec 18 '12 at 18:28

Exporting the notebook-expression as the FullForm string seems to solve at least some of the problems that saving the InputForm has. Of course FullForm is quite verbose and it will also uncompress Graphics as Szabolcs has mentioned. For the purpose of supplying palette files in a version independent way this might still be good enough. Here is an example of how to do it:

filename = ToFileName[{$HomeDirectory, "Desktop"}, "tst.nb"]
nb = CreateDocument[{Button["Test", Print["hallo"]], Defer[1 + 1]}];
nbexpr = DeleteCases[NotebookGet[nb], 
   Verbatim[Rule][FrontEndVersion, _]];
  ToString[FullForm[nbexpr], PageWidth -> 78], {"Text", "String"}];

It probably is worth noting that a notebookfile generated like this won't open in Player Pro or the free CDF player as it misses the correct cache information. What is somewhat surprising is that when only the version string is changed slightly (it must be at least the same length), we can achieve to create notebooks which will open with older versions of both Mathematica and Player Pro and even can at least be looked at with the CDF Player. Create a notebook:

nb = CreateDocument[{a + b, Defer[1 + 1]}];
NotebookSave[nb, filename];

and string-manipulate it:

Export[filename, StringReplace[
  Import[filename, {"Text", "String"}],
  StartOfLine ~~ "FrontEndVersion->\"" ~~ $Version ~~ "\"," -> 
       "FrontEndVersion->\"6.0" <> StringTake[$Version, {4, -1}] <> "\","
  ], {"Text", "String"}]

open it with older versions of Mathematica, Player Pro or CDF-Player. None of the versions I tried seems to have a problem with a version 6.0 built in November 2012 :-). I don't know exactly why and when this works, it might well be a bug and change in future versions.

share|improve this answer
Why not tell people to do SetOptions[$FrontEndSession, MessageOptions -> {"InsufficientVersionWarning" -> False}] before opening the palette? – Rolf Mertig Dec 19 '12 at 0:02
@RolfMertig: presumably because it is more effort and more confusing than telling them to klick OK in the dialog that pops up? I think the goal is to provide a palette that just works and does not need any of those extra actions from users... – Albert Retey Dec 19 '12 at 14:07
Right. Since I don't really like the default setting anyway I like to put this into an installer. E.g. : Import@("http:" <> "//") will do SetOptions[$FrontEnd, MessageOptions-> {"InsufficientVersionWarning" ->False}] – Rolf Mertig Dec 19 '12 at 20:26
@RolfMertig: while it doesn't exactly answer the original question your idea to provide an installer is of course a good alternative solution to the underlying problem. Why don't you provide it as an answer? – Albert Retey Dec 19 '12 at 21:00
Well yes, exactly, it is not an answer to the question. I made a comment here… and I am working on a more general Mathematica installer package right now anyway. You can see an early (not yet really nice, but working) example (one installer calls another one with progress indicators) mentioned here: – Rolf Mertig Dec 19 '12 at 21:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.