[Tips] Extract Input Code from Long Notebooks

Recently both our users and developers have contributed a large amount of good articles and demonstrations on Community. It is a great adventure to read through the notebooks and play around the codes. Sometimes you may want to create another notebook along side with only input cells (executable parts only), so you can quickly run all notebook quickly and view the results avoiding long scroll.

Here are two ways you can make it happen:

at.gif

Or you can

  • Put the following script in the top line of your notebook from which you need to extract input codes. This method is more general because you can choose any style you like in the Cases function, note limit to Input style. And Alternative lets you pick multiple styles at the same time:

     this = EvaluationNotebook[];
     new = NotebookGet[EvaluationNotebook[]];
     new = Cases[new, Cell[__, "Input" | "Code", ___], \[Infinity]];
     nb = CreateDocument[new];
     SelectionMove[nb, Next, Cell];
     NotebookDelete[nb];
     Pause[3];
     NotebookClose[this] 
    

tutorial.gif

5 Likes

news-congrads-kkluyshnik-02-04-19.jpg – you have earned Featured Contributor Badge 2015-11-02_10-07-11.png

Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!