Let's say I print a cell like so.

  BoxData[" "], "Input", Evaluatable -> True, 
  CellEvaluationFunction -> Function[Print[#];]

Now I type in several lines of text in the Cell in Mathematica.

For example



I hit Shift+Enter and get the following output.


But when I do Ctrl+Shift+e, the Cells content is really

  RowBox[{" ", 
       "1", "\[IndentingNewLine]", "\[IndentingNewLine]", "3"}]}]]

Why doesn't CellEvaluationFuction receive the actual cell data? Is there a hidden function/argument that might give me such information?

  • 1
    $\begingroup$ According to the docs, "CellEvaluationFunction is applied to the BoxData expression representing the input to be evaluated." [Emphasis mine.] The docs do not say that the Front End won't substitute some simplification of the expression in the cell. I believe for TagBox and InterpretationBox, the difference might be quite a bit different. At the least, one should not be surprised that any "typesetting" differences are stripped. $\endgroup$
    – Michael E2
    Commented Aug 1, 2013 at 23:34
  • 1
    $\begingroup$ @MichaelE2 Okay then a workaround would be appreciated to achieve such functionality. I am working on a workaround using CellTags right now, but I have some doubts on how dependable it will be with multiple cells. $\endgroup$
    – William
    Commented Aug 1, 2013 at 23:37
  • 1
    $\begingroup$ Related: (13317) -- UndocumentedTestFEParserPacket[string, False] would give the unmodified Box form for that string. This is not directly applicable but it may be useful at some point. $\endgroup$
    – Mr.Wizard
    Commented Aug 6, 2013 at 7:31

1 Answer 1


Make your CellEvaluationFunction this:


Note that EvaluationCell (and the CellObject it creates) are new to version 9.

  • $\begingroup$ John, would you please take a look at my question here? Also, can this answer be made to work in v7 by using SelectionMove and EvaluationCell? $\endgroup$
    – Mr.Wizard
    Commented Aug 6, 2013 at 7:34
  • $\begingroup$ @Mr.Wizard I don't have version 7 to test but I willing to be this works in v7 also. Basically I just read the entire notebook and extract the needed Cell. You could probably use CellIds in replacement of CellTags. pastebin.com/FmCEPju6 $\endgroup$
    – William
    Commented Aug 6, 2013 at 15:31
  • $\begingroup$ @Mr.Wizard The use of EvaluationCell as a selector for SelectionMove, while no longer supported in v9, still seems to work, and also works in older versions. E.g., SelectionMove[EvaluationNotebook[], All, EvaluationCell] $\endgroup$
    – John Fultz
    Commented Aug 6, 2013 at 16:25
  • $\begingroup$ @JohnFultz Sorry for the confusion I was talking about my linked code. pastebin.com/FmCEPju6 I was responding to Mr.Wizard's comment. It doesn't use EvaluationCell but NoteebokRead[InputNotebook[]] $\endgroup$
    – William
    Commented Aug 6, 2013 at 16:26
  • $\begingroup$ @Liam Actually, my comment was confused and didn't make much sense. SE wouldn't let me edit it anymore, so I just deleted it. $\endgroup$
    – John Fultz
    Commented Aug 6, 2013 at 16:28

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.