Keywords

Overview:

  • Teaching: 10 min
  • Exercises: 0 min

Questions

  • How can I define my own keywords?

Objectives

  • Learn how to make a new type of environment

If NBfancy is initialised with the flag --extra_config it will give the user access to two additional configuration files: keywords.cfg and box.ipynb. The first of these, keywords.cfg, can be used to modify the behaviour of existing keywords and allows the user to define their own keywords. The notebook file called "box" is discussed in the next section.

In [1]:
!nbfancy init example2 --extra_conf
!ls example2/config
box.ipynb  footer.ipynb  header.ipynb  keywords.cfg

The configuration file itself is a CSV file, which defines the behaviour of the underlying keywords. If this file is present and different to the internal configuration, it will be used instead.

In [2]:
!cat example2/config/keywords.cfg
##################################################
## Default keywords and colour scheme
## Supported colours:
## red, orange, yellow, green, blue, purple,
## brown, black, grey, gray, white
## Supported symbols from font-awesome
##################################################

## Heading
Keyword, Colour, Symbol, keep_keyword, hide

## Environments
Schedule, white, fa-clock-o, True, False

Prerequisites, green, fa-star, True, False
Overview, green, fa-file-o, True, False
Key Points, green, fa-key, True, False
Setup, green, fa-gears, True, False

Exercise, yellow, fa-pencil-square-o, False, False

Information, blue, fa-info-circle, False, False
Solution, blue, fa-eye, False, True

Comments in this file are denoted using # and any line starting with # is ignored. Blank lines are also ignored allowing for the config to contain vertical spaces. The first line defines the headings: the keyword and all the properties that are expected. After that each line defines an environement by defining a keyword, which will trigger the cell in a notebook to be processed followed by the formatting. The formatting consists of the colour of the boxm the symbol as defined by the font-awsome font, whether or not the keyword is printed in the rendered notebook and finally whether the cell get hidden (used for solutions).

Key Points:

  • The --extra_conf flag for the nbfancy init command gives access to more configuration files
  • The file keywords.cfg is a CSV file used to define new keyword environments