Workflow for including jupyter (aka ipython) notebooks as pages in a LaTeX documents?

For Option 2, does it do what you want if you use something like this?

\includepdf[
    %% Include all pages of the PDF
    pages=-,
    %% make this page have the usual page style
    %% (you can change it to plain etc). By default pdfpages
    %% sets the pagecommand to \pagestyle{empty}
    pagecommand={\pagestyle{headings}},  
    %% Add a "section" entry to the ToC with the heading
    %% "Quilling Shapes" and the label "sec:shapes"
    addtotoc={1,section,1,Quilling Shapes,sec:shapes}]
%% The pdf file itself
{QuillingShapes.pdf}

Here is how I like to include Jupyter notebooks in a LaTeX document with \include{}.

Outline

  1. In the Jupyter Notebook, use the raw option for non-code exposition which contains LaTeX. This is achieved by selecting the cell and then pressing ESC followed by R. The cell might look like this:
This is some text in the notebook which contains LaTeX.  
So we can write $\theta \in (0,1)$ or cite \ref{chapter1}  
from elsewhere in the Latex file.

Your LaTeX can reference whatever you like in the overall LaTeX document.

  1. Use nbconvert to output to markdown first. Suppose your notebook is named test.ipynb. Then use
jupyter nbconvert --to markdown test.ipynb

This code creates test.md which is the intermediate file.

  1. Use Pandoc to convert the markdown into LaTeX, as in
pandoc --listings -f markdown -t latex test.md -o test.tex

This will create test.tex which can then be inserted into your main LaTeX document with \include{test.tex}.
Note: The listings package must be available to your LaTeX installation. Dropping the --listings option works, but produces Tex which includes many additional command sequences you may not want in your main Tex file. Add the standalone option in order to preview the pdf or the see which command sequences and packages you might want to include in your main Latex document:

pandoc --listings -f markdown -t latex test.md -s -o test.tex
pdflatex test.tex

You can then open the pdf test.pdf for a preview.


Take a look at Authorea (http://www.authorea.com) - it's similar to Overleaf, but offers a few more advanced features, including easy integration of ipython notebooks. See https://www.authorea.com/users/9932/articles/11070 for more info

Tags:

Thesis