latex-lsp / tree-sitter-latex

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

Support for \text and \(short)intertext #3

Open cionx opened 3 years ago

cionx commented 3 years ago

The current grammar doesn’t seem to know the command \text, \intertext, and \shortintertext provided by amsmath and mathtools.

I’m not sure how \(short)intertext ought to be parsed: In terms of code it is a child of the surrounding math environment (e.g. align*). But it can actually contains content that (I think) would not fit in the resulting tree structure.

For example: the following is a valid (and useful) use of \intertext:

\begin{enumerate}
    \item
        Let
        \begin{align*}
            x &= 2.
    \intertext{
    \item
        Let also
    }
            y &= 3.
        \end{align*}
\end{enumerate}
pfoerster commented 3 years ago

Sorry for the long response time. Adding \text is straightforward but parsing \intertext correctly with all its quirks can be quite challenging if not almost impossible without some severe modifications to the grammar. Honestly, I am not sure how to parse the last example correctly, as this does not really fit into a tree.

clason commented 2 years ago

I think having just the "standard" use parsed correctly would be great already. The last example should be very rare and would be acceptable not to support (for the foreseeable future). Especially \text{} is something that is frequently used.

pfoerster commented 2 years ago

I think having just the "standard" use parsed correctly would be great already. The last example should be very rare and would be acceptable not to support (for the foreseeable future). Especially \text{} is something that is frequently used.

5686c9c adds a new rule with support for the simple cases. The hard case is probably a "wont' fix" for now.

XVilka commented 5 months ago

From the issue https://github.com/nvim-treesitter/nvim-treesitter/issues/2214 both \text and \intertext are supported, only missing one is \shortintertext

I don't understand why, though, the grammar looks fine:

    text_mode: $ =>
      seq(
        field('command', choice('\\text', '\\intertext', '\\shortintertext')),
        field('content', $.curly_group),
      ),