4

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?

SPPearce
  • 5,653
  • 2
  • 18
  • 40

1 Answers1

4

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

enter image description here

After closing the notebook, and reopening, you will see:

Graphics[{Red,Circle[]}]
$PrePrint =.
2+2

enter image description here

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.

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
  • Thank you, that looks like it does exactly what I want. I'll leave it another day to see if anyone else answers. – SPPearce Feb 15 '17 at 09:16