emacsauctexmath-mode

Prevent Emacs from linebreaking in TeX inline math


I use Emacs in combination with AUCTeX to edit manuscripts with a lot of inline maths using $. When automatic filling (e.g., with M-q), Emacs often breaks these inline math environments at positions which disturbs the fluency of reading (e.g., in subscripts or the like).

Is there a way to tell Emacs to prefer putting the whole $…$ environment in a new line if that would prevent breaking? More specifically, if breaking in maths would occur, the whole environment should be moved to a new line which should not be broken apart.

An example:

Lorem ipsum dolor sit amet, consectetur adipisici elit, sed $a^2 + b^2 = c^2$ eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.

should result in

Lorem ipsum dolor sit amet, consectetur adipisici elit, sed
$a^2 + b^2 = c^2$ eiusmod tempor incidunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam.

Solution

  • Try:

    (add-hook 'LaTeX-mode-hook
              (lambda ()
                (add-to-list 'fill-nobreak-predicate 'texmathp)))
    

    Place it in your .emacs and restart emacs.