2
$\begingroup$

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.

$\endgroup$
0

2 Answers 2

2
$\begingroup$

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"]]]
$\endgroup$
2
  • 1
    $\begingroup$ Why not "\n" instead of "\[NewLine]"? $\endgroup$
    – Öskå
    May 15, 2014 at 13:55
  • $\begingroup$ @Öskå I don't know ;P probably old habit. Good point ;) $\endgroup$
    – Kuba
    May 15, 2014 at 13:56
0
$\begingroup$

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]
   }]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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