arnog / mathlive

A web component for easy math input
https://cortexjs.io/mathlive
MIT License
1.57k stars 276 forks source link

Feature: Auto-scaling brackets without smartfences #351

Open Khazuar opened 4 years ago

Khazuar commented 4 years ago

Problem

There's multiple issues we have with the current smartfences-feature:

Not using the smartfence-feature means that we're stuck with "normal" brackets though that don't scale with their contents. We tried just adding an inline shortcut that would replace all ( with \left( and all ) with \right), but every \left( will automatically spawn a \right..

Solution

I don't expect all the issues with smartfences to be solved (I doubt there's a good solution for them tbh), but I'd be great if it were possible to have the \left and \right brackets as a separate feature. \right. should only be inserted at the very end of the line (main-line or subscript/superscript-line) when there's too many opening brackets (to keep the latex valid), and they should be removed when closing brackets are added. Likewise \left. might be inserted in the beginning if there's too many closing brackets.

Example

User input Latex markup returned from mf.$latex()
( \left(\right.
(, a \left(a\right.
(, a, ) \left(a\right)
(, a, ^ MOVE RIGHT ) \left(a^{}\right)
(, a, ^ b + ( c MOVE RIGHT ) \left(a^{b+\left(c\right.}\right)
arnog commented 4 years ago

When a user wants to turn the term (a+b+c+d) into (a+b)+(c+d), they often try to insert a ) after the b and a ( just before the c. Just to be clear: this is the behavior you are observing with smartfence off?

Are you looking for smartfence (i.e. insertion of \left, \right) but without the ghosting brackets? If that's the case, I think I could add an option for that, but FYI, it's already possible to prevent the ghosted brackets from displaying by overriding the "MLsmart-fenceopen" and "MLsmart-fenceclose" CSS rules.

Khazuar commented 4 years ago

Just to be clear: this is the behavior you are observing with smartfence off?

With the smartfence-feature on. Hiding the ghost fences would be a start, I don't mind if there's \right? at the end (as it is right now) instead of the \right. I proposed. But the caret is still automatically jumping to the ghost brackets position.