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.

I have an opened Mathematica notebook containing several cells. Suppose, I am interested in one of them -- it may contain a complete or incomplete expression (e.g. with syntax errors, highlighted unbalanced brackets etc), possibly with embedded graphics, some of the identifiers automatically colorized by Mathematica Front End according to their meaning (undefined symbols, Block locals, Module locals, conflicting names...) and some possibly having a manually changed style (font, size, color etc). I need to get a String whose content represents the content of this cell with highest possible fidelity (recall that Mathematica strings preserve formatting and support arbitrary embedded expressions including graphics). The string should mimic the structure and be editable to the same extent as the original cell (so it should not, for example, contain just a graphical image depicting the cell).

Could you please suggest how to do this?

share|improve this question
I hope you're not expecting the "string local variables" to change color when I remove it from the "Module" in the string :P –  rm -rf Jun 18 '13 at 19:17
@rm-rf Of course, I'm not. I want to capture a snapshot of the cell, not its behavior. –  Vladimir Reshetnikov Jun 19 '13 at 8:17
I know, I was only joking... :) This is a good question. I have no idea where to dig into this, but most probably, it will be some crazy function in FrontEnd` . –  rm -rf Jun 19 '13 at 8:48
Perhaps rasterizing cell contents, do text-recognizing with TextRecognize or Tesseract, and a bit of image-processing to get the colors/style? –  István Zachar Dec 11 '13 at 22:01
What do you want to do with this string? Or more specific: With what program do you want to be able to edit this string? –  Karsten 7. Jul 23 '14 at 23:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.