diff options
| -rw-r--r-- | examples/exshexample.tex | 43 | ||||
| l--------- | examples/lexercise.lua | 1 | ||||
| -rw-r--r-- | exercisesheets-beamer.sty | 45 | ||||
| -rw-r--r-- | exercisesheets.sty | 45 | ||||
| -rw-r--r-- | lexercise.lua | 76 |
5 files changed, 210 insertions, 0 deletions
diff --git a/examples/exshexample.tex b/examples/exshexample.tex index 1761154..3b34800 100644 --- a/examples/exshexample.tex +++ b/examples/exshexample.tex @@ -156,6 +156,49 @@ task restate font={\color{black!60}}, \restatetask Yeah, but what about the subtasks? I forgot the \restatetask[1] and the \restatetask[2] one. Or did I? \end{exercise} + + \begin{Lexercise} + --use [[]] if you need \ or escape it: "\\" + firstline = [[Assume $\pi=4$.]], + points=10, + name="Pragmatic", + options=[[main task font={\itshape}]], + task = [[ + This is the main task specified via the Lua + interface. + ]], + solution=[[ + This is a solution for the main task. + ]], + altsolutions={ + { + name="Alternative Solution", + text="This is also a solution." + },{ + idea=true, + text="This is also a solution." + } + }, + \end{Lexercise} + + \begin{Lexercise} + firstline = "Assume $e=3$.", + points="sum", + task = [[ + This exercise has some subexercises. + ]], + subexercises = { + { + task = "First things first.", + points = 4, + solution = [[None.]], + },{ + task = "Second things afterwards.", + points = 16, + altsolutions = { [[None.]],[[Yet.]] }, + } + } + \end{Lexercise} \end{sheet} diff --git a/examples/lexercise.lua b/examples/lexercise.lua new file mode 120000 index 0000000..660683f --- /dev/null +++ b/examples/lexercise.lua @@ -0,0 +1 @@ +../lexercise.lua
\ No newline at end of file diff --git a/exercisesheets-beamer.sty b/exercisesheets-beamer.sty index fe40937..6688624 100644 --- a/exercisesheets-beamer.sty +++ b/exercisesheets-beamer.sty @@ -1349,3 +1349,48 @@ \end{beamercolorbox}}% \vskip0pt% } + + +\ifluatex +\usepackage{luacode} +\begingroup +\catcode`!=0 +\catcode`\@=11 +\catcode`\_=12 +\catcode`\{=12 %set those to the same value (11/12) as below! +\catcode`\}=12 % +\catcode`<=1 +\catcode`>=2 +\catcode`\~=11 +\catcode`\\=11 +%% Exoanded, when \catcode`\^^M=12 holds +!global!long!def!@start@Lexercise@Helper#1\end{Lexercise}< % + !directlua<exsh_cur_exercise=exercise ({#1})> % + !endgroup!end<Lexercise>!par % +> +!endgroup +\def\startLexercise{ +\begingroup +\catcode`!=12 +\catcode`\$=12 +\catcode`\#=12 +\catcode`\_=12 +\catcode`\^=12 +\catcode`\&=12 +\catcode`\|=12 +\catcode`\{=12 %set those to the same value (11/12) as above! +\catcode`\}=12 % +\catcode`\~=12 +\catcode`\@=11 +\catcode`\%=12 +\catcode`\^^I=12 +\catcode`\^^J=12\catcode`\^^M=12\catcode`\\=11\endlinechar-1\@start@Lexercise@Helper} + +\newenvironment{Lexercise}{% + \startLexercise% +}{% + \directlua{tex.print(exsh_cur_exercise)} +} + +\directlua{dofile("lexercise.lua")} +\fi diff --git a/exercisesheets.sty b/exercisesheets.sty index 0024d76..9492cb9 100644 --- a/exercisesheets.sty +++ b/exercisesheets.sty @@ -1205,3 +1205,48 @@ \newcommand{\samplehide}[1]{% \ifbool{exsh@samplesolutions}{}{#1}% } + + +\ifluatex +\usepackage{luacode} +\begingroup +\catcode`!=0 +\catcode`\@=11 +\catcode`\_=12 +\catcode`\{=12 %set those to the same value (11/12) as below! +\catcode`\}=12 % +\catcode`<=1 +\catcode`>=2 +\catcode`\~=11 +\catcode`\\=11 +%% Exoanded, when \catcode`\^^M=12 holds +!global!long!def!@start@Lexercise@Helper#1\end{Lexercise}< % + !directlua<exsh_cur_exercise=exercise ({#1})> % + !endgroup!end<Lexercise>!par % +> +!endgroup +\def\startLexercise{ +\begingroup +\catcode`!=12 +\catcode`\$=12 +\catcode`\#=12 +\catcode`\_=12 +\catcode`\^=12 +\catcode`\&=12 +\catcode`\|=12 +\catcode`\{=12 %set those to the same value (11/12) as above! +\catcode`\}=12 % +\catcode`\~=12 +\catcode`\@=11 +\catcode`\%=12 +\catcode`\^^I=12 +\catcode`\^^J=12\catcode`\^^M=12\catcode`\\=11\endlinechar-1\@start@Lexercise@Helper} + +\newenvironment{Lexercise}{% + \startLexercise% +}{% + \directlua{tex.print(exsh_cur_exercise)} +} + +\directlua{dofile("lexercise.lua")} +\fi diff --git a/lexercise.lua b/lexercise.lua new file mode 100644 index 0000000..22649d5 --- /dev/null +++ b/lexercise.lua @@ -0,0 +1,76 @@ +solution = function(sol) + if type(sol) ~= "string" then + local solt = sol + sol = "[" + if solt.idea then + sol = sol .. "idea," + end + if solt.name then + sol = sol .. "strings/solution={"..solt.name.."}," + end + sol = sol .. "] " .. (solt.text or "") + end + return [[\begin{solution}]]..sol..[[\end{solution}]] +end + +subexercise = function(se) + local pts = "" + local sols = "" + if type(se) ~= "string" then + local set = se + se = "[" + if set.points then + pts = [[\points{]] .. set.points ..[[}]] + end + if set.solution then + sols = sols .. solution(set.solution) + end + if set.altsolutions then + for _,sol in ipairs(set.altsolutions) do + sols = sols .. solution(sol) + end + end + se = se .. "]{" .. (set.task or "") .. "}" + end + return [[\subtask]]..se .. pts .. sols +end + +exercise = function(ex) + local ece = [[\begin{exercise}[]] + if ex.firstline then + ece = ece .. [[firstline={]] .. ex.firstline .. [[},]] + end + if ex.points then + ece = ece .. [[points={]] .. ex.points .. [[},]] + end + if ex.name then + ece = ece .. [[name={]] .. ex.name .. [[},]] + end + if ex.options then + ece = ece .. ex.options .. "," + end + ece = ece .. "]{}" + if ex.task then + ece = ece .. [[\begin{maintask}]] .. ex.task + .. [[\end{maintask}]] + end + if ex.solution then + ece = ece .. solution(ex.solution) + end + if ex.altsolutions then + for _,sol in ipairs(ex.altsolutions) do + ece = ece .. solution(sol) + end + end + if ex.subexercises then + ece = ece .. [[\begin{subtasks}]] + for _,se in ipairs(ex.subexercises) do + ece = ece .. subexercise(se) + end + ece = ece .. [[\end{subtasks}]] + end + ece = ece .. "\n" .. [[\end{exercise}]] + print(ece) + return ece +end + |
