compute-engine icon indicating copy to clipboard operation
compute-engine copied to clipboard

Parsing variable names (chars without spaces between) results in a `Multiply` element with a list

Open mindreframer opened this issue 4 years ago • 2 comments

parse("Pts_{total} =")  // ["Multiply","P","t",["Subscript","s",["Multiply","t","o","t","a","l"]]]

This is how it looks like, it's basically a variable name for total points. Screenshot 2021-04-10 at 23 14 04

I understand the reason to wrap it in Multiply, yet I'm not sure how to deal with it... Wrapping it in \text{} changes formatting, keeping it like it is now obscures the AST... If you don't have a suggestion / solution, feel free to close this issue, it seems to be a somewhat fundamental ambiguity in the semantic interpretation of LaTEX.

mindreframer avatar Apr 10 '21 21:04 mindreframer

If you have a finite set, you can define entries in the dictionary:

const customLatex = new LatexSyntax({
          dictionary: 
            [...LatexSyntax.getDictionary(),
              {
                name: 'Pts', // MathJSON symbol
                trigger: { symbol: ['P', 't', 's'] } // symbol is an array of Latex tokens
              }
          ]
});

If you have an arbitrary set, you can define a dictionary entry with a custom parse function:

const customLatex = new LatexSyntax({
          dictionary: 
            [...LatexSyntax.getDictionary(),
              {
                parse: (lhs: Expression, scanner: Scanner,  minPrec: number) : string => {
                // parsing code goes here...
                }
              }
          ]
});

arnog avatar Apr 10 '21 22:04 arnog

Interesting, I might try the custom parse function option and see if that helps! Thanks a lot for the quick response!

mindreframer avatar Apr 10 '21 22:04 mindreframer