From d37de423d8f280b26acac10c8141df9c4e2a730d Mon Sep 17 00:00:00 2001
From: Frank Fuhlbrück
Date: Mon, 29 Oct 2018 11:54:28 +0100
Subject: option to skip individual exercises

---
 exercisesheets.sty | 107 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 67 insertions(+), 40 deletions(-)

(limited to 'exercisesheets.sty')

diff --git a/exercisesheets.sty b/exercisesheets.sty
index 33ce1f1..7e6bac8 100644
--- a/exercisesheets.sty
+++ b/exercisesheets.sty
@@ -47,7 +47,10 @@
 \newif\ifexsh@solutions
 \newif\ifexsh@oralsolutions
 \newif\ifexsh@nonoralsolutions
+\newif\ifexsh@samplesolutions
 \newif\ifexsh@inplace
+\newif\ifexsh@sample
+\newif\ifexsh@hide%currently only set via sample in exercise env.
 \newif\ifexsh@pointsfloatright
 \newif\ifexsh@bonus
 \newif\ifexsh@abbrev
@@ -57,6 +60,9 @@
   solutions/true/.code=\exsh@solutionstrue\exsh@oralsolutionstrue\exsh@nonoralsolutionstrue,
   solutions/oral/.code=\exsh@solutionstrue\exsh@oralsolutionstrue\exsh@nonoralsolutionsfalse,
   solutions/nonoral/.code=\exsh@solutionstrue\exsh@oralsolutionsfalse\exsh@nonoralsolutionstrue,
+  solutions/sample nonoral/.code=\exsh@solutionstrue\exsh@oralsolutionsfalse\exsh@nonoralsolutionstrue\exsh@samplesolutionstrue,
+  solutions/sample oral/.code=\exsh@solutionstrue\exsh@oralsolutionstrue\exsh@nonoralsolutionsfalse\exsh@samplesolutionstrue,
+  solutions/sample all/.code=\exsh@solutionstrue\exsh@oralsolutionstrue\exsh@nonoralsolutionstrue\exsh@samplesolutionstrue,
   solutions/false/.code=\exsh@solutionsfalse\exsh@oralsolutionsfalse\exsh@nonoralsolutionsfalse,
   solutions/.default=true,
   only/.initial={-},
@@ -66,6 +72,8 @@
   bonus/.default=true,
   inplace/.is if=exsh@inplace,
   inplace/.default=true,
+  sample/.is if=exsh@sample,
+  sample/.default=true,
   pointsfloatright/.is if=exsh@pointsfloatright,
   pointsfloatright/.default=true,
   abbrev/.is if=exsh@abbrev,
@@ -122,6 +130,7 @@
   points/.initial={},
   oral/.style={/exsh/points=oral},oral/.value forbidden,
   inplace/.initial={false},
+  sample/.initial={false},
   pointsfloatright/.initial={false},
   bonus/.initial={false},
   nobonus/.style={/exsh/bonus=false},nobonus/.value forbidden,
@@ -440,7 +449,7 @@
     \exsh@sheethead
   \else
     \refstepcounter{part}%
-    \expandafter\exsh@skipsheet
+    \def\exsh@skipwhat{sheet}\expandafter\exsh@skipstuff
   \fi
 }{%
   \par
@@ -464,20 +473,25 @@
 \listadd{\exsh@nonenums}{asparablank}
 \listadd{\exsh@nonenums}{inparablank}
 \listadd{\exsh@nonenums}{list}
-\long\def\exsh@skipsheet#1{%
-  \ifstrequal{#1}{\begin}{\exsh@skipsheet@begin}{%
-    \ifstrequal{#1}{\end}{\exsh@skipsheet@end}{%
-      \ifstrequal{#1}{\label}{\exsh@skipsheet@label}{%
-        \ifstrequal{#1}{\input}{\exsh@skipsheet@input}{%
-          \ifstrequal{#1}{\exsh@skipsheet@endfile}{\currfile@pop\exsh@skipsheet}{%
-            \ifstrequal{#1}{\setcounter}{\expandafter\exsh@skipsheet\setcounter}{%
+\long\def\exsh@skipstuff#1{%
+  \ifstrequal{#1}{\begin}{\exsh@skipstuff@begin}{%
+    \ifstrequal{#1}{\end}{\exsh@skipstuff@end}{%
+      \ifstrequal{#1}{\label}{\exsh@skipstuff@label}{%
+        \ifstrequal{#1}{\input}{\exsh@skipstuff@input}{%
+          \ifstrequal{#1}{\exsh@skipstuff@endfile}{\currfile@pop\exsh@skipstuff}{%
+            \ifstrequal{#1}{\setcounter}{\expandafter\exsh@skipstuff\setcounter}{%
               \ifstrequal{#1}{\item}{\ifdef{\@enumctr}{\@hyper@itemtrue\refstepcounter{\@enumctr}}{}}{}%
-              \exsh@skipsheet}}}}}}%
-}
-\def\exsh@skipsheet@end#1{%
-  \ifstrequal{#1}{sheet}{\end{sheet}}{\endgroup\exsh@skipsheet}%
+              \exsh@skipstuff}}}}}}%
+}
+\def\exsh@skipstuff@end#1{%
+  \expandafter\ifstrequal\expandafter{\exsh@skipwhat}{#1}{%
+    \expandafter\end\expandafter{\exsh@skipwhat}%
+    \let\exsh@skipwhat\relax%
+  }{
+    \endgroup\exsh@skipstuff%
+  }%
 }
-\def\exsh@skipsheet@begin#1{%
+\def\exsh@skipstuff@begin#1{%
   \begingroup
   \ifstrequal{#1}{exercise}{\refstepcounter{section}%
     % automatic label for the first exercise in every included file
@@ -487,15 +501,15 @@
         \label{ex:\currfilebase}}}%
   }{}%
   \ifinlist{#1}{\exsh@enums}{%
-    \exsh@skipsheet@beginenum
+    \exsh@skipstuff@beginenum
   }{%
     \ifinlist{#1}{\exsh@nonenums}{%
       \undef\@enumctr
     }{}%
-    \exsh@skipsheet
+    \exsh@skipstuff
   }%
 }
-\def\exsh@skipsheet@beginenum{%
+\def\exsh@skipstuff@beginenum{%
   \ifnum\@enumdepth>\thr@@
     \@toodeep
   \else
@@ -504,12 +518,12 @@
     \setcounter{\@enumctr}{0}%
   \fi
   \@ifundefined{@enumlabel@}{%
-    \exsh@skipsheet
+    \exsh@skipstuff
   }{%
-    \@ifnextchar[{\@enumlabel@{\exsh@skipsheet}[}{\exsh@skipsheet}%
+    \@ifnextchar[{\@enumlabel@{\exsh@skipstuff}[}{\exsh@skipstuff}%
   }%
 }
-\def\exsh@skipsheet@label#1{%
+\def\exsh@skipstuff@label#1{%
   % Locally modify \protected@write to use \immediate\write instead.
   % This is needed to include labels after the last shipout in the aux file.
   \begingroup
@@ -521,13 +535,13 @@
   }%
   \label{#1}%
   \endgroup
-  \exsh@skipsheet
+  \exsh@skipstuff
 }
-\def\exsh@skipsheet@input#1{%
+\def\exsh@skipstuff@input#1{%
   \CatchFileDef{\exsh@inputfilecontent}{#1}{}%
   \currfile@push
   \currfile@set{#1}%
-  \expandafter\exsh@skipsheet\exsh@inputfilecontent\exsh@skipsheet@endfile
+  \expandafter\exsh@skipstuff\exsh@inputfilecontent\exsh@skipstuff@endfile
 }
 
 \def\exsh@sheethead{%
@@ -562,11 +576,13 @@
       \fi
       \ifthenelse{\equal{}{\pgfkeysvalueof{/exsh/note}}}{%
       }{%
-        \begingroup
-          \pgfkeysvalueof{/exsh/sheet note font}%
-          \vskip\pgfkeysvalueof{/exsh/above sheet note skip}\relax
-          \pgfkeysvalueof{/exsh/note}\\\unskip%
-        \endgroup
+        \ifbool{exsh@samplesolutions}{}{%
+          \begingroup
+            \pgfkeysvalueof{/exsh/sheet note font}%
+            \vskip\pgfkeysvalueof{/exsh/above sheet note skip}\relax
+            \pgfkeysvalueof{/exsh/note}\\\unskip%
+          \endgroup
+        }%
       }%
     \endgroup
   }%
@@ -650,19 +666,24 @@
   }%
   \refstepcounter{section}%
   \edef\exsh@tmp{[\pgfkeysvalueof{/exsh/strings/exercise} \arabic{section}\exsh@shortexname\expandonce\exsh@shortpoints]}%
-  \expandafter\exsh@startsection\exsh@tmp{\noindent%
-    \hbox to 0pt{\hss\pgfkeysvalueof{/exsh/exercisemark}}%
-    \pgfkeysvalueof{/exsh/strings/exercise}~\arabic{section}\exsh@exname\exsh@firstline\expandonce\exsh@points}%
-  \unskip\vskip\pgfkeysvalueof{/exsh/below exercise title skip}\relax
-  \@afterindentfalse
-  % automatic label for the first exercise in every included file
-  \ifthenelse{\equal{\jobname}{\currfilebase}}{}{%
-    \ifcsdef{exsh@autolabel@\currfilebase}{}{%
-      \csdef{exsh@autolabel@\currfilebase}{}%
-      \label{ex:\currfilebase}}}%
-  % Use \leavevmode to ensure proper distances above environments that start
-  % with a new \par. Make sure that a \label does not mess up the layout.
-  \@ifnextchar\label{\exsh@label}{\leavevmode\ignorespaces}%
+  \ifbool{exsh@samplesolutions}{\ifbool{exsh@sample}{\exsh@hidefalse}{\exsh@hidetrue}}{\exsh@hidefalse}%
+  \ifbool{exsh@hide}{%
+    \def\exsh@skipwhat{exercise}\expandafter\exsh@skipstuff%
+  }{%
+    \expandafter\exsh@startsection\exsh@tmp{\noindent%
+      \hbox to 0pt{\hss\pgfkeysvalueof{/exsh/exercisemark}}%
+      \pgfkeysvalueof{/exsh/strings/exercise}~\arabic{section}\exsh@exname\exsh@firstline\expandonce\exsh@points}%
+    \unskip\vskip\pgfkeysvalueof{/exsh/below exercise title skip}\relax
+    \@afterindentfalse
+    % automatic label for the first exercise in every included file
+    \ifthenelse{\equal{\jobname}{\currfilebase}}{}{%
+      \ifcsdef{exsh@autolabel@\currfilebase}{}{%
+        \csdef{exsh@autolabel@\currfilebase}{}%
+        \label{ex:\currfilebase}}}%
+    % Use \leavevmode to ensure proper distances above environments that start
+    % with a new \par. Make sure that a \label does not mess up the layout.
+    \@ifnextchar\label{\exsh@label}{\leavevmode\ignorespaces}%
+  }%
 }{}
 \newcommand{\exsh@label}[2]{#1{#2}\leavevmode\ignorespaces}
 \newcommand{\exsh@startsection}[2][]{%
@@ -844,3 +865,9 @@
 \newcommand{\ifnonoralsolutions}[2]{%
   \ifbool{exsh@nonoralsolutions}{#1}{#2}%
 }
+\newcommand{\ifsamplesolutions}[2]{%
+  \ifbool{exsh@samplesolutions}{#1}{#2}%
+}
+\newcommand{\samplehide}[1]{%
+  \ifbool{exsh@samplesolutions}{}{#1}%
+}
-- 
cgit v1.2.3

