latex-lsp / tree-sitter-latex

LaTeX grammar for tree-sitter
MIT License
98 stars 24 forks source link

Arguments to commands in math mode? #100

Closed gi1242 closed 8 months ago

gi1242 commented 8 months ago

Never mind: The error was something else. I'll open a different issue.

~~Hi All,

I noticed arguments to commands are always parsed in text mode. However, they could be text mode or math mode, depending on the command and the context. Handling every corner case is probably very complicated.

But would it be possible to at least implement the following:

  1. Arguments to commands in text mode default to text mode (e.g. \emph{...})

  2. Arguments to commands in math mode default to math mode (e.g. $a + \frac{b}{c}$). (They currently default to text mode, which is very inconvenient, especially as the arguments are often long math expressions.)

  3. Some commands always take math mode arguments (e.g. \ensuremath)

  4. Some commands always take text mode arguments (e.g. \text )

The list of commands that take math / text mode as arguments is probably too huge to completely enumerate. But handling the commonly used ones correctly would be a huge help.

Please let me know if I can provide more info or help in any way.

GI

PS: I wrote a syntax file for tex a few years ago mainly to ensure spell checking was done in the right places. gi1242/vim-tex-syntax. It has various lists of commands and their argument types. If you think you might implement this I would be happy to scrape common lists of commands that always take math mode inputs, and those that always take text mode inputs.~~