Message Boards Message Boards

To construct a pasting button

I want to write a function, highlight --- select --- it, and then have a button which plots this function. I have tried

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

but it does not do the work.

Any idea ?

POSTED BY: Cyrille Piatecki
2 Replies

Thanks I think it was not a trivial question

POSTED BY: Cyrille Piatecki

For readers information, cross posted and answered on Mathematica.SE:

How to paste an equation to a graphics

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},...].

enter image description here

POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract