MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Why aren't nested groups? XML again.

  • To: mathgroup at
  • Subject: [mg61745] Re: Why aren't nested groups? XML again.
  • From: albert <awnl at>
  • Date: Fri, 28 Oct 2005 03:25:23 -0400 (EDT)
  • References: <djq62m$jbg$>
  • Sender: owner-wri-mathgroup at

Hi Steven,

> With cell groupings (I have learned that there are limited ways to
> establish my own) the Mathematica notebook actually is organize
> hierarchically, but
> getting at that hierarchy, and exploiting it is non-trivial.  It seems
> potentially much cleaner and intuitive to simply reproduce the XML
> structure as cells.  Has anybody tried this sort of thing?  Can it be made
> to work without extraordinary effort?

once again I'm not sure whether or not I a) understand what exactly you want
to do, b) if I can help at all. Anyway here are my 2 cents:

within a mathematica notebook cells containing cells and the cell hierarchy
are two distinct things.

the former are called inline cells and every cell can contain other cells,
most often that is the case when you insert a formula within a Text-Cell.
This is not directly visible, but will only become clear when you look at
the cell-expression (on most systems by selecting a cell and hit
Ctrl-Shist-E). e.g.:

  "the following is an inline cell: ",
  Cell[BoxData[SubscriptBox["x", "i"]]]
}], "Text"]

on the other hand there is the cell hirarchy that you can fold/unfold by
double-clicking on the cell-brackets, probably in Mathematica language
better called cellgrouping. This is done by enclosing cells within a commen
cellgroup. The whole mechanism is obscured somewhat because with the
default-settings for Notebooks CellGrouping is set to Automatic (which you
should only change if you have a good reason). Here is how you can study
the details:

      Cell["titel", "Title"],
      Cell["section", "Section"],
      Cell["text", "Text"]

this will open a new notebook with a usual hierarchy of cells, using all
defaults (StyleSheet, CellGrouping -> Automatic ...). Note that for the
cellgrouping the expression representing the notebook is automatically
changed. You can see what the cell hirarchy would look like, if the
cellgroups would not automatically be inserted:

      Cell["titel", "Title"],
      Cell["section", "Section"],
      Cell["text", "Text"]
      }, CellGrouping -> Manual]]

finally, you can control the cell-grouping "manually" as in the following
example. note that in this case, the text cell is not hierarchically "part"
of the section because I did not put them into a commen cellgroup:

          Cell["titel", "Title"],
          Cell["section", "Section"],
          Cell["text", "Text"]
      }, CellGrouping -> Manual]]

I guess from here you can find your way to what you want to achieve. Anyway,
since you seem to look for an approach in analogy to XML documents you
might like better the idea to create a stylesheet ("dtd") with the proper
cellgrouping rules for your celltypes ("tags") and then use
CellGroup->Automatic and StyleDefinitions->(yourstylesheet) for your
notebook and let Mathematica do the cell grouping based on the rules given
in the stylesheet. For converting the notebook-expression back to XML you
will need to explicitly handle the CellGroupData-Heads anyway.


  • Prev by Date: Re: Re: Integrate vs Nintegrate for impulsive functions<> got it !!!!
  • Next by Date: Re: Re: MLPutRealList vs. sequence of MLPutDouble
  • Previous by thread: Why aren't nested groups? XML again.
  • Next by thread: MLPutRealList vs. sequence of MLPutDouble