Directory macros/latex/contrib/pyjupyter
README.md
PYJUPYTER
A lightweight LaTeX package that provides a clean Python code environment inspired by Jupyter notebooks.
Author : BARA O. Bright
Description
The pyjupyter package defines a jupyter environment for displaying Python code in a visually structured box.
It combines :
listings for syntax highlighting
tcolorbox for the visual container
optionally the sourcecodepro font for improved monospaced typography
The design philosophy of the package is to remain minimal, robust, and compatible with standard LaTeX workflows.
Typical use cases include:
scientific and technical reports
programming assignments
lecture notes
computational or reproducible research documents
The package does not attempt to replicate the full Jupyter interface, but rather provides a simple and elegant way to include Python code blocks in LaTeX documents.
Contents
pyjupyter.sty : The LaTeX style file
README.md : This file
pyjupyter.pdf if you have documentation
Requirements
Mandatory dependencies :
tcolorbox
listings
xcolor
Optional dependency : sourcecodepro (for better monospaced font rendering)
All mandatory dependencies are part of standard LaTeX distributions such as TeX Live or MiKTeX.
Installation
This package is meant to be installed automatically by TeXLive, MikTeX, etc.
Otherwise, place pyjupyter.sty in :
the same directory as your .tex document or
a local TEXMF tree
Then load it in your document :
\usepackage{pyjupyter}
Basic usage
Example:
\begin{jupyter}[]
# Example Python code
def square(x):
return x**2
print(square(4))
\end{jupyter}
Important Note About the Brackets
The jupyter environment must always be invoked with brackets immediately after \\begin{jupyter} :
\begin{jupyter}[]
even when no options are specified.
Reason
Python comments begin with the character #.
Due to the way TeX parses macro arguments, starting the environment directly with a # character can conflict with parameter parsing in macro definitions.
Providing the optional argument brackets ensures that the environment is initialized correctly before the code is processed by listings.
This prevents errors when the first line of code is a Python comment.
Customization
The environment accepts all tcolorbox options :
Example :
\begin{jupyter}[colback=blue!5]
print("Custom background")
\end{jupyter}
You may also pass options to listings :
\begin{jupyter}[listing options={numbers=left}]
print("Line numbers enabled")
\end{jupyter}
But for line numbering, it is highly recommended to use the built-in numbered option rather than passing manual listing options :
\begin{jupyter}[numbered]
print("Line numbers enabled (recommended)")
\end{jupyter}
You can still pass other custom options to listings if needed :
\begin{jupyter}[listing options={basicstyle=\ttfamily\small}]
print("Custom styles")
\end{jupyter}
License
This package is distributed under the LaTeX Project Public License (LPPL) version 1.3c.
Changes
First public version: 1.0.0
Copyright 2026 BARA O. Bright
E-mail: barabright62 (at) gmail (dot) com
Download the contents of this package in one zip archive (170.9k).
pyjupyter – Lightweight environment for typesetting Python code
The pyjupyter package provides a lightweight and elegant environment for typesetting Python code in LaTeX documents with a visual style inspired by Jupyter notebooks.
It leverages the listings package for syntax highlighting and tcolorbox for structured, breakable frames. Key features include:
- Full support for French accents and UTF-8 encoding.
- Intelligent syntax highlighting for Python operators and keywords.
- A dedicated numbered option for line numbering.
- Seamless integration with TeXstudio via an included .cwl file for auto-completion.
- Robust handling of Python comments (#) using an optional argument syntax.
| Package | pyjupyter |
| Version | 1.0.0 2026-03-06 |
| Licenses | The LaTeX Project Public License 1.3c |
| Copyright | 2026 Bara Ouyèté Bright |
| Maintainer | Bara Ouyèté Bright |
| Topics | Listing |
| See also | pynotebook |