I have been using LaTeX for some time, in favour of traditional text editors such as MS Word or LibreOffice. The quality and versatility of LaTeX documents simply far exceeds that of its over-complicated competitors.
More recently however, I have started using python, and by extension the Ipython notebook interface. What a pleasant, interactive and dynamic interface this turned out to be.
However, last week I found myself frustrated with the lack of integration between python and LaTeX. There exists a LaTeX package called python.sty which allows you to integrate python code and output into your pdf document. It has provided me with some headaches, and mostly was not what I was looking for, as it doesn’t play well with LaTeX editors.
Then I proceeded to try out a poor man’s solution to integrating LaTeX with Ipython notebooks such that you can run all cells and generate a decent looking pdf output, that remains fairly dynamic.
This was my first attempt, and it worked rather okay. As I was working on a new project today, I made some rather nice refinements. It remains an inadequate solution, but I get by. Below are the steps I followed, conceptually. You can view the notebook here.
Note ipython notebook was run in –pylab=inline mode
- Place a %%writefile magics command at the start of every section of relevant markdown code cell.
- Then proceed to go about construction your ipython notebook as usual.
- Create a bibliography for yout Ipynb in bibtex format and write to .bib format using the %%writefile magics.
- Write a LaTeX template which you will use to consolidate all the various images and sections into one document.
- Change the Markdown cells to code cells and run the %%writefile function to generate .txt files of the markdown code.
- Write additional latex section you which to insert, such as for images and abstract.
- Use the pandoc (http://johnmacfarlane.net/pandoc/README.html) command line tool from the %%bash magics to convert your markdown code to the appropriate .tex sections that will make is way into the final document.
- Add the appropriate .tex sections to your LaTeX document using the command rather than the command
- Run the bibtex command from bash to generate the bibliography.
- Run the pdflatex command from bash to generate your .pdf doc and display with xdg-open.
I am having fun today.