Uses treesitter to expose "in_mathmode()" function for latex.
I found the code in this comment.
Put this in your tex.snippets
file.
global !p
def math():
return vim.eval('mode#in_mathzone()') == '1'
...
endglobal
To restrict a snippet to mathmode, use
context "math()"
snippet iff "iff" Ai
\iff
endsnippet