Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
1  
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 at 22:08
    
Yes. That's exactly what I want. –  Nordlöw Feb 22 at 1:00

1 Answer 1

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))
    (exchange-point-and-mark))
    (save-excursion
      (while (re-search-backward "^\\(.+\\)$" beg t)
    (replace-match "\\\\item \\1" t nil)
    (beginning-of-line 1))))
  ad-do-it
  ;; 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 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 at 1:25
1  
@Nordlöw ask a new question, I have already the answer ;-). –  giordano Feb 22 at 11:13
    
Ok. Great. Here's the new question: tex.stackexchange.com/questions/161784/… –  Nordlöw Feb 22 at 11:34

Your Answer

 
discard

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.