Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is it possible to change the way Mathematica saves so that Out[] lines are never included?

I have a .nb file that processes a lot of data, and displays most of it as standard output. These graphs, tables, and intensity plots almost double the size of the file. I'd like to easily save these files in a smaller form and also prevent accidentally sending confidential results to users outside my company or not under an NDA.

That is, of course, without using Cell -> Delete All Output before each save. I can't be expected to remember to do that all the time! :-P

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

In Options Inspector you can change the EvaluationOptions for Selected Notebook or for Global Preferences by adding

  {"WindowClose" :>  FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}

to the NotebookEventActions line.

Screenshots for changing the notebook evaluation options in Options Inspector:

A notebook with Input and Output cells and the Evaluation Options page in Option Inspector

before

After editing the NotebookEventActions line in Options Inspector or evaluating

SetOptions[EvaluationNotebook[], NotebookEventActions -> {"WindowClose" :> 
 FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}]; 

inside the notebook:

after edit

After clicking X on the on the notebooks window frame:

after window close

After clicking Yes on the dialog window:

after yes

Alternative: you can add

 SetOptions[EvaluationNotebook[], NotebookEventActions -> {"WindowClose" :> 
 FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}]; 

to a notebook's initialization cell.

share|improve this answer
    
+1 This is probably a better solution than mine. It can be added at a per-notebook level while mine has to be global. Also, the final SetOptions approach is very quick to do. –  Simon Feb 23 '12 at 21:44
add comment

After making a backup of the MenuSetup.tr file, you can insert the following line somewhere in the Menu["&File"...] section:

MenuItem["Delete output and Save", FrontEndExecute[{
    FrontEndToken["DeleteGeneratedCells"], FrontEndToken["Save"]}], 
  MenuKey["X", Modifiers->{"Control", "Shift"}]],

I placed it beneath the MenuItem["&Save"...] line. You can also change the key combination to something more memorable.


To see a list of all frontend tokens go to http://stackoverflow.com/a/4209612/421225

And the following code should give the location of MenuSetup.tr on all three supported platforms

With[{os = Switch[$OperatingSystem,
    "Unix", "X",
    "MacOSX", "OSX",
    "Windows", "Windows"]}, 
 FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", 
   "TextResources", os, "MenuSetup.tr"}]]
share|improve this answer
    
Good to see you posting again, Simon. –  Mr.Wizard Feb 23 '12 at 12:53
    
@Mr.Wizard: Yeah been busy, but today I had time to procrastinate. Nice moderator diamond, btw! –  Simon Feb 23 '12 at 13:15
add comment

Your Answer

 
discard

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.