# HG changeset patch # User Uwe Brauer # Date 1482759648 0 # Mon Dec 26 13:40:48 2016 +0000 # Node ID 3b6a83400e4b87493deb35847e74a719feff2a6d # Parent 4289df859492a852b8ecacedb3c3ef4aa62392f1 Add style/exam.el, modify Makefile.in: add exam.el * style/exam.el. Various improvements thanks to Arash Esbati . * tex-style.el: Move defcustom from exam.el to tex-style.el * Makefile.in (STYLESRC): add exam.el * style/exam.el: Add style file diff --git a/Makefile.in b/Makefile.in --- a/Makefile.in +++ b/Makefile.in @@ -159,7 +159,7 @@ style/framed.el style/paracol.el style/menukeys.el \ style/bidi.el style/FiraMono.el style/FiraSans.el \ style/bicaption.el style/amsfonts.el style/subfiles.el \ - style/dcolumn.el + style/dcolumn.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,374 @@ +;;; 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")))) + +(defun LaTeX-exam-insert-label (_optional &optional name type) + "Indent the line and query/insert a label incl. the \"\\label\" macro. +Arguments NAME and TYPE are the same as for the function +`LaTeX-label'. OPTIONAL is ignored." + (indent-according-to-mode) + (let ((currenv (LaTeX-current-environment))) + (LaTeX-label (or name currenv) (or type 'environment)))) + +(TeX-add-style-hook + "exam" + (lambda () + + ;; Make our label prefix available ... + (let ((envs '("questions"))) + (dolist (env envs) + ;; to AUCTeX + (add-to-list 'LaTeX-label-alist + (cons env 'LaTeX-exam-label)) + ;; to RefTeX with `reftex-add-label-environments' + (when (fboundp 'reftex-add-label-environments) + (reftex-add-label-environments + `((,env ,LaTeX-exam-reftex-quick-id-key ,LaTeX-exam-label + "~\\ref{%s}" nil + (regexp "[Qq]uestions?" "[Nn]umbers?"))))))) + (when (or (member "xcolor" (TeX-style-list)) + (member "color" (TeX-style-list))) + (TeX-add-symbols '("shadedsolutions" 0))) + + (LaTeX-add-environments "solution" + "solutionorbox" + "solutionorlines" + "solutionordottedlines" + '("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 + "\\|" + "\\(titled\\)?question\\b" + "\\|" + "\\(sub\\|subsub\\)?part\\b")) + (LaTeX-set-paragraph-start)) + + (TeX-add-symbols + '("part" [ "Points" ] (TeX-arg-literal " ")) + '("subpart" [ "Points" ] (TeX-arg-literal " ")) + '("gradetable" + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Orientation") + '("v" "h") ] + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Table index") + '("questions" "pages") ] ) + '("bonusgradetable" + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Orientation") + '("v" "h") ] + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Table index") + '("questions" "pages") ] ) + '("bonuspointtable" + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Orientation") + '("v" "h") ] + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Table index") + '("questions" "pages") ] ) + '("partialgradetable" + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Orientation") + '("v" "h") ] + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Table index") + '("questions" "pages") ] ) + '("partialbonusgradetable" + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Orientation") + '("v" "h") ] + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Table index") + '("questions" "pages") ] ) + '("partialbonuspointtable" + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Orientation") + '("v" "h") ] + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Table index") + '("questions" "pages") ] ) + '("pointtable" + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Orientation") + '("v" "h") ] + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Table index") + '("questions" "pages") ] ) + '("partialpointtable" + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Orientation") + '("v" "h") ] + [ TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Table index") + '("questions" "pages") ] ) + + '("subsubpart" [ "Points" ] (TeX-arg-literal " ")) + '("question" ["Points"] (TeX-arg-literal " ")) + '("subpart" ["Points"] (TeX-arg-literal " ")) + '("bonusquestion" ["Points"] (TeX-arg-literal " ")) + '("extrafootheight" [ TeX-arg-length "Extra height 1. page footer" ] + (TeX-arg-length "Extra height footers")) + '("titledquestion" "Title" ["Points"] LaTeX-exam-insert-label (TeX-arg-literal " ")) + '("ContinuedQuestion" 0) ;ok + '("CorrectChoice" 0) ;ok + '("CorrectChoiceEmphasis" 1) ;ok + '("IncompleteQuestion" 0) ;ok + '("SolutionEmphasis" 1) ;ok + '("addpoints" 0) ;ok + '("addquestionobject" 0) ;ok + '("answerclearance" 1) ;ok + '("answerline" ["Points"] (TeX-arg-literal " ")) ;ok + '("begingradingrange" 1) ;ok + '("bhpgword" 1) ;ok + '("bhpword" 1) ;ok + '("bhqword" 1) ;ok + '("bhsword" 1) ;ok + '("bhtword" 1) ;ok + '("bonuspart" 0) ;ok + '("bonuspointformat" 0) ;ok + '("bonuspointname" 1) ;ok + '("bonuspointpoints" 2) ;ok + '("bonuspointsinrange" 0) ;ok + '("bonuspointsofquestion" 1) ;ok + '("bonuspointsonpage" 0) ;ok + '("bonusqformat" 1) ;ok + '("bonussubpart" 0) ;ok + '("bonussubsubpart" 0) ;ok + '("bonustitledquestion" "Title" ["Points"] LaTeX-exam-insert-label (TeX-arg-literal " ")) ;ok + '("bonustotalformat" 0) ;ok + '("boxedpoints" 0) ;ok + '("bracketedpoints" 0) ;ok + '("bvpgword" 1) ;ok + '("bvpword" 1) ;ok + '("bvqword" 1) ;ok + '("bvsword" 1) ;ok + '("bvtword" 1) ;ok + '("cancelspace" 0) ;ok + '("cellwidth" 1) ;ok + '("cfoot" 1) ;ok + '("chbpword" 1) ;ok + '("chead" 1) ;ok + '("checkboxchar" 1) ;ok + '("checkboxeshook" 0) ;ok + '("checkedchar" 1) ;ok + '("choice" 0) ;ok + '("choicelabel" 0) ;ok + '("choiceshook" 0) ;ok + '("chpgword" 1) ;ok + '("chpword" 1) ;ok + '("chqword" 1) ;ok + '("chsword" 1) ;ok + '("chsword" 1) ;ok + '("correctchoice" 0) ;ok + '("correctchoiceemphasis" 1) ;ok + '("covercfoot" 3) ;ok + '("coverchead" 3) ;ok + '("coverextrafootheight" 3) ;ok + '("coverextraheadheight" 3) ;ok + '("coverfirstpagefooter" 3) ;ok + '("coverfirstpageheader" 3) ;ok + '("coverfooter" 3) ;ok + '("coverheader" 3) ;ok + '("coverlfoot" 3) ;ok + '("coverlhead" 3) ;ok + '("coverrfoot" 3) ;ok + '("coverrhead" 3) ;ok + '("coverrunningfooter" 3) ;ok + '("coverrunningheader" 3) ;ok + '("cvbpword" 1) ;ok + '("cvpgword" 1) ;ok + '("cvpword" 1) ;ok + '("cvqword" 1) ;ok + '("cvsword" 1) ;ok + '("cvtword" 1) ;ok + '("dottedlinefillheight" 1) ;ok + '("droppoints" 0) ;ok + '("droptotalbonuspoints" 0) ;ok + '("droptotalpoints" 0) ;ok + '("endgradingrange" 1) ;ok + '("extraheadheight" 1) ;ok + '("extrawidth" 1) ;ok + '("fillwithdottedlines" 1) ;ok + '("fillwithdottedlines" 1) ;ok + '("fillwithlines" 1) ;ok + '("fillwithlines" 1) ;ok + '("firstpagefooter" 1) ;ok + '("firstpagefootrule" 0) ;ok + '("firstpageheader" 3) ;ok + '("firstpageheadrule" 0) ;ok + '("footer" 3) ;ok + '("footrule" 0) ;ok + '("framedsolutions" 0) ;ok + '("fullwidth" 1) ;ok + '("gradetablestretch" 0) ;ok + '("greeknum" 0) ;ok + '("half" 0) ;ok + '("hpgword" 1) ; ok + '("hpword" 1) ; ok + '("hqword" 1) ; ok + '("hsword" 1) ; ok + '("htword" 1) ; ok + '("ifcontinuation" 0) ;ok + '("ifincomplete" 0) ;ok + '("iflastpage" 0) ;ok + '("ifprintanswers" 0) ;ok + '("lfoot" 1) ;ok + '("lhead" 1) ;ok + '("linefillheight" 1) ;ok + '("linefillthickness" 1) ;ok + '("makeemptybox" 1) ;ok + '("marginbonuspointname" 1) ;ok + '("marginpointname" 1) ;ok + '("marginpointsep" 1) ;ok + '("marksnotpoints" 0) ;ok + '("noaddpoints" 0) ;ok + '("nobonusqformat" 1) ;ok + '("noboxedpoints" 0) ;ok + '("nobracketedpoints" 0) ;ok + '("nocancelspace" 0) ;ok + '("nomorequestions" 0) ;ok + '("nopointsinmargin" 0) ;ok + '("nopointsinrightmargin" 0) ;ok + '("noprintanswers" 0) ;ok + '("noqformat" 1) ;ok + '("numbonuspoints" 0) ;ok + '("numcoverpages" 0) ;ok + '("numpages" 0) ;ok + '("numparts" 0) ;ok + '("numpoints" 0) ;ok + '("numquestions" 0) ;ok + '("numsubparts" 0) ;ok + '("numsubsubparts" 0) ;ok + '("oddeven" 2) ;ok + '("partlabel" 0) ;ok + '("partopsep" 0) ;ok + '("partshook" 0) ;ok + '("pointname" 1) ;ok + '("pointpoints" 2) ;ok + '("pointsdroppedatright" 0) ;ok + '("pointsinmargin" 0) ;ok + '("pointsinrightmargin" 0) ;ok + '("pointsofquestion" 1) ;ok + '("pointsonpage" 1) ;ok + '("printanswers" 0) ;ok + '("qformat" 1) ;ok + '("questionlabel" 0) ;ok + '("questionshook" 0) ;ok + '("rfoot" 1) ;ok + '("rhead" 1) ;ok + '("rightpointsmargin" 0) ;ok + '("roman" 0) ;ok + '("romannumeral" 0) ;ok + '("runningfooter" 3) ;ok + '("runningfootrule" 0) ;ok + '("runningheader" 3) ;ok + '("runningheadrule" 0) ;ok + '("settabletotalbonuspoints" 1) ;ok + '("settabletotalpoints" 1) ;ok + '("shadedsolutions" 0) ;ok + '("solutiontitle" 0) ;ok + '("subpartlabel" 0) ;ok + '("subpartshook" 0) ;ok + '("subsubpartlabel" 0) ;ok + '("subsubpartshook" 0) ;ok + '("thechoice" 0) ;ok + '("themarginpoints" 0) ;ok + '("thepartno" 0) ;ok + '("thequestion" 0) ;ok + '("thequestiontitle" 0) ;ok + '("thesubpart" 0) ;ok + '("thesubsubpart" 0) ;ok + '("totalbonuspoints" 0) ;ok + '("totalformat" 0) ;ok + '("totalnumpages" 0) ;ok + '("totalpoints" 0) ;ok + '("unframedsolutions" 0) ;ok + '("uplevel" 1) ;ok + '("usehorizontalhalf" 0) ;ok + '("useslantedhalf" 0) ;ok + '("vpgword" 1) ; ok + '("vpword" 1) ; ok + '("vqword" 1) ; ok + '("vsword" 1) ; ok + '("vtword" 1) ; ok + '("thepoints" 0) + ;; ... more stuff here + ) + (LaTeX-add-lengths "answerlinelength" "answerskip") + + + ;; Fontification + (when (and (featurep 'font-latex) + (eq TeX-install-font-lock 'font-latex-setup)) + (font-latex-add-keywords '(("question" "[") + ("titledquestion" "{[") + ("subpart" "[") + ("subsubpart" "[")) + 'textual))) + LaTeX-dialect) + +;;; exam.el ends here diff --git a/tex-style.el b/tex-style.el --- a/tex-style.el +++ b/tex-style.el @@ -368,6 +368,24 @@ :group 'LaTeX-style :type 'character) +;; style/exam.el + +(defcustom LaTeX-exam-reftex-quick-id-key ?x + "Unique letter identifying exam class macros in RefTeX. + +A character argument for quick identification when RefTeX inserts +new labels with `reftex-label'. It must be unique. It is +initialized to ?x." + :group 'LaTeX-style + :type 'character) + +(defcustom LaTeX-exam-label "exm:" + "Default prefix to labels in environments of exam class." + :group 'LaTeX-style + :type 'string) + + + (provide 'tex-style) ;;; tex-style.el ends here