Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Here is something more general:

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

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

    ExpressionCell[Defer[a = 1;], "Input", StripOnInput -> True],
   ToBoxes@ExpressionCell[Defer[b = 3;], "Input", StripOnInput -> True]
share|improve this answer

Your Answer


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.