1

I want to know if it is possible to temporally disable a cell temporally in Mathematica.

When I evaluate a notebook, there is a certain cell that should not be evaluated. I have seen the Evaluatable option for cells, but when I apply this option on to cell, it doesn't change anything.

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
StarBucK
  • 2,164
  • 1
  • 10
  • 33

1 Answers1

2

I don't know why you are having trouble with the menu command. Please try this palette as an alternative.

Run this code to create the palette, then select the Cell you wish to disable (or simply put the cursor within it) and press the Disable Evaluation button.

CreatePalette @ 
 Button["Disable Evaluation",
   SelectionMove[SelectedNotebook[], All, Cell];
   SetOptions[NotebookSelection[SelectedNotebook[]], Evaluatable -> False]
 ]

You should see the cell bracket subtly change from the normal to disabled form:

enter image description here

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • I have two issues with this. The first is that in a notebook I usually have mixed text (as comment) and code cells. For a group of mixed content cells the evaluatable flag is off. The second is stylistic but important: the difference must be visible, it is laughable that I have to spot that pixel in the bracket to be able to see which cells I have disabled, and which I didnt... – alessandro Jul 04 '17 at 06:51
  • @alessandro (1) I don't know what you mean by mixed content cells. Comments delineated by (* *) should not affect the evaluation of cells. (2) I think it is good that no unwanted style is imposed on your cells. You can of course apply a style such as a different background color along with disabling cells, automated with palette buttons as above if desired. This is a more flexible design. Are you having trouble achieving this? – Mr.Wizard Jul 04 '17 at 11:25
  • (1) sorry for not being clear: at least for me, the need to enable/disable code regards often whole selections/parts of a notebook, and such parts usually have mixed content, i.e. include code, text cells for comments, section headings... that I'd like to disable. If you try and select any part of a notebook that doesnt contain only input cells, you'll see that Mathematica considers it as non-evaluatable. – alessandro Jul 04 '17 at 12:15
  • (2) in this I disagree strongly - I appreciate that M is flexible enough (although I'm not an expert in styles at all, and I dont know how to accomplish it...) - but in any programming environment I always expect that disabled code has a very different style from enabled code (as M comments, in fact) – alessandro Jul 04 '17 at 12:18
  • @alessandro (1) So you're saying you lack a function to toggle evaluation on only the input cells within a larger selection? Would you consider a Palette button for that action a solution? (2) Alright, I can accept that especially from the programming environment perspective. However Notebooks are also intended as documents in such a way that code and declaration are somewhat interchangeable. It makes sense for your document not to impose unwanted styles. This may be peculiar to the Notebook concept and at odds with a purely programmatic one. (continued) – Mr.Wizard Jul 04 '17 at 12:55
  • As a work-around you could create a stylesheet with a second Input style, say InputOff, that has both disabled evaluation and a different background color. You would then have to disable cells by changing their style rather than using the normal menu option. This again might be automated with a Palette button if desired. – Mr.Wizard Jul 04 '17 at 12:57
  • thank you for the help Mr.Wizard - sorry if I hijacked a bit the discussion – alessandro Jul 04 '17 at 13:31