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."
    (goto-char end)
    (when (and (eq 0 (forward-line))
               (looking-at "[[:space:]]*$"))

(add-hook 'LaTeX-after-insert-env-hook #'auctex+-insert-environment-avoid-empty-line)

Tested with GNU Emacs 26.1 (build 1, x86_64-unknown-cygwin, GTK+ Version 3.22.28) of 2018-05-28 and auctex 11.92.0.

I've got it running for a while now and it does what I want.

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.