Skillversitas

Converting Notebooks

nbconvert is the standard tool for turning .ipynb documents into other formats: scripts, HTML, PDF, slides, and more. It executes the notebook (or not), applies a template, and writes the target format - the bridge between "living document" and "shareable artifact".

Notebook to Python Script

jupyter nbconvert --to script mynotebook.ipynb
# writes mynotebook.py with cell contents as code (markdown as comments or stripped)

Notebook to HTML

jupyter nbconvert --to html mynotebook.ipynb
jupyter nbconvert --to html --execute mynotebook.ipynb   # run cells first

The HTML output embeds CSS so it renders standalone - suitable for emailing or posting to a static site.

Notebook to PDF

jupyter nbconvert --to pdf mynotebook.ipynb

PDF conversion goes through LaTeX (via the LaTeX template); you need a working LaTeX installation (tlmgr on Linux, MacTeX on macOS, MiKTeX on Windows) and a TeX template with the right fonts.

Notebook to Slides (Reveal.js)

jupyter nbconvert --to slides mynotebook.ipynb
# separate slides with cell tags: slide, subslide, fragment
# (Cell -> Edit Metadata in the UI adds tags)

Custom Templates

jupyter nbconvert --to html --template basic mynotebook.ipynb
jupyter nbconvert --to html --template my_template --self-contained mynotebook.ipynb

Templates are Jinja2; --self-contained inlines CSS/JS for a single-file artifact. This is how branded reports come out of notebooks.

Cleaning Before Export

jupyter nbconvert --to notebook \
  --ClearOutputPreprocessor.enabled=True \
  --ExecutePreprocessor.enabled=False \
  --inplace mynotebook.ipynb

Clearing outputs and resetting execution counts before committing or sharing makes diffs clean and guarantees the reader's first run is a true run.

Summary

Use jupyter nbconvert --to script/html/pdf/slides to turn notebooks into scripts, standalone HTML, PDFs (via LaTeX), and Reveal.js slide decks; --execute runs cells before conversion, and templates plus --self-contained produce branded single-file reports. Clean outputs with the ClearOutput preprocessor before exporting or committing.