Introducing Jupyter Notebooks in Sphinx
This notebook showcases very basic functionality of rendering your jupyter notebooks as tutorials inside your sphinx documentation.
As part of the LINCC Frameworks python project template, your notebooks will be executed AND rendered at document build time.
You can read more about Sphinx, ReadTheDocs, and building notebooks in LINCC’s documentation
[1]:
def sierpinsky(order):
"""Define a method that will create a Sierpinsky triangle of given order,
and will print it out."""
triangles = ["*"]
for i in range(order):
spaces = " " * (2**i)
triangles = [spaces + triangle + spaces for triangle in triangles] + [
triangle + " " + triangle for triangle in triangles
]
print(f"Printing order {order} triangle")
print("\n".join(triangles))
Then, call our method a few times. This will happen on the fly during notebook rendering.
[2]:
for order in range(3):
sierpinsky(order)
Printing order 0 triangle
*
Printing order 1 triangle
*
* *
Printing order 2 triangle
*
* *
* *
* * * *
[3]:
sierpinsky(4)
Printing order 4 triangle
*
* *
* *
* * * *
* *
* * * *
* * * *
* * * * * * * *
* *
* * * *
* * * *
* * * * * * * *
* * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * * * * * * * *