I’ve been investigating Jupyter Notebook (previously called ipython). It’s an interactive environment in which you can embed code, add text, equations and plots. It would be a great tool to use for teaching (and that is the context in which I cam to hear of it). Students can play with examples, modify them, write their own adding text and equations where they want.
While designed for interactive python apparently you can also load other languages including R, Julia and Octave (though I’ve yet to successfully do this) and notebooks can be exported to Latex, pdf or html.
Further reading: