The issue is related to #281.
It seems that the inserted map such as `m does not work in some math environment such as align but work for other such as equation. I try to update the version of vimtex to newest, it seems the issue is not solved.
I would be happy if you could provide a complete example. For me, this does work as expected. As indicated in the issue template, I would prefer a minimal LaTeX example and a minimal vimrc file.
I am so sorry that I missed the minimal vimrc file:
set nocp
set wildmenu
filetype plugin indent on
call plug#begin( '~/.vim/myvim/plugged/' )
Plug 'lervag/vimtex'
call plug#end()
let g:tex_flavor = 'latex'
let g:vimtex_view_method='skim'
And the minimal text file is:
\documentclass{amsart}
\begin{document}
$a$, $\alpha$
\[
\alpha
\]
\begin{equation}
\alpha
\end{equation}
\begin{align*}
`a
\end{align*}
\end{document}
as you can see, the `a is not expanded to \alpha as expected.
Yes, I can reproduce. However, it is actually not really a bug, but a feature. If you compile the document, it will generate a .fls file which is parsed by vimtex for a list of required packages. When this file is present (and up to date), then you should observe that everything works. Without this file, vimtex does not know that amsmath is loaded and the align environment is not recognized as a math environment. The imaps behaviour relies on the syntax groups to match math environments.
I understand and agree it is somewhat inconvenient that some things only work when the auxilliary files are present. But I currently don't have a good solution to that, other than loading all of the syntax regardless of which packages are loaded. But this would impact the efficiency, because syntax is expensive.
Yeah, I see the main problem is that my file is separated into two files:
% the test.tex
\documentclass{amsart}
\begin{document}
\input{subfile}
\end{document}
% the subfile.tex
%! TEX root = test.tex
$a$, $\alpha$
\[
\alpha
\]
\begin{equation}
\alpha
\end{equation}
\begin{align*}
\alpha
\beta
\end{align*}
there we NEED to add the root of tex and tell that the main file is test.tex.
No, you should not need to add the root of the tex file. I've created your example:
.
├── minimal.tex
├── minimal.vim
└── subfile.tex
If I open subfile.tex with the minimal.vim like this: vim --servername VIM minimal.vim subfile.tex, then do \ll to compile the document, then finally reopen the file. Now everything works for me. This works also without the %! TeX root specifier.
If it does not for you, then your example is still not the same as your original problem. Perhaps the subfile is put in some subfolder as well? In some cases, the automatic search for the mainfile does not work and one has to use the %! TeX root specifier to make it work.
Yes you'r right, I believe this is cased by I place the test file in a folder that contains other tex file as well, in such case the auto-search scheme not work and I have to specify the root of TeX. I think my problem is solved.
Great, happy to hear it.
Note, though: if you want you could provide a minimal example similar to your actual case. Then I could see if it is possible to improve the main file detection algorithm. No promises, though!
I have an issue related to this phenomenon:
However, the environment is still not recognized by vimtex. So I try to reload vimtex with :VimtexReload with no effect; I need to exit vim and open the file again in order for vimtex to recognize the environment. Is there a way to avoid having to exit and restart vim?
Yes, in this case things do not work as expected yet. Sorry. Instead of :VimtexReload, you can try to do :edit or :edit!. This reloads the file, and I think it should refresh the syntax.
I'm closing this issue as it seems resolved.
Most helpful comment
No, you should not need to add the root of the tex file. I've created your example:
If I open
subfile.texwith theminimal.vimlike this:vim --servername VIM minimal.vim subfile.tex, then do\llto compile the document, then finally reopen the file. Now everything works for me. This works also without the%! TeX rootspecifier.If it does not for you, then your example is still not the same as your original problem. Perhaps the subfile is put in some subfolder as well? In some cases, the automatic search for the mainfile does not work and one has to use the
%! TeX rootspecifier to make it work.