#!/usr/bin/env python # coding: utf-8 # # An Example Notebook # # This notebook is meant for testing conversion to other formats. # # It contains [Markdown cells](#Markdown), [code cells](#Code-Cells) with [different kinds of outputs](#Special-Display-Formats) and [raw cells](#Raw-Cells) with different formats. # ## Markdown # # We can use *emphasis*, **boldface**, `preformatted text`. # # > It looks like strike-out text is not supported: ~~strikethrough~~. # # * Red # * Green # * Blue # # *** # # 1. One # 1. Two # 1. 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: # # ```python # 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](images/notebook_icon.png) # # SVG file (local): ![Python logo](images/python_logo.svg) # # PNG file (remote): ![Python logo (remote)](https://www.python.org/static/img/python-logo-large.png) # # SVG file (remote): ![Jupyter logo (remote)](http://jupyter.org/assets/nav_logo.svg) # ### Links to Other Notebooks # # Relative links to local notebooks can be used: [a link to a notebook in a subdirectory](subdir/another.ipynb), [a link to an orphan notebook](orphan.ipynb) (latter won't work in LaTeX output, because orphan pages are not included there). # # This is how a link is created in Markdown: # # ``` # [a link to a notebook in a subdirectory](subdir/another.ipynb) # ``` # # Markdown also supports *reference-style* links: [a reference-style link][mylink], [another version of the same link][mylink]. # # [mylink]: subdir/another.ipynb # # These can be created with this syntax: # # ``` # [a reference-style link][mylink] # # [mylink]: subdir/another.ipynb # ``` # # Links to sub-sections are also possible, e.g. [this subsection](subdir/another.ipynb#A-Sub-Section). # # This link was created with: # # ``` # [this subsection](subdir/another.ipynb#A-Sub-Section) # ``` # # You just have to remember to replace spaces with hyphens! # # BTW, links to sections of the current notebook work, too, e.g. [beginning of this section](#Links-to-Other-Notebooks). # # This can be done, as expected, like this: # # ``` # [beginning of this section](#Links-to-Other-Notebooks) # ``` # ## Code Cells # # An empty code cell: # In[ ]: # A cell with no output: # In[ ]: None # A simple output: # In[ ]: 6 * 7 # The standard output stream: # In[ ]: print('Hello, world!') # Normal output + standard output # In[ ]: print('Hello, world!') 6 * 7 # 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[ ]: 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' # ## Special Display Formats # # See [IPython example notebook](https://nbviewer.jupyter.org/github/ipython/ipython/blob/master/examples/IPython Kernel/Rich Output.ipynb). # # TODO: tables? e.g. Pandas DataFrame? # In[ ]: from IPython.display import display, Image, SVG, Math, YouTubeVideo # ### Local Image Files # In[ ]: i = Image(filename='images/notebook_icon.png') i # In[ ]: display(i) # For some reason this doesn't work with `Image(...)`: # In[ ]: SVG(filename='images/python_logo.svg') # ### Image URLs # In[ ]: Image(url='https://www.python.org/static/img/python-logo-large.png') # In[ ]: Image(url='https://www.python.org/static/img/python-logo-large.png', embed=True) # In[ ]: Image(url='http://jupyter.org/assets/nav_logo.svg') # In[ ]: Image(url='https://www.python.org/static/favicon.ico') # In[ ]: Image(url='http://python.org/images/python-logo.gif') # ### Math # In[ ]: eq = Math(r"\int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)") eq # In[ ]: display(eq) # In[ ]: get_ipython().run_cell_magic('latex', '', '\\begin{equation}\n\\int_{-\\infty}^\\infty f(x) \\delta(x - x_0) dx = f(x_0)\n\\end{equation}\n') # In[ ]: YouTubeVideo('iV2ViNJFZC8') # ## 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 "Python" format are not shown at all (nor acted upon in any way). print("I'm a raw Python cell!")