Re: Initialization cell appearance
- To: mathgroup at smc.vnet.net
- Subject: [mg74288] Re: Initialization cell appearance
- From: Albert <awnl at arcor.net>
- Date: Sat, 17 Mar 2007 02:04:28 -0500 (EST)
- References: <etb5c3$k2f$1@smc.vnet.net> <etcoj8$9ub$1@smc.vnet.net>
Hi,
> this is the way to go. It works, I am using this all the time. Just make
> a copy of your favourit StyleSheet, in that make a copy of the
> InputCell-Style and change it to be an Initialization Cell. Depending on
> where you put the new definition in your StyleSheet, you can even switch
> between this new style and a regular InputCell...
here the last part of the sentence was missing:
... with a Alt-<N>, N=0...9 keyboard shortcut
to let this message contain some more useful information here is a piece
of code that shows how you could automate the process if you don't like
the StyleSheet-solution:
(* this just creates a new notebook to test the following code, in your
real application you want to set nb to the notebook object you want to
alter ... *)
nb = NotebookPut[
Notebook[{Cell["1+1", "Input"], Cell["2+2", "Input",
InitializationCell -> True]}]
]
(* here comes the code: select each cell of the notebook, check whether
it is an InitializationCell and change the background. The else part of
the if would reset the background to the stylesheet default if it is not
an initialization cell anymore. Of course there are plenty of
possibilities to do this better, just adopt it to your needs... *)
SelectionMove[nb, Before, Notebook];
SelectionMove[nb, Next, Cell];
select = NotebookRead[nb];
While[select =!= {},
isinit = AbsoluteOptions[NotebookSelection[nb],InitializationCell];
If[isinit,
SetOptions[NotebookSelection[nb], Background -> Yellow],
SetOptions[NotebookSelection[nb], Background -> Automatic]
];
SelectionMove[nb, Next, Cell];
select = NotebookRead[nb]
];
hth,
albert