# PasteButton: Pasting expression name without quotation marks?

I am struggling to find a way to use PasteButton to paste the name of an expression (in particular a list) without showing the contents of the expression or without wrapping it in quotes. For example, in this example the values of myList {1,2,3} is pasted rather than the blackened expression name myList.

myList={1,2,3}

PasteButton["Paste myList", myList]


If instead I use ToString then myList is pasted with quotation marks around it as "myList":

PasteButton["Paste myList", ToString@myList]


I simply want the expression name myList without quotes around it so I can choose to evaluate it with Shift+Enter or not. There must be something obvious I am missing. Any suggestions?

• PasteButton["Paste myList", Defer@myList] Nov 15 '15 at 20:57
• @MarcoB Thanks. Any idea how can I do this with PasteButton if I located myList by using Names["Global*"]? For example if Names["Global*"][[1]] is "myList" how can I use PasteButton to paste it as the blackened text myList and not the values of myList or the string "myList"? Nov 15 '15 at 21:03
• That seems convoluted. Perhaps you could edit your question to provide more context explaining what you ultimately want to achieve with these manipulations. Nov 15 '15 at 21:08
• @user13999 Hi, I've seen you have accepted only answer for all your questions. Aren't any of others good enough? Please, take a Tour.
– Kuba
Nov 17 '15 at 8:27
• @Kuba Ok, I accepted your answer on the pop-up workspace. Thanks for your help. Nov 18 '15 at 14:58

You could use ToExpression to convert the string to a symbol, with Defer as the third argument:

symbolname = First@Names["Globalmy*"]
(* "myList" *)

PasteButton[ToExpression[symbolname, InputForm, Defer]]

• Great, thanks for picking up on my added comment. Nov 15 '15 at 23:00

Or you can use RawBoxes:

PasteButton[ RawBoxes @ First @ Names["Global*"] ]

• Cool, never heard of RawBoxes. Thanks. Nov 15 '15 at 23:01