How to cross-reference to other pages from documentation

Note

This page was written in the style of a How-to Guide according to The Diátaxis Framework.

This guide shows how to reference to other pages in the documentation.

Warning

Actual cross-referencing is only possible with .rst files. If you are trying to cross-reference from a Jupyter notebook (.ipynb), you are actually linking to an external page, and therefore you should check How to add external links instead.

Pre-requisites

This guide assumes your project already has a working Sphinx documentation project in a folder called docs and the recommended folder structure. If you don’t have it, you can set it up with sphinx-quickstart following the tutorial Create a New Documentation Project.

Shorten the reference

It’s not always necessary to specify the full name of your object when writing the reference. For example, you can write :class:`.QuantumCircuit` instead of :class:`qiskit.circuit.QuantumCircuit` to link to QuantumCircuit if no other class from any module is called QuantumCircuit. If there is another class with the same name, you will get a warning from Sphinx. You can also set any title you want for your links by using the following syntax: :role:`title <name>`. For example, you can add this link by writing:

:class:`this link <qiskit.circuit.QuantumCircuit>`