From f3fecd9f8ba9c426544015305b24a11a2e8d9ec5 Mon Sep 17 00:00:00 2001
From: Frank Fuhlbrück
Date: Wed, 6 Oct 2021 12:23:21 +0200
Subject: Option for enabling beamer headers

---
 exercisesheets.sty | 80 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 73 insertions(+), 7 deletions(-)

(limited to 'exercisesheets.sty')

diff --git a/exercisesheets.sty b/exercisesheets.sty
index 47c0896..c066a94 100644
--- a/exercisesheets.sty
+++ b/exercisesheets.sty
@@ -18,8 +18,8 @@
 %\NeedsTeXFormat{LaTeX2e}[1994/12/01]
 
 % don't forget to update the version and date in exercisesheets.tex
-\def\exsh@version{0.7}
-\def\exsh@date{2020/10/11}
+\def\exsh@version{0.8}
+\def\exsh@date{2021/10/06}
 
 \ProvidesPackage{exercisesheets}[\exsh@date\space\exsh@version\space Typesetting of exercise sheets]
 \message{`Typesetting of exercise sheets' \exsh@version\space <\exsh@date>}
@@ -56,6 +56,7 @@
 \newif\ifexsh@pointsfloatright
 \newif\ifexsh@bonus
 \newif\ifexsh@abbrev
+\newif\ifexsh@filenameasexercisename
 
 \pgfkeys{/exsh/.is family,/exsh,
   solutions/.is choice,
@@ -73,24 +74,32 @@
   gradingguides/.default=true,
   only/.initial={-},
   all/.style={/exsh/only={-}},all/.value forbidden,
-  solutionsby/.code={\def\exsh@solutionsby{#1}},solutionsby/.value required,
+  solutionsby/.code={\def\exsh@solutionsby{#1}},
+  solutionsby/.value required,
+  exercisespath/.code={\def\exsh@exercisespath{#1}},
+  exercisespath/.value required,
   bonus/.is if=exsh@bonus,
   bonus/.default=true,
   inplace/.is if=exsh@inplace,
   inplace/.default=true,
   sample/.is if=exsh@sample,
   sample/.default=true,
+  filenameasexercisename/.is if=exsh@filenameasexercisename,
+  filenameasexercisename/.default=true,
   pointsfloatright/.is if=exsh@pointsfloatright,
   pointsfloatright/.default=true,
   abbrev/.is if=exsh@abbrev,
   abbrev/.default=true,
   %options from exercisesheets-beamer are ignored
+  beamerwithheadline/.default={ignore},
+  beamerwithheadline/.initial={ignore},
   beamersolution/.default={ignore},
   beamersolution/.initial={ignore},
   defersolutiontitle/.default={ignore},
   defersolutiontitle/.initial={ignore},
   framed/.default={ignore},
   framed/.initial={ignore},
+  framed/.code={\let\newframe\relax},
 }
 
 % store title data for sheet headers
@@ -150,6 +159,7 @@
   oral/.style={/exsh/points=oral},oral/.value forbidden,
   inplace/.initial={false},
   sample/.initial={false},
+  filenameasexercisename/.initial={false},
   pointsfloatright/.initial={false},
   bonus/.initial={false},
   nobonus/.style={/exsh/bonus=false},nobonus/.value forbidden,
@@ -504,12 +514,13 @@
 \long\def\exsh@skipstuff#1{%
   \ifstrequal{#1}{\begin}{\exsh@skipstuff@begin}{%
     \ifstrequal{#1}{\end}{\exsh@skipstuff@end}{%
+     \ifstrequal{#1}{\includeexercise}{\exsh@skipstuff@incex}{%
       \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}}{}}{}%
-              \pgfkeysvalueof{/exsh/custom skip macro}{#1}}}}}}}%
+              \pgfkeysvalueof{/exsh/custom skip macro}{#1}}}}}}}}%
 }
 \let\exshskipcontinue\exsh@skipstuff
 \long\def\exsh@skipcustomstuff#1{\exshskipcontinue}
@@ -528,7 +539,7 @@
     \ifthenelse{\equal{\jobname}{\currfilebase}}{}{%
       \ifcsdef{exsh@autolabel@\currfilebase}{}{%
         \csdef{exsh@autolabel@\currfilebase}{}%
-        \label{ex:\currfilebase}}}%
+        \exsh@autolabel{ex:\currfilebase}}}%
   }{}%
   \ifinlist{#1}{\exsh@enums}{%
     \exsh@skipstuff@beginenum
@@ -574,6 +585,21 @@
   \expandafter\exsh@skipstuff\exsh@inputfilecontent\exsh@skipstuff@endfile
 }
 
+\def\exsh@skipstuff@incex{%
+  \@ifstar\exsh@skipstuff@incex@@\exsh@skipstuff@incex@%
+}
+
+\newcommand{\exsh@skipstuff@incex@}[2][]{%
+\exsh@skipstuff\input{%
+  \ifdefvoid{\exsh@exercisespath}{}{\exsh@exercisespath/}#2}%
+}
+
+\newcommand{\exsh@skipstuff@incex@@}[2][]{%
+\refstepcounter{section}
+\exsh@autolabel{ex:#2}
+\exsh@skipstuff
+}
+
 \def\exsh@sheethead{%
   \pgfkeysgetvalue{/exsh/title}{\exsh@tmp}%
   \ifexsh@solutions
@@ -628,9 +654,14 @@
     {\csname the#1\endcsname\autodot\enskip}}%
 }{}
 
+%Do nout use \let here as \label may change before its use
+\def\exsh@autolabel{\label}
+
 \newenvironment*{exercise}[1][]{%
   % TODO: \edef is not safe with luatex and umlauts, only fixed for "oral" for now
-  \pgfkeys{exsh,every exercise,#1}%
+  % TODO: check whether the TODO above is still relevant
+  %\edef seams to work fine with lualatex from TeXLive 2020
+  \pgfkeys{exsh,every exercise,#1,includeoverride}%
   \ifthenelse{\equal{}{\pgfkeysvalueof{/exsh/points}}}{%
     \def\exsh@points{}%
     \def\exsh@shortpoints{}%
@@ -709,7 +740,7 @@
     \ifthenelse{\equal{\jobname}{\currfilebase}}{}{%
       \ifcsdef{exsh@autolabel@\currfilebase}{}{%
         \csdef{exsh@autolabel@\currfilebase}{}%
-        \label{ex:\currfilebase}}}%
+        \exsh@autolabel{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}%
@@ -724,6 +755,41 @@
   [#1]{#2}%
 }%
 
+
+\exshset{includeoverride/.style={}}
+\def\includeexercise{%
+  \@ifstar\exsh@includeexercise@\exsh@includeexercise%
+}
+
+\newcommand{\exsh@includeexercise}[2][]{%
+\ifbool{exsh@filenameasexercisename}{%
+  \exshset{includeoverride/.style={name={#2},#1}}%
+}{%
+  \exshset{includeoverride/.style={#1}}%
+}%
+\input{\ifdefvoid{\exsh@exercisespath}{}{\exsh@exercisespath/}#2}
+\exshset{includeoverride/.style={}}
+}
+
+\newcommand{\exsh@includeexercise@}[2][]{%
+\ifbool{exsh@filenameasexercisename}{%
+  \exshset{includeoverride/.style={name={#2},#1}}%
+}{%
+  \exshset{includeoverride/.style={#1}}%
+}%
+\begingroup
+%auto labelling is still allowed, but other labels are forbidden
+%here we may use \let as the definition is close to its use
+\let\exsh@autolabel\label
+\def\label##1{%
+  \PackageError{exercisesheets}{\string\label{##1}\space
+  inside \string\includeexercise*}{}%
+}
+\input{\ifdefvoid{\exsh@exercisespath}{}{\exsh@exercisespath/}#2}
+\endgroup
+\exshset{includeoverride/.style={}}
+}
+
 \AfterPackage*{varioref}{
   \labelformat{section}{\pgfkeysvalueof{/exsh/strings/exercise}~\arabic{section}}
   \labelformat{enumi}{\arabic{section}.\alph{enumi}}
-- 
cgit v1.2.3

