MathGroup Archive 1999

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

Search the Archive

Re: Reset In[ ] & Out[ ]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16139] Re: Reset In[ ] & Out[ ]
  • From: dreiss at !SPAMscientificarts.com (David Reiss)
  • Date: Sat, 27 Feb 1999 03:23:08 -0500
  • Organization: EarthLink Network, Inc.
  • References: <7atri7$7n7@smc.vnet.net> <7b36i3$23v@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <7b36i3$23v at smc.vnet.net>, Paul Abbott
<paul at physics.uwa.edu.au> wrote:

> Dana DeLouis wrote:
>  
> > Hello.  I often Insert and delete equations.  Does anyone know of a way to
> > reset the In [ ] and Out [ ] numbering system without first closing and then
> > reopening the file?  I have had no luck finding this information.  Thank
> > you.
> 
> Without writing a button program, I am aware of no way of removing the
> In/Out CellLabel without opening and closing the Notebook.  
> 
> However, you can suppress the CellLabel using 
> 
>         Kernel | Show In/Out Names
> 
> or you can use
> 
>         $Line=0
> 
> to reset the In/Out numbers.
> 
> Cheers,
>         Paul
> 
> ____________________________________________________________________ 
> Paul Abbott                                   Phone: +61-8-9380-2734
> Department of Physics                           Fax: +61-8-9380-1014
> The University of Western Australia           
> Nedlands WA  6907                     mailto:paul at physics.uwa.edu.au 
> AUSTRALIA                        http://www.physics.uwa.edu.au/~paul
> 
>             God IS a weakly left-handed dice player
> ____________________________________________________________________


Just for fun I experimented with the following:


Here is a function that removes the In and Out cell lables 
and resets the $Line number to 1.  If the option RemoveOutput 
is set to True (its default is False), all output cells 
are removed as well.  It comes with all the caveats of something
that is free and largely untested: use at your own risk and 
preferably on a copy of a notebook -- expecially in light of 
the bug noted later on for BadCleanNotebookInOut.


(*  ************ CleanNotebookInOut  ********************* *)

ClearAll[CleanNotebookInOut]; 

CleanNotebookInOut::usage = "CleanNotebookInOut[] removes 
the In and Out CellLabels from the notebook in which it is 
evaluated and resets the line number to 1.  If the 
RemoveOutput option is set to True then all Output cells in 
the notebook are deleted as well."; 

Options[CleanNotebookInOut] = {RemoveOutput -> False}; 

CleanNotebookInOut[opts___?OptionQ] := 

  Module[{nb, theNotebook, revisedNotebook, removeOutput}, 
  
   removeOutput = 
     RemoveOutput /. 
      Flatten[{opts, Options[CleanNotebookInOut]}]; 
      
    $Line = 0; 
    
    nb = SelectedNotebook[]; 
    
    theNotebook = NotebookGet[nb]; 
    
    revisedNotebook = 
     theNotebook /. 
      Cell[x___, CellLabel -> _, y___] :> Cell[x, y];
       
    NotebookPut[revisedNotebook, nb];
     
    If[removeOutput, 
      FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]
      ]; 
      ]
   
(*  *********************************************** *)

If this CleanNotebookInOut[] is executed in a notebook
along with other cells that are thereby put into the evaluation
queue, the notebook is overwritten (which is what the function
is designed to do) and the remaining cells that were in the 
evaluation queue are removed from it.  Presumably this is because
the evaluation queue looks to the notebook for the next 
cell with a highlighted bracket and, after the execution
of CleanNotebookInOut[], these cells are "no more."
I am sure that I am being naive about the functioning of the 
evaluation queue here, so any tutilage on 
this would be appreciated.
     
It is interesting to note that in Version 3 if this function 
is rewritten in the following form (which should have the 
same effect) the results are not what one would expect. 
(The difference between CleanNotebookInOut and 
BadCleanNotebookInOut is only in where the DeleteGeneratedCells 
front end token is executed: at the end in the former case and 
at the beginning in the latter.)


(*  ************ BadCleanNotebookInOut  ****************** *)

ClearAll[BadCleanNotebookInOut]; 

  BadCleanNotebookInOut::usage = "BadCleanNotebookInOut[] 
attempts to remove the In and Out CellLabels from the 
notebook in which it is evaluated and reset the line number 
to 1.  If the RemoveOutput option is set to True then all 
Output cells in the notebook are deleted as well. However 
it has a bug that causes it to erase the entire notebook if 
there are no output cells."; 

  Options[BadCleanNotebookInOut] = {RemoveOutput -> False};
   
  BadCleanNotebookInOut[(opts___)?OptionQ] := 
  
   Module[{nb, theNotebook, revisedNotebook, removeOutput}, 
   
    removeOutput = 
      RemoveOutput /. 
       Flatten[{opts, Options[BadCleanNotebookInOut]}];
        
     $Line = 0; 
     
     If[removeOutput, 
      FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]
      ]; 
      
      nb = SelectedNotebook[]; 
      
     theNotebook = NotebookGet[nb]; 
     
     revisedNotebook = 
      theNotebook /. 
       Cell[x___, CellLabel -> _, y___] :> Cell[x, y]; 
       
     NotebookPut[revisedNotebook, nb]; 
     ]
    
   
(*  *********************************************** *)


    
An example of failed expectations here is that if 
one evaluates,

BadCleanNotebookInOut[RemoveOutput->True]

in a notebook that has  no output cells the result 
is that the notebook is  rendered blank.  
This, I believe, is a bug (or at 
least I don't understand it).






Regards,

David

-- 


   
----------------------------------------
 
Scientific Arts:
Creative Services and Consultation 
for the Applied and Pure Sciences
 
  http://www.scientificarts.com

David Reiss 
Email: dreiss at !SPAMscientificarts.com 

----------------------------------------
 


Remove the !SPAM to send email


  • Prev by Date: Re: Evaluate/Module
  • Next by Date: Re: Retrieve definitions (aka ?)
  • Previous by thread: Re: Reset In[ ] & Out[ ]
  • Next by thread: Higher resolution WORLD PLOT