{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# An example Jupyter Notebook\n", "\n", "This notebook is a demonstration of directly-parsing Jupyter Notebooks into\n", "Sphinx using the MyST parser.[^download]\n", "\n", "[^download]: This notebook can be downloaded as\n", " **{jupyter-download:notebook}`basic`** and {download}`basic.md`\n", "\n", "## Markdown\n", "\n", "As you can see, markdown is parsed as expected. Embedding images should work as expected.\n", "For example, here's the MyST-nb logo:\n", "\n", "\n", "\n", "because MyST-NB is using the MyST-markdown parser, you can include rich markdown with Sphinx\n", "in your notebook. For example, here's a note block:\n", "\n", "`````{note}\n", "Wow, a note! It was generated with this code:\n", "\n", "````\n", "```{note}\n", "Wow, a note!\n", "```\n", "````\n", "`````\n", "\n", "Equations work as expected:\n", "\n", "\\begin{equation}\n", "\\frac {\\partial u}{\\partial x} + \\frac{\\partial v}{\\partial y} = - \\, \\frac{\\partial w}{\\partial z}\n", "\\end{equation}\n", "\n", "And some MyST-specific features like **equation numbering** can be used in notebooks:\n", "\n", "$$e^{i\\pi} + 1 = 0$$ (euler)\n", "\n", "Euler's identity, equation {math:numref}`euler`, was elected one of the\n", "most beautiful mathematical formulas.\n", "\n", "You can see the syntax used for this example [here](https://myst-parser.readthedocs.io/en/latest/using/syntax.html#roles-an-in-line-extension-point).\n", "\n", "## Code cells and outputs\n", "\n", "You can run cells, and the cell outputs will be captured and inserted into\n", "the resulting Sphinx site.\n", "\n", "### `__repr__` and HTML outputs\n", "\n", "For example, here's some simple Python:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Matplotlib is building the font cache; this may take a moment.\n" ] }, { "data": { "text/plain": [ "array([[ 7.65856217, 77.50683455, 76.6292053 , 75.50042516, 9.53204748,\n", " 20.57801603, 78.64515099, 71.24094754, 35.09063661, 78.64697143],\n", " [81.67000198, 15.85152669, 35.30333755, 5.43947639, 44.94160698,\n", " 90.28811921, 82.06552136, 47.91661398, 19.41788208, 2.98159657],\n", " [44.36282524, 34.64668099, 22.23518987, 49.44878042, 66.11661212,\n", " 15.05490797, 71.07759266, 8.03645309, 63.13802588, 73.9903403 ]])" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "data = np.random.rand(3, 100) * 100\n", "data[:, :10]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This will also work with HTML outputs" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | a | \n", "b | \n", "c | \n", "
---|---|---|---|
0 | \n", "7.658562 | \n", "81.670002 | \n", "44.362825 | \n", "
1 | \n", "77.506835 | \n", "15.851527 | \n", "34.646681 | \n", "
2 | \n", "76.629205 | \n", "35.303338 | \n", "22.235190 | \n", "
3 | \n", "75.500425 | \n", "5.439476 | \n", "49.448780 | \n", "
4 | \n", "9.532047 | \n", "44.941607 | \n", "66.116612 | \n", "