jgm / typst-hs

Haskell library for parsing and evaluating typst
Other
44 stars 5 forks source link

Subscript on composite symbol fails in math mode #41

Closed KaarelKurik closed 8 months ago

KaarelKurik commented 8 months ago

I'm testing this with the standalone binary for pandoc 3.1.12.2. Unfortunately I was unable to find what version of typst-hs it is tied to, so I apologize if this has already been fixed.

A typst document of the form $plus_2$ works fine, as does $plus.circle$, while $plus.circle_2$ fails with the complaint

(line 1, column 2):
Symbol does not have a method "circle_2" or Symbol does not have variant "circle_2"
jgm commented 8 months ago

This is tricky. When we're parsing the syntax, we handle this as

        (FieldAccess
           (Ident (Identifier "circle_2")) (Ident (Identifier "plus")))

Later we look up plus, see that it refers to a symbol, and then try to resolve circle_2. You might ask, why not exclude the _2? Answer: because if plus were a dictionary, it could very well have a field like circle_2. Perhaps we need to make parsing sensitive to whether we're in math mode, excluding _ in identifiers in that case.