3
$\begingroup$

DefaultNewInlineCellStyle only take effect for newly generated inline cells.

for example

    Cell[TextData[{Cell[BoxData[FormBox[RowBox[{RowBox[{"f","",RowBox[{"(","x",")"}]}],"","=","",RowBox[{"a","",FormBox[SubscriptBox["f","1"],StandardForm],"",RowBox[{"(","x",")"}]}]}],TraditionalForm]],"DisplayFormula"],",",Cell[BoxData[FormBox[RowBox[{RowBox[{"g","",RowBox[{"(","x",")"}]}],"","=","",RowBox[{"r","",FormBox[SubscriptBox["g","1"],StandardForm],"",RowBox[{"(","x",")"}]}]}],TraditionalForm]],"DisplayFormula"],",",Cell[BoxData[FormBox[RowBox[{RowBox[{"h","",RowBox[{"(","x",")"}]}],"","=","",RowBox[{"s","",FormBox[SubscriptBox["h","1"],StandardForm],"",RowBox[{"(","x",")"}]}]}],TraditionalForm]],"DisplayFormula"],","}],"Text"]

Here, for some reasons, $f(x),a,f_1(x)$ in Notebook are not in an consistent style. Choose them, set same font/clear format/apply an stylesheet does not take effect, because of different values of StandardForm and TraditionalForm and other.

If I do the following

SetOptions[$FrontEnd,DefaultNewInlineCellStyle->{"Section",FontFamily->"Mathematica",Background->Red}]

How to make the previous inline cells,or further, all inline cells in the notebook the same formatting style?

$\endgroup$
1
  • $\begingroup$ Probably I got a bit tied up in finding the CellObjects. It is probably better to use something with Style stuff as Silvia suggests. $\endgroup$ Jun 17, 2013 at 11:11

1 Answer 1

1
$\begingroup$

Note: This may only work in v9 as many notebook programming functions were added there (Cells in particular).

It is quite frustrating that there is almost a nice way to do this, but not quite. The Inline Cells are indeed stored somewhere as Cell objects. So in theory we can manipulate them using SetOptions, rather than rewriting every "proper" (not inline) cell in the notebook. But it is hard to actually get the CellObjects. Of course I would have preferred if there was a simpler answer, but I guess this may still help.

The code below shows you how to get the cell objects semi-programmatically (it is not really robust). But it also shows you how you can get the CellObjects by selecting them and then using SelectedCells.

The code below makes a new notebook with your textcell with its inline cells and then makes those cells have an orange background.

cnb =
 NotebookPut[

  Notebook[
   List@
    Cell[TextData[{Cell[
        BoxData[FormBox[
          RowBox[{RowBox[{"f", "", RowBox[{"(", "x", ")"}]}], "", "=",
             "", RowBox[{"a", "", 
              FormBox[SubscriptBox["f", "1"], StandardForm], "", 
              RowBox[{"(", "x", ")"}]}]}], TraditionalForm]], 
        "DisplayFormula"], ",", 
       Cell[BoxData[
         FormBox[RowBox[{RowBox[{"g", "", RowBox[{"(", "x", ")"}]}], 
            "", "=", "", 
            RowBox[{"r", "", 
              FormBox[SubscriptBox["g", "1"], StandardForm], "", 
              RowBox[{"(", "x", ")"}]}]}], TraditionalForm]], 
        "DisplayFormula"], ",", 
       Cell[BoxData[
         FormBox[RowBox[{RowBox[{"h", "", RowBox[{"(", "x", ")"}]}], 
            "", "=", "", 
            RowBox[{"s", "", 
              FormBox[SubscriptBox["h", "1"], StandardForm], "", 
              RowBox[{"(", "x", ")"}]}]}], TraditionalForm]], 
        "DisplayFormula"], ","}], "Text"]
   ]
  ]

SelectionMove[cnb, Before, Notebook]
SelectionMove[cnb, Next, Cell]
SelectionMove[cnb, Before, CellContents]
SelectionMove[cnb, Next, Character]
cell1 = SelectedCells[cnb];
SelectionMove[cnb, Next, Cell];
cell2 = SelectedCells[cnb];
SelectionMove[cnb, Next, Cell];
cell3 = SelectedCells[cnb];

Now that we have found the inline cells and named them cell1, cell2 and cell3, we can do

SetOptions[# // First, Background -> Orange] & /@ {cell1, cell2, 
  cell3}

to make the backgrounds orange.

The line SelectionMove[cnb, Before, Notebook] is not necessary but may be convenient if you want to experiment yourself.

Workflow

I suggest you store references to inline cells. The code above can help you find your inline cells, but it is not robust. The main problem is to get into the first inline cell I guess. In your example, this was easy enough, as we could simply do SelectionMove[cnb, Next, Character], as that moved us into the first inline cell. You may want to set the cursor into the first inline cell yourself and then you can probably use the code

Block[{iii = 1},
 While[
  SelectedCells[cnb] =!= {}
  ,
  inlineCell[iii] = SelectedCells[cnb];
  SelectionMove[cnb, Next, Cell];
  iii++
  ]
 ]

to get all the inline cells in the current "proper cell".

$\endgroup$
1
  • $\begingroup$ Yes, what a pity, Cells[] does not scan inline cells by defaut. Anyway, this answer is useful. --, $\endgroup$ Jun 17, 2013 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.