LaTeX templates for Jupyter notebook conversion to PDF
Project description
An Authentic LaTeX Conversion Template for Jupyter Notebooks.
A more accurate representation of jupyter notebooks when converting to pdf. 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.
This repository also acts as a reference for how to package nbconvert templates to be pip installable without using exporters and entry points.
Improvements
- \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.
- Syntax highlighting improvements. (Bonus if using XeLaTeX)
- "\LaTeX" and "\TeX" are no longer converted into a logo on conversion to pdf unless they are in math mode. (replicating the functionality of these commands in notebook markdown).
Markdown paragraphs are no longer auto-indented in the pdf.(This change was merged into nbconvert 5.5.0)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)$\LaTeX$ and $\Tex$ in markdown cells will no longer cause conversion to fail.(This change was merged into nbconvert 5.4.0)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.
Pygments
This repository also contains a pygments style called jupyter_python that can be used programmatically and was used in previous versions of the template. Syntax highlighting improvements are done without the style though as it was insufficient to achieve the highlighting quality I wanted, and it needed a shell escape.
Installation
If you have multiple python interpreters installed, but sure to install on the one with nbconvert. Otherwise, the templates will be put into the wrong data folder.
pip install nb_pdf_template
Updating
pip install -U nb_pdf_template
Manual Install:
Drop the "latex_authentic" folder into the folder containing the other LaTeX nbconvert templates. If using anaconda, it should be something like:
*/Anaconda3/share/jupyter/nbconvert/templates
Uninstalling
pip uninstall nb_pdf_template
or if manually installed then remove the files manually.
Use
From the command line:
jupyter nbconvert --to pdf filename.ipynb --template latex_authentic
Config file:
c.LatexExporter.template_name = 'latex_authentic'
The jupyter_nbconvert_config.py file will let you drop the "--template latex_authentic" in the cli, and to the jupyter_notebook_config.py or jupyter_lab_config.py files will let you use "download as pdf" from within Jupyter Notebook/Lab with the template.
You can also use the --template-file flag or c.LatexExporter.template_file= variable to change the index file with the following options:
| Option | Use | Text wrapping length |
|---|---|---|
| index | This is the default. | 89 |
| index_A4 | A4 paper version of the default. | 85 |
| m | Prompts above the cells instead of to the left. | 94 |
| m_A4 | A4 paper version of the above. | 90 |
Build
To build the package use
hatch build
Tips (Good for any template)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nb_pdf_template-5.0.1.tar.gz.
File metadata
- Download URL: nb_pdf_template-5.0.1.tar.gz
- Upload date:
- Size: 308.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
229580d6bd7c7f65c969eb078661edf722b04a490049d7532631297f7b7ffc40
|
|
| MD5 |
8f4d4964e06ad5edb4909c74bb20dcfe
|
|
| BLAKE2b-256 |
84f422736522c0d15aa41dcd6fd0416f1e58c02f3515c394a26a20ad7b76123f
|
File details
Details for the file nb_pdf_template-5.0.1-py3-none-any.whl.
File metadata
- Download URL: nb_pdf_template-5.0.1-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99c612a7d6f56590346ae877ad49a12eb83d2c5865503ceba4ea48e4376a1e62
|
|
| MD5 |
f0a0c0fbf228c67905851d74b4aa8a5a
|
|
| BLAKE2b-256 |
023a3e9b8b51e0ba3b7b34ffac67b1e8e2e9e59a0d64032a1cbc47a6e835292d
|