# Copy and Paste: what is copied to the clipboard?

Copy and Paste is so familiar and works so well that I never wondered what is really happening. My simple idea is that when I select something in the notebook and press [ControlKey]C, then my selection is placed on the on the clipboard. Then, when I go to another position in my notebook and press [ControlKey]V, the contents of the clipboard, i.e. what I selected, is placed at that position in the notebook.

What exactly is placed on the clipboard? I know we have a menu for that, Copy As, but I am considering the straightforward Copy. Since everything in the notebook is typesetted in boxes, I expect that it will be some or other box structure, similar to cell expressions, or a string.

Evaluate:

DynamicModule[{x}, Dynamic[x]]


The output looks like FE'x$$37, but in fact is a DynamicModule. I select the output cell and copy it. Then I paste it into a text editor, e.g. Notepad++, and I see \!$$DynamicBox[ToBoxes[CellContextx, StandardForm], ImageSizeCache->{88., {2., 15.}}]$$  That is more or less as expected. Almost identical: DynamicModule[{x}, x]  It shows x$$, but just as before, it is a DynamicModule. When I copy the output cell and paste it into Notepad++, I see only

x$$ Nevertheless, when I paste it into the notebook, I find a DynamicModule. Even stronger, when I start a fresh Mathematica session and paste the clipboard into a new notebook, the result is a cell containing the DynamicModule as above. So the clipboard contains enough information that Mathematica can construct the DynamicModule, but Notepad++ (and Ditto) are unable to show the complete information from the clipboard. Is there a way to see what exactly Mathematica has placed on the clipboard? It is not important at all, I am just curious. • NotebookGet[FrontEndClipboardNotebook[]]? – kglr Jun 19 '18 at 10:20 • On some operating systems (definitely on Windows) the clipboard can hold data in multiple formats at the same time. I do not know if this is what happens in Mathematica, but it could work like this: when you copy a Graphics, it may be copied in vector format (EMF), as a bitmap, as a Mathematica expression (i.e. text) simultaneously. As I remember, MS Word on Windows even has a special Paste command that allows choosing the format to paste. – Szabolcs Jun 19 '18 at 10:20 • Normally, what gets pasted depends on what application you are pasting into, and what formats that application can handle. E.g. when copying rich text, the plain text version would get pasted into Notepad, but the rich text version into WordPad. Here's a screenshot of the 6 different formats Mathematica seems to produce on OS X when copying a graph: i.stack.imgur.com/YoS5M.png They seem to come in pairs, so only 3 are distinct: a Cell expression, a bitmap in TIFF format, and vector graphics in PDF format. On Windows, this might be different. – Szabolcs Jun 19 '18 at 10:24 • Even on OS X, if I copy a different symbolic expression, e.g. 1+x^2, I see a different collection of formats on the clipboard: a Cell expression, MathML and plain text in 3 different character encodings. – Szabolcs Jun 19 '18 at 10:27 ## 1 Answer This answer is specifically for the Windows platform, but should be similar in other OS as well. Whenever you copy something to the clipboard the OS attempts to save it to a temporary cache in as many formats as possible. Then when you paste it, the program chooses which format is most appropriate. In your question you mentioned pasting into Mathematica sessions as well as a text editor. If you had tried posting it into an graphics program, you would have seen FE'x$$37as an image. You can see this functionality easily in Word where it allows you to select the paste format.

In older versions of Windows, there was something called Clipboard Viewer. It doesn't come standard since XP, but you can download it and it works fine. The program gives you a sneak peak at what is in your clipboard. If you use the View menu, it shows you all the formats available. If the program can show it nativity, it will, otherwise it shows the type of data included but the option is greyed out.

As per your question, I am attaching a screenshot of all the formats your particular result in Mathematica puts into the clipboard for the output FE'x$$37: I did some testing and confirmed that depending on the nature of the object, Mathematica puts different formats in the clipboard. You can download the clipboard viewer and explore some more if you are interested. • Your answer came in when I was already studying the clear comments of @Szabolcs. Thanks to both of you. I was not aware of a clipboard viewer in Windows, so I found it highly interesting to see the one in OS X. Moreover, it was completely new to me that when you copy something to the clipboard, it could be stored in more than one format. That explains quite well that in my x$$ example, there must be at least two formats and when pasting into a text editor, only the text format is used. That answers my question. – Fred Simons Jun 19 '18 at 12:59
• I also looked at three clipboard viewers for Windows. The original Windows Clipboard Viewer mentioned by Ben shows the format Mathematica Cells, but it is grayed out and indeed does not work. I also found InsideClipboard and Free Clipboard Viewer. Both show the Mathematica Cells format correctly, but with a Plot result in the clipboard, InsideClipboard was unable to show the picture, Clipboard Viewer showed the picture in in the format Picture (inclusive the cell label) and Free Clipboard Viewer in the format RTF (without the cell label). – Fred Simons Jun 19 '18 at 13:04
• It really is impressive that so much is going on in the background with just a few simple key strokes that we use all the time. Amazing that programs can output so many formats and then other programs can (usually) correctly choose how to bring the info back in. I ended up playing around with a few other programs (Word, Paintshop, Audacity) and it is cool to see all the formats they automatically cache. – kickert Jun 19 '18 at 13:22
• I used ClipView (peterbuettner.de/develop/tools/clipview) when developing a solution for mathematica.stackexchange.com/questions/158117/… – Gustavo Delfino Jun 19 '18 at 14:23