Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I've created a notebook for use in an in-class presentation. There is a fair amount of MMA code, and my students know nothing about MMA nor do they need to. I don't want to distract them with the code. I understand how to collapse the input cells and show only the output, but the input cells expand whenever I evaluate the notebook so I'm back to where I started.

This notebook is meant to be interactive, so it has to be evaluated whenever I change the input. In this case, I have an InputField that requests a ticker symbol and then the code uses FinancialData to get the data and from that creates the results.

I've tried creating a slideshow, but that has the same behavior. I've looked at the resources and answer in "Best way to give presentations with Mathematica" without finding any mention of this issue.

So, in MMA 8.04 is there any way to force the input cells to stay hidden after the notebook is evaluated? Surely, there must be an option for this somewhere.

share|improve this question
    
How are you collapsing the input cells? In my version of Mathematica if I close an input cell (by delecting Cell > Cell Properties > Open) the cell stays closed during and after evaluation. –  Heike Jan 25 '12 at 20:43
    
@Heike clearly the problem is we are missing the delecting key. ;-) –  Mr.Wizard Jan 25 '12 at 20:46
    
@Mr.Wizard maybe it will be introduced in version 9 –  Heike Jan 25 '12 at 20:52
    
@Heike, that was exactly the problem. I wasn't aware of that command. Thanks. –  Tim Mayes Jan 25 '12 at 21:28
    
@NasserM.Abbasi, thanks for the pointer. Glad to know that I'm not alone. –  Tim Mayes Jan 25 '12 at 21:39

3 Answers 3

up vote 18 down vote accepted

Please try this code, based on Sasha's adaption of my own answer to this question.

AutoCollapse[] := (
  If[$FrontEnd =!= $Failed, 
   SelectionMove[EvaluationNotebook[], All, GeneratedCell];
   FrontEndTokenExecute["SelectionCloseUnselectedCells"]])

Then in a new cell:

2 + 2
AutoCollapse[]

Always place AutoCollapse[] as the last line of an Input cell.


I may be reading more into your question than is there. As Heike points you can close the input cells manually by deselecting menu Cell > Cell Properties > Open but I assumed you knew this already and provided the soluition(?) above. If all you need is a hidden cell that generates output, use the menu. If you need something a little more flexible that automatically hides after you make your changes, I hope you will find AutoCollapse useful.

share|improve this answer
    
Oooh, that seems to work great! The only problem, easily fixable, is that it changes the background color of my output to transparent (or at least to the background color of the stylesheet - I'm using Creative NaturalColor). I can fix this by explicitly specifying Background -> White for my charts. Thanks! –  Tim Mayes Jan 25 '12 at 20:54
    
@Tim I used Print which is a bit hacking, and that is probably what causes the difference. For my own curiosity I would like to know whether AutoCollapse or Cell > Cell Properties > Open is closer to the intention of your question. –  Mr.Wizard Jan 25 '12 at 21:00
1  
@Tim I am glad you have a solution. If in the future you need AutoCollapse I think that is working well now too. –  Mr.Wizard Jan 25 '12 at 21:27
1  
@Jacob I copied that directly from Sasha's code. I believe it is simply to keep the AutoCollapse core code from running when it is evaluated outside of a Notebook interface, for example if you saved the Notebook as a Package. –  Mr.Wizard Jan 20 at 0:15
1  
@ThomasFankhauser I tried this with OSX 10.9.3 and MMA10 and it works, so the problem could be local to your computer. –  Pickett Jul 19 at 10:22

This might be a good time to use Dynamic objects that will update as required with controls, buttons, or UpdateInterval, leaving direct evaluation of cells for outside of class.

share|improve this answer
    
That would be a good idea, except that I don't need frequent evaluation. I just need to evaluate at the beginning of the lecture so that we have up-to-date data (and maybe a couple of other times to show that the results aren't a fluke). Of course, I could give up on the fresh data and go with slightly stale data so that I don't need to evaluate at all. –  Tim Mayes Jan 25 '12 at 20:34

You could alt-click an output bracket which will cause all output brackets to be selected and then ctrl-} to close all subgroups, which, in this case, will close all input brackets that had output.

Alternatively, you could select all outputs in this way and check the menu item Cell>Grouping Close All Unselected

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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