R-nvim / R.nvim

Neovim plugin to edit R files
GNU General Public License v3.0
178 stars 18 forks source link

.Rnw does not highlight latex syntax until I do :e #185

Closed dankelley closed 4 months ago

dankelley commented 4 months ago

I've been trying out lazyvim lately, and find that the R.nvim support for R files is excellent. I sometimes also use .Rnw format, so I can have small R snippets inside a larger latex file. When I load such a file, the R components are syntax highlighted, and e.g. gd works. That's great.

The only (slight) problem is that there is no syntax highlighting for the latex portions of the file. I found that reloading the file with :e turns highlighting on, so this is not a big problem. Nevertheless, I thought I might point it out here, in case there is a larger issue involved.

My setup is available at www.github.com/dankelley/nvim, with the R material being in plugins/rlang.lua. I think I've copied that properly from the present website.

Thanks for the continued developement of this great package. You'll never know how many people you've helped!

Dan.

jalvesaq commented 4 months ago

Add "latex" to the ensure_installed option of nvim-treesitter. This may fix the problem. Anyway, I'm closing the issue because R.nvim doesn't interfere with syntax highlighting. We only highlight the R Console (if colorout isn't installed), and the Object Browser.

dankelley commented 4 months ago

Thanks so much for this, @jalvesaq. I still have much to learn about dealing with neovim, and I truly appreciate the help. Dan.

jalvesaq commented 4 months ago

Neovim has two highlighting methods: via traditional Vim script and based on tree-sitter. Maybe the tree-sitter-based syntax (which seems to be enabled by Vimtex) does not conceal LaTeX commands with their corresponding Greek letters and, when you do :e you are somewhat loading traditional Vim syntax highlighting over the tree-sitter-based one. This is just a guess...