Skip to content

Commit

Permalink
DOC: Separate notebooks for different gallery types
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Jan 13, 2023
1 parent 13eeb84 commit 23869df
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 91 deletions.
61 changes: 36 additions & 25 deletions doc/a-normal-rst-file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,48 @@ here. Instead, the footnote citations are placed into the footnotes of
their respective pages.


Thumbnail Link Galleries (HTML only)
-------------------------------------

In some case it is desired to create thumbnail links to existing notebooks,
already included in a ``toctree``. This can be used e.g. to link to a subset
of notebooks from API documentation to highlight the use of some functionality.
For this there is a dedicated ``nblinkgallery`` directive.

The following example gallery was created using:

.. code-block:: rest
.. nblinkgallery::
:caption: A few links
:name: rst-link-gallery
gallery/multiple-outputs
gallery/no-thumbnail
gallery/cell-metadata
orphan
.. nblinkgallery::
:caption: A few links
:name: rst-link-gallery

gallery/multiple-outputs
gallery/no-thumbnail
gallery/cell-metadata
orphan

.. seealso::

`Link Galleries in Jupyter Notebooks <gallery/gallery-with-links.ipynb>`_


Thumbnail Galleries
-------------------

With ``nbsphinx`` you can create thumbnail galleries in notebook files
as described in :ref:`/subdir/gallery.ipynb`.

as described in :ref:`/gallery/gallery-with-nested-documents.ipynb`.
If you like, you can also create such galleries in reST files
using the ``nbgallery`` directive.

It takes the same parameters as the `toctree`__ directive.

__ https://www.sphinx-doc.org/en/master/usage/restructuredtext/
Expand Down Expand Up @@ -305,25 +338,3 @@ The following example gallery was created using:
:reversed:

gallery/*-rst

Thumbnail Links Galleries (HTML only)
-------------------------------------

In some case it is desired to just create thumbnail links to existing notebooks,
already included in a ``toctree``. This can be used e.g. to link to a subset
of notebooks from API documentation to highlight the use of some functionality.
For this there is a dedicated ``nblinkgallery`` directive.

The following example gallery was created using:

.. code-block:: rest
.. nblinkgallery::
gallery/multiple-outputs
gallery/no-thumbnail
.. nblinkgallery::
gallery/multiple-outputs
gallery/no-thumbnail

90 changes: 90 additions & 0 deletions doc/gallery/gallery-with-links.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"nbsphinx": "hidden"
},
"source": [
"This notebook is part of the `nbsphinx` documentation: https://nbsphinx.readthedocs.io/."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Gallery With Links (HTML only)\n",
"\n",
"Contrary to\n",
"[nbsphinx-gallery](gallery-with-nested-documents.ipynb),\n",
"the cell tag/metadata `nbsphinx-link-gallery`\n",
"creates a gallery from notebooks (and other source) files\n",
"without including them as sub-sections.\n",
"Other than that, it works in a similar way,\n",
"but only the options\n",
"`\"name\"`,\n",
"`\"caption\"` and\n",
"`\"reversed\"` are supported.\n",
"In LaTeX output, this has no effect.\n",
"The cell is ignored and nothing is added to the LaTeX document.\n",
"\n",
"In reST files\n",
"(and [raw reST cells](../raw-cells.ipynb#reST)),\n",
"the\n",
"[nblinkgallery](../a-normal-rst-file.rst#thumbnail-link-galleries-html-only)\n",
"directive can be used.\n",
"\n",
"The following Markdown cell\n",
"has the `nbsphinx-link-gallery` tag,\n",
"which turns the contained links into a gallery\n",
"and uses the first section title as `caption`:"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": [
"nbsphinx-link-gallery"
]
},
"source": [
"## This is a thumbnail gallery with links to existing documents:\n",
"\n",
"This paragraph will be ignored.\n",
"Only links are taken into account.\n",
"\n",
"## This section title will be ignored\n",
"\n",
"... because only the first title in this cell is used.\n",
"\n",
"* [Dummy Notebook 2](due-rst.pct.py)\n",
"* [An Orphan Notebook](../orphan.ipynb)\n",
"* [Notebook About Code Cells](../code-cells.ipynb)\n",
"* [Thumbnail With a Tooltip](cell-metadata.ipynb)\n",
"* [A Page About Contributing (Not a Notebook)](../contributing.rst)\n",
"* [A Page Using reStructuredText (Not a Notebook)](../a-normal-rst-file.rst)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
106 changes: 106 additions & 0 deletions doc/gallery/gallery-with-nested-documents.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"nbsphinx": "hidden"
},
"source": [
"This notebook is part of the `nbsphinx` documentation: https://nbsphinx.readthedocs.io/."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Gallery With Nested Documents\n",
"\n",
"You can create\n",
"[thumbnail galleries in reST files](../a-normal-rst-file.rst#thumbnail-galleries),\n",
"but you can also create such galleries in Jupyter notebooks\n",
"by adding the `nbsphinx-gallery`\n",
"cell tag or metadata,\n",
"which is used just like the\n",
"[nbsphinx-toctree](../subdir/toctree.ipynb) cell tag/metadata.\n",
"For possible options, see the [toctree](../subdir/toctree.ipynb) notebook.\n",
"\n",
"<div class=\"alert alert-info\">\n",
"\n",
"Note\n",
"\n",
"In LaTeX output this behaves just like ``toctree``,\n",
"i.e. no thumbnail gallery is shown,\n",
"but the linked files are included in the document.\n",
"\n",
"Like with ``toctree`` you should avoid adding content\n",
"after a gallery (except other toctrees and galleries)\n",
"because this content would appear in the LaTeX output\n",
"*after* the content of all included source files,\n",
"which is probably not what you want.\n",
"\n",
"</div>\n",
"\n",
"The following cell has the `nbsphinx-gallery` tag,\n",
"which creates a thumbnail gallery.\n",
"The *first* section title in that cell (if available)\n",
"is used as `caption` (unless it is already given in the metadata).\n",
"\n",
"The notebooks in the following gallery describe different ways\n",
"how to select which images are used as thumbnails.\n",
"The notebooks are added as sub-sections under the current section,\n",
"just like when using ``toctree``.\n",
"If you want to create a gallery from links to notebooks\n",
"that are already included somewhere else,\n",
"you can use [nbsphinx-link-gallery](gallery-with-links.ipynb)."
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": [
"nbsphinx-gallery"
]
},
"source": [
"This section title will be used as ``caption``:\n",
"\n",
"## This is a thumbnail gallery with sub-documents:\n",
"\n",
"This paragraph will be ignored.\n",
"Only links and the first section title are scanned,\n",
"everything else is ignored.\n",
"\n",
"* [Using a Cell Tag to Select a Thumbnail](cell-tag.ipynb)\n",
"* [Using Cell Metadata to Select a Thumbnail](cell-metadata.ipynb)\n",
"* [Choosing from Multiple Outputs](multiple-outputs.ipynb)\n",
"* [No Thumbnail Available](no-thumbnail.ipynb)\n",
"* [Specifying a Thumbnail File](thumbnail-from-conf-py.ipynb)\n",
"\n",
"## This section title will be ignored\n",
"\n",
"... because only the first title in this cell is used."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
6 changes: 3 additions & 3 deletions doc/gallery/multiple-outputs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"\n",
"The following cell has this metadata,\n",
"selecting the third output to be used as thumbnail in\n",
"[the gallery](../subdir/gallery.ipynb).\n",
"[the gallery](gallery-with-nested-documents.ipynb).\n",
"\n",
"```json\n",
"{\n",
Expand Down Expand Up @@ -57,7 +57,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -71,7 +71,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.11.1"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions doc/gallery/no-thumbnail.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"This notebook doesn't contain any thumbnail metadata.\n",
"\n",
"It should be displayed with the default thumbnail image in the\n",
"[gallery](../subdir/gallery.ipynb)."
"[gallery](gallery-with-nested-documents.ipynb)."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -38,7 +38,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.11.1"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions doc/gallery/thumbnail-from-conf-py.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"a thumbnail is specified (via the\n",
"[nbsphinx_thumbnails](../configuration.ipynb#nbsphinx_thumbnails)\n",
"option),\n",
"which will be used in the [gallery](../subdir/gallery.ipynb).\n",
"which will be used in the [gallery](gallery-with-nested-documents.ipynb).\n",
"\n",
"The keys in the `nbsphinx_thumbnails` dictionary can contain wildcards,\n",
"which behave very similarly to the\n",
Expand Down Expand Up @@ -101,7 +101,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -115,7 +115,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.11.1"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 23869df

Please sign in to comment.