1 ;; This is a math-mode find and replace. It relies on the AUCTeX
2 ;; package for the "texmathp" function.
4 ;; Originally from http://stackoverflow.com/questions/19845598,
5 ;; and modified to mention AUCTeX if it is missing.
7 (fset 'latex-query-replace-regexp-math
8 `(lambda (regexp to-string &optional delimited start end backward)
9 "Like `query-replace-regexp' but only searches within math environments."
10 ,(interactive-form 'query-replace-regexp)
12 (if (fboundp 'texmathp)
13 (let ((replace-re-search-function
14 (lambda (regexp bound noerror)
16 (while (let ((ret (re-search-forward regexp bound noerror)))
17 (when (save-match-data (texmathp)) (throw :found ret))
19 (query-replace-regexp regexp to-string delimited start end backward))
20 (error "AUCTeX and latex-mode are required for this function.")