-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlbt-7-lbt-WS0.lua
More file actions
186 lines (158 loc) · 4.82 KB
/
lbt-7-lbt-WS0.lua
File metadata and controls
186 lines (158 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
-- +---------------------------------------+
-- | Template: lbt.WS0 |
-- | |
-- | Purpose: Simple worksheet with title, |
-- | course and teacher notes. |
-- +---------------------------------------+
-- This code will be rendered over two pages: one for the teacher's notes and
-- one for the worksheet. The title will be used on both pages. A table of
-- contents entry will be generated for the worksheet but not the teacher's
-- notes. The course, if given, will appear as a subtle part of the title. The
-- title and course will appear at the top of the page and be underlined with a
-- full-width rule. A little space will appear before the body, and the rest is
-- up to you!
--
-- The teacher's notes appear entirely in blue so that they are easily visually
-- distinguished from the worksheet when flicking through the pages.
local F = string.format
local f = {}
local op = {}
local a = {}
local m = {}
op.WS0 = {
title_color = 'BlueViolet',
teacher_notes_color = 'blue',
teacher_notes_include = true,
}
local function init()
end
-- Input: (pc) parsed content
local function expand(pc)
local title = lbt.util.content_meta_or_error(pc, 'TITLE')
local course = lbt.util.content_meta_or_error(pc, 'COURSE')
local tnotes = lbt.util.content_meta_or_nil(pc, 'TEACHERNOTES') or '(none specified)'
local titlecol = lbt.util.resolve_oparg('WS0.title_color')
local tncol = lbt.util.resolve_oparg('WS0.teacher_notes_color')
local tnincl = lbt.util.resolve_oparg('WS0.teacher_notes_include')
-- 1. Preamble
local a = [[
\setlength{\parindent}{0em}
\setlength{\parskip}{6pt plus 2pt minus 2pt}
\newcommand{\TitleSet}[2]{{\bfseries\color{#1}#2}}
\newcommand{\CourseSet}[1]{{\color{CadetBlue}\itshape #1}}
\tcbset{colback=blue!10!white}
]]
-- 2. Teacher notes
local b
if tnincl then
b = F([[
\newpage
\begingroup
\color{%s}
\fbox{Teacher's notes on \textbf{%s}}
\vspace{2.5em}
%s
\endgroup
]], tncol, title, tnotes)
else
b = ''
end
-- 3. New page and table-of-contents addition
local c = F([[
\newpage
\addcontentsline{toc}{\lbtCurrentContentsLevel}{Worksheet: %s}
]], title)
-- 4. Worksheet title and horizontal rule
local d = nil
if course == nil then
d = F([[
\TitleSet{%s}{%s}
\rule[8pt]{\textwidth}{0.4pt}
]], titlecol, title, course)
else
d = F([[
\TitleSet{%s}{%s} \hfill \CourseSet{%s}
\rule[8pt]{\textwidth}{0.4pt}
]], titlecol, title, course)
end
-- 5. General body
local e = F([[
\bigskip
%s
\clearpage
]], lbt.util.latex_expand_content_list('BODY', pc))
-- Put it all together!
return lbt.util.combine_latex_fragments(a,b,c,d,e)
end
-- EXAMPLE and NOTE and CHALLENGE and general headings ------------------------
local function heading_and_text_indent(heading, color, text)
local colorsetting = ''
if color then colorsetting = F([[\color{%s}]], color) end
return F([[
{%s \bfseries %s} \par
\begin{adjustwidth}{2em}{}
%s
\end{adjustwidth} \par
]], colorsetting, heading, text)
end
local function heading_and_text_inline(heading, color, text)
local colorsetting = ''
if color then colorsetting = F([[\color{%s}]], color) end
return F([[ {%s \bfseries %s} \quad %s \par ]], colorsetting, heading, text)
end
op.EXAMPLE = { starred = false, color = 'blue' }
a.EXAMPLE = 1
f.EXAMPLE = function (n, args, o)
local fn = heading_and_text_indent
if o.starred then
fn = heading_and_text_inline
end
return fn('Example', o.color, args[1])
end
op.NOTE = { starred = false, color = 'Mahogany' }
a.NOTE = 1
f.NOTE = function (n, args, o)
local fn = heading_and_text_indent
if o.starred then
fn = heading_and_text_inline
end
return fn('Note', o.color, args[1])
end
op.CHALLENGE = { starred = false, color = 'Plum' }
a.CHALLENGE = 1
f.CHALLENGE = function (n, args, o)
local fn = heading_and_text_indent
if o.starred then
fn = heading_and_text_inline
end
lbt.api.counter_reset('qq')
return fn('Challenge', o.color, args[1])
end
op.HEADING = { starred = false }
a.HEADING = '2-3'
f.HEADING = function(n, args, o)
local fn = heading_and_text_indent
if o.starred then
fn = heading_and_text_inline
end
if n == 2 then
return fn(args[1], nil, args[2])
elseif n == 3 then
return fn(args[1], args[2], args[3])
end
end
-- smallnote macro ------------------------------------------------------------
m.smallnote = function(text, _) -- ignore the ExpansionContext parameter
return F([[\textcolor{CadetBlue}{\small %s} ]], text)
end
return {
name = 'lbt.WS0',
desc = 'A worksheet with title, course, teacher notes',
sources = {"lbt.Questions"},
init = init,
expand = expand,
functions = f,
opargs = op,
posargs = a,
macros = m,
}