Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reference programatically created label if it placed on the same line with heading #3512

Open
1 task done
istudyatuni opened this issue Feb 27, 2024 · 4 comments
Open
1 task done
Labels
bug Something isn't working syntax About syntax, parsing, etc.

Comments

@istudyatuni
Copy link
Contributor

istudyatuni commented Feb 27, 2024

Description

#set heading(numbering: "1.")

// doesn't work
#let lab = label("asdf")

= asdf #lab

@asdf // error: cannot reference text

// work
#let lab = label("asdf")

= asdf
#lab

@asdf

// work

= asdf <asdf>

@asdf

Reproduction URL

No response

Operating system

Linux

Typst version

  • I am using the latest version of Typst
@istudyatuni istudyatuni added the bug Something isn't working label Feb 27, 2024
@PgBiel
Copy link
Contributor

PgBiel commented Feb 28, 2024

Write #[= asdf] #lab instead for now, this is a current limitation in how label attachment is parsed. The compiler can correctly associate the label-specific <asdf> syntax with the entire heading, but as far as it knows = asdf #lab could be =asdf 5 (which would be part of the heading) or =asdf test (which would also be), so it disambiguates by having lab be part of the heading body, and thus it points to asdf (inside the heading) instead of the whole heading.

@istudyatuni
Copy link
Contributor Author

Why is it closed? Is this behavior be intended, or will it not be fixed/will be fixed soon?

@laurmaedje
Copy link
Member

laurmaedje commented Feb 28, 2024

It's not a bug per se as the label is contained within the heading and there's not much the compiler can change about it at the parser stage. The only possible solution I'm aware of is to not allow variable labels to be attached via markup at all. We might do that. But even that would probably not completely eliminate the confusion.

@adrfantini
Copy link

I've had this issue as well, and found it quite confusing. You can find my experience in discussion #4043.

In my case I wrongly assumed the issue was with the dynamic label (built from a variable).

Both the documentation and the error codes were not very clear as to what was happening in this case.
What I tried seemed very intuitive to me, so I'm guessing more people will hit this issue.

If this is not fixable, maybe at least the error/help messages could be clearer?

@laurmaedje laurmaedje reopened this May 1, 2024
@Enivex Enivex added the syntax About syntax, parsing, etc. label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working syntax About syntax, parsing, etc.
Projects
None yet
Development

No branches or pull requests

5 participants