From 7b299cb87dfb293aecd1963232f822d7aeb2c5b5 Mon Sep 17 00:00:00 2001
From: Sebastian Kuhnert
Date: Wed, 21 Oct 2009 15:05:22 +0000
Subject: exercisesheets.sty: add support for optional exercises and bonus
 points

---
 exercisesheets.sty | 112 +++++++++++++++++++++++++++++++++++------------------
 1 file changed, 74 insertions(+), 38 deletions(-)

(limited to 'exercisesheets.sty')

diff --git a/exercisesheets.sty b/exercisesheets.sty
index 7b3b5e6..22d2488 100644
--- a/exercisesheets.sty
+++ b/exercisesheets.sty
@@ -84,6 +84,10 @@
   firstline/.initial={},
   points/.initial={},
   oral/.style={/exsh/points=oral},oral/.value forbidden,
+  bonus/.style={/exsh/strings/points=\pgfkeysvalueof{/exsh/strings/bonus points},
+    /exsh/strings/point=\pgfkeysvalueof{/exsh/strings/bonus point}},
+  pointsinfo/.initial={},
+  optional/.style={/exsh/pointsinfo=\pgfkeysvalueof{/exsh/strings/optional}},optional/.value forbidden,
   %
   % translatable strings
   strings/sheet/.initial={},
@@ -98,37 +102,46 @@
   strings/oral/.initial={},
   strings/point/.initial={},
   strings/points/.initial={},
+  strings/bonus point/.initial={},
+  strings/bonus points/.initial={},
+  strings/optional/.initial={},
   %
   % languages: predifined string sets
   language/.is choice,
   language/german/.code={%
-    \exsh@deforprovide{/exsh/strings/sheet}      {\"Ubungsblatt}%
-    \exsh@deforprovide{/exsh/strings/sheets}     {\"Ubungsbl\"atter}%
-    \exsh@deforprovide{/exsh/strings/solutions}  {L\"osungsvorschl\"age}%
-    \exsh@deforprovide{/exsh/strings/solutionsby}{L\"osungen von}%
-    \exsh@deforprovide{/exsh/strings/exercise}   {Aufgabe}%
-    \exsh@deforprovide{/exsh/strings/solution}   {L\"osung}%
-    \exsh@deforprovide{/exsh/strings/idea}       {L\"osungsidee}%
-    \exsh@deforprovide{/exsh/strings/hint}       {Hinweis}%
-    \exsh@deforprovide{/exsh/strings/remark}     {Bemerkung}%
-    \exsh@deforprovide{/exsh/strings/oral}       {m\"undlich}%
-    \exsh@deforprovide{/exsh/strings/point}      {Punkt}%
-    \exsh@deforprovide{/exsh/strings/points}     {Punkte}%
+    \exsh@deforprovide{/exsh/strings/sheet}       {\"Ubungsblatt}%
+    \exsh@deforprovide{/exsh/strings/sheets}      {\"Ubungsbl\"atter}%
+    \exsh@deforprovide{/exsh/strings/solutions}   {L\"osungsvorschl\"age}%
+    \exsh@deforprovide{/exsh/strings/solutionsby} {L\"osungen von}%
+    \exsh@deforprovide{/exsh/strings/exercise}    {Aufgabe}%
+    \exsh@deforprovide{/exsh/strings/solution}    {L\"osung}%
+    \exsh@deforprovide{/exsh/strings/idea}        {L\"osungsidee}%
+    \exsh@deforprovide{/exsh/strings/hint}        {Hinweis}%
+    \exsh@deforprovide{/exsh/strings/remark}      {Bemerkung}%
+    \exsh@deforprovide{/exsh/strings/oral}        {m\"undlich}%
+    \exsh@deforprovide{/exsh/strings/point}       {Punkt}%
+    \exsh@deforprovide{/exsh/strings/points}      {Punkte}%
+    \exsh@deforprovide{/exsh/strings/bonus point} {Zusatzpunkt}%
+    \exsh@deforprovide{/exsh/strings/bonus points}{Zusatzpunkte}%
+    \exsh@deforprovide{/exsh/strings/optional}    {optional}%
   },language/german/.value forbidden,
   language/ngerman/.style={/exsh/language/german=#1},
   language/english/.code={%
-    \exsh@deforprovide{/exsh/strings/sheet}      {Exercise Sheet}%
-    \exsh@deforprovide{/exsh/strings/sheets}     {Exercise Sheets}%
-    \exsh@deforprovide{/exsh/strings/solutions}  {Suggested Solutions}%
-    \exsh@deforprovide{/exsh/strings/solutionsby}{Solutions by}%
-    \exsh@deforprovide{/exsh/strings/exercise}   {Exercise}%
-    \exsh@deforprovide{/exsh/strings/solution}   {Solution}%
-    \exsh@deforprovide{/exsh/strings/idea}       {Idea for solution}%
-    \exsh@deforprovide{/exsh/strings/hint}       {Hint}%
-    \exsh@deforprovide{/exsh/strings/remark}     {Remark}%
-    \exsh@deforprovide{/exsh/strings/oral}       {oral}%
-    \exsh@deforprovide{/exsh/strings/point}      {point}%
-    \exsh@deforprovide{/exsh/strings/points}     {points}%
+    \exsh@deforprovide{/exsh/strings/sheet}       {Exercise Sheet}%
+    \exsh@deforprovide{/exsh/strings/sheets}      {Exercise Sheets}%
+    \exsh@deforprovide{/exsh/strings/solutions}   {Suggested Solutions}%
+    \exsh@deforprovide{/exsh/strings/solutionsby} {Solutions by}%
+    \exsh@deforprovide{/exsh/strings/exercise}    {Exercise}%
+    \exsh@deforprovide{/exsh/strings/solution}    {Solution}%
+    \exsh@deforprovide{/exsh/strings/idea}        {Idea for solution}%
+    \exsh@deforprovide{/exsh/strings/hint}        {Hint}%
+    \exsh@deforprovide{/exsh/strings/remark}      {Remark}%
+    \exsh@deforprovide{/exsh/strings/oral}        {oral}%
+    \exsh@deforprovide{/exsh/strings/point}       {point}%
+    \exsh@deforprovide{/exsh/strings/points}      {points}%
+    \exsh@deforprovide{/exsh/strings/bonus point} {bonus point}%
+    \exsh@deforprovide{/exsh/strings/bonus points}{bonus points}%
+    \exsh@deforprovide{/exsh/strings/optional}    {optional}%
   },language/english/.value forbidden,
   language/.unknown/.code={%
     \PackageWarning{exercisesheets}{Unknown language \pgfkeyscurrentname.
@@ -464,16 +477,27 @@
     \def\exsh@points{}%
     \def\exsh@shortpoints{}%
   }{%
-    \ifthenelse{\equal{oral}{\pgfkeysvalueof{/exsh/points}}}{%
-      \edef\exsh@points{\pgfkeysvalueof{/exsh/strings/oral}}%
+    \ifthenelse{\equal{}{\pgfkeysvalueof{/exsh/points}}}{%
+      \edef\exsh@points{\pgfkeysvalueof{/exsh/pointsinfo}}%
     }{%
-      \ifthenelse{\equal{1}{\pgfkeysvalueof{/exsh/points}}}{%
-        \edef\exsh@points{1 \pgfkeysvalueof{/exsh/strings/point}}%
+      \ifthenelse{\equal{oral}{\pgfkeysvalueof{/exsh/points}}}{%
+        \edef\exsh@points{\pgfkeysvalueof{/exsh/strings/oral}}%
       }{%
-        \edef\exsh@points{\pgfkeysvalueof{/exsh/points} \pgfkeysvalueof{/exsh/strings/points}}%
+        \ifthenelse{\equal{1}{\pgfkeysvalueof{/exsh/points}}}{%
+          \edef\exsh@points{1 \pgfkeysvalueof{/exsh/strings/point}}%
+        }{%
+          \edef\exsh@points{\pgfkeysvalueof{/exsh/points} \pgfkeysvalueof{/exsh/strings/points}}%
+        }%
+      }%
+      \ifthenelse{\equal{}{\pgfkeysvalueof{/exsh/pointsinfo}}}{}{%
+        \edef\exsh@points{\expandonce\exsh@points, \pgfkeysvalueof{/exsh/pointsinfo}}%
       }%
     }%
-    \edef\exsh@shortpoints{ (\expandonce\exsh@points)}%
+    \ifthenelse{\equal{}{\exsh@points}}{%
+      \def\exsh@shortpoints{}%
+    }{%
+      \edef\exsh@shortpoints{ (\expandonce\exsh@points)}%
+    }%
     \preto\exsh@points{\enskip\hfill\bgroup%
       \pgfkeysvalueof{/exsh/points font}}%
     \appto\exsh@points{\egroup}%
@@ -574,19 +598,31 @@
   \PackageWarning{exercisesheets}{Obsolete \string\pun[] macro used. Please use
     something\MessageBreak like \string\points{10} or \string\points{oral} instead.}{}%
   \exsh@subexpoints{#1}%
-} \newcommand{\points}[1]{%
-  \ifthenelse{\equal{#1}{oral}}{%
+}
+\newcommand{\points}[2][]{%
+  \exshset{pointsinfo={},#1}%
+  \ifthenelse{\equal{}{\pgfkeysvalueof{/exsh/pointsinfo}}}{%
+    \def\exsh@tmp{}%
+  }{%
+    \def\exsh@tmp{, \pgfkeysvalueof{/exsh/pointsinfo}}%
+  }%
+  \ifthenelse{\equal{#2}{oral}}{%
     \exshset{oral}%
-    \exsh@subexpoints{\pgfkeysvalueof{/exsh/strings/oral}}%
+    \exsh@subexpoints{\pgfkeysvalueof{/exsh/strings/oral}\exsh@tmp}%
   }{%
-    \exshset{points=#1}%
-    \ifthenelse{\equal{#1}{1}}{%
-      \exsh@subexpoints{1~\pgfkeysvalueof{/exsh/strings/point}}%
+    \exshset{points=#2}%
+    \ifthenelse{\equal{#2}{}}{%
+      \exsh@subexpoints{\pgfkeysvalueof{/exsh/pointsinfo}}%
     }{%
-      \exsh@subexpoints{#1~\pgfkeysvalueof{/exsh/strings/points}}%
+      \ifthenelse{\equal{#2}{1}}{%
+        \exsh@subexpoints{1~\pgfkeysvalueof{/exsh/strings/point}\exsh@tmp}%
+      }{%
+        \exsh@subexpoints{#2~\pgfkeysvalueof{/exsh/strings/points}\exsh@tmp}%
+      }%
     }%
   }%
-} \newcommand{\exsh@subexpoints}[1]{%
+}
+\newcommand{\exsh@subexpoints}[1]{%
   \unskip\nobreak\space\nobreak\hspace*{\fill}\allowbreak\hspace*{\fill}%
   {\pgfkeysvalueof{/exsh/points font}\mbox{(#1)}}%
 }
-- 
cgit v1.2.3

