# Updating the format style of input cells from an older/'pre-styled' notebook

I have been given a large notebook that was created in mathematica 6. It contains a structure of sections and subsections and the input text is formatted in an unusual (possibly just old) style (see screen grab below).

My main aim is to update the formatting of the input cells to the standard mathematica 8 format as I find this format much easier to read/debug (example below).

My first thought was to simply copy the entire notebook into a text editor and then copy back into a notebook. However, this results in the generation of a single large input cell that is prohibitively tedious to break up...

Applying a new stylesheet does not change the input cell style.

Is it possible to update the formatting/style throughout a notebook whilst preserving the cell structure and hierarchy?

Edit: An excerpt from the original notebook can be found here,

and here is the same excerpt after clearing formatting (but without syntax highlighting).

• Please upload a sample Notebook if you can. It sounds like this may be a compound problem as I think Clear Formatting should have restored the original syntax highlighting if there is not something else going on. Feb 25, 2013 at 12:21
• @Mr.Wizard not sure how I upload a notebook?... I have a before and after ready to go... Feb 25, 2013 at 12:40
• Notebook files are text, so you can open one in a text editor, copy the text, and use pastebin.com (512kB limit) Feb 25, 2013 at 12:41

If applying a new stylesheet doesn't change the appearance then it looks like the styling is local to each cell. If you have a look at the underlying expression of some of these input cells by going to the menu and choosing Cell > Show Expression you should see some StyleBoxes, as per this example using your code that you have supplied:

So if it is the case that all this styling has been introduced locally at each cell then go to the menu and select Edit > Select All to select all cells. Then select Format > Clear Formatting. This will remove all the local styling through out your notebook and your notebook will now respond to your choice of stylesheet.

Based on your feedback it appears other cells have localized styling as well and you want to keep that. So then you just need to clear the formatting for the input cells only.

Further inspection of the code you have been given reveals it to be a mess -- it is inputform without row boxes. With this information I'd actually recommend converting to standard form as per Mr Wizards answer but then your comments will be lost. Therefore I recommend the following, more laborious approach:

1. Make the input cell a text cell (or other cell).

2. Now make it back to an input cell.

3. Now clear the formatting.

Th screen grab shows the stages:

and to prove it works when I change the stylesheet:

If you have several of these notebooks these steps could be done programmatically but for a one off I'll leave it at that.

• Thanks for your answer. Unfortunately, while clearing the formatting causes all of the text to go black, applying a new stylesheet does not cause the input cells to change to the standard colours (e.g. blue for variables, green for arguments, etc.). Feb 25, 2013 at 11:32
• that is strange behaviour. So even the text has local styling then? If you want to keep local styling for everything except Input then just clear the formatting for input cells only. Feb 25, 2013 at 21:22
• Your second strategy pretty much sorted the problem. Thanks! Feb 27, 2013 at 0:46

Here are two cells with weird embedded styles, including colors, background colors, and sizes:

Select both cells and press Shift+Ctrl+N to re-parse to StandardForm:

• If you do that you would lose any comments that are present in input cells in this notebook he has been given. Better to simply clear the formatting. Feb 25, 2013 at 7:56
• @Mike I suppose so. I wanted to provide another option and I frequently make use of this when I get code in a format that I don't like, say excessive use of infix notation :o) , and want to put it back into a "normal" form. By the way, I voted for yours. Feb 25, 2013 at 8:00
• It is another option for sure but it should come with the warning that comments will be lost if employed. Feb 25, 2013 at 11:23
• This approach works great, except that i would like to keep the comments... is there any other way to do this? perhaps I should post a question about parsing to std- or input-form whilst retaining comments...? Feb 25, 2013 at 11:35