NvChad / base46

NvChad's base46 theme plugin with caching ( Total re-write )

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Syntax highlighting colorscheme incorrect for Latex files when using vimtex

mvds314 opened this issue · comments

Describe the bug
I want to use vimtex for syntax highlighting LaTeX, as people claim it is better that treesitter this filetype.

When I open neovim, and open a LaTeX file right away, the highlighting color do no match the NvChad theme (onedark in my case), but resembes one of the vim default themes (not sure which one).

To Reproduce
Steps to reproduce the behavior:

  1. Install vimtex, set up NvChad with any theme (onedark)
2. Disable treesitter for latex like [so](https://github.com/lervag/vimtex/issues/2469):
  {
    "nvim-treesitter/nvim-treesitter",
    opts = {
      ensure_installed = { "html", "css", "bash", "python", "latex", "json", "lua", "vim", "yaml" },
    },
	config = function(_, opts)
	  -- https://www.reddit.com/r/neovim/comments/xqogsu/turning_off_treesitter_and_lsp_for_specific_files/
      require "nvim-treesitter.configs".setup {
	    highlight = { enable = true, -- false will disable the whole extension
                      disable = { "tex", "latex" }, -- list of language that will be disabled
					  use_languagetree = true,
					},
	  }
    end,
  },
  1. Open neovim
  2. open a Latex file, syntax highlighting does not look good (it resembles one of the vim default themes, not sure which one).
  3. Then switch (leader+t+h) to the selected theme of NvChad

Expected behavior
Step 6 should not be required

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Operating System: Windows 11
  • Terminal: neovim-qt

add event="VeryLazy" for vimtex plugin

Tried it like so: { "lervag/vimtex", ft = "tex", event="VeryLazy"},

But it does not solve the problem.
Syntax highlighting still looks like this (intially):
image
After I switch theme (manually), it looks like this:
image
Meaning the onedark theme, as all other files look.

@mvds314 share your settings + a test latex file

Sure, I put my NvChadConfig on github

For a test file, any LaTeX file would suffice. For example, put this code a file called example.tex, and open it right away opening neovim.

simplescreenrecorder-2023-09-12_06.17.41.mp4

i cant reproduce this issue, also treesitter latex treesitter parser seems to provide nice highlighting, then why use vimtex?

Let me check on my Linux machine later today.

Treesitter doesn't seem be doing a good job for LaTeX. I'm not sure why, but others complain about it too.
So, my first though was to turn treesitter off for for tex files and use vimtex (as I need to install that anyway), maybe there are other solutions too.

The issue persist on my Linux machine.

Steps I followed:

  • Clone my config in into ~/.config/nvim/lua/custom/....
  • Start neovim (version 0.9.1-3), NvChadUpdate, MasonInstallAll, restart etc
  • Paste the Latex code from the website above into neovim, save it as example.tex
  • Then highlighting looks wrong (as in the image above with yellow)
  • When I switch theme to onedark, it looks as it is supposed to be (the image above).

I believe I fixed it. Not sure why, but my guess is my custom config was overriding the standard treesitter config.
And, I should have added the line: dofile(vim.g.base46_cache .. "syntax")

So that the entire config for treesitter now looks like this:

  {
    "nvim-treesitter/nvim-treesitter",
    opts = {
      ensure_installed = { "html", "css", "bash", "python", "latex", "json", "lua", "vim", "yaml" },
    },
    config = function(_, opts)
      -- https://www.reddit.com/r/neovim/comments/xqogsu/turning_off_treesitter_and_lsp_for_specific_files/
      dofile(vim.g.base46_cache .. "syntax")
      require("nvim-treesitter.configs").setup {
        highlight = {
          enable = true, -- false will disable the whole extension
          disable = { "tex", "latex" }, -- list of language that will be disabled
          use_languagetree = true,
        },
        indent = { enable = true },
      }
    end,
  },

yes @mvds314 the dofile code is in the default config too