TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In AUCTeX I would like the behaviour of LaTeX-environment and/or LaTeX-insert-item to create multiple items for every line when called with mark active.

share|improve this question
To be clear: you want to mark a region and wrap it with an itemize-like environment and put an \item at the beginning of every line? – giordano Feb 21 '14 at 22:08
Yes. That's exactly what I want. – Nordlöw Feb 22 '14 at 1:00
up vote 4 down vote accepted

If I understood what you want, the following code should do the trick:

(defadvice LaTeX-env-item
  (around LaTeX-env-item-region activate)
  "When there is an active region, wrap the environment around it.
Insert \\item macros at the beginning of every non empty line of the region."
  (let ((beg (min (point) (mark)))
    (if (< (point) (mark))
      (while (re-search-backward "^\\(.+\\)$" beg t)
    (replace-match "\\\\item \\1" t nil)
    (beginning-of-line 1))))
  ;; Remove the extra \item.
  (re-search-forward "\\\\item " (save-excursion (end-of-line)) t)
  (replace-match ""))

This works with all environments inserted with LaTeX-env-item, i.e. enumerate, itemize, trivlist, description, and theindex by default.

share|improve this answer
Great! I fixed your code so it works both when point < mark and vice versa. – Nordlöw Feb 22 '14 at 1:23
BTW: Do you know of any way to automatically insert [<+->] arguments to the itemize environment when I'm in a beamer frame so I get pretty incremental display during presentation? – Nordlöw Feb 22 '14 at 1:25
@Nordlöw ask a new question, I have already the answer ;-). – giordano Feb 22 '14 at 11:13
Ok. Great. Here's the new question: tex.stackexchange.com/questions/161784/… – Nordlöw Feb 22 '14 at 11:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.