[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX] Indent custom env like itemize/enumerate environment
From: |
Arash Esbati |
Subject: |
Re: [AUCTeX] Indent custom env like itemize/enumerate environment |
Date: |
Mon, 12 Jun 2017 22:17:24 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2 |
Thorsten Grothe <address@hidden> writes:
> where is the best place for moodle.el? I got a personal directory under
> .emacs.d created with TeX-auto-generate, named simply auctex and put
> moodle.el in this dir, but auctex does not see it, it happens nothing,
> what I'm doing wrong?
Hi Thorsten,
in your .emacs, set `TeX-style-private' to a directory of your choice,
e.g.
(setq TeX-style-private "~/.emacs.d/auctex")
and put moodle.el in that directory.
Also put this in your .emacs and restart Emacs.
(setq TeX-parse-self t)
Now restart Emacs and open your .tex file which contains
\usepackage{moodle} or do `C-c C-m usepackage RET moodle RET'. AUCTeX
should then load the style.
I've touched the code and it should now cover all macros and
environments provided by the package. Happy testing and thanks in
advance.
--8<---------------cut here---------------start------------->8---
;;; Code:
(defvar LaTeX-moodle-key-val-options
'(("points")
("default grade")
("penalty")
("fraction")
("feedback"))
"Key=value options for moodle macros and environments.")
(defun LaTeX-moodle-question-env-with-args (env)
"Insert ENV provided by moodle.sty incl. arguments and first \\item."
(LaTeX-insert-environment
env
(let ((opts (TeX-read-key-val
t
(cond (;; 3.3.1 Multiple Choice
(string= env "multi")
(append '(("shuffle" ("true" "false"))
("numbering" ("alph" "Alph" "arabic"
"roman" "Roman" "none"))
("single" ("true" "false"))
("multiple" ("true" "false")))
(when (string= "cloze"
(LaTeX-current-environment))
'(("vertical" ("true" "false"))
("horizonal" ("true" "false"))))
LaTeX-moodle-key-val-options))
;; 3.3.3 Short Answer
((string= env "shortanswer")
(append '(("case sensitive" ("true" "false"))
("usecase" ("true" "false")))
(when (string= "cloze"
(LaTeX-current-environment))
'(("vertical" ("true" "false"))
("horizonal" ("true" "false"))))
LaTeX-moodle-key-val-options))
;; 3.3.4 Essay Questions
((string= env "essay")
(append '(("response required" ("true" "false"))
("response format" ("html" "file"
"html+file"
"text" "monospaced"))
("response field lines")
("attachments allowed" ("0" "1" "2" "3"
"unlimited"))
("attachments required" ("0" "1" "2" "3"))
("response template"))
(when (string= "cloze"
(LaTeX-current-environment))
'(("vertical" ("true" "false"))
("horizonal" ("true" "false"))))
LaTeX-moodle-key-val-options))
;; 3.4 Matching Questions
((string= env "matching")
(append '(("shuffle" ("true" "false"))
("drag and drop" ("true" "false"))
("dd" ("true" "false")))
LaTeX-moodle-key-val-options))
(t (append
(when (string= "cloze" (LaTeX-current-environment))
'(("vertical" ("true" "false"))
("horizonal" ("true" "false"))))
LaTeX-moodle-key-val-options)))))
(qname (unless (string= "cloze" (LaTeX-current-environment))
(TeX-read-string (TeX-argument-prompt nil nil "Question
name")))))
(concat
(when (and opts (not (string= opts "")))
(format "[%s]" opts))
(when (and qname (not (string= qname "")))
(format "{%s}" qname)))))
(if (TeX-active-mark)
(progn
(LaTeX-find-matching-begin)
(end-of-line 1))
(end-of-line 0))
(delete-char 1)
(when (looking-at (concat "^[ \t]+$\\|"
"^[ \t]*" TeX-comment-start-regexp "+[ \t]*$"))
(delete-region (point) (line-end-position)))
(delete-horizontal-space)
;; Deactivate the mark here in order to prevent `TeX-parse-macro'
;; from swapping point and mark and the \item ending up right after
;; \begin{...}.
(TeX-deactivate-mark)
;; Query and insert the question text.
(let ((qtext (TeX-read-string (TeX-argument-prompt nil nil "Question Text"))))
(when (and qtext (not (string= qtext "")))
(newline)
(indent-according-to-mode)
(insert qtext)
(LaTeX-fill-paragraph)))
(LaTeX-insert-item)
;; The inserted \item may have outdented the first line to the
;; right. Fill it, if appropriate.
(when (and (not (looking-at "$"))
(not (assoc env LaTeX-indent-environment-list))
(> (- (line-end-position) (line-beginning-position))
(current-fill-column)))
(LaTeX-fill-paragraph nil)))
(defun LaTeX-moodle-item-argument ()
"Insert an \\item with optional argument in environments of moodle package."
(let ((TeX-insert-macro-default-style 'mandatory-args-only))
(TeX-insert-macro "item"))
;; Add * to `LaTeX-moodle-key-val-options' in multi environment:
(let ((opts
(TeX-read-key-val t (if (string= "multi" (LaTeX-current-environment))
(append '(("*")) LaTeX-moodle-key-val-options)
LaTeX-moodle-key-val-options))))
(when (and opts (not (string= opts "")))
(delete-horizontal-space)
(if (string= opts "*")
(insert opts)
(insert LaTeX-optop opts LaTeX-optcl))))
(just-one-space)
(when (string= "matching" (LaTeX-current-environment))
(save-excursion
(insert TeX-esc "answer")
(just-one-space))))
(TeX-add-style-hook
"moodle"
(lambda ()
(LaTeX-add-environments
;; 3.2 Quiz and Question Environments
'("quiz"
(lambda (environment)
(LaTeX-insert-environment
environment
(let ((opts (TeX-read-key-val t LaTeX-moodle-key-val-options))
(bank (TeX-read-string (TeX-argument-prompt nil nil "Question
bank name"))))
(concat
(when (and opts (not (string= opts "")))
(format "[%s]" opts))
(format "{%s}" bank))))))
'("cloze" "Question bank name"))
(TeX-add-symbols
'("moodleset"
(TeX-arg-eval
(lambda ()
(let ((opts (TeX-read-key-val optional
(append '(("ppi"))
LaTeX-moodle-key-val-options))))
(format "%s" opts)))))
;; 5 Graphics
'("ghostscriptcommand" "File name")
'("imagemagickcommand" "File name")
'("opensslcommand" "File name"))
;; Make environments available to AUCTeX:
(dolist (env '("multi" "numerical" "shortanswer" "essay" "matching"))
(LaTeX-add-environments `(,env LaTeX-moodle-question-env-with-args))
(add-to-list 'LaTeX-item-list `(,env . LaTeX-moodle-item-argument) t))
;; Fontification
(when (and (featurep 'font-latex)
(eq TeX-install-font-lock 'font-latex-setup))
(font-latex-add-keywords '(("moodleset" "{")
("ghostscriptcommand" "{")
("imagemagickcommand" "{")
("opensslcommand" "{"))
'function)
(font-latex-add-keywords '(("answer" "")
;; Cater for a fontified starred \item
("item" "*["))
'textual)))
LaTeX-dialect)
(defvar LaTeX-moodle-package-options
'("draft")
"Package options for the moodle package.")
;;; moodle.el ends here
--8<---------------cut here---------------end--------------->8---
Best, Arash
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, (continued)
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, Arash Esbati, 2017/06/05
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, Thorsten Grothe, 2017/06/05
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, Thorsten Grothe, 2017/06/06
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, Arash Esbati, 2017/06/06
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, Thorsten Grothe, 2017/06/06
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, Arash Esbati, 2017/06/08
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, Arash Esbati, 2017/06/10
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, Thorsten Grothe, 2017/06/11
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, Arash Esbati, 2017/06/11
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment, Thorsten Grothe, 2017/06/12
- Re: [AUCTeX] Indent custom env like itemize/enumerate environment,
Arash Esbati <=