Re: how to write output to another notebook?
- To: mathgroup at smc.vnet.net
- Subject: [mg27844] Re: how to write output to another notebook?
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Mon, 19 Mar 2001 17:51:23 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Murray, > That is, if in one notebook I have an input cell with a certain > expression and evaluate that input cell, then I want the corresponding > output cell written to the notebook nb -- no matter what that output > cell might happen to contain. Here is an attempt: the basic idea is ues a setting or $Pre write to nb the input cell together with code to - delete the written cell after evaluation, - correct the value of $Line, - put the input line after the generated cells. You may need some adjustments for your particular use. A clean variant might be be to evaluate as above in an invisible auxiliary notebook, auxnb, copy the contents of auxnb to nb, and then delete the contents of auxnb. nb1= InputNotebook[]; nb2 = NotebookCreate[]; SetAttributes[pr, HoldAll]; Module[{AA, BB}, pr[x_] := If[EvaluationNotebook[]=== nb1, NotebookWrite[nb2, Cell["", CellOpen ->False, CellTags -> BB ], Before]; NotebookWrite[nb2, Cell[BoxData[ MakeBoxes[ NotebookFind[nb2,ToString[AA],All,CellTags]; NotebookDelete[nb2]; NotebookFind[nb2,ToString[BB],All,CellTags]; SelectionMove[nb2, All,Cell] ; NotebookDelete[nb2]; x ] ], "Input", CellOpen->False, CellTags\[Rule]AA ], All ]; SelectionMove[nb2,All,CellContents]; $Line=$Line-1; SelectionEvaluateCreateCell[nb2], x ] ]; $Pre:= pr Test: ( the following may raise a warning panel becaues of the evaluation of 1/0 --- nothing to do with the functioning of the above code) {a^b+2 +3, Print[123], 1/0,Plot[x,{x,0,1}], StylePrint["cell text"]} Also, select Plot[x, {x,0,1}] and evaluate it in place. To remove this definition of $Pre use $Pre =. -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Murray Eisenberg" <murraye at mediaone.net> wrote in message news:3AB3CF7A.2B3BD3E9 at mediaone.net... > I guess I didn't make myself sufficiently clear. It is NOT a question > of writing the Cell expression for some particular result, but rather > writing -- "automatically" the result of an ARBITRARY evaluated > expression to another notebook. > > That is, if in one notebook I have an input cell with a certain > expression and evaluate that input cell, then I want the corresponding > output cell written to the notebook nb -- no matter what that output > cell might happen to contain. > > I do NOT know the form of the output cell ahead of time -- because I do > NOT know the result of evaluating the expression. > > I need to do this in an "automated" way, under program control. > > > Allan Hayes wrote: > > > > Murray, > > > > nb = NotebookCreate[]; > > > > NotebookWrite[nb, > > Cell[BoxData[ > > ToBoxes[{1,2}+{3,4}], "Output"] > > ] > > ] > > > > -- > > Allan > > --------------------- > > Allan Hayes > > Mathematica Training and Consulting > > Leicester UK > > www.haystack.demon.co.uk > > hay at haystack.demon.co.uk > > Voice: +44 (0)116 271 4198 > > Fax: +44 (0)870 164 0565 > > > > "Murray Eisenberg" <murray at math.umass.edu> wrote in message > > news:98vi9q$91l at smc.vnet.net... > > > How (in Mathematica 4.1) can I cause evaluation of an input cell in one > > > notebook to put the resulting Output cell in another, open notebook? > > > > > > I know about the function NotebookWrite, but I need to cause it to write > > > the Cell[...., "Output"] expression resulting from evaluating an > > > arbitrary Input cell. > > > > > > For something VERY simple, I could "fake" it, e.g., to write the result > > > of 1 + 2 to the open notebook corresponding to a notebook object nb, I > > > would use: > > > > > > NotebookWrite[nb, 1 + 2] > > > > > > But to write the output cell corresponding to, say, > > > > > > {1, 2} + {3, 4} > > > > > > I CANNOT use merely NotebookWrite[nb, {1, 2} + {3, 4}]. Rather, I need > > > to construct "manually" the entire output cell expression: > > > > > > NotebookWrite[nb, Cell[BoxData[ > > > RowBox[{"{", > > > RowBox[{"4", ",", "6"}], "}"}]], "Output", > > > CellLabel->"Out[12]="]] > > > > > > The difficulty is that I do not know ahead of time what the output will > > > be for a given input, so I need Mathematica to create the appropriate > > > Cell expression that I may then use as the argument to NotebookWrite. > > > > > > How can I do that? > > > > > -- > Murray Eisenberg murray at math.umass.edu > Mathematics & Statistics Dept. phone 413 549-1020 (H) > Univ. of Massachusetts 413 545-2859 (W) > Amherst, MA 01003-4515