aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
l---------examples/exsh_lexercise.lua1
-rw-r--r--examples/exshexample.tex8
l---------examples/lexercise.lua1
-rw-r--r--exercisesheets-beamer.sty18
-rw-r--r--exercisesheets.sty20
-rw-r--r--exsh_lexercise.lua (renamed from lexercise.lua)64
6 files changed, 80 insertions, 32 deletions
diff --git a/examples/exsh_lexercise.lua b/examples/exsh_lexercise.lua
new file mode 120000
index 0000000..0669efc
--- /dev/null
+++ b/examples/exsh_lexercise.lua
@@ -0,0 +1 @@
+../exsh_lexercise.lua \ No newline at end of file
diff --git a/examples/exshexample.tex b/examples/exshexample.tex
index 3b34800..acd3874 100644
--- a/examples/exshexample.tex
+++ b/examples/exshexample.tex
@@ -1,4 +1,4 @@
-\long\def\ifbeamer#1#2{#1}
+\long\def\ifbeamer#1#2{#2}
\ifbeamer{\documentclass{beamer}}{\documentclass{article}}
%navigation symbols and the title collide if
@@ -185,12 +185,14 @@ task restate font={\color{black!60}},
firstline = "Assume $e=3$.",
points="sum",
task = [[
- This exercise has some subexercises.
+ This exercise has some subexercises. The Lua interface
+ computes point sums in a single pass.
]],
subexercises = {
{
task = "First things first.",
- points = 4,
+ bonuspoints = 4,
+ pointoptions = "abbrev",--passed to LaTeX interface
solution = [[None.]],
},{
task = "Second things afterwards.",
diff --git a/examples/lexercise.lua b/examples/lexercise.lua
deleted file mode 120000
index 660683f..0000000
--- a/examples/lexercise.lua
+++ /dev/null
@@ -1 +0,0 @@
-../lexercise.lua \ No newline at end of file
diff --git a/exercisesheets-beamer.sty b/exercisesheets-beamer.sty
index 6688624..4ba3690 100644
--- a/exercisesheets-beamer.sty
+++ b/exercisesheets-beamer.sty
@@ -1353,6 +1353,8 @@
\ifluatex
\usepackage{luacode}
+
+%change only some catcodes to
\begingroup
\catcode`!=0
\catcode`\@=11
@@ -1363,13 +1365,14 @@
\catcode`>=2
\catcode`\~=11
\catcode`\\=11
-%% Exoanded, when \catcode`\^^M=12 holds
-!global!long!def!@start@Lexercise@Helper#1\end{Lexercise}< %
+%% Expanded, when \catcode`\^^M=12 holds
+!global!long!def!exsh@start@Lexercise@#1\end{Lexercise}< %
!directlua<exsh_cur_exercise=exercise ({#1})> %
- !endgroup!end<Lexercise>!par %
+ !endgroup!end<Lexercise>%
>
!endgroup
-\def\startLexercise{
+
+\def\exsh@lua@catcodesBG{
\begingroup
\catcode`!=12
\catcode`\$=12
@@ -1384,10 +1387,13 @@
\catcode`\@=11
\catcode`\%=12
\catcode`\^^I=12
-\catcode`\^^J=12\catcode`\^^M=12\catcode`\\=11\endlinechar-1\@start@Lexercise@Helper}
+\catcode`\^^J=12\catcode`\^^M=12\catcode`\\=11\endlinechar-1}
+
+\def\exsh@start@Lexercise{%
+ \exsh@lua@catcodesBG\exsh@start@Lexercise@}
\newenvironment{Lexercise}{%
- \startLexercise%
+ \exsh@start@Lexercise%
}{%
\directlua{tex.print(exsh_cur_exercise)}
}
diff --git a/exercisesheets.sty b/exercisesheets.sty
index 9492cb9..29c2728 100644
--- a/exercisesheets.sty
+++ b/exercisesheets.sty
@@ -1209,6 +1209,8 @@
\ifluatex
\usepackage{luacode}
+
+%change only some catcodes to
\begingroup
\catcode`!=0
\catcode`\@=11
@@ -1219,13 +1221,14 @@
\catcode`>=2
\catcode`\~=11
\catcode`\\=11
-%% Exoanded, when \catcode`\^^M=12 holds
-!global!long!def!@start@Lexercise@Helper#1\end{Lexercise}< %
+%% Expanded, when \catcode`\^^M=12 holds
+!global!long!def!exsh@start@Lexercise@#1\end{Lexercise}< %
!directlua<exsh_cur_exercise=exercise ({#1})> %
- !endgroup!end<Lexercise>!par %
+ !endgroup!end<Lexercise>%
>
!endgroup
-\def\startLexercise{
+
+\def\exsh@lua@catcodesBG{
\begingroup
\catcode`!=12
\catcode`\$=12
@@ -1240,13 +1243,16 @@
\catcode`\@=11
\catcode`\%=12
\catcode`\^^I=12
-\catcode`\^^J=12\catcode`\^^M=12\catcode`\\=11\endlinechar-1\@start@Lexercise@Helper}
+\catcode`\^^J=12\catcode`\^^M=12\catcode`\\=11\endlinechar-1}
+
+\def\exsh@start@Lexercise{%
+ \exsh@lua@catcodesBG\exsh@start@Lexercise@}
\newenvironment{Lexercise}{%
- \startLexercise%
+ \exsh@start@Lexercise%
}{%
\directlua{tex.print(exsh_cur_exercise)}
}
-\directlua{dofile("lexercise.lua")}
+\directlua{dofile("exsh_lexercise.lua")}
\fi
diff --git a/lexercise.lua b/exsh_lexercise.lua
index 22649d5..5f7cdae 100644
--- a/lexercise.lua
+++ b/exsh_lexercise.lua
@@ -14,14 +14,24 @@ solution = function(sol)
end
subexercise = function(se)
- local pts = ""
+ local pts,p,bp = ""
local sols = ""
if type(se) ~= "string" then
local set = se
- se = "["
- if set.points then
- pts = [[\points{]] .. set.points ..[[}]]
+ local po = ""
+ if set.pointoptions then
+ po = po .. set.pointoptions
+ end
+ p,bp = set.points,set.bonuspoints
+ if p and bp then
+ pts = [[\points[]] .. po .. "]{" .. set.points .. "+" ..
+ set.bonuspoints .. "}"
+ elseif bp then
+ pts = [[\points[bonus,]] .. po .. "]{" .. set.bonuspoints .. "}"
+ elseif p then
+ pts = [[\points[]] .. po .. "]{" .. set.points .. "}"
end
+
if set.solution then
sols = sols .. solution(set.solution)
end
@@ -30,18 +40,47 @@ subexercise = function(se)
sols = sols .. solution(sol)
end
end
+
+ se = "["
+ if set.options then
+ se = se .. set.options
+ end
se = se .. "]{" .. (set.task or "") .. "}"
end
- return [[\subtask]]..se .. pts .. sols
+ return [[\subtask]]..se .. pts .. sols, p, bp
end
exercise = function(ex)
+ local subex = ""
+ local pts,bpts = 0,0
+ if ex.subexercises then
+ subex = [[\begin{subtasks}]]
+ for _,se in ipairs(ex.subexercises) do
+ local s,p,bp = subexercise(se)
+ subex = subex .. s
+ pts = pts + (p or 0)
+ bpts = bpts + (bp or 0)
+ end
+ subex = subex .. [[\end{subtasks}]]
+ end
+ if ex.points and ex.points == "sum" then
+ if pts > 0 and bpts > 0 then
+ pts = pts .. "+" .. bpts
+ elseif bpts > 0 then --and pts = 0
+ pts = bpts
+ ex.options = (ex.options or "") .. ",bonus"
+ --else bpts = 0 thus pts is all points
+ end
+ else
+ pts = ex.points
+ end
+
local ece = [[\begin{exercise}[]]
if ex.firstline then
ece = ece .. [[firstline={]] .. ex.firstline .. [[},]]
end
- if ex.points then
- ece = ece .. [[points={]] .. ex.points .. [[},]]
+ if pts then
+ ece = ece .. [[points={]] .. pts .. [[},]]
end
if ex.name then
ece = ece .. [[name={]] .. ex.name .. [[},]]
@@ -62,15 +101,10 @@ exercise = function(ex)
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 .. subex
+
ece = ece .. "\n" .. [[\end{exercise}]]
- print(ece)
return ece
end