It displays how to easily and fast master the essentials of formatting text with Markdown Syntax in Jupyter Notebook with concrete examples
In this post, we will learn systematically how to format text with Markdown syntax in the Jupyter Notebook with easily understanding example.
1.2 Create a Markdown cell
It is easy to create a Markdown cell in the Jupyter notebook. It can be divided into the following steps:
- insert a new cell
- click the drop-down of cell types, or
- use shortcut m on our computer keyboard immediately after inserting a new cell
2. Markdown Text Formatting
2.1 Headings
It is easy to create headers at different levels by using hash signs #
followed by a blank space and the header title. For example, we create the header from level 1 to level 6.
# Title of Header 1
## Title of Header 2
### Title of Head 3
#### Title of Header 4
##### Title of Header 5
###### Title of Header 6
It renders the following results:
Title of Header 1
Title of Header 2
Title of Head 3
Title of Header 4
Title of Header 5
Title of Header 6
2.2 Line Break
To create a line break, put two or more spaces at the end of each line, and then press enter
.
This is the first line.<space1><space2><enter>This is the second line.<space1><space2><enter>This is the third line.
This is a first line.
This is the second line.
This is the third line.
2.3 Paragraphs
It uses a blank lines to create paragraphs.
This is the first paragraphs in standard Markdown.
This is the second paragraphs in standard Markdown.
The result is as follows:
This is the first paragraphs in standard Markdown.
This is the second paragraphs in standard Markdown.
2.4 List and Nested List
It is very convenient to create an ordered, unordered and nested list in the Jupyter notebook. Let’s see some examples as follows.
(1) Ordered List
We can easily create an ordered list using numbers starting from number 1 or any numbers you like. What you see is what you type.
- Fruits
- Food
- Drink
(2) Unordered List
In the Jupyter notebook, an unordered list can be created with bullets using any of the following signs
- dash sign
-
- asterisk sign
*
- plus sign
+
For example, we use dash ‘-‘ to create an unordered lost.
- Fruits
- Food
- Drink
- Fruits
- Food
- Drink
(3) Nested list
To nest one list within another, just indent each item in the sublist by tap key, or four spaces.
(i) Ordered list with nested lists
We can create nested lists in an ordered list, and the nested lists can be
- unordered lists
- ordered lists
- mixed ones
1. Fruits
1.1. Apple
1.2. Banana
2. Food
- Bread
- Pasta
3. Drink
We obtain the following result.
- Fruits
1.1. Apple
1.2. Banana - Food
- Bread
- Pasta
- Drink
(ii) Unordered list with nested lists
Similarly, We can create nested lists in an unordered list, and the nested lists can be the following formats:
- unordered lists
- ordered lists
- mixed lists
Let’s see the following example, where it uses * to create the unordered lists.
* Fruits
* Apple
* Banana
* Food
1. Bread
2. Pasta
* Drink
It generates the following result.
- Fruits
- Apple
- Banana
- Food
- Bread
- Pasta
- Drink
2.5 Emphasis
(1) Bold
To bold text, add two asterisks **
or underscores __
before and after a word or phrase, or even a letter or more letters in a word. For example,
I want to use **bold text**.
I want to use __bold text__.
I want to use bold letters of **t**e**x**t.
The results are as follows:
I want to use bold text.
I want to use bold text.
I want to use bold letters of text.
(2) Italic
To italicize text, just add one asterisk sign *
, or underscore _
before and after a word or phrase, or even a letter or more letters in a word.
This is an *italicized text*.
This is an _italicized text_.
This is an italicized text.
This is an italicized text.
(3) Bold and Italic
To emphasize text with both bold and italics at the same time, add three asterisks or underscores before and after a word or phrase.
download
The bold and italic text is ***really important***.
The bold and italic text is ___really important___.
This bold and italic text is __*really important*__.
This bold and italic text is **_really important_**.
The results are the same as the follows.
The bold and italic text is really important.
The bold and italic text is really important.
This bold and italic text is really important.
This bold and italic text is really important.
(4) Highlight
We usually highlight a text, a code, a command, or path to draw other’s attention by using the backticks (`).
`print('Hi, Python!')`
`sudo install python3`
`~/Documents/mybooks/myjupyterbook/conternts`
print('Hi, Python!')
sudo install python3
~/Documents/mybooks/myjupyterbook/conternts
(5) Strikethrough
To strikethrough words means by putting a horizontal line through the center of them, which usually indicates that certain words are a mistake and excluded in the document.
In Markdown syntax, use two tilde symbols (~~) before and after the words to strikethrough these words. For example,
The following sentence is full of mistakes, so we strikethrough it.
~~We is living in an beautifully world.~~ We are living in a beautiful world.
The result looks as follows:
The following sentence is full of mistakes, so we strikethrough it.
We is living in an beautifully world. We are living in a beautiful world.
2.6 Blockquotes
Use a greater than sign (>) and then a space, then type the text. The text is indented and has a gray horizontal line to the left of it until the next carriage return. Let’s see an example as follows.
> This is the start of a blockquote.
>> This is a nested blockquote.
>>
> * a quoted list item 1.
> * a quoted list item 2.
> This is the end of the blockquote, and then add a space between the line and next regular text line.
This line resumes the regular paragraph text.
It renders the following result.
This is the start of a blockquote.
This is a nested blockquote.
- a quoted list item 1.
- a quoted list item 2.
This is the end of the blockquote, and then add a space between the line and next regular text line.
This line resumes the regular paragraph text.
2.7 Code Blocks
If you want to include a code block in your Jupyter notebook, just use three backticks
(`) or tilde (~)
signs to enclose the code. For example,
~~~python
for i in (1,2,3):
print(i)
~~~
or
```python
for i in (1,2,3):
print(i)
```
The results are the same as follows:
for i in (1,2,3):
print(i)
or
for i in (1,2,3):
print(i)
2.8 Horizontal Rules
A horizontal rule is usually used to provide a visual break and divide content. To create a horizontal rule, use three or more asterisks (***), dashes (—), or underscores (___) on a line by themselves.
***
---
___
They render the same horizontal rule as follows.
Task lists allow you to create a list of items with checkboxes. In Markdown, creating a task list by add dashes (-) and brackets with a space ([ ]) at the beginning of the list items, and add an x in between the brackets ([x]) to select a checkbox. For example:
### Publication Process:
- [x] Preparation of a book manuscript
- [x] Look for a press
- [ ] Proofreading
- [ ] Publish the book
It produces the following results,
Publication Process:
- [x] Preparation of a book manuscript
- [x] Look for a press
- [ ] Proofreading
- [ ] Publish the book
2.10 Hyperlinks
(1) Internal links
Links are either internal or external. Internal links are usually used to link to the sections in the notebook, and to do that we usually link to the header of that part using the code [heading title](#heading-title)
to link to the part of heading title. For the text in the parentheses, replace spaces and special characters with a hyphen. For example:
This example show you how to link to the section: **[2.9 Task Lists](#2.9-Task-Lists)**.
This example show you how to link to the section: 2.9 Task Lists.
When you click the link, it will skip to 2.9 Task Lists in the notebook.
You can read this post for more detailed and specific introduction on this topic.
(2) External links
External links are usually used to link to an external web page. You use [link text](http://url)
to make an external link. For example:
Deepsim Academy is E-learning platform on Python, Data analysis, Wavelet transform, as well as Machine learning, and you can visit [Deepsim Academy](https://academy.deepsim.xyz) for more information.
After running above Markdown cell, it renders the following result.
Deepsim Academy is E-learning platform on Python, Data analysis, Wavelet transform, as well as Machine learning, and you can visit Deepsim Academy for more information.
When you click Deepsim Academy in the above text, it directs you to the webpage of the Deepsim Academy.
(3) Reference Links
If there are more links, we can make the external link as reference.
Hi, I am Dr. Shouke Wei, the founder of [Deepsim Intelligence Technology][1] and [Deepsim Academy][2].[Deepsim Intelligence Technology][1] is AI and Data analysis based consulting company, and [Deepsim Academy][2] is E-learning paltform on Python, Data analysis, Wavelet transform and Machine learning. Besides, I have created [Deepsim Blog][3].
[1]: <https://deepsim.xyz/> "Deepsim Intelligence Technology"
[2]: <https://academy.deepsim.xyz/> "Deepsim Academy"
[3]: <https://blog.deepsim.xyz/> "Deepsim Blog"
This method is named as a “reference-style” link because it is similar to the in-text citations and references in an article, a thesis, or a report.
After running the above Markdown cell, we get the following text with three hyperlinks to the websites of Deepsim Intelligence Technology, Deepsim Academy and Deepsim Blog.
Hi, I am Dr. Shouke Wei, the founder of Deepsim Intelligence Technology and Deepsim Academy.Deepsim Intelligence Technology is AI and Data analysis based consulting company, and Deepsim Academy is E-learning paltform on Python, Data analysis, Wavelet transform and Machine learning. Besides, I have created Deepsim Blog.
2.11 Emoji
Adding Emojis can make the code output and documentation interesting and attractive. However, standard Markdown doesn’t seem to support emoji codes.
We can copy an emoji from a source like Emojipedia and past it to your Markdown text. For example:
I really love this video! ❤️
The story is so funny! 😂
It makes me laughing and laughing!🤣
Thank you, video author 🙏!
You can read more about how to insert Emojis in the Jupyter notebook in this post.