MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Initialization cell appearance

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74355] Re: Initialization cell appearance
  • From: "John Jowett" <John.Jowett at cern.ch>
  • Date: Mon, 19 Mar 2007 05:51:07 -0500 (EST)
  • References: <etb5c3$k2f$1@smc.vnet.net> <etcoj8$9ub$1@smc.vnet.net> <etg40k$igp$1@smc.vnet.net>

Albert,
        Thank you (to the others also) for your suggestions.  Your code for 
running through the notebook and changing the background of thee 
initialization cells is probably the most useful as it means I can avoid 
defining a new cell style (I think it is probably a good idea to have only 
one class of input cells).

There is a small bug in your code though (the definition of isinit).  I copy 
it again here with the correction:

SelectionMove[nb, Before, Notebook];
SelectionMove[nb, Next, Cell];
select = NotebookRead[nb];
While[select =!= {},
isinit = InitializationCell /.
AbsoluteOptions[NotebookSelection[nb], InitializationCell];
If[isinit,
SetOptions[NotebookSelection[nb], Background -> Yellow],
SetOptions[NotebookSelection[nb], Background -> Automatic]
];
SelectionMove[nb, Next, Cell];
select = NotebookRead[nb]
];


Typically I would use this with

nb = NotebookOpen[<path to some notebook file>]

and I think I will turn it into a utility function.  I suppose it could also 
be implemented as a replacement rule on the notebook expression.   Would 
this be faster, I wonder ?

John Jowett



"Albert" <awnl at arcor.net> wrote in message news:etg40k$igp$1 at 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




  • Prev by Date: Slots & Ampersands
  • Next by Date: Re: NDSolve doesn't stop
  • Previous by thread: Re: Initialization cell appearance
  • Next by thread: Re: Initialization cell appearance