I have this test code:

    foo

    \begin{equation}
      foo
    \end{equation}
    
    foo

    $foo$

    foo

I want to replace "foo" with "bar" everywhere but LaTeX math, so I have written these functions:

    (defun test-a ()
      (interactive)
      (let ((isearch-filter-predicate 'skip-equation-env))
    
        (query-replace-regexp "foo"
                              "bar" nil (point-min) (point-max))))
    
    (defun skip-equation-env (beg end)
      (catch 'skip-region
        (save-excursion
          (save-match-data
            (when (and (looking-back "\\\\begin{equation}\\([[:graph:] \n]+\\)")
    		           (looking-at "\\([[:graph:] \n]+\\)\\\\end{equation}"))
    	      (throw 'skip-region nil)))
          t)))

    (defun test-b ()
      (interactive)
      (let ((isearch-filter-predicate 'skip-inline-math))
    
        (query-replace-regexp "foo"
                              "bar" nil (point-min) (point-max))))
    
    (defun skip-inline-math (beg end)
      (catch 'skip-region
        (save-excursion
          (save-match-data
            (when (face-at-point beg 'tex-math)
    	      (throw 'skip-region nil)))
          t)))

I have adapted `skip-equation-env` and `skip-inline-math` from another code to be fit to my case, so I'm not sure of all their lines.

I have tested these functions successfully, but I would like to know if there is a more suitable way to write them using `isearch-filter-predicate`. I am new to `isearch`.

I am not allowed to use `auctex`.