[Python-modules-commits] [nbsphinx] 01/03: Import nbsphinx_0.2.9+ds.orig.tar.xz
Jerome Benoit
calculus-guest at moszumanska.debian.org
Sun Sep 25 21:29:25 UTC 2016
This is an automated email from the git hooks/post-receive script.
calculus-guest pushed a commit to branch experimental
in repository nbsphinx.
commit 4a649831962ebbfaa18048aaa8b35a0d20b66304
Author: Jerome Benoit <calculus at rezozer.net>
Date: Sun Sep 25 21:53:19 2016 +0100
Import nbsphinx_0.2.9+ds.orig.tar.xz
---
CONTRIBUTING.rst | 47 ++
LICENSE | 19 +
MANIFEST.in | 8 +
NEWS.rst | 39 +
PKG-INFO | 57 ++
README.rst | 36 +
doc/a-normal-rst-file.rst | 105 +++
doc/allow-errors.ipynb | 121 ++++
doc/code-cells.ipynb | 497 +++++++++++++
doc/conf.py | 80 +++
doc/executing-notebooks.ipynb | 58 ++
doc/hidden-cells.ipynb | 101 +++
doc/images/notebook_icon.png | Bin 0 -> 8031 bytes
doc/images/python_logo.svg | 269 +++++++
doc/images/raw_cells.png | Bin 0 -> 47888 bytes
doc/index.rst | 22 +
doc/links.ipynb | 136 ++++
doc/markdown-cells.ipynb | 292 ++++++++
doc/never-execute.ipynb | 77 ++
doc/orphan.ipynb | 86 +++
doc/pre-executed.ipynb | 187 +++++
doc/raw-cells.ipynb | 174 +++++
doc/requirements.txt | 3 +
doc/subdir/a-notebook-in-a-subdir.ipynb | 71 ++
doc/subdir/toctree.ipynb | 112 +++
doc/timeout.ipynb | 62 ++
doc/usage.ipynb | 252 +++++++
doc/yet-another.ipynb | 44 ++
nbsphinx.py | 1193 +++++++++++++++++++++++++++++++
setup.py | 41 ++
30 files changed, 4189 insertions(+)
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
new file mode 100644
index 0000000..34b3301
--- /dev/null
+++ b/CONTRIBUTING.rst
@@ -0,0 +1,47 @@
+Contributing
+============
+
+If you find bugs, errors, omissions or other things that need improvement,
+please create an issue or a pull request at
+http://github.com/spatialaudio/nbsphinx/.
+Contributions are always welcome!
+
+Instead of pip-installing the latest release from PyPI_, you should get the
+newest development version (a.k.a. "master") from Github_::
+
+ git clone https://github.com/spatialaudio/nbsphinx.git
+ cd nbsphinx
+ python3 setup.py develop --user
+
+This way, your installation always stays up-to-date, even if you pull new
+changes from the Github repository. If you have only Python 3 installed, you
+might have to use the command ``python`` instead of ``python3``.
+When installing ``nbsphinx`` this way, you can also quickly check other Git
+branches (in this example the branch is called "another-branch")::
+
+ git checkout another-branch
+
+When you run Sphinx now, it automatically uses the version "another-branch" of
+``nbsphinx``. If you want to go back to the "master" branch, use::
+
+ git checkout master
+
+To get the latest changes from Github, use::
+
+ git pull --ff-only
+
+If you make changes to the documentation, you should create the HTML
+pages locally using Sphinx and check if they look OK::
+
+ python3 setup.py build_sphinx
+
+To check the LaTeX output, use::
+
+ python3 setup.py build_sphinx -b latex
+
+Again, you'll probably have to use ``python`` instead of ``python3``.
+The generated files will be available in the directories ``build/sphinx/html/``
+and ``build/sphinx/latex/``, respectively.
+
+.. _PyPI: https://pypi.python.org/pypi/nbsphinx/
+.. _Github: http://github.com/spatialaudio/nbsphinx/
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..8db4a47
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2015-2016 Matthias Geier
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..2519331
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,8 @@
+include LICENSE
+include *.rst
+include doc/requirements.txt
+include doc/conf.py
+include doc/*.rst
+include doc/*.ipynb
+include doc/subdir/*.ipynb
+include doc/images/*
diff --git a/NEWS.rst b/NEWS.rst
new file mode 100644
index 0000000..17734f6
--- /dev/null
+++ b/NEWS.rst
@@ -0,0 +1,39 @@
+Version 0.2.9 (2016-07-26):
+ * Add option ``nbsphinx_prompt_width``
+
+Version 0.2.8 (2016-05-20):
+ * Add options ``nbsphinx_execute`` and ``nbsphinx_execute_arguments``
+ * Separate "display priority" for HTML and LaTeX
+
+Version 0.2.7 (2016-05-04):
+ * Special CSS tuning for ``sphinx_rtd_theme``
+ * Replace info/warning ``<div>`` elements with ``nbinfo``/``nbwarning``
+
+Version 0.2.6 (2016-04-12):
+ * Support for LaTeX math environments in Markdown cells
+ * Add options ``nbsphinx_timeout`` and ``nbsphinx_codecell_lexer``
+
+Version 0.2.5 (2016-03-15):
+ * Add option ``nbsphinx_allow_errors`` to globally ignore exceptions
+ * Separate class `nbsphinx.Exporter`
+
+Version 0.2.4 (2016-02-12):
+ * Support for "nbsphinx-toctree" cell metadata
+
+Version 0.2.3 (2016-01-22):
+ * Links from notebooks to local files can now be used
+
+Version 0.2.2 (2016-01-06):
+ * Support for links to sub-sections in other notebooks
+
+Version 0.2.1 (2016-01-04):
+ * No need to mention ``source_suffix`` and ``source_parsers`` in ``conf.py``
+
+Version 0.2.0 (2015-12-27):
+ * Add support for ``allow_errors`` and ``hidden`` metadata
+ * Add custom reST template
+ * Add nbinput and nboutput directives with HTML+CSS and LaTeX formatting
+ * Turn nbsphinx into a Sphinx extension
+
+Version 0.1.0 (2015-11-29):
+ Initial release
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..aa07b67
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,57 @@
+Metadata-Version: 1.1
+Name: nbsphinx
+Version: 0.2.9
+Summary: Jupyter Notebook Tools for Sphinx
+Home-page: http://nbsphinx.rtfd.org/
+Author: Matthias Geier
+Author-email: Matthias.Geier at gmail.com
+License: MIT
+Description: Jupyter Notebook Tools for Sphinx
+ =================================
+
+ ``nbsphinx`` is a Sphinx_ extension that provides a source parser for
+ ``*.ipynb`` files.
+ Custom Sphinx directives are used to show `Jupyter Notebook`_ code cells (and of
+ course their results) in both HTML and LaTeX output.
+ Un-evaluated notebooks -- i.e. notebooks without stored output cells -- will be
+ automatically executed during the Sphinx build process.
+
+ .. _Sphinx: http://sphinx-doc.org/
+ .. _Jupyter Notebook: http://jupyter.org/
+
+ Documentation (and example of use):
+ http://nbsphinx.readthedocs.io/
+
+ Source code repository (and issue tracker):
+ https://github.com/spatialaudio/nbsphinx/
+
+ Python Package Index:
+ https://pypi.python.org/pypi/nbsphinx/
+
+ License:
+ MIT -- see the file ``LICENSE`` for details.
+
+ Quick Start:
+ #. Install ``nbsphinx``::
+
+ python3 -m pip install nbsphinx --user
+
+ #. Edit your ``conf.py`` and add ``'nbsphinx'`` to ``extensions``.
+
+ #. Edit your ``index.rst`` and add the names of your ``*.ipynb`` files
+ to the ``toctree``.
+
+ #. Run Sphinx!
+
+Keywords: Sphinx,Jupyter,notebook
+Platform: any
+Classifier: Development Status :: 3 - Alpha
+Classifier: Framework :: Sphinx
+Classifier: Framework :: Sphinx :: Extension
+Classifier: Intended Audience :: Education
+Classifier: Intended Audience :: Science/Research
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: OS Independent
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 3
+Classifier: Topic :: Documentation :: Sphinx
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..706d7fb
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,36 @@
+Jupyter Notebook Tools for Sphinx
+=================================
+
+``nbsphinx`` is a Sphinx_ extension that provides a source parser for
+``*.ipynb`` files.
+Custom Sphinx directives are used to show `Jupyter Notebook`_ code cells (and of
+course their results) in both HTML and LaTeX output.
+Un-evaluated notebooks -- i.e. notebooks without stored output cells -- will be
+automatically executed during the Sphinx build process.
+
+.. _Sphinx: http://sphinx-doc.org/
+.. _Jupyter Notebook: http://jupyter.org/
+
+Documentation (and example of use):
+ http://nbsphinx.readthedocs.io/
+
+Source code repository (and issue tracker):
+ https://github.com/spatialaudio/nbsphinx/
+
+Python Package Index:
+ https://pypi.python.org/pypi/nbsphinx/
+
+License:
+ MIT -- see the file ``LICENSE`` for details.
+
+Quick Start:
+ #. Install ``nbsphinx``::
+
+ python3 -m pip install nbsphinx --user
+
+ #. Edit your ``conf.py`` and add ``'nbsphinx'`` to ``extensions``.
+
+ #. Edit your ``index.rst`` and add the names of your ``*.ipynb`` files
+ to the ``toctree``.
+
+ #. Run Sphinx!
diff --git a/doc/a-normal-rst-file.rst b/doc/a-normal-rst-file.rst
new file mode 100644
index 0000000..2201204
--- /dev/null
+++ b/doc/a-normal-rst-file.rst
@@ -0,0 +1,105 @@
+Normal reStructuredText Files
+=============================
+
+This is a normal RST file.
+
+.. note:: Those still work!
+
+Links to Notebooks
+------------------
+
+Links to notebooks can be easily created:
+:ref:`subdir/a-notebook-in-a-subdir.ipynb`
+(the notebook title is used as link text).
+You can also use
+:ref:`an alternative text <subdir/a-notebook-in-a-subdir.ipynb>`.
+
+The above links were created with:
+
+.. code-block:: rst
+
+ :ref:`subdir/a-notebook-in-a-subdir.ipynb`
+ :ref:`an alternative text <subdir/a-notebook-in-a-subdir.ipynb>`
+
+Links to subsections are also possible, e.g.
+:ref:`subdir/a-notebook-in-a-subdir.ipynb#A-Sub-Section`
+(the subsection title is used as link text) and
+:ref:`alternative text <subdir/a-notebook-in-a-subdir.ipynb#A-Sub-Section>`.
+
+These links were created with:
+
+.. code-block:: rst
+
+ :ref:`subdir/a-notebook-in-a-subdir.ipynb#A-Sub-Section`
+ :ref:`alternative text <subdir/a-notebook-in-a-subdir.ipynb#A-Sub-Section>`
+
+.. note::
+
+ * Spaces in the section title have to be replaced by hyphens!
+ * "``../``" is not allowed, you have to specify the full path even if the
+ current source file is in a subdirectory!
+
+Sphinx Directives for Jupyter Notebook Cells
+--------------------------------------------
+
+For comparison, this is a "normal" Sphinx code block using ``ipython3``
+syntax highlighting:
+
+.. code-block:: ipython3
+
+ %file helloworld.py
+ #!/usr/bin/env python3
+ print('Hello, world!')
+
+The ``nbsphinx`` extension provides custom directives to show notebook cells:
+
+.. nbinput:: ipython3
+ :execution-count: 42
+
+ 6 * 7
+
+.. nboutput::
+ :execution-count: 42
+
+ 42
+
+This was created with
+
+.. code-block:: rst
+
+ .. nbinput:: ipython3
+ :execution-count: 42
+
+ 6 * 7
+
+ .. nboutput::
+ :execution-count: 42
+
+ 42
+
+Sphinx Directives for Info/Warning Boxes
+----------------------------------------
+
+.. nbwarning::
+ **Warning:**
+
+ This is an experimental feature!
+ Its usage may change in the future or it might disappear completely, so
+ don't use it for now.
+
+With a bit of luck, it will be possible (some time in the future) to create
+info/warning boxes in Markdown cells, see
+https://github.com/jupyter/notebook/issues/1292.
+If this ever happens, ``nbsphinx`` will provide directives for creating such
+boxes.
+For now, there are two directives available: ``nbinfo`` and ``nbwarning``.
+This is how an info box looks like:
+
+.. nbinfo::
+ **Note:**
+
+ This is an info box.
+
+ It may include nested formatting, even another info/warning box:
+
+ .. nbwarning:: **Warning:** You should probably not use nested boxes!
diff --git a/doc/allow-errors.ipynb b/doc/allow-errors.ipynb
new file mode 100644
index 0000000..6e45ae9
--- /dev/null
+++ b/doc/allow-errors.ipynb
@@ -0,0 +1,121 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "nbsphinx": "hidden"
+ },
+ "source": [
+ "This notebook is part of the `nbsphinx` documentation: http://nbsphinx.readthedocs.io/."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Ignoring Errors\n",
+ "\n",
+ "Normally, if an exception is raised while executing a notebook, the Sphinx build process is stopped immediately.\n",
+ "\n",
+ "If a notebook contains errors on purpose (or if you are too lazy to fix them right now), you have three options:\n",
+ "\n",
+ "1. Manually execute the notebook in question and save the results, see [the pre-executed example notebook](pre-executed.ipynb#Exceptions).\n",
+ "\n",
+ "2. Allow errors in all notebooks by setting this option in [conf.py](conf.py):\n",
+ "```\n",
+ "nbsphinx_allow_errors = True\n",
+ "```\n",
+ "\n",
+ "3. Allow errors on a per-notebook basis by adding this to the notebook's JSON metadata:\n",
+ "```json\n",
+ "\"nbsphinx\": {\n",
+ " \"allow_errors\": true\n",
+ "},\n",
+ "```\n",
+ "\n",
+ "This very notebook is an example for the last option.\n",
+ "The results of the following code cells are not stored within the notebook, therefore it is executed during the Sphinx build process.\n",
+ "Since the above-mentioned `allow_errors` flag is set in this notebook's metadata, all cells are executed although most of them cause an exception."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "nonsense"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "42 / 0"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "print 'Hello, world!'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "6 ~ 7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "6 * 7"
+ ]
+ }
+ ],
+ "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.5.1+"
+ },
+ "nbsphinx": {
+ "allow_errors": true
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 1
+}
diff --git a/doc/code-cells.ipynb b/doc/code-cells.ipynb
new file mode 100644
index 0000000..b8f2341
--- /dev/null
+++ b/doc/code-cells.ipynb
@@ -0,0 +1,497 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "nbsphinx": "hidden"
+ },
+ "source": [
+ "This notebook is part of the `nbsphinx` documentation: http://nbsphinx.readthedocs.io/."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Code Cells\n",
+ "\n",
+ "## Code, Output, Streams\n",
+ "\n",
+ "An empty code cell:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Two empty lines:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Leading/trailing empty lines:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "\n",
+ "\n",
+ "# 2 empty lines before, 1 after\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "A simple output:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "6 * 7"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The standard output stream:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "print('Hello, world!')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Normal output + standard output"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "print('Hello, world!')\n",
+ "6 * 7"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The standard error stream is highlighted and displayed just below the code cell.\n",
+ "The standard output stream comes afterwards (with no special highlighting).\n",
+ "Finally, the \"normal\" output is displayed."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "import sys\n",
+ "\n",
+ "print(\"I'll appear on the standard error stream\", file=sys.stderr, flush=True)\n",
+ "print(\"I'll appear on the standard output stream\")\n",
+ "\"I'm the 'normal' output\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Special Display Formats\n",
+ "\n",
+ "See [IPython example notebook](https://nbviewer.jupyter.org/github/ipython/ipython/blob/master/examples/IPython Kernel/Rich Output.ipynb).\n",
+ "\n",
+ "TODO: tables? e.g. Pandas DataFrame?"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "from IPython.display import display"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Local Image Files"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "from IPython.display import Image\n",
+ "i = Image(filename='images/notebook_icon.png')\n",
+ "i"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "display(i)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "For some reason this doesn't work with `Image(...)`:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "from IPython.display import SVG\n",
+ "SVG(filename='images/python_logo.svg')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Image URLs"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "Image(url='https://www.python.org/static/img/python-logo-large.png')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "Image(url='https://www.python.org/static/img/python-logo-large.png', embed=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "Image(url='http://jupyter.org/assets/nav_logo.svg')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "Image(url='https://www.python.org/static/favicon.ico')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "Image(url='http://python.org/images/python-logo.gif')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Math"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "from IPython.display import Math\n",
+ "eq = Math(r\"\\int_{-\\infty}^\\infty f(x) \\delta(x - x_0) dx = f(x_0)\")\n",
+ "eq"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "display(eq)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "%%latex\n",
+ "\\begin{equation}\n",
+ "\\int_{-\\infty}^\\infty f(x) \\delta(x - x_0) dx = f(x_0)\n",
+ "\\end{equation}"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### YouTube Videos"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "from IPython.display import YouTubeVideo\n",
+ "YouTubeVideo('WAikxUGbomY')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Unsupported Output Types\n",
+ "\n",
+ "If a code cell produces data with an unsupported MIME type, the Jupyter Notebook doesn't generate any output.\n",
+ "`nbsphinx`, however, shows a warning message."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "display({\n",
+ " 'text/x-python': 'print(\"Hello, world!\")',\n",
+ " 'text/x-haskell': 'main = putStrLn \"Hello, world!\"',\n",
+ "}, raw=True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## ANSI Colors\n",
+ "\n",
+ "The standard output and standard error streams may contain [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code) to change the text and background colors."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "print('BEWARE: \\x1b[1;33;41mugly colors\\x1b[m!', file=sys.stderr, flush=True)\n",
+ "print('ABC\\x1b[43mDEF\\x1b[35mGHI\\x1b[1mJKL\\x1b[49mMNO\\x1b[39mPQR\\x1b[22mSTU')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The following code showing the 8 basic ANSI colors is based on http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html.\n",
+ "Each of the 8 colors has an \"intense\" variation, which is used for bold text."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "text = ' XYZ '\n",
+ "formatstring = '\\x1b[{}m' + text + '\\x1b[m'\n",
+ "\n",
+ "print(' ' * 6 + ' ' * len(text) +\n",
+ " ''.join('{:^{}}'.format(bg, len(text)) for bg in range(40, 48)))\n",
+ "for fg in range(30, 38):\n",
+ " for bold in False, True:\n",
+ " fg_code = ('1;' if bold else '') + str(fg)\n",
+ " print(' {:>4} '.format(fg_code) + formatstring.format(fg_code) +\n",
+ " ''.join(formatstring.format(fg_code + ';' + str(bg))\n",
+ " for bg in range(40, 48)))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "ANSI also supports a set of 256 indexed colors.\n",
+ "The following code showing all of them is based on http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "formatstring = '\\x1b[38;5;{0};48;5;{0}mX\\x1b[1mX\\x1b[m'\n",
+ "\n",
+ "print(' + ' + ''.join('{:2}'.format(i) for i in range(36)))\n",
+ "print(' 0 ' + ''.join(formatstring.format(i) for i in range(16)))\n",
+ "for i in range(7):\n",
+ " i = i * 36 + 16\n",
+ " print('{:3} '.format(i) + ''.join(formatstring.format(i + j)\n",
+ " for j in range(36) if i + j < 256))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "You can even use 24-bit RGB colors:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "start = 255, 0, 0\n",
+ "end = 0, 0, 255\n",
+ "length = 79\n",
+ "out = []\n",
+ "\n",
+ "for i in range(length):\n",
+ " rgb = [start[c] + int(i * (end[c] - start[c]) / length) for c in range(3)]\n",
+ " out.append('\\x1b['\n",
+ " '38;2;{rgb[2]};{rgb[1]};{rgb[0]};'\n",
+ " '48;2;{rgb[0]};{rgb[1]};{rgb[2]}mX\\x1b[m'.format(rgb=rgb))\n",
+ "print(''.join(out))"
+ ]
+ }
+ ],
+ "metadata": {
... 3403 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/nbsphinx.git
More information about the Python-modules-commits
mailing list