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.

In developing a notebook, I often find I have created a very boated file that takes a long time to save. I would like to slim it down. It is usually the result of graphics and images, but they may be hidden deep in the hierarchy of the notebook. Finding the wasted space is a pain. A very useful tool would be something that graphically indicated (perhaps in the cell marker) the number of bytes (or similar) that are within a cell. Anyone know of such a thing, or have a pointer on how to create?

share|improve this question
Nice idea, seems totally doable –  Rojo Jul 25 '12 at 2:05
You could automate conversion of all images to bitmap. –  Mike Honeychurch Jul 25 '12 at 2:43
I asked WRI if it's possible to toggle the front end to display graphic output and the output of ancillary (exploratory) code in a separate notebook on a per-cell basis, but the reply I got didn't sound promising. –  alancalvitti Jul 25 '12 at 3:05
Top Menu: Cell >> Delete All output - saves a lot of space for notebooks with a lot of graphics. –  Vitaliy Kaurov Jul 25 '12 at 3:20
In addition to @VitaliyKaurov: programmatically delete certain cells (here Output): NotebookFind[ SelectedNotebook[], "Output", All, CellStyle]; NotebookDelete[ SelectedNotebook[]] –  Yves Klett Jul 25 '12 at 6:43

1 Answer 1

Maybe, displaying the bytecount of every output expression in tooltips or status area:

$Post = Tooltip[#, ByteCount[#]] &


$Post = StatusArea[#, ByteCount[#]] &

To delete all generated cells in the notebook, evaluate




To delete all generated cells upon closing a notebook, you can use

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

inside the notebook.

Or, you can select Selected Notebook or Global Preferences in the Options Inspector and add

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

to the NotebookEventActions line.

share|improve this answer
kguler, this piqued my curiosity. This may be a good way for me to avoid my earlier problem (mathematica.stackexchange.com/q/47805/9150). But I'd prefer never to save the output cells, even when I save without closing the notebook. I couldn't find an event like SaveNotebook with which I could adopt this solution. Any ideas? –  Rico Picone May 14 '14 at 0:08
Note that it wouldn't be useful if the output cells disappeared from the notebook every time it was saved. What I'm proposing is making the output cells more ephemeral, sort-of like a kernel. –  Rico Picone May 14 '14 at 0:13
@RicoPicone, something like SetOptions[EvaluationNotebook[], NotebookEventActions -> {{"MenuCommand", "Save"} :> FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}];? –  kglr May 14 '14 at 7:47
Yes, that works to delete the output cells on save (thanks), but, as I feared, it deletes them from the immediate view of the notebook. I'd prefer it if the output remained in the immediate view of the notebook even when it was saved and its output cells deleted in the saved version. I realize this might be very hard to do. I want a "working copy" that saves (sans output) to the "disk copy," but without losing the output in the "working copy." This is probably pretty easy if the "working copy" is a different file than the "disk copy," but I don't know how to do it if its the same file. –  Rico Picone May 14 '14 at 14:22
Should I make this a new question? It's so related to this question that I feared it would be marked a duplicate. –  Rico Picone May 14 '14 at 14:24

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.