From: Paul Howland on
Hello.

I am dynamically creating a notebook from another notebook.

I would like to be able to display a formatted table in the
dynamically created notebook (e.g. equivalent of
Print[TableForm[...]]]). Ideally, I would like to be able to direct
the output of the Print[] statement to the new notebook, rather than
the one that is executing the code.

However, SetSelectedNotebook[] doesn't appear to do this.

Using NotebookWrite does allow me to write to the new notebook, but
requires low-level manipulation of Boxes, etc. It doesn't seem able
to take higher level formatting commands and direct these to the
notebook.

Is it possible to do something like NotebookWrite[nb, TableForm[...]]
or to somehow re-direct normal Print output to the new notebook? I'm
getting lost in GridBoxes, etc at the moment and there must be a
simpler way!

Many thanks for your help!

Paul

From: Albert Retey on
Am 27.04.2010 10:05, schrieb Paul Howland:
> Hello.
>
> I am dynamically creating a notebook from another notebook.
>
> I would like to be able to display a formatted table in the
> dynamically created notebook (e.g. equivalent of
> Print[TableForm[...]]]). Ideally, I would like to be able to direct
> the output of the Print[] statement to the new notebook, rather than
> the one that is executing the code.
>
> However, SetSelectedNotebook[] doesn't appear to do this.
>
> Using NotebookWrite does allow me to write to the new notebook, but
> requires low-level manipulation of Boxes, etc. It doesn't seem able
> to take higher level formatting commands and direct these to the
> notebook.
>
> Is it possible to do something like NotebookWrite[nb, TableForm[...]]
> or to somehow re-direct normal Print output to the new notebook? I'm
> getting lost in GridBoxes, etc at the moment and there must be a
> simpler way!

If you use ToBoxes and define something like this:

printtonb[nb_, expr_] := (
SelectionMove[nb, After, Cell];
NotebookWrite[nb, Cell[BoxData[ToBoxes[expr]], "Print"]]
)

the printtonb will behave a lot like a Print redirected to the other
notebook:

nb = CreateDocument[];
printtonb[nb, TableForm[RandomReal[{0, 1}, {3, 3}]]]
printtonb[nb, TableForm[RandomReal[{0, 1}, {3, 3}]]]

you might also want to consider "Output" as CellStyle instead of "Print"...

hth,

albert

From: Paul Howland on
Perfect - thank you Albert.