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?
1 Answer
$\begingroup$
$\endgroup$
12
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.
-
$\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$ Commented 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$ Commented May 14, 2014 at 0:13
-
$\begingroup$ @RicoPicone, something like
SetOptions[EvaluationNotebook[], NotebookEventActions -> {{"MenuCommand", "Save"} :> FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}];
? $\endgroup$– kglrCommented 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$ Commented 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$ Commented May 14, 2014 at 14:24
NotebookFind[ SelectedNotebook[], "Output", All, CellStyle]; NotebookDelete[ SelectedNotebook[]]
$\endgroup$