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.

When inserting an itemize environment around some text (using C-c C-e) AucTeX insists on doing paragraph-filling on said text, which messes up my layout. Is there a simple way to prevent that ?

Context is, I'm turning plain-text notes into a latex document. When the plain-text draft contains:

- first item
- second item

I want to select the two lines, type C-c C-e itemize RET, and obtain:

\begin{itemize}
\item - first item
- second item
\end{itemize}

Then it would be easy to add the missing \item commands where required. But instead, AucTeX calls LaTeX-fill-region on the content of the environment (cf latex.el line 686) and I end up with:

\begin{itemize}
\item - first item - second item
\end{itemize}

Obviously this is no big deal for such a short list. But for some longer text it is, because the structure of my list is lost.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

I had a quick look at the source and auctex really wants to fill the region-)

Obviously you could change everywhere that needs changing but it would be simpler just to write a simple function that just inserted begin and end not really based on the auctex code.

or simplest is to select the region

- first item
- second item

and use C-w C-x C-e <return> C-y

Ie kill the region insert the environment around nothing then yank the region back. It's only a couple of extra keystrokes so less than it would take to write a new function unless you are doing this a lot:-)

share|improve this answer

Here's a quick & dirty function for you:

(defun itemize (beg end) 
 "wrap the active region in an 'itemize' environment,
  converting hyphens at the beginning of a line to \item"
  (interactive "r")
  (save-restriction
    (narrow-to-region beg end)
    (beginning-of-buffer)
    (insert "\\begin{itemize}\n")
    (while (re-search-forward "^- " nil t)
      (replace-match "\\\\item "))
    (end-of-buffer)
    (insert "\\end{itemize}\n")))

Select the region you want to convert and call M-x itemize. This hard-codes "- " at the beginning of a line as the beginning of an item. If you use other conventions, you'll need to tweak it accordingly.

share|improve this answer

Use M-<return> at the right position (after first item), which insert a return and a \item. M-<return> is also great when using RefTex-mode in align-environments, as it inserts \\ and the next label.

(More a comment, but too low reputation as a new user to comment :/)

share|improve this answer
    
Sure. And my point is precisely that I want to be able to type <M-return> at the beginning of each line without having to go fishing for my dashes :-) –  Gyom Jun 14 '13 at 12:14

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.