You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Calligraphic Math Unicode literals with variation selectors not recognised as a single character #6328
I have a strong preference towards inputting Unicode directly in my source files, which makes the source files significantly easier to read and use in my opinion.
I was playing around with the calligraphic math characters, which as of Unicode 14.0 take a variation selector (0xFE00 or 0xFE01 suffix), but these are not recognised as a single character/grapheme, which leads to an Unknown Variable error.
$"Default (OK)" : &ℱ\"Calligraphic": &ℱ︀\"Script": &ℱ︁\$
Which gives error "Unknown variable ℱ︀", which I suspect is due to the fact that it considers both the base character 0x2131 and variation selector 0xFE01 to be characters, which is not the case.
### Reproduction URL
_No response_### Operating system
Windows
### Typst version
- [x] I am using the latest version of Typst
Good find! We should add this as a test case based on the resolution.
This is a lexing issue. We treat text with a valid start character plus a valid continuing character as an identifier. And it seems that we treat variation selectors as continuing characters for identifiers1, which makes us lex this as an identifier (which errors since it's undefined).
A possible fix could be to assert that identifiers in math aren't single grapheme clusters
Do we do this in other places in the syntax? This feels a bit dangerous not only in terms of comparative performance when lexing identifiers, but also because, in theory, grapheme cluster splitting depends on the Unicode version and may change over time, if my memory serves me well, which could be a bit problematic for the syntax... but it's possible this is a dismissable concern (just wanted to bring it up).
in theory, grapheme cluster splitting depends on the Unicode version and may change over time, if my memory serves me well, which could be a bit problematic for the syntax... but it's possible this is a dismissable concern (just wanted to bring it up).
I think at least for this specific instance (calligraphic vs roundhand distinction), it is not likely that the clustering will ever change now that it has been adopted, though I think you were referring to the idea of applying this approach more generally, in which case I guess there is a small chance that breakages could occur. A possible solution I think could be to consider any updates to the Unicode version used in Typst to be a potentially breaking change. Consequently, updates to the Unicode version used in Typst could be sign-posted as a potentially breaking change (in the few if any instances where the update does change grapheme clustering)
Activity
wrzian commentedon May 24, 2025
Good find! We should add this as a test case based on the resolution.
This is a lexing issue. We treat text with a valid start character plus a valid continuing character as an identifier. And it seems that we treat variation selectors as continuing characters for identifiers1, which makes us lex this as an identifier (which errors since it's undefined).
Here's the relevant source code:
typst/crates/typst-syntax/src/lexer.rs
Lines 639 to 647 in 2a258a0
typst/crates/typst-syntax/src/lexer.rs
Lines 1079 to 1089 in 2a258a0
A possible fix could be to assert that identifiers in math aren't single grapheme clusters, but I would want a second opinion before deciding on it.
Footnotes
This assert succeeds:
assert!(is_math_id_continue('\u{FE01}'))↩mkorje commentedon May 28, 2025
I think this is quite reasonable, and would fit in with the changes to the
GlyphFragmentstruct I made in #6336 (if/when that gets merged).PatrickMassot commentedon Jun 1, 2025
A related case: the single letter test also fails when using something like φ̅ (where a φ letter is followed by a combining overline).
PgBiel commentedon Jun 1, 2025
Do we do this in other places in the syntax? This feels a bit dangerous not only in terms of comparative performance when lexing identifiers, but also because, in theory, grapheme cluster splitting depends on the Unicode version and may change over time, if my memory serves me well, which could be a bit problematic for the syntax... but it's possible this is a dismissable concern (just wanted to bring it up).
mkorje commentedon Jun 3, 2025
This is tracked in #1524.
JeppeKlitgaard commentedon Jun 4, 2025
I think at least for this specific instance (calligraphic vs roundhand distinction), it is not likely that the clustering will ever change now that it has been adopted, though I think you were referring to the idea of applying this approach more generally, in which case I guess there is a small chance that breakages could occur. A possible solution I think could be to consider any updates to the Unicode version used in Typst to be a potentially breaking change. Consequently, updates to the Unicode version used in Typst could be sign-posted as a potentially breaking change (in the few if any instances where the update does change grapheme clustering)
mkorje commentedon Jun 25, 2025
This is blocked on #6489 currently.