mathquill / mathquill

Easily type math in your webapp
http://mathquill.com
Mozilla Public License 2.0
2.66k stars 703 forks source link

Feasible to implement autocomplete? #717

Open bergwerf opened 7 years ago

bergwerf commented 7 years ago

I want an equation editor that has an auto-completion system. I have a database of available symbols and functions. And instead of typing something like \frac{\partial}{\partial x} to insert a differential, I want the user to type a label or name that can be resolved into this function (e.g. diff), which will then be inserted (when the user enters, or when the user adds a special symbol like a new operator or an opening parentheses). I cannot decide whether it is feasible to adapt MathQuill for this purpose. I considered writing a LaTeX parser to infer the expression from the latex output of MathQuill but this does not seem like an easy solution either.

So my question is, would it be possible to write such an autocomplete, and preserve some of the metadata in the equation data structure, so that it can be retrieved again later.

Joe312341 commented 7 years ago

substituteKeyboardEvents is probably what you are looking for.

bergwerf commented 7 years ago

Thanks! Where can I find an example, or some documentation?

Joe312341 commented 7 years ago

The function is not documented and it is also not included in the latest release so you'll have to run the build yourself. You can check out the visual tests file to see usage.

laughinghan commented 7 years ago

Ummm...that is accurate, if dour.

Does it work for you to have the shortcut be \diff, or does it have to be just diff? Do you want the x and the individual \partials to be editable, or do you want the whole thing to be backspaced and selected as one?

Another thing you can look into is how autoCommands is implemented: as it stands, using autoCommands, typing diff can only auto-convert to \diff, but that would be the place to make it auto-convert to \frac{\partial}{\partial x} instead.

I would expect you'll find adapting MathQuill to be much, much easier than implementing your own equation editor, which in my experience, hasn't been easy ^_^

Can you clarify what you mean about preserving metadata?

BTW the Slack channel tends to be more active for these kinds of discussions: http://slackin.mathquill.com :)