1.3 Markdown Syntax#


Creating a New Jupyter Notebook#

  1. Open Visual Studio Code (or JupyterLab).

  2. Click on “File” > “New File” > “Jupyter Notebook” or create a new .ipynb file.

  3. Select the Python interpreter (kernel) you want to use.

  4. Save the notebook with a relevant name.

  5. Begin writing markdown and code cells to document and run your code.


Anatomy of a Jupyter Notebook#

  • Markdown Cells: Used for formatting text and documentation using Markdown syntax.

  • Code Cells: Used to write and execute Python code.

  • YAML Metadata (optional): Jupyter Notebook files can contain metadata, but it’s usually handled behind the scenes unless you’re converting to formats like HTML or PDF.


Aesthetic Matters#

Tidy and organized notebooks are easier to read—for you and anyone you share them with.
It is always good practice to properly document your work, divide it into meaningful sections, and alternate between markdown and code cells to explain what your code is doing.


Formatting Text in Markdown#

Structure of the Markdown#

Markdown has a linear structure and is great for documenting your projects, especially when sharing on platforms like GitHub or in collaborative research environments.

Some examples of how to format text:

Heading 1#

Heading 2#

Heading 3#

Heading 4#

Heading 5#
Heading 6#

Italic:#

  • Surround text with single asterisks * or underscores _.

Bold:#

  • Surround text with double asterisks ** or double underscores __.

Bold Italic:#

  • Combine both formats with triple asterisks *** or triple underscores ___.

Ordered List#

  1. First item

  2. Second item

Unordered List#

  • Bullet item 1

  • Bullet item 2

  • Another bullet 1

  • Another bullet 2


Code Chunks#

In Jupyter, code chunks are simply code cells.

To insert a new code cell:

  • Click the + Code button or use the shortcut:

    • Windows/Linux: Alt + Enter (run current + insert new below)

    • macOS: Option + Enter

You can run a code cell using:

  • Shift + Enter – runs the cell and moves to the next

  • Ctrl + Enter – runs the cell and stays in the same cell

Colored boxes#

Do not overuse them, but there may be instances where they are actually helpful! In general, they can be really useful to orient yourself in your own scripts, knowing where each section is. Then, for the portfolio submission, keep them to the bare minimum.



Tip: Use blue boxes (alert-info) for tips and notes. If it’s a note, you don’t have to include the word “Note”.
Example: Use yellow boxes for examples that are not inside code cells.
Up to you: Use green boxes sparingly, and only for some specific purpose that the other boxes can't cover. For example, if you have a lot of related content to link to, maybe you decide to use green boxes for related links from each section of a notebook.
Just don't: In general, avoid the red boxes. These should only be used for actions that might cause data loss or another major issue.

And now, the source code for the markdown output we saw above:#


"""
# A Jupyter Notebook Markdown Syntax Example

---

## Creating a New Jupyter Notebook
1. Open Visual Studio Code (or JupyterLab).
2. Click on "File" > "New File" > "Jupyter Notebook" or create a new `.ipynb` file.
3. Select the Python interpreter (kernel) you want to use.
4. Save the notebook with a relevant name.
5. Begin writing markdown and code cells to document and run your code.

---

### Anatomy of a Jupyter Notebook
- **Markdown Cells:** Used for formatting text and documentation using Markdown syntax.
- **Code Cells:** Used to write and execute Python code.
- **YAML Metadata (optional):** Jupyter Notebook files can contain metadata, but it's usually handled behind the scenes unless you're converting to formats like HTML or PDF.

---

### Aesthetic Matters
Tidy and organized notebooks are easier to read—for you and anyone you share them with.  
It is always good practice to properly document your work, divide it into meaningful sections, and alternate between markdown and code cells to explain what your code is doing.

---

## Formatting Text in Markdown

### Structure of the Markdown
Markdown has a linear structure and is great for documenting your projects, especially when sharing on platforms like GitHub or in collaborative research environments.

Some examples of how to format text:

# Heading 1  
## Heading 2  
### Heading 3  
#### Heading 4  
##### Heading 5  
###### Heading 6  

### *Italic*:  
- Surround text with single asterisks `*` or underscores `_`.

### **Bold**:  
- Surround text with double asterisks `**` or double underscores `__`.

### ***Bold Italic***:  
- Combine both formats with triple asterisks `***` or triple underscores `___`.

### Ordered List
1. **First item**  
2. **Second item**

### Unordered List
* **Bullet item 1**  
* **Bullet item 2**

- **Another bullet 1**  
- **Another bullet 2**

---

## Code Chunks

In Jupyter, **code chunks** are simply code cells.

To insert a new code cell:
- Click the `+ Code` button or use the shortcut:
  - **Windows/Linux:** `Alt + Enter` (run current + insert new below)
  - **macOS:** `Option + Enter`

You can run a code cell using:
- `Shift + Enter` – runs the cell and moves to the next
- `Ctrl + Enter` – runs the cell and stays in the same cell

## Create links

[**Link to Markdown Cheatsheet**](https://www.ibm.com/docs/en/watson-studio-local/1.2.3?topic=notebooks-markdown-jupyter-cheatsheet)

[*You can create a link to a desired webpage*](https://www.ibm.com/docs/en/watson-studio-local/1.2.3?topic=notebooks-markdown-jupyter-cheatsheet)

[True story](https://www.opencpu.org/images/markdown-everywhere.jpg)

[Follow me](https://i.redd.it/icdv9tg5eyt61.jpg)

---

<br >
<br >

## Colored boxes

Do not overuse them, but there may be instances where they are actually helpful!
In general, they can be really useful to orient yourself in your own scripts, knowing where each section is. Then, for the portfolio submission, keep them to the bare minimum.
<br >
<br >
<br >

---
<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>

<div class="alert alert-block alert-warning">
<b>Example:</b> Use yellow boxes for examples that are not 
inside code cells.
</div>

<div class="alert alert-block alert-success">
<b>Up to you:</b> Use green boxes sparingly, and only for some specific 
purpose that the other boxes can't cover. For example, if you have a lot 
of related content to link to, maybe you decide to use green boxes for 
related links from each section of a notebook.
</div>

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