Skip to content

Commit

Permalink
DOC: Show how to use Markdown source files
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed May 12, 2021
1 parent 5f702d2 commit 80103c5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/README.md → doc/README
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This folder contains the source files for the documentation.
See [CONTRIBUTING](../CONTRIBUTING.rst) for how to create the HTML and LaTeX
See ../CONTRIBUTING.rst for how to create the HTML and LaTeX
files from these sources.

The online documentation is available at https://nbsphinx.readthedocs.io/.
43 changes: 43 additions & 0 deletions doc/a-markdown-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Using Markdown Files

Sphinx on its own doesn't know how to handle Markdown files,
but there are extensions that enable their usage as Sphinx source files.
For an example, see the
[Sphinx documentation](https://www.sphinx-doc.org/en/master/usage/markdown.html).

Alternatively, when using `nbsphinx` it is also possible to use Markdown
files via [custom notebook formats](custom-formats.ipynb).

You only need to install the [jupytext](https://jupytext.readthedocs.io/)
package and add a configuration setting to `conf.py`,
which can be used to select one of
[several Markdown flavors supported by jupytext](https://jupytext.readthedocs.io/en/latest/formats.html#markdown-formats)
(here we are using R Markdown):

```python
nbsphinx_custom_formats = {
'.md': ['jupytext.reads', {'fmt': 'Rmd'}],
}
```

This very page was generated from a Markdown file using these settings.


## Links to Notebooks (and Other Sphinx Source Files)

Links to other Sphinx source files can be created like in
[Markdown cells of notebooks](markdown-cells.ipynb#Links-to-Other-Notebooks).


## Math

Math equation can be used just like in
[Markdown cells of notebooks](markdown-cells.ipynb#Equations).

Inline like this: $\text{e}^{i\pi} = -1$.

Or as a separate block:

\begin{equation*}
\int\limits_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
\end{equation*}
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
# Support for notebook formats other than .ipynb
nbsphinx_custom_formats = {
'.pct.py': ['jupytext.reads', {'fmt': 'py:percent'}],
'.md': ['jupytext.reads', {'fmt': 'Rmd'}],
}

# -- The settings below this line are not specific to nbsphinx ------------
Expand Down
3 changes: 2 additions & 1 deletion doc/custom-formats.pct.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
# .. literalinclude:: conf.py
# :language: python
# :start-at: nbsphinx_custom_formats
# :lines: -3
# :lines: -4
# :emphasize-lines: 2

# %% [markdown]
# Another example is [this gallery example page](gallery/due-rst.pct.py).
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ was generated from Jupyter notebooks.
subdir/*
custom-css
a-normal-rst-file
a-markdown-file
links
contributing
version-history
Expand Down

0 comments on commit 80103c5

Please sign in to comment.