What syntax to use to add a label and footnote to heading?

I am trying to add a label and footnote to a heading like so:

#set page(paper: "a7")
#set heading(numbering: "1.")

= Recipe#label("rec")#footnote[adapted from pantry]

- five grams sugar
- ten grams flour

= Method
stir all items from @rec together

I get a

Cannot reference text (@rec) line 10
error.

If I change the syntax of assigning the label to <rec> and move the #footnote to a new line I can get it to compile, but then the footnote isn’t with the header:

#set page(paper: "a7")
#set heading(numbering: "1.")

= Recipe<rec>
#footnote[adapted from pantry]

- five grams sugar
- ten grams flour

= Method
stir all items from @rec together

This also occurs in VS Code with tinymist, but that error actually comes up as a:

label @rec occurs multiple times in the document

Use backticks when referencing code snippets, specifically references.

(post deleted by author)

Labels always need to be after whatever they are supposed to attach to. If you want to label a heading, it must be after the entire heading, including any footnotes in the header. Thus:

= Foo #footnote[Baz] <bar>

See @bar. // See Section 1.

—-

The following are equivalent:

= Foo #footnote[Baz] <bar>
#heading[Foo #footnote[Baz]]<bar2>
#heading[Foo #footnote[Baz]]#label("bar3")

However,

= Foo #footnote[Baz] #label("bar4")

is subtly different, as the label gets attached to the footnote and not the heading. This is because the <> syntax is special-cased to end the heading.

So according to the documentation, it seems like #label("bar") does not work for headings in markup mode, only <bar> is suitable? Do I understand that correctly?

And if I want to reference an element in the header but not the header itself, I then use #label("bar2")?

Yes, for headings using the = shorthand this is correct.

If you use #heading[], there is no difference and it only matters whether the label is inside or outside the [].

Altough the following attaches the label to the heading:

= foo #footnote[Baz]
#label("bar")

because the newline also ends the heading

2 Likes

@Warp37, you haven’t wrapped the @rec references. If a user with this handle exists, they will get a notification from you, possibly spamming their email inbox.

Complex errors are wrapped in code block to prevent any issues with the error’s content.