Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Let's say I print a cell like so.

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

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

For example

1


2

I hit Shift+Enter and get the following output.

BoxData[List["1","3"]]

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

BoxData[
  RowBox[{" ", 
     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?

share|improve this question
1  
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. –  Michael E2 Aug 1 '13 at 23:34
1  
@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. –  Liam William Aug 1 '13 at 23:37
1  
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. –  Mr.Wizard Aug 6 '13 at 7:31
add comment

1 Answer 1

up vote 6 down vote accepted

Make your CellEvaluationFunction this:

Function[Print[NotebookRead[EvaluationCell[]]];]

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

share|improve this answer
    
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? –  Mr.Wizard Aug 6 '13 at 7:34
    
@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 –  Liam William Aug 6 '13 at 15:31
    
@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] –  John Fultz Aug 6 '13 at 16:25
    
@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[]] –  Liam William Aug 6 '13 at 16:26
    
@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. –  John Fultz Aug 6 '13 at 16:28
add comment

Your Answer

 
discard

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.