Debian Codegraph @

texmf-dist/doc/latex/ran_toks/docs/rantoks_man.tex

raw
1 \RequirePackage[!use=preview,!use=efpmca,!use=usebw]{spdef}
2 \documentclass{article}
3 \usepackage[fleqn]{amsmath}
4 \usepackage[
5 web={centertitlepage,designv,forcolorpaper,
6 latextoc,extended},
7 eforms,aebxmp
8 ]{aeb_pro}
9 \usepackage{ran_toks}
10
11 \useThisSeed{227819015}
12 %\useThisSeed{1441984427}
13 %\useLastAsSeed
14 %\useThisSeed{2001383846}
15
16 %2001383846 % initializing seed value
17 %1629639958 % last random number used
18
19 \let\pkg\textsf
20 \let\env\texttt
21 \let\opt\textsf
22
23 %\rtdebugtrue
24 %\ranToksOn
25 %\ranToksOff
26
27
28 %\usepackage{myriadpro}
29 \usepackage[altbullet]{lucidbry}
30
31 %\usepackage{makeidx}
32 %\makeindex
33 \usepackage{acroman}
34 \usepackage[active]{srcltx}
35
36 \makeatletter
37 \def\eq@fititin#1{\noindent\unskip\nobreak\hfill\penalty50
38 \hskip2em\hbox{}\nobreak\hfill#1}
39 \def\fitit{\eq@fititin{\exrtnlabelformat}}
40 \@mparswitchfalse\reversemarginpar
41 \renewcommand{\paragraph}
42 {\@startsection{paragraph}{4}{0pt}{6pt}{-3pt}
43 {\normalfont\normalsize\bfseries}}
44 \renewcommand{\subparagraph}
45 {\@startsection{subparagraph}{5}{\parindent}{6pt}{-3pt}%
46 {\normalfont\normalsize\bfseries}}
47 \makeatother
48
49 \def\anglemeta#1{$\langle\textit{\texttt{#1}}\rangle$}
50 \let\ameta\anglemeta
51 \def\meta#1{\textit{\texttt{#1}}}
52 \def\darg#1{\texttt{\{#1\}}}
53 \def\takeMeasure{\bgroup\obeyspaces\takeMeasurei}
54 \def\takeMeasurei#1{\global\setbox\webtempboxi\hbox{\ttfamily#1}\egroup}
55 \def\bxSize{\wd\webtempboxi+2\fboxsep+2\fboxrule}
56
57 \newcommand{\FmtMP}[2][0pt]{\mbox{}\marginpar{%
58 \raisebox{.5\baselineskip+#1}{%
59 \expandafter\parbox\expandafter[\parboxValign]%
60 {\marginparwidth}{\aebbkFmtMp#2}}}}
61 \def\aebbkFmtMp{\kern0pt\itshape\small
62 \ifusebw\color{gray}\else\color{blue}\fi
63 \raggedleft\hspace{0pt}}\newcommand{\BlogArticle}{%
64 \makebox[0pt][l]{\hspace{-1pt}\color{blue}\Pisymbol{webd}{254}%
65 }\raisebox{.5pt}{\ifusebw\color{black}\else
66 \color{red}\fi\ding{045}}}
67 \def\parboxValign{t}
68
69
70 \usepackage[active]{srcltx}
71
72 \let\amtIndent\leftmargini
73 \def\SUB#1{${}_{\text{#1}}$}
74
75 \newdimen\aebdimen \aebdimen\topsep
76 \newcommand\bVerb[1][]{\begingroup#1\vskip\aebdimen\parindent0pt}%
77 \def\eVerb{\vskip\aebdimen\endgroup\noindent}
78
79
80 \urlstyle{rm}
81
82 \let\tops\texorpdfstring
83
84 \DeclareDocInfo
85 {
86 university={\AcroTeX.Net},
87 title={\tops{The \textsf{ran\_toks}}{The manual for the ran\_toks}
88 Package\tops{\\[6pt]\large}{: }
89 Randomizing the order of tokens},
90 author={D. P. Story},
91 email={[email protected]},
92 subject=Documentation for the ran\_toks package,
93 talksite={\url{www.acrotex.net}},
94 version={1.4, 2021/06/06},
95 Keywords={LaTeX, PDF, random, tokens, JavaScript, Adobe Acrobat},
96 copyrightStatus=True,
97 copyrightNotice={Copyright (C) \the\year, D. P. Story},
98 copyrightInfoURL={http://www.acrotex.net}
99 }
100 \DeclareInitView{windowoptions={showtitle}}
101
102
103 \def\dps{$\hbox{$\mathfrak D$\kern-.3em\hbox{$\mathfrak P$}%
104 \kern-.6em \hbox{$\mathcal S$}}$}
105
106 \universityLayout{fontsize=Large}
107 \titleLayout{fontsize=LARGE}
108 \authorLayout{fontsize=Large}
109 \tocLayout{fontsize=Large,color=aeb}
110 \sectionLayout{indent=-62.5pt,fontsize=large,color=aeb}
111 \subsectionLayout{indent=-31.25pt,color=aeb}
112 \subsubsectionLayout{indent=0pt,color=aeb}
113 \subsubDefaultDing{\tops{$\bullet$}{\textrm\textbullet}}
114
115 \def\exSrc{\makebox[0pt][r]{\large{\Pisymbol{webd}{157}}\enspace}}
116
117 %\pagestyle{empty}
118 %\parindent0pt\parskip\medskipamount
119
120 \chngDocObjectTo{\newDO}{doc}
121 \begin{docassembly}
122 var titleOfManual="The ran_toks Package";
123 var manualfilename="Manual_BG_Print_rt.pdf";
124 var manualtemplate="Manual_BG_Brown.pdf"; // Blue, Green, Brown
125 var _pathToBlank="C:/Users/Public/Documents/ManualBGs/"+manualtemplate;
126 var doc;
127 var buildIt=false;
128 if ( buildIt ) {
129 console.println("Creating new " + manualfilename + " file.");
130 doc = \appopenDoc({cPath: _pathToBlank, bHidden: true});
131 var _path=this.path;
132 var pos=_path.lastIndexOf("/");
133 _path=_path.substring(0,pos)+"/"+manualfilename;
134 \docSaveAs\newDO ({ cPath: _path });
135 doc.closeDoc();
136 doc = \appopenDoc({cPath: manualfilename, oDoc:this, bHidden: true});
137 f=doc.getField("ManualTitle");
138 f.value=titleOfManual;
139 doc.flattenPages();
140 \docSaveAs\newDO({ cPath: manualfilename });
141 doc.closeDoc();
142 } else {
143 console.println("Using the current "+manualfilename+" file.");
144 }
145 var _path=this.path;
146 var pos=_path.lastIndexOf("/");
147 _path=_path.substring(0,pos)+"/"+manualfilename;
148 \addWatermarkFromFile({
149 bOnTop:false,
150 bOnPrint:false,
151 cDIPath:_path
152 });
153 \executeSave();
154 \end{docassembly}
155
156 %\definePath\bgPath{"C:/Users/Public/Documents/%
157 % ManualBGs/Manual_BG_Print_AeB.pdf"}
158 %\begin{docassembly}
159 %\addWatermarkFromFile({%
160 % bOnTop: false,
161 % cDIPath: \bgPath
162 %})
163 %\executeSave()
164 %\end{docassembly}
165
166 \begin{document}
167
168 \maketitle
169
170 \selectColors{linkColor=black}
171 \tableofcontents
172 \selectColors{linkColor=webgreen}
173
174 \section{Introduction}
175
176 This is a short package for randomizing the order of tokens. The package
177 is long overdue; users of \textsf{\textbf{AeB}} and of \pkg{eqexam} have long asked for a way to
178 randomize the order of the problems in a test or quiz, or anything for
179 that matter.
180
181 \newtopic\noindent\exSrc The \texttt{examples} folder contains nine demonstration files:
182 \begin{enumerate}
183 \item \texttt{ran-toks.tex} reproduces the sample code of this manual.
184 \item \texttt{rt-tst-eqe.tex} shows how to use \pkg{ran\_toks} to
185 randomize the \emph{questions} of an exam document created by the
186 \pkg{eqexam} package.
187 \item \texttt{rt-tst-qz.tex} shows how to randomize choices of a
188 multiple choice field in a \env{quiz} environment of the
189 \pkg{exerquiz} package, when the choices contain verbatim text.
190 \item \texttt{rt-cb.tex} is a demonstration of how to use the
191 \pkg{collectbox} package to place verbatim content into a token list
192 (see \cs{ranToks}, \hyperref[s:ranToks]{Section~\ref*{s:ranToks}}).
193 \xdef\svEnumi{\the\value{enumi}}
194 \end{enumerate}
195 The next five files concern the DB application and require the \opt{usedbapp} option,
196 they are discussed in \hyperref[s:DBApp]{Section~\ref*{s:DBApp}}.
197 \begin{enumerate}\setcounter{enumi}{\svEnumi}
198 \item \texttt{mc-db.tex} is an \pkg{eqexam} file, draws from the
199 database files \texttt{db1.tex}, \texttt{db2.tex},
200 \texttt{db3.tex}, and \texttt{db4.tex}, to construct the questions
201 of the exam. The questions are drawn at random from the DB files. Refer
202 to \hyperref[s:DBApp]{Section~\ref*{s:DBApp}} for a few more details.
203 \item \texttt{mc-dbu.tex} is an \pkg{eqexam} file that draws from the
204 database test file, draws from the database files \texttt{db1.tex},
205 \texttt{db2.tex}, \texttt{db3.tex}, and \texttt{db4.tex}, to
206 construct the questions of the exam. However, \texttt{mc-dbu.tex}
207 differs from \texttt{mc-db.tex} for it selects unique questions
208 cross the four versions of the document. Refer to
209 \hyperref[s:DBApp]{Section~\ref*{s:DBApp}} for a few more details.
210 \item \texttt{viewDB.tex} A demo file of how to view the DB files for
211 the purpose of reviewing the questions, modifying them, or adding
212 to them.
213 \item \texttt{mc-dbu-ctrld.tex} is a variation on \texttt{mc-dbu.tex},
214 it is not meant to be compiled directly, but by the file
215 \texttt{ctrl-build.tex}.
216 \item \texttt{ctrl-build.tex} is a simple TEX file that controls the
217 compilation of a targeted file (\texttt{mc-dbu-ctrld.tex} in this
218 example) over the various versions supported by the targeted file.
219 Try it, you'll like it. Uses the \pkg{shellesc} package to control
220 the process.
221
222 \end{enumerate}
223
224 \section{The Preamble and Package Options}
225
226 The preamble for this package is
227 \bVerb\takeMeasure{\string\usepackage[\ameta{options}]\darg{ran\_toks}}%
228 \begin{minipage}{\bxSize}\kern0pt
229 \begin{Verbatim}[frame=single,commandchars=!()]
230 \usepackage[!ameta(options)]{ran_toks}
231 \end{Verbatim}
232 \end{minipage}\eVerb
233 The one option of \pkg{ran\_toks} is \opt{usedbapp}\FmtMP{\opt{usedbapp} option}, which brings in
234 specialized code to support a database test application. This option is
235 discussed in \hyperref[s:DBApp]{Section~\ref*{s:DBApp}}, beginning on page~\pageref*{s:DBApp}.
236
237 The requirements for \textsf{ran\_toks} are the \textsf{verbatim} package
238 (part of the standard {\LaTeX} distribution, and the macro file
239 \texttt{random.tex} by Donald Arseneau.
240
241
242 \section{The main commands and environments}\label{rtmain}
243
244 There are two styles for defining a series of tokens to be randomized,
245 using either the \cs{ranToks} command or the \cs{bRTVToks}/\cs{eRTVToks}
246 pair. Each of these is discussed in the next two subsections.
247
248 \subsection{The \tops{\protect\cs{ranToks}}{\CMD{ranToks}} command}\label{s:ranToks}
249
250 The \cs{ranToks} command was the original concept; declare a series of
251 tokens to be randomized.
252 \bVerb\takeMeasure{\string\ranToks\darg{\ameta{name}}\{\%\enspace}%
253 \begin{minipage}{\bxSize}\kern0pt
254 \begin{Verbatim}[frame=single,commandchars=!()]
255 \ranToks{!ameta(name)}{%
256 !quad{!ameta(token!SUB(1))}
257 !quad{!ameta(token!SUB(2))}
258 !quad...
259 !quad{!ameta(token!SUB(n))}
260 }
261 \end{Verbatim}
262 \end{minipage}\eVerb
263 were \ameta{token\SUB{k}} is any non-verbatim content;\footnote{However, for workarounds, see
264 \texttt{rt-cb.tex} and \texttt{rt-tst-qz.tex.}} each token is enclosed in braces
265 (\darg{}), this is required. The \ameta{name} parameter is required, and
266 must be unique for the document; it is used to build the names of internal
267 macros. Of course several such \cs{ranToks} can be used in the document,
268 either in the preamble or in the body of the document. Multiple
269 \cs{ranToks} commands must have a different \ameta{name} parameter.
270
271 \emph{After} a \cs{ranToks} command has been executed, the number of tokens
272 counted is accessible through the \cs{nToksFor} command,
273 \bVerb\takeMeasure{\string\nToksFor\darg{\ameta{name}}}%
274 \begin{minipage}{\bxSize}\kern0pt
275 \begin{Verbatim}[frame=single,commandchars=!()]
276 \nToksFor{!ameta(name)}
277 \end{Verbatim}
278 \end{minipage}\eVerb
279 The one argument is \ameta{name}, and will expand to the total number
280 of tokens listing as argument in the \cs{ranToks} command by the same
281 name.
282
283 The \cs{ranToks} command does not display the randomized tokens, for that
284 the command \cs{useRanTok} is used.
285 \bVerb\takeMeasure{\string\useRTName\darg{\ameta{name}}}%
286 \begin{minipage}{\bxSize}
287 \begin{Verbatim}[frame=single,commandchars=!()]
288 \useRanTok{!ameta(num)}
289 \useRTName{!ameta(name)}
290 \end{Verbatim}
291 \end{minipage}\eVerb
292 The argument of \cs{useRanTok} is a positive integer between 1 and
293 \cs{nToksFor\darg{\ameta{name}}}, the number of tokens declared by
294 \cs{ranToks}, inclusive. There is no space created following the
295 \cs{useRanTok} command, so if these are to be used ``inline'', enclose them
296 in braces (\darg{}), for example, \darg{\cs{useRanTok\darg{1}}}. The use of
297 \cs{useRTName} is optional unless the listing of the \cs{useRanTok} commands
298 is separated from the \cs{ranToks} command that defined them by another
299 \cs{ranToks} command of a different name. That should be clear!
300
301 Consider this example.
302
303 \begin{Verbatim}[xleftmargin=\amtIndent]
304 \ranToks{myPals}{%
305 {Jim}{Richard}{Don}
306 {Alex}{Tom}{J\"{u}rgen}
307 }
308 \end{Verbatim}
309 \ranToks{myPals}{%
310 {Jim}{Richard}{Don}
311 {Alex}{Tom}{J\"{u}rgen}
312 }
313 I have {\nToksFor{myPals}} pals, they are \useRanTok{1}, \useRanTok{2},
314 \useRanTok{3}, \useRanTok{4}, {\useRanTok{5}} and \useRanTok{6}. (Listed
315 in the order of best friend to least best friend.)
316 The verbatim listing is,
317 \begin{Verbatim}[xleftmargin=\amtIndent]
318 I have {\nToksFor{myPals}} pals, they are \useRanTok{1},
319 \useRanTok{2}, \useRanTok{3}, \useRanTok{4}, {\useRanTok{5}}
320 and \useRanTok{6}.
321 \end{Verbatim}
322 Notice that \cs{useRanToks} are not enclosed in braces for 1--4 because
323 they are each followed by a comma; the fifth token, \texttt{\darg{\cs{useRanTok\darg{5}}}}, is
324 enclosed in braces to generate a space following the insertion of the text.
325
326 Repeating the sentence yields, ``I have {\nToksFor{myPals}} pals, they are
327 \useRanTok{1}, \useRanTok{2}, \useRanTok{3}, \useRanTok{4},
328 {\useRanTok{5}} and \useRanTok{6}'', which is the exact same random order. To
329 obtain a different order, re-execute the \cs{ranToks} command with the same
330 arguments.\footnote{{\ttfamily\string\ranToks\darg{myPals}\darg{\darg{Jim}\darg{Richard}\darg{Don}\darg{Alex}\darg{Tom}\darg{J\string\"\darg{u}rgen}}} in this example.} Doing just that, \ranToks{myPals}{{Jim}{Richard}{Don}
331 {Alex}{Tom}{J\"{u}rgen}}we obtain, ``I have {\nToksFor{myPals}} pals, they
332 are \useRanTok{1}, \useRanTok{2}, \useRanTok{3}, \useRanTok{4},
333 {\useRanTok{5}} and \useRanTok{6}.'' A new order?
334 An alternative to re-executing \cs{ranToks} is to use the \cs{reorderRanToks} command:
335 \bVerb\takeMeasure{\string\reorderRanToks\darg{\ameta{name}}}%
336 \begin{minipage}{\bxSize}\kern0pt
337 \begin{Verbatim}[frame=single,commandchars=!()]
338 \reorderRanToks{!ameta(name)}
339 \end{Verbatim}
340 \end{minipage}\eVerb Now, executing \verb~\reorderRanToks{myPals}~ and compiling the sentence again yields,
341 ``I~have {\nToksFor{myPals}} pals, they are
342 \useRanTok{1}, \useRanTok{2}, \useRanTok{3}, \useRanTok{4},
343 {\useRanTok{5}} and \useRanTok{6}.'' For most applications, re-randomizing
344 the same token list in the same document is not very likely something you
345 need to do.
346
347 The \cs{reorderRanToks\darg{\ameta{name}}} command rearranges the list of tokens
348 associated with \ameta{name}, which may not be what you want; the
349 \cs{copyRanToks} command, on the other hand, makes a (randomized) copy of its
350 first required argument \ameta{name\SUB1} and saves it as \ameta{name\SUB2}, without
351 effecting the order of \ameta{name\SUB1}.
352 \bVerb\takeMeasure{\string\copyRanToks\darg{\ameta{name\SUB1}}\darg{\ameta{name\SUB2}}}%
353 \begin{minipage}{\bxSize}\kern0pt
354 \begin{Verbatim}[frame=single,commandchars=!()]
355 \copyRanToks{!ameta(name!SUB1)}{!ameta(name!SUB2)}
356 \end{Verbatim}
357 \end{minipage}\eVerb Thus, if \verb!\copyRanToks{myPals}{myPals1}! is executed, the token list name
358 \texttt{myPals1} contains the names of my pals in another randomized order,
359 while maintaining the same order of \texttt{myPals}.
360
361
362 \newtopic
363 My original application for this, the one that motivated writing this
364 package at long last, was the need to arrange several form buttons
365 randomly on the page. My point is that the listing given in the argument
366 of \cs{ranToks} can pretty much be anything that is allowed to be an
367 argument of a macro; this would exclude verbatim text created by \cs{verb}
368 and verbatim environments.
369
370 \subsection{The
371 \tops{\protect\cs{bRTVToks}/\protect\cs{eRTVToks}}
372 {\CMD{bRTVToks}/\CMD{eRTVToks}} pair of commands}\label{ss:RTVToks}
373
374 Sometimes the content to be randomized is quite large or contains verbatim
375 text. For this, it may be more convenient to use the
376 \cs{bRTVToks}/\penalty0\cs{eRTVToks} command pair. The syntax is
377 \bVerb\takeMeasure{\string\bRTVToks\darg{\ameta{name}}}%
378 %\edef\WIDTH{\the\wd\webtempboxi}%
379 \def\1{\rlap{\hspace*{\linewidth}\texttt{\%{\sffamily{ \raisebox{1pt}{<--}Begin token listing}}}}}%
380 \def\2{\rlap{\hspace*{\linewidth}\texttt{\%{\sffamily{ \raisebox{1pt}{<--}End token listing}}}}}%
381 %\takeMeasure{\string\bRTVToks\darg{\ameta{name}}\quad\%{\sffamily{ <-Begin token listing}}}%
382 \begin{minipage}{\bxSize}\kern0pt
383 \begin{Verbatim}[frame=single,commandchars=!()]
384 !1\bRTVToks{!ameta(name)}
385 \begin{rtVW}
386 !quad!ameta(content!SUB(1))
387 \end{rtVW}
388 ...
389 ...
390 \begin{rtVW}
391 !quad!ameta(content!SUB(n))
392 \end{rtVW}
393 !2\eRTVToks
394 \end{Verbatim}
395 \end{minipage}\eVerb
396 %\bVerb\takeMeasure{\string\bRTVToks\darg{\ameta{name}}\quad}%
397 %\edef\WIDTH{\the\wd\webtempboxi}%
398 %\def\1{\rlap{\hspace*{\WIDTH}\texttt{\% <-{\sffamily{ End token listing}}}}}%
399 %\takeMeasure{\string\bRTVToks\darg{\ameta{name}}\quad\% <-{\sffamily{ Begin token listing}}}%
400 %\begin{minipage}{\bxSize}\kern0pt
401 %\begin{Verbatim}[frame=single,commandchars=!()]
402 %\bRTVToks{!ameta(name)}!quad% <-!sffamily( Begin token listing)
403 %\begin{rtVW}
404 %!quad!ameta(content!SUB(1))
405 %\end{rtVW}
406 %...
407 %...
408 %\begin{rtVW}
409 %!quad!ameta(content!SUB(n))
410 %\end{rtVW}
411 %!1\eRTVToks
412 %\end{Verbatim}
413 %\end{minipage}\eVerb
414 The \cs{bRTVToks}\texttt{\darg{\ameta{name}}} command begins the (pseudo)
415 environment and is ended by \cs{eRTVToks}. Between these two are a series of
416 \texttt{rtVW} (random toks verbatim write) environments. When the document is
417 compiled, the contents (\ameta{content\SUB{i}}) of each of these environments
418 are written to the computer hard drive and saved under a different name
419 (based on the parameter \ameta{name}). Later, using the \cs{useRanTok}
420 commands, they are input back into the document in a random order.
421
422 The \env{rtVW} environment also writes the command
423 \cs{RTVWHook}\marginpar{\small\itshape\flushright\cs{RTVWHook}} to the top of
424 the file. Its initial value is \cs{relax}. It can be redefined with
425 \cs{rtVWHook\darg{\ameta{arg}}}, which expands to
426 \verb|\def\RTVWHook{|\ameta{arg}\verb|}|.
427
428 The use of \cs{useRTName} and \cs{useRanTok} were explained and illustrated
429 in the previous section. Let's go to the examples,
430 \begin{Verbatim}[xleftmargin=\amtIndent]
431 \bRTVToks{myThoughts}
432 \begin{rtVW}
433 \begin{minipage}[t]{.67\linewidth}
434 Roses are red and violets are blue,
435 I've forgotten the rest, have you too?
436 \end{minipage}
437 \end{rtVW}
438 \begin{rtVW}
439 \begin{minipage}[t]{.67\linewidth}
440 I gave up saying bad things like
441 \verb!$#%%%^*%^&#$@#! when I was just a teenager.
442 \end{minipage}
443 \end{rtVW}
444 \begin{rtVW}
445 \begin{minipage}[t]{.67\linewidth}
446 I am a good guy, pass it on! The code for this last sentence is,
447 \begin{verbatim}
448 %#$% I am a good guy, pass it on! ^&*&^*
449 \end{verbatim}
450 How did that other stuff get in there?
451 \end{minipage}
452 \end{rtVW}
453 \eRTVToks
454 \end{Verbatim}
455 OK, now, let's display these three in random order. Here we place them in
456 an \texttt{enumerate} environment.
457
458 \bRTVToks{myThoughts}%
459 \begin{rtVW}
460 \begin{minipage}[t]{.67\linewidth}
461 Roses are red and violets are blue,
462 I've forgotten the rest, have you too?
463 \end{minipage}
464 \end{rtVW}
465 \begin{rtVW}
466 \begin{minipage}[t]{.67\linewidth}
467 I gave up saying bad things like
468 \verb!$#%%%^*%^&#$@#! when I was just a teenager.
469 \end{minipage}
470 \end{rtVW}
471 \begin{rtVW}
472 \begin{minipage}[t]{.67\linewidth}
473 I am a good guy, pass it on! The code for this last sentence is,
474 \begin{verbatim}
475 %#$% I am a good guy, pass it on! ^&*&^*
476 \end{verbatim}
477 How did that other stuff get in there?
478 \end{minipage}
479 \end{rtVW}
480 \eRTVToks
481 \begin{enumerate}
482 \item \useRanTok{1}
483 \item \useRanTok{2}
484 \item \useRanTok{3}
485 \end{enumerate}
486 The verbatim listing of the example above is
487 \begin{Verbatim}[xleftmargin=\amtIndent]
488 \begin{enumerate}
489 \item \useRanTok{1}
490 \item \useRanTok{2}
491 \item \useRanTok{3}
492 \end{enumerate}
493 \end{Verbatim}
494 The \cs{reorderRanToks} works for lists created by the \cs{bRTVToks}/\penalty0\cs{bRTVToks} construct.
495 If we say \cs{reorderRanToks\darg{myThoughts}} and reissue the above list, we obtain,
496 \begin{enumerate}\ranToksOn\reorderRanToks{myThoughts}
497 \displayListRandomly[\item]{myThoughts}
498 \end{enumerate}
499 The command \cs{copyRanToks} works for list created by
500 \cs{bRTVToks}/\penalty0\cs{bRTVToks} as well.
501
502 \paragraph*{On the \cs{displayListRandomly} command.}\label{para:DLR}
503 In the enumerate example immediately above, the items in the list are
504 explicitly listed as \cs{item \cs{useRanTok\darg{1}}} and so on; an
505 alternate approach is to use the command \cs{displayListRandomly}, like so,
506 \begin{Verbatim}[xleftmargin=\amtIndent]
507 \begin{enumerate}
508 \displayListRandomly[\item]{myThoughts}
509 \end{enumerate}
510 \end{Verbatim}
511 The full syntax for \cs{displayListRandomly} is displayed next.
512 \bVerb\takeMeasure{\string\displayListRandomly[\ameta{prior}][\ameta{post}]\darg{\ameta{name}}}%
513 \begin{minipage}{\bxSize}\kern0pt
514 \begin{Verbatim}[frame=single,commandchars=!()]
515 \displayListRandomly[!ameta(prior)][!ameta(post)]{!ameta(name)}
516 \end{Verbatim}
517 \end{minipage}
518 \eVerb The action of \cs{displayListRandomly} is to expand all tokens that
519 are listed in the \ameta{name} token list, each entry is displayed as
520 \ameta{prior}\cs{useRanTok\darg{i}}\ameta{post}, where \texttt{i}
521 goes from~1 to \cs{nToksFor\darg{\ameta{name}}}. In the example above,
522 \ameta{prior} is \cs{item}, but normally, its default is empty. The defaults
523 for \ameta{prior} and \ameta{post} are both empty.
524
525 \subparagraph*{The optional arguments.} When only one optional argument is present,
526 if is interpreted as \ameta{prior}. To obtain a \ameta{post} with no \ameta{prior}
527 use the syntax,
528 \begin{quote}
529 \cs{displayListRandomly[][\ameta{post}]\darg{\ameta{name}}}
530 \end{quote}
531 Within \emph{each optional argument}, the four commands \cs{i},
532 \cs{first}, \cs{last}, and \cs{lessone} are (locally) defined. The \cs{i} command is the index
533 counter of the token currently being typeset; \cs{first} is the index of the
534 first item; \cs{last} is the index of the last item; and \cs{lessone} is one
535 less than \cs{last}. The two optional arguments and the four commands may use
536 to perform logic on the token as it is being typeset. For example:
537 \begin{Verbatim}[xleftmargin=\amtIndent,fontsize=\small]
538 List of pals: \displayListRandomly
539 [\ifnum\i=\last and \fi]
540 [\ifnum\i=\last.\else, \fi]{myPals}
541 \end{Verbatim}
542 yields,
543 \begin{quote}
544 List of pals: \displayListRandomly
545 [\ifnum\i=\last and \fi]
546 [\ifnum\i=\last.\else, \fi]{myPals}
547 \end{quote}
548 The optional arguments are wrapped to the next line to keep them within the margins, cool.
549
550 The example above shows the list of my pals with an Oxford comma. How would
551 you modify the optional argument to get the same listing without the Oxford
552 comma? (\displayListRandomly[\ifnum\i=\last and \fi][\ifnum\i=\last.\else\ifnum\i=\lessone\relax\space\else, \fi\fi]{myPals})
553 Hint: a solution involves the other command \cs{lessone}.
554
555 \subsubsection{Nested
556 \tops{\protect\cs{bRTVToks}/\protect\cs{eRTVToks}}
557 {\CMD{bRTVToks}/\CMD{eRTVToks}} command pairs}\label{ss:NestedRTVToks}
558
559 These is at least one example of using nested
560 \cs{bRTVToks}/\allowbreak\cs{eRTVToks}. When nested
561 \cs{bRTVToks}/\allowbreak\cs{eRTVToks} command pairs, use the \env{rtVWi}
562 environment instead of the \env{rtVW} environment. The nested
563 \cs{bRTVToks}/\allowbreak\cs{eRTVToks} pair is placed\FmtMP{placement} within
564 a \env{rtWV} environment; in this way the contents of that \env{rtWV}
565 environment, itself can be randomized. The \cs{displayListRandomly} (or
566 \cs{useRanTok}) command is used to list out the nested items. See the next
567 page for an example.
568
569 \newpage
570
571 \bRTVToks{Depth0}
572 \begin{rtVW}
573 Depth0: Item 1
574 \end{rtVW}
575 \begin{rtVW}
576 Depth0: Item 2:
577 \bRTVToks{Depth1}
578 \begin{rtVWi}
579 Depth1: Item 1
580 \end{rtVWi}
581 \begin{rtVWi}
582 Depth1: Item 2
583 \bRTVToks{Depth2}
584 \begin{rtVWii}
585 Depth2: Item 1
586 \end{rtVWii}
587 \begin{rtVWii}
588 Depth2: Item 2
589 \end{rtVWii}
590 \begin{rtVWii}
591 Depth2: Item 3
592 \end{rtVWii}
593 \eRTVToks
594 \begin{itemize}
595 \displayListRandomly[\item]{Depth2}
596 \end{itemize}
597 \end{rtVWi}
598 \begin{rtVWi}
599 Depth1: Item 3
600 \end{rtVWi}
601 \eRTVToks
602 \begin{itemize}
603 \displayListRandomly[\item]{Depth1}
604 \end{itemize}
605 \end{rtVW}
606 \begin{rtVW}
607 Depth0: Item 3
608 \end{rtVW}
609 \begin{rtVW}
610 Depth0: Item 4
611 \end{rtVW}
612 \begin{rtVW}
613 Depth0: Item 5
614 \end{rtVW}
615 \eRTVToks
616 \begin{enumerate}\small
617 \displayListRandomly[\item]{Depth0}
618 \end{enumerate}
619 The verbatim listing for this example follows.
620 \begin{Verbatim}[commandchars=!(),fontsize=\small]
621 \bRTVToks{Depth0}
622 \begin{rtVW}
623 Depth0: Item 1
624 \end{rtVW}
625 \begin{rtVW}
626 Depth0: Item 2:
627 \bRTVToks{Depth1} % !textsf(begin Depth2 within an rtVW env.)
628 \begin{rtVWi}
629 Depth1: Item 1
630 \end{rtVWi}
631 \begin{rtVWi}
632 Depth1: Item 2
633 \bRTVToks{Depth2} % !textsf(begin Depth1 within an rtVWi env.)
634 \begin{rtVWii}
635 Depth2: Item 1
636 \end{rtVWii}
637 \begin{rtVWii}
638 Depth2: Item 2
639 \end{rtVWii}
640 \begin{rtVWii}
641 Depth2: Item 3
642 \end{rtVWii}
643 \eRTVToks
644 \begin{itemize}
645 \displayListRandomly[\item]{Depth2} % !textsf(display Depth2 toks)
646 \end{itemize}
647 \end{rtVWi}
648 \begin{rtVWi}
649 Depth1: Item 3
650 \end{rtVWi}
651 \eRTVToks
652 \begin{itemize}
653 \displayListRandomly[\item]{Depth1} % !textsf(display Depth1 toks)
654 \end{itemize}
655 \end{rtVW}
656 \begin{rtVW}
657 Depth0: Item 3
658 \end{rtVW}
659 \begin{rtVW}
660 Depth0: Item 4
661 \end{rtVW}
662 \begin{rtVW}
663 Depth0: Item 5
664 \end{rtVW}
665 \eRTVToks
666 \begin{enumerate}
667 \displayListRandomly[\item]{Depth0} % !textsf(display Depth0 toks)
668 \end{enumerate}
669 \end{Verbatim}
670 Oops. Did I forget to mention that \pkg{ran\_toks} supports nested to a depth of two.
671
672 Some authors like to indent nested things, but to avoid spurious spaces
673 appearing, \cs{end\darg{rtVW}} (and \cs{end\darg{rtVWi}}) should be placed in
674 the far left margin, as shown above. Recall the \env{rtVW} is a verbatim
675 environment.
676
677 The above example is reproduced in the \texttt{ran\_toks.tex} sample file found in the
678 \texttt{examples} folder. Also found in that folder is \texttt{nested-matching.tex}, a \pkg{exerquiz}
679 quiz that motivated creating nested \cs{bRTVToks}/\allowbreak\cs{eRTVToks} command pairs.
680
681 \section{Additional arguments and commands}\label{AddCmds}
682
683 The syntax given earlier for \cs{useRanTok} was not completely specified.
684 It is,
685 \bVerb\takeMeasure{\string\useRanTok[\ameta{name}]\darg{\ameta{num}}}%
686 \begin{minipage}{\bxSize}\kern0pt
687 \begin{Verbatim}[frame=single,commandchars=!()]
688 \useRanTok[!ameta(name)]{!ameta(num)}
689 \end{Verbatim}
690 \end{minipage}\eVerb
691 The optional first parameter specifies the \ameta{name} of the list from
692 which to draw a random token; \ameta{num} is the number of the
693 token in the range of 1 and \cs{nToksFor\darg{\ameta{name}}},
694 inclusive. The optional argument is useful in special circumstances when
695 you want to mix two random lists together.
696
697 \newtopic\noindent To illustrate: \useRanTok[myPals]{1}, \useRanTok[myThoughts]{2}
698
699 \newtopic\noindent The verbatim listing is
700 \begin{Verbatim}[xleftmargin=\amtIndent]
701 To illustrate: \useRanTok[myPals]{1}, \useRanTok[myThoughts]{2}
702 \end{Verbatim}
703 The typeset version looks a little strange, but recall, the text of
704 \texttt{myThoughts} were each put in a \texttt{minipage} of width \texttt{.67\cs{linewidth}}.
705 Without the \texttt{minipage}, the text would wrap around normally.
706
707 \paragraph*{Accessing the original order.} The original order of the list of tokens is not lost, you can retrieve
708 them using the command \cs{rtTokByNum},
709 \bVerb\takeMeasure{\string\rtTokByNum[\ameta{name}]\darg{\ameta{num}}}%
710 \begin{minipage}{\bxSize}\kern0pt
711 \begin{Verbatim}[frame=single,commandchars=!()]
712 \rtTokByNum[!ameta(name)]{!ameta(num)}
713 \end{Verbatim}
714 \end{minipage}\eVerb
715 This command expands to the token declared in the list named \ameta{name}
716 that appears at the \ameta{num} place in the list. (Rather awkwardly written.)
717 For example, my really best pals are {\rtTokByNum[myPals]{3}} and
718 \rtTokByNum[myPals]{4}, but don't tell them. The listing is,
719 \begin{Verbatim}[xleftmargin=\amtIndent]
720 For example, my really best pals are {\rtTokByNum[myPals]{3}}
721 and \rtTokByNum[myPals]{4}, but don't tell them.
722 \end{Verbatim}
723 In some sense, \cs{rtTokByNum[\ameta{name}]} acts like a simple array, the
724 length of which is \cs{nToksFor\{\ameta{name}\}}, and whose $k^{\text{th}}$
725 element is \cs{rtTokByNum[\ameta{name}]\{\ameta{k}\}}.
726
727 \paragraph*{Turning off randomization.} The randomization may be turned off
728 using \cs{ranToksOff} or turned back on with \cs{ranToksOn}.
729 \bVerb\takeMeasure{\string\ranToksOff\quad\string\ranToksOn}%
730 \begin{minipage}{\bxSize}\kern0pt
731 \begin{Verbatim}[frame=single,commandchars=!()]
732 \ranToksOff!quad\ranToksOn
733 \end{Verbatim}
734 \end{minipage}\eVerb
735 This can be done globally in the preamble for the whole of the document,
736 or in the body of the document just prior to either \cs{ranToks} or
737 \cs{bRTVToks}. For example,
738 \begin{Verbatim}[xleftmargin=\amtIndent]
739 \ranToksOff
740 \ranToks{integers}{ {1}{2}{3}{4} }
741 \ranToksOn
742 \end{Verbatim}
743 As a check, executing `$\cs{useRanTok\darg{3}} = \cs{rtTokByNum\darg{3}} = 3 $' yields
744 `\ranToksOff\ranToks{integers}{ {1}{2}{3}{4}}\ranToksOn
745 $\useRanTok{3} = \rtTokByNum{3} = 3 $'? As anticipated.
746
747 To create a non-randomized list of tokens that already have been created (and randomized), use
748 \cs{copyRanToks}:
749 \begin{Verbatim}[xleftmargin=\amtIndent]
750 \ranToksOff\copyRanToks{myPals}{myOriginalPals}\ranToksOn
751 \end{Verbatim}
752 Then, using \cs{displayListRandomly} in a clever way,
753 \begin{Verbatim}[xleftmargin=\amtIndent]
754 \displayListRandomly[\ifnum\i=\last\space and \fi(\the\i)~]
755 [\ifnum\i=\last.\else,\fi\space]{myOriginalPals}
756 \end{Verbatim}
757 we obtain: \ranToksOff\copyRanToks{myPals}{myOriginalPals}\ranToksOn
758 \displayListRandomly[\ifnum\i=\last\space and \fi(\the\i)~][\ifnum\i=\last.\else,\fi\space]{myOriginalPals}
759 The original list for \texttt{myPals} remains unchanged:
760 \displayListRandomly[\ifnum\i=\last\space and \fi(\the\i)~][\ifnum\i=\last.\else,\fi\space]{myPals}
761
762 The \cs{useRanTok} command---whether it operates on a randomized token list
763 or not---behaves similarly to an array. Thus, if we wanted to extract
764 the third entry of the non-randomized token list (array)
765 \texttt{myOriginalPals}, we do so by expanding the command
766 \verb!\useRanTok[myOriginalPals]{3}! to produce
767 \useRanTok[myOriginalPals]{3}.
768
769 \subparagraph*{Document preparation.}
770 The command \cs{ranToksOff} is probably best in the preamble to turn off
771 all randomization while the rest of the document is being composed.
772
773 \paragraph*{The \textsf{ran\_toks} auxiliary file.} The package writes to a file named
774 \cs{jobname\_rt.sav}, below represents two typical lines in this file.
775 \begin{Verbatim}[xleftmargin=\amtIndent]
776 1604051353 % initializing seed value
777 5747283528 % last random number used
778 \end{Verbatim}
779 The first line is the initializing seed value used for the last
780 compilation of the document; the second line is the last value of the
781 pseudo-random number generator used in the document.
782
783 Normally, the pseudo-random number generator provided by
784 \texttt{random.tex} produces a new initial seed value every minute. So if
785 you recompile again before another minute, you'll get the same initial
786 seed value.
787
788 \paragraph*{Controlling the initial seed value.}\label{para:ControlSeed} To obtain a new initial seed
789 value each time you compile, place \cs{useLastAsSeed} in the preamble.
790 \bVerb\takeMeasure{\string\useLastAsSeed}%
791 \begin{minipage}{\bxSize}\kern0pt
792 \begin{Verbatim}[frame=single]
793 \useLastAsSeed
794 \end{Verbatim}
795 \end{minipage}\eVerb
796 When the document is compiled, the initial seed value taken as the second
797 line in the \cs{jobname\_rt.sav} file, as seen in the above example.
798 With this command in the preamble, a new set of random numbers is
799 generated on each compile. If the file \cs{jobname\_rt.sav} does not
800 exist, the generator will be initialized by its usual method, using the time and date.
801
802 The command \cs{useThisSeed} allows you to reproduce a previous
803 pseudo-random sequence.
804 \bVerb\takeMeasure{\string\useThisSeed\darg{\ameta{init\_seed\_value}}}%
805 \begin{minipage}{\bxSize}\kern0pt
806 \begin{Verbatim}[frame=single,commandchars=!()]
807 \useThisSeed{!ameta(init_seed_value)}
808 \end{Verbatim}
809 \end{minipage}\eVerb
810 This command needs to be placed in the preamble. The value of
811 \ameta{init\_seed\_value} is an integer, normally taken from the
812 first line of the \cs{jobname\_rt.sav} file.
813
814 When creating tests (possibly using \textsf{eqexam}), the problems, or
815 contiguous collections of problems, can be randomly ordered using the
816 \cs{bRTVToks}/\penalty0\cs{eRTVToks} command pair paradigm. For example,
817 suppose there are two classes and you want a random order (some of) the
818 problems for each of the two classes. Proceed as follows:
819 \begin{enumerate}
820 \item Compile the document, open \cs{jobname\_rt.sav}, and copy the
821 first line (in the above example, that would be
822 \texttt{1604051353}).
823 \item Place \cs{useThisSeed\darg{1604051353}} in the preamble. Compiling
824 will bring back the same pseudo-random sequence very time.
825 \item Comment this line out, and repeat the process (use
826 \cs{useLastAsSeed} to generate new random sequences at each
827 compile) until you get another distinct randomization, open
828 \cs{jobname\_rt.sav}, and copy the first line again, say its \texttt{735794511}.
829 \item Place \cs{useThisSeed\darg{735794511}} in the preamble.
830 \item Label each
831 \begin{Verbatim}
832 %\useThisSeed{1604051353} % 11:00 class
833 %\useThisSeed{735794511} % 12:30 class
834 \end{Verbatim}
835 To reproduce the random sequence for the class, just uncomment the random
836 seed used for that class.
837 \end{enumerate}
838 If you are using \textsf{eqexam}, the process can be automated as follows:
839 \begin{Verbatim}[xleftmargin=\amtIndent,commandchars=!()]
840 \vA{\useThisSeed{1604051353}} % 11:00 class
841 \vB{\useThisSeed{735794511}} % 12:30 class
842 \end{Verbatim}
843 Again, this goes in the preamble.
844
845 \section{Commands to support a DB application}\label{s:DBApp}
846
847 The commands described in this section are only available with the \opt{usedbapp} option,
848 \begin{Verbatim}
849 \usepackage[usedbapp]{ran_toks}
850 \end{Verbatim}
851 This option was designed for an \pkg{eqexam} document.
852
853 \subsection{Basic functionality}\label{s:basicFunc}
854
855 The premise here is that you have an \pkg{eqexam} document (a test) and you have a series
856 of standard questions you ask students. Over the years, you have accumulated questions of a similar type
857 that you like to pose to your students. The questions of a similar type are placed in a DB test file. For example,
858 you have a file named \texttt{db1.tex} containing questions on a certain narrow topic. The format for this file
859 is,
860 \begin{Verbatim}[commandchars=!()]
861 %
862 % !textsf(Questions on some narrow topic)
863 %
864 \bRTVToks{DB1} %<-!textsf(DB !ameta(name))
865 \begin{rtVW}
866 % !textsf(an !pkg(eqexam) question is contained in this rtVW environment)
867 \end{rtVW}
868 \begin{rtVW}
869 % !textsf(an !pkg(eqexam) question is contained in this rtVW environment)
870 \end{rtVW}
871 ...
872 \eRTVToks
873 \end{Verbatim}
874 Refer to the file \texttt{db1.tex}, \texttt{db2.tex},\dots, \texttt{db4.tex} for more specific
875 examples. The DB \ameta{name} must be unique among all the DB test files used.
876
877 The next step is to input your DB files. To do this, execute either of the commands
878 \cs{useTheseDBs} or \cs{useProbDBs} prior to the opening of an \env{exam} environment (\pkg{eqexam}),
879 or perhaps in the preamble. The syntax is,
880 \bVerb\takeMeasure{\string\useTheseDBs\darg{\ameta{db\SUB{1}},\ameta{db\SUB{2}},...,\ameta{db\SUB{n}}}}%
881 \setlength\eflength{\bxSize}%
882 \begin{minipage}{\bxSize}\def\1{\rlap{\sffamily\hskip\eflength(An alias for \cs{useTheseDBs})}}\kern0pt
883 \begin{Verbatim}[frame=single,commandchars=!()]
884 \useTheseDBs{!ameta(db!SUB(1)),!ameta(db!SUB(2)),...,!ameta(db!SUB(n))}
885 !1\useProbDBs{!ameta(db!SUB(1)),!ameta(db!SUB(2)),...,!ameta(db!SUB(n))}
886 \end{Verbatim}
887 \end{minipage}\eVerb The argument of \cs{useTheseDBs} is a comma-delimited
888 list of file names. Each file name contains a
889 \cs{bRTVToks}/\penalty0\cs{eRTVToks} construct. Within this pair are
890 \env{rtVW} environments, as described in
891 \hyperref[ss:RTVToks]{Section~\ref*{ss:RTVToks}}. The \cs{useTheseDBs}
892 command inputs the files listed in its comma-delimited argument; a warning is
893 emitted if one or more of the files are not found. The default extension is
894 \texttt{.tex}, \cs{useTheseDBs\darg{db1,db2}} inputs the files
895 \texttt{db1.tex} and \texttt{db2.tex}, if they exist, while
896 \cs{useTheseDBs\darg{db1.def,db2.db}} inputs the files \texttt{db1.def} and
897 \texttt{db2.db}, if they exist. The command \cs{useProbDBs} is an alias for
898 \cs{useTheseDBs}.
899
900 Once the database files have been input, in the body of the document you can extract
901 questions using \cs{useRanTok}; for example, \cs{useRanTok[DB1]\darg{1}} extracts the question
902 with an index of 1 from the database file DB1;\footnote{It is assumed that DB1 is the \ameta{name}
903 is the required argument of \cs{bRTVToks}, which is declared in the \texttt{db1.tex} file.} \cs{useRanTok[DB2]\darg{2}} extracts the question
904 with an index of 2 from the database file DB2, and so on.
905
906 Refer to the demonstration file \texttt{mc-db.tex} for an example.
907
908 \subsection{Striving for uniqueness of choices}
909
910 By default, when you expand \cs{useRanTok\darg{1}} and later you expand
911 \cs{useRanTok\darg{1}} again you get the exact same result;\footnote{Here, we
912 are assuming the \ameta{name} of the token list is the same for both
913 expansions of \cs{useRanTok\darg{1}}.} this is the normal behavior. However,
914 in the context of posing questions from a database of questions, repeating
915 the questions is not what is wanted necessarily. In the next two subsections,
916 we speak to the problem, first within a single-version document, and
917 secondly, within a multi-version document.
918
919
920 \subsubsection{For documents with a single version}
921
922 The issue of not wanting to repeat a question from a database comes up when
923 you want to pose several questions from a given database file. We illustrate
924 using the demo file \texttt{mc-db.tex} found in the \texttt{examples} folder.
925 In that file, the exam has two parts, as shown in
926 \hyperref[fig:2prts]{Figure~\ref*{fig:2prts}}.\footnote{The verbatim listing
927 here has been simplified.}
928 \begin{figure}[htb]\centering
929 \settowidth{\eflength}{\ttfamily\string\useRanTok[DB1]\darg{1}}%
930 \edef\x{\the\eflength}%
931 \setlength\eflength{\x+\widthof{\textsf{\quad\%An alternate approach}\texttt{ }}}%
932 \def\0{\rlap{\hskip\x\relax\quad\% \textsf{An alternate approach}}}%
933 \def\1{\rlap{\hskip\x\relax\quad\% \cs{begin\darg{Part2}}}}%
934 \def\2{\rlap{\hskip\x\relax\quad\% \cs{useRanTok[DB1]\darg{3}}}}%
935 \def\3{\rlap{\hskip\x\relax\quad\% \cs{useRanTok[DB1]\darg{4}}}}%
936 \def\4{\rlap{\hskip\x\relax\quad\% \cs{end\darg{Part2}}}}%
937 \fboxsep0pt
938 \begin{minipage}{\eflength}
939 \begin{Verbatim}[commandchars=!()]
940 \begin{Part1}
941 \useRanTok[DB1]{1}
942 \useRanTok[DB1]{2}
943 \end{Part1}
944
945 !0% !textsf( First approach)
946 !1\begin{Part2}
947 !2\useRanTok[DB1]{1}
948 !3\useRanTok[DB1]{2}
949 !4\end{Part2}
950 \end{Verbatim}
951 \end{minipage}
952 \caption{Simplified two-part exam}\label{fig:2prts}
953 \end{figure}
954 For \textsf{Part1}, we take two problems (at random) from \textsf{DB1}. In
955 \textsf{Part2}, we take two problems again from \textsf{DB1}; these two will
956 be the \emph{same} as the ones chosen from \textsf{Part1}. To get two
957 \emph{different} questions the natural approach is to write
958 \cs{useRanTok[DB1]\darg{3}} and \cs{useRanTok[DB1]\darg{4}}, as shown on the
959 right in \hyperref[fig:2prts]{Figure~\ref*{fig:2prts}}. Now, returning to the \textsf{First approach}, there is a way of forcing
960 \pkg{ran\_toks} to choose two different question even though the indexes used are the same.
961
962 To have different questions appear when you specify \verb~\useRanTok[DB1]{1}~
963 and \verb~\useRanTok[DB1]{2}~, first expand the command
964 \cs{uniqueXDBChoicesOn}, perhaps between parts or in the preamble. When
965 \cs{uniqueXDBChoicesOn} is expanded, \cs{useRanTok} tries to find an
966 ``unused'' choice.
967 \begin{Verbatim}[xleftmargin=\parindent,commandchars=!()]
968 \uniqueXDBChoicesOn
969 \begin{document}
970 ...
971 \begin{Part1}
972 \useRanTok[DB1]{1}
973 \useRanTok[DB1]{2}
974 \end{Part1}
975
976 %\uniqueXDBChoicesOn
977
978 \begin{Part2}
979 \useRanTok[DB1]{1}
980 \useRanTok[DB1]{2}
981 \end{Part2}
982 \end{Verbatim}
983 The command \cs{uniqueXDBChoicesOff} turns off the feature of striving to
984 find ``unused'' choices. Additional discussion on \cs{uniqueXDBChoicesOn} is
985 found in the next section; the command \cs{InputUsedIDs}, discussed in the
986 next section, is not needed when the \pkg{eqexam} document \emph{does not
987 have} multiple versions. You can experiment with striving to find unused
988 questions in the demo file \texttt{mc-db.tex}.
989
990 \subsubsection{For documents with multiple versions}
991
992 The scheme outlined in \hyperref[s:basicFunc]{Section~\ref*{s:basicFunc}} works well for an
993 \pkg{eqexam} document that only has one version in the source file. The way
994 \pkg{ran\_toks} works, it will not repeat random choices --- unless you
995 sample from a same DB file more times than there are problems in that file;
996 for example, suppose \texttt{db1.tex} has two questions in it, if you execute
997 \cs{useRanTok[DB1]\darg{1}}, \cs{useRanTok[DB1]\darg{2}}, and
998 \cs{useRanTok[DB1]\darg{3}}, then the problem selected by
999 \cs{useRanTok[DB1]\darg{3}} is the same as \cs{useRanTok[DB1]\darg{1}}. This
1000 latter situation is not likely, is it?
1001
1002 One of the very powerful features of \pkg{eqexam} is that a single source
1003 file can have multiple versions in it.
1004 \begin{Verbatim}[xleftmargin=\parindent,commandchars=!()]
1005 \examNum{1}
1006 \numVersions{4}
1007 \forVersion{a} %!textsf( a, b, c, d)
1008 \vA{\useThisSeed{54356}}
1009 \vB{\useThisSeed{577867}}
1010 \vC{\useThisSeed{6746788}}
1011 \vD{\useThisSeed{856785}}
1012 \end{Verbatim}
1013 The above shows how to set up a multi-version \pkg{eqexam} document, see the
1014 \pkg{eqexam} documentation for more details. Here, as in the demo file
1015 \texttt{mc-dbu.tex}, we declare 4 versions (a, b, c, and d).
1016 \cs{forVersion\darg{a}} declares the next compile is for version a (or A,
1017 either one). List also is a method of passing an initial seed to the
1018 pseudo-random number generator, for each version. (These can be arbitrarily
1019 typed in, or obtained by the methods discussed in
1020 \textbf{\nameref{para:ControlSeed}} on page~\pageref*{para:ControlSeed}.)
1021
1022 \paragraph*{The problem.} For a multi-version \pkg{eqexam} document, where
1023 each version samples from the same set of DB Test files, later versions of the exam
1024 may have questions that are repeats of the ones posed in earlier versions of
1025 the same source file. This may or may not be a problem if the different
1026 versions are given to different classes at approximately the same time where
1027 there is no opportunity for the details of the test to ``leak out'' from one
1028 class to another.
1029
1030 \paragraph*{The solution.} The solution to this problem requires the introduction of several
1031 new commands.
1032 \bVerb\takeMeasure{\string\uniqueXDBChoicesOn}%
1033 \setlength\eflength{\bxSize}%
1034 \begin{minipage}{\bxSize}\kern0pt\def\1{\rlap{\sffamily\hskip\eflength\%\textsf{ to view the IDs of problems used}}}\relax
1035 \def\2{\rlap{\sffamily\hskip\eflength\%\textsf{ preamble only (required)}}}\relax
1036 \def\3{\rlap{\sffamily\hskip\eflength\%\textsf{ there is also \cs{uniqueXDBChoicesOff} (the default)}}}\relax
1037 \begin{Verbatim}[frame=single,commandchars=!()]
1038 !3\uniqueXDBChoicesOn
1039 !2\InputUsedIDs
1040 !1%\viewIDstrue
1041 \end{Verbatim}
1042 \end{minipage}\eVerb The \cs{uniqueXDBChoicesOn} command
1043 brings some special code into the \cs{useRanTok} command; this special code
1044 tries to select problems that have not already been selected by earlier
1045 versions of the source document. Key to this selection process is that the
1046 special code needs to know which questions were earlier selected; that is the
1047 role of the \cs{InputUsedIDs}. This latter command uses the value declared in
1048 \cs{numVersions}, so it must appear \emph{after} the declaration of the
1049 number of versions.
1050
1051 When \cs{uniqueXDBChoicesOn} is expanded, as the source document is compiled,
1052 an auxiliary file named \cs{jobname-ver\ameta{Ltr}.cut} is written. This
1053 file keeps a record of the problem ID of the problems selected, believe it or
1054 not. \cs{InputUsedIDs} inputs the appropriate CUT files:
1055 \begingroup\tightsettings
1056 \begin{itemize}
1057 \item for version B, \cs{jobname-verA.cut} is input;
1058 \item for version C, \cs{jobname-verA.cut}, \cs{jobname-verB.cut} are input;
1059 \item for version D, \cs{jobname-verA.cut}, \cs{jobname-verB.cut}, \cs{jobname-verC.cut} are input;
1060 \item and so on.
1061 \end{itemize}
1062 \endgroup\noindent
1063 In this way, when you compile version \ameta{Ltr}, the document inputs all
1064 the information it needs about previous versions to make in informed choice.
1065
1066 \paragraph*{Workflow.} When compiling a multi-version \pkg{eqexam} document, do the following:
1067 \begin{enumerate}
1068 \item Build each version in \emph{alphabetical order}, that is, compile with \cs{forVersion\darg{a}},
1069 then \cs{forVersion\darg{b}}, and so on.
1070 \item Rename PDF produced to reflect the version \ameta{Ltr}; eg, \verb~\jobname-verA.pdf~ or
1071 \verb!\jobname-sec02.pdf!, or whatever.\footnote{The demo file \texttt{ctrl-build.tex} shows
1072 how to build all versions and rename the final PDF files all from one controlling file.}
1073 \end{enumerate}
1074
1075 %\paragraph*{Final comments.} \cs{uniqueXDBChoicesOn} does several things, it causes \cs{useRanTok}
1076 %to use some special code to ensure cross-version uniqueness of choices, but
1077 %it also initiates writing of the choice history to the auxiliary CUT files
1078 %\cs{jobname-ver\ameta{Ltr}.cut}. By placing \cs{uniqueXDBChoicesOff} in
1079 %the body of the document (outside a group, perhaps) that turns off the
1080 %execution of the special code as well and writing to the CUT files. I believe
1081 %you can later in the document turn this back on with \cs{uniqueXDBChoicesOn},
1082 %though I have not done a lot of testing of this.
1083
1084 \newtopic\noindent
1085 Now, I simply must get back to my retirement. \dps
1086
1087 \end{document}