# LaTeX-environment inserts unwanted empty line

When I'm editing a LaTeX document and I'm using C-c C-e for LaTeX-environment, I often get a blank line after the newly-inserted environment. This is never what I want and sometimes even plainly wrong because it can lead to errors if you for example insert a matrix into a displayed equation.

Is there an easy way to turn this off? I checked the customization options but couldn't find anything obvious.

You can try the following lisp code.

Put it into your init file and restart emacs.

The function auctex+-insert-environment-avoid-empty-line kills the emtpy line after \end{...} if there is one.

(defun auctex+-insert-environment-avoid-empty-line (_name _start end)
"Avoid insertion of empty line after environment."
(save-excursion
(goto-char end)
(when (and (eq 0 (forward-line))
(looking-at "[[:space:]]*\$"))
(kill-line))))