texmathp defined in AUCTeX (autoloaded from
texmathp) does exactly that (ok, actually it does a bit more).
Used interactively, it will give you some more information, including whether the point is in a math construct.
Used in elisp, it will be
t if in math,
nil otherwise. The additional pieces of informations are then stored in the variable
t, this is a cons of
(MATCH . POSITION), where
MATCH is a string containing the TeX command or the name of the environment that triggered math mode, and
POSITION is the position at which that string was found in the buffer.
MATCH is something like
"equation", … When
nil, the variable
(nil . pos) where
pos is the beginning of the paragraph.
Warning from the docstring:
The functions assumes that you have (almost) syntactically correct (La)TeX in
It is aware of all environments that
AUCTeX knows of (for example for font-locking), and you can add more using the variable