From b216df0bff1f24aa24e8039daea663dc64e3c1bd Mon Sep 17 00:00:00 2001
From: Frank Fuhlbrück
Date: Wed, 9 Feb 2022 13:46:46 +0100
Subject: inlcudelexercise at skipping it

---
 exercisesheets.sty | 131 ++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 100 insertions(+), 31 deletions(-)

(limited to 'exercisesheets.sty')

diff --git a/exercisesheets.sty b/exercisesheets.sty
index d096e54..501251a 100644
--- a/exercisesheets.sty
+++ b/exercisesheets.sty
@@ -659,15 +659,16 @@
 \long\def\exsh@skipstuff#1{%
    \exsh@ifsingletoken{#1}{%
     \ifstrequal{#1}{\begin}{\exsh@skipstuff@begin}{%
-      \ifstrequal{#1}{\end}{\exsh@skipstuff@end}{%
+     \ifstrequal{#1}{\end}{\exsh@skipstuff@end}{%
       \ifstrequal{#1}{\includeexercise}{\exsh@skipstuff@incex}{%
+       \ifstrequal{#1}{\includeLexercise}{\exsh@skipstuff@incLex}{%
         \ifstrequal{#1}{\label}{\exsh@skipstuff@label}{%
         \ifstrequal{#1}{\subtask}{\exsh@skipstuff@subtask}{%
           \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}{\exsh@hyper@itemtrue\refstepcounter{\@enumctr}}{}}{}%
-                \pgfkeysvalueof{/exsh/custom skip macro}{#1}}}}}}}}}%
+                \pgfkeysvalueof{/exsh/custom skip macro}{#1}}}}}}}}}}%
   }{%
     \exsh@skipstuff#1%
   }%
@@ -745,16 +746,32 @@
 }
 
 \newcommand{\exsh@skipstuff@incex@}[2][]{%
-\exsh@skipstuff\input{%
-  \ifdefvoid{\exsh@exercisespath}{}{\exsh@exercisespath/}#2}%
+  \exsh@skipstuff\input{%
+    \ifdefvoid{\exsh@exercisespath}{}{\exsh@exercisespath/}#2}%
 }
 
 \newcommand{\exsh@skipstuff@incex@@}[2][]{%
-\refstepcounter{section}
-\exsh@autolabel{ex:#2}
-\exsh@skipstuff
+  \refstepcounter{section}
+  \exsh@autolabel{ex:#2}
+  \exsh@skipstuff
+}
+
+\def\exsh@skipstuff@incLex{%
+  \@ifstar\exsh@skipstuff@incLex@@\exsh@skipstuff@incLex@%
 }
 
+\newcommand{\exsh@skipstuff@incLex@}[2][]{%
+  \exsh@dlua{
+    local prefix =
+      "\ifdefvoid{\exsh@exercisespath}{}{\exsh@exercisespath/}"
+    exsh_cur_exercise=dofile(prefix .. "#2.lua")
+  }%
+  \expandafter\exsh@skipstuff%
+    \exsh@dlua{exsh_texprintlines(exsh_cur_exercise)}%
+}
+
+\let\exsh@skipstuff@incLex@@\exsh@skipstuff@incex@@
+
 %%%%%%%%%%%%%%% BEGIN BEAMER-SPECIFIC: %%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \ifexsh@beamer 
 \def\exsh@sheethead{%
@@ -1043,40 +1060,93 @@
 \fi
 %%%%%%%%%%%%%%% END BEAMER-SPECIFIC %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+%includeoverride is not part of the public interface
 \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={}}
+  \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={}}
+  \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={}}
 }
 
+
+\def\includeLexercise{%
+  \@ifstar\exsh@includeLexercise@\exsh@includeLexercise%
+}
+
+\ifluatex
+\newcommand{\exsh@includeLexercise}[2][]{%
+  \ifbool{exsh@filenameasexercisename}{%
+    \exshset{includeoverride/.style={name={#2},#1}}%
+  }{%
+    \exshset{includeoverride/.style={#1}}%
+  }%
+  \directlua{
+    local prefix =
+      "\ifdefvoid{\exsh@exercisespath}{}{\exsh@exercisespath/}"
+    exsh_cur_exercise=dofile(prefix .. "#2.lua")
+    exsh_texprintlines(exsh_cur_exercise)
+  }%
+  \exshset{includeoverride/.style={}}%
+}
+
+\newcommand{\exsh@includeLexercise@}[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\includeLexercise*}{}%
+  }
+  \directlua{
+    local prefix =
+      "\ifdefvoid{\exsh@exercisespath}{}{\exsh@exercisespath/}"
+    exsh_cur_exercise=dofile(prefix .. "#2.lua")
+    exsh_texprintlines(exsh_cur_exercise)
+  }%
+  \endgroup
+  \exshset{includeoverride/.style={}}
+}
+\else
+  \newcommand{\exsh@includeLexercise}[2][]{
+    \refstepcounter{section}
+    Lexercise needs Lua\LaTeX!
+  }
+  \let\exsh@includeLexercise@\exsh@includeLexercise
+\fi
+
 \AfterPackage*{varioref}{
   \labelformat{section}{\pgfkeysvalueof{/exsh/strings/exercise}~\arabic{section}}
 }
@@ -1617,7 +1687,6 @@
   \fi
 }
 
-%TODO:setcounter without luatex
 \def\exsh@skipstuff@Lexercise{\exsh@lua@catcodesBG\exsh@start@skip@Lexercise}%
 \def\exsh@start@lframed@{\exsh@lua@catcodesBG\exsh@start@lframed}
 
-- 
cgit v1.2.3

