{ "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": [ "# Markdown Cells\n", "\n", "We can use *emphasis*, **boldface**, `preformatted text`.\n", "\n", "> It looks like strike-out text is not supported: ~~strikethrough~~.\n", "\n", "* Red\n", "* Green\n", "* Blue\n", "\n", "***\n", "\n", "1. One\n", "1. Two\n", "1. Three\n", "\n", "Arbitrary Unicode characters should be supported, e.g. łßō.\n", "Note, however, that this only works if your HTML browser and your LaTeX processor provide the appropriate fonts." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Equations\n", "\n", "Inline equations like $\\text{e}^{i\\pi} = -1$\n", "can be created by putting a LaTeX expression between two dollar signs, like this:\n", "`$\\text{e}^{i\\pi} = -1$`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "**Note:**\n", "\n", "Avoid leading and trailing spaces around math expressions, otherwise errors like the following will occur when Sphinx is running:\n", "\n", " ERROR: Unknown interpreted text role \"raw-latex\".\n", "\n", "See also the [pandoc docs](https://pandoc.org/MANUAL.html#math):\n", "\n", "> Anything between two `$` characters will be treated as TeX math. The opening `$` must have a non-space character immediately to its right, while the closing `$` must have a non-space character immediately to its left, and must not be followed immediately by a digit.\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Equations can also be displayed on their own line like this:\n", "\\begin{equation}\n", "\\int\\limits_{-\\infty}^\\infty f(x) \\delta(x - x_0) dx = f(x_0).\n", "\\end{equation}\n", "\n", "This can be done by simply using one of the LaTeX math environments, like so:\n", "\n", "```\n", "\\begin{equation}\n", "\\int\\limits_{-\\infty}^\\infty f(x) \\delta(x - x_0) dx = f(x_0)\n", "\\end{equation}\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "**Note:**\n", "\n", "For equations to be shown in HTML output,\n", "you have to specify a\n", "[math extension](https://www.sphinx-doc.org/en/master/usage/extensions/math.html)\n", "in your [extensions](usage.ipynb#extensions) setting, e.g.:\n", "\n", "```python\n", "extensions = [\n", " 'nbsphinx',\n", " 'sphinx.ext.mathjax',\n", " # ... other useful extensions ...\n", "]\n", "```\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Automatic Equation Numbering\n", "\n", "This is not automatically enabled in Jupyter notebooks,\n", "but you can install a notebook extension in order to enable equation numbering:\n", "https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/equation-numbering/readme.html.\n", "\n", "Automatic Equation Numbering is enabled on https://nbviewer.jupyter.org/,\n", "see e.g. the latest version of this very notebook at the link https://nbviewer.jupyter.org/github/spatialaudio/nbsphinx/blob/master/doc/markdown-cells.ipynb#Automatic-Equation-Numbering.\n", "\n", "When using `nbsphinx`, you can use the following `mathjax_config` setting in your `conf.py` file\n", "to enable automatic equation numbering in HTML output.\n", "In LaTeX output, the equations are numbered by default.\n", "\n", "```python\n", "mathjax_config = {\n", " 'TeX': {'equationNumbers': {'autoNumber': 'AMS', 'useLabelIds': True}},\n", "}\n", "```\n", "\n", "You can use `\\label{...}` to give a unique label to an equation:\n", "\n", "\\begin{equation}\n", "\\phi = \\frac{1 + \\sqrt{5}}{2}\n", "\\label{golden-mean}\n", "\\end{equation}\n", "\n", "```\n", "\\begin{equation}\n", "\\phi = \\frac{1 + \\sqrt{5}}{2}\n", "\\label{golden-mean}\n", "\\end{equation}\n", "```\n", "\n", "If automatic equation numbering is enabled,\n", "you can later reference that equation using its label.\n", "You can use `\\eqref{golden-mean}` for a reference with parentheses: \\eqref{golden-mean},\n", "or `\\ref{golden-mean}` for a reference without them: \\ref{golden-mean}.\n", "\n", "In HTML output, these equation references only work for equations within a single HTML page.\n", "In LaTeX output, equations from other notebooks can be referenced, e.g. \\eqref{fibonacci-recurrence}." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Manual Equation Numbering\n", "\n", "If you prefer to assign equation numbers (or some kind of names) manually,\n", "you can do so with `\\tag{...}`:\n", "\n", "\\begin{equation}\n", "a^2 + b^2 = c^2\n", "\\tag{99.4}\n", "\\label{pythagoras}\n", "\\end{equation}\n", "\n", "```\n", "\\begin{equation}\n", "a^2 + b^2 = c^2\n", "\\tag{99.4}\n", "\\label{pythagoras}\n", "\\end{equation}\n", "```\n", "\n", "The above equation has the number \\ref{pythagoras}." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Citations\n", "\n", "According to https://nbconvert.readthedocs.io/en/latest/latex_citations.html,\n", "`nbconvert` supports citations using a special HTML-based syntax.\n", "`nbsphinx` supports the same syntax.\n", "\n", "Example: Kluyver et al. (2016).\n", "\n", "```html\n", "Kluyver et al. (2016)\n", "```\n", "\n", "You don't actually have to use ``,\n", "any inline HTML tag can be used, e.g. ``:\n", "Python: An Ecosystem for Scientific Computing.\n", "\n", "```html\n", "Python: An Ecosystem for Scientific Computing\n", "```\n", "\n", "You'll also have to define a list of references,\n", "see [the section about references](a-normal-rst-file.rst#references).\n", "\n", "There is also a Notebook extension which may or may not be useful: https://github.com/takluyver/cite2c." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Code\n", "\n", "We can also write code with nice syntax highlighting:\n", "\n", "```python3\n", "print(\"Hello, world!\")\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tables\n", "\n", "A | B | A and B\n", "------|-------|--------\n", "False | False | False\n", "True | False | False\n", "False | True | False\n", "True | True | True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Images\n", "\n", "Local image: ![Jupyter notebook icon](images/notebook_icon.png)\n", "\n", " ![Jupyter notebook icon](images/notebook_icon.png)\n", "\n", "Remote image: ![Python logo (remote)](https://www.python.org/static/img/python-logo-large.png)\n", "\n", " ![Python logo (remote)](https://www.python.org/static/img/python-logo-large.png)\n", "\n", "### SVG support for LaTeX\n", "\n", "LaTeX doesn't support SVG images, but there are Sphinx extensions that can be used for automatically converting SVG images for inclusion in LaTeX output.\n", "\n", "Just include one of the following options in the list of\n", "[extensions](usage.ipynb#extensions)\n", "in your `conf.py` file.\n", "\n", "* `'sphinxcontrib.inkscapeconverter'` or `'sphinxcontrib.rsvgconverter'`:\n", " See https://github.com/missinglinkelectronics/sphinxcontrib-svg2pdfconverter\n", " for installation instructions.\n", " \n", " The external programs `inkscape` or `rsvg-convert` (Debian/Ubuntu package `librsvg2-bin`)\n", " are needed, respectively.\n", "\n", "* `'sphinx.ext.imgconverter'`:\n", " This is a built-in Sphinx extension, see\n", " https://www.sphinx-doc.org/en/master/usage/extensions/imgconverter.html.\n", " \n", " This needs the external program `convert` from *ImageMagick*.\n", "\n", " The disadvantage of this extension is that SVGs are converted to bitmap images.\n", "\n", "If one of those extensions is installed, SVG images can be used even for LaTeX output:\n", "\n", "![Python logo](images/python_logo.svg)\n", "\n", " ![Python logo](images/python_logo.svg)\n", "Remote SVG images can also be used (and will be shown in the LaTeX output):\n", "\n", "![Jupyter logo](https://jupyter.org/assets/main-logo.svg)\n", "\n", " ![Jupyter logo](https://jupyter.org/assets/main-logo.svg)" ] }, { "attachments": { "stickfigure.png": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAHv0lEQVR42u2ae2xbZxnGf+f4OLbjOHGcNq2bpqF12tJmZGtJttK1m7Z1XMomVQyp4zYESEMwMNLEKEgIbQJNFKkIVUNogJj2B9u6cYkETBUtl5UNWDt10NGMbiU0G+klpE6aq9PYMX+c5xRjEl8SJ3WcvdKR7ePvXN7ney/P+34fvCWLW4x5eIYHCAGV+v2PcgcgBFTpewB4J/AxYDmQAKLAaeBcOQLQKgW3AymgETgL1AJHgAlgI9ADPAQcB8bLxZ1WAZ3AYaALuBdo0flrgTogLID6gDc0xlMOynuAm4DXgU9plj1Zxt4B/BM4JYAWvPL3AX8VCPnO6A5gRFayoKUFiAOvFTibzcDfgTuvphuYRbjHkPz518BAAVbTCkwCr17NQGgW6T5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414A3O1pXBmMpVLFGol09YC4fVV3PLpJp77YTfJiRTx4UTJATATZQtqiTW0BLjtvtVUVLp45WAv8aEE5ShZp3VZs5/qervFV2oWMC8AAHOVm0tGTBa5vAXAYgfgP6N1EOJNty18AAAAAElFTkSuQmCC" } }, "cell_type": "markdown", "metadata": {}, "source": [ "## Cell Attachments\n", "\n", "Images can also be embedded in the notebook itself. Just drag an image file into the Markdown cell you are just editing or copy and paste some image data from an image editor/viewer.\n", "\n", "The generated Markdown code will look just like a \"normal\" image link, except that it will have an `attachment:` prefix:\n", "\n", " ![a stick figure](attachment:stickfigure.png)\n", "\n", "This is a cell attachment: ![a stick figure](attachment:stickfigure.png)\n", "\n", "In the Jupyter Notebook, there is a speciall \"Attachments\" cell toolbar which you can use to see all attachments of a cell and delete them, if needed." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## HTML Elements (HTML only)\n", "\n", "It is allowed to use plain HTML elements within Markdown cells.\n", "Those elements are passed through to the HTML output and are ignored for the LaTeX output.\n", "Below are a few examples.\n", "\n", "HTML5 [audio](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio) elements can be created like this:\n", "\n", "```html\n", "\n", "```\n", "\n", "Example:\n", "\n", "\n", "\n", "\n", "HTML5 [video](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video) elements can be created like this:\n", "\n", "```html\n", "\n", "```\n", "\n", "Example:\n", "\n", "\n", "\n", "The alternative text is shown in browsers that don't support those elements. The same text is also shown in Sphinx's LaTeX output.\n", "\n", "
\n", "\n", "**Note:** You can also use local files for the `
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Info/Warning Boxes\n", "\n", "
\n", "\n", "**Warning:**\n", "\n", "This is an *experimental feature*!\n", "Its usage will probably change in the future or it might be removed completely!\n", "\n", "
\n", "\n", "Until there is an info/warning extension for Markdown/CommonMark (see [this issue](https://github.com/jupyter/notebook/issues/1292)), such boxes can be created by using HTML `
` elements like this:\n", "\n", "```html\n", "
\n", "\n", "**Note:** This is a note!\n", "\n", "
\n", "```\n", "\n", "For this to work reliably, you should obey the following guidelines:\n", "\n", "* The `class` attribute has to be either `\"alert alert-info\"` or `\"alert alert-warning\"`, other values will not be converted correctly.\n", "* No further attributes are allowed.\n", "* For compatibility with CommonMark, you should add an empty line between the `
` start tag and the beginning of the content.\n", "\n", "
\n", "\n", "**Note:**\n", "\n", "The text can contain further Markdown formatting.\n", "It is even possible to have nested boxes:\n", "\n", "
\n", "\n", "... but please don't *overuse* this!\n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Links to Other Notebooks\n", "\n", "Relative links to local notebooks can be used:\n", "[a link to a notebook in a subdirectory](subdir/a-notebook-in-a-subdir.ipynb),\n", "[a link to an orphan notebook](orphan.ipynb)\n", "(latter won't work in LaTeX output, because orphan pages are not included there).\n", "\n", "This is how a link is created in Markdown:\n", "\n", "```\n", "[a link to a notebook in a subdirectory](subdir/a-notebook-in-a-subdir.ipynb)\n", "```\n", "\n", "Markdown also supports *reference-style* links:\n", "[a reference-style link][mylink],\n", "[another version of the same link][mylink].\n", "\n", "[mylink]: subdir/a-notebook-in-a-subdir.ipynb\n", "\n", "These can be created with this syntax:\n", "\n", "```\n", "[a reference-style link][mylink]\n", "\n", "[mylink]: subdir/a-notebook-in-a-subdir.ipynb\n", "```\n", "\n", "Links to sub-sections are also possible, e.g.\n", "[this subsection](subdir/a-notebook-in-a-subdir.ipynb#A-Sub-Section).\n", "\n", "This link was created with:\n", "\n", "```\n", "[this subsection](subdir/a-notebook-in-a-subdir.ipynb#A-Sub-Section)\n", "```\n", "\n", "You just have to remember to replace spaces with hyphens!\n", "\n", "BTW, links to sections of the current notebook work, too, e.g.\n", "[beginning of this section](#Links-to-Other-Notebooks).\n", "\n", "This can be done, as expected, like this:\n", "\n", "```\n", "[beginning of this section](#Links-to-Other-Notebooks)\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Links to `*.rst` Files (and Other Sphinx Source Files)\n", "\n", "Links to files whose extension is in the configuration value [source_suffix](https://www.sphinx-doc.org/en/master/config.html#confval-source_suffix), will be converted to links to the generated HTML/LaTeX pages. Example: [A reStructuredText file](a-normal-rst-file.rst).\n", "\n", "This was created with:\n", "\n", "```\n", "[A reStructuredText file](a-normal-rst-file.rst)\n", "```\n", "\n", "Links to sub-sections are also possible. Example: [Sphinx Directives](a-normal-rst-file.rst#sphinx-directives-for-info-warning-boxes).\n", "\n", "This was created with:\n", "\n", "```\n", "[Sphinx Directives](a-normal-rst-file.rst#sphinx-directives-for-info-warning-boxes)\n", "```\n", "\n", "
\n", "\n", "**Note:**\n", "\n", "Sphinx section anchors are different from Jupyter section anchors!\n", "To create a link to a subsection in an `.rst` file (or another non-notebook source file), you not only have to replace spaces with hyphens, but also slashes and some other characters.\n", "In case of doubt, just check the target HTML page generated by Sphinx.\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Links to Local Files\n", "\n", "Links to local files (other than Jupyter notebooks and other Sphinx source files) are also possible, e.g. [requirements.txt](requirements.txt).\n", "\n", "This was simply created with:\n", "\n", "```\n", "[requirements.txt](requirements.txt)\n", "```\n", "\n", "The linked files are automatically copied to the HTML output directory.\n", "For LaTeX output, links are created,\n", "but the files are not copied to the target directory." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Links to Domain Objects\n", "\n", "Links to [Sphinx domain objects](https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html) (such as a Python class or JavaScript function) are also possible. For example:\n", "[example_python_function()](a-normal-rst-file.rst#example_python_function).\n", "\n", "This was created with:\n", "\n", "```\n", "[example_python_function()](a-normal-rst-file.rst#example_python_function)\n", "```\n", "\n", "This is especially useful for use with the Sphinx [autodoc](https://www.sphinx-doc.org/en/master/ext/autodoc.html) extension!" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.5" } }, "nbformat": 4, "nbformat_minor": 4 }