Issue
Previously workign "isMath()" function written worked for several latex environments. I have switched to neovim, although I am not sure if this is relevant. Now, the function will not register the align environment at all, nor does it register double dollar signs, but still works for single dollar signs.
The isMath Function is as follows:
def isMath():
synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))")
if not set(texIgnoreMathZoneIds).isdisjoint(synstackids):
return False
return not set(texMathZoneIds).isdisjoint(synstackids)
def prose():
return not isMath()
One (simple) example to try out is the following snippet:
context "isMath()"
snippet ,, "ldots" iA
, \ldots, $0
endsnippet
And trying this in a .tex file
\begin{align} \end{align}
vs. in
$ $
produces the snippet in the latter, but not the former.
I had the same problem. To fix it follow the steps:
in your init.vim add this line: (Enables the vimball package)
packadd vimball
Then download and unzip this file http://www.drchip.org/astronaut/vim/vbafiles/amsmath.vba.gz ,
open with neovim and run :so %
And then it should work accordingly.
The problem is that neovim doesn't recognise the environments 'E' etc, due the removal of the packages amsmath from syntax highlighting. I think the new versions of vim have the same problem. (According to some google search)
Hello I am facing the same problem with vim8.2, but it seems that this solution does not work.
Well, if isMath returning False UltiSnips is doing its job correctly, right? am not sure where the bug here is - and how UltiSnips should be changed to fix it.
Could you advise a bit more what you expect to get out of this bug report?
Okay, so the solution proposed by NikosZ worked perfectly for nvim, but failed for vim8. @SirVer , this turned out not to be an UltiSnips issue. The problem was getting the function recognize align* as a math environment. Thank you for taking the time to read by issue!
@SirVer The problem is not related to UltiSnips but to the Tex.
The problem is that the environment code for align isn鈥檛 recognized. My method works for neovim . I believe for vim you can use a similar method to install the vb file.
I can confirm the same problem exists with vim 8.2, and that installing the vimball suggested by @NikosZ above does work. Just noting this for others who might run across the same problem, in the hope that they won't spend many hours looking for a fix themselves.
I don't think this issue is related to UltiSnips. The source of the problem is probably this commit in Vimtex: https://github.com/lervag/vimtex/commit/1ccaf71ea1f7ebe85d09650deec1ffdf1b2af406, which changes the syntax highlighting names for ams-related environments: 'E' has been changed to 'AmsE', etc.
Updating the math() function to be the following should probably fix your issue:
texMathZones = ['texMathZone' + x for x in ['A', 'AS', 'B', 'BS', 'C', 'CS',
'D', 'DS', 'E', 'ES', 'F', 'FS', 'G', 'GS', 'H', 'HS', 'I', 'IS', 'J', 'JS',
'K', 'KS', 'L', 'LS', 'DS', 'V', 'W', 'X', 'Y', 'Z', 'AmsA', 'AmsB', 'AmsC',
'AmsD', 'AmsE', 'AmsF', 'AmsG', 'AmsAS', 'AmsBS', 'AmsCS', 'AmsDS', 'AmsES',
'AmsFS', 'AmsGS' ]]
texIgnoreMathZones = ['texMathText']
texMathZoneIds = vim.eval('map('+str(texMathZones)+", 'hlID(v:val)')")
texIgnoreMathZoneIds = vim.eval('map('+str(texIgnoreMathZones)+", 'hlID(v:val)')")
ignore = texIgnoreMathZoneIds[0]
def math():
synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))")
try:
first = next(i for i in reversed(synstackids) if i in texIgnoreMathZoneIds or i in texMathZoneIds)
return first != ignore
except StopIteration:
return False
By the way, when testing this, also keep in mind this Vimtex issue: https://github.com/lervag/vimtex/issues/1680.
I took the math context that @gillescastel wrote juste above.
But to make the context working, i had to put explicitly
\usepackage{amsmath}
in my preamble even if the amsmath package was already loaded by some package.
Closing as this seems unrelated to UltiSnips. Thanks for all the feedback!
Most helpful comment
I don't think this issue is related to UltiSnips. The source of the problem is probably this commit in Vimtex: https://github.com/lervag/vimtex/commit/1ccaf71ea1f7ebe85d09650deec1ffdf1b2af406, which changes the syntax highlighting names for ams-related environments: 'E' has been changed to 'AmsE', etc.
Updating the
math()function to be the following should probably fix your issue:By the way, when testing this, also keep in mind this Vimtex issue: https://github.com/lervag/vimtex/issues/1680.