MathGroup Archive 2000

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

Search the Archive

Removing In and Out Labels in all Open Notebooks [revisited]

In [mg22000], P. J. Hinton and Dale Horton combined to give a <<really
useful and elegant>> method for removing In[] and Out[] strings from
open Notebooks:

    (SelectionMove[#, All, Notebook];
    SetOptions[NotebookSelection[#], CellLabel -> ""])&,
Notebooks[] ]

I have found a few little snags with this (version 4.0 for NT):

(1) if the code is placed in init.m as recommended, I found an
unrepeatable intermittent problem when execution transfers to the
EvaluationNotebook (i.e. open a Notebook, then select a large group of
cells, press ENTER to evaluate, and watch the fun as Input cell
contents get mangled).  The problem persisted even when wrapping with
Evaluate etc, but happened so rarely that I could not tie it down.  If
the code is put in end.m, this problem does not occur (and the startup
delays are avoided when LARGE notebooks are open).  Note that [I now
discover] end.m is not evaluated when "Kernel>Quit Kernel>local" is
selected from the Front End but only when executing Quit[] or Exit[]. 
I also put the code in a Palette, this works well (very simple: a
Button with FrontEnd` code only for removing In[] and Out[] from the
SelectedNotebook only, and a button for Quit[] to invoke end.m).

(2) the use of SetOptions[] on Cells in any open Palettes generates an
annoying beep.  It is possible to check each Notebook for (e.g.)
"Palettes" in the "FileName" option in NotebookInformation to identify
these, so this is not a problem.

(3) The window header of an open Notebook is given an asterisk to
denote a file which has been edited in some way: unfortunately this is
set when SetOptions has been used as above.  When many windows are
open including some which were neither edited nor evaluated, you then
feel you have to save all the files "just in case" (unless your memory
is better than mine).
I can see no simple way to find out the status of a Notebook, but the
information must be there somewhere - in my attempts I found that:

  * NotebookInformation is of no help here (memory and file
    modification dates are insufficient, and the asterisk is not
    included in the WindowTitle)

  * FrontEnd`NotebookInformation exists (?) but doesn't seem
    to do anything

  * Options[NotebookSelection[<NotebookObject>],CellLabel] is not a
      reliable guide if only a single case is examined.
    If all cells are selected, only the option for
    the first Cell is returned.

I therefore resorted to a brute-force solution which I have started to
use, but it is really too much even for end.m (try using it when
several LARGE unevaluated notebooks are open...) and currently beats  
my Palette-writing abilities.  Can anyone neaten it up, preferably
with hints on how to put it into a Button in a Palette?

((filetest = "FileName" /. NotebookInformation[#1];
  If[  (Head[filetest] =!= FrontEnd`FileName || 
        filetest[[1,-1]] =!= "Palettes"),
     SelectionMove[#1, Before, Notebook];
     While[(  SelectionMove[#1, Next, Cell];
              cellopt = Options[NotebookSelection[#1],
            ) =!= $Failed, 
        celloptstr = CellLabel /. cellopt;
        If[(  StringQ[celloptstr] && StringLength[celloptstr] > 4 && 
              (  StringTake[celloptstr, 3] === "In[" || 
                 StringTake[celloptstr, 4] === "Out[") ), 
           SelectionMove[#1, All, Notebook];
           SetOptions[NotebookSelection[#1], CellLabel -> ""];
) & ) /@ Notebooks[]; ]

John Tanner     (john.tanner at
BAE SYSTEMS (Sensor Systems Division), Edinburgh, Scotland

  • Prev by Date: Re: FindMinimum and Gradient
  • Next by Date: Re: Conditionals with multiple tests?(2)
  • Previous by thread: Re: saving notebook files
  • Next by thread: Re: Conditionals with multiple tests?(2)