I am trying to produce a table of sections with each section containing a DynamicModule. My two questions are: (1) How do I produce grouped sections that are folded shut? (2) How do I stop the text in my DynamicModule from having quotes around it?

Here is a toy code for the dynamic module

f[a_] := DynamicModule[{x = 0.5}, 
  "Plot " <> ToString[a], 
   Plot[Sin[a x t], {t, 0, 2 \[Pi]}, AxesLabel -> {"x", "y"}]

I now do a table to produce the sections

CellPrint[TextCell["Section " <> ToString[i], "Subsection"]];
{i, 3}];

The output is open cells and extra quotes around the strings. How do I CellPrint folded cells and get rid of the extra quotes"?

Mathematica graphics

  • $\begingroup$ What do you mean by are folded shut? $\endgroup$
    – Kuba
    May 21 '15 at 11:46
  • $\begingroup$ @Kuba When you double click on the right bracket you open and shut the cells. I call this folding to avoid a clash with the option CellOpen $\endgroup$
    – Hugh
    May 21 '15 at 12:11
  • $\begingroup$ @Kuba Thank you for solving my question 2. How about solving my question 1? I will certainly accept it if you can do this? $\endgroup$
    – Hugh
    May 21 '15 at 13:20
  • $\begingroup$ Sorry for delay. I think the answer should fit your needs now. $\endgroup$
    – Kuba
    May 22 '15 at 6:32

You can use CellGroupData with 1 as the second argument for creation of cell groups where only first cell is open:

   Cell@CellGroupData[{Cell["Section " <> ToString[i], "Subsection"], 
      Cell[ToBoxes@ExpressionCell@f[i], "Output"]}, 1]], {i, 3}];


The quotes around the text are not shown because I have specified the "Output" style for the cells containing DynamicModule (this style sets ShowStringCharacters->False option for Cell).

  • $\begingroup$ I had not seen CellGroupData before. Thanks for this. $\endgroup$
    – Hugh
    May 22 '15 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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