In Jupyter Book Fundamentals we covered the basics of Jupyter Book structure and writing text content in markdown. However, Jupyter Book can go far beyond basic text formatting and has tools to help you share information with figures, videos, special blocks, interactive elements and advanced cross-referencing. In this lesson we will look at some of these features that elevate your book over a plain-text document.
Directives and roles¶
This lesson will make use of roles and directives. These have a similar syntax, and are used to extend the basic markdown features. The main difference is that roles are written in-line and take a single argument, whereas directives are multi-line containers which may have multiple arguments and options.
Both directives and roles use “fences”, which are either (at least) three colons ::: or backticks ```.
You can use more colons or backticks to nest directives.
The MyST documentation explains the syntax, nesting and the difference between colons and backticks in more detail.
Images and figures¶
The quickest way to include an image is with the Markdown notation  as done below
resulting in

However, this gives us limited options to customize the figure.
We can include more options using the figure directive.
If we want to add a figure to our book, we can use the URL of an external website (as in the figure above). However, this carries the risk that the figure will no longer be visible if it is moved from its location.[1] It is therefore better to have the figure as a local source file where you build the book. We will do this by adding an image file to your git repository.
The filename is case sensitive. So it matters whether your extension is .png or .PNG. You can also use .* to avoid this issue, the system will then pick the right extension where the best options is chosen first (e.g. .gif over .png, and .svg over .jpg). This also avoids conversion issues for pdf output of non-static or non-supported formats
You can find more information about figure options in the MyST documentation.
You can position figures in different places (left / center / right / margin), adjust the size, add a caption, etc.. Check the documentation above and try out the different settings.
Embed a video (from YouTube)¶
We can embed videos hosting platforms like YouTube or Vimeo using the iframe directive. For example, the following code embeds a video about Markdown,
```{iframe} https://www.youtube.com/embed/dhzrlXzYOlU?si=n2U0HSJyotjp-r93
:width: 80%
Purves et al. - Jupyter Book 2 0 – A Next Generation tool for sharing for Computational Content
```resulting in
Purves et al. - Jupyter Book 2 0 – A Next Generation tool for sharing for Computational Content
The use of iframe is not limited to videos. You can embed content from other websites that support iframe embedding.
You can also use the figure directive to include a video from a local file, just like with images.
There is a plugin available that converts the YouTube clip in a qr code and a thumbnail for pdf exports.
Embed a video of your choice using either the iframe or video directive.
You can use a YouTube video or any other video that supports embedding.
Displaying code¶
You can display code using Markdown syntax.
```language
code
```for example,
``` python
print("Hello world!")
```renders as,
print("Hello world!")You can also use the code directive which will render the code in a block and has features line line numbers and captions.
Take the following Python code snippet and put it in a code block with
- Python syntax highlighting 
- Indicate the file name - fibonacci.py
- Add a caption explaining that this function returns the - nth number in the Fibonacci series
def fib(n):
    if n < 0:
        return
    if n in [0, 1]:
        return n
    else:
        return fib(n-2) + fib(n-1)Diagrams¶
MyST supports displaying Mermaid diagrams using the mermaid directive.
Mermaid let’s you create a number of different types of diagrams using plain text.
This is a great way to show diagrams in your book, while keeping the source easily editable in version control.
For example, the following directive
```{mermaid}
flowchart LR
  Start --> Stop
  A1(["Novice"]) --> B1
  A2(["I do know"]) --> B2 & B1
  B1(["Expert"])
  B2(["try"])
  A(["Start"]) --> B{"Decision"}
  B --> C["Option A"] & D["Option B"]
```Renders as,
Create your own mermaid diagram. You can create a diagram from scratch, consulting the syntax in the Mermaid documentation, or copy an example
Admonitions¶
Admonitions can be used to separate text from the main text and highlight it appropriately. Here are a set of admonitions built in to Myst,
This is an note admonition
This is an important admonition
This is an hint admonition
This is an seealso admonition
This is an tip admonition
This is an attention admonition
This is an caution admonition
This is an warning admonition
This is an danger admonition
This is an error admonition
Custom admonitions can also be created in a plugin, but hiding the icon and adding your own icon in the title is a quick way to get a custom look.
Use an appropriate admonition to contain the following paragraphs.
Hand wash only
Syntax error
Beware of the leopard
Tabs, cards, grids¶
MyST has a number of features for arranging and organising content, you have already seen some of these following these lessons.
Tabs can be used to separate content into different sections that can be viewed by clicking on the tab headers. They are useful when you want to present a set of mutually exclusive options.
:::: {tab-set}
::: {tab-item} Tab 1
Content for Tab 1
:::
::: {tab-item} Tab 2
Content for Tab 2
:::
::::Renders as,
Content for Tab 1
Content for Tab 2
Put the following instructions for installing MyST into a tab set,
splitting instructions for pip and npm into different tabs
Install MyST
Using pip pip install mystmd
Using npm npm install -g mystmd
- Fetching images from someone else’s site also puts strain on their web server, which they may not appreciate.