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.

1 Answer 1


The following works.

(defun latex-isearch-in-math ()
  "Call `isearch-forward' with `isearch-filter-predicate' set to filter out matches outside LaTeX math environments."
  (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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.