4
$\begingroup$

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?

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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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