0

I am using Emacs with AUCTeX as my editor. Right now, if I use C-c C-e and create an enumerate environment, it will give me

\begin{enumerate}
  \item
\end{enmerate}

What I'd like is

\begin{enumerate}

  \item

\end{enumerate}

Or, at least

\begin{enumerate}

  \item
\end{enumerate}

That is a single newline between the begin and the first item. I would like this to work with all environments with items. Thanks.

1

This is probably not the most efficient way, but it should do the job:

(defun TeX-arg-item-with-newline (_optional)
  "Insert \\item with a newline above and below the macro.
OPTIONAL is ignored."
  (when (or TeX-arg-item-label-p
            (string-equal (LaTeX-current-environment)
                          "description"))
    (let ((TeX-arg-opening-brace LaTeX-optop)
          (TeX-arg-closing-brace LaTeX-optcl))
      (TeX-argument-insert (TeX-read-string
                            (TeX-argument-prompt t nil "Item label"))
                           t)))
  (insert " ")
  (save-excursion
    (re-search-backward "\\\\item"
                        (line-beginning-position) t)
    (forward-line -1)
    (unless (looking-at-p "^[ ]*$")
      (forward-line)
      (LaTeX-newline)
      (indent-according-to-mode)))
  (save-excursion
    (forward-line)
    (unless (looking-at-p "^[ ]*$")
      (LaTeX-newline)
      (delete-horizontal-space))))

(add-hook 'LaTeX-mode-hook
          (lambda ()
            (TeX-add-symbols '("item" TeX-arg-item-with-newline ignore))))

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.