# How to paste an equation to a graphics

I wonder why PasteButton["Plot", Plot[\[SelectionPlaceholder], {x, 0, 10}]] applied to x^2 --- highlighted --- doesn't work.

In case you want to plot in place you can use something like:

Button["Plot",
NotebookWrite[
InputNotebook[],
ToBoxes @ Plot[
Evaluate @ ToExpression @ CurrentValue @ "SelectionData",
{x, 0, 10}
]
]
]


You may want to add Method -> "Queued" for more complicated plot to avoid timeout.

And if you want x from the selection to be scoped properly, e.g. to give a plot even if x already has a value, then wrap the procedure inside the Button with Block[{x},...].

• On my computer I have the message Could not parse RowBox[{^,2}] as input. Apr 7 '16 at 8:35
• Sorry you are right! Have you a solution for the extension of the question ? Apr 7 '16 at 9:40
• To do the same thing without immediate evaluation in such a way to be abble to make modification to the plot Apr 7 '16 at 11:40
• @cyrille.piatecki isn't Algohi's answer allowing you that?
– Kuba
Apr 7 '16 at 11:48

According to the documentation, "PasteButton, evaluates its arguments in an ordinary way, so that expr is immediately evaluated"

It is like you evaluate Plot[\[SelectionPlaceholder], {x, 0, 10}] which will give empty plot.

This could be one solution:

PasteButton["Plot", Defer[Plot[\[SelectionPlaceholder], {x, 0, 10}]]]

• Perfect. And How to do tha same without evaluation --- to be able to change marginaly some parameters ? Apr 7 '16 at 8:23