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 ran into this when I was working with an example from the Help Pages of V9. Cells is a new function added in V9. The following appears to work the first time it is evaluated in a notebook with nb assigned to some appropriate value, say, EvaluationNotebook[].

Scan[(CurrentValue[#, StyleNames] = "Title") &, Cells[nb, CellStyle -> "Section"]]

However, if I try again to change the cells affected by the first evaluation to another style or back to the original style, nothing changes. Neither this

Scan[(CurrentValue[#, StyleNames] = "Text") &, Cells[nb, CellStyle -> "Title"]] 

nor this

Scan[(CurrentValue[#, StyleNames] = "Section") &, Cells[nb, CellStyle -> "Title"]]  

has any effect.

For other CurrenValue targets such as FontSize, it's easy to change the value repeatedly.

 Scan[(CurrentValue[#, FontSize] = 100) &,  Cells[nb, CellStyle -> "Section"]]
 Scan[(CurrentValue[#, FontSize] = 30) &,  Cells[nb, CellStyle -> "Section"]]
share|improve this question

2 Answers 2

up vote 5 down vote accepted

It appears that it only works once because it messes up the cell expressions it modifies the first time it is evaluated.

I started with a notebook with several kinds of cells but only one text cell, which had the cell expresion

Cell["Some text", "Text"]

I evaluated

nb = EvaluationNotebook[];
Scan[(CurrentValue[#, StyleNames] = "Section") &, Cells[nb, CellStyle -> "Text"]]

and everything looked good -- the text cell was reformatted to a section cell. However, the cell expression was now

Cell["Some text", "Text", "Section"]

It should have been

Cell["Some text", "Section"]

So I think we are looking at a bug.

share|improve this answer
Yeah, anyway, one not so comfortable way is to reset the nb each time re-change the Style of Cell. –  HyperGroups May 8 '13 at 4:38
quaternions.blog.163.com/blog/static/20608214720134802320281 here, I re-format all inline cells by Replace Rules Cell[]->Cell[,Background->Red] about CellExpression. is there any other simple way? Such like the option, DefaultInlineFormatType which I found seems only take effect for new Created Inline Cells –  HyperGroups May 8 '13 at 4:45
@HyperGroups. Your comment seems to be a new question. Please ask it properly by posting it as a question, so it can be given proper attention and so people can answer it using the full facilities of Mathematica.SE –  m_goldberg May 8 '13 at 21:13

I agree that CurrentValue should work, here is a work around:

 SelectionMove[#, All, Cell]; 
 FrontEndTokenExecute[EvaluationNotebook[], "Style", "Title"]
) & /@ Cells[CellStyle -> "Section"]
share|improve this answer

Your Answer


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.