From 9806c5dedd8a61daf666d35bc666c23321a359b3 Mon Sep 17 00:00:00 2001
From: Frank Fuhlbrück
Date: Wed, 26 Jan 2022 19:20:16 +0100
Subject: starterd merging beamer and normal version

---
 exercisesheets-beamer.sty | 212 +++++++++++++++++++++++++++++++++++++---------
 1 file changed, 173 insertions(+), 39 deletions(-)

(limited to 'exercisesheets-beamer.sty')

diff --git a/exercisesheets-beamer.sty b/exercisesheets-beamer.sty
index 4ba3690..990b973 100644
--- a/exercisesheets-beamer.sty
+++ b/exercisesheets-beamer.sty
@@ -45,6 +45,9 @@
 
 % configuration keys
 
+\newif\ifexsh@beamer
+\@ifclassloaded{beamer}{\exsh@beamertrue}{}
+
 \newif\ifexsh@patchenumerate\exsh@patchenumeratetrue
 \newif\ifexsh@savetasks
 \newif\ifexsh@solutions
@@ -53,11 +56,16 @@
 \newif\ifexsh@samplesolutions
 \newif\ifexsh@exnumsheet
 \newif\ifexsh@forcesample %force printing sample sol. of wrong type
+%For beamer only
+\ifexsh@beamer
 \newif\ifexsh@beamerwithheadline
 \newif\ifexsh@beameruseblocks
-\newif\ifexsh@beamersolution
 \newif\ifexsh@defersolutiontitle
 \newif\ifexsh@framed
+\fi
+%Also only true for beamer, but we want to use it elsewhere
+\newif\ifexsh@beamersolution
+%%
 \newif\ifexsh@gradingguides
 \newif\ifexsh@inplace
 \newif\ifexsh@sample
@@ -75,6 +83,33 @@
   \PackageError{exercisesheets}{
     beamercompatibility used twice}{}%
 \else
+\ifexsh@beamer
+  %currently we do nothing if beamer is loaded, 
+  %but this might change
+\else
+  %TODO:\only<>{A} -> {A} which breaks global effects of A
+  \let\pause\relax
+  \def\frame{}
+  \renewcommand{\frame}[1][]{}
+  \let\endframe\relax
+  \def\onslide<##1>{}
+  \def\only<##1>{}
+  \def\uncover<##1>{}
+  \def\visible<##1>{}
+  \def\invisible<##1>{}
+  \long\def\alt<##1>##2##3{##2}
+  \long\def\temporal<##1>##2##3##4{##3}
+  \def\uncover<##1>{}
+  \let\exsh@origitem\item
+  \def\exsh@ovrlitem<##1>{\exsh@origitem}
+  \def\item{\@ifnextchar<\exsh@ovrlitem\exsh@origitem}
+  \let\exsh@origitemize\itemize
+  \def\exsh@ovrlitemize[##1]{\exsh@origitemize}
+  \def\itemize{\@ifnextchar[\exsh@ovrlitemize\exsh@origitemize}
+  \let\exsh@origenumerate\enumerate
+  \def\exsh@ovrlenumerate[##1]{\exsh@origenumerate}
+  \def\enumerate{\@ifnextchar[\exsh@ovrlenumerate\exsh@origenumerate}
+\fi
   \exsh@beamercompatdonetrue
 \fi
 }
@@ -97,21 +132,6 @@
   number within sheet/.default=true,
   forcesample/.is if=exsh@forcesample,
   forcesample/.default=true,
-  filenameasexercisename/.is if=exsh@filenameasexercisename,
-  filenameasexercisename/.default=true,
-  beamerwithheadline/.is if=exsh@beamerwithheadline,
-  beamerwithheadline/.default=true,
-  beameruseblocks/.is if=exsh@beameruseblocks,
-  beameruseblocks/.default=true,
-  beamersolution/.is if=exsh@beamersolution,
-  beamersolution/.default=true,
-  defersolutiontitle/.is if=exsh@defersolutiontitle,
-  defersolutiontitle/.default=true,
-  framed/.is if=exsh@framed,
-  framed/.default=true,
-  beamercompatibility/.default={ignore},
-  beamercompatibility/.initial={ignore},
-  beamercompatibility/.code={\exsh@beamercompatibility},
   gradingguides/.is if=exsh@gradingguides,
   gradingguides/.default=true,
   only/.initial={-},
@@ -128,18 +148,55 @@
   sample/.default=true,
   showtodos/.is if=exsh@showtodos,
   showtodos/.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,
+  beamercompatibility/.default={ignore},
+  beamercompatibility/.initial={ignore},
+  beamercompatibility/.code={\exsh@beamercompatibility}
+}
+\ifexsh@beamer
+\pgfkeys{exsh,
+  beamerwithheadline/.is if=exsh@beamerwithheadline,
+  beamerwithheadline/.default=true,
+  beameruseblocks/.is if=exsh@beameruseblocks,
+  beameruseblocks/.default=true,
+  beamersolution/.is if=exsh@beamersolution,
+  beamersolution/.default=true,
+  defersolutiontitle/.is if=exsh@defersolutiontitle,
+  defersolutiontitle/.default=true,
+  framed/.is if=exsh@framed,
+  framed/.default=true,
+  beamersolution/.initial={false},
+  beamerwithheadline/.initial={false},
+  beameruseblocks/.initial={false},
+  defersolutiontitle/.initial={false},
+  framed/.initial={false},
 }
+\else
+\pgfkeys{exsh,
+  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},
+}
+\fi
 
-\providecommand{\@subject}{}
 % store title data for sheet headers
 \ifundef\subject{% \subject is only provided by KOMA classes
   \newcommand{\subject}[1]{}%
   \def\@subject{}%
 }{}
+% beamer has subject, but not \@subject:
+\providecommand{\@subject}{}
 \apptocmd{\subject}{\pgfkeys{/exsh/subject={#1}}}{}{}%
 \ifdefempty{\@subject}{
   \pgfkeys{exsh,subject/.initial={\PackageWarning{exercisesheets-beamer}{No \string\subject\space given}}}
@@ -194,11 +251,6 @@
   % additional exercise info
   name/.initial={},
   forcesample/.initial={false},
-  beamersolution/.initial={false},
-  beamerwithheadline/.initial={false},
-  beameruseblocks/.initial={false},
-  defersolutiontitle/.initial={false},
-  framed/.initial={false},
   firstline/.initial={},
   points/.initial={},
   oral/.style={/exsh/points=oral},oral/.value forbidden,
@@ -220,6 +272,13 @@
   exercisemark/.initial={},
   difficult/.style={/exsh/exercisemark=*},difficult/.value forbidden,
   savetasks/.initial=false,
+}
+%beamer specific options
+\ifexsh@beamer
+\pgfkeys{exsh,
+}
+\fi
+\pgfkeys{exsh,
   %
   % translatable strings
   strings/sheet/.initial={},
@@ -360,12 +419,14 @@
 % allow further keys to be set
 \def\exshset#1{\pgfkeys{exsh,#1}}
 
+\ifexsh@beamer
 \define@key{beamerframe}{t}[true]{% top
   \beamer@frametopskip=-2pt\relax%
   \beamer@framebottomskip=0pt plus 1fill\relax%
   \beamer@frametopskipautobreak=\beamer@frametopskip\relax%
   \beamer@framebottomskipautobreak=\beamer@framebottomskip\relax%
 }
+\fi
 
 % automatic language selection
 \AfterEndPreamble{%
@@ -573,6 +634,11 @@
 \listadd{\exsh@nonenums}{asparablank}
 \listadd{\exsh@nonenums}{inparablank}
 \listadd{\exsh@nonenums}{list}
+\ifexsh@beamer
+  \let\exsh@hyper@itemtrue\relax
+\else
+  \def\exsh@hyper@itemtrue{\@hyper@itemtrue}
+\fi
 \long\def\exsh@skipstuff#1{%
   \ifstrequal{#1}{\begin}{\exsh@skipstuff@begin}{%
     \ifstrequal{#1}{\end}{\exsh@skipstuff@end}{%
@@ -581,8 +647,7 @@
         \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}}{}}{}%
+              \ifstrequal{#1}{\item}{\ifdef{\@enumctr}{\exsh@hyper@itemtrue\refstepcounter{\@enumctr}}{}}{}%
               \pgfkeysvalueof{/exsh/custom skip macro}{#1}}}}}}}}%
 }
 \let\exshskipcontinue\exsh@skipstuff
@@ -663,6 +728,7 @@
 \exsh@skipstuff
 }
 
+\ifexsh@beamer
 \def\exsh@sheethead{%
   \pgfkeysgetvalue{/exsh/title}{\exsh@tmp}%
   \ifexsh@solutions
@@ -705,6 +771,54 @@
 %   \stepcounter{page}%
   \end{frame}
 }
+\else
+\def\exsh@sheethead{%
+  \pgfkeysgetvalue{/exsh/title}{\exsh@tmp}%
+  \ifexsh@solutions
+    \expandafter\edef\expandafter\exsh@tmp{\expandonce\exsh@tmp:\noexpand~\pgfkeysvalueof{/exsh/strings/solutions}}%
+  \fi
+  \refstepcounter{part}%
+  \part[\pgfkeysvalueof{/exsh/title}]{\normalsize
+    \pgfkeysvalueof{/exsh/sheet header font}\centering%
+    \begingroup\raggedright%
+      {\pgfkeysvalueof{/exsh/subject font}\pgfkeysvalueof{/exsh/subject}}\hfill
+      {\pgfkeysvalueof{/exsh/semester font}\pgfkeysvalueof{/exsh/semester}}\\
+      {\pgfkeysvalueof{/exsh/author font}\exsh@author}\hfill
+      {\pgfkeysvalueof{/exsh/date font}\pgfkeysvalueof{/exsh/date}}\\
+      \vskip\pgfkeysvalueof{/exsh/above sheet title skip}\relax%
+    \endgroup
+    \begingroup
+      \pgfkeysvalueof{/exsh/sheet title font}\exsh@tmp\\\unskip
+    \endgroup
+    \begingroup
+      \pgfkeysvalueof{/exsh/sheet header font}%
+      \ifexsh@solutions%
+        \ifdefvoid{\exsh@solutionsby}{}{%
+          \begingroup
+            \pgfkeysvalueof{/exsh/solutionsby font}%
+            \vskip\pgfkeysvalueof{/exsh/above solutionsby skip}\relax
+            \pgfkeysvalueof{/exsh/strings/solutionsby}~\exsh@solutionsby\\\unskip%
+          \endgroup
+        }%
+      \else
+      \fi
+      \ifthenelse{\equal{}{\pgfkeysvalueof{/exsh/note}}}{%
+      }{%
+        \ifbool{exsh@samplesolutions}{}{%
+          \begingroup
+            \pgfkeysvalueof{/exsh/sheet note font}%
+            \vskip\pgfkeysvalueof{/exsh/above sheet note skip}\relax
+            \pgfkeysvalueof{/exsh/note}\\\unskip%
+          \endgroup
+        }%
+      }%
+    \endgroup
+  }%
+  \unskip
+  \vskip\pgfkeysvalueof{/exsh/below sheet header skip}\relax
+  \stepcounter{page}%
+}
+\fi
 
 \ifdef{\othersectionslevelsformat}{%
   \renewcommand{\othersectionlevelsformat}[1]{%
@@ -850,9 +964,11 @@
       }%
     }%
   \fi
-  \clearpage
+  \ifexsh@beamer\clearpage\fi
 }
 \newcommand{\exsh@label}[2]{#1{#2}\leavevmode\ignorespaces}
+
+\ifexsh@beamer
 \newcommand{\exsh@startsection}[2][]{%
    \newpage
 %   \begin{block}{}
@@ -884,6 +1000,15 @@
     }
   \fi
 }%
+\else
+\newcommand{\exsh@startsection}[2][]{%
+  \@startsection{section}{1}{\z@}%
+  {\pgfkeysvalueof{/exsh/above exercise skip}}%
+  {1em}% afterskip corrected below
+  {\pgfkeysvalueof{/exsh/exercise title font}}%
+  [#1]{#2}%
+}%
+\fi
 
 
 \exshset{includeoverride/.style={}}
@@ -1025,6 +1150,13 @@
 }{%
   \unskip)%
 }
+
+
+\ifexsh@beamer
+  \let\exsh@postsolutionclear\clearpage
+\else
+  \let\exsh@postsolutionclear\par
+\fi
 \providecommand{\solution}{}
 \renewenvironment{solution}[1][]{%
   \pgfkeys{exsh,every solution,#1,solution font}%
@@ -1051,15 +1183,13 @@
   }{}%
   \next
 }{%
-%   \ifbool{exsh@framed}{\end{frame}}{}
   \ifbool{exsh@beamersolution}{}{%
     \ifthenelse{\equal{oral}{\pgfkeysvalueof{/exsh/points}}}{%
-      \ifbool{exsh@oralsolutions}{\clearpage}{}%
+      \ifbool{exsh@oralsolutions}{\exsh@postsolutionclear}{}%
     }{%
-      \ifbool{exsh@nonoralsolutions}{\clearpage}{}%
+      \ifbool{exsh@nonoralsolutions}{\exsh@postsolutionclear}{}%
     }%
   }%
-%   \fi
 }
 
 \def\exsh@solutiontitle#1{
@@ -1352,7 +1482,10 @@
 
 
 \ifluatex
-\usepackage{luacode}
+  \let\exsh@dlua\directlua
+\else
+  \def\exsh@dlua#1{}
+\fi
 
 %change only some catcodes to 
 \begingroup
@@ -1366,8 +1499,8 @@
 \catcode`\~=11
 \catcode`\\=11
 %% Expanded, when \catcode`\^^M=12 holds
-!global!long!def!exsh@start@Lexercise@#1\end{Lexercise}< %
-  !directlua<exsh_cur_exercise=exercise ({#1})> %
+!global!long!def!exsh@start@Lexercise#1\end{Lexercise}< %
+  !exsh@dlua<exsh_cur_exercise=exercise ({#1})> %
   !endgroup!end<Lexercise>%
 >
 !endgroup
@@ -1389,14 +1522,15 @@
 \catcode`\^^I=12
 \catcode`\^^J=12\catcode`\^^M=12\catcode`\\=11\endlinechar-1}
 
-\def\exsh@start@Lexercise{%
-  \exsh@lua@catcodesBG\exsh@start@Lexercise@}
-
 \newenvironment{Lexercise}{%
-  \exsh@start@Lexercise%
+  \exsh@lua@catcodesBG\exsh@start@Lexercise%
 }{%
-  \directlua{tex.print(exsh_cur_exercise)}
+  \ifluatex
+    \exsh@dlua{tex.print(exsh_cur_exercise)}%
+  \else
+    Lexercise needs Lua\LaTeX!
+  \fi
 }
 
-\directlua{dofile("lexercise.lua")}
-\fi
+\exsh@dlua{dofile("exsh_lexercise.lua")}
+
-- 
cgit v1.2.3

