Michael_Scharf
Michael_Scharf

Reputation: 34508

How to reference a IPython notebook cell in markdown?

How do I reference a cell in a IPython notebook markdown?

I know how to make a reference to an external link. But is there a way to assign an ID to a cell and then refer to the cell in the markdown?

Upvotes: 138

Views: 89368

Answers (2)

Pedro Marcelino
Pedro Marcelino

Reputation: 1038

If you want to link directly to a specific section of your notebook, it can be useful to use this code: [section title](#section-title). Note that, for the text in the parentheses, you should replace spaces and special characters with a hyphen.

As an example, consider this case in which we want to insert a link to the section 'Univariate + One step ahead':

Section that I want to link

To do so, we just need to add the code [Univariate + One step ahead](#Univariate-+-One-step-ahead):

Code to create the link

This way we avoid the introduction of an anchor tag, since the section title already acts as one.

Upvotes: 75

Amit
Amit

Reputation: 20456

Yes, there's way to do just that in IPython.

First, define the destination in the cell you want to link with a html anchor tag and give it an Id. For example:

<a id='another_cell'></a>

Note - When you run the above cell in markdown, it will become invisible. You can add some text above the anchor to identify the cell.

Second, create the internal hyperlink to the destination created above using Markdown syntax in another cell and run it:

[Another Cell](#another_cell)

Now, clicking on link should take you to the destination.

Upvotes: 177

Related Questions