Markdown for Jupyter Notebooks: A Handy Cheatsheet

Anurag
4 min readJun 9, 2023

--

If you’re using Jupyter Notebooks for documentation or creating informative content, Markdown is an essential tool that allows you to format text and make it more visually appealing. In this cheatsheet, we’ll explore various Markdown formatting techniques and examples that you can use in your Jupyter notebooks.

https://s33046.pcdn.co/wp-content/uploads/2020/08/notebook.png

Headings

Headings help structure your content and provide hierarchy. Here are examples of different heading levels you can use:

  • Notebook title: Use a single # followed by a blank space.
  • Example: # My Awesome Notebook
  • Major headings: Use ## followed by a blank space.
  • Example: ## Introduction
  • Subheadings: Use ### followed by a blank space.
  • Example: ### Installation Guide
  • 4th level subheadings: Use #### followed by a blank space.
  • Example: #### Advanced Techniques

Emphasis

Markdown provides options to emphasize text using bold or italic styles. Here’s how you can apply emphasis to your text:

  • Bold text: Surround the text with double underscores __ or double asterisks **.
  • Example: __Important__ or **Important**
  • Italic text: Surround the text with single underscores _ or single asterisks *.
  • Example: _Note_ or *Note*

Mathematical Symbols

When you need to display mathematical symbols or equations, you can enclose them within dollar signs $. For instance:

  • Inline mathematical symbols: $x + y = z$
  • Displayed mathematical symbols or equations: $$x + y = z$$

Monospace Font

To display text in a monospace font, use the grave accent or back single quotation mark (`) to surround the text. This is useful for displaying code snippets, file paths, or user input. For example:

  • `print(“Hello, World!”)`

Line Breaks

Sometimes, Markdown doesn’t create line breaks where you want them. To force a line break, use <br> in your Markdown code.

Indenting

You can indent text within Markdown cells by using the greater than sign (>). This is useful for indicating quoted text or code blocks. Here's an example:

> This text will be indented when rendered.

Bullets

Markdown allows you to create bulleted lists easily. You can use either a hyphen (-) or an asterisk (*) followed by one or two spaces to create a bullet point. For example:

  • Bulleted item 1
  • Bulleted item 2

Colored Note Boxes

To display text within colored boxes, you can use <div> tags. Different colors represent different types of notes. Here are examples of the available colors and their meanings:

Blue (alert-info):

<div class=”alert alert-block alert-info”>
<b>Tip:</b> Use blue boxes (alert-info) for tips and notes.
If it’s a note, you don’t have to include the word “Note”.
</div>

Yellow (alert-warning):

<div class=”alert alert-block alert-warning”>
<b>Example:</b> Use yellow boxes for examples that are not
inside code cells or use for mathematical formulas if needed.
</div>

Green (alert-success):

<div class=”alert alert-block alert-success”>
<b>Up to you:</b> Use green boxes sparingly and only for specific
purposes that other boxes can’t cover. For instance, if you have a lot
of related content to link to, you may use green boxes for
related links from each section of a notebook.
</div>

Red (alert-danger):

<div class=”alert alert-block alert-danger”>
<b>Just don’t:</b> In general, avoid red boxes. They should only be
used for actions that might cause data loss or another major issue.
</div>

Graphics

You can easily include images in Markdown cells by dragging and dropping them directly into the cell. For other cell types, you can use the following code to add hosted graphics:

<img src=”url/filename.gif” alt=”Alt text” title=”Title text” />

Note that adding captions to graphics is not supported in Markdown.

Geometric Shapes

If you need to include geometric shapes, you can use Unicode characters to represent them. Simply use &# followed by the decimal or hex reference number for the shape. For example, &#9658; represents a right-pointing triangle.

You can find a list of reference numbers for geometric shapes in the UTF-8 Geometric Shapes reference.

Horizontal Lines

To insert a horizontal line in your Markdown cell, simply enter three asterisks on a new line:

***

Internal Links

If you want to link to a section within your notebook, you can use the following code:

[Section title](#section-title)

Make sure to replace any spaces and special characters in the section title with hyphens. Alternatively, you can add an ID above the section using the following code:

<a id=”section_ID”></a>

External Links

To create a link to an external site, use the following code:

__[link text](http://url)__

Replace link text with the text you want to display for the link, and http://url with the actual URL you want to link to.

Markdown in Jupyter Notebooks is a powerful tool for creating well-structured and visually appealing documentation. By utilizing the formatting techniques mentioned above, you can enhance the readability and user experience of your notebooks. So go ahead and leverage the power of Markdown in your Jupyter notebooks to create amazing content!

Remember, this cheatsheet provides only a glimpse of what Markdown can do. Feel free to explore more advanced Markdown syntax and techniques to further customize your Jupyter notebooks. Happy Markdowning!

--

--

Anurag

Currently working as Product Manager who is also a passionate engineer with an experience in Artificial Intelligence.