latex-lsp / tree-sitter-latex

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

\{ in curly group gets interpreted as math mode, breaks ENTIRE document #44

Closed primeapple closed 2 years ago

primeapple commented 2 years ago

Hi everyone, I installed your parser in neovim with the treesitter extension.

I'm using this plugin to select my colorschemes: https://github.com/NvChad/base46

So I have this code in my latex document to define a listing highlighting for json.

\lstdefinelanguage{json}{
    literate=
    *{0}{{{\color{numb}0}}}{1}
    {1}{{{\color{numb}1}}}{1}
    {2}{{{\color{numb}2}}}{1}
    {3}{{{\color{numb}3}}}{1}
    {4}{{{\color{numb}4}}}{1}
    {5}{{{\color{numb}5}}}{1}
    {6}{{{\color{numb}6}}}{1}
    {7}{{{\color{numb}7}}}{1}
    {8}{{{\color{numb}8}}}{1}
    {9}{{{\color{numb}9}}}{1}
    {:}{{{\color{punct}{:}}}}{1}
    {,}{{{\color{punct}{,}}}}{1}
    {\{}{{{\color{delim}{\{}}}}{1}
    {\}}{{{\color{delim}{\}}}}}{1}
    {[}{{{\color{delim}{[}}}}{1}
    {]}{{{\color{delim}{]}}}}{1},
}

Especially have a look at the line

    {\{}{{{\color{delim}{\{}}}}{1}

This line breaks the highlighting for the ENTIRE Document. All other lines in the example get interpreted as curly_group, while this one gets interpreted as math_set. It has several errors and causes every following text to be interpreted as part of this math_set . This breaks the entire highlighting. Deleting this line, solves the issue.

As a bonus, you can see another error in the video in the line:

\definecolor{delim}{RGB}{20,105,176}

But this is not a problem for the rendering

Video:

https://user-images.githubusercontent.com/35628420/168420422-00eb5a12-48d4-4071-b5f6-48b428023724.mp4

I'm wondering, other colorschemes with Treesitter Integration, like https://github.com/Mofiqul/dracula.nvim seem to handle this better and don't completely break. Could you guess a reason for this?

This is the TreeSitter integration of my colorschemes: https://github.com/NvChad/base46/blob/master/lua/integrations/treesitter.lua This is the one of dracula.nvim: https://github.com/Mofiqul/dracula.nvim/blob/a219971291c56bcca3827cb7bd40aaaef23feeca/lua/dracula/init.lua#L180

pfoerster commented 2 years ago

Thanks for the detailed report!

\definecolor{delim}{RGB}{20,105,176}

This error should be fixed now (8ac966ece55fc9696eab53e223499c7d687052bc).

{{}{{{\color{delim}{{}}}}{1}

I think there is no good way to keep the math_set rule and fix this error. Besides, the math_set rule is not really a syntactic element of LaTeX so I removed it (23463ca6b867e8089d3b680ad720dc8fd26af34e). For example, $ \} $ is not forbidden by LaTeX.

primeapple commented 2 years ago

That was quick! Thank you so much, this really did help a lot! Unless you desire to do something else in this, you can close it :)