latex-snippets icon indicating copy to clipboard operation
latex-snippets copied to clipboard

"math()" context doesn't work

Open tarsiec opened this issue 1 year ago • 2 comments

Snippets with "math()" contexts don't work in any math environment. Math context currently defined as

def math():
	return vim.eval('vimtex#syntax#in_mathzone()') == '1'

Nor does it work for me when changed to

texMathZones = ['texMathZone' + x for x in ['', 'X', 'XX', 'Env', 'EnvStarred', 'Ensured']]
texIgnoreMathZones = ['texMathTextArg']

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

As suggested by an issue on vimtex (https://github.com/lervag/vimtex/issues/1870)

tarsiec avatar Jul 18 '22 10:07 tarsiec

Do you have Treesitter enabled for Latex files? If so, please consider to deactivate TreeSitter for Latex files

nvim-treesitter/nvim-treesitter/issues/1184

JirR02 avatar Aug 29 '22 14:08 JirR02

mine doesn't work neither. I'm new to vim and work on Windows. I just put the tex.snippets file under the path AppDate\Local\nvim\plugged\ultisnips\. and i found i can't transfer the snippet, say // or / fraction with <Tab>. as you can see that here I can't even call a common snippet not requiring context "math()"

snippet // "Fraction" iA
\\frac{$1}{$2}$0
endsnippet

snippet / "Fraction" i
\\frac{${VISUAL}}{$1}$0
endsnippet```

AlfredLouis00 avatar Sep 11 '23 10:09 AlfredLouis00