lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.51k stars 389 forks source link

Inline math environment is not detected by ts$ command #2707

Closed Ma94xx closed 1 year ago

Ma94xx commented 1 year ago

Inline math ($1+1=2$) is not detected as environment, hence no commands like ts$ or ci$ are working. If I try to toggle from displaymath, it works as expected.

Steps to reproduce

  1. nvim -u minimal.vim minimal.tex
  2. Insert some inline math e.g. $3+3=6$
  3. Jump to the delimiter
  4. Press ts$ in normalmode

Expected behavior

I expect $3+3=6$ to change to \begin{displaymath}3+3=6\end{displaymath}

Actual behavior

The cursor jumps to the next $ sign or does nothing, but no other changes are made

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Linux 6.3.1-arch1-1
  Vim version: NVIM v0.9.0
  Has clientserver: true
  Servername: /run/user/1000/nvim.136216.0

VimTeX project: minimal
  base: minimal.tex
  root: /home/max
  tex: /home/max/minimal.tex
  main parser: fallback current file
  document class: 
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Zathura
    xwin id: 0
  qf method: LaTeX logfile

Edit: After updating nvim, I get this error message when trying to toggle displaymath with ts$ photo_2023-05-15_21-49-50

lervag commented 1 year ago

Inline math ($1+1=2$) is not detected as environment, hence no commands like ts$ or ci$ are working.

It works for me in. You seem to indicate that you are testing this with some minimal setup, but I believe you are not doing that properly.

Steps to reproduce

  1. nvim -u minimal.vim minimal.tex

Two immediate things:

The standard minimal.vim that I use to suggest looks like this:

set nocompatible
" YOU NEED TO CHANGE THE FOLLOWING LINES!
" Use the path to VimTeX on YOUR system
set runtimepath^=~/.local/plugged/vimtex
set runtimepath+=~/.local/plugged/vimtex/after

filetype plugin indent on
syntax enable

" VimTeX options go here, e.g.
let g:vimtex_view_method = 'zathura'

The standard minimal LaTeX file is:

\documentclass{minimal}
\begin{document}
Hello World!
\end{document}
Ma94xx commented 1 year ago

Well, so I messed things up. I'm sorry. The content of the minimal.tex is the following:

\documentclass{minimal}
\begin{document}
Hello $World!$
\end{document}

And the content of my minimal.vim

set nocompatible
" YOU NEED TO CHANGE THE FOLLOWING LINES!
" Use the path to VimTeX on YOUR system
set runtimepath^=~/.local/share/nvim/site/pack/packer/start/vimtex
set runtimepath+=~/.local/plugged/VimTeX 

filetype plugin indent on
syntax enable

" VimTeX options go here, e.g.
let g:vimtex_view_method = 'zathura'

In the minimal version it works (I guess the --clean flag did it). So I guess its not a vimtex bug. Sorry for opening an issue. Any idea what could cause this? Or any known conflicting plug ins?

lervag commented 1 year ago

And the content of my minimal.vim …

Thanks; notice, you either copied the wrong file, or you made a minor mistake (that I don't think is relevant for this particular case):

set runtimepath^=~/.local/share/nvim/site/pack/packer/start/vimtex
" this is correct:
set runtimepath+=~/.local/share/nvim/site/pack/packer/start/vimtex/after

In the minimal version it works (I guess the --clean flag did it). So I guess its not a vimtex bug. Sorry for opening an issue.

No need to apologize!

Any idea what could cause this? Or any known conflicting plug ins?

Yes, or, I do have ideas for how to figure it out. My main hypothesis is that you are using Treesitter for highlighting. This will disable VimTeXs syntax highlighting, which ts$ and ci$ and similar depend on. See :help vimtex-faq-treesitter. You can easily check by doing :Inspect when your cursor is within inline math, for instance. To disable Treesitter highlighting for LaTeX, you can change your treesitter config like this:

      require("nvim-treesitter.configs").setup {
        -- … whatever config your are using
        highlight = {
          enable = true,
          disable = { "latex" },
        },
      }

If that is not the cause, then, after opening a .tex file: What is the ouput of :map ts and :map ci?

Ma94xx commented 1 year ago

Thank you so much! That actually worked! Never thought of treesitter being an issue for vimtex. Just because I didn't mention so far: vimtex is awsome! thanks for sharing!

lervag commented 1 year ago

Glad to hear it works now; and thanks for the kind words! :)

loximann commented 6 months ago

I am experiencing the same issue in vim.

My minimum file:

\documentclass{minimal}
\begin{document}
Hello $World!$ 
\begin{displaymath}
2+2
\end{displaymath}
\end{document}

My VimtexInfo:

System info:
  OS: Fedora release 38 (Thirty Eight)
  Vim version: VIM 9.1 (1-158)
  Has clientserver: false

VimTeX project: foo
  base: foo.tex
  root: /home/sergio
  tex: /home/sergio/foo.tex
  main parser: fallback current file
  document class: 
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: General
  qf method: LaTeX logfile

:map ts show the line n ts$ @<Plug>(vimtex-env-toggle-math), :map ci shows nothing. As far as I know, I disabled all packages (except for vimtex) and .vimrc consists solely of

syntax on
filetype plugin on
filetype indent on

Any hints for troubleshooting?

lervag commented 6 months ago

How did you install VimTeX?

The best approach is really to open a new issue and describe by use of the issue template. Your issue is most likely not the same as the original issue in this thread.

loximann commented 6 months ago

Thanks, I hope this is OK! https://github.com/lervag/vimtex/issues/2915