# HG changeset patch # User Uwe Brauer # Date 1479055122 0 # Sun Nov 13 16:38:42 2016 +0000 # Node ID a524ab3c63e3ae71ee7d2cc4ac3d18e0bd87e293 # Parent e37527510e63bb0a4fcd64db2ab385a6f7fda5f2 Add style/exam.el and entry in Makefile.in * Makefile.in (STYLESRC): Add entry style: style/exam.el * style/exam.el New style file. Thanks to Arash Esbati for various improvments. diff --git a/Makefile.in b/Makefile.in --- a/Makefile.in +++ b/Makefile.in @@ -157,7 +157,7 @@ style/splitidx.el style/tikz.el style/xcolor.el \ style/pdflscape.el style/commath.el style/empheq.el \ style/framed.el style/paracol.el style/menukeys.el \ - style/bidi.el + style/bidi.el style/exam.el STYLEELC = $(STYLESRC:.el=.elc) diff --git a/style/exam.el b/style/exam.el new file mode 100644 --- /dev/null +++ b/style/exam.el @@ -0,0 +1,101 @@ +;;; exam.el --- AUCTeX style for the (LaTeX) exam class + + +;; Copyright (C) 2016 Free Software Foundation, Inc. + +;; Author: Uwe Brauer +;; Created: 2016-03-06 +;; Keywords: tex + +;; This file is part of AUCTeX. + +;; AUCTeX 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 3, or (at your option) +;; any later version. + +;; AUCTeX is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with AUCTeX; see the file COPYING. If not, write to the Free +;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +;; 02110-1301, USA. + +;;; Commentary: + +;; This file adds support for the exam class. + +;; Acknowledgements +;; Arash Esbati for a almost complete rewrite. + +;;; 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." + (TeX-insert-macro + (cond ((string= environment "questions") + "question") + ((string= environment "parts") + "part") + ((string= environment "subparts") + "subpart") + ((string= environment "subsubparts") + "subsubpart") + ;; Fallback + (t "item")))) + +(TeX-add-style-hook + "exam" + (lambda () + (LaTeX-add-environments "solution" + "solutionorbox" + '("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) + (concat + LaTeX-item-regexp + "\\|" + "question\\b" + "\\|" + "\\(sub\\|subsub\\)?part\\b"))) + + (TeX-add-symbols + '("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" "[")) + 'textual))) + LaTeX-dialect) + +;;; exam.el ends here +