0.3.0

Notebook parsing, MathRole KaTeX compatibility

2 min read 471 words 2 days ago

Released: 2026-02-14

Native Jupyter notebook support and improved math rendering for KaTeX users.


Highlights

  • parse_notebook() — Convert Jupyter .ipynbfiles to Markdown content and metadata. Zero dependencies. Use notebooks as content sources for static sites, docs, or custom pipelines.
  • MathRole fix — The{math} role for inline math now outputs raw LaTeX (no \( \) delimiters), matching the math plugin. Both work seamlessly with KaTeX's katex.render().

Features

Notebook Parsing

Parse Jupyter notebooks (.ipynb) into Markdown content and structured metadata — the same shape you get from Markdown files with frontmatter. No nbformat dependency; uses stdlib jsononly.

Basic usage:

from patitas import parse_notebook, parse, render

with open("tutorial.ipynb") as f:
    content, metadata = parse_notebook(f.read(), "tutorial.ipynb")

# content: Markdown string (ready for parse() or render)
# metadata: title, type, notebook info, optional Jupytext/date/tags
doc = parse(content)
html = render(doc)

What you get:

Cell type Conversion
Markdown cells Passed through as Markdown
Code cells Wrapped in fenced code blocks (language from metadata)
Code outputs Rendered as HTML (images, HTML, plain text, errors)
Raw cells Passed through as-is

Metadata extracted:

  • title— From notebook metadata, Jupytext, or filename fallback
  • type — Always "notebook"
  • notebook.kernel_name — e.g. "python3"
  • notebook.cell_count— Number of cells
  • notebook.language_version— Kernel language
  • Optional:date, tags, authors, summary, description(if present in metadata)

Use cases:

  • Static site generators — Drop.ipynbinto content; Bengal uses this for native notebook rendering
  • Documentation — Build docs from notebooks without running them
  • Custom pipelines — Extract content for search, indexing, or conversion

Requirements: nbformat 4 or 5. Older formats raiseValueErrorwith a clear message.

MathRole — KaTeX Compatibility

The{math} role for inline math now emits raw LaTeX, matching the math plugin's output. Both produce the same structure expected by KaTeX's katex.render().

Before (0.2.x): MathRole wrapped content in\( \)delimiters, which could conflict with KaTeX's expectations.

After (0.3.0): Both the math plugin and MathRole output raw LaTeX inside a<span class="math notranslate nohighlight">element. KaTeX can render them identically.

Example:

The equation {math}`E = mc^2` is famous.

Block math uses $$...$$ or the math plugin.

Role syntax: {math}followed by backtick-delimited expression.

Renders to HTML suitable for client-side KaTeX:

The equation <span class="math notranslate nohighlight">E = mc^2</span> is famous.

Use with KaTeX:

document.querySelectorAll('.math').forEach(el => {
  katex.render(el.textContent, el, { throwOnError: false });
});

Installation

pip install patitas>=0.3.0
pip install patitas[syntax]   # Optional: syntax highlighting via Rosettes

Breaking Changes

None — all changes are backwards compatible.


Documentation

  • API Referenceparse_notebook(), parse(), render()
  • Bengal — Static site generator with native notebook support