8
$\begingroup$

I have to close many cells each time before I export a notebook to HTML since I do not want to display many code cells and other cells.

I select each cell one by one, and do cell->cell properties->open to uncheck it, so it closes. Then I export to html. Then I have to go reverse the whole process one by one again. I do this many times during the day.

I am getting tired of doing this. I know in V9 there is now a cell API so I am sure there is a way to program this where one will add each cell into some cell group, and then issue a command to open or close all cells.

But, is there a way, from the notebook UI, a way to say to Mathematica: please select all closed cells. Then when they are selected, I can go use the UI to change the property of all selected cells at once using the cell->... as above. (I still have to select the cells again one by one when I want to close them again, but at least I can reduce the amount of work by half).

Actually, ideally what I'd like to do, is say: Export all cells except the Input and Code cells. i.e. selective Export by types of cells. That will be the most flexible way. i.e. there should be an export wizard, where one can select type of cells to export. So one can check in/off classes of cells in notebook, then click export. Default will be to export all cells.

thank you

$\endgroup$
2
  • $\begingroup$ the short answer to all of this is yes. It is probably going to be easier in 9 but I don't have it yet. For the final part of your question just use NotebookGet to get the notebook expression and then DeleteCases with a pattern something like Cell[_,"Input"|"Code",___]. I'm about finished for tonight but if the question is still open tomorrow I will try a full answer. $\endgroup$ Nov 30, 2012 at 9:08
  • 1
    $\begingroup$ This answer might probably help: mathematica.stackexchange.com/a/14470/5 $\endgroup$
    – rm -rf
    Nov 30, 2012 at 14:41

1 Answer 1

5
$\begingroup$

The link that @rm -rf provides does most of what you have asked for. For the final part of your question

Actually, ideally what I'd like to do, is say: Export all cells except the Input and Code cells. i.e. selective Export by types of cells.

Evaluate this code -- which you can modify for your particular circumstances -- in your notebook.

tmp = NotebookGet[EvaluationNotebook[]];
tmp = DeleteCases[tmp, Cell[_, "Input" | "Code", ___], \[Infinity]];
NotebookSave[tmp, "noimport.nb"]

Before:

enter image description here

After:

enter image description here

You will probably have to tweek it for your particular circumstances but that is the simple base code.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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