· John Dummy · 2 min read
Jupyter Notebook Integration
How to write blog posts using Jupyter Notebooks with full LaTeX and code block support.
This blog supports Jupyter notebooks (.ipynb files) by converting them to Markdown, allowing you to share interactive code and mathematical formulations directly with your readers.
Environment Setup
The Python environment is managed with uv and direnv for maximum performance and stability:
- Auto-activation:
direnvautomatically activates the virtual environment when you enter the project directory. - Dependency Management: All requirements are pinned in
requirements.txt.
First-Time Installation
# Sync dependencies
uv pip install -r requirements.txt
# Allow direnv to manage the environment
direnv allow .Creating a Blog Post from a Notebook
- Write your Notebook: Save your
.ipynbfile in thenotebooks/directory. - Convert: Run the conversion script provided in the repository.
python3 scripts/convert-notebook.py notebooks/your-notebook.ipynbThis script performs several automated tasks:
- Converts cells to Markdown.
- Adds appropriate frontmatter (defaulting to
topic: blogandaccessLevel: public). - Relinks and moves generated images (plots, figures) to the correct asset directory.
- Handles LaTeX equations () so they render beautifully using KaTeX.
Features Supported
- ✅ Syntax Highlighting: Automatic for Python, JavaScript, and more.
- ✅ Mathematical Equations: Full support for inline (
$...$) and block ($$...$$) LaTeX. - ✅ Rich Outputs: DataFrames, plots, and console outputs are preserved.
- ✅ Access Control: You can set the
accessLevelin the frontmatter of the converted Markdown.
Best Practices
- Run All Cells: Ensure you execute your notebook before conversion so that the outputs are correctly captured.
- Review Frontmatter: After conversion, check the generated
.mdfile to verify the title and tags are what you intended. - Draft Status: Converted posts are set to
draft: trueby default. Set this tofalsewhen you’re ready to publish.