This is a solution if you are using AUCTeX (which I highly recommend). Put the following code in your .emacs file:
"A list of LaTeX environment names in which `auto-fill-mode' should be inhibited.")
(defun my-LaTeX-auto-fill-function ()
"This function checks whether point is currently inside one of
the LaTeX environments listed in
`my-LaTeX-no-autofill-environments'. If so, it inhibits automatic
filling of the current paragraph."
(let ((do-auto-fill t)
(while (and do-auto-fill (not (string= current-environment "document")))
(setq level (1+ level)
current-environment (LaTeX-current-environment level)
do-auto-fill (not (member current-environment my-LaTeX-no-autofill-environments))))
(defun my-LaTeX-setup-auto-fill ()
"This function turns on auto-fill-mode and sets the function
used to fill a paragraph to `my-LaTeX-auto-fill-function'."
(setq auto-fill-function 'my-LaTeX-auto-fill-function))
(add-hook 'LaTeX-mode-hook 'my-LaTeX-setup-auto-fill)
Let's go from the bottom to the top to understand what this does. The "add-hook" function registers a call-back that is invoked every time you open a .tex file. The hook variable
LaTeX-mode-hook is provided by AUCTeX.
The call-back is the function
my-LaTeX-setup-auto-fill which we define above. It turns on
auto-fill-mode and then tells it to use the function
my-LaTeX-auto-fill-function to actually perform the automatic filling.
In order for this construction to work, it is important that you don't turn auto-fill mode off an on again afterwards, or else the
my-LaTeX-auto-fill-function won't be used. If you already have a mechanism in place that automatically turns on
auto-fill-mode when you edit a .tex file, you should probably turn that off and have the above function turn it on for you instead.
The definition of
my-LaTeX-auto-fill-function can be found above. What it basically does is this: it checks whether you're currently inside an "equation" environment and if so, it does nothing. If you're not inside an "equation" environment, it does auto-fill.
Finally, the variable at the top defines for which LaTeX environments auto-fill should be inhibited. I currently put "equation" and "equation*" there, but you can add further environments if you like.