# [IPython-dev] Including IPython notebooks as subsections in a LaTeX document?

Tue May 27 17:01:44 EDT 2014

On Tue, May 27, 2014 at 11:23 AM, Maximilian Albert <
maximilian.albert at gmail.com> wrote:

> Hi all,
>
> apologies if this has been asked before - it sounds like such a natural
> question that I can't imagine it hasn't, but I can't seem to find any
> information on it (maybe I'm using the wrong keywords for my search).
>
> I'm interested in including (converted) IPython notebooks as subsections
> in a bigger LaTeX document. What is the best way to achieve this?
>
> Ideally, I would like to have a .tex document that looks like this:
>
> ==>
> \documentclass{article}
>
> % Load the IPython style definitions somehow
>
> \begin{document}
>
> \section{Introduction}
> blah blah blah
>
> \section{Contents of first notebook}
> \include{awesome_notebook}
>
> \section{Foobar}
> blah blah blah
>
> \section{Contents of second notebook}
> \include{awesome_notebook_02}
>
> % ... some other sections ...
>
> \end{document}
> <==
>
> The .tex files for the notebooks would be provided by nbconvert:
>
>    \$ ipython nbconvert --to latex --template inline awesome_notebook.ipynb
>
> Obviously the "inline" template doesn't exist (yet), but what I'd like it
> to do is produce a .tex file of the "bare-bones" contents of the notebook
> which can just be included in a document like the above. Naturally, I would
> also need a .tex or .sty file somewhere which provides the commands that
> usually go into the preamble of the converted notebook.
>
> My first thought was to copy the template 'base.tplx' that comes with
> IPython and adapt it so that it only contains the bits between
> "\begin{document}" and "\end{document}". The preamble commands could be
> copied into a separate file that I can then load once in the preamble of my
> bigger document.
>
> However, I was wondering if there is a simpler/more elegant approach, or
> if anyone has any better ideas how to include notebooks in LaTeX documents?
>

Max, your approach sounds correct to me.  I'm not aware of many
simpler/elegant solutions, mostly just "afternoon hacks" :)

A
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140527/b7d013cc/attachment.html>