26
$\begingroup$

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?

$\endgroup$
10
  • 2
    $\begingroup$ Nice idea, seems totally doable $\endgroup$
    – Rojo
    Jul 25, 2012 at 2:05
  • $\begingroup$ You could automate conversion of all images to bitmap. $\endgroup$ Jul 25, 2012 at 2:43
  • $\begingroup$ 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. $\endgroup$ Jul 25, 2012 at 3:05
  • 5
    $\begingroup$ Top Menu: Cell >> Delete All output - saves a lot of space for notebooks with a lot of graphics. $\endgroup$ Jul 25, 2012 at 3:20
  • $\begingroup$ In addition to @VitaliyKaurov: programmatically delete certain cells (here Output): NotebookFind[ SelectedNotebook[], "Output", All, CellStyle]; NotebookDelete[ SelectedNotebook[]] $\endgroup$
    – Yves Klett
    Jul 25, 2012 at 6:43

1 Answer 1

12
$\begingroup$

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

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

or

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

To delete all generated cells in the notebook, evaluate

FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]

or

FrontEndTokenExecute["DeleteGeneratedCells"]

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.

$\endgroup$
12
  • $\begingroup$ 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? $\endgroup$ May 14, 2014 at 0:08
  • $\begingroup$ 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. $\endgroup$ May 14, 2014 at 0:13
  • $\begingroup$ @RicoPicone, something like SetOptions[EvaluationNotebook[], NotebookEventActions -> {{"MenuCommand", "Save"} :> FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}];? $\endgroup$
    – kglr
    May 14, 2014 at 7:47
  • $\begingroup$ 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. $\endgroup$ May 14, 2014 at 14:22
  • $\begingroup$ Should I make this a new question? It's so related to this question that I feared it would be marked a duplicate. $\endgroup$ May 14, 2014 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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