Formating IPython Notebook with Markdown

Text can be added to IPython Notebooks using Markdown cells. Markdown is a popular markup language that is a superset of HTML. Its specification can be found here:

Markdown Basics

You can make text italic or bold.

You can build nested itemized or enumerated lists:

Unordered list can use

You can indent lists

Now another list:

  1. Here we go
    1. Sublist
    2. Sublist
  2. There we go
  3. Now this

You can add horizontal rules:

Here is a blockquote:

Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than right now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!

And shorthand for links:

IPython's website


If you want, you can add headings using Markdown's syntax:

Heading 1

Heading 2

Heading 2.1

Heading 2.2

BUT most of the time you should use the Notebook's Heading Cells to organize your Notebook content, as they provide meaningful structure that can be interpreted by other tools, not just large bold fonts.


Emphasis, aka italics, with asterisks or underscores.

Strong emphasis, aka bold, with asterisks or underscores.

Combined emphasis with asterisks and underscores.

Strikethrough uses two tildes. Scratch this.

Embedded Code

You can embed code meant for illustration instead of execution in Python:

def f(x):
    """a docstring"""
    return x**2

or other languages:

if (i=0; i<n; i++) {
  printf("hello %d\n", i);
  x += 4;

LaTeX Equations

Courtesy of MathJax, you can include mathematical expressions both inline: \(e^{i\pi} + 1 = 0\) and displayed:

\[e^x=\sum_{i=0}^\infty \frac{1}{i!}x^i\]

General HTML

Because Markdown is a superset of HTML you can even add things like HTML tables:

Header 1 Header 2
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2

Colons can be used to align columns.

Tables | Are | Cool |
------------- |:-------------:| -----:|
col 3 is | right-aligned | $1600 |
col 2 is | centered |$12 |
zebra stripes | are neat | $1 |

The outer pipes (|) are optional, and you don't need to make the raw Markdown line up. You can also use inline Markdown.

Markdown | Less | Pretty --- | --- | --- Still | renders | nicely 1 | 2 | 3

Local Files

If you have local files in your Notebook directory, you can refer to these files in Markdown cells via relative URLs that are prefixed with files/:


For example, in the "examples" sub-folder, we have the Gnu Radio logo:

<img src="files/examples/grc-logo.png" />

and a video with the HTML5 video tag:

<video controls src="files/examples/bigbuckbunny.ogg" />


Here's our logo (hover to see the title text):

Inline-style: alt text

Reference-style: alt text

Security of local files

Note that this means that the IPython notebook server also acts as a generic file server for files inside the same tree as your notebooks. Access is not granted outside the notebook folder so you have strict control over what files are visible, but for this reason it is highly recommended that you do not run the notebook server with a notebook directory at a high level in your filesystem (e.g. your home directory).

When you run the notebook in a password-protected manner, local file access is restricted to authenticated users unless read-only views are active.

Adapted From: Brian E. Granger's Git repository and Adam Pritchard's Git repository