A more accurate representation of jupyter notebooks when converting to pdfs. This template was designed to make converted jupyter notebooks look (almost) identical to the actual notebook. If something doesn't exist in the original notebook then it doesn't belong in the conversion.
Work is in progress for updating this for nbconvert 7.0. Minimal changes were needed to make the template itself work, so it should work with nbconvert 6.0 as well, but officially nbconvert 5 and 6 won't be supported. Once I have figured out the new template install process, I will push a release.
- \maketitle is removed (If you want a title then add a markdown cell to the top of your notebook).
- Sections are no longer numbered automatically (notebooks don't number sections so the pdf shouldn't).
- Markdown paragraphs are no longer auto-indented in the pdf.
- Syntax highlighting improvements. (Bonus if using XeLaTeX)
-
BOXES! are drawn around code cells.(This change was merged into nbconvert 5.5.0) -
In/Out counts will move to the left as the execution count increases instead of pushing code to the right (only numbers are displayed by default to save page width).(This change was merged into nbconvert 5.5.0) -
(This change was merged into nbconvert 5.4.0)$\LaTeX$ and$\Tex$ in markdown cells will no longer cause conversion to fail. - "\LaTeX" and "\TeX" are no longer converted into a logo on conversion to pdf unless they are in math mode. (This and the above point replicate the functionality of these commands in notebook markdown).
-
In/Out prompt colours updated to match Jupyter.(This change was merged into nbconvert 5.5.0) -
Output text wrapping improvements.(This change was merged into nbconvert 5.5.0) -
Code cell text wrapping.(This change was merged into nbconvert 5.5.0)
Quick Comparison: for a closer look see the example directory.
pip install nb_pdf_template
python -m nb_pdf_template.install
pip install -U nb_pdf_template
python -m nb_pdf_template.install
Drop all of the "*.tplx" files into the folder containing the other LaTeX nbconvert templates. If using anaconda, it should be something like:
*/Anaconda3/Lib/site-packages/nbconvert/templates/latex
From the command line:
jupyter nbconvert --to pdf filename.ipynb --template classic
Adding:
c.LatexExporter.template_file = 'classic'
to the jupyter_nbconvert_config.py
file will let you drop the "--template classic", and to the jupyter_notebook_config.py
file will let you use "download as pdf" from within the Jupyter notebook.
Replace classic
with your template of choice.
This package offers the following templates:
Template | Use |
---|---|
classic.tplx (Recommended) | For most accurate recreation of the default Jupyter Notebook style. |
classicm.tplx | m for modified. Similar to classic.tplx, but in/out prompts are above cells instead of in the margin. Bonus left margins are smaller so code cells are wider. |