Debian Codegraph @

texmf-dist/source/latex/ktv-texdata/ktv-texdata.dtx

raw
1 % \iffalse
2 % File: ktv-texdata.dtx
3 % Copyleft 2003 Ky Anh
4 %
5 % This program is free software; you can redistribute it and/or
6 % modify it under the terms of the GNU General Public License
7 % as published by the Free Software Foundation; either version 2
8 % of the License, or (at your option) any later version.
9 %
10 % This program is distributed in the hope that it will be useful,
11 % but WITHOUT ANY WARRANTY; without even the implied warranty of
12 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 % See the GNU General Public License for more details.
14 %
15 % For error reports,
16 % or offers to help improve the `ktv-texdata' package,
17 % please mail to
18 % Ky` Anh, [email protected]
19 % \fi
20 %
21 % \iffalse
22 %<*dtx>
23 \ProvidesFile{ktv-texdata.dtx}
24 [2003/11/20 v1468 KTV, Data Manager]
25 %</dtx>
26 %<package>\NeedsTeXFormat{LaTeX2e}
27 %<package>\ProvidesPackage{ktv-texdata}
28 %<package>[2003/10/06 v05.34 KTV, Data Manager]
29 %<*driver>
30 \documentclass[oneside]{ltxdoc}
31 \usepackage{ktv-buildnum}
32 \CodelineIndex
33 \RecordChanges
34 \DocInput{ktv-texdata.dtx}
35 \begin{thebibliography}{VE}
36 \addcontentsline{toc}{section}{References}
37 \bibitem[VE]{VE}
38 Victor EIJKHOUT, {\it \TeX\ by Topic}, Addison-Wesley, 1992.
39 \end{thebibliography}
40 \end{document}
41 %</driver>
42 %
43 % \fi
44 %
45 % \GetFileInfo{ktv-texdata.dtx}
46 %
47 % \def\docversion{\the\buildnum}
48 % \def\docdate{\filedate}
49 %
50 % \makeatletter
51 % \let\@afterindentfalse\@afterindenttrue
52 % \@afterindenttrue
53 % \makeatother
54 %
55 % \def\pkg{{\bf ktv-texdata}}
56 % \def\back:{$\backslash$}
57 % \def\trick:{\DescribeMacro{Trick}{:: \bf TRICK}\hrulefill\par}
58 %
59 % \begin{document}
60 % \title{\pkg\ package}
61 % \author{K\`{y} Anh\\(\ttfamily{[email protected], [email protected]})}
62 % \date{\begin{tabular}{rll}
63 % \texttt{package:}
64 % &version 05.34, & last update 2003/10/06
65 % \\
66 % \texttt{documentation:}
67 % &version \docversion, & last update \docdate
68 % \end{tabular}}
69 % \maketitle
70 %
71 % ^^M\CheckSum{656}
72 %
73 % \begin{abstract}
74 %
75 % This package provides a simple way to use
76 % the \TeX\ input files whose contents
77 % are in the numbered environments.
78 %
79 % This package is useful for
80 % \underline{\bf the teachers of mathematics},
81 % who often work with large libraries of mathematical exercises.
82 %
83 % \end{abstract}
84 %
85 % \tableofcontents
86 %
87 % \section{How will you do?}
88 % \label{sec:howwillyoudo}
89 %
90 % Assume that you have an input file (named `|foo.tex|')
91 % that specifies 16 exercies
92 % \begin{verbatim}
93 % % --- first line of `foo.tex'
94 % \begin{exercice}\label{ex:1}
95 % This is the first exercice.
96 % \end{exercice}
97 %
98 % \begin{exercice}\label{ex:2}
99 % This is the second exercice.
100 % \end{exercice}
101 %
102 % ...
103 % \begin{exercice}[*]\label{ex:16}
104 % This is the 16th exercice
105 % (with a star mark *).
106 % \end{exercice}
107 % % --- last line of `foo.tex'
108 % \end{verbatim}
109 % On Tuesday, for e.g., you want to create a student test
110 % that contains the first 8 exercises of the `|foo.tex|'.
111 % However, on Wednesday, you want to create another test
112 % that contains the last 8 exercises of the `|foo.tex|'.
113 %
114 % Of course, the simplest way to do that
115 % is \emph{copying} and \emph{pasting}.
116 % Of course, this way becomes too complex in case,
117 % for e.g., you need only the exercies that are numbered oddly
118 % (1, 3, 5, 7, 9, 11, 13, 15).
119 %
120 % You may think of a solution like this
121 % \begin{verbatim}
122 % \getonly{1,2,3,4,5,6,7,8} % on Tuesday
123 % \getonly{9,10,11,12,13,14,15,16} % on Wednesday
124 % \getonly{1,3,5,7,9,11,13,15} % on Friday
125 % \end{verbatim}
126 %
127 % Yes, here we go....
128 %
129 % \section{Introduction}
130 %
131 % \subsection{Convention}
132 %
133 % Instead of using |#1|, |#2|, etc., to specify
134 % the first, the second,... parameter or argument of a macro,
135 % we will use |#foo|, |#xfoo|,... where |#foo| is
136 % a short description of |#1|,
137 % and |#xfoo| is a short description of |#2|, etc.
138 %
139 % \emph{Parameter} is something declared in the macro's definitons.
140 %
141 % \emph{Argument} is something you pass to a macro when you call it.
142 %
143 % The optional parameters are enclosed in the brackets (`|[|' and `|]|').
144 %
145 % \subsection{Data item `bxx'}
146 %
147 % \subsubsection{Form}
148 % \label{ssec:bxx.form}
149 %
150 % Each `|bxx|', or a \emph{data item}, is of the form
151 % \begin{center}
152 % \begin{tabular}{l}
153 % |\bxx(#env)[#thm]ID;|\\
154 % \emph{something to typeset}\\
155 % |\exx|
156 % \end{tabular}
157 % \end{center}
158 % Note that `|\exx|' must be located at
159 % \emph{the beginning of a new line}\\
160 % and the semicolon `|;|' is mandatory.
161 %
162 % \DescribeMacro{ID}
163 % |ID| is any non-empty string of
164 % characters, numbers or punctuations:
165 % \begin{center}
166 % \begin{tabular}{rl}
167 % |ID| &$\longrightarrow$ |char-num| / |xpunct| / |ID|\,|ID|\\
168 % |char-num|&$\longrightarrow$ |a..z| / |A..Z| / |0..9|\\
169 % |xpunct| &$\longrightarrow$ |:| / |.| / |,|
170 % \end{tabular}
171 % \end{center}
172 % For example, `|ex:1|', `|Ex:2003|' are the |ID|s, but `|ex;1|' isnot.
173 %
174 % \DescribeMacro{#env}
175 % |#env| is any predefined environment.
176 % Parameter |(#env)| is \emph{optional}.
177 %
178 % \DescribeMacro{#thm}
179 % |#thm|\, is the \emph{optional argument} for the environment |#env|.
180 % It is also the \emph{optional parameter} for the macro |\bxx|,
181 % because it is enclosed in the brackets;
182 % so you can specify a `|bxx|' like this
183 % \begin{center}
184 % \begin{tabular}{l}
185 % |\bxx(#env)ID;|\\
186 % \emph{something to typeset}\\
187 % |\exx|\\
188 % \end{tabular}
189 % \end{center}
190 % or more simply (because |(#env)| is optional)
191 % \begin{center}
192 % \begin{tabular}{l}
193 % |\bxx ID;|\\
194 % \emph{something to typeset}\\
195 % |\exx|\\
196 % \end{tabular}
197 % \end{center}
198 %
199 % \subsubsection{Meaning}
200 %
201 % \DescribeMacro{\bxx}
202 % \DescribeMacro{\exx}
203 % What does `|bxx|' mean?
204 %
205 % Yes, it's very familar with |\begin{#env}| and |\end{#env}|.
206 % \begin{center}
207 % \begin{tabular}{r@{\hspace{5mm}\emph{means}\hspace{5mm}}l}
208 % |\bxx(#env)[#thm]ID;| & |\begin{#env}[#thm]|\\
209 % \emph{something to typeset} & \emph{itself}\\
210 % |\exx| & |\end{#env}|
211 % \end{tabular}
212 % \end{center}
213 %
214 % \subsubsection{Identifying the `bxx'}
215 % \label{ssec:bxx.identify}
216 %
217 % We use |ID| and |#env| to identify a `|bxx|'
218 % by associating that `|bxx|' with the string |#envID|.
219 % This string is named \emph{string-id} of the `|bxx|'.
220 % Then two `|bxx|'s are different
221 % if their \emph{string-id}s are different.
222 % For e.g., after the declaration
223 % \begin{center}
224 % \begin{verbatim}
225 % \bxx(exercise)100;
226 % ...
227 % \exx
228 % \end{verbatim}
229 % \end{center}
230 % the \emph{string-id} of the `|bxx|' is `|exercise100|'.
231 %
232 % \subsection{Data file. Example}
233 %
234 % An input file containing one or more `|bxx|'
235 % is called a \emph{data fille}.
236 % Using the `|bxx|', we reedit the `foo.tex' in the first section.
237 % Then, `|foo.tex|' becomes a \emph{data file}.
238 % \begin{verbatim}
239 % % --- first line of the new `foo.tex'
240 % \bxx(exercice)ex:1;
241 % \label{ex:1}
242 % This is the first exercice.
243 % \exx
244 % \bxx(exercice)ex:2; \label{ex:2}
245 % This is the second exercice.
246 % \exx
247 % ...
248 % \bxx(exercice)ex:16;\label{ex:16}
249 % This is the 16th exercice.
250 % \exx
251 % % --- last line of the new `foo.tex'
252 % \end{verbatim}
253 %
254 % \section{User's macros}
255 %
256 % \subsection{Turning on/off the detail(s)}
257 %
258 % \DescribeMacro{\xdetailon}
259 % \DescribeMacro{\xdetailoff}
260 % Syntax
261 % \begin{center}
262 % |\xdetailon| \\ |\xdetailoff|
263 % \end{center}
264 %
265 % By default, the package shows \emph{string-id} of the `|bxx|'
266 % you want to get on the margin. You can turn this feature
267 % on/off by these marcos. The macros can be put anywhere in your
268 % document. See the package's test for an illustration.
269 %
270 % You can also pass an option to the package, like this
271 % \begin{center}
272 % |\usepackage[detailon]{ktv-texdata}|, or\\
273 % |\usepackage[detailoff]{ktv-texdata}|\phantom{xx}
274 % \end{center}
275 %
276 % \subsection{Specifying the default environment}
277 %
278 % \DescribeMacro{\xenv}
279 % Syntax
280 % \begin{center}
281 % |\xenv(#env)|
282 % \end{center}
283 % This macro specifies the default environment used for the macros
284 % `|bxx|', `|\xget|', `|\xgetall|', etc.
285 % Here |#env| is any predefined environment.
286 %
287 % This macro can be put anywhere.
288 % It keeps the effect until the next |\xenv|.
289 %
290 % \subsection{Getting/Ignoring the `bxx'}
291 %
292 % There are 7 macros used to get/remove the `bxx' from the data file.
293 % \begin{center}
294 % \begin{tabular}{l@{ \ }l@{ \ }l}
295 % |\xget| & |\xgetall| & |\xgetallbut|\\
296 % |\xkill| & |\xkillall| & |\xkillallbut|\\
297 % & |\xspec| &
298 % \end{tabular}
299 % \end{center}
300 % The macro |\xspec| is described in subsection \ref{ssec:xspec}.
301 %
302 % \DescribeMacro{\xgetall}
303 % \DescribeMacro{\xkillall}
304 % Syntax
305 % \begin{center}
306 % |\xgetall|\\ |\xkillall|
307 % \end{center}
308 % |\xgetall| means that
309 % you want to \emph{get all the data items from the data file},
310 % while |\xkillall| means that you want to \emph{ignore all...}.
311 % These macros remove the effects of any |\xget|, |\xkill|
312 % that is called before them.
313 %
314 % \DescribeMacro{\xget}
315 % Syntax
316 % \begin{center}
317 % |\xget(#env){#ID-list}|
318 % \end{center}
319 % where
320 % \begin{itemize}
321 % \item
322 % |#env| is an environment name. The parameter |(#env)| is optional.
323 % \item
324 % |#ID-list| is a list of |ID|s that're seperated by the comma (`|,|'),
325 % each |ID| can be prefixed by a plus sign (`|+|')
326 % or by a minus sign (`|-|').
327 % \end{itemize}
328 % For e.g., the specification
329 % \begin{center}
330 % |\xget(exercise){-12,-3,+5,6,-99,+100}|
331 % \end{center}
332 % means that you want to get from the data file all the `|bxx|'s
333 % whose \emph{string-id}s are
334 % \begin{center}
335 % |exercise5|, |exercise6|, |exercise100|
336 % \end{center}
337 % Because you specified |-12|, |-3|, |-99|,
338 % all the `|bxx|' whose \emph{string-id}s are
339 % |exercise12|, |exercise3|, |exercise99| are ignored.
340 % Of course, |exercise7| is ignored, too.
341 %
342 % \trick:
343 % The parameter |(#env)| is optional; so if you specified
344 % \begin{center}
345 % |\xenv(exercise)|
346 % \end{center}
347 % then you can write shortly
348 % \begin{center}
349 % |\xget{-12,-3,+5,6,-99,+100}|
350 % \end{center}
351 %
352 % \trick:
353 % A sequence of two |\xget|s can be replaced by one |\xget|, for e.g.,
354 % \begin{center}
355 % |\xget{1,6}| |\xget{3,-4}|
356 % $\longrightarrow$ |\xget{1,6,3,-4}|
357 % \end{center}
358 %
359 % \DescribeMacro{\xkill}
360 % The syntax and tricks are the same as |\xget|.
361 % Try to guess the usage of this macro.
362 %
363 % \DescribeMacro{\xgetallbut}
364 % \DescribeMacro{\xkillallbut}
365 % The syntax is the same as |\xget|.
366 %
367 % The macro |\xgetallbut| means that you want to
368 % \emph{get all the data items} \underline{but}
369 % \emph{the data items specified in the} |#ID-list|.
370 %
371 % Inversely, the macro |\xkillallbut| means that you want to
372 % \emph{ignore all the data items} \underline{but}
373 % \emph{the data items specified in the} |#ID-list|.
374 %
375 % \trick:
376 % These macros are affected by |\xget| and |\xkill|.
377 % For e.g., the sequence
378 % \begin{center}
379 % |\xget{1,2,3}| |\xgetallbut{3,4,7}|
380 % \end{center}
381 % will be understood as |\xgetallbut{1,2,3,4,7}|.
382 %
383 % Here're some other examples (may be useless for you)
384 % \begin{center}
385 % \begin{tabular}{r@{ }l@{ $\longrightarrow$ }l}
386 % |\xget{1,2}| &|\xgetallbut{2,3,4}| &|\xgetallbut{1,2,3,4}|\\
387 % |\xkill{1,2}| &|\xgetallbut{2,3,4}| &|\xgetallbut{2,3,4}|\\
388 % |\xget{1,2}| &|\xkillallbut{2,3,4}| &|\xkillallbut{1,2,3,4}|\\
389 % |\xkill{1,2}| &|\xkillallbut{2,3,4}| &|\xkillallbut{2,3,4}|\\[2mm]
390 % |\xgetallbut{2,3,4}| &|\xget{1,2}| &|\xgetallbut{1,2,3,4}|\\
391 % |\xgetallbut{2,3,4}| &|\xkill{1,2}| &|\xgetallbut{3,4}|\\
392 % |\xkillallbut{2,3,4}|&|\xget{1,2}| &|\xkillallbut{1,2,3,4}|\\
393 % |\xkillallbut{2,3,4}|&|\xkill{1,2}| &|\xkillallbut{3,4}|\\
394 % \end{tabular}
395 % \end{center}
396 %
397 % \subsection{Openning the data file}
398 %
399 % \DescribeMacro{\xopenlib}
400 % Syntax
401 % \begin{center}
402 % |\xopenlib foo;|
403 % \end{center}
404 % where |foo|\footnote{The extension
405 % `|.tex|' may be omitted, so \back:|xopenlib foo;|
406 % is the same as \back:|xopenlib foo.tex;|.}
407 % is a data file.
408 % The semicolon `|;|' is mandatory.
409 %
410 % The commands |\xget|, |\xkill|, etc.,
411 % in the previous section play no rule with the data file.
412 % They just tell |\xopenlib| that the `|bxx|' should be got/ignored.
413 % It's |\xopenlib| that opens the data file, looks for the `|bxx|'
414 % and does many other things. So if you want to |\xget{1,3,2}|,
415 % the really code is
416 % \begin{center}
417 % |\xget{1,3,2}| |\xopenlib foo;|
418 % \end{center}
419 % See subsection \ref{ssec:xlib} for a trick.
420 %
421 % \subsection{Specifying the default data file}
422 % \label{ssec:xlib}
423 %
424 % \DescribeMacro{\xlib}
425 % It's convenient to specify a default data file. Let's do it by
426 % \begin{center}
427 % |\xlib foo;|
428 % \end{center}
429 % The file extension `|.tex|' can be omitted.
430 %
431 % \trick:
432 % After specifying the default data file, you can open that file by
433 % \begin{center}
434 % |\xopenlib;|
435 % \end{center}
436 %
437 % \subsection{Getting orderly the data items}
438 % \label{ssec:xspec}
439 %
440 % Do you have any questions about the order of the `bxx's?
441 %
442 % Yes, if you had, the answer is:
443 % the calling of |\xget|, |\xgetall|, |\xkill|, etc.,
444 % will produce the output in which the order of the data items
445 % is same as the order of data items in the data file.
446 % More concretely, if in `|foo.tex|' you specify
447 % \begin{verbatim}
448 % \bxx 15;
449 % ITEMA.
450 % \exx
451 % \bxx 14;
452 % ITEMB.
453 % \exx
454 % \end{verbatim}
455 % then |\xget{14,15}| |\xopenlib foo;|\\
456 % or\phantom{en} |\xget{15,14}| |\xopenlib foo;|\\
457 % gives the same results:
458 % `|ITEMA|' is put before `|ITEMB|'.
459 %
460 % So we need the macro described below.
461 %
462 % \DescribeMacro{\xspec}
463 % Syntax (same as |\xget|)
464 % \begin{center}
465 % |\xspec(#env){#ID-list}|
466 % \end{center}
467 % |(#env)| is also an optional parameter.
468 %
469 % This macro opens the data file (so you needn't to
470 % specify a |\xopenlib...| after it), extract the data items
471 % from the data file within the order in the |#ID-list|.
472 %
473 % So if you want to put `|ITEMB|' before the `|ITEMA|'
474 % (see above example), you should call
475 % \begin{center}
476 % |\xspec{14,15}|
477 % \end{center}
478 %
479 % \section{Advanced features}
480 %
481 % \subsection{Enabling/Disabling section in data file}
482 %
483 % A data file may be divided into sections.
484 % But when looking for data file, this package
485 % will be typeset normally anything that isnot inside any a `|bxx|'
486 % (for e.g, a |\section| command),
487 % so you can see some strange outputs.
488 %
489 % \DescribeMacro{\xenablesection}
490 % \DescribeMacro{\xdisablesection}
491 % Syntax
492 % \begin{center}
493 % |\xdisablesection|\\|\xenablesection|
494 % \end{center}
495 % The first macro disables three commands
496 % \begin{center}
497 % |\section| |\subsection| |\subsubsection|
498 % \end{center}
499 % The second enables three above section commands
500 % by restoring them to the values that this package
501 % captured at the beginning of the document.
502 % (So if you redefine a section command inside
503 % |\begin{document}| and |\end{document}|,
504 % you may lost that new command after using the sequence
505 % |\xdisablesection| |\xenablesection|.
506 %
507 % {\bf NOTE:}
508 %
509 % |\xdisablesection| cannot disable the command
510 % \begin{center}
511 % |\section[optional]{...}|
512 % \end{center}
513 %
514 % \subsection{Data item followed by `hint' environment}
515 %
516 % \DescribeEnv{hint}
517 % If a data item, or a `|bxx|', in data file is an exercise,
518 % it is often followed by a hint (a solution).
519 % All the hints should be collected in a private place.
520 % The `|hint|' environment helps you in this behaviour.
521 % You put `|hint|' just after the declaration of a data item,
522 % like this
523 % \begin{verbatim}
524 % \bxx 100;
525 % This is Exercise A
526 % \exx
527 % \begin{hint}
528 % This is the hint of excercise A.
529 % \end{hint}
530 % \end{verbatim}
531 % When you get the above `|bxx|', for e.g., by |\xget{100}|,
532 % the content of the hint, here's \emph{\lq\lq This is the hint...\rq\rq}
533 % will be written automatically to a file called `|hintfile|'.
534 %
535 % \DescribeMacro{\xopenhint}
536 % If you want to open the hint file, just call
537 % \begin{center}
538 % |\xopenhint|
539 % \end{center}
540 %
541 % {\bf IF YOU WANT TO KNOW MORE...}
542 %
543 % The `|hintfile|' is really a data file, whose name is
544 % \begin{center}
545 % |\jobname.KTVhint|
546 % \end{center}
547 % |\jobname| is the name of current job,
548 % and `|.KTVhint|' is the extension\footnote{If your system
549 % doesnot support the long extension file name,
550 % please report to the author.} provided by the author.
551 %
552 % By default, all the contents
553 % of the `|hintfile|' will be loaded (|\xgetall|).
554 %
555 % It's too complex to explain the structure of the `|hintfile|'.
556 % Let's typset the test, look for the `|hintfile|'
557 % and the results for more details. Thank you!
558 %
559 % \section{Important notes (to the users)}
560 %
561 % \begin{itemize}
562 % \item[a)]
563 % (bug)
564 % You must put |\xenv(#env)| before any calling |\xget|, |\xkill|, etc.
565 % Try this bug to know how the package works.
566 % \item[b)]
567 % Donot put |\xdisablesection| just before |\tableofcontents|.
568 % (Otherwise, an error will be reported.)
569 % \item[c)]
570 % The environment(s) of the data items in the data file must be predefined.
571 % \item[d)]
572 % |\xopenhint| should be called at the very end of the document,
573 % and must be called after any |\xspec|, |\xopenlib| commands.
574 % (|\xopenhint| will closed the `|hintfile|';
575 % after that the writting operations have no effect on this file.)
576 % \item[e)]
577 % (bug)
578 % Labelling the `|bxx|' maynot work well.
579 % If you try to load twice a `|bxx|',
580 % then two loadings will have a same label.
581 % In next version, we will redefine the |\label| and |\ref| to fix this bug.
582 % \end{itemize}
583 %
584 %
585 % \section{Generating package and example}
586 %
587 % Excuting
588 % \begin{center}
589 % {{\bf latex} \ttfamily ktv-texdata.ins}
590 % \end{center}
591 % to generate the package ({\tt ktv-texdata.sty})
592 % and a test
593 % ({\it two files:} {\tt ktv-test.tex}; {\tt ktv-data.tex}).
594 % Then typeset file {\ttfamily ktv-test.tex}.
595 %
596 % \section{Implementation}
597 %
598 % \subsection{Notes}
599 %
600 % \emph{The implementation} is the document
601 % {\bf used only} by the package's hacker!!!
602 %
603 % This package is written by |top-down| technique:
604 % A macro |\fooA| sometimes calls the macro |\fooB|
605 % whose the definitions appears after the defintions of |\fooA|.
606 %
607 % This package uses some advanced and interesting macro techniques
608 % (\emph{unknown-number-of-parameters-macro},
609 % \emph{two-optional-parameters-macro}, and much more).
610 % If you're a newbie of \LaTeX\ programming,
611 % you will learn some new things by learning the code of package.
612 %
613 % \subsection{Requirements. Options}
614 %
615 % \begin{macrocode}
616 %<*package>
617 \RequirePackage{verbatim}
618 % \end{macrocode}
619 %
620 % \begin{macro}{\@@xdetail}
621 % This macro shows \emph{string-id} of the current `|bxx|'
622 % on the margin.
623 % \begin{macrocode}
624 \def\@@xdetail{\marginpar{{\bf\@xenv}\@xlbl}}
625 % \end{macrocode}
626 % \end{macro}
627 %
628 % \begin{environment}{detailon}
629 % |detailon| is the default option.
630 % Anything else means |detailoff|.
631 % \begin{macrocode}
632 \DeclareOption{detailon}{\let\@xdetail\@@xdetail}
633 \DeclareOption*{\let\@xdetail\relax}
634 \ExecuteOptions{detailon}
635 \ProcessOptions
636 % \end{macrocode}
637 % \end{environment}
638 %
639 % \subsection{General purpose macros}
640 %
641 % \begin{macro}{\b@sy}
642 % |\b@sy| means `not |\relax|'.
643 % \begin{macrocode}
644 \def\b@sy{}
645 % \end{macrocode}
646 % \end{macro}
647 %
648 % \begin{macro}{\if@xNIL}
649 % Check if string |#1| is empty.
650 %
651 % \begin{macrocode}
652 \def\if@xNIL#1;{\ifx\relax#1\relax}
653 % \end{macrocode}
654 % \end{macro}
655 %
656 % \subsection{Scanning and setting flag for \emph{string-id}}
657 % \label{ssec:scanning}
658 %
659 % First, consider the example when the user calls
660 % \begin{center}
661 % |\xget(exercise){ex:1,-ex:3,ex:5,ex:7,ex:9,ex:11,ex:13,ex:15}|
662 % \end{center}
663 % Here he (the user) wants to get the `|bxx|'
664 % that is numbered oddly,
665 % and that uses the environment `|exercise|'
666 % from the data file
667 % (\underline{\bf but} he doesn't want to get |ex:3|).
668 %
669 % Because the number of exercises he wants to get is unknown
670 % (he just specifies a list of the items he needs),
671 % we must design a macro that scans for all the items in the list.
672 % Moreover, this macro will set the flag `|get|' or `|donotget|'
673 % for each item (in the above example, the flag for |ex:3|
674 % is `|donotget|', for the others is `|get|').
675 %
676 % \begin{macro}{\usr@xenv}
677 % \begin{macro}{\usr@xlbl}
678 % These macros are used to store the result of the scanning.
679 % \begin{macrocode}
680 \def\usr@xenv{}
681 \def\usr@xlbl{}
682 % \end{macrocode}
683 % \end{macro}
684 % \end{macro}
685 %
686 % \begin{macro}{\@multact}
687 % Scan and set the flag (|get|, |donotget|) for the items of a list.
688 % The syntax is
689 % \begin{center}
690 % |\@multact(#usr-env){#ID-list}|
691 % \end{center}
692 % where |#ID-list| is a list of |ID|(s)\footnote{%
693 % see subsection \ref{ssec:bxx.form}.}
694 % that're seperated by the comma (`|,|').
695 % Moreover, each |ID| can be prefixed by a plus/minus sign (|+|, |-|).
696 % \begin{center}
697 % \begin{tabular}{rl}
698 % |#ID-list| &$\longrightarrow$ |XID| / |#ID-list|, |XID| \\
699 % |XID| &$\longrightarrow$ |ID| / |+ID| / |-ID|
700 % \end{tabular}
701 % \end{center}
702 % If |ID| is prefixed by a |+| (resp., a |-|), it means
703 % that this |ID| has a `{\it positive}' (resp., `{\it negative}')
704 % meaning\footnote{%
705 % If the user wants to get something,
706 % the |+| means `{\it he wants}', but |-| means `{\it he doesn't want}'.
707 % If the user doesn't want to get someting,
708 % the |+| means `{\it no, he doesn't want}',
709 % while the |-| means `{\it yes, he wants}'.}
710 % in the current context.
711 % An |ID| without prefix is the same as |+ID|.
712 %
713 % The |#usr-env| is any environment (maynot be predefined).
714 % This |#usr-env| is concatenated with every |ID| in the |#ID-list|.
715 % The concatenation will create the \emph{string-id}(s)
716 % for which we will later set the flag.
717 %
718 % Here we use (|#usr-env|) instead of (|#env|)
719 % because the environment |#usr-env| is used at the time the user
720 % wants to \emph{get some thing} from the data file (for e.g.,
721 % by the command |\xget{ex:1,ex:2}|).
722 % This environment may be different from the environment we
723 % specify in the data file, it maynot even be predefined.
724 %
725 % Note that |(#usr-env)| is optional parameter of macro |\@multact|.
726 % In case that |(#usr-env)| is omitted,
727 % |#usr-env| will get the default value saved in |\@@xenv|.
728 % \begin{macrocode}
729 \def\@multact{\futurelet\@tchar\chk@multact}
730 % \end{macrocode}
731 % We first check if the next char is a `|(|'.
732 % \begin{macrocode}
733 \def\chk@multact{%
734 \ifx(\@tchar
735 \let\@txen\opt@multact
736 \else
737 \let\@txen\nop@multact
738 \fi
739 \@txen}
740 % \end{macrocode}
741 % If the next char is a `|(|'
742 % \begin{macrocode}
743 \def\opt@multact(#1)#2{%
744 \def\usr@xenv{#1}%
745 % \end{macrocode}
746 % then read the |#ID-list| by calling |\@xmultarg|%
747 % (see subsection \ref{ssec:ID.extract} below)
748 % \begin{macrocode}
749 \@xmultarg{#2}}
750 % \end{macrocode}
751 % If the next char is not a `|(|', |\usr@xenv| gets the default value
752 % \begin{macrocode}
753 \def\nop@multact#1{%
754 \def\usr@xenv{\@@xenv}
755 % \end{macrocode}
756 % then read the |#ID-list| by calling |\@xmultarg|
757 % \begin{macrocode}
758 \@xmultarg{#1}}
759 % \end{macrocode}
760 % \end{macro}
761 %
762 % \subsection{Extracting ID from the \#ID-list}
763 % \label{ssec:ID.extract}
764 %
765 % \begin{macro}{\@action}
766 % |\@action| is \emph{something} we want to affect
767 % each \emph{string-id}\footnote{\emph{string-id}%
768 % is created by concatenation |\#usr-env| and |ID|.
769 % See subsection \ref{ssec:bxx.identify}.
770 % } found.
771 % We first let |\@action| to |\relax|,
772 % so we avoid seeing the error `|! Undefined control...|'.
773 % (This letting existed in some previous versions of package.
774 % Now the author doesnot know what's going on if this line is removed!)
775 % \begin{macrocode}
776 \let\@action\relax
777 % \end{macrocode}
778 % \end{macro}
779 % \begin{macro}{\@@MINUS}
780 % \begin{macro}{\@@MINUS}
781 % \begin{macro}{\@@ZERO}
782 % There are three kinds of actions
783 % (|plus| action, |minus| action, and |nosign| action).
784 % We'll see in subsection \ref{ssec:action.collection} that
785 % every action is named `|MINUS|\emph{something}',
786 % or `|ZERO|\emph{something}', or `|PLUS|\emph{something}'.
787 % \begin{macrocode}
788 \def\@@MINUS{MINUS}
789 \def\@@PLUS{PLUS}
790 \def\@@ZERO{ZERO}
791 % \end{macrocode}
792 % \end{macro}
793 % \end{macro}
794 % \end{macro}
795 %
796 % \begin{macro}{\@xmultarg}
797 % |\@xmultarg| is used to extract the |ID|(s) from the |#ID-list|.
798 % Here we use the macro technique specified in \cite{VE}.
799 % First, we add to the argument |#1| the terminator\footnote{Because
800 % that `|@|' is never used to create an |ID|,
801 % the terminator `|@@@|' works well.} |\@endlbl| (`|@@@|').
802 % Then we call |\@@xmultarg|.
803 % \begin{macrocode}
804 \def\@xmultarg#1{\@@xmultarg#1,@@@,}
805 \def\@endlbl{@@@}
806 % \end{macrocode}
807 % \end{macro}
808 % \begin{macro}{\@@xmultarg}
809 % Now is the extracting.
810 % \begin{macrocode}
811 \def\@@xmultarg#1,{%
812 \def\@xtempi{#1}
813 \ifx\@endlbl\@xtempi
814 % do nothing
815 \else\@@@xmultarg#1,
816 \expandafter\@@xmultarg
817 \fi}
818 % \end{macrocode}
819 % \end{macro}
820 % \begin{macro}{\@@@xmultarg}
821 % Every |ID| extracted will be concatenated
822 % with the |#usr-env| to create the \emph{string-id}.
823 % The \emph{string-id} will be affected
824 % by one of three actions (|plus|, |minus| or |nosign|/|zero|).
825 % We first check the sign of the |ID| in the |#ID-list|.
826 % \begin{macrocode}
827 \def\@@@xmultarg{\futurelet\@tchar\chk@@@xmultarg}
828 \def\chk@@@xmultarg{% 2003/05/14
829 \ifx-\@tchar\relax
830 \let\@txen\@@MINUS
831 \else\ifx+\@tchar\relax
832 \let\@txen\@@PLUS
833 \else
834 \let\@txen\@@ZERO
835 \fi
836 \fi
837 % \end{macrocode}
838 % To affect |\@action| on the \emph{string-id},
839 % we must specify `|type|' of the action.
840 % The type is saved in |\@txen| (see previous codes).
841 % \begin{macrocode}
842 \csname\@txen\@action\endcsname}
843 % \end{macrocode}
844 % \end{macro}
845 %
846 % \subsection{Comment creator macro}
847 %
848 % \begin{macro}{\c@mm@nt}
849 % If we donot want to get a `|bxx|' from the data file,
850 % we just let temporarily macro `|\bxx|' to `|\c@mm@nt|'.
851 % This macro scans and passes (or {\it ignore})
852 % the input \emph{line by line}, until it finds the fisrt `|\exx|'.
853 % That's why every `|bxx|' must be ended by a `|\exx|' in a single line!
854 % And that's why `|bxx|' cannot be nested!
855 % \begin{macrocode}
856 \gdef\c@mm@nt{%
857 \begingroup
858 \catcode`\^^M=12 %
859 \x@comment}
860 {\catcode`\^^M=12 \endlinechar=-1 %
861 \gdef\x@comment#1^^M{%
862 \def\@xtest{#1}%
863 \ifx\@xtest\exx
864 \let\@txen=\endgroup
865 \else
866 \let\@txen\x@comment
867 \fi
868 \@txen}}
869 % \end{macrocode}
870 % \end{macro}
871 %
872 % \subsection{Hint file. Hint creator environment}
873 %
874 % An exercise, for e.g., may be followed by a hint (or a solution).
875 % In a test, a book of excercises,
876 % all hints should be collected in a single file
877 % (named `|hint file|') that is genererated automatically by the package.
878 % The |hint file| is also a data file; of course, it contains
879 % only the hint that follows the `|bxx|' we want to get from the data file
880 % (the \emph{active} `|bxx|'s).
881 %
882 % Because a hint sometimes will be disabled,
883 % we need a boolean test |\if@xhint|.
884 % \begin{macrocode}
885 \newif\if@xhint
886 % \end{macrocode}
887 % The name of hint file is `|\jobname.KTVhint|'.
888 % \begin{macrocode}
889 \newwrite\@xfhint
890 \immediate\openout\@xfhint=\jobname.KTVhint
891 % \end{macrocode}
892 % We put some information in the first two lines of hint file.
893 % \begin{macrocode}
894 {\catcode`\%=12
895 \immediate\write\@xfhint{%% File created automatically by `ktv-texdata'.}
896 \immediate\write\@xfhint{%% DONOT EDIT THIS FILE MANUALLY.}}
897 % \end{macrocode}
898 %
899 % \begin{environment}{hint}
900 % Here is a trick about `hint' environment.
901 % We collect hints in a same file.
902 % So we need something to know exactly what `|bxx|'
903 % a `hint' (in the hint file) associates with.
904 % \emph{So.... we assume} that `|#env|'
905 % specified in `|bxx|' (in the data file) is a numberable environment.
906 % Then when a `hint' follows a `|bxx|' (named |bxxA|) is written to hint file,
907 % its number is the same as the number of `|bxx|A' in the output.
908 % So we need a counter\footnote{Please try to figure out this counter.}
909 % to index the active `|bxx|'.
910 % \begin{macrocode}
911 \newcount\c@bxx
912 % \end{macrocode}
913 % \begin{macrocode}
914 \newenvironment{hint}{% begin-part of `hint'
915 % \end{macrocode}
916 % If the hint is enabled
917 % \begin{macrocode}
918 \if@xhint
919 \let\exx\relax
920 % \end{macrocode}
921 % In the numbered environment `|#env|',
922 % \LaTeX\ automatically creates a counter\footnote{%
923 % We should not check for the existing of this counter:
924 % the checking may eat so much time!}%
925 % named `|c@#env|'.
926 % We let `|c@bxx|' to the current value of `|c@#env|',
927 % then subtract `|c@bxx|' by 1 (\LaTeX\ will increase `|c@bxx|' later).
928 % We create an data item in the hint file,
929 % whose \emph{string-id} is the same as the current `|bxx|'.
930 % \begin{macrocode}
931 \c@bxx=\csname c@\@xenv\endcsname%
932 \advance\c@bxx by-1 %
933 \immediate\write\@xfhint{\string\setcounter{\@xenv}{\the\c@bxx}}
934 \immediate\write\@xfhint{\string\bxx(\@xenv)\@xlbl;}
935 % \end{macrocode}
936 % The contents of the hint environment now will be written to the hint file.
937 % \begin{macrocode}
938 \let\do\@makeother\dospecials\catcode`\^^M\active%
939 \def\verbatim@processline{%
940 \immediate\write\@xfhint{\the\verbatim@line}}%
941 \expandafter\verbatim@start
942 % \end{macrocode}
943 % If the hint is disable, let it start a comment environment.
944 % Here we use `|\comment|' defined in |verbatim| package,
945 % not the `|\c@mm@nt|' defined in this package\protect\footnote{%
946 % \emph{A fun story:} in the first version of package, the author
947 % used `\back:|comment|' by a mistake, but package ran very well.
948 % He later found this error, and changed `\back:|comment|'
949 % to `\back:|c@mm@nt|', then the package dumped into the errors!}.
950 % \begin{macrocode}
951 \else
952 \def\exx{\exx}%
953 \expandafter\comment
954 \fi}%
955 % \end{macrocode}
956 % Now the end-part of hint environment. If the hint is enabled,
957 % we put an `|\exx|' to terminate `|\bxx|' in the hint file.
958 % The line |\noexpand\exx| was added here but the author forgot the reason.
959 % Please help him!
960 % \begin{macrocode}
961 {%
962 \noexpand\exx
963 \if@xhint
964 \immediate\write\@xfhint{\string\exx}
965 \fi}
966 % \end{macrocode}
967 % \end{environment}
968 %
969 % \subsection{Replacements of macro \back:bxx}
970 %
971 % Macro |\bxx| will be replaced by one of these macros
972 % |\@bxx|, |\@bxy|, |\@ball|, |\@bnone|, |\@bnonebut|, |\@ballbut|.
973 % The replacement depends on what the macro |\xgetfoo|, |\xkillfoo|, ...
974 % are specified by the user.
975 %
976 % For e.g., if the user calls |\xgetall|,
977 % then |\bxx| is replaced by |\@ball|;
978 % if they call |\xkillall|, then |\@bnone| takes place.
979 %
980 % For more details about the replacement,
981 % see the definition of |\xget|, |\xgetall|, |\xkill|, |xkillall|, etc.
982 % in the subsection \ref{ssec:user.macros}.
983 %
984 % Here's the summary of the replacements.
985 % \begin{center}
986 % \begin{tabular}{rl}
987 % {Calling } & {The replacement of |\bxx|}
988 % \\[3mm]\hline\\
989 % |\xget| & |\@bxx|\\
990 % |\xgetall| & |\@ball|\\
991 % |\xgetallbut| & |\@ballbut|\\[3mm]
992 % |\xkill| & |\@bxx|\\
993 % |\xkillall| & |\@bnone|\\
994 % |\xkillallbut| & |\@bnonebut|\\[3mm]
995 % |\xspec| & |\@bxy|
996 % \\\\\hline
997 % \end{tabular}
998 % \end{center}
999 %
1000 % The common syntax for the macros |\@bfoo| is
1001 % \begin{center}
1002 % |\@bfoo(#env)[#thm]{#ID}|;
1003 % \end{center}
1004 % Here |#thm| is the optional argument of the environment |#env|.
1005 % Both `|[#thm]|' and `|(#env)|' are the optional parameters
1006 % of the |\@bfoo| (this means you can omit `|[#thm]|' or `|(#env)|'
1007 % or both of them while callling `|\@bfoo|').
1008 % \begin{macro}{\@bxx, \@bxy}
1009 % Each macro |\@bxx|, |\@bxy| does two things.
1010 %
1011 % \emph{Firstly,} it gets the information about the current `|bxx|'
1012 % (information contains: |#env|, |#thm| and |#ID|).
1013 % We use the |\@bxxarg| macro .
1014 %
1015 % \emph{Secondly,}
1016 % it calls |\@bfoodone| to typeset the content of the `|bxx|'.
1017 % \begin{macrocode}
1018 \def\@bxx#1;{%
1019 \@bxxarg#1;%
1020 \@bxxdone}
1021 \def\@bxy#1;{%
1022 \@bxxarg#1;%
1023 \@bxydone}
1024 % \end{macrocode}
1025 % \end{macro}
1026 % \begin{macro}{\@ball}
1027 % Macro |\@ball| first gets the information about the `|bxx|'
1028 % (like |\@bxx|), but then it calls `|\@bdone@kern|',
1029 % the kernel of the |\@bdone|.
1030 % \begin{macrocode}
1031 \def\@ball#1;{%
1032 \@bxxarg#1;%
1033 \@bdone@kern}
1034 % \end{macrocode}
1035 % \end{macro}
1036 % \begin{macro}{\@bnone}
1037 % Macro |\@bnone| starts the comment by calling |\c@mm@nt|.
1038 % This macro also disable the hint environment that follows the `|bxx|'.
1039 % \begin{macrocode}
1040 \def\@bnone#1;{%
1041 \@xhintfalse
1042 \def\exx{\exx}
1043 \expandafter\c@mm@nt}
1044 % \end{macrocode}
1045 % \end{macro}
1046 % \begin{macro}{\@bnonebut}
1047 % Macro |\@bnonebut| ignores the contents of the `|bxx|'
1048 % if and only if the command `|\csname\@xenv\@xlbl\endcsname|'
1049 % equals to `|\relax|'.
1050 %
1051 % First, the macro scans for information.
1052 % \begin{macrocode}
1053 \def\@bnonebut#1;{%
1054 \@bxxarg#1;%
1055 % \end{macrocode}
1056 % Then it checks the status of the command
1057 % `|\csname\@xenv\@xlbl\endcsname|'.
1058 % If this command is undefined, we turn off the next `hint'
1059 % and start the comment command (to ignore the content of the `|bxx|').
1060 % \begin{macrocode}
1061 \expandafter\ifx\csname\@xenv\@xlbl\endcsname\relax
1062 \@xhintfalse
1063 \def\exx{\exx}
1064 \expandafter\c@mm@nt
1065 % \end{macrocode}
1066 % If this command is defined, the contents of the
1067 % `|bxx|' will be typeset. Before calling `|\@bdone@kern|',
1068 % we let the status of the command `|...\@xenv\@xlbl...|'
1069 % to `|\relax|'. By doing this, we ensure that two `|bxx|'s in the
1070 % data file that have the same \emph{string-id} will be typeset only once.
1071 % \begin{macrocode}
1072 \else
1073 \expandafter\let\csname\@xenv\@xlbl\endcsname\relax
1074 \expandafter\@bdone@kern
1075 \fi}
1076 % \end{macrocode}
1077 % \end{macro}
1078 % \begin{macro}{\@ballbut}
1079 % Macro |\@ballbut| is inverse from the macro `|\@bnonebut|'.
1080 % \begin{macrocode}
1081 \def\@ballbut#1;{%
1082 \@bxxarg#1;
1083 \expandafter\ifx\csname\@xenv\@xlbl\endcsname\relax
1084 \expandafter\@bdone@kern
1085 \else
1086 \expandafter\let\csname\@xenv\@xlbl\endcsname\relax
1087 \@xhintfalse
1088 \def\exx{\exx}
1089 \expandafter\c@mm@nt
1090 \fi}
1091 % \end{macrocode}
1092 % \end{macro}
1093 %
1094 % \subsection{Getting information from `bxx'}
1095 %
1096 % \begin{macro}{\@bxxarg}
1097 % This macro reads the information about the `|bxx|'.
1098 % The information contains |#env| (saved in `|\@xenv|'),
1099 % |#thm| (saved in `|\xhead|'), |#ID| (saved in `|\xlbl|').
1100 %
1101 % We first set the initial value for three macros:
1102 % \begin{macrocode}
1103 \def\@xenv{}
1104 \def\@xhed{}
1105 \def\@xlbl{}
1106 % \end{macrocode}
1107 % We define two macros that save the default values
1108 % for the |#env| and |#thm|. The default value of |#thm|
1109 % should be null (why?). Now the default |#thm|
1110 % is aslo null, but in the subsection \ref{ssec:user.macros},
1111 % we define macro |\xenv| to change this behaviour.
1112 % \begin{macrocode}
1113 \def\@@xenv{}
1114 \def\@@xhed{}
1115 % \end{macrocode}
1116 % Now we define |\@bxxarg|.
1117 % \begin{macrocode}
1118 \def\@bxxarg{\futurelet\@tchar\chk@bxxarg}
1119 % \end{macrocode}
1120 % We check if the next char is a `|(|'.
1121 % \begin{macrocode}
1122 \def\chk@bxxarg{%
1123 \ifx(\@tchar
1124 \let\@txen\env@bxxarg
1125 \else
1126 \let\@txen\nop@bxxarg
1127 \fi
1128 \@txen}
1129 % \end{macrocode}
1130 % If the next char is a `|(|', we hope that
1131 % the `|bxx|' specifies the `|(#env)|'.
1132 % Here the author uses an `|\edef|', but he really
1133 % doesnot know the reasons.
1134 % The `|\def|' version sometimes causes a strange error.
1135 % \begin{macrocode}
1136 \def\env@bxxarg(#1)#2;{%
1137 \edef\@xenv{#1}%
1138 % \end{macrocode}
1139 % Now we look for the rest of the argument by calling |\@@bxxarg|.
1140 % \begin{macrocode}
1141 \@@bxxarg#2;}
1142 % \end{macrocode}
1143 % If the next char isnot a `|(|',
1144 % `|bxx|' uses the default environment.
1145 % \begin{macrocode}
1146 \def\nop@bxxarg#1;{%
1147 \edef\@xenv{\@@xenv}%
1148 % \end{macrocode}
1149 % Now we look for the rest of the argument (call |\@@bxxarg|).
1150 % \begin{macrocode}
1151 \@@bxxarg#1;}
1152 % \end{macrocode}
1153 % \end{macro}
1154 % \begin{macro}{\@@bxxarg}
1155 % The calling of |\@@bxxarg| will first check if
1156 % the next char is a `|[|'.
1157 % \begin{macrocode}
1158 \def\@@bxxarg{\futurelet\@tchar\chk@@bxxarg}
1159 % \end{macrocode}
1160 % \begin{macrocode}
1161 \def\chk@@bxxarg{%
1162 \ifx[\@tchar
1163 \let\@txen\hed@@bxxarg
1164 \else
1165 \let\@txen\nop@@bxxarg
1166 \fi
1167 \@txen}
1168 % \end{macrocode}
1169 % If the next char is a `|[|',
1170 % we hope that `|bxx|' specifies the `|[#thm]|'
1171 % \begin{macrocode}
1172 \def\hed@@bxxarg[#1]#2;{%
1173 \edef\@xhed{#1}%
1174 \edef\@xlbl{#2}}
1175 % \end{macrocode}
1176 % If the next char isnot a `|[|', the `|#thm|' gets the default value.
1177 % \begin{macrocode}
1178 \def\nop@@bxxarg#1;{%
1179 \edef\@xhed{\@@xhed}%
1180 \edef\@xlbl{#1}}
1181 % \end{macrocode}
1182 % \end{macro}
1183 %
1184 % \subsection{Typesetting the content of `bxx'}
1185 %
1186 % \begin{macro}{\@bxxdone}
1187 % This macro starts a |\c@mm@nt| (if the command
1188 % `|...\@xenv\@xlbl...|' is `|\relax|'),
1189 % or calls |\@bdone@kern| (the kernel of the |\@bxxdone|).
1190 % \begin{macrocode}
1191 \def\@bxxdone{%
1192 \expandafter\ifx\csname\@xenv\@xlbl\endcsname\relax
1193 \@xhintfalse
1194 \def\exx{\exx}
1195 \expandafter\c@mm@nt
1196 \else
1197 \expandafter\let\csname\@xenv\@xlbl\endcsname\relax
1198 \expandafter\@bdone@kern
1199 \fi}
1200 % \end{macrocode}
1201 % \end{macro}
1202 %
1203 % \begin{macro}{\@bdone@kern}
1204 % This macro typesets the contents of the `|bxx|'
1205 % by starting the environment `|#env|'. It also turns on the
1206 % next hint environment.
1207 %
1208 % If the `|bxx|' specifies the `|#thm|',
1209 % we should call `|\begin{#env}[#thm]|';
1210 % otherwise, we just call `|\begin{#env}|'.
1211 % (Then the `|\exx|' equals to `|\end{#env}|'.)
1212 %
1213 % \emph{Note that} `|\begin{#env}[]|' is different from `|\begin{#env}|.
1214 % So we must check if the `|#thm|' is empty.
1215 % \begin{macrocode}
1216 \def\@bdone@kern{%
1217 \@xhinttrue%
1218 \def\exx{\end{\@xenv}}
1219 \expandafter\if@xNIL\@xhed;
1220 \def\@txen{%
1221 \begin{\@xenv}\@xdetail}
1222 \else
1223 \def\@txen{%
1224 \begin{\@xenv}[\@xhed]\@xdetail}
1225 \fi
1226 \@txen}
1227 % \end{macrocode}
1228 % \end{macro}
1229 %
1230 % \begin{macro}{\@bxydone}
1231 % This macro just passes the arguments to |\@bxy@kern|.
1232 % \begin{macrocode}
1233 \def\@bxydone{\@bxy@kern(\@xenv){\@xlbl}}
1234 % \end{macrocode}
1235 % \end{macro}
1236 %
1237 % \begin{macro}{\@bxy@kern}
1238 % This macro is the kernel of |\@bxydone|.
1239 % It opens the data file, searchs for the `|bxx|'
1240 % whose \emph{string-id} is `|\@bxy@id|'.
1241 % If such `|bxx|' is found, the macro stops the seaching\footnote{%
1242 % We really donot stop the searching. We just ignore the other
1243 % `|bxx|'(s) in the data file.
1244 % \emph{Trick:} Each time this macro opens the data file,
1245 % it gets at most one data item,
1246 % while, for e.g., \back:|\@bdone@kern| may get more than one.}
1247 % and calls `|\@bdone@kern|' to typeset the contents of that `|bxx|'.
1248 % Any `|bxx|' in the data file whose \emph{string-id} doesnot match
1249 % the string saved in |\@bxy@id| will be ignored.
1250 %
1251 % Because a \emph{string-id} never accepts the value `@',
1252 % we just let |\@bxy@id| to `@' to stop the searching.
1253 % \begin{macrocode}
1254 \def\@bxy@id{@}
1255 \def\@bxy@kern(#1)#2{%
1256 \edef\@xtempi{#1#2}
1257 \ifx\@bxy@id\@xtempi
1258 \def\@bxy@id{@}
1259 \expandafter\@bdone@kern
1260 \else
1261 \@xhintfalse
1262 \def\exx{\exx}
1263 \expandafter\c@mm@nt
1264 \fi}
1265 % \end{macrocode}
1266 % \end{macro}
1267 %
1268 % \begin{macro}{\@xspec@i}
1269 % If you read the above codes carefully,
1270 % you donot see anything about the `\emph{openning the data file}'.
1271 % Yes, the truth is that |\@bxy|, |\@bxydone| and aslo |\@bxy@kern|
1272 % are always used within the |\@xspec@i|.
1273 % This macro does the openning.
1274 % \begin{macrocode}
1275 \def\@xspec@i(#1)#2{
1276 \let\bxx\@bxy
1277 \edef\@bxy@id{#1#2}
1278 % \end{macrocode}
1279 % Now start the searching (openning)
1280 % \begin{macrocode}
1281 \input \@xlib}
1282 % \end{macrocode}
1283 % \end{macro}
1284 %
1285 % \subsection{Actions affect on the \emph{string-id}}
1286 % \label{ssec:action.collection}
1287 %
1288 % Each action |foo| must be associated with 3 routines
1289 % \begin{center}
1290 % |PLUSfoo+#1|,\,\, |MINUSfoo-#1|,\,\, |ZEROfoo#1|,
1291 % \end{center}
1292 %
1293 % \begin{macro}{@@@setflag}
1294 % The positive meanings of this action is to define the command
1295 % \begin{center}
1296 % |\csname\usr@xenv#1\endcsname|
1297 % \end{center}
1298 % by letting this command to `|\b@sy|'.
1299 % \begin{macrocode}
1300 \def\PLUS@@@setflag+#1,{%
1301 \expandafter\let\csname\usr@xenv#1\endcsname\b@sy}
1302 \def\MINUS@@@setflag-#1,{%
1303 \expandafter\let\csname\usr@xenv#1\endcsname\relax}
1304 \def\ZERO@@@setflag#1,{%
1305 \expandafter\let\csname\usr@xenv#1\endcsname\b@sy}
1306 % \end{macrocode}
1307 % \end{macro}
1308 %
1309 % \begin{macro}{@@@killflag}
1310 % The positive meanings of this action is to undefine the command
1311 % \begin{center}
1312 % |\csname\usr@xenv#1\endcsname|
1313 % \end{center}
1314 % by letting this command to `|\relax|'.
1315 % \begin{macrocode}
1316 \def\PLUS@@@killflag+#1,{%
1317 \expandafter\let\csname\usr@xenv#1\endcsname\relax}
1318 \def\MINUS@@@killflag-#1,{%
1319 \expandafter\let\csname\usr@xenv#1\endcsname\b@sy}
1320 \def\ZERO@@@killflag#1,{%
1321 \expandafter\let\csname\usr@xenv#1\endcsname\relax}
1322 % \end{macrocode}
1323 % \end{macro}
1324 %
1325 % \begin{macro}{@@@xspec}
1326 % This action associates with the |\xspec| (see subsection
1327 % \ref{ssec:user.macros} for details).
1328 % This action, unlike |@@@killflag| nor |@@@setflag|,
1329 % doesnot define/undefine the command `|...\usr@xenv#1...|'.
1330 % The positive meaning of this action is
1331 % \emph{openning data file
1332 % and getting the specified {\normalfont `|bxx|'}}.
1333 % \begin{macrocode}
1334 \def\PLUS@@@xspec+#1,{%
1335 \@xspec@i(\usr@xenv){#1}}
1336 \def\MINUS@@@xspec-#1,{}
1337 \def\ZERO@@@xspec#1,{%
1338 \@xspec@i(\usr@xenv){#1}}
1339 % \end{macrocode}
1340 % \end{macro}
1341 %
1342 % \subsection{Openning the data file}
1343 % \label{ssec:data.file.open}
1344 %
1345 % \begin{macro}{\@xlib}
1346 % \begin{macro}{\@@xlib}
1347 % |\@xlib| stores the data file specified by users.\\
1348 % |\@@xlib| stores the data file used by the |\@openlib|.\\
1349 % Currently, two macros save the null values.
1350 % \begin{macrocode}
1351 \def\@xlib{}
1352 \def\@@xlib{}
1353 % \end{macrocode}
1354 % \end{macro}
1355 % \end{macro}
1356 %
1357 % \begin{macro}{\@openlib}
1358 % Open the data file. The syntax of this macro is |\@openlib#1;|,
1359 % where |#1| is the file name. If |#1| is omitted, the |\@openlib|
1360 % uses the data file whose name is stored in |\@xlib|. Note that
1361 % in this case, the calling of macro is |\@openlib;|.
1362 % \begin{macrocode}
1363 \def\@openlib#1;{%
1364 \if@xNIL#1;
1365 \expandafter\if@xNIL\@xlib;
1366 % do nothing
1367 \else
1368 \def\@@xlib{\@xlib}
1369 \fi
1370 \else
1371 \def\@@xlib{#1}
1372 \fi
1373 \input \@@xlib}
1374 % \end{macrocode}
1375 % \end{macro}
1376 %
1377 % \subsection{User's macros}
1378 % \label{ssec:user.macros}
1379 %
1380 % \begin{macro}{\xspec}
1381 % This macro provides a special ways to read the data file.
1382 % After its scanning the data file, the order of the `|bxx|'s in the
1383 % ouput is the same the order of the |ID|s specified in the |#ID-list|.
1384 % \begin{macrocode}
1385 \def\xspec{%
1386 \def\@action{@@@xspec}%
1387 \@multact}
1388 % \end{macrocode}
1389 % \end{macro}
1390 % \begin{macro}{\xlib}
1391 % \begin{macro}{\xopenlib}
1392 % |\xlib| specifies the data file.
1393 % |\xopenlib| opens the data file.
1394 % \begin{macrocode}
1395 \def\xlib#1;{%
1396 \edef\@xlib{#1}}
1397 \let\xopenlib\@openlib
1398 % \end{macrocode}
1399 % \end{macro}
1400 % \end{macro}
1401 % \begin{macro}{\xkill}
1402 % \begin{macro}{\xkillall}
1403 % \begin{macro}{\xkillallbut}
1404 % Macro's names speak that...
1405 % \begin{macrocode}
1406 \def\xkill{%
1407 \let\bxx\@bxx
1408 \def\@action{@@@killflag}%
1409 \@multact}
1410 \def\xkillall{%
1411 \let\bxx\@bnone}
1412 \def\xkillallbut{%
1413 \let\bxx\@bnonebut
1414 \def\@action{@@@setflag}%
1415 \@multact}
1416 % \end{macrocode}
1417 % \end{macro}
1418 % \end{macro}
1419 % \end{macro}
1420 %
1421 % \begin{macro}{\xget}
1422 % \begin{macro}{\xgetall}
1423 % \begin{macro}{\xgetallbut}
1424 % Macro's names speak that...
1425 % \begin{macrocode}
1426 \def\xget{%
1427 \let\bxx\@bxx
1428 \def\@action{@@@setflag}%
1429 \@multact}
1430 \def\xgetall{%
1431 \let\bxx\@ball}
1432 \def\xgetallbut{%
1433 \let\bxx\@ballbut
1434 \def\@action{@@@setflag}%
1435 \@multact}
1436 % \end{macrocode}
1437 % \end{macro}
1438 % \end{macro}
1439 % \end{macro}
1440 %
1441 % \begin{macro}{\xhintready}
1442 % The hint file must be closed (`ready') before being opened.
1443 % \begin{macrocode}
1444 {\catcode`\%=12
1445 \gdef\xhintready{
1446 \begingroup\catcode`\%=12
1447 \immediate\write\@xfhint{\string\endinput}
1448 \immediate\write\@xfhint{%% END OF FILE %%}
1449 \endgroup\immediate\closeout\@xfhint}}
1450 % \end{macrocode}
1451 % \end{macro}
1452 %
1453 % \begin{macro}{\xopenhint}
1454 % Open the hint file.
1455 % \begin{macrocode}
1456 \def\xopenhint{%
1457 \xhintready
1458 \xgetall
1459 \xlib \jobname.KTVhint;
1460 \xopenlib;}
1461 % \end{macrocode}
1462 % \end{macro}
1463 % \begin{macro}{\xenv}
1464 % Specify the default environment.
1465 % \begin{macrocode}
1466 \def\xenv(#1){%
1467 \edef\@@xenv{#1}}
1468 % \end{macrocode}
1469 % \end{macro}
1470 %
1471 % \begin{macro}{\xdetailon}
1472 % \begin{macro}{\xdetailoff}
1473 % Turn the details on/off.
1474 % \begin{macrocode}
1475 \def\xdetailon{%
1476 \let\@xdetail\@@xdetail}
1477 \def\xdetailoff{%
1478 \let\@xdetail\relax}
1479 % \end{macrocode}
1480 % \end{macro}
1481 % \end{macro}
1482 %
1483 % \begin{macro}{\xenablesection}
1484 % \begin{macro}{\xdisablesection}
1485 % If we put some `|\section|' commands in the data file,
1486 % we may want to disable/enable them.
1487 %
1488 % First, we define a null section.
1489 % \begin{macrocode}
1490 \def\nil@section#1{}
1491 % \end{macrocode}
1492 % \end{macro}
1493 % \end{macro}
1494 % Then we save the old values of section-relatives
1495 % just before |\begin{document}|.
1496 % We mention only |\section|, |\subsection|, |\subsubsection|.
1497 % \begin{macrocode}
1498 \AtBeginDocument{%
1499 \let\old@section\section
1500 \let\old@subsection\subsection
1501 \let\old@subsubsection\subsubsection}
1502 % \end{macrocode}
1503 % Everytime you want to disable the section,
1504 % we let |\section| to |\nil@section|.
1505 % \begin{macrocode}
1506 \def\xdisablesection{%
1507 \let\section\nil@section%
1508 \let\subsection\nil@section%
1509 \let\subsubsection\nil@section}
1510 % \end{macrocode}
1511 % To restore, let |\section| to his old value
1512 % (that we captured at the beginning of document).
1513 % If you redefine |\section| inside |\begin{document}|
1514 % and |\end{document}|, you cannot get that new |\section|
1515 % after using any |\xdisablesection|.
1516 % \begin{macrocode}
1517 \def\xenablesection{%
1518 \let\section\old@section%
1519 \let\subsection\old@subsection%
1520 \let\subsubsection\old@subsubsection}
1521 % \end{macrocode}
1522 %
1523 % \subsection{Initialization}
1524 %
1525 % See section \ref{sec:history} for a reason.
1526 % \begin{macrocode}
1527 \let\bxx\@bxx
1528 % \end{macrocode}
1529 %
1530 % \begin{macrocode}
1531 %</package>
1532 % \end{macrocode}
1533 %
1534 % \section{History}
1535 % \label{sec:history}
1536 %
1537 % \begin{tabular}{ccl}
1538 % {\bf v01}.xx &2002/12/xx &the first design\\[2mm]
1539 % {\bf v02}.xx &2002/12/yy &\emph{changes forgotten}\\[2mm]
1540 % {\bf v03}.14 &2002/12/18 &the first good version\\
1541 % v03.15 &2003/03/26 &some litle changes\\
1542 % v03.17 &2003/04/19 &use two-step macro technique\\
1543 % & &|\bxx|,|\xlib|,|\xopenlib|
1544 % needn't any ended-char\\[2mm]
1545 % {\bf v04}.18 &2003/04/22 &modify: |\@bxy@kern|\\
1546 % v04.19 &2003/04/23 &change: use |\par| instead of
1547 % |\enlinechar| in def. of |\bxx|\\
1548 % v04.19 &2003/05/06 &use `|;|' as delimiter
1549 % in definition of |\bxx|\\
1550 % v04.20 &2003/05/11 &optimize: |\@bnone|\\
1551 % v04.21 &2003/05/12 &\emph{changes forgotten}\\[2mm]
1552 % {\bf v05}.23 &2003/05/13 &add: |\xgetallbut|, |\xkillallbut|;
1553 % optimize\\
1554 % v05.24 &2003/05/13 &remove: |\ifdetail|, |\if@xnil| (boolean var.)\\
1555 % & &and optimize\\
1556 % v05.25 &2003/05/14 &fix: some litle bugs;
1557 % remove: |\@act|\\
1558 % v05.26 &2003/05/14 &remove: bad options\\
1559 % v05.27 &2003/05/15 &bug: |\bxx(verbatim)...;| failed\\
1560 % v05.28 &2003/05/17 &bug: |\foo-section| cause error\\
1561 % & &move: |\foo-section| to the very end of package\\
1562 % v05.29 &2003/05/18 &bug: |\bxx| canot be nested.\\
1563 % & &(nesting: |deactive bxx| causes error)\\
1564 % & &(nesting: |\xgetall| works well, but\\
1565 % & &contents of |hint| is too bad.)\\
1566 % v05.30 &2003/08/xx &rewrite: document (vietnamese), optimize\\
1567 % v05.31 &2003/09/20 &rewrite: document (english), optimize\\
1568 % v05.32 &2003/09/20 &rewrite: document (english), optimize\\
1569 % & &remove: token list |\everyactivebxx| \\
1570 % & &bug: cannot use |\xgetallbut|, |\xkillallbut|,\\
1571 % & &|\xget|, etc., before any |\xenv(#env)|\\
1572 % v05.33 &2003/09/21 &remove: initialization\\
1573 % & &add: |\xopenhint|\\
1574 % v05.34 &2003/09/22 &bug: otions donot work.\\
1575 % & &fix: put |\@@xdetail|
1576 % before |\DeclareOption{detailon}|\\
1577 % & &bug: if |\xopenlib;| before any |\xget...|\\
1578 % & &then |\bxx| is |unknown control sequence|\\
1579 % & &fix: |\let\bxx\@bxx| to initialize\\
1580 % v05.39 &2003/09/20 &(future) optimize: |\@xspec|
1581 % \end{tabular}
1582 %
1583 % \section{Miscellanea}
1584 %
1585 % The author write this package because he
1586 % has some big libraries of mathematical exercises,
1587 % but he really doesn't like |copying| and |pasting|
1588 % everytime he edits a new test for students.
1589 %
1590 % This package may contains some bugs.
1591 % So the author hopes that you can help him, even a bit.
1592 %
1593 % In section \ref{sec:howwillyoudo},
1594 % the author mentioned the ability of getting the data items
1595 % whose |ID|s are numbered oddly....
1596 % Currently this feature is unsupported .
1597 % Please wait for the next version,
1598 % or you should do something by yourself!
1599 %
1600 % The author's English isnot quite well.
1601 % He often mis-spells and dumps into error.
1602 % He would like to be sorry!\\[1mm]
1603 %
1604 % If you find out that the package is useful for your private works,
1605 % please send to the author a little notice. Thank you very much!
1606 %
1607 % The emails of the author is\\
1608 % \centerline{\ttfamily [email protected], [email protected]}
1609 %
1610 % \Finale
1611 %
1612 % \iffalse
1613 %
1614 %<*example>
1615 \documentclass{article}
1616 \usepackage{ktv-texdata}
1617
1618 \usepackage{amsthm}
1619
1620 \def\back:{$\backslash$}
1621
1622 \begin{document}
1623
1624 \begin{center}
1625 \Large\bf TEST :: package == {\tt ktv-texdata.sty}
1626 \end{center}
1627
1628 \section{Create a data file}
1629 See file {\tt ktv-data.tex}.
1630 There're three part in the data file.
1631 In the first and the last part, all `\verb~bxx~'
1632 specify their own environment. In the second part,
1633 the data items omit the enrironment (use default).
1634
1635 There're some special data items:
1636 the \verb~\bxx(yyy)2;..\exx~ is followed by a hint,
1637 the \verb~\bxx(yyy)[TT]5;..\exx~ specifies
1638 an optional argument for enrivonment \verb~yyy~.
1639
1640 \section{Define the envrinoment}
1641 \begin{verbatim}
1642 \theoremstyle{definition}
1643 \newtheorem{xxx}{XX}
1644 \newtheorem{zzz}{ZZ}
1645 \newtheorem{yyy}{YY}
1646 \end{verbatim}
1647 \theoremstyle{definition}
1648 \newtheorem{xxx}{XX}
1649 \newtheorem{zzz}{ZZ}
1650 \newtheorem{yyy}{YY}
1651
1652 \section{Specified default environment by \back:env(xxx)}
1653
1654 \xenv(xxx)
1655
1656 \begin{verbatim}
1657 \xenv(xxx)
1658 \end{verbatim}
1659 You should specify the default enrironment
1660 before any calling to \back:xget, \back:xkill, \back:xgetll,
1661 \back:xkillall, etc.
1662
1663 Otherwise, if your data file contains some `\verb|bxx|'
1664 that doesnot specify the environment, you will receive an error!
1665 (In the source code of the test, remove the line \back:env(xxx)
1666 to see what will be going.)
1667
1668 \section{Specified data file by \back:env(xxx)}
1669 \xlib ktv-data;
1670
1671 \begin{verbatim}
1672 \xlib ktv-data;
1673 \end{verbatim}
1674 You also specify the the library, or data file.
1675 The above specification affects on any \back:xopenlib;
1676 that's put after this line in the source code of the test.
1677
1678 \section{\back:xget\{2,4\}}
1679 \begin{verbatim}
1680 \xget{2,4}
1681 \xopenlib;
1682 \end{verbatim}
1683 \xget{2,4}
1684 \xopenlib;
1685
1686 \section{Uneffect \back:xenv(zzz) after \back:xget\{1,4\}}
1687 \begin{verbatim}
1688 \xget{1,4}
1689 \xenv(zzz)
1690 \xopenlib;
1691 \end{verbatim}
1692 This example illustrate that any \back:xenv(...)
1693 that follows a \back:xget doesnot take any affect on that \back:xget.
1694 Try to figure out this illustration.
1695 \xget{1,4}
1696 \xenv(zzz)
1697 \xopenlib;
1698
1699 \section{Now use \back:xenv(yyy)}
1700 ...to change the default environment to zzz.
1701 \begin{verbatim}
1702 \xenv(yyy)
1703 \end{verbatim}
1704 \xenv(yyy)
1705
1706 \section{Use \back:xgetallbut(zzz)\{1,2\}}
1707 \begin{verbatim}
1708 \xgetallbut(zzz){1,2}
1709 \xopenlib;
1710 \end{verbatim}
1711 \xgetallbut(zzz){1,2}
1712 \xopenlib;
1713
1714 \section{Use \back:xkillallbut(zzz)\{1,2\}}
1715 \begin{verbatim}
1716 \xkillallbut(zzz){1,2}
1717 \xopenlib;
1718 \end{verbatim}
1719 \xkillallbut(zzz){1,2}
1720 \xopenlib;
1721
1722 \section{Use \back:xspec}
1723 This macro reserves the order of the `bxx'
1724 that you specify in the argument.
1725
1726 \subsection{This is \back:xspec\{1,5,2\}}
1727 \begin{verbatim}
1728 \xspec{1,5,2}
1729 \end{verbatim}
1730 This calling uses default environment \verb~zzz~.
1731 \xspec{1,5,2}
1732
1733 \subsection{This is \back:xspec(zzz)\{1,5,2\}}
1734 \begin{verbatim}
1735 \xspec(zzz){1,5,2}
1736 \end{verbatim}
1737 \xspec(zzz){1,5,2}
1738
1739 \section{Turn off the details by \back:xdetailoff}
1740 \xdetailoff
1741 \begin{verbatim}
1742 \xdetailoff
1743 \end{verbatim}
1744 You now cannot see anything on the right margin.
1745
1746 \section{Hint}
1747 \begin{verbatim}
1748 \xopenhint
1749 \end{verbatim}
1750 Some exercise should have a hint.\\
1751 Of course, only hints of the active `bxx' will be accepted.
1752 \xopenhint
1753
1754 \section{Now the time you try the package yourself!}
1755 Thank you for your enjoying.\\[3mm]
1756 Please send any bug, report,... to the author at
1757 \begin{verbatim}
1758 [email protected]
1759 \end{verbatim}
1760 \end{document}
1761 %</example>
1762 %
1763 %<*datafile>
1764 \bxx(yyy)1;
1765 This is {\it yyyyy}.one.
1766 \exx
1767 \bxx(yyy)2;
1768 This is {\it yyyyy}.two with hint.
1769 \exx
1770 \begin{hint}
1771 This is HINT of {\it yyyyy}.2
1772 \end{hint}
1773 \bxx(yyy)3;
1774 This is {\it yyyyy}.three.
1775 \exx
1776 \bxx(yyy)4;
1777 This is {\it yyyyy}.four.
1778 \exx
1779 \bxx(yyy)[TT]5;
1780 This is {\it yyyyy}.six with header TT
1781 \exx
1782
1783 ^^M % ------------------------------------------------------------------
1784
1785 \bxx1;
1786 This is one.
1787 \\In the data file, this `bxx' doesnot specify the enrvironment.
1788 \\So this used default environment.
1789 \exx
1790 \bxx2;
1791 This is two with hint.
1792 \\In the data file, this `bxx' doesnot specify the enrvironment.
1793 \\So this used default environment.
1794 \exx
1795 \begin{hint}
1796 This is hint of two.
1797 \\In the data file, this `bxx' doesnot specify the enrvironment.
1798 \\So this used default environment.
1799 \end{hint}
1800 \bxx3;
1801 This is three.
1802 \\In the data file, this `bxx' doesnot specify the enrvironment.
1803 \\So this used default environment.
1804 \exx
1805 \bxx4;
1806 This is four.
1807 \\In the data file, this `bxx' doesnot specify the enrvironment.
1808 \\So this used default environment.
1809 \exx
1810 \bxx5;
1811 This is six.
1812 \\In the data file, this `bxx' doesnot specify the enrvironment.
1813 \\So this used default environment.
1814 \exx
1815
1816 ^^M % ------------------------------------------------------------------
1817
1818 \bxx(zzz)1;
1819 This is ZZZZZZZ.one.
1820 \exx
1821 \bxx(zzz)2;
1822 This is ZZZZZZZ.two.
1823 \\Containning an equation:
1824 \begin{equation}
1825 \int_{0}^{\infty}f(x)\,dx = \pi
1826 \end{equation}
1827 \exx
1828 \bxx(zzz)3;
1829 This is ZZZZZZZ.three.
1830 \exx
1831 \bxx(zzz)4;
1832 This is ZZZZZZZ.four.
1833 \exx
1834 \bxx(zzz)[TT]5;
1835 This is ZZZZZZZ.six with header TT.
1836 \exx
1837 %</datafile>
1838 % \fi