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 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). original formatting

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).

new formatting

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).

share|improve this question
    
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. –  Mr.Wizard Feb 25 '13 at 12:21
    
@Mr.Wizard not sure how I upload a notebook?... I have a before and after ready to go... –  geordie Feb 25 '13 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) –  Mr.Wizard Feb 25 '13 at 12:41
add comment

2 Answers

up vote 6 down vote accepted

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:

enter image description here

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:

enter image description here

and to prove it works when I change the stylesheet:

enter image description here

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

share|improve this answer
    
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.). –  geordie Feb 25 '13 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. –  Mike Honeychurch Feb 25 '13 at 21:22
    
Your second strategy pretty much sorted the problem. Thanks! –  geordie Feb 27 '13 at 0:46
add comment

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

Mathematica graphics

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

Mathematica graphics

share|improve this answer
1  
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. –  Mike Honeychurch Feb 25 '13 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. –  Mr.Wizard Feb 25 '13 at 8:00
    
It is another option for sure but it should come with the warning that comments will be lost if employed. –  Mike Honeychurch Feb 25 '13 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...? –  geordie Feb 25 '13 at 11:35
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.