3

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.

Frunobulax
  • 153
  • 6

1 Answers1

2

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))))

(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.

Tobias
  • 32,569
  • 1
  • 34
  • 75