Why does my heading label errors with "cannot reference text"?

You should write instead,

= asdf
#lab

Why does this happen?

This occurs because your code is not parsed as

#heading(level: 1, [asdf]) #asdf

but

#heading(level: 1, [asdf #asdf])

See [1] and [2] for details.

[1] Programmatic label placed on the same line with heading is confusing · Issue #3512 · typst/typst · GitHub
[2] How to reference a composite variable label? · typst/typst · Discussion #4043 · GitHub

4 Likes