daniel3735928559 / guppy

WYSIWYG mathematics editor with structured, searchable, LaTeX-compatible, and parseable output
https://guppy.js.org
186 stars 63 forks source link

symbols.json file structure #132

Open dvergeylen opened 5 years ago

dvergeylen commented 5 years ago

Hi Daniel,

Playing a bit with the symbols.json file, I was wondering why it was simply a hash of symbols, as this doesn't allow to specify an order of symbols (neither of tabs).

This might be a bit confusing at first but why couldn't we define the symbols.json file as array of groups, containing an array of symbols? Something like this:

{
    "_version": "2.0.0-alpha.3",
    "_name": "base",
    "groups": [
        { "name": "functions",
          "symbols": [
          {  "name":  "symbol1",
              "attrs": "apple"
           },
           { "name": "symbol2",
              "attrs": "pear"
           }
        ]},
      { "name": "operators",
        "symbols": []
      }
    ]
}

Parsing arrays sequentially,

I can deliver a PR for this, as I will implement this in my fork for personal purpose anyway :wink:

dvergeylen commented 5 years ago

Tabs order isn't guaranteed actually: they are created by hand and then parsed in a for loop, but that doesn't guarantee they will be handled in the order they were inserted. See https://stackoverflow.com/q/280713

I did a quick test and indeed, Firefox and Chrome doesn't display the same osk tab order: 123, abc, ABC for the former, abc, 123, ABC for the latter. 😕 Having a syntax in the symbols.json file that would ensure a correct order would sanitize the user experience (IMHO).

saivan commented 5 years ago

Yes I agree with this too. This makes a lot of sense, and would also help to solve the problem encountered in #91, as you could avoid overwriting symbols if an earlier symbol also matches the current text. Javascript objects dont need to keep order in tact, although as you rightly point out, on most browsers they currently do :P