Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can I print grouped cells with CellPrint ?

The closest thing I have to what I want to do is this

CellPrint[CellGroup[{TextCell["i","Item"],ExpressionCell[Defer[x^2;],"Input"]},1]]

But the cells aren't grouped.

share|improve this question

2 Answers

Not pretty, but it works:

      CellPrint[
  CellGroup[{TextCell["i", "Item", CellTags -> "groupit"], 
    ExpressionCell[Defer[x^2;], "Input", CellTags -> "groupit"]}, 1]];
NotebookFind[EvaluationNotebook[], "groupit", All, CellTags];
FrontEndExecute[FrontEndToken["CellGroup"]];
SelectionMove[EvaluationNotebook[], After, Cell]
share|improve this answer
Thanks, this would be perfect if the grouped cells were closed, as the ExpressionCell typically contains big outputs in what I want to do. – Faysal Aberkane Feb 5 at 14:44
I found it, FrontEndExecute[FrontEndToken["OpenCloseGroup"]]; before SelectionMove – Faysal Aberkane Feb 5 at 14:48
Fyi I have incorporated your answer in my answer here mathematica.stackexchange.com/q/15134/66 – Faysal Aberkane Feb 5 at 15:06

Documentation of CellGrouping under "possible issues", says that the automatic grouping of a document overrides your cell grouping - at least in v8. If you try

CreateDocument[
 CellGroup[{TextCell["i","Item"],ExpressionCell[Defer[x^2;],"Input"]},1]
,CellGrouping -> Manual]

the new document will have the cells grouped (but I don't know if that's what you are after or if changing the CellGrouping of a notebook from the notebook itself is possible).

share|improve this answer
No I want to print grouped cells in the same notebook as the evaluated cell – Faysal Aberkane Feb 5 at 14:33

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.