Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2009

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

Search the Archive

Re: Bug of NotebookRead

  • To: mathgroup at
  • Subject: [mg100187] Re: Bug of NotebookRead
  • From: dbreiss at
  • Date: Wed, 27 May 2009 04:09:12 -0400 (EDT)
  • References: <gvdr93$757$>

Yes, I came across this back in Version 6 and reported it to the
WOlfram bugs system.  Following is is the note that I sent them.  In
my experience I have come across this problem only rarely.  But I did
encounter it when working on which
makes use of lots and lots of tagging.  I think that the workaround
that I may have use for the particular case that I had was to use

FrontEndExecute[FrontEndToken[notebookObject, "Copy"]]

rather than NotebookRead.  Then I paste the result in an invisible
notebook using (after creating a notebook  InvisibleNotebooksObject
that has the optoin Visible->False)

FrontEndExecute[FrontEndToken[InvisibleNotebooksObject, "Paste"]]

And then I select all cells in that notebook and do a NotebookRead on
them  (then close the invisible notebook.

In[1]:= $Version

Out[1]= "6.0 for Mac OS X x86 (32-bit) (June 19, 2007)"

NotebookRead sometimes does not read its selection

Create the following notebook:

nb = NotebookPut[
     CellGroupData[{Cell["Subsubsection", "Subsubsection"],
       Cell["item 1", "Item"], Cell["item 2", "Item"],
       Cell["item 3", "Item"]}, Open]]}]]

In this notebook select the "Subsubsection" cell and the "item 2"
cell. (Exclude
the "item 1" cell and the "item3" cell.)

Then in a second notebook execute


The following corrupted CellGroupData expression results.  Note that
the second
cell apears as a second argument to the CellGroupData rather than as
part of an
element in the list that is the first argument to CellGroupData.

Cell[CellGroupData[{Cell["Subsubsection", "Subsubsection"]},
  Cell["item 2", "Item"]]]

Now select the "Subsubsection" cell,  the "item 2" cell, and  the
"item 3" cell
(exclude the "item 1" cell)

Then in a second notebook execute NotebookRead[nb].

This is the result.


Cell[CellGroupData[{Cell["Subsubsection", "Subsubsection"]},
  Cell["item 2", "Item"]]]

Note that the CellGroupData is corrupted as above and that the third
("item 3")
cell does not appear in the expression at all.


On May 25, 6:18 am, Hannes Kessler <HannesKess... at> wrote:
> Hello,
> cell tags could be very useful to extract quickly selected information
> from notebooks, see David Reiss presentation
> But be aware of the following bug of NotebookRead applied to tagged
> cells in a structured notebook with sections and subsections:
> The section cell and the input / output cells in the example are
> tagged, but not the subsection cell. The resulting notebook contains
> only the section cell. The tagged input/ouput cells are lost as a
> consequence of the read notebook data containing a wrong CellGroupData
> [[{Cell[..]},Cell[..]] instead of a correct CellGroupData[[{Cell
> [..],Cell[..]}]. This could be fixed by a corresponding replacement
> rule. But the second input/output cell is missing completely and
> cannot be recovered at all.
> notebook1 = Notebook[{
>     Cell["Section 1", "Section", CellTags -> "zzz"],
>     Cell["Subsection 1 (no tag)", "Subsection"],
>     Cell[BoxData[RowBox[{"x", "=", "1"}]], "Input", CellTags ->
> "zzz"],
>     Cell[BoxData["1"], "Output", CellTags -> "zzz"],
>     Cell[BoxData[RowBox[{"y", "=", "2"}]], "Input", CellTags ->
> "zzz"],
>     Cell[BoxData["2"], "Output", CellTags -> "zzz"]
>     }];
> notebookObject = NotebookPut[notebook1, WindowTitle -> "Notebook 1"];
> NotebookFind[notebookObject, "zzz", All, CellTags];
> notebookData = NotebookRead[notebookObject]
> notebook2 = Notebook[Flatten[{notebookData}]];
> NotebookPut[notebook2, WindowTitle -> "Notebook 2"];
> Did anybody encounter this problem, are there workarounds? I am new to
> the tagging approach and a bit frustrated as this was my very first
> experience with it.
> I am using Mathematica 7.0.1 on Windows XP
> Best regards,
> Hannes Kessler

  • Prev by Date: Re: calculations in findRoot
  • Next by Date: Numbering
  • Previous by thread: Re: Bug of NotebookRead
  • Next by thread: How to handle Units of Measure