Skip to content

Commit

Permalink
DOC: Fixed typo in subsection heading (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbar authored and choldgraf committed Mar 31, 2020
1 parent c9c0cc7 commit be8c94d
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 26 deletions.
8 changes: 8 additions & 0 deletions docs/examples/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Example pages

This section is to collect examples that others can use for inspiration
and reference.

```{toctree}
jupyter_sphinx
```
34 changes: 16 additions & 18 deletions docs/examples/jupyter_sphinx.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
# A Jupyter Sphinx example

```{toctree}
:maxdepth: 2
:caption: "Contents:"
```

Jupyter-sphinx is a Sphinx extension that executes embedded code in a Jupyter
kernel, and embeds outputs of that code in the document. It has support
for rich output such as images, Latex math and even javascript widgets, and
it allows to enable [thebelab](https://thebelab.readthedocs.io/) for live
code execution with minimal effort.

This page describes some jupyter-sphinx functionality and displays it below
for comparison to MyST-NB output.


## Basic Usage

You can use the `jupyter-execute` directive to embed code into the document

````
```{execute}
```{jupyter-execute}
name = 'world'
print('hello ' + name + '!')
```
````

The above is rendered as follows:

```{execute}
```{jupyter-execute}
name = 'world'
print('hello ' + name + '!')
```
Expand All @@ -36,19 +34,19 @@ is rendered directly after the code snippet.
Because all code cells in a document are run in the same kernel, cells later in the document
can use variables and functions defined in cells earlier in the document:

```{execute}
```{jupyter-execute}
a = 1
print('first cell: a = {}'.format(a))
```
```{execute}
```{jupyter-execute}
a += 1
print('second cell: a = {}'.format(a))
```

Because jupyter-sphinx uses the machinery of `nbconvert`, it is capable of rendering
any rich output, for example plots:

```{execute}
```{jupyter-execute}
import numpy as np
from matplotlib import pyplot
Expand All @@ -63,14 +61,14 @@ pyplot.grid()

LaTeX output:

```{execute}
```{jupyter-execute}
from IPython.display import Latex
Latex('∫_{-∞}^∞ e^{-x²}dx = \sqrt{π}')
```
or even full-blown javascript widgets:

```{execute}
```{jupyter-execute}
import ipywidgets as w
from IPython.display import display
Expand All @@ -87,7 +85,7 @@ display(a, b)
You may choose to hide the code of a cell, but keep its output visible using `:hide-code:`

````
```{execute}
```{jupyter-execute}
:hide-code:
print('this code is invisible')
Expand All @@ -96,7 +94,7 @@ print('this code is invisible')

produces:

```{execute}
```{jupyter-execute}
:hide-code:
print('this code is invisible')
Expand All @@ -105,29 +103,29 @@ print('this code is invisible')
or vice versa with ``:hide-output:``::

````
```{execute}
```{jupyter-execute}
:hide-output:
print('this output is invisible')
```
````

```{execute}
```{jupyter-execute}
:hide-output:
print('this output is invisible')
```

You may also display the code *below* the output with ``:code-below:``::

```{execute}
```{jupyter-execute}
:code-below:
print('this output is above the code')
```

You may also add *line numbers* to the source code with ``:linenos:``::

```{execute}
```{jupyter-execute}
:linenos:
print('A')
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ In addition, here is a reference page that uses the `jupyter-sphinx` package to
outputs, to compare how these outputs look relative to the MyST-NB style.

```{toctree}
examples/jupyter_sphinx.md
examples/index.md
```

Finally, here is documentation on contributing to the development of MySt-NB
Expand Down
19 changes: 18 additions & 1 deletion docs/use/basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"as well as math outputs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Math\n",
"Math(\"\\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -148,7 +165,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.1"
"version": "3.7.3"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down
2 changes: 1 addition & 1 deletion docs/use/glue.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### The `glu` role/directive\n",
"### The `glue` role/directive\n",
"\n",
"The simplest role and directive are `glue:any`,\n",
"which paste the glued output inline or as a block respectively,\n",
Expand Down
1 change: 1 addition & 0 deletions docs/use/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ A collection of example pages to see how notebook content is rendered
in Sphinx with MyST-NB.

```{toctree}
:maxdepth: 1
basic
interactive
hiding
Expand Down
6 changes: 3 additions & 3 deletions docs/use/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
MyST-NB also provides functionality for notebooks within markdown. This lets you
include and control notebook-like behavior from with your markdown content.

The primary way to accomplish this is with the `{execute}` directive. The content
The primary way to accomplish this is with the `{jupyter-execute}` directive. The content
of this directive should be runnable code in Jupyter. For example, the following
code:

````
```{execute}
```{jupyter-execute}
a = "This is some"
b = "Python code!"
print(f"{a} {b}")
Expand All @@ -17,7 +17,7 @@ print(f"{a} {b}")

Yields the following:

```{execute}
```{jupyter-execute}
a = "This is some"
b = "Python code!"
print(f"{a} {b}")
Expand Down
2 changes: 0 additions & 2 deletions myst_nb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ def visit_element_html(self, node):
app.connect("config-inited", update_togglebutton_classes)
app.connect("env-updated", save_glue_cache)
app.add_css_file("mystnb.css")
# We use `execute` here instead of `jupyter-execute`
app.add_directive("execute", JupyterCell)
app.setup_extension("jupyter_sphinx")
app.add_domain(NbGlueDomain)

Expand Down
5 changes: 5 additions & 0 deletions myst_nb/_static/mystnb.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ div.section div.jupyter_container {
border: 1px solid #ffd6d6;
}

/* Math align to the left */
.cell_output .MathJax_Display {
text-align: left !important;
}

/* Pandas tables. Pulled from the Jupyter / nbsphinx CSS */
div.cell_output table {
border: none;
Expand Down

0 comments on commit be8c94d

Please sign in to comment.