literate programming, cell tagging #2249

tmbdev opened this Issue Aug 4, 2012 · 1 comment


None yet

3 participants

tmbdev commented Aug 4, 2012

IPython notebooks allow very nice mixing of text and code in a "literate programming" style. One aspect that's missing from IPython notebooks that literate programming offers, however, is the ability to present content in an order different from the execution order.

I want to suggest a simple, general mechanism by which one might get such features:

  • each code cell can have tags added to it
  • tags are preceded by "#:"
  • untagged cells get the tag "default", only "default" cells are executed by default
  • I can enable/disable the execution of additional tags; this is equivalent to wrapping the cell into an "if" statement
  • I can explicitly request execution of a tagged group of cells from a notebook anywhere in a notebook

Note that I already can perform out-of-order execution by hand, so that isn't something all that unusual for
IPython notebooks.

So, with this, I could:

  • tag a bunch of cells as "#:test" and only using them during testing
  • tag a bunch of cells as "#:appendix" and state at the beginning of the notebook that I want to execute the "appendix" there;
    this allows me to move boring preliminaries of a notebook to the end without hiding them entirely
  • load all the cells tagged "#:exported" from another notebook, in effect treating it like a library
  • write a separate tool that takes all the cells tagged "#:exported" and convert them into a ".py" library, while still
    retaining sync with the notebook where I develop them
Carreau commented Aug 4, 2012

I don't think this will be soon in the notebook.
In the mean time, you can access cell meta data and store whatever you wish in it in javascript and it will be saved.

what you can do if your first cell is markdown, add a <script> tag that contains javascript that execute code stored in a string into the kernel.
Using IPython.kernel.execute("code string",silent=true)

@minrk minrk removed the prio-medium label Jan 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment