Skip to main content

Spell Check in Jupyter Notebook

The purpose of this post is to show how to have automatic spell check in Jupyter Notebook, as shown below.

Example of spell checking in Jupyter Notebook.

There are several ways to do this. However, the easiest way is through the (nbextension) Spellchecker. plugin.

Step by step

The steps to follow are those:

  1. Install Jupyter notebook extensions (nbextensions). This includes Spellchecker.

  2. Locate the dictionaries in the folder where the plugin is. Dictionaries must use UTF-8 encoding.

  3. Configure the path of the dictionaries. This can be a URL or a path relative to the folder where the plugin is located.

We will describe each step in detail below.

Step 1: Install nbextensions

There is a list of plugins that add some commonly used functionality to the Jupyter notebook.

Type the following in a terminal, to install it using PIP.

pip install jupyter_contrib_nbextensions

However, if Anaconda is being used the recommended method is to use conda, as shown below.

conda install -c conda-forge jupyter_contrib_nbextensions

This should install the plugins and also the configuration interface. In the main menu of Jupyter notebook a new tab named Nbextension will appear. Here you can choose the add-ons to use. The appearance is as follows.

Graphical interface for Jupyter plugins.

Some recommended plugins are:

  • Collapsible Headings: that allows to hide sections of the documents.

  • RISE: that turns notebooks into presentations.

Step 2: Dictionaries for Spanish

The documentation of Spellchecker suggests using a Python script to download dictionaries from project Chromium. However, these are encoded in ISO-8859-1 (western) and it fails for characters with accents or tildes. So, to avoid problems the dictionary must be UTF-8. They can be downloaded at this link.

Once you have the dictionaries, they must be located in the path of the plugin. On my computer this would be

~/.local/share/jupyter/nbextensions/spellchecker/

and within this we will place them in

~/.local/share/jupyter/nbextensions/spellchecker/typo/dictionaries

This location is arbitrary, the important thing is that we need to know the relative path to the plugin.

Step 3: Plugin Configuration

Now, in the Nbextensions tab we select the plugin and fill the fields with the information from our dictionary:

  • language code to use with typo.js: es_ES

  • url for the dictionary .dic file to use: ./typo/dictionaries/es_ES.dic

  • url for the dictionary .aff file to use: ./typo/dictionaries/es_ES.aff

This is shown below.

Configuration with local files.

Another option is to use the URL for the files. The dictionaries of the project hunspell in UTF-8 are available at https://github.com/wooorm/dictionaries. In this case, the configuration would be:

  • language code to use with typo.js: es_ES

  • url for the dictionary .dic file to use: https://raw.githubusercontent.com/wooorm/dictionaries/master/dictionaries/es/index.dic

  • url for the dictionary .aff file to use: https://raw.githubusercontent.com/wooorm/dictionaries/master/dictionaries/es/index.aff

And it is shown below.

Configuration with remote files.

Comments

Comments powered by Disqus