# Delete output cell content but not the space assigned

I'm writing a slide show in Mathematica, and so have Input and Output cells. I want to hide the Output cells until they are generated, but with leaving the space there. Else when I evaluate each cell the ones below jump around.

If I delete the text inside the Output cell it is no longer connected to the Input cell above. Is this possible?

• Somewhat related: (680) – Mr.Wizard Feb 17 '17 at 7:27
• That's useful to read, thanks @Mr.Wizard. – KraZug Feb 17 '17 at 10:37

One possibility is to have a function create a toggler that resets to the invisible state when the notebook is closed. Here is a function that does this:

hideOnClose /: MakeBoxes[hideOnClose[expr_], fmt:StandardForm] := Module[{i=1},
TemplateBox[
{MakeBoxes[expr,fmt]},
"Hide",
DisplayFunction -> (TogglerBox[
Dynamic[i],
{1 -> PaneBox[#, ImageSize->Scaled[1]], 2->""},
DynamicBox[ToBoxes[i], Deinitialization:>(i=2)],
ImageSize->All, Alignment->Center]
&),
InterpretationFunction->(#&)
]
]


The simplest way to implement this is to use:

$PrePrint = hideOnClose  Using $PrePrint means that you can refer to Out and the hideOnClose wrapper won't cause trouble. As an example, suppose you evaluate:

Graphics[{Red,Circle[]}]
$PrePrint =. 2+2  After closing the notebook, and reopening, you will see: Graphics[{Red,Circle[]}]$PrePrint =.
2+2


The red circle has disappeared, but the 2+2 output has not because I unset the $PrePrint first. One might consider using a custom style in a style sheet instead, eg., "HideInput" with a CellProlog and CellEpilog that sets and unsets $PrePrint. Then, use "HideInput" for cells you want to hide.

• Thank you, that looks like it does exactly what I want. I'll leave it another day to see if anyone else answers. – KraZug Feb 15 '17 at 9:16