A Sphinx Extension for Generating Jupyter Notebooks
Installation
To install you can clone the repository and install using:
python setup.py install
Usage
Update project conf.py file to include the jupyter extension and the
desired configuration settings (see configuration
section below):
extensions = ["sphinx_tojupyter"]
then run
make jupyter
Features
MyST-NB Glue Support
This extension supports MyST-NB glue functionality, allowing you to store and reference notebook variables in your documentation:
Basic Usage:
\```python from myst_nb import glue glue("my_variable", "Hello World") glue("my_number", 3.14159) \``` The value is {glue:text}`my_variable` and pi is approximately {glue:text}`my_number:.2f`.
Figure Glue:
\```python import matplotlib.pyplot as plt from myst_nb import glue fig, ax = plt.subplots() ax.plot([1, 2, 3], [1, 4, 9]) glue("my_plot", fig, display=False) \``` \```{glue:figure} my_plot :name: fig-example Caption for the figure. \```
Requirements:
- Add
myst_nbto your extensions inconf.py - Set
nb_execution_mode = "cache"(or "auto"/"force")
See the test suite for more examples.
sphinx-proof Support
Full support for sphinx-proof directives, allowing you to include mathematical theorems, proofs, and related content in your notebooks:
Supported Directives (15 types):
theorem,axiom,lemma,definition,remarkconjecture,corollary,algorithm,criterionexample,property,observation,propositionassumption,notation,proof
Example:
\```{prf:theorem} Pythagorean Theorem :label: pythagoras In a right triangle, the square of the hypotenuse equals the sum of squares of the other two sides: $$ a^2 + b^2 = c^2 $$ \``` \```{prf:proof} The proof follows from... \```
Features:
- ✅ Automatic numbering from Sphinx's numfig system
- ✅ Support for titled and untitled directives
- ✅ Cross-reference handling
- ✅ Clean markdown formatting for notebooks
Requirements:
- Add
sphinx_proofto your extensions inconf.py - Enable
numfig = Truefor numbered directives
See the test suite for comprehensive examples.
LaTeX Macros Support
Define custom LaTeX commands once, use everywhere (HTML and notebooks):
# conf.py mathjax3_config = { 'tex': { 'macros': { 'ZZ': r'\mathbb{Z}', 'RR': r'\mathbb{R}', 'NN': r'\mathbb{N}', } } }
Then use them in your documentation:
The set of integers is $\ZZ$ and the reals are $\RR$.
Benefits:
- ✅ Single configuration for HTML and notebooks
- ✅ Standard Sphinx/Jupyter Book approach
- ✅ Macros automatically added to generated notebooks
- ✅ Works with existing
mathjax3_configsetups
See the LaTeX macros documentation and test suite for more details.
Credits
This project is supported by QuantEcon. The writers and translators have been migrated and improved from the sphinxcontrib-jupyter project.
Many thanks to the contributors of this project.
LICENSE
Copyright © 2020 QuantEcon Development Team: BSD-3 All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.