Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the ipython notebook to produce engineering calcs

I am a structural engineer and I need to produce calculations which basically look like a report with a mix of text, tables, math expressions etc... These calculations are highly repetitive so when I design a joist for instance, apart from the numbers, the output is the same.

At the moment, I tend to do the calcs and then write them down either by hand or in an open office document. To do some of the repetitive calculations I sometimes use the Ipython notebook together with some python modules I've written.

Now the really neat thing would be to use my calcs in the Ipytrhon notebook directly to produce the output. The output could be a pdf document.

Thus seeing nbconvert appear really got me interested, I still need to do some work on understanding the templating bit.

So to get there, I need to :

  1. Make my module functions output some latex - I should be OK with this
  2. Format the nbconvert output as I want. I found this Writing an IPython notebook to HTML or PDF with Table Of Content and this Suppress code in NBConvert? IPython Can anybody point toward more comprehensive tutorials? Is there a way selectively show or hide some blocks of codes from the input? Something like this in the input cell would be fantastic :

    /hide
    Boring code
    //hide
    Interesting python code I want to show
    
  3. Find a way to insert pdf pages Sometimes I will need to insert other stuff such as drawing or even something handwritten and it would be nice to be able to write a small function like insertmypdf(pathtomy/document.pdf). So that when I execute nbconvert it automatically inserts the pages.

Am I dreaming? If you could point me in the right direction I will be grateful. Ideally all the time I spend retyping stuff I've calculated before could be replaced by a

ipython nbconvert --to=latex --template=latex_template.tplx --post=pdf file.ipynb
like image 534
Cambium Avatar asked Jan 03 '14 12:01

Cambium


1 Answers

Can anybody point toward more comprehensive tutorials?

You can probably blame me (among others) for not writing those, but as the API is still slowly changing we are reluctant on writing docs that will be soon deprecated, still I wrote some stuff in the past that can give you some ideas. Damian Avila blog can also be a good resources as he himself use custom templates to hide/show code cells, and wrote about that in some of his posts. I've also seen this but haven't fully read it yet.

Is there a way selectively show or hide some blocks of codes from the input?

Either using cell-level metadata, or markup language, yes, but it will require custom code in templates, you'll probably figure out by reading the above links, while you dive in nbconvert architecture. But it wont be a one liner.

3) will be the more difficult, but I suppose you can do it with custom filters on the markdown cell

You though and feedback on the process are always welcome.

like image 104
Matt Avatar answered Sep 22 '22 13:09

Matt