The table below provides the information needed to formulate my question: how can I gather a selected number of tagged output cells and variables in a new notebook?

enter image description here

I have two notebooks nb1 and nb2. These notebooks have tagged input cells uniquely named such as tc11 and tc21 in nb1; similarly, tc41 and tc53 in nb2. In the 3rd column of the table, I give two sample lists of the output cells that I want to gather in a new Notebook (newNB). For example, {tc11, tc46} and {tc31, tc53, tc46} are the lists that I like to bring into newNB.

In nb1 and nb2, I also have variables to be brought into newNB. Examples of variable lists include {var11, var22} and {var21, var12}.

I like to have a Mathematica function such as:

gatherF[lstNB_, lstOUT_, lstVAR_]:=

with three arguments: list of notebooks (lstNB), list of tagged output cells (lstOUT), and list of variables (lstVAR).

Note that tagged output cells inherit tagged input cells, meaning that input and output cells have the same name. I only want the tagged output cells, not input cells.

  • $\begingroup$ What do you mean by "variables to be brought into newNB"? $\endgroup$
    – Kuba
    Commented Dec 11, 2019 at 9:11
  • $\begingroup$ @Kuba: A variable is a calculation done in a notebook, such as x=y+3 where I call x as a variable. In my real case, a tagged cell includes a Manipulate[...] and I want to get the output from the Manipulate. Whereas a variable is defined out of the Manipulate. $\endgroup$ Commented Dec 11, 2019 at 12:12
  • $\begingroup$ @Kuba: My explanation of a variable is not complete. I do not want to get the value assigned to x but I want x variable to be active in the new notebook so that I can use it in other calculations. $\endgroup$ Commented Dec 11, 2019 at 12:26

1 Answer 1


Let me know if it fits your needs:

notebooks = {(*__NotebookObject*)};
tags = {(*__String*)};
styles = {"Output"};

notebooks //
  Map[Cells[#, CellStyle -> styles, CellTags -> tags] &] //
  Flatten //
  Map[NotebookRead] //
  • $\begingroup$ I run your code with an example. There is no error nor warnings. The only output I get is a NotebookObject[...]. Does this NotebookObject include the outputs I am after?` If so, how can I open this NotebookObject? Thank you very much for the code. $\endgroup$ Commented Dec 11, 2019 at 12:21
  • $\begingroup$ @Tugrul The point notebook object should correspond to a newly created notebook window. Did it not appear? What is your os and mma version? $\endgroup$
    – Kuba
    Commented Dec 12, 2019 at 7:31
  • $\begingroup$ No, there was no window open. My OS is Windows and MMA version 11.3 $\endgroup$ Commented Dec 12, 2019 at 17:08
  • $\begingroup$ @TugrulTemel That is weird, does this create a window for you: CreateDocument[]? $\endgroup$
    – Kuba
    Commented Dec 13, 2019 at 7:16
  • $\begingroup$ Yes, it creates a window including only Print[...], which is something I like to print. But this window is just showing that CreateDocument[...] has worked, however, I do not see any printout result. $\endgroup$ Commented Dec 13, 2019 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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