auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX] Re: Items in itemize-like environments


From: Nikos Apostolakis
Subject: [AUCTeX] Re: Items in itemize-like environments
Date: Fri, 21 Apr 2006 22:26:39 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Ralf Angeli <address@hidden> writes:

> * Nikos Apostolakis (2006-04-19) writes:

>> [snip] when I hit "M-RET" inside a "questions" environment, Emacs
>> [should] insert "\question" and ask me "how many points is this question
>> worth?".  The answer should then become a label, eg if the answer
>> is "100" then "\question[100]" is inserted.
>
> You could use something like
>
> (add-to-list 'LaTeX-item-list
>            '("questions" .
>              (lambda ()
>                (let ((value (read-from-minibuffer
>                              "How many points is this question worth? ")))
>                  (insert (concat "\\question" (unless (string= value "")
>                                                 (format "[%s]" value))))))))
>

Great! Thanks.  I actually did:

(insert (concat "\\question" (if (string= value "")
                                 " "
                               (format "[%s]" value))))

instead, so that when no points are specified then the spacing is
still right.


>> Ideally the previous answer should be the default,
>
> You could do this with a global variable you set to the value used
> last.  For an example you can look at the function `LateX-environment'
> in latex.el.
>

Well with the above code, the previous value is easily accessible
via minibuffer history and that's more than sufficient.  

Now I am not sure how to make sure that these customizations are
automatically loaded every time I open an exam document class file.
I did put them in an .el file (see the end of this message) and I
loaded it but that doesn't seem to have the desired effect.  What
did I do wrong?

Thanks in advance,
Nikos

,----[ exam.el ]
| ;;; exam.el --- AUCTeX style for `exam.cls'
| 
| ;; Author: Nikos Apostolakis
| ;; (Plagiarizing alltt.el by Ralf Angeli)
| 
| ;; This file is *not* part of AUCTeX.
| 
| ;; This file is free software; you can redistribute it and/or modify it
| ;; under the terms of the GNU General Public License as published by
| ;; the Free Software Foundation; either version 2, or (at your option)
| ;; any later version.
| 
| ;;; Code:
| 
| (TeX-add-style-hook
|  "exam"
|  (lambda ()
|    (LaTeX-add-environments '("questions" LaTeX-env-item))
|    (add-to-list 'LaTeX-item-list
|            '("questions" .
|              (lambda ()
|                (let ((value (read-from-minibuffer
|                              "How many points is this question worth? ")))
|                  (insert (concat "\\question" (if (string= value "")
|                                                   " "
|                                                 (format "[%s]" value))))))))
|    (LaTeX-add-environments '("parts" LaTeX-env-item))
|    (add-to-list 'LaTeX-item-list
|            '("parts" .
|              (lambda ()
|                (let ((value (read-from-minibuffer
|                              "How many points is this part worth? ")))
|                  (insert (concat "\\part" (if (string= value "")
|                                               " "
|                                             (format "[%s]" value))))))))
|    (setq LaTeX-item-regexp 
"\\(bib\\)?item\\b\\|\\(part\\b\\|question\\b\\)")))  
| 
| 
| ;;; exam.el ends here
`----





reply via email to

[Prev in Thread] Current Thread [Next in Thread]