How to paste an equation to a graphics
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}]]]
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},...]
.