3

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.

faysou
  • 10,999
  • 3
  • 50
  • 125

1 Answers1

3

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]
Rolf Mertig
  • 17,172
  • 1
  • 45
  • 76
  • Thanks, this would be perfect if the grouped cells were closed, as the ExpressionCell typically contains big outputs in what I want to do. – faysou Feb 05 '13 at 14:44
  • I found it, FrontEndExecute[FrontEndToken["OpenCloseGroup"]]; before SelectionMove – faysou Feb 05 '13 at 14:48
  • Fyi I have incorporated your answer in my answer here http://mathematica.stackexchange.com/q/15134/66 – faysou Feb 05 '13 at 15:06