Skip to content

Commit 31937b7

Browse files
committed
Bootstrapping example project from jupyter-book create docs/
0 parents  commit 31937b7

File tree

11 files changed

+425
-0
lines changed

11 files changed

+425
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
docs/conf.py
2+
docs/_build

README.rst

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Example: Jupyter Book for Read the Docs
2+
=======================================
3+
4+
.. image:: https://readthedocs.org/projects/example-jupyter-book/badge/?version=latest
5+
:target: https://example-jupyter-book.readthedocs.io/en/latest/?badge=latest
6+
:alt: Documentation Status
7+
8+
.. This README.rst should work on Github and is also included in the Sphinx documentation project in docs/ - therefore, README.rst uses absolute links for most things so it renders properly on GitHub
9+
10+
This example shows a Jupyter Book project with Read the Docs. You're encouraged to view it to get inspiration and copy & paste from the files in the source code. If you are using Read the Docs for the first time, have a look at the official `Read the Docs Tutorial <https://docs.readthedocs.io/en/stable/tutorial/index.html>`__.
11+
12+
📚 `docs/ <https://github.com/readthedocs-examples/example-jupyter-book/blob/main/docs/>`_
13+
A basic Jupyter Book project lives in ``docs/``. All the ``*.md`` make up sections in the documentation.
14+
⚙️ `.readthedocs.yaml <https://github.com/readthedocs-examples/example-jupyter-book/blob/main/.readthedocs.yaml>`_
15+
Read the Docs Build configuration is stored in ``.readthedocs.yaml``.
16+
⚙️ `docs/config.yml <https://github.com/readthedocs-examples/example-jupyter-book/blob/main/docs/conf.py>`_
17+
This is the configuration for Jupyter Book which is used to generate a Sphinx-configuration on-the-fly. However, the Sphinx ``conf.py`` file is NOT managed in a git repository, as it is managed by Jupyter Book!
18+
📍 `docs/requirements.txt <https://github.com/readthedocs-examples/example-jupyter-book/blob/main/docs/requirements.txt>`_ and `docs/requirements.in <https://github.com/readthedocs-examples/example-jupyter-book/blob/main/docs/requirements.in>`_
19+
Python dependencies are `pinned <https://docs.readthedocs.io/en/latest/guides/reproducible-builds.html>`_ (uses `pip-tools <https://pip-tools.readthedocs.io/en/latest/>`_). Make sure to add your Python dependencies to ``requirements.txt`` or if you choose [pip-tools](https://pip-tools.readthedocs.io/en/latest/), edit ``docs/requirements.in`` and remember to run ``pip-compile docs/requirements.in``.
20+
🔢 Git tags versioning
21+
We use a basic versioning mechanism by adding a git tag for every release of the example project. All releases and their version numbers are visible on `example-jupyter-book.readthedocs.io <https://example-jupyter-book.readthedocs.io/en/latest/>`__.
22+
📜 `README.rst <https://github.com/readthedocs-examples/example-jupyter-book/blob/main/README.rst>`_
23+
Contents of this ``README.rst`` are visible on Github and included on `the documentation index page <https://example-jupyter-book.readthedocs.io/en/latest/>`_ (Don't Repeat Yourself).
24+
⁉️ Questions / comments
25+
If you have questions related to this example, feel free to can ask them as a Github issue `here <https://github.com/readthedocs-examples/example-jupyter-book/issues>`_.
26+
27+
28+
Example Project usage
29+
---------------------
30+
31+
This project has a standard Sphinx layout which is built by Read the Docs almost the same way that you would build it locally (on your own laptop!).
32+
33+
You can build and view this documentation project locally - we recommend that you activate `a local Python virtual environment first <https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment>`_:
34+
35+
.. code-block:: console
36+
37+
# Install required Python dependencies (Sphinx etc.)
38+
pip install -r docs/requirements.txt
39+
40+
# Enter the Sphinx project
41+
cd docs/
42+
43+
# Run the raw sphinx-build command
44+
sphinx-build -M html . _build/
45+
46+
47+
You can also build the documentation locally with ``make``:
48+
49+
.. code-block:: console
50+
51+
# Enter the Sphinx project
52+
cd docs/
53+
54+
# Build with make
55+
make html
56+
57+
# Open with your preferred browser, pointing it to the documentation index page
58+
firefox _build/html/index.html
59+
60+
61+
Using the example in your own project
62+
-------------------------------------
63+
64+
If you are new to Read the Docs, you may want to refer to the `Read the Docs User documentation <https://docs.readthedocs.io/>`_.
65+
66+
If you are copying this code in order to get started with your documentation, you need to:
67+
68+
#. place your ``docs/`` folder alongside your Python project. If you are starting a new project, you can adapt the `pyproject.toml` example configuration.
69+
#. use your existing project repository or create a new repository on Github, GitLab, Bitbucket or another host supported by Read the Docs
70+
#. copy ``.readthedocs.yaml`` and the ``docs/`` folder into your project.
71+
#. customize all the files, replacing example contents.
72+
#. add your own Python project, replacing the ``pyproject.toml`` configuration and ``lumache.py`` module.
73+
#. rebuild the documenation locally to see that it works.
74+
#. *finally*, register your project on Read the Docs, see `Importing Your Documentation <https://docs.readthedocs.io/en/stable/intro/import-guide.html>`_.
75+
76+
77+
Read the Docs tutorial
78+
----------------------
79+
80+
To get started with Read the Docs, you may also refer to the `Read the Docs tutorial <https://docs.readthedocs.io/en/stable/tutorial/>`__.
81+
It provides a full walk-through of building an example project similar to the one in this repository.

docs/_config.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Book settings
2+
# Learn more at https://jupyterbook.org/customize/config.html
3+
4+
title: Example Jupyter Book for Read the Docs
5+
author: Read the Docs team
6+
logo: logo.png
7+
8+
# Force re-execution of notebooks on each build.
9+
# See https://jupyterbook.org/content/execute.html
10+
execute:
11+
execute_notebooks: force
12+
13+
# Define the name of the latex output file for PDF builds
14+
latex:
15+
latex_documents:
16+
targetname: book.tex
17+
18+
# Add a bibtex file so that we can create citations
19+
bibtex_bibfiles:
20+
- references.bib
21+
22+
# Information about where the book exists on the web
23+
repository:
24+
url: https://github.com/readthedocs-examples/example-jupyter-book # Online location of your book
25+
path_to_book: docs # Optional path to your book, relative to the repository root
26+
branch: main # Which branch of the repository should be used when creating links (optional)
27+
28+
# Add GitHub buttons to your book
29+
# See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository
30+
html:
31+
use_issues_button: true
32+
use_repository_button: true

docs/_toc.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Table of contents
2+
# Learn more at https://jupyterbook.org/customize/toc.html
3+
4+
format: jb-book
5+
root: intro
6+
chapters:
7+
- file: markdown
8+
- file: notebooks
9+
- file: markdown-notebooks

docs/intro.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Welcome to your Jupyter Book
2+
3+
This is a small sample book to give you a feel for how book content is
4+
structured.
5+
It shows off a few of the major file types, as well as some sample content.
6+
It does not go in-depth into any particular topic - check out [the Jupyter Book documentation](https://jupyterbook.org) for more information.
7+
8+
Check out the content pages bundled with this sample book to see more.
9+
10+
```{tableofcontents}
11+
```

docs/logo.png

9.62 KB
Loading

docs/markdown-notebooks.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
jupytext:
3+
cell_metadata_filter: -all
4+
formats: md:myst
5+
text_representation:
6+
extension: .md
7+
format_name: myst
8+
format_version: 0.13
9+
jupytext_version: 1.11.5
10+
kernelspec:
11+
display_name: Python 3
12+
language: python
13+
name: python3
14+
---
15+
16+
# Notebooks with MyST Markdown
17+
18+
Jupyter Book also lets you write text-based notebooks using MyST Markdown.
19+
See [the Notebooks with MyST Markdown documentation](https://jupyterbook.org/file-types/myst-notebooks.html) for more detailed instructions.
20+
This page shows off a notebook written in MyST Markdown.
21+
22+
## An example cell
23+
24+
With MyST Markdown, you can define code cells with a directive like so:
25+
26+
```{code-cell}
27+
print(2 + 2)
28+
```
29+
30+
When your book is built, the contents of any `{code-cell}` blocks will be
31+
executed with your default Jupyter kernel, and their outputs will be displayed
32+
in-line with the rest of your content.
33+
34+
```{seealso}
35+
Jupyter Book uses [Jupytext](https://jupytext.readthedocs.io/en/latest/) to convert text-based files to notebooks, and can support [many other text-based notebook files](https://jupyterbook.org/file-types/jupytext.html).
36+
```
37+
38+
## Create a notebook with MyST Markdown
39+
40+
MyST Markdown notebooks are defined by two things:
41+
42+
1. YAML metadata that is needed to understand if / how it should convert text files to notebooks (including information about the kernel needed).
43+
See the YAML at the top of this page for example.
44+
2. The presence of `{code-cell}` directives, which will be executed with your book.
45+
46+
That's all that is needed to get started!
47+
48+
## Quickly add YAML metadata for MyST Notebooks
49+
50+
If you have a markdown file and you'd like to quickly add YAML metadata to it, so that Jupyter Book will treat it as a MyST Markdown Notebook, run the following command:
51+
52+
```
53+
jupyter-book myst init path/to/markdownfile.md
54+
```

docs/markdown.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Markdown Files
2+
3+
Whether you write your book's content in Jupyter Notebooks (`.ipynb`) or
4+
in regular markdown files (`.md`), you'll write in the same flavor of markdown
5+
called **MyST Markdown**.
6+
This is a simple file to help you get started and show off some syntax.
7+
8+
## What is MyST?
9+
10+
MyST stands for "Markedly Structured Text". It
11+
is a slight variation on a flavor of markdown called "CommonMark" markdown,
12+
with small syntax extensions to allow you to write **roles** and **directives**
13+
in the Sphinx ecosystem.
14+
15+
For more about MyST, see [the MyST Markdown Overview](https://jupyterbook.org/content/myst.html).
16+
17+
## Sample Roles and Directives
18+
19+
Roles and directives are two of the most powerful tools in Jupyter Book. They
20+
are kind of like functions, but written in a markup language. They both
21+
serve a similar purpose, but **roles are written in one line**, whereas
22+
**directives span many lines**. They both accept different kinds of inputs,
23+
and what they do with those inputs depends on the specific role or directive
24+
that is being called.
25+
26+
Here is a "note" directive:
27+
28+
```{note}
29+
Here is a note
30+
```
31+
32+
It will be rendered in a special box when you build your book.
33+
34+
Here is an inline directive to refer to a document: {doc}`markdown-notebooks`.
35+
36+
37+
## Citations
38+
39+
You can also cite references that are stored in a `bibtex` file. For example,
40+
the following syntax: `` {cite}`holdgraf_evidence_2014` `` will render like
41+
this: {cite}`holdgraf_evidence_2014`.
42+
43+
Moreover, you can insert a bibliography into your page with this syntax:
44+
The `{bibliography}` directive must be used for all the `{cite}` roles to
45+
render properly.
46+
For example, if the references for your book are stored in `references.bib`,
47+
then the bibliography is inserted with:
48+
49+
```{bibliography}
50+
```
51+
52+
## Learn more
53+
54+
This is just a simple starter to get you started.
55+
You can learn a lot more at [jupyterbook.org](https://jupyterbook.org).

docs/notebooks.ipynb

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Content with notebooks\n",
8+
"\n",
9+
"You can also create content with Jupyter Notebooks. This means that you can include\n",
10+
"code blocks and their outputs in your book.\n",
11+
"\n",
12+
"## Markdown + notebooks\n",
13+
"\n",
14+
"As it is markdown, you can embed images, HTML, etc into your posts!\n",
15+
"\n",
16+
"![](https://myst-parser.readthedocs.io/en/latest/_static/logo-wide.svg)\n",
17+
"\n",
18+
"You can also $add_{math}$ and\n",
19+
"\n",
20+
"$$\n",
21+
"math^{blocks}\n",
22+
"$$\n",
23+
"\n",
24+
"or\n",
25+
"\n",
26+
"$$\n",
27+
"\\begin{aligned}\n",
28+
"\\mbox{mean} la_{tex} \\\\ \\\\\n",
29+
"math blocks\n",
30+
"\\end{aligned}\n",
31+
"$$\n",
32+
"\n",
33+
"But make sure you \\$Escape \\$your \\$dollar signs \\$you want to keep!\n",
34+
"\n",
35+
"## MyST markdown\n",
36+
"\n",
37+
"MyST markdown works in Jupyter Notebooks as well. For more information about MyST markdown, check\n",
38+
"out [the MyST guide in Jupyter Book](https://jupyterbook.org/content/myst.html),\n",
39+
"or see [the MyST markdown documentation](https://myst-parser.readthedocs.io/en/latest/).\n",
40+
"\n",
41+
"## Code blocks and outputs\n",
42+
"\n",
43+
"Jupyter Book will also embed your code blocks and output in your book.\n",
44+
"For example, here's some sample Matplotlib code:"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": null,
50+
"metadata": {},
51+
"outputs": [],
52+
"source": [
53+
"from matplotlib import rcParams, cycler\n",
54+
"import matplotlib.pyplot as plt\n",
55+
"import numpy as np\n",
56+
"plt.ion()"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"# Fixing random state for reproducibility\n",
66+
"np.random.seed(19680801)\n",
67+
"\n",
68+
"N = 10\n",
69+
"data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]\n",
70+
"data = np.array(data).T\n",
71+
"cmap = plt.cm.coolwarm\n",
72+
"rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))\n",
73+
"\n",
74+
"\n",
75+
"from matplotlib.lines import Line2D\n",
76+
"custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n",
77+
" Line2D([0], [0], color=cmap(.5), lw=4),\n",
78+
" Line2D([0], [0], color=cmap(1.), lw=4)]\n",
79+
"\n",
80+
"fig, ax = plt.subplots(figsize=(10, 5))\n",
81+
"lines = ax.plot(data)\n",
82+
"ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);"
83+
]
84+
},
85+
{
86+
"cell_type": "markdown",
87+
"metadata": {},
88+
"source": [
89+
"There is a lot more that you can do with outputs (such as including interactive outputs)\n",
90+
"with your book. For more information about this, see [the Jupyter Book documentation](https://jupyterbook.org)"
91+
]
92+
}
93+
],
94+
"metadata": {
95+
"kernelspec": {
96+
"display_name": "Python 3",
97+
"language": "python",
98+
"name": "python3"
99+
},
100+
"language_info": {
101+
"codemirror_mode": {
102+
"name": "ipython",
103+
"version": 3
104+
},
105+
"file_extension": ".py",
106+
"mimetype": "text/x-python",
107+
"name": "python",
108+
"nbconvert_exporter": "python",
109+
"pygments_lexer": "ipython3",
110+
"version": "3.8.0"
111+
},
112+
"widgets": {
113+
"application/vnd.jupyter.widget-state+json": {
114+
"state": {},
115+
"version_major": 2,
116+
"version_minor": 0
117+
}
118+
}
119+
},
120+
"nbformat": 4,
121+
"nbformat_minor": 4
122+
}

0 commit comments

Comments
 (0)