Multicell

Overview:

  • Teaching: 10 min
  • Exercises: 0 min

Questions

  • What is a multicell?
  • How can I use multicell functionality?

Objectives

  • Understand how the multicell can be used

A group of notebook cells can be grouped together into an environment using the multicell functionality. This is done using a keyword, followed by a plus (+). From that point on in the notebook all cells, including code and raw cells, are part of the multicell environment. The multicell is terminated using : keyword +, after which cells behave as normal.

Experimental

Multicell support is still considered experimental, so be wary that there may still be some bugs in the functionality and unexpected behaviour.

To prevent markdown cells from being executed, we will show the syntax using %%markdown magic. After the example the rendered output is shown.

In [1]:
%%markdown
## Information+: Multicell information 1
Here is some information about multicells

Information+: Multicell information 1

Here is some information about multicells

  • They group notebook cells together into one environment
  • They can be very useful

The multicell is terminated using a colon and the corresponding keyword. (1)

:information+

Multicell information 1

Here is some information about multicells

  • They group notebook cells together into one environment
  • They can be very useful
  • They struggle when there are identical cells in a notebook

The multicell is terminated using a colon and the corresponding keyword. (2)

The above doesn't really show much additional functionality, apart from adding a big indent to the additional cells. The real power of multicells is combining them with code and raw cells

In [2]:
%%markdown
## Information+: Multicell information 2
This is a raw cell

Information+: Multicell information 2

This is a raw cell

RAW CELL

This is a simple Python3 code cell

In [3]:
import __hello__
Hello world!

This is the end of the multicell

:information+

Multicell information 2

This is another raw cell

ROAR

This is a different Python3 code cell

In [4]:
import math
print(math.pi)
3.141592653589793

This is the end of the next multicell

It is even possible to nest multicells, given that they are distinct environments. However, we strongly discourage the use of the nesting functionality, and it may be removed in the future.

Forgetting the : keyword +

If the corresponding : keyword + is missing from the notebook, there is no way to stop NBfancy from consuming all of the remaining cells in that notebook and including them in that multicell. This is very noticable behaviour and is easily corrected by adding the line to original plain notebook.

You were probably curious about nested multicells

Setup: Don't do it!

Key Points:

  • A multicell environment uses a keyword followed by a +
  • All cells in the notebook between the first multicell and the : keyword + go into the multicell
  • Multicells are useful for highlighting code