2
$\begingroup$

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.

$\endgroup$
4
  • 1
    $\begingroup$ This may be useful for this: reference.wolfram.com/mathematica/ref/… $\endgroup$
    – Szabolcs
    Commented Feb 8, 2013 at 2:47
  • $\begingroup$ @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. $\endgroup$
    – Steve D
    Commented Feb 8, 2013 at 3:18
  • 1
    $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Commented Feb 8, 2013 at 3:26
  • $\begingroup$ @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. $\endgroup$
    – Steve D
    Commented Feb 8, 2013 at 14:52

1 Answer 1

2
$\begingroup$

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

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.