stefnotch / aftermath-editor

A WYSIWYG mathematics editor that understands your formulas!
https://stefnotch.github.io/aftermath-editor
MIT License
13 stars 0 forks source link

Autocomplete and autocorrect #29

Open stefnotch opened 1 year ago

stefnotch commented 1 year ago

Because I'm working on a math formula editor: In a lovely editor of your dreams, what would you expect to type to get $$\limsup_{x \to \infty} 2x$$ ?

Here are a few different "shortcut" variants: Do note that they are closer to macros/autocomplete suggestions than they are to conventional shortcuts.

Typing and it automatically applies the shortcut, see https://cortexjs.io/mathlive/ and http://mathquill.com/

  • Should typing lim followed by hitting the Backspace result in li being typed?

Indicating that you're using a shortcut by typing \lim and then hitting enter

  • Should that automatically submit the shortcut whenever possible?

Typing lim and then it suggests the shortcut, like VSCode does when you type for. See also https://www.mathicando.com/#!/demo -- stefnotch

stefnotch commented 1 year ago

Old note: Mathlive autocomplete (accept with space, I guess) limn[space] turns into lim_{n \to \infin} limnto-[space] turns into lim n to -infinity lim[space] turns into lim liminf is \lim \inf What shortcut does Mathcad have for infinity? (00 or oo could work?)

stefnotch commented 1 year ago

Inside a $\lim_{cat \to 42} |$, the word "cat" is very much something that the autocomplete could suggest, if the user provides a parser that tracks variables and such.

stefnotch commented 1 year ago

Open question:

Bonus points if for a sum symbol, it can show "sum as text" in its autocomplete suggestions.

stefnotch commented 1 year ago

What should space do? Accept or reject? Also, should a^2+4 followed by space jump out of the exponent?

Space should simply insert a space character. We need that for $a\ b$ being two separate symbols. After all, we have a greedy lexer/parser, and thus we need a way to "stop" it.

stefnotch commented 1 year ago

Space could also be used as a placeholder, and as a way of pushing symbols around.

e.g. When we have $\frac{a}{\color{blue}|\color{black}b}$, then hitting space could do something like $\frac{a}{\quad \color{blue}|\color{black}}b$

stefnotch commented 1 year ago

image Oh look at what super smart thing MathICanDo does!

stefnotch commented 1 year ago

How does autocomplete even work when there are multiple cursors?

Code_2023-07-02-0310.webm I'm autocompleting lim but I also have a second cursor at an empty place.

Answer: Not sure if there is even an intuitive answer. So doing literally anything[1] is fine.

[1] Anything other than failing horribly.

stefnotch commented 11 months ago

Regarding autocorrect

/_^ logic is simply

  1. Input symbol()
  2. Check if it's an escaped token after parsing
  3. If it's not an escaped token, do the special thing.

Reasoning is very simple: it'd be annoying if 1_a_b suddenly behaved differently, just because someone implemented a _italics_ parser. Same goes for a^= and other stuff.

That logic is hardcoded, which is fine, I think.

stefnotch commented 10 months ago

The delayed autocorrect can handle quite a lot. The user can type stuff like inN to get $\in \mathbb{N}$. Notice how there's no space between the $in$ and the N.

That is because $\in$ is the only sensible symbol for in. So the parser picks up on that and makes use of the knowledge.

Depending on user testing, we might have to scale it back though. Maybe it is confusing?

stefnotch commented 10 months ago

Rules to follow https://jeremymikkola.com/posts/2019_03_19_rules_for_autocomplete.html

stefnotch commented 8 months ago

Vscode snippets sqrt => \sqrt{$1} root => \sqrt[$1]{$2} .box() => Box(prev token) / => \frac{prev}{next} \/ => escaped slash "/" or "\/"

What if I change the autocompletion logic to actually look at the syntax tree? Well then => wouldn't work? But what if I change it to be able to also look at the syntax tree?