Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Please imagine a simple loop:


We can ask Print[] to output $(1,2,3,4,...)$ to a different notebook (in the context of the same kernel)?

share|improve this question
You could look up NotebookWrite. – Yves Klett Sep 23 '13 at 9:27
@YvesKlett Sorry, should have found that. – RM1618 Sep 23 '13 at 9:28
Not to worry - perhaps someone can help with Print as well. – Yves Klett Sep 23 '13 at 9:29
Possible duplicates / related: (1041), (5040), (7081), (10456), (22584), (29235) – Mr.Wizard Sep 23 '13 at 9:52
Also this: (just change MessagesNotebook[] to your desired notebook. – R. M. Sep 23 '13 at 13:58
up vote 11 down vote accepted

As Yves already mentioned, you can easily create and edit notebooks through Mathematica commands. A start would be this tutorial, which you can find in the Documentation Center under tutorial/ManipulatingNotebooksFromTheKernel

Here is a short example printing the i values into a new notebook:

nb = CreateDocument[];

For[i = 1, i <= 10, i++,
 SelectionMove[nb, Next, Cell];
  Cell[BoxData@RowBox[{"i is now ", ToString[i]}], "Output"]];

If you want to know how to construct cell expressions, you could just go over any cell in a notebook and hit Ctrl+Shift+E to see the underlying structure.

share|improve this answer

Although the question has been answered, no reason for this question was given. One possible motivation is to be able to discard a lot of diagnostic output, e.g. from an iterative process, by trashing the newly created notebook.

In such a case an alternative could be Dynamic[.], e.g.

For[i = 1, i <= 10, i++,
    iter = "i is now " <> ToString[i]
share|improve this answer
Thanks for your answer - my reason for asking was that I was interested in printing multiple plots or outputs at different speeds while running a computation. It became cumbersome to have everything moving around in the same notebook. – RM1618 Sep 23 '13 at 23:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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