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.

  • 1
    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
  • 1
    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]

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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