Linking numbered elements

How to link numbered elements like source blocks, tables or figures.

If you need to link to any of these elements, they need to have the #+name keyword. The #+caption is optional.

Below, you will find examples of the supported numbered elements, and how to link to them.

Code block (src-block#

#+name: code__hello
#+caption: Saying "Hello" in ~emacs-lisp~
#+begin_src emacs-lisp
(message "Hello")
#+end_src

Link to the above code block: [[code__hello]]

Table (table#

#+name: tab__simple_table
#+caption: Simple Table
|----------+----------+----------|
| Header 1 | Header 2 | Header 3 |
|----------+----------+----------|
| abc      | def      | ghi      |
|----------+----------+----------|

Link to the above table: [[tab__simple_table]]

Figure #

#+name: fig__some_figure
#+caption: Some Figure
[[./images/some_figure.png]]

Link to the above figure: [[fig__some_figure]]

See Image Links for more details.

When links are made to any of these numbered elements, ox-hugo has an option to prefix the link descriptions with that element’s type name.

Table 1: Default prefixes (English) for the supported elements
Element Type Prefix (en)
src-block or code block Code Snippet
table Table
figure1 Figure

To enable this auto-prefixing feature, set org-hugo-link-desc-insert-type to a non-nil value.

(with-eval-after-load 'ox-hugo
  (setq org-hugo-link-desc-insert-type t))
Code Snippet 1: Enable auto-prefixing of link descriptions with the referenced element's type name

This feature has language support too. If the #+language keyword is set to a language code other than en (example: de), the translations of the element type names get exported. The translations are based on the org-export-dictionary variable from ox.el.


  1. “figure” is not exactly a proper “Org element”. A “figure” is a standalone figure link in an Org paragraph. ↩︎

Fork me on GitHub