An Example Notebook

This notebook is meant for testing conversion to other formats.

It contains Markdown cells, code cells with different kinds of outputs and raw cells with different formats.

Markdown

We can use emphasis, boldface, preformatted text.

It looks like strike-out text is not supported: [STRIKEOUT:strikethrough].
  • Red
  • Green
  • Blue

  1. One
  2. Two
  3. Three

Equations

Equations can be formatted really nicely, either inline, like \(\text{e}^{i\pi} = -1\), or on a separate line, like

\[\int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)\]

Code

We can also write code with nice syntax highlighting:

print("Hello, world!")

Tables

A B A and B
False False False
True False False
False True False
True True True

Images

PNG file (local): Jupyter notebook icon

SVG file (local): Python logo

PNG file (remote): Python logo (remote)

SVG file (remote): Jupyter logo (remote)

Code Cells

An empty code cell:

In [1]:

A cell with no output:

In [1]:
None

A simple output:

In [2]:
6 * 7
Out[2]:
42

The standard output stream:

In [3]:
print('Hello, world!')
Hello, world!

Normal output + standard output

In [4]:
print('Hello, world!')
6 * 7
Hello, world!
Out[4]:
42

The standard error stream is highlighted and displayed just below the code cell. The standard output stream comes afterwards (with no special highlighting). Finally, the “normal” output is displayed.

In [5]:
import logging
logging.warning('I am a warning and I will appear on the standard error stream')
print('I will appear on the standard output stream')
'I am the "normal" output'
WARNING:root:I am a warning and I will appear on the standard error stream
I will appear on the standard output stream
Out[5]:
'I am the "normal" output'

Special Display Formats

See IPython example notebook.

TODO: tables? e.g. Pandas DataFrame?

In [6]:
from IPython.display import display, Image, SVG, Math, YouTubeVideo

Local Image Files

In [7]:
i = Image(filename='images/notebook_icon.png')
i
Out[7]:
_images/example_22_0.png
In [8]:
display(i)
_images/example_23_0.png

For some reason this doesn’t work with Image(...):

In [9]:
SVG(filename='images/python_logo.svg')
Out[9]:

Image URLs

In [10]:
Image(url='https://www.python.org/static/img/python-logo-large.png')
Out[10]:
In [11]:
Image(url='https://www.python.org/static/img/python-logo-large.png', embed=True)
Out[11]:
_images/example_28_0.png
In [12]:
Image(url='http://jupyter.org/assets/nav_logo.svg')
Out[12]:
In [13]:
Image(url='https://www.python.org/static/favicon.ico')
Out[13]:
In [14]:
Image(url='http://python.org/images/python-logo.gif')
Out[14]:

Math

In [15]:
eq = Math(r"\int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)")
eq
Out[15]:
\[\int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)\]
In [16]:
display(eq)
\[\int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)\]
In [17]:
%%latex
\begin{equation}
\int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
\end{equation}
\[\begin{equation} \int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0) \end{equation}\]
In [18]:
YouTubeVideo('iV2ViNJFZC8')
Out[18]:

Raw Cells

Cells with the cell type “Raw NBConvert” can have different formats. This information is stored in the notebook metadata. To select the format from within Jupyter, switch the cell toolbar to “Raw Cell Format”.

By default (if no cell format is selected), the cell content is included (without any conversion) in both the HTML and LaTeX output. This is typically not useful at all.

Raw cells in “reST” format are interpreted as reStructuredText and parsed by Sphinx. The result is visible in both HTML and LaTeX output. This way, links from Jupyter notebooks to reST pages are possible, e.g. A Normal reStructuredText File.

Raw cells in “Markdown” format are interpreted as Markdown and the result is included in both HTML and LaTeX output. Since the Jupyter Notebook also supports “normal” Markdown cells, this might not be useful at all.

Raw cells in “HTML” format are only included in HTML output (without any conversion). This might not be very useful, since raw HTML code is also allowed within “normal” Markdown cells.

Raw cells in “LaTeX” format are only included in LaTeX output.

Raw cells in “Python” format are not shown at all (nor acted upon in any way).