"Fossies" - the Fresh Open Source Software Archive

Member "auctex-12.3/style/exam.el" (18 Oct 2020, 12571 Bytes) of package /linux/misc/auctex-12.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lisp source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "exam.el": 12.2_vs_12.3.

    1 ;;; exam.el --- AUCTeX style for the (LaTeX) exam class
    2 
    3 ;; Copyright (C) 2016--2020 Free Software Foundation, Inc.
    4 
    5 ;; Author: Uwe Brauer <oub@mat.ucm.es>
    6 ;; Created: 2016-03-06
    7 ;; Keywords: tex
    8 
    9 ;; This file is part of AUCTeX.
   10 
   11 ;; AUCTeX is free software; you can redistribute it and/or modify it
   12 ;; under the terms of the GNU General Public License as published by
   13 ;; the Free Software Foundation; either version 3, or (at your option)
   14 ;; any later version.
   15 
   16 ;; AUCTeX is distributed in the hope that it will be useful, but
   17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
   18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   19 ;; General Public License for more details.
   20 
   21 ;; You should have received a copy of the GNU General Public License
   22 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
   23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   24 ;; 02110-1301, USA.
   25 
   26 ;;; Commentary:
   27 
   28 ;; This file adds support for the exam class.
   29 
   30 ;; Acknowledgements
   31 ;; Arash Esbati <arash@gnu.org> for a almost complete rewrite.
   32 
   33 ;;; Code:
   34 
   35 ;; Silence the compiler:
   36 (declare-function font-latex-add-keywords
   37           "font-latex"
   38           (keywords class))
   39 
   40 (defvar LaTeX-article-class-options)
   41 
   42 (defvar LaTeX-exam-class-options
   43   '("answers" "noanswers" "cancelspace" "nocancelspace" "addpoints")
   44   "Class options for the exam class.")
   45 
   46 (TeX-load-style "article")
   47 ;; Add options from `LaTeX-article-class-options' only once:
   48 (dolist (opt LaTeX-article-class-options)
   49   (add-to-list 'LaTeX-exam-class-options opt))
   50 
   51 (defun LaTeX-exam-insert-item ()
   52   "Insert a new item in an environment from exam class.
   53 Item inserted depends on the environment."
   54   (TeX-insert-macro
   55    (cond ((string= environment "questions")
   56           "question")
   57          ((string= environment "parts")
   58           "part")
   59          ((string= environment "subparts")
   60           "subpart")
   61          ((string= environment "subsubparts")
   62           "subsubpart")
   63      ((member environment '("choices" "oneparchoices"
   64                 "checkboxes" "oneparcheckboxes"))
   65       "choice")
   66          ;; Fallback
   67          (t "item"))))
   68 
   69 (defun LaTeX-exam-insert-label (_optional &optional name type)
   70   "Indent the line and query/insert a label incl. the \"\\label\" macro.
   71 Arguments NAME and TYPE are the same as for the function
   72 `LaTeX-label'.  OPTIONAL is ignored."
   73   (indent-according-to-mode)
   74   (let ((currenv (LaTeX-current-environment)))
   75     (LaTeX-label (or name currenv) (or type 'environment))))
   76 
   77 (TeX-add-style-hook
   78  "exam"
   79  (lambda ()
   80    (TeX-run-style-hooks "article")
   81    ;; Make our label prefix available ...
   82    (let ((envs '("questions")))
   83      (dolist (env envs)
   84        ;; to AUCTeX
   85        (add-to-list 'LaTeX-label-alist
   86                     (cons env 'LaTeX-exam-label))
   87        ;; to RefTeX with `reftex-add-label-environments'
   88        (when (fboundp 'reftex-add-label-environments)
   89          (reftex-add-label-environments
   90           `((,env ,LaTeX-exam-reftex-quick-id-key ,LaTeX-exam-label
   91                   "~\\ref{%s}" nil
   92                   (regexp "[Qq]uestions?" "[Nn]umbers?")))))))
   93    (when (or (member "xcolor" (TeX-style-list))
   94              (member "color" (TeX-style-list)))
   95      (TeX-add-symbols '("shadedsolutions" 0)))
   96 
   97    (LaTeX-add-environments
   98     '("solution" [ "Height" ])
   99     '("select")
  100     '("choices" LaTeX-env-item)
  101     '("oneparchoices" LaTeX-env-item)
  102     '("checkboxes" LaTeX-env-item)
  103     '("oneparcheckboxes" LaTeX-env-item)
  104     '("solutionorbox" [ "Height" ])
  105     '("solutionorlines" [ "Height" ])
  106     '("solutionordottedlines" [ "Height" ])
  107     '("solutionorgrid" [ "Height" ])
  108     '("questions" LaTeX-env-item)
  109     '("parts" LaTeX-env-item)
  110     '("subparts" LaTeX-env-item)
  111     '("subsubparts" LaTeX-env-item))
  112 
  113    ;; Tell AUCTeX about special environments:
  114    (let ((envs '("questions"
  115          "parts"      "subparts"         "subsubparts"
  116          "choices"    "oneparchoices"
  117          "checkboxes" "oneparcheckboxes")))
  118      (dolist (env envs)
  119        (add-to-list 'LaTeX-item-list
  120                     (cons env 'LaTeX-exam-insert-item)
  121             t)))
  122 
  123    ;; Append us only once:
  124    (unless (and (string-match "question" LaTeX-item-regexp)
  125                 (string-match "sub" LaTeX-item-regexp))
  126      (set (make-local-variable 'LaTeX-item-regexp)
  127           (concat
  128            LaTeX-item-regexp
  129            "\\|"
  130        "choice\\b"
  131        "\\|"
  132            "\\(titled\\)?question\\b"
  133            "\\|"
  134            "\\(sub\\)*part\\b"))
  135      (LaTeX-set-paragraph-start))
  136 
  137    (TeX-add-symbols
  138     '("part" [ "Points" ] (TeX-arg-literal " "))
  139     '("subpart" [ "Points" ] (TeX-arg-literal " "))
  140     '("gradetable"
  141       [ TeX-arg-eval completing-read
  142                      (TeX-argument-prompt optional nil "Orientation")
  143                      '("v" "h") ]
  144       [ TeX-arg-eval completing-read
  145                      (TeX-argument-prompt optional nil "Table index")
  146                      '("questions" "pages") ] )
  147     '("bonusgradetable"
  148       [ TeX-arg-eval completing-read
  149                      (TeX-argument-prompt optional nil "Orientation")
  150                      '("v" "h") ]
  151       [ TeX-arg-eval completing-read
  152                      (TeX-argument-prompt optional nil "Table index")
  153                      '("questions" "pages") ] )
  154     '("bonuspointtable"
  155       [ TeX-arg-eval completing-read
  156                      (TeX-argument-prompt optional nil "Orientation")
  157                      '("v" "h") ]
  158       [ TeX-arg-eval completing-read
  159                      (TeX-argument-prompt optional nil "Table index")
  160                      '("questions" "pages") ] )
  161     '("partialgradetable"
  162       [ TeX-arg-eval completing-read
  163                      (TeX-argument-prompt optional nil "Orientation")
  164                      '("v" "h") ]
  165       [ TeX-arg-eval completing-read
  166                      (TeX-argument-prompt optional nil "Table index")
  167                      '("questions" "pages") ] )
  168     '("partialbonusgradetable"
  169       [ TeX-arg-eval completing-read
  170                      (TeX-argument-prompt optional nil "Orientation")
  171                      '("v" "h") ]
  172       [ TeX-arg-eval completing-read
  173                      (TeX-argument-prompt optional nil "Table index")
  174                      '("questions" "pages") ] )
  175     '("partialbonuspointtable"
  176       [ TeX-arg-eval completing-read
  177                      (TeX-argument-prompt optional nil "Orientation")
  178                      '("v" "h") ]
  179       [ TeX-arg-eval completing-read
  180                      (TeX-argument-prompt optional nil "Table index")
  181                      '("questions" "pages") ] )
  182     '("pointtable"
  183       [ TeX-arg-eval completing-read
  184                      (TeX-argument-prompt optional nil "Orientation")
  185                      '("v" "h") ]
  186       [ TeX-arg-eval completing-read
  187                      (TeX-argument-prompt optional nil "Table index")
  188                      '("questions" "pages") ] )
  189     '("partialpointtable"
  190       [ TeX-arg-eval completing-read
  191                      (TeX-argument-prompt optional nil "Orientation")
  192                      '("v" "h") ]
  193       [ TeX-arg-eval completing-read
  194                      (TeX-argument-prompt optional nil "Table index")
  195                      '("questions" "pages") ] )
  196 
  197     '("subsubpart" [ "Points" ] (TeX-arg-literal " "))
  198     '("question"  ["Points"] (TeX-arg-literal " "))
  199     '("bonusquestion"  ["Points"] (TeX-arg-literal " "))
  200     '("extrafootheight"  [ TeX-arg-length "Extra height 1. page footer" ]
  201       (TeX-arg-length "Extra height footers"))
  202     '("titledquestion" "Title" ["Points"] LaTeX-exam-insert-label (TeX-arg-literal " "))
  203     '("ContinuedQuestion" 0)
  204     '("CorrectChoice" 0)
  205     '("CorrectChoiceEmphasis" 1)
  206     '("IncompleteQuestion" 0)
  207     '("SolutionEmphasis" 1)
  208     '("addpoints" 0)
  209     '("addquestionobject" 0)
  210     '("answerclearance" 1)
  211     '("answerline"  ["Points"] (TeX-arg-literal " "))
  212     '("begingradingrange" 1)
  213     '("bhpgword" 1)
  214     '("bhpword" 1)
  215     '("bhqword" 1)
  216     '("bhsword" 1)
  217     '("bhtword" 1)
  218     '("bonuspart" 0)
  219     '("bonuspointformat" 0)
  220     '("bonuspointname" 1)
  221     '("bonuspointpoints" 2)
  222     '("bonuspointsinrange" 0)
  223     '("bonuspointsofquestion" 1)
  224     '("bonuspointsonpage" 0)
  225     '("bonusqformat" 1)
  226     '("bonussubpart" 0)
  227     '("bonussubsubpart" 0)
  228     '("bonustitledquestion" "Title" ["Points"] LaTeX-exam-insert-label (TeX-arg-literal " "))
  229     '("bonustotalformat" 0)
  230     '("boxedpoints" 0)
  231     '("bracketedpoints" 0)
  232     '("bvpgword" 1)
  233     '("bvpword" 1)
  234     '("bvqword" 1)
  235     '("bvsword" 1)
  236     '("bvtword" 1)
  237     '("cancelspace" 0)
  238     '("cellwidth" 1)
  239     '("cfoot" 1)
  240     '("chbpword" 1)
  241     '("chead" 1)
  242     '("checkboxchar" 1)
  243     '("checkboxeshook" 0)
  244     '("checkedchar" 1)
  245     '("choice" (TeX-arg-literal " "))
  246     '("choicelabel" 0)
  247     '("choiceshook" 0)
  248     '("chpgword" 1)
  249     '("chpword" 1)
  250     '("chqword" 1)
  251     '("chsword" 1)
  252     '("chsword" 1)
  253     '("correctchoice" 0)
  254     '("correctchoiceemphasis" 1)
  255     '("covercfoot" 3)
  256     '("coverchead" 3)
  257     '("coverextrafootheight" 3)
  258     '("coverextraheadheight" 3)
  259     '("coverfirstpagefooter" 3)
  260     '("coverfirstpageheader" 3)
  261     '("coverfooter" 3)
  262     '("coverheader" 3)
  263     '("coverlfoot" 3)
  264     '("coverlhead" 3)
  265     '("coverrfoot" 3)
  266     '("coverrhead" 3)
  267     '("coverrunningfooter" 3)
  268     '("coverrunningheader" 3)
  269     '("cvbpword" 1)
  270     '("cvpgword" 1)
  271     '("cvpword" 1)
  272     '("cvqword" 1)
  273     '("cvsword" 1)
  274     '("cvtword" 1)
  275     '("dottedlinefillheight" 1)
  276     '("droppoints" 0)
  277     '("droptotalbonuspoints" 0)
  278     '("droptotalpoints" 0)
  279     '("endgradingrange" 1)
  280     '("extraheadheight" 1)
  281     '("extrawidth" 1)
  282     '("fillwithdottedlines" 1)
  283     '("fillwithlines" 1)
  284     '("firstpagefooter" 1)
  285     '("firstpagefootrule" 0)
  286     '("firstpageheader" 3)
  287     '("firstpageheadrule" 0)
  288     '("footer" 3)
  289     '("footrule" 0)
  290     '("framedsolutions" 0)
  291     '("fullwidth" 1)
  292     '("gradetablestretch" 0)
  293     '("greeknum" 0)
  294     '("half" 0)
  295     '("hpgword" 1)
  296     '("hpword" 1)
  297     '("hqword" 1)
  298     '("hsword" 1)
  299     '("htword" 1)
  300     '("ifcontinuation" 0)
  301     '("ifincomplete" 0)
  302     '("iflastpage" 0)
  303     '("ifprintanswers" 0)
  304     '("lfoot" 1)
  305     '("lhead" 1)
  306     '("linefillheight" 1)
  307     '("linefillthickness" 1)
  308     '("makeemptybox" 1)
  309     '("marginbonuspointname" 1)
  310     '("marginpointname" 1)
  311     '("marginpointsep" 1)
  312     '("marksnotpoints" 0)
  313     '("noaddpoints" 0)
  314     '("nobonusqformat" 1)
  315     '("noboxedpoints" 0)
  316     '("nobracketedpoints" 0)
  317     '("nocancelspace" 0)
  318     '("nomorequestions" 0)
  319     '("nopointsinmargin" 0)
  320     '("nopointsinrightmargin" 0)
  321     '("noprintanswers" 0)
  322     '("noqformat" 1)
  323     '("numbonuspoints" 0)
  324     '("numcoverpages" 0)
  325     '("numpages" 0)
  326     '("numparts" 0)
  327     '("numpoints" 0)
  328     '("numquestions" 0)
  329     '("numsubparts" 0)
  330     '("numsubsubparts" 0)
  331     '("oddeven" 2)
  332     '("partlabel" 0)
  333     '("partopsep" 0)
  334     '("partshook" 0)
  335     '("pointname" 1)
  336     '("pointpoints" 2)
  337     '("pointsdroppedatright" 0)
  338     '("pointsinmargin" 0)
  339     '("pointsinrightmargin" 0)
  340     '("pointsofquestion" 1)
  341     '("pointsonpage" 1)
  342     '("printanswers" 0)
  343     '("printselectedfalse" 0)
  344     '("printselectedtrue" 0)
  345     '("qformat" 1)
  346     '("questionlabel" 0)
  347     '("questionshook" 0)
  348     '("rfoot" 1)
  349     '("rhead" 1)
  350     '("rightpointsmargin" 0)
  351     '("roman" 0)
  352     '("romannumeral" 0)
  353     '("runningfooter" 3)
  354     '("runningfootrule" 0)
  355     '("runningheader" 3)
  356     '("runningheadrule" 0)
  357     '("settabletotalbonuspoints" 1)
  358     '("settabletotalpoints" 1)
  359     '("shadedsolutions" 0)
  360     '("solutiontitle" 0)
  361     '("subpartlabel" 0)
  362     '("subpartshook" 0)
  363     '("subsubpartlabel" 0)
  364     '("subsubpartshook" 0)
  365     '("thechoice" 0)
  366     '("themarginpoints" 0)
  367     '("thepartno" 0)
  368     '("thequestion" 0)
  369     '("thequestiontitle" 0)
  370     '("thesubpart" 0)
  371     '("thesubsubpart" 0)
  372     '("totalbonuspoints" 0)
  373     '("totalformat" 0)
  374     '("totalnumpages" 0)
  375     '("totalpoints" 0)
  376     '("unframedsolutions" 0)
  377     '("uplevel" 1)
  378     '("usehorizontalhalf" 0)
  379     '("useslantedhalf" 0)
  380     '("vpgword" 1)
  381     '("vpword" 1)
  382     '("vqword" 1)
  383     '("vsword" 1)
  384     '("vtword" 1)
  385     '("thepoints" 0)
  386     ;; ... more stuff here
  387     )
  388    (LaTeX-add-lengths "answerlinelength" "answerskip")
  389 
  390    ;; Fontification
  391    (when (and (featurep 'font-latex)
  392               (eq TeX-install-font-lock 'font-latex-setup))
  393      (font-latex-add-keywords '(("question"        "[")
  394                                 ("titledquestion"  "{[")
  395                                 ("subpart"         "[")
  396                                 ("subsubpart"      "["))
  397                               'textual)))
  398  LaTeX-dialect)
  399 
  400 ;;; exam.el ends here