Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there a way to paste multiple expressions into notebook using PasteButton? For example, I want to do

PasteButton["Inputs", {Defer@(a=1;), Defer@(b=2;)}]

I want the expressions to be shown in multiple lines just as if we are typing them in, not as a list.

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

I'm not sure how to do this with PasteButton, here's ordinary one:

Button["Inputs", NotebookWrite[InputNotebook[], 
                 Cell[BoxData[RowBox[{MakeBoxes[a = 1;], "\n", MakeBoxes[b = 1;]}]], 
                      "Input"]]]

Here is something more general:

Button["Inputs", NotebookWrite[InputNotebook[], Cell[BoxData[
       MakeBoxes[a = 1; b = 1; c = 1; d = 1; e = 1;] /. ";" -> Sequence[";", "\n"]], 
       "Input"]]]
share|improve this answer
1  
Why not "\n" instead of "\[NewLine]"? –  Öskå May 15 at 13:55
    
@Öskå I don't know ;P probably old habit. Good point ;) –  Kuba May 15 at 13:56
add comment

Here is an approach based on Kuba's approach which allows you to use things like ExpressionCell and Defer.

Button["Inputs",
 NotebookWrite[InputNotebook[], 
   {
   ToBoxes@
    ExpressionCell[Defer[a = 1;], "Input", StripOnInput -> True],
   ToBoxes@ExpressionCell[Defer[b = 3;], "Input", StripOnInput -> True]
   }]]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.