# Revert FullForm-ed text to prettyprinted

Sometimes strings in a notebook/package file end up garbled due to some unknown/unintentional conversion of the expression/cell/notebook. I could not find a way to revert such unreadable text to its original version. When I convert such a cell to OutputForm (via the menu option), the result looks similar to the original, but then I cannot copy the text anymore.

From this (inserted as image to maintain formatting):

To this:

"Set.\!$$\* StyleBox[\"obj\",\nFontSlant->\"Italic\"]$$.\!$$\* StyleBox[\"new\",\nFontSlant->\"Italic\"]$$, Set.\!$$\* StyleBox[\"obj\",\nFontSlant->\"Italic\"]$$.\!$$\* StyleBox[\"field\",\nFontSlant->\"Italic\"]$$.\!$$\* StyleBox[\"new\",\nFontSlant->\"Italic\"]$$ or Set.\!$$\* StyleBox[\"obj\",\nFontSlant->\"Italic\"]$$.\!$$\* StyleBox[SubscriptBox[\"f\", \"1\"],\nFontSlant->\"Italic\"]$$.\!$$\* StyleBox[SubscriptBox[ StyleBox[\"f\",\nFontSlant->\"Italic\"], \"2\"],\n\ FontSlant->\"Italic\"]$$.(\[Ellipsis]).\!$$\* StyleBox[\"new\",\nFontSlant->\"Italic\"]$$ is interpreted as \
SetField[\!$$\* StyleBox[\"obj\",\nFontSlant->\"Italic\"]$$, \!$$\* StyleBox[\"new\",\nFontSlant->\"Italic\"]$$], SetField[\!$$\* StyleBox[\"obj\",\nFontSlant->\"Italic\"]$$, \!$$\* StyleBox[\"field\",\nFontSlant->\"Italic\"]$$, \!$$\* StyleBox[\"new\",\nFontSlant->\"Italic\"]$$] or SetField[\!$$\* StyleBox[\"obj\",\nFontSlant->\"Italic\"]$$, \!$$\* StyleBox[SubscriptBox[ StyleBox[\"f\",\nFontSlant->\"Italic\"], \"1\"],\n\ FontSlant->\"Italic\"]$$, \!$$\* StyleBox[SubscriptBox[\"f\", \"2\"],\nFontSlant->\"Italic\"]$$, \
\[Ellipsis], \!$$\* StyleBox[\"new\",\nFontSlant->\"Italic\"]$$] respectively. Note that \
Set modifies the behaviour of Dot."


I don't really know what the Cell > Convert To menuoptions do, as both cells are in StandardForm and are also set to StandardForm Display. Is there a way to revert the garbled text to its original without manually editing it? Anyone knows the cause of this behaviour? You are welcome to edit the title of this post as I had no idea how to make it informative.

Edit:

These conversions mostly happen in package files (.nb) when I comment out some usage messages or other formatted text. The text immediately converts to raw form when I remove the comment markers. Sadly, when I use kguler's answer below, and copy the text reverted by Normal, the pasted text appears again in raw form.

• Do you have a sample corrupted file? Jan 26 '12 at 11:15
• Quite a few. But I intend to look for a solution that reverts the given expression "inline" (i.e. I don't even have to close the notebook). Jan 26 '12 at 11:32
• Related question: stackoverflow.com/questions/8283256/… Jan 26 '12 at 11:48

The fastest method keystroke-wise that I have found is:

1. Create new empty cell

2. Press Ctrl+Shift+E to get Cell[BoxData[""], "Input"]

3. Paste your expression into that one replacing the "" inside of BoxData.

4. Press Ctrl+Shift+E again.

Alternatively, plaste your expression into this and evaluate:

FrontEndExecute@FrontEndCellPrint[
(* expression here *)
]

• I did try //BoxData//Cell[..] combination but could not get it to work. Now I see I needed to add CellPrint.
– kglr
Jan 26 '12 at 16:42

This looks like the Raw Input Form (one of the Convert To options in the Cell menu) of a string with formatted elements. Also, if you take a formatted string like the first code block in your question and append it with //ToBoxes, or if you select Show Expression in the Cell menu, you get something similar to the second block.

Append //Normal to the second block of code in your question to get the first block back.

Edit: If you use //Normal or //Normal//Print; and after highlighting the content of the printed cell select Copy As->Plain Text in the Edit menu, it seems work. Alternatively, combining all steps, if you add the following at the end of problem cells

 // Normal // Print; SelectionMove[
EvaluationNotebook[], Previous, Cell]; FrontEndExecute[
FrontEndToken["CopySpecial", "PlainText"]]; SelectionMove[
EvaluationNotebook[], After, CellGroup, 2]; FrontEndExecute[
FrontEndToken["Paste"]];


you get a copy of the contents that can be edited and copied without reverting to FullForm.

Cleaner alternative is a variant of Mr. Wizard's answer: Put at the end of the problem cell

 // BoxData // Cell[#,"Text"] & // CellPrint
`
• Thanks, that worked. Saves me a lot of typing! Jan 26 '12 at 11:43
• On a closer look, it only works in simple cases. See edit in my post. Jan 26 '12 at 11:51
• Yes, with the addition, it works. Strange though that this method returns an expression and not a string. Jan 27 '12 at 14:30