The ultimate substance of all matter is the atom, likewise,
the ultimate substance of mathematica cell is the cell expression,
and it can be obtained easily.

enter image description here

After copying the cell expression, and paste it then we see following popup :

enter image description here

Here, if I click yes, a cell with the cell expression(=copied a minute ago) is created.
(If click no, a cell of plain texts(=copied a minute ago) is created)

In fact the plain text of the cell expression is

Cell[BoxData[blahblah], ...]

And executing the following code is almost equivalent to pasting the copied cell exression and clicking yes.


What I want to say is from now on. It is almost equivalent, but not 100% equivalent.

For example, I experienced that

the copied cell expression for a certain cell with a certain image was

Cell[BoxData[GraphicsBox[blahblah, ... ,  BaseStyle -> "ImageGraphics" , ...]],...]

For this cell(=a certain cell with a certain image), let's first try copy cell expression and paste method.
Then I get 100% the same cell. In other words, the cell is duplicated exactly.

Now let's try ToExpression[BoxData[.. method. Execute

 ToExpression[BoxData[GraphicsBox[blahblah, ... ,  BaseStyle -> "ImageGraphics" , ...]]]

then the output cell created isn't the same as the original cell. To be specific, one of the option part

 BaseStyle -> "ImageGraphics"

is changed to

 DefaultBasicStyle -> "ImageGraphics"

The change isn't small.
Because if that part is changed, the image size (the size we see by eyes) doesn't vary according to notebook magnification.
(If you would like to know more about this issue please refer to the following link :
Creating a size changing image in output cell)

ToExpression generally works well but not in 100% manner.
Copy cell expression and paste method is 100% method but difficult to implement in code and cumbersome even if implemented.

Can we create a function, that works 100% exactly like copy cell expression and paste method?





It will be a revolution at least for me.

  • $\begingroup$ Checking ClipboardNotebook and NotebookWrite may be helpful. $\endgroup$
    – rnotlnglgq
    Apr 5, 2023 at 7:53
  • $\begingroup$ Thank you, At present, I can set the cell expression (the plain text string) of any cell that I want as a variable, say var1, with some codes. In that respect, I think the role of ClipboardNotebook is almost over at that stage. $\endgroup$
    – imida k
    Apr 5, 2023 at 10:02
  • $\begingroup$ I should find a way to way to create a cell with the exact cell expression. Hope NotebookWrite can do it but after seeing examples the tutorial of NotebookWrite, NotebookWrite doesn't seem to have ability to create a cell with given cell expression. $\endgroup$
    – imida k
    Apr 5, 2023 at 10:11
  • 1
    $\begingroup$ "[T]he ultimate substance ... is the cell expression"?? Not hardly. Hint: cells are meaningless in mathkernel. What's common across the program is the expression; that's the base unit. $\endgroup$ Apr 5, 2023 at 20:54
  • $\begingroup$ I think there is an ultimate aspect in that I can make/decorate output whatever I want (complex table, grid, very complex nested matrix with nest fractions..). $\endgroup$
    – imida k
    Apr 6, 2023 at 20:46

1 Answer 1


You can use CellPrint together with NotebookRead.

For example, the following code will reproduce the first cell from the notebook:

  • $\begingroup$ Wow, it worked! CellPrint is ultimate in some sense! Better then ToExpression. $\endgroup$
    – imida k
    Apr 5, 2023 at 13:40

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.