tree-sitter-latex

Created on 5 Nov 2018  路  5Comments  路  Source: tree-sitter/tree-sitter

Any plans to add latex to existing parsers?

Most helpful comment

I'm trying to get the ball rolling on a canonical Tree-sitter grammar for LaTeX. As mentioned, correctly parsing LaTeX can be very difficult, but supporting the basics and simply ignoring the difficult parts will make it feasible with not too much effort.

At this point, I've essentially only added the core scaffolding, and need to begin defining a grammar.
You can follow the progress at https://github.com/thomasjo/tree-sitter-latex.

All 5 comments

I would love to see this created, but I personally don't have plans to create it in the near term. If you're interested in creating it, that'd be great!

LaTeX can be very difficult to parse, as it can reprogram macros in real-time. It鈥檚 certainly possible, but it would be a lot of work :( https://tex.stackexchange.com/questions/4201/is-there-a-bnf-grammar-of-the-tex-language

I think we could write a grammar that would give us better syntax highlighting, code folding, etc than whatever TextMate grammar people are currently using.

Granted, the parser won't work on LaTeX code that, say, redefines category codes to switch the meaning of [ and ] (as that answer points out is possible 馃 ), but that code would never have syntax-highlighted properly anyway, in any editor, so I don't think that matters.

I'm trying to get the ball rolling on a canonical Tree-sitter grammar for LaTeX. As mentioned, correctly parsing LaTeX can be very difficult, but supporting the basics and simply ignoring the difficult parts will make it feasible with not too much effort.

At this point, I've essentially only added the core scaffolding, and need to begin defining a grammar.
You can follow the progress at https://github.com/thomasjo/tree-sitter-latex.

Was this page helpful?
0 / 5 - 0 ratings