DS4N6

Originally published at http://www.ds4n6.io.

jupyter nbconvert my_notebook.ipynb --to pdf

If you want to change the font size, for instance, you can do it through overriding templates ( docs, base templates), but it can get complex. So the easiest way is to convert to LaTeX first, do some simple replacements, and then convert the resulting LaTeX to pdf via the pdflatex utility:

$ jupyter nbconvert --to latex my_notebook.ipynb
$ sed -r -i 's/documentclass\[11pt\]\{article\}/documentclass[8pt]{extarticle}/' my_notebook.tex # <---- This modifies the font size from 11pt to 8pt
$ sed -r -i 's/geometry\{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}/geometry{verbose,tmargin=0.5in,bmargin=0.5in,lmargin=0.2in,rmargin=0.2in}/' my_notebook.tex # <---- This sets the margins
$ pdflatex my_notebook
$ rm my_notebook.tex; rm my_notebook.out; rm my_notebook.aux; rm Requirements:

Requirements:

  • texlive-xetex must be installed in the system (Ubuntu installation: apt-get install texlive-xetex texlive-generic-extra)

Refs:

--

--

Originally published at http://www.ds4n6.io.

import nbformat as nbfnb = nbf.v4.new_notebook()# Text Cell ---------------------------------
text = """\
# My first automatic Jupyter Notebook
This is an auto-generated notebook."""
# Code Cell ---------------------------------
code = """\
%pylab inline
hist(normal(size=2000), bins=50);"""
# Create & Save the Notebook ----------------
nb['cells'] = [nbf.v4.new_markdown_cell(text), nbf.v4.new_code_cell(code) ]
nbf.write(nb, 'test.ipynb')
# You can run this notebook from the command line (if you want):
jupyter nbconvert --execute --inplace test.ipynb

Refs:

--

--

DS4N6

DS4N6

Community focused on bringing Data Science & Artificial Intelligence to the fingertips of the average Forensicator and promoting advances in the field.