Converting a Jupyter Notebook to Pdf
Published in
Nov 16, 2020
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: