I have a long tex document and I would like to perform a search for finding some string inside math environments. Is there a search function already provided by auctex to do this? Other solutions are welcomed.

(I found https://stackoverflow.com/questions/19845598/emacs-regex-replacing-a-string-inside-a-latex-equation on a similar topic for replacing a string inside math environments).

  • I'm not sure I understood the question, and probably "forward search" in the context of LaTeX means something different from what you mean. Do you want to search for a particular string and want to be sure it is inside math mode? – giordano Sep 27 '16 at 9:40
  • I edited the question, 'forward search' may be confused with inverse/forward search between output and tex source. I just mean an ordinary search as you wrote. – Name Sep 27 '16 at 10:01
  • I'd have suggested to use texmathp (to test whether the string is inside math mode) together with standard Emacs searching facilities, but this possibility is already mentioned in the question on stackoverflow you linked. What's wrong with it? – giordano Sep 27 '16 at 10:09
  • I thought since I am interested to perform only a search (and not find-replace as in the link), there exists perhaps an easier way to do it. Anyway I am happy with the solution given in the link. – Name Sep 27 '16 at 10:47

Bundled with AUCTeX there is the texmathp utility (which, however, is independent from the TeX modes provided by AUCTeX and can be used without it), which allows you to test whether point is inside a mathematical mode or not.

The simplest suggestion I can give you is to combine texmathp with search-forward, here is a possible implementation:

(defun mg-search-in-math (string)
  (interactive "MSearch string: ")
  (while (null (and (search-forward string)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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