From e2f4885c63150fdd25ff57d87430fd531e3db5df Mon Sep 17 00:00:00 2001 From: Sebastian Kuhnert Date: Mon, 16 Nov 2009 09:29:32 +0000 Subject: add auctex style file for exercisesheets.sty --- exercisesheets.el | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 exercisesheets.el diff --git a/exercisesheets.el b/exercisesheets.el new file mode 100644 index 0000000..6c37747 --- /dev/null +++ b/exercisesheets.el @@ -0,0 +1,84 @@ +;;; exercisesheets.el --- AUCTeX style for `exercisesheets.sty' + +;; Author: Sebastian Kuhnert +;; Created: 2009-11-18 +;; Keywords: tex + + +(defun LaTeX-exercisesheets-read-kwopt (context spec &optional required) + "Ask the user if/how an option should be included. + +CONTEXT is used in the prompt. + +SPEC is a string of the form `opt' for boolean options (ask if it should be included), +`opt=' for free-form arguments for the option (include if non-empty), +`opt=arg1,arg2,arg3' for suggestions with completion (empty means skip), +`opt=!arg1,arg2,arg3' for alternatives with completion (empty means skip). + +If REQUIRED is non-nil, + +The result is the string to be used as argument. If the option is skipped, the result is nil." + (if (string-match "^\\(.*\\)=\\(!?\\)\\(.*\\)$" spec) + (let* ((optstr (if required "optional " "")) + (require-match (if (match-string 2 spec) t nil)) + (answer (save-match-data + (if (string= "" (match-string 3 spec)) + (read-string (concat context ": " optstr "argument " (match-string 1 spec) "=")) + (completing-read (concat context ": " optstr "argument " (match-string 1 spec) "=") + (split-string (match-string 3 spec) ",") + nil + require-match))))) + (if (or (not (string= "" answer)) required) + (if (string-match-p "[,= ]" answer) + (concat (match-string 1 spec) "={" answer "}") + (concat (match-string 1 spec) "=" answer)) + nil)) + (if (y-or-n-p (concat context ": include argument " spec "? ")) + spec + nil))) + +(defun LaTeX-exercisesheets-read-kwopts(context startdelim enddelim &rest specs) + (let* ((anslist (mapcar + (lambda (spec) (LaTeX-exercisesheets-read-kwopt context spec)) + args)) + (ansstr (list-to-string (delq nil anslist) ","))) + (if (not (string= "" ansstr)) + (concat startdelim ansstr enddelim)))) + +(defun LaTeX-exercisesheets-insert-kwopts(optional &rest specs) + (if optional + (LaTeX-exercisesheets-read-kwopts(nil "[" "]" specs)) + (LaTeX-exercisesheets-read-kwopts(nil "{" "}" specs)))) + +(defun LaTeX-exercisesheets-insert-environment (env &rest args) + "Insert environment ENV considering keyword arguments ARGS. + +Each entry of ARGS can be a string (a keyword) or a conscell +consisting of keyword and explanation for the user (used in the prompt)." + (LaTeX-insert-environment env (LaTeX-exercisesheets-read-kwopts (concat env " environment") "[" "]" args))) + +(TeX-add-style-hook "exercisesheets" + (lambda () + ;; New symbols + (TeX-add-symbols + '("subject" 1) + '("TODO" 0) + '("points" [ (LaTeX-exercisesheets-insert-kwopts "optional" "bonus") ] "points") + '("exshset" 1) + '("ifsolutions" 2)) + ;; New environments + (LaTeX-add-environments + '("sheet" LaTeX-exercisesheets-insert-environment "date=" "note=" "title=") + '("exercise" LaTeX-exercisesheets-insert-environment "points=" "oral" "name=" "firstline=") + "solution" ;;; oral + "hint" + "hint*") + ;; Warning keywords + (font-latex-add-keywords '("TODO") + 'warning) + )) + +(defvar LaTeX-exercisesheets-package-options '("only=" "all" "solutions" "solutions=oral" "solutionsby=" "language=") + "Package options for the exercisesheets package.") + +;;; exercisesheets.el ends here -- cgit v1.2.3