m-educat.mkiv /size: 6701 b    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=m-educat,
3%D        version=2003.03.05,
4%D          title=\CONTEXT\ Extra Modules,
5%D       subtitle=Educational Extras,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D This module will collect a few macros cq.\ definitions
15%D meant for educational use. Most of the code has been laying
16%D around for some time and has been (or is still) used in
17%D \PRAGMA\ projects.
18
19\unprotect
20
21\definesystemvariable{iv}
22
23\definecolor [answerareacolor] [s=.90]
24\definecolor [answerlinecolor] [white]
25
26\definetextbackground
27  [\v!answerarea]
28  [\c!location=\v!text,
29   \c!n=0,
30   \c!frame=\v!off,
31   \c!framecolor=answerlinecolor,
32   \c!rulethickness=2pt,
33   \c!background=\v!color,
34   \c!backgroundcolor=answerareacolor,
35   \c!alternative=2] % betweenline
36
37% n=gedwongen
38% m=extra auto
39
40\def\setupanswerarea
41  {\setuptextbackground[\v!answerarea]}
42
43\setvalue\e!answerspace
44  {\dosingleempty\doanswerspace}
45
46\def\doanswerspace[#1]%
47  {\begingroup
48   \dontcomplain
49   \setupanswerarea
50     [\c!n=0,\c!m=#1,\c!location=\v!text]%
51   \let\currenttextbackground\v!answerarea
52   \doifelsenothing{\textbackgroundparameter\c!m}
53     {\expandafter\donoanswerspace}
54     {\expandafter\dodoanswerspace}%
55   [#1]}
56
57\def\donoanswerspace[#1]#2%
58  {\setupthinrules
59     [\c!alternative=\textbackgroundparameter\c!alternative,
60      \c!color=\textbackgroundparameter\c!framecolor,
61      \c!background=\textbackgroundparameter\c!background,
62      \c!backgroundcolor=\textbackgroundparameter\c!backgroundcolor,
63      \c!rulethickness=\textbackgroundparameter\c!rulethickness]%
64   \doifelse{\textbackgroundparameter\c!n}{*}
65     {\thinrule
66      \par}
67     {\scratchcounter0\textbackgroundparameter\c!n\relax
68      % tricky, guess
69      \def\processisolatedword##1%
70        {\setbox\scratchbox=\hbox{##1}%
71         \vbox{\hsize\wd\scratchbox\thinrule
72         \ifcase\scratchcounter\else
73           \setbox\scratchbox=\hbox{\space}%
74           \nobreak\hskip\zeropoint \s!minus \wd\scratchbox
75           \vbox{\hsize\wd\scratchbox\thinrule}%
76         \fi}}%
77      \processisolatedwords{#2}\processisolatedword
78      % so far
79      \ifcase\scratchcounter \else \ifnum\scratchcounter<3
80        \nobreak \vbox{\hsize\scratchcounter em\thinrule}%
81      \else % more
82        \advance \scratchcounter -2
83        \dorecurse\scratchcounter{\allowbreak\vbox{\hsize1em\thinrule}}%
84        \nobreak \vbox{\hsize2em\thinrule}%
85      \fi \fi}%
86   \endgroup}
87
88\def\dodoanswerspace[#1]#2% m case
89  {\getvalue{\e!start\v!answerarea}%
90   #2%
91   \doifelse{\textbackgroundparameter\c!m}{*}
92     {\hfill\strut
93      \getvalue{\e!stop\v!answerarea}%
94      \par}
95     {\scratchcounter0\textbackgroundparameter\c!m\relax
96      \ifcase\scratchcounter \else \ifnum\scratchcounter<3
97        \nobreak \hbox to \scratchcounter em{\strut\hss}%
98      \else % more
99        \advance \scratchcounter -2
100        \dorecurse\scratchcounter{\allowbreak\hbox to 1em{\strut\hss}}%
101        \nobreak \hbox to 2em{\strut\hss}%
102      \fi \fi
103      \getvalue{\e!stop\v!answerarea}}%
104   \endgroup}
105
106\setvalue{\e!start\e!answerlines}%
107  {\dosingleempty\dostartanswerlines}
108
109\def\dostartanswerlines[#1]%
110  {\begingroup
111   \dontcomplain
112   \setupanswerarea
113     [\c!n=0,\c!m=,#1,\c!location=\v!text]%
114   \let\currenttextbackground\v!answerarea
115   \doifnot{\textbackgroundparameter\c!option}\v!joinedup\softbreak
116   \doifelsenothing{\textbackgroundparameter\c!m}
117     {\expandafter\donostartanswerlines}
118     {\expandafter\dodostartanswerlines}%
119   [#1]}
120
121\def\donostartanswerlines[#1]%
122  {\setupthinrules
123     [\c!alternative=\textbackgroundparameter\c!alternative,
124      \c!color=\textbackgroundparameter\c!framecolor,
125      \c!background=\textbackgroundparameter\c!background,
126      \c!backgroundcolor=\textbackgroundparameter\c!backgroundcolor,
127      \c!rulethickness=\textbackgroundparameter\c!rulethickness]%
128   \thinrules[\c!n=\textbackgroundparameter\c!n]\par
129   \endgroup
130   \grabuntil{\e!stop\e!answerlines}}
131
132\def\dodostartanswerlines[#1]%
133  {\begingroup
134   \getvalue{\e!start\v!answerarea}%
135   \ignorespaces}
136
137\setvalue{\e!stop\e!answerlines}%
138  {\scratchcounter0\textbackgroundparameter\c!m\relax
139   % a \softbreak is more efficient in pos dan \par
140   \ifcase\scratchcounter
141     % nothing
142   \or
143     \softbreak
144   \else
145     \softbreak
146     \advance \scratchcounter \minusone
147     \dorecurse\scratchcounter{\strut\hfill\strut\softbreak}%
148   \fi
149   \strut\hfill\strut
150   \getvalue{\e!stop\v!answerarea}%
151   \par\endgroup\endgroup}
152
153\setvalue\e!answerlines
154  {\dosingleempty\doanswerlines}
155
156\def\doanswerlines[#1]#2%
157  {\getvalue{\e!start\e!answerlines}[#1]%
158   #2%
159   \getvalue{\e!stop\e!answerlines}}
160
161\protect
162
163\continueifinputfile{m-educat.mkiv}
164
165%D Test materiaal.
166
167\starttext
168
169\startnotmode[answers]
170
171  \setupanswerarea[level=+1]
172
173\stopnotmode
174
175\setupcolors[state=start]
176
177test test test \answerspace [n=10] {Whow}. test test test
178test tets test test \answerspace [n=10] {Whow}. test test
179test test tets test test \answerspace [n=10] {Whow}. test
180test test test tets test test \answerspace [n=10] {Whow}.
181test test test test test test \answerspace [n=*] {Whow.}
182
183test test test test test test test \startanswerlines
184[n=3] What A Junk Answer \stopanswerlines
185
186test test test test test test test \startanswerlines
187[n=3,alternative=0] What A Junk Answer \stopanswerlines
188
189test test test test test test test \startanswerlines
190[n=3,alternative=1] What A Junk Answer \stopanswerlines
191
192test test test test test test test \startanswerlines
193[n=3,alternative=2] What A Junk Answer \stopanswerlines
194
195\startitemize[paragraph]
196\item \startanswerlines [option=seried,n=2] xxx \stopanswerlines
197\stopitemize
198
199test test test \answerspace [m=10] {Whow}. test test test
200test tets test test \answerspace [m=10] {Whow}. test test
201test test tets test test \answerspace [m=10] {Whow}. test
202test test test tets test test \answerspace [m=10] {Whow}.
203test test test test test test \answerspace [m=*] {Whow.}
204
205test test test test test test test \startanswerlines
206[m=2] What A Junk Answer \stopanswerlines
207
208test test test test test test test \startanswerlines
209[m=2,alternative=0] What A Junk Answer \stopanswerlines
210
211test test test test test test test \startanswerlines
212[m=2,alternative=1] What A Junk Answer \stopanswerlines
213
214test test test test test test test \startanswerlines
215[m=2,alternative=2] What A Junk Answer \stopanswerlines
216
217\startitemize[paragraph]
218\item \startanswerlines [option=seried,m=2] xxx \stopanswerlines
219\stopitemize
220
221\stoptext
222