# How to perform incremental search inside math environments in tex/latex documents

Is there a way to perform incremental search that filters out all non-math environments (i.e., only searches within $...$, $$...$$, and if possible other relevant \begin{..}..\end{..} environments)?

Note: a similar question provided an answer without the incremental part.

The following works.

(defun latex-isearch-in-math ()
"Call isearch-forward' with isearch-filter-predicate' set to filter out matches outside LaTeX math environments."
(interactive)
(let ((isearch-filter-predicate
(lambda (BEG END)
(save-excursion (save-match-data (goto-char BEG) (texmathp)))))
(case-fold-search nil))
(funcall 'isearch-forward)))


Note: it is almost identical to this answer, except call-interactively must be replaced with funcall.