In Emacs 25.3 (but not 22.3, for example), the search string " " (space) in LaTeX mode is matched by the carriage return character as well as the space character. I can understand why Emacs has been programmed this way: a single carriage return in LaTeX will give a space in the compiled document. However, I'd like to turn this behaviour off in the Emacs search, so that a search for " " returns only spaces. How can I do this?

I've tried looking for answers through Google and through a direct search on SE ("emacs latex mode search") but couldn't find an answer. Grateful for any help.

1 Answer 1


Try hitting M-s SPC while in isearch to toggle whitespace matching before you type in the space character to search. Also, you might want to check the variable 'search-whitespace-regexp' and its documentation. In my case, it was set to the default value and so searching for " " did not find carriage return, but when set to "[ \t\r\n]+", it does – unless toggled off with M-s SPC.

I found this in the documentation of isearch itself, hit C-h m while in isearch to get there.

  • LaTeX mode changes the variable search-whitespace-regexp from the default. If I reset the variable manually after I've loaded my tex file, then the problem is solved. However, if I try to set it in my init file (which is what I want to do), then the default gets overridden when Emacs sees I'm reading a tex file. Any thoughts? Jan 12, 2018 at 16:46
  • It doesn't at my site. Have you installed/activated the AUCTeX package? Because I do, and there is no problem, but when I try it with no config / packages, I get the same issue (and AUCTeX is much superior to the built-in tex-modes anyways).
    – schmuu
    Jan 13, 2018 at 15:32

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.