aboutsummaryrefslogtreecommitdiff
path: root/README
blob: dd02b18252dbe05f5a3c76f601fb2eb4574c2a80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
The exercisesheets package

The exercisesheets package provides a way to typeset exercise sheets as used in
university courses. It evolved from a set of macros an environments that were
finally combined into this package.

Copyright (c) 2008-2022 Sebastian Kuhnert, Frank Fuhlbrück
Licence: LPPL 1.3c or later
Current Maintainer: Frank Fuhlbrück

Files belonging to this package:
exercisesheets.sty  The package itself
exercisesheets.tex  Documentation source
exercisesheets.el   Emacs integration (outdated)
README              This file
Examples            Folder with example file
0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
;;; exercisesheets.el --- AUCTeX style for `exercisesheets.sty'

;; Author: Sebastian Kuhnert <mail@sebastian-kuhnert.de>
;; 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