Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

How could I create two Input cells, such that when the first is evaluated, the contents of the first are copied to the second? So for example, there would be two empty cells - let's call them A and B - and when the user enters f[x_]:=x^2+4 in A, nothing happens. When that same user evaluates cell A, then the contents of cell B are updated to be f[x_]:=x^2+4. There is a similar question here, but I don't need to be that low-level about things, and I also don't want automatic refreshing; only when cell A has been evaluated.

share|improve this question
This may be useful for this:… – Szabolcs Feb 8 '13 at 2:47
@Szabolcs: Ok, thanks, this could be a very good place to start. DO you know how I would use such a function to update the contents of another cell? It can't be just the usual Dynamic, because I need cell B to be an input cell. – Steve D Feb 8 '13 at 3:18
Unfortunately I don't have time to figure it out, but this is what I'd try (not sure it's the best or even that it would work): first identify cell B somehow, e.g. with a cell tag. Then make the CellEvaluationFunction locate cell B (NotebookLocate), select it, and replace its contents e.g. using NotebookWrite (NotebookApply? not sure). Hope this helps. – Szabolcs Feb 8 '13 at 3:26
@Szabolcs: Your suggestion definitely helped, and it works when I enter it directly into the notebook. However, if I use it as an argument to CellEvaluationFunction, it does not work. – Steve D Feb 8 '13 at 14:52
up vote 2 down vote accepted

Why not use CellEpilog? :

CellPrint /@
  {ExpressionCell[ , "Input",
    CellTags -> "CellA",
    Background -> LightGray,
    CellEpilog :> Module[{contA},

      contA = NotebookRead[Cells[CellTags -> "CellA"]] /.
        {Cell[b_, "Input", ___], ___} :> b;
      NotebookFind[EvaluationNotebook[], "CellB", Next, CellTags];
      SelectionMove[EvaluationNotebook[], All, CellContents];
      NotebookWrite[EvaluationNotebook[], contA]
   ExpressionCell[, "Input", CellTags -> "CellB",
    Background -> LightOrange]
share|improve this answer
Thanks, this worked perfectly! – Steve D Feb 12 '13 at 7:16

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.