2

I am using the exam class to write some multiple choice questions on emacs. How can I achieve some sort of automatic \choice key combination in the checkboxes environment etc. Just like that I can use M-RET to achieve automatic \item in the itemize or enumerate environment?

In fact, some days ago I accidentally found out that I can use M-j to get what I want, but I lost it soon afterwards, and sadly I cannot regenerated the situation ever again. Do I need to activate something? Thanks in advance!

1

You have to hack LaTeX-item-list. Honestly, this is a bit uncomfortable to do because it should be a task for style files.

Anyway, you can add the following lines to your init file

(add-hook 'LaTeX-mode-hook
      (lambda ()
        ;; Add checkboxes
        (add-to-list
         'LaTeX-item-list
         '("checkboxes" . (lambda ()
                (let (TeX-insert-braces)
                  (TeX-insert-macro "choice ")))))
        ;; Add choices
        (add-to-list
         'LaTeX-item-list
         '("choices" . (lambda ()
                 (let (TeX-insert-braces)
                   (TeX-insert-macro "choice ")))))))

In this way, you can type C-c C-j in choices and checkboxes environments and a newline will be inserted, with new line starting with \choice.

I did it only for a couple of environments, if you want to include others follow the example for checkboxes.

See also https://stackoverflow.com/q/20361826

  • this is great! by any chance do you know some possibility how got it by accident before? i did not add anything related to choice or checkboxes before. as you mentioned, is there a style file for exam? thanks~ – davyjones Apr 7 '16 at 13:04
  • C-c C-j will always insert \item as if point were in an itemize environment, unless it is in another environment listed in LaTeX-item-list. Unfortunately not, AUCTeX doesn't provide an exam style file, I could try writing down one some day. – giordano Apr 7 '16 at 14:48

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.