Skip to article content


Link to equations, figures, tables, and so much more!

References refer to labeled content (e.g. a figure, document or table) and automatically generates links and extra information, like numbering. This page covers the basics of setting up references to content and shows examples for sections, figures, tables and equations.

1Directive Targets¶

Targets are custom anchors that you can refer to elsewhere, for example, a figure, section, table, program, or proof. To be referenced, they must have a label/identifier pair in the AST. These can be created by setting the label option in many directives. For example, to label and reference a figure, use the following syntax:

Cross-referencing content is accomplished with markdown link syntax ([text](#target)) where #target is the target label[1], like the figure, equation or section header that you are referencing. If you leave the text empty, MyST will fill in the link with the title, caption, document name, or equation number as appropriate (e.g. “Figure 1” or “Section 1.3.7”). If you do supply text, you can control what is displayed in the reference, as well as have access to placing the name and enumerator of the target, using {name} and {number}, respectively[2].

MyST SyntaxRendered
Default for numbered references is to fill in the listing and number (e.g. Figure 1.).
Note that headings are numbered on this page, so it will show the number rather than the header title.
Section 3
[Sec. %s](#targeting-headers)
Modify the title, but keep the enumerator, you can use {number} or %s to place the number.
Note that unnumbered targets (e.g. a paragraph) will resolve the number to ??, similar to LaTeX\LaTeX, and a warning shown.
Sec. 3
[Sec. **_%s_**](#targeting-headers)
Markup is parsed first and then the content in placed.
Content inside of inlineCode is not replaced.
Sec. 3
[Section "{name}"](#targeting-headers)
Use {name} to place the name of the header in the content.
Headers resolve the text of the header, if there is a caption in the target it will be used.
For targets that do not have a caption or header, the name will resolve to the label.
Section “Header Targets”
[**bold _reference_**](#targeting-headers)
If you override the text in the link, that will be used.
bold reference
Link to documents using relative links from the markdown.
Citations and Bibliography
Link to static files that will be included in your built website. Similar to the {download} role.

3Header Targets¶

To add labels to a header use (my-section)= before the header, these can then be used in markdown links and {ref} roles. This is helpful if you want to quickly insert links to other parts of your book. Referencing a heading will show the heading and the subsequent two pieces of content[3], unless a header is encountered.

4Header Numbering¶

By default section numbering for headers is turned off with numbering for figure and table numbering enabled. To turn on numbering for headers, you can can change the frontmatter in the document or project. See Section 9 for more details on the numbering object.

5Equations Targets¶

To reference equations, use the {eq} role. It will automatically insert the number of the equation. Note that you cannot modify the text of equation links.

6Notebook Cell Targets¶

You can label notebook cells using a comment at the top of the cell, using a #| label: syntax, or have this added directly in the notebook metadata for the cell.

#| label: my-cell
print('hello world')

The cell output or the entire cell can be embedded or referred to using the image or link syntax.

[](#my-cell) - This is a cross-reference to a notebook cell
![](#my-cell) - This will embed the output of a notebook cell

or as a figure directive, where you can then add a caption. If you are referring to that figure in a further cross reference that figure (i.e. not the original cell), give it a new name.

:::{figure} #my-cell
:label: fig-my-cell
♻️ See Also: Reusing Jupyter Outputs

See more about reusing Jupyter outputs in figures, adding placeholders, and other options.

7Label Anything¶

It is possible to label any document node by adding (my-label)= before any other block of content. These can be referenced using the {ref} role, but by default will not be enumerated, so you cannot use %s or {number} in the content.

8Referencing using Roles¶

The {ref} role can be used to bring the title or caption directly in line, the role can take a single argument which is the label, for example, {ref}`reference-target`
You can also choose the reference text directly (not taking from the title or caption) by using, {ref}`your text here <reference-target>`.
The {numref} role is exactly the same as the above {ref} role, but also allows you to use a %s in place of the number, which will get filled in when the content is rendered. For example, {numref}`Custom Table %s text <my-table-ref>`. will become Custom Table 3 text.
The {eq}`my-equation` syntax creates a numbered link to the equation, which is equivalent to [](#my-equation) as there is no text content to fill in a title or caption.
The {doc}`./` syntax creates a link to the document, which is equivalent to [](./
The {download}`./` syntax creates a download to a document, which is equivalent to [](./


Frontmatter may specify numbering to customize how various components of the page are numbered. By default, numbering is enabled for figures, equations, tables, and code blocks; it is disabled for headings and other content types contained on the page.

To enable numbering of all content, you may simply use:

numbering: true

Similarly, to disable all numbering:

numbering: false

The numbering object allows you to be much more granular with enabling and disabling specific components:

  code: false
  headings: true

For components with numbering enabled you may specify start to begin counting at a number other than 1 and template to redefine how the component will render when referenced in the text. For this example, the figures on the page will start with Figure 5 and when referenced in the text they will appear as “fig (5)”

    start: 5
    template: fig (%s)

Numbering may be used for figure as above, as well as subfigure, equation, subequation, table, code, headings (for all heading depths), and heading_1 through heading_6 (for modifying each depth separately).

You may also add numbering for custom content kinds:

    enabled: true

:::{figure} image.png
:label: my-box
:kind: box

This figure will be numbered as "Box 1"

Finally, under the numbering object, you may specify enumerator. For now, this applies to all numberings on the page. Instead of enumerating as simply 1, 2, 3... they will follow the template set in enumerator. For example, in Appendix 1, you may want to use the following numbering so content is enumerated as A1.1, A1.2, A1.3...

  enumerator: A1.%s
MyST MarkdownMyST Markdown
Community-driven tools for the future of technical communication and publication