I want to create a textual style that has some CellEvaluationFunction that processes the contents of the cell a certain way. Particularly, it has to do something with the contents of inline cells (formulas in the middle of the text).

The problem is that it seems the CellEvaluationFunction receives an already parsed string (something like what you would get when you "copy as input", so I lose the inline cells.
If the cell is one of those that start with an empty box, boxdata, like in StandardForm or TraditionalForm, then the function does get the box structure, but then the writing is not the same: spaces become boxes, it formats as formulas, and inline cells get formatted as text.

Could you please include a Cell Expression with appearance that you want, with inline boxes, etc.?
–
Mr.Wizard♦Mar 1 '12 at 0:56

1

Rojo, whoops. I've had several windows open and working on a few things at once. the result is lack of attention!
–
Mike HoneychurchMar 1 '12 at 1:05

1

@Rojo If you want to understand how the FE communicates with the kernel, you should learn to use LinkSnooper. I use it all the time to see what's actually being passed back and forth on the links. Look up LinkSnooper in the docs, which links to a Javadoc page that documents it. Given the sorts of things you express an interest in, I think you would find it a highly instructive tool. If you have any questions about using it, post them here and I'll try to keep an eye out for them.
–
John FultzMar 1 '12 at 12:20

1 Answer
1

You're not going to get this to work on raw TextData cells. The FE evaluates TextData cells using EnterTextPacket, which merely sends a string along. And, so, the contents must be encoded as a string. Which means you're going to lose all of your typesetting structure. So, let's assume that you've embedded the above cell in a typeset cell where we'll have some more choices. E.g.,

Now the FE is going to send an EnterExpressionPacket which maintains the full box structure, including inline cells, and that we can work with. From that starting point, I wrote a version of myEvalFun which works for your sample input. It's not very robust...in particular, it assumes that the cell contains one TextData cell with, at most, one level of BoxData cells inside of it. And that the contents of the TextData cell contain nothing other than strings and BoxData cells (other valid TextData contents include StyleBoxes, ButtonBoxes, and TextData cells). But I think it'll give you a good starting point to work from.

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.