Skip to content

Linking to other Jupyter notebooks

Rini Banerjee edited this page Jul 30, 2020 · 5 revisions

Links to other Jupyter notebooks will initially not work. For example, if we are in the wave1D_fd2.ipynb notebook, we might come across a link like the following:

Clicking this will not do anything. If we double click on the notebook cell, we should see the following Markdown:

[wave:pde1:num:dispersion](#wave:pde1:num:dispersion)

The text in the square brackets is what the reader of the notebook sees, while the text in the normal brackets is the reference to the section we want to open when the link is clicked.

What to do

Step 1: Figure out which notebook this should link to. At this stage, it would be a good idea to look at the corresponding section for this notebook in the original book pdf and find out which part of the book is being referred to. There is also a readme in each subdirectory in fdm-devito-notebooks that explains which notebook corresponds to which book chapters for each section. You can use both of these to work out which notebook needs to be opened when clicking on the link.

For this example, we find that wave_analysis.ipynb contains the book section, and so we change the Markdown to the following:

[wave:pde1:num:dispersion](wave_analysis.ipynb#wave:pde1:num:dispersion)

Now, our link will look the same, but when we click it, it should open the wave_analysis.ipynb notebook and go to the 'Numerical dispersion relation' section.

Step 2: Now we need to change the text in the square brackets to the name of the section we are referring to, like so:

[Numerical dispersion relation](wave_analysis.ipynb#wave:pde1:num:dispersion)

Now, when we run our cell, we should see the following:

and clicking this should take us to the same notebook and same section as before.

NB: This works with notebooks in different directories too - all we need to do is provide the path. If we wanted to access this notebook section from 01_vib, for example, we would put:

[Numerical dispersion relation](../02_wave/wave_analysis.ipynb#wave:pde1:num:dispersion)

Find and replace

Once you have verified that the above works, you can apply this to all links in this notebook by clicking Edit -> Find and Replace. Then click the up-and-down button (as shown below) to replace all occurrences.