joeyuping / quick_latex_obsidian

MIT License
327 stars 21 forks source link

Feature Request: Allow expansion straight after expanding a different shorthand #49

Open mayurankv opened 2 years ago

mayurankv commented 2 years ago

Currently, if one wants to type $\alpha\beta$ they could expand al, type a space and then expand be. A way to do this without typing the space would be to append a space after expansions so the space would already exist but then to expand the fraction $\alpha /\beta$, this wouldn't give the desired result as the \alpha isn't recognised by the fraction expansion. A way around this and to allow really slick workflows would be to allow expansion directly after another expansion as long as no arrow keys are presed. i.e. Letting the use expand al to \alpha and then typing be directly so it looks like \alphabe but on expansion it would be \alpha\beta. This would just be like temporarily inserting a space after the expansion and removing it if anything other than another shorthand is evaluated. I'm not sure as to how this could work in obsidian but I think this would be a really useful addition to the tool and allow continuous typing without navigation by arrows or unnecessary splitting by spaces.

joeyuping commented 2 years ago

Hi @mayurankv !

Thank you for the suggestion!

Indeed! This was originally how the function was designed. However, we were met with an issue. When user type "de", the shorthand expands to "\delta", but pressing space afterward causes the plugin to think that the "ta" at the end of "\delta" is the shorthand for "\tau", so it expanded again, which is not intended. Because of this, I enforced that there should be a space before a shorthand for it to fire.

I am not sure how this may be overcomed while having the function you mentioned. If you may have any idea to resolve this, please do share!

mayurankv commented 2 years ago

Again apologies for the late follow up, would it be possible to insert a pseudo space automatically which is then removed?

i.e. Obsidian would see (where _ is the cursor position):

  1. User types "al" - "al_"
  2. User presses space - "\alpha _" (Note the space automatically inserted after alpha)
  3. User tpes "be" - "be" - "\alpha be_"
  4. User presses space - "\alpha\beta _" (Previous space automatically removed)

It would be even better if this was an invisible space, i.e. the plugin sees a space to prevent the delta tau expansion, but the user does not.

Now in the case no further expansion is needed and the space should not remain:

  1. User types "al" - "al_"
  2. User presses space - "\alpha _"
  3. User either: Presses space, Moves an arrow key, continues typing or leaves note.

If the user does any of pressing space, moving an arrow key or leaving note, the space should be removed before the action occurs. If the user continues typing then the space should be left until the space bar is next pressed and if no expansion occurs, the space should be made real.

Please let me know if you have any problems with this suggestion, happy to think about other ways of implementing it.