summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/probsoln/probsoln-manual.html
blob: 74e787ec6b0b785cfd33e587f60a66ac51e03a12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<!--Converted with LaTeX2HTML 2002 (1.67)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>probsoln v3.0: creating problem sheets optionally with solutions</TITLE>
<META NAME="description" CONTENT="probsoln v3.0: creating problem sheets optionally with solutions">
<META NAME="keywords" CONTENT="probsoln-manual">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="LaTeX2HTML v2002">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">


</HEAD>

<BODY >
<A NAME="top"></A>

<P>

<P>

 <H1 ALIGN="CENTER">probsoln v3.0: creating problem sheets optionally with solutions</H1>
<P ALIGN="CENTER"><STRONG>Nicola L.C. Talbot
<BR>
<BR>
School of Computing Sciences
<BR>
University of East Anglia
<BR>
Norwich. Norfolk
<BR>
NR4 7TJ. United Kingdom.
<BR><TT><A NAME="tex2html1"
  HREF="http://theoval.cmp.uea.ac.uk/~nlct/">http://theoval.cmp.uea.ac.uk/~nlct/</A></TT></STRONG></P>
<P ALIGN="CENTER"><STRONG>26th August 2008</STRONG></P>
<BR>

<H2><A NAME="SECTION00010000000000000000">
Contents</A>
</H2>
<!--Table of Contents-->

<UL>
<LI><A NAME="tex2html16"
  HREF="probsoln-manual.html#SECTION00020000000000000000">1 Introduction</A>
<LI><A NAME="tex2html17"
  HREF="probsoln-manual.html#SECTION00030000000000000000">2 Package Options</A>
<LI><A NAME="tex2html18"
  HREF="probsoln-manual.html#SECTION00040000000000000000">3 Showing and Hiding Solutions</A>
<LI><A NAME="tex2html19"
  HREF="probsoln-manual.html#SECTION00050000000000000000">4 General Formatting Commands</A>
<LI><A NAME="tex2html20"
  HREF="probsoln-manual.html#SECTION00060000000000000000">5 Defining a Problem</A>
<LI><A NAME="tex2html21"
  HREF="probsoln-manual.html#SECTION00070000000000000000">6 Using a Problem</A>
<LI><A NAME="tex2html22"
  HREF="probsoln-manual.html#SECTION00080000000000000000">7 Loading Problems From External Files</A>
<LI><A NAME="tex2html23"
  HREF="probsoln-manual.html#SECTION00090000000000000000">8 Iterating Through Datasets</A>
<LI><A NAME="tex2html24"
  HREF="probsoln-manual.html#SECTION000100000000000000000">9 Random Number Generator</A>
<LI><A NAME="tex2html25"
  HREF="probsoln-manual.html#SECTION000110000000000000000">10 Compatibility With Versions Prior to 3.0</A>
<LI><A NAME="tex2html26"
  HREF="probsoln-manual.html#SECTION000120000000000000000">Index</A>
</UL>
<!--End of Table of Contents-->
<P>

<H1><A NAME="SECTION00020000000000000000">
1 Introduction</A>
</H1>
The <TT>probsoln</TT> package is designed for teachers or
lecturers who want to create problem sheets for their 
students.  This package was designed with specifically 
mathematics problems in mind, but can be used for other 
subjects as well.  The idea is to create a file containing a
large number of problems with their solutions which can be 
read in by LaTeX, and then select a number of problems to
typeset.  This means that once the database has been set up,
each year you can easily create a new problem sheet that is
sufficiently different from the previous year, thus
preventing the temptation of current students seeking out
the previous year's students, and checking out their
answers.  There is also an option that can be passed to the
package to determine whether or not the solutions should be
printed.  In this way, one file can either produce the
student's version or the teacher's version.

<P>
<A HREF="probsoln-manual.html#top">Top</A>

<P>

<H1><A NAME="SECTION00030000000000000000"></A><A NAME="sec:pkgopt"></A>
<BR>
2 Package Options
</H1>
The following options may be passed to this package:
<DL>
<DT><STRONG><TT>answers</TT><A NAME="673"></A></STRONG></DT>
<DD>Show the answers
</DD>
<DT><STRONG><TT>noanswers</TT><A NAME="676"></A></STRONG></DT>
<DD>Don't show the answers (default)
</DD>
<DT><STRONG><TT>draft</TT><A NAME="679"></A></STRONG></DT>
<DD>Display the label and dataset name when a problem is used
</DD>
<DT><STRONG><TT>final</TT><A NAME="682"></A></STRONG></DT>
<DD>Don't display label and dataset name when a problem is used
</DD>
</DL>

<P>
<A HREF="probsoln-manual.html#top">Top</A>

<P>

<H1><A NAME="SECTION00040000000000000000"></A><A NAME="sec:showanswers"></A>
<BR>
3 Showing and Hiding Solutions
</H1>

<P>
In addition to the <TT>answers</TT><A NAME="688"></A> and <TT>noanswers</TT><A NAME="691"></A> package
options, it is also possible to show or suppress the solutions
using <TT>&#092;showanswers</TT> and
<TT>&#092;hideanswers</TT>, respectively.
The boolean variable <TT>showanswers</TT><A NAME="694"></A> determines whether the
answers should be displayed. You can use this value with the
<TT>ifthen</TT><A NAME="697"></A> package to specify different text depending on 
whether the solutions should be displayed. For example:
<PRE>
Assignment 1\ifthenelse{\boolean{showanswers}}{ (Solution Sheet)}{}
</PRE>
Alternatively you can use <TT>&#092;ifshowanswers</TT><A NAME="700"></A>...<TT>&#092;else</TT>...
<TT>&#092;fi</TT>:
<PRE>
Assignment 1\ifshowanswers\space (Solution Sheet)\fi
</PRE>

<P>
For longer passages, you can use the environments <A NAME="1547"></A><TT>onlyproblem</TT>
and <A NAME="1551"></A><TT>onlysolution</TT>. For example:
<PRE>
\begin{onlyproblem}%
What is the derivative of $f(x) = x^2$?
\end{onlyproblem}%
\begin{onlysolution}%
$f'(x) = 2x$
\end{onlysolution}
</PRE>
The above will only display the question if <TT>showanswers</TT><A NAME="705"></A>
is false and will only display the solution if <TT>showanswers</TT><A NAME="708"></A>
is true. If you want the question to appear in the answer
sheet as well as the solution, then don't put the question in
the <TT>onlyproblem</TT> environment:
<PRE>
What is the derivative of $f(x) = x^2$?
\begin{onlysolution}%
Solution: $f'(x) = 2x$
\end{onlysolution}
</PRE>
<B>NOTE:</B> You can't use verbatim text in the body of the
<TT>onlyproblem</TT><A NAME="712"></A> or <TT>onlysolution</TT><A NAME="715"></A> environments.
If you need verbatim-like text, then try packages such as
<TT>alltt</TT><A NAME="718"></A>. Remember that you also can't use verbatim
text in command arguments.

<P>
<A HREF="probsoln-manual.html#top">Top</A>

<P>

<H1><A NAME="SECTION00050000000000000000"></A><A NAME="sec:formatting"></A>
<BR>
4 General Formatting Commands
</H1>

<P>
The commands and environments described in this section are
provided to assist formatting problems and their solutions.
<A NAME="1556"></A>
<BR CLEAR="ALL">
<HR><code>\begin{solution}</code><I>text</I><code>\end{solution}</code>
<BR CLEAR="ALL">
<HR>This is equivalent to 
<code>\par\noindent\textbf{\solutionname}:</code><I>text</I>
where <TT>&#092;solutionname</TT> defaults
to "Solution". Note that you must place the <TT>solution</TT>
environment inside the <TT>onlysolution</TT><A NAME="725"></A> environment or
between <TT>&#092;ifshowanswers</TT><A NAME="728"></A>...<TT>&#092;fi</TT> to ensure that it
is suppressed when the solutions are not wanted. (See
<A HREF="probsoln-manual.html#sec:showanswers">Showing and
Hiding Solutions</A>.) 

<P>
Note that the <TT>probsoln</TT> package will only define the 
<TT>solution</TT> environment if it is not already defined.

<P>
<A NAME="1560"></A>
<BR CLEAR="ALL">
<HR><code>\begin{textenum}</code>...<code>\end{textenum}</code>
<BR CLEAR="ALL">
<HR>The <TT>textenum</TT> environment is like the <TT>enumerate</TT><A NAME="734"></A> 
environment but is in-line. It uses the same counter that the
<TT>enumerate</TT> environment would use at that level so the
question can be compact but the answer can use <TT>enumerate</TT>
instead. For example:
<PRE>
\begin{onlyproblem}%
Differentiate the following: 
\begin{textenum}
\item $f(x)=2^x$;
\item $f(x)=\cot(x)$
\end{textenum}
\end{onlyproblem}
\begin{onlysolution}
\begin{enumerate}
\item 
\begin{align*}
f(x) &amp;= 2^x = \exp(\ln(x^2)) =\exp(2\ln(x))\\
f'(x) &amp;= \exp(2\ln(x))\times \frac{2}{x}\\
 &amp;= f(x)\frac{2}{x}
\end{align*}
\item
\begin{align*}
f(x) &amp;= \cot(x) = (\tan(x))^{-2}\\
f'(x) &amp;= -(\tan(x))^{-2}\times\sec^2(x)\\
&amp;=-\csc^2x
\end{align*}
\end{enumerate}
\end{onlysolution}
</PRE>
In this example, the items in the question are brief, so an
<TT>enumerate</TT><A NAME="739"></A> environment would result in a lot of 
unnecessary white space,
but the answers require more space, so an <TT>enumerate</TT>
environment is more appropriate. Since the <TT>textenum</TT><A NAME="743"></A>
environment uses the same counters as the <TT>enumerate</TT>
environment, the question and answer sheets use consistent
labelling. Note that there are other packages available on
CTAN that you can use to create in-line lists. Check the
<A NAME="tex2html2"
  HREF="http://www.tex.ac.uk/tex-archive/help/Catalogue/bytopic.html#enumeration">TeX 
Catalogue</A> for
further details.

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;correctitem</TT><A NAME="747"></A>
<BR><TT>&#092;incorrectitem</TT><A NAME="750"></A>
<BR CLEAR="ALL">
<HR>You can use the commands <TT>&#092;correctitem</TT> and <TT>&#092;incorrectitem</TT> 
in place of <TT>&#092;item</TT><A NAME="753"></A>. If the solutions are suppressed, these
commands behave in the same way as <TT>&#092;item</TT>, otherwise they
format the item label using one of the commands:

<BR CLEAR="ALL">
<HR><TT>&#092;correctitemformat</TT><A NAME="756"></A><TT>{</TT><EM>label</EM><TT>}</TT>
<BR><TT>&#092;incorrectitemformat</TT><A NAME="759"></A><TT>{</TT><EM>label</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>For example:
<PRE>
Under which of the following functions does $S=\{a_1,a_2\}$
become a probability space?
\begin{enumerate}
\incorrectitem $P(a_1)=\frac{1}{3}$, $P(a_2)=\frac{1}{2}$
\correctitem $P(a_1)=\frac{3}{4}$, $P(a_2)=\frac{1}{4}$
\correctitem $P(a_1)=1$, $P(a_2)=0$
\incorrectitem $P(a_1)=\frac{5}{4}$, $P(a_2)=-\frac{1}{4}$
\end{enumerate}
</PRE>

<P>
<A HREF="probsoln-manual.html#top">Top</A>

<P>

<H1><A NAME="SECTION00060000000000000000"></A><A NAME="sec:defproblem"></A>
<BR>
5 Defining a Problem
</H1>

<P>
It is possible to construct a problem sheet with solutions using
the commands described in the previous sections, however it is
also possible to define a set of problems for later use. In this
way you can create an external file containing many problems some
or all of which can be loaded and used in a document. The
<TT>probsoln</TT> package has a default data set labelled
"default" in which you can store problems or you can create
multiple data sets. You can then iterate through each problem
in a problem set. You can use a previously defined problem more
than once, which means that by judicious use of <TT>onlyproblem</TT><A NAME="766"></A>,
<TT>onlysolution</TT><A NAME="769"></A> or the <TT>showanswers</TT><A NAME="772"></A> boolean variable
in conjunction with <TT>&#092;showanswers</TT><A NAME="775"></A> and <TT>&#092;hideanswers</TT><A NAME="778"></A>,
you can print the solutions in a different location to the
questions (for example in an appendix).

<P>
<A NAME="1565"></A>
<BR CLEAR="ALL">
<HR><code>\begin{defproblem}</code><TT>[</TT><EM>n</EM><TT>]{</TT><EM>label</EM><TT>}</TT><I>definition</I><code>\end{defproblem}</code>
<BR CLEAR="ALL">
<HR>This defines the problem whose label is given by <I>label</I>.
The label must be unique for a given data set and should not
contain active characters. (Active characters include the special
characters such as $ and &amp;, but some packages may make other
symbols active. For example, the <TT>ngerman</TT><A NAME="781"></A> and <TT>babel</TT><A NAME="784"></A>
packages make certain punctuation active. Check the relevant 
package documentation for details.)

<P>
If <TT>defproblem</TT> occurs in the document or is included via
<TT>&#092;input</TT> or <TT>&#092;include</TT>, then the problem will be added to
the default data set. If <TT>defproblem</TT> occurs in an external
file that is loaded using one of the commands defined in
<A HREF="probsoln-manual.html#sec:load">Loading Problems From 
External Files</A> then the problem will be added to
the specified data set.

<P>
The contents of the <TT>defproblem</TT> environment should be the
text that defines the problem. This may include any of the
commands defined in 
<A HREF="probsoln-manual.html#sec:showanswers">Showing and Hiding 
Solutions</A> and <A HREF="probsoln-manual.html#sec:formatting">General Formatting 
Commands</A>.

<P>
The problem may optionally take <I>n</I> arguments (where 
<I>n</I> is from 0 to 9). The arguments can be referenced
in the definition via <TT>#1</TT>,...,<TT>#9</TT>.
If <I>n</I> is omitted then the problem doesn't take any
arguments.
The following example defines a problem with one argument:
<PRE>
\begin{defproblem}[1]{diffsin}
Differentiate $f(x)=\sin(#1x)$.
\begin{onlysolution}%
\begin{solution}
$f'(x) = #1\cos(#1x)$
\end{solution}
\end{onlysolution}
\end{defproblem}
</PRE>

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;newproblem</TT><A NAME="790"></A><TT>[</TT><EM>n</EM><TT>]{</TT><EM>label</EM><TT>}{</TT><EM>problem</EM><TT>}{</TT><EM>solution</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This is a shortcut command for:
<TT>
<TT>&#092;begin</TT>{defproblem}<TT>[</TT><EM>n</EM><TT>]{</TT><EM>label</EM><TT>}</TT>%
<I>problem</I>%
<TT>&#092;begin</TT>{onlysolution}%
<TT>&#092;begin</TT>{solution}%
<I>solution</I>%
<TT>&#092;end</TT>{solution}%
<TT>&#092;end</TT>{onlysolution}%
<TT>&#092;end</TT>{defproblem}
</TT>
For example:
<PRE>
\newproblem[1]{diffsin}{%
\(f(x) = \sin(#1x)\)
}{%
\(f'(x) = #1\cos(#1x)\)
}
</PRE>
is equivalent to
<PRE>
\begin{defproblem}[1]{diffcos}%
\(f(x) = \cos(#1x)\)
\begin{onlysolution}%
\begin{solution}%
\(f'(x) = -#1\sin(#1x)\)
\end{solution}%
\end{onlysolution}%
\end{defproblem}
</PRE>
(In this example, the argument will need to be a positive number
to avoid a double minus in the answer. If you want to perform
floating point arithmetic on the arguments, then try the
<TT>fp</TT><A NAME="793"></A> package.)

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;newproblem*</TT><A NAME="796"></A><TT>[</TT><EM>n</EM><TT>]{</TT><EM>label</EM><TT>}{</TT><EM>definition</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This is a shortcut for:
<TT>
<TT>&#092;begin</TT>{defproblem}<TT>[</TT><EM>n</EM><TT>]{</TT><EM>label</EM><TT>}</TT>%
<I>definition</I>%
<TT>&#092;end</TT>{defproblem}
</TT>

<P>
<B>NOTE:</B> Verbatim text must not be used in the contents of <TT>defproblem</TT><A NAME="799"></A>
or in any of the arguments to <TT>&#092;newproblem</TT> or
<TT>&#092;newproblem*</TT>. If you need verbatim-like text consider using
<TT>&#092;texttt</TT> or the <TT>alltt</TT><A NAME="802"></A> package.

<P>
<A HREF="probsoln-manual.html#top">Top</A>

<P>

<H1><A NAME="SECTION00070000000000000000"></A><A NAME="sec:useproblem"></A>
<BR>
6 Using a Problem
</H1>

<P>
Once you have defined a problem using <TT>defproblem</TT><A NAME="808"></A> or
<TT>&#092;newproblem</TT> (see 
<A HREF="probsoln-manual.html#sec:defproblem">Defining a 
Problem</A>), you can later display the problem 
using:

<BR CLEAR="ALL">
<HR><TT>&#092;useproblem</TT><A NAME="811"></A><TT>[</TT><EM>data set</EM><TT>]{</TT><EM>label</EM><TT>}{</TT><EM>arg<SUB>1</SUB></EM><TT>}</TT>...
<TT>{</TT><EM>arg<SUB>N</SUB></EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>where <I>data set</I> is the name of the data set that contains
the problem (the default data set is used if omitted), 
<I>label</I> is the label identifying the required problem and
<I>arg<SUB>1</SUB></I>, ..., 
<I>arg<SUB>N</SUB></I> 
are the arguments to pass to the problem, if the problem was 
defined to have arguments (where N is the number 
of arguments specified when the problem was defined).

<P>
For example, in the previous section the problem <TT>diffcos</TT> 
was defined to have one argument, so it can be used as follows:
<PRE>
\useproblem{diffcos}{3}
</PRE>
This will be equivalent to:
<PRE>
\(f(x) = \cos(3x)\)
\begin{onlysolution}%
\begin{solution}%
\(f'(x) = -3\sin(3x)\)
\end{solution}%
\end{onlysolution}%
</PRE>

<P>
<A HREF="probsoln-manual.html#top">Top</A>

<P>

<H1><A NAME="SECTION00080000000000000000"></A><A NAME="sec:load"></A>
<BR>
7 Loading Problems From External Files
</H1>

<P>
You can store all your problem definitions (see
<A HREF="probsoln-manual.html#sec:defproblem">Defining New 
Problems</A>) in an external file. 
These problems can all be appended to the default data set by
including the file via <TT>&#092;input</TT><A NAME="817"></A> or they can be appended
to other data sets using one of the commands described below.
Once you have loaded all the required problems, you can
iterate through the data sets using the commands described
in <A HREF="probsoln-manual.html#sec:foreach">Iterating 
Through Datasets</A>. Note that the commands below
will create a new data set, if the named data set doesn't
exist.

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;loadallproblems</TT><A NAME="820"></A><TT>[</TT><EM>data set</EM><TT>]{</TT><EM>filename</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This will load all problems defined in <I>filename</I> and
append them to the specified data set, in the order in which
they are defined in the file. If <I>data set</I> is
omitted, the default data set will be used. If <I>data set</I>
doesn't exist, it will be created.

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;loadselectedproblems</TT><A NAME="823"></A><TT>[</TT><EM>data set</EM><TT>]{</TT><EM>labels</EM><TT>}{</TT><EM>filename</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This is like <TT>&#092;loadproblems</TT>, but only those problems whose
label is listed in the comma-separated list <I>labels</I> are
loaded. For example, if I have some problems defined in the
file <TT>derivatives.tex</TT>, then
<PRE>
\loadselectedproblems{diffsin,diffcos}{derivatives}
</PRE>
will only load the problems whose labels are <TT>diffsin</TT>
and <TT>diffcos</TT>, respectively. All the other problems in 
the file will remain undefined.

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;loadrandomproblems</TT><A NAME="826"></A><TT>[</TT><EM>data set</EM><TT>]{</TT><EM>n</EM><TT>}{</TT><EM>filename</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This randomly loads <I>n</I> problems from <I>filename</I> and
adds them to the given data set. If <I>data set</I> is omitted,
the default data set is assumed. Note that the problems will be
added to the data set in a random order, not in the order in
which they were defined. There must be at least <I>n</I> problems
defined in <I>filename</I>.

<P>
<B>NOTE:</B> It is generally not a good idea to place anything in 
<I>filename</I> that is not inside the body of <TT>defproblem</TT><A NAME="829"></A> 
or in the arguments to <TT>&#092;newproblem</TT><A NAME="832"></A> or <TT>&#092;newproblem*</TT><A NAME="835"></A>.
All the commands in this section input the external file within
a local scope, so commands definitions would need to be made
global to have any effect. In addition, <TT>&#092;loadrandomproblems</TT>
has to load each file twice, which means that anything outside
a problem definition will be parsed twice.

<P>

<P>
<A HREF="probsoln-manual.html#top">Top</A>

<P>

<H1><A NAME="SECTION00090000000000000000"></A><A NAME="sec:foreach"></A>
<BR>
8 Iterating Through Datasets
</H1>

<P>
Once you have defined all your problems for a given data set,
you can use an individual problem with <TT>&#092;useproblem</TT><A NAME="841"></A>
(see <A HREF="probsoln-manual.html#sec:useproblem">Using a 
Problem</A>) but it is more likely that you will
want to iterate through all the problems so that you don't need
to remember the labels of all the problems you have defined.

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;foreachproblem</TT><A NAME="844"></A><TT>[</TT><EM>data set</EM><TT>]{</TT><EM>body</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This does <I>body</I> for each problem in the given data set.
If <I>data set</I> is omitted, the default data set is used.
Within <I>body</I> you can use 
<TT>&#092;thisproblem</TT> to use the
current problem and <TT>&#092;thisproblemlabel</TT> 
to access the current label. If the problem requires arguments,
you will be prompted for them, so if you want to use this
approach you will need to use LaTeX in interactive mode. If
you do provide arguments, they will be stored in the event that
you need to iterate through the data set again. The
arguments will be included in <TT>&#092;thisproblem</TT>, so you only
need to use <TT>&#092;thisproblem</TT> without having to specify
<TT>&#092;useproblem</TT><A NAME="847"></A>. For example, to iterate through all problems
in the default data set:
<PRE>
\begin{enumerate}
\foreachproblem{\item\thisproblem}
\end{enumerate}
</PRE>

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;foreachdataset</TT><A NAME="850"></A><TT>{</TT><EM>cmd</EM><TT>}{</TT><EM>body</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This does <I>body</I> for each of the defined data sets. Within
<I>body</I>, <I>cmd</I> will be set to the name of the current
data set. For example, to display all problems in all data sets:
<PRE>
\begin{enumerate}
\foreachdataset{\thisdataset}{%
\foreachproblem[\thisdataset]{\item\thisproblem}}
\end{enumerate}
</PRE>

<P>
Suppose I have two external files called
<TT>derivatives.tex</TT> and <TT>probspaces.tex</TT> which
define problems using both <TT>onlyproblem</TT><A NAME="853"></A> and 
<TT>onlysolution</TT><A NAME="856"></A> for example:
<PRE>
\begin{defproblem}{cosxsqsinx}%
\begin{onlyproblem}%
$y = \cos(x^2)\sin x$.%
\end{onlyproblem}%
\begin{onlysolution}%
\[\frac{dy}{dx} = -\sin(x^2)2x\sin x + \cos(x^2)\cos x\]
\end{onlysolution}%
\end{defproblem}
</PRE>
I can write a document that creates two data sets, one for
the derivative problems and one for the problems about
probability spaces. I can then use <TT>&#092;hideanswers</TT><A NAME="859"></A> and
iterate through the require data set to produce the problems.
Later, I can use <TT>&#092;showanswers</TT><A NAME="862"></A> and iterate over all problems defined in both data
sets to produce the chapter containing all the answers. When
displaying the questions, I have taken advantage of the fact that
I can cross-reference items within an <TT>enumerate</TT><A NAME="865"></A> environment,
and redefined <TT>&#092;theenumi</TT><A NAME="868"></A> to label the questions according to
the chapter. The cross-reference label is constructed from
the problem label and is referenced in the answer section to
ensure that the answers have the same label as the questions.
<PRE>
\documentclass{report}
\usepackage{probsoln}
\begin{document}
\hideanswers
\chapter{Differentiation}
% randomly select 25 problems from derivatives.tex and add to
% the data set called 'deriv'
\loadrandomproblems[deriv]{25}{derivatives}

% Display the problems
\renewcommand{\theenumi}{\thechapter.\arabic{enumi}}
\begin{enumerate}
\foreachproblem[deriv]{\item\label{prob:\thisproblemlabel}\thisproblem}
\end{enumerate}
% You may need to change \theenumi back here

\chapter{Probability Spaces}
% randomly select 25 problems from probspaces.tex and add to
% the data set called 'spaces'
\loadrandomproblems[spaces]{25}{probspaces}

% Display the problems
\renewcommand{\theenumi}{\thechapter.\arabic{enumi}}
\begin{enumerate}
\foreachproblem[spaces]{\item\label{prob:\thisproblemlabel}\thisproblem}
\end{enumerate}
% You may need to change \theenumi back here

\appendix

\chapter{Solutions}
\showanswers
\begin{itemize}
\foreachdataset{\thisdataset}{%
\foreachproblem[\thisdataset]{\item[\ref{prob:\thisproblemlabel}]\thisproblem}
}
\end{itemize}

\end{document}
</PRE>

<P>

<P>
<A HREF="probsoln-manual.html#top">Top</A>

<P>

<H1><A NAME="SECTION000100000000000000000"></A><A NAME="sec:random"></A>
<BR>
9 Random Number Generator
</H1>

<P>
This package provides a pseudo-random number generator that is used
by <TT>&#092;loadrandomproblems</TT><A NAME="874"></A>.

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;PSNrandseed</TT><A NAME="877"></A><TT>{</TT><EM>n</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This sets the seed to <I>n</I> which must be a non-zero integer.
For example, to generate a different set of random numbers
every time you LaTeX your document,<A NAME="tex2html3"
  HREF="#foot462"><SUP>1</SUP></A> put the following in your
preamble:
<PRE>
\PSNrandseed{\time}
</PRE>
or to generate a different set of random numbers every year you
LaTeX your document:
<PRE>
\PSNrandseed{\year}
</PRE>

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;PSNgetrandseed</TT><A NAME="880"></A><TT>{</TT><EM>register</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This stores the current seed in the count register specified by 
<I>register</I>.
For example:
<PRE>
\newcount\myseed
\PSNgetrandseed{\myseed}
</PRE>

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;PSNrandom</TT><A NAME="883"></A><TT>{</TT><EM>register</EM><TT>}{</TT><EM>n</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>Generates a random integer from 1 to <I>n</I> and stores in 
the count register specified by <I>register</I>. For example,
the following generates an integer from 1 to 10 and stores it
in the register <TT>&#092;myreg</TT>:
<PRE>
\newcount\myreg
\PSNrandom{\myreg}{10}
</PRE>

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;random</TT><A NAME="886"></A><TT>{</TT><EM>counter</EM><TT>}{</TT><EM>min</EM><TT>}{</TT><EM>max</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>Generates a random integer from <I>min</I> to <I>max</I> and
stores in the given counter. For example, the following generates
a random number between 3 and 8 (inclusive) and stores it in
the counter <TT>myrand</TT>.
<PRE>
\newcounter{myrand}
\random{myrand}{3}{8}
</PRE>

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;doforrandN</TT><A NAME="889"></A><TT>{</TT><EM>n</EM><TT>}{</TT><EM>cmd</EM><TT>}{</TT><EM>list</EM><TT>}{</TT><EM>text</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>Randomly selects <I>n</I> values from the comma-separated list
given by <I>list</I> and iterates through this subset. On
each iteration it sets <I>cmd</I> to the current value and
does <I>text</I>. For example, the following will load a
randomly selected problem from two of the listed files (where
<TT>file1.tex</TT>, <TT>file2.tex</TT> and <TT>file3.tex</TT>
are files containing at least one problem):
<PRE>
\doforrandN{2}{\thisfile}{file1,file2,file3}{%
\loadrandomproblems{1}{\thisfile}}
</PRE>

<P>

<P>
<A HREF="probsoln-manual.html#top">Top</A>

<P>

<H1><A NAME="SECTION000110000000000000000">
10 Compatibility With Versions Prior to 3.0</A>
</H1>

<P>
Version 3.0 of the <TT>probsoln</TT> package completely changed the
structure of the package, but the commands described in this
section have been provided to maintain compatibility with 
earlier versions. The only problems that are likely to occur are
those where commands are contained within groups. This will 
effect any commands that are contained in external files that are
outside of the arguments to <TT>&#092;newproblem</TT><A NAME="896"></A> and <TT>&#092;newproblem*</TT><A NAME="899"></A>.
However, since the external files had to be parsed twice in
order to load the problems, this shouldn't be an issue as adding
anything other than problem definitions in those files would
be problematic anyway.

<P>
The other likely difference is where the random generator is
used in a group. This includes commands such as 
<TT>&#092;selectrandomly</TT><A NAME="902"></A>. For example, if your document contained
something like:
<PRE>
\begin{enumerate}
\selectrandomly{file1}{8}

\item Solve the following:
\begin{enumerate}
\selectrandomly{file2}{4}
\end{enumerate}

\selectrandomly{file3}{2}
\end{enumerate}
</PRE>
Then using versions prior to v3.0 will produce a different
set of random numbers since the second <TT>&#092;selectrandomly</TT>
is in a different level of grouping. If you want to ensure
that the document produces exactly the same random set with
the new version as with the old version, you will need to
get and set the random number seed. For example, the above
would need to be modified so that it becomes:
<PRE>
\begin{enumerate}
\selectrandomly{file1}{8}

\item Solve the following:
\newcount\oldseed
\PSNgetrandseed{\oldseed}
\begin{enumerate}
\selectrandomly{file2}{4}
\end{enumerate}
\PSNrandseed{\oldseed}

\selectrandomly{file3}{2}
\end{enumerate}
</PRE>

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;selectrandomly</TT><A NAME="905"></A><TT>{</TT><EM>filename</EM><TT>}{</TT><EM>n</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This is now equivalent to:
<TT>
{<TT>&#092;loadrandomproblems[</TT><EM>filename</EM><TT>]{</TT><EM>n</EM><TT>}{</TT><EM>filename</EM><TT>}</TT>}%
<TT>&#092;foreachproblem[</TT><EM>filename</EM><TT>]{</TT><EM><TT>&#092;PSNitem&#092;thisproblem&#092;endPSNitem</TT></EM><TT>}</TT>
</TT>

<P>

<BR CLEAR="ALL">
<HR><TT>&#092;selectallproblems</TT><A NAME="908"></A><TT>{</TT><EM>filename</EM><TT>}</TT>
<BR CLEAR="ALL">
<HR>This is now equivalent to:
<TT>
{<TT>&#092;loadallproblems[</TT><EM>filename</EM><TT>]{</TT><EM>filename</EM><TT>}</TT>}%
<TT>&#092;foreachproblem[</TT><EM>filename</EM><TT>]{</TT><EM><TT>&#092;PSNitem&#092;thisproblem&#092;endPSNitem</TT></EM><TT>}</TT>
</TT>

<P>
Note that in both the above cases, a new data set is created
with the same name as the file name.

<P>

<P>
<A HREF="probsoln-manual.html#top">Top</A>

<P>

<P>
<BR>

<H2><A NAME="SECTION000120000000000000000">
Index</A>
</H2><DL COMPACT>
<DT><STRONG><TT>alltt</TT></STRONG>
<DD><A HREF="probsoln-manual.html#718">3</A>
 | <A HREF="probsoln-manual.html#802">5</A>
<DT><STRONG><TT>babel</TT></STRONG>
<DD><A HREF="probsoln-manual.html#784">5</A>
<DT><STRONG><TT>&#092;correctitem</TT></STRONG>
<DD><A HREF="probsoln-manual.html#747">4</A>
<DT><STRONG><TT>&#092;correctitemformat</TT></STRONG>
<DD><A HREF="probsoln-manual.html#756">4</A>
<DT><STRONG><TT>defproblem</TT> environment</STRONG>
<DD><A HREF="probsoln-manual.html#1565">5</A>
 | <A HREF="probsoln-manual.html#799">5</A>
 | <A HREF="probsoln-manual.html#808">6</A>
 | <A HREF="probsoln-manual.html#829">7</A>
<DT><STRONG><TT>&#092;doforrandN</TT></STRONG>
<DD><A HREF="probsoln-manual.html#889">9</A>
<DT><STRONG><TT>enumerate</TT> environment</STRONG>
<DD><A HREF="probsoln-manual.html#734">4</A>
 | <A HREF="probsoln-manual.html#739">4</A>
 | <A HREF="probsoln-manual.html#865">8</A>
<DT><STRONG><TT>&#092;foreachdataset</TT></STRONG>
<DD><A HREF="probsoln-manual.html#850">8</A>
<DT><STRONG><TT>&#092;foreachproblem</TT></STRONG>
<DD><A HREF="probsoln-manual.html#844">8</A>
<DT><STRONG><TT>fp</TT></STRONG>
<DD><A HREF="probsoln-manual.html#793">5</A>
<DT><STRONG><TT>&#092;hideanswers</TT></STRONG>
<DD><A HREF="probsoln-manual.html#778">5</A>
 | <A HREF="probsoln-manual.html#859">8</A>
<DT><STRONG><TT>&#092;ifshowanswers</TT></STRONG>
<DD><A HREF="probsoln-manual.html#700">3</A>
 | <A HREF="probsoln-manual.html#728">4</A>
<DT><STRONG><TT>ifthen</TT></STRONG>
<DD><A HREF="probsoln-manual.html#697">3</A>
<DT><STRONG><TT>&#092;incorrectitem</TT></STRONG>
<DD><A HREF="probsoln-manual.html#750">4</A>
<DT><STRONG><TT>&#092;incorrectitemformat</TT></STRONG>
<DD><A HREF="probsoln-manual.html#759">4</A>
<DT><STRONG><TT>&#092;input</TT></STRONG>
<DD><A HREF="probsoln-manual.html#817">7</A>
<DT><STRONG><TT>&#092;item</TT></STRONG>
<DD><A HREF="probsoln-manual.html#753">4</A>
<DT><STRONG><TT>&#092;loadallproblems</TT></STRONG>
<DD><A HREF="probsoln-manual.html#820">7</A>
<DT><STRONG><TT>&#092;loadrandomproblems</TT></STRONG>
<DD><A HREF="probsoln-manual.html#826">7</A>
 | <A HREF="probsoln-manual.html#874">9</A>
<DT><STRONG><TT>&#092;loadselectedproblems</TT></STRONG>
<DD><A HREF="probsoln-manual.html#823">7</A>
<DT><STRONG><TT>&#092;newproblem</TT></STRONG>
<DD><A HREF="probsoln-manual.html#790">5</A>
 | <A HREF="probsoln-manual.html#832">7</A>
 | <A HREF="probsoln-manual.html#896">10</A>
<DT><STRONG><TT>&#092;newproblem*</TT></STRONG>
<DD><A HREF="probsoln-manual.html#796">5</A>
 | <A HREF="probsoln-manual.html#835">7</A>
 | <A HREF="probsoln-manual.html#899">10</A>
<DT><STRONG><TT>ngerman</TT></STRONG>
<DD><A HREF="probsoln-manual.html#781">5</A>
<DT><STRONG><TT>onlyproblem</TT> environment</STRONG>
<DD><A HREF="probsoln-manual.html#1547">3</A>
 | <A HREF="probsoln-manual.html#712">3</A>
 | <A HREF="probsoln-manual.html#766">5</A>
 | <A HREF="probsoln-manual.html#853">8</A>
<DT><STRONG><TT>onlysolution</TT> environment</STRONG>
<DD><A HREF="probsoln-manual.html#1551">3</A>
 | <A HREF="probsoln-manual.html#715">3</A>
 | <A HREF="probsoln-manual.html#725">4</A>
 | <A HREF="probsoln-manual.html#769">5</A>
 | <A HREF="probsoln-manual.html#856">8</A>
<DT><STRONG>package options</STRONG>
<DD><DL COMPACT>
<DT><STRONG><TT>answers</TT></STRONG>
<DD><A HREF="probsoln-manual.html#673">2</A>
 | <A HREF="probsoln-manual.html#688">3</A>
<DT><STRONG><TT>draft</TT></STRONG>
<DD><A HREF="probsoln-manual.html#679">2</A>
<DT><STRONG><TT>final</TT></STRONG>
<DD><A HREF="probsoln-manual.html#682">2</A>
<DT><STRONG><TT>noanswers</TT></STRONG>
<DD><A HREF="probsoln-manual.html#676">2</A>
 | <A HREF="probsoln-manual.html#691">3</A>
</DL>
<DT><STRONG><TT>&#092;PSNgetrandseed</TT></STRONG>
<DD><A HREF="probsoln-manual.html#880">9</A>
<DT><STRONG><TT>&#092;PSNrandom</TT></STRONG>
<DD><A HREF="probsoln-manual.html#883">9</A>
<DT><STRONG><TT>&#092;PSNrandseed</TT></STRONG>
<DD><A HREF="probsoln-manual.html#877">9</A>
<DT><STRONG><TT>&#092;random</TT></STRONG>
<DD><A HREF="probsoln-manual.html#886">9</A>
<DT><STRONG><TT>&#092;selectallproblems</TT></STRONG>
<DD><A HREF="probsoln-manual.html#908">10</A>
<DT><STRONG><TT>&#092;selectrandomly</TT></STRONG>
<DD><A HREF="probsoln-manual.html#902">10</A>
 | <A HREF="probsoln-manual.html#905">10</A>
<DT><STRONG><TT>&#092;showanswers</TT></STRONG>
<DD><A HREF="probsoln-manual.html#775">5</A>
 | <A HREF="probsoln-manual.html#862">8</A>
<DT><STRONG><TT>showanswers</TT> boolean variable</STRONG>
<DD><A HREF="probsoln-manual.html#694">3</A>
 | <A HREF="probsoln-manual.html#705">3</A>
 | <A HREF="probsoln-manual.html#708">3</A>
 | <A HREF="probsoln-manual.html#772">5</A>
<DT><STRONG>\textttsolution environment</STRONG>
<DD><A HREF="probsoln-manual.html#1556">4</A>
<DT><STRONG><TT>textenum</TT> environment</STRONG>
<DD><A HREF="probsoln-manual.html#1560">4</A>
 | <A HREF="probsoln-manual.html#743">4</A>
<DT><STRONG><TT>&#092;theenumi</TT></STRONG>
<DD><A HREF="probsoln-manual.html#868">8</A>
<DT><STRONG><TT>&#092;useproblem</TT></STRONG>
<DD><A HREF="probsoln-manual.html#811">6</A>
 | <A HREF="probsoln-manual.html#841">8</A>
 | <A HREF="probsoln-manual.html#847">8</A>

</DL>
<P>
<A HREF="probsoln-manual.html#top">Top</A>
<BR><HR><H4>Footnotes</H4>
<DL>
<DT><A NAME="foot462">... document,</A><A
 HREF="probsoln-manual.html#tex2html3"><SUP>1</SUP></A></DT>
<DD>assuming you
leave at least a minute between runs.

</DD>
</DL>
<BR><HR>

</BODY>
</HTML>