[Top][All Lists]

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

Re: [AUCTeX-devel] patch for exam class

From: Arash Esbati
Subject: Re: [AUCTeX-devel] patch for exam class
Date: Sun, 13 Nov 2016 14:20:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1

Uwe Brauer <address@hidden> writes:

> Hi it seems that I sent this patch to the wrong list.

I'm not an exam user, but I think it would be nice if you add some code
in order to get "question" and "part" et al. inserted as an item while
you are in the respective environment.

You need to define a function like `LaTeX-exam-insert-item' and hook it
into AUCTeX.  Some other comments are below:

--8<---------------cut here---------------start------------->8---
;;; Code:

(defvar LaTeX-exam-class-options '("answers" "addpoints")
  "Class options for the exam class.")

(defun LaTeX-exam-insert-item ()
  "Insert a new item in an environment from exam class.
Item inserted depends on the environment."
   (cond ((string= environment "questions")
         ((string= environment "parts")
         ((string= environment "subparts")
         ((string= environment "subsubparts")
         ;; Fallback
         (t "item"))))

 (lambda ()
   (LaTeX-add-environments "solution"
                           '("questions" LaTeX-env-item)
                           '("parts" LaTeX-env-item)
                           '("subparts" LaTeX-env-item)
                           '("subsubparts" LaTeX-env-item))

   ;; Tell AUCTeX about special environments:
   (let ((envs '("questions" "parts" "subparts" "subsubparts")))
     (dolist (env envs)
       (add-to-list 'LaTeX-item-list
                    (cons env 'LaTeX-exam-insert-item))))

   ;; Append us only once:
   (unless (and (string-match "question" LaTeX-item-regexp)
                (string-match "subsub" LaTeX-item-regexp))
      (set (make-local-variable 'LaTeX-item-regexp)
    '("part" [ "Points" ] (TeX-arg-literal " "))
    '("subpart" [ "Points" ] (TeX-arg-literal " "))
    '("subsubpart" [ "Points" ] (TeX-arg-literal " "))
    '("question"  ["Points"] (TeX-arg-literal " "))
    '("titledquestion" "Title" ["Points"])
    '("droptotalpoints" 0)
    '("droppoints" 0))

   ;; Fontification
   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("question"        "[")
                                ("subpart"         "[")
                                ("subsubquestion"  "["))

;;; exam.el ends here
--8<---------------cut here---------------end--------------->8---

> +   (TeX-add-symbols
> +    '("part" TeX-arg-examn-points 0)

You don't need `TeX-arg-examn-points'.  Adding ["Points"] suffices.

> +    '("subpart" TeX-arg-examn-points 0)
> +    '("subsubpart" TeX-arg-examn-points 0)
> +    '("question"  ["Points"] reftex-label)

Please don't use `reftex-label'.  Non Reftex-user will get an error.
`TeX-arg-ref' does the right thing here.

> +    '("titledquestion" "Title" ["Points"]  reftex-label)
> +    '("question" TeX-arg-examn-points 0)
> +    '("droptotalpoints" 0)
> +    '("droppoints" 0)
> +    ))
> + LaTeX-dialect)
> +
> +(defun TeX-arg-examn-points (optional &optional prompt)
> +  "Prompt for overlay specification and optional argument."
> +  (let ((options (read-input "Points: ")))

,----[ C-h f read-input RET ]
| read-input is an alias for ‘read-string’ in ‘subr.el’.
| This function is obsolete since 22.1;
| use ‘read-string’ instead.

AUCTeX has a compat function `TeX-read-string'.  You should use that

Best, Arash

reply via email to

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