summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/jeopardy/jeopardy.dtx
blob: a2101cce5d1c3b1129f3c5becb1e859a145347b7 (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
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
% \iffalse meta-comment
%
% Copyright (C) 2004 by Robert Marik <marik@mendelu.cz>
% -------------------------------------------------------
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.2 or later is part of all distributions of LaTeX 
% version 1999/12/01 or later.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{jeopardy.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{jeopardy}
%<*package>\ProvidesPackage{jeopardy}
[2010/04/07 v1.1a .dtx jeopardy file]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\EnableCrossrefs         
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{jeopardy.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v1.0}{2006/10/28}{Initial version}
% \changes{v1.01}{2006/10/30}{Minor changes to get compatibility with
%   the last exerquiz.sty} 
% \changes{v1.02}{2006/11/2}{Option picture
%   added. Changed macro "title" into "JeopardyTitle".}
% \changes{v1.02a}{2006/11/3}{Minor update: Option bgpicture
%   added.}
% \changes{v1.1}{2007/03/12}{Option twoplayers.}
% \changes{v1.1a}{2010/04/07}{Examples redesigned to work in TeXlive 2009.}
%
% \GetFileInfo{jeopardy.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment,\vbox,\hbox, \', \@@end,
%   \@@RespBoxMathActions, \@@RespBoxTxtActions, \@Panelhomepagename,
%   \@Panelfullscreenname, \@jeopardyFineTunefalse, \@Panelclosename,
%   \@Panelquitname, }
% 
%
% \title{The \textsf{jeopardy} package\thanks{This document
%     corresponds to \textsf{jeopardy}~\fileversion, dated
%     \filedate.}}  \author{Robert Ma\v r\'\i k \\
%   \texttt{marik@mendelu.cz}\thanks{Supported by the grant 18/2006 of
%     the Fund for Developement of Czech Universities.}}
%
% \maketitle
%
% \section{Introduction}
%
% Jeopardy like game -- redesigned the \verb|jj_game.cls| by D. P.
% Story.  The package requires to load \verb|exerquiz| and
% \verb|dljslib| packages from AcroTeX bundle. The current only
% supported way to produce pdf file is \verb|pdftex|. The main
% properties include
% \begin{itemize}
% \item In contrast to \verb|jj_game.cls|, the \verb|oQuestion|
%   environment is used to allow fill-in questions.
% \item The \verb|proofing| option is introduced. Use this option to
%   typeset your answers into the document. To check the answers for
%   \verb|\RespBoxMath| and |\RespBoxTxt| commands remember to use
%   transparent background for these text fields or use the browser
%   which does not show these fields, like \verb|xpdf|.
% \item Option |twoplayers| builds game for two players.
% \item Option |bgpicture| is used to place the picture below the
%   buttons (|graphicx| package is used). The name of the picture is
%   stored in the |\JeopardyPictureFile| command. Default value is
%   |picture.jpg|.  You can change it by using command like
%   |\def\JeopardyPictureFile{blabla.jpg}|. If you use this option,
%   you may also consider the (rather tricky) option |finetune|. This
%   option is described with the corresponding code at the end of this
%   file. The |bgpicture| option is automaticaly turned on when
%   |picture| option is active.
% \item The option |picture| is introduced for another version of the
%   game. The user gets no score but uncovers parts of a picture
%   hidden by buttons and (after wrong answer) non-transparent fields.
%   It can be used in the class and students can guess what is on the
%   picture. The option adds the "Solution" button below the
%   gameboard.  If the user clicks this button, all buttons from not
%   yet answered questions and fields from wrong answered questions
%   are hidden and the picture is fully visible. After the second
%   click on this button, a |\ChampionMsg| is shown. This can be used
%   for example to store the name of a person on the picture. 
% \item The user is not allowed to browse pages of the game without
%   clicking in gameboard. We use the (not portable)
%   \verb|\pdfpageattr| command to achieve this behavior. This can be
%   turned off by \verb|allowpeeking| option.
% \item The \verb|evalonblur| option may be used. This concerns
%   filling forms for |\RespBoxTxt| and |\RespBoxMath| questions and
%   the following problem with switching keyboard layout: When filling
%   the text field, if user switches the keyboard
%   layout\footnote{necessary, for example, to write powers on Czech
%     keyboard} using keyboard shortcut on Linux, the (not yet
%   finished and hence incorrect) answer is evaluated and marked as
%   wrong. Known workarounds:
%   \begin{itemize}
%   \item The user should erase the contents of the field completely,
%     switch the keyboard, click into the field and type his/her
%     answer.
%   \item The user should change keyboard using mouse and Gnome applet.
%   \item The author can compile the file with \verb|evalonblur|
%     option. The answer is evaluated after \verb|shift+click|-ing
%     outside the field.
%   \end{itemize}
% \end{itemize}
% This package has been tested on Texlive2005+Linux (pdfeTeXk, Version
% 3.141592-1.30.4-2.2 (Web2C 7.5.5)), with \verb|exerquiz| 2006/18/06
% v6.05e.
%
% \section{Usage}
%
% To instal the style run |latex jeopardy.ins| from the directory with
% |jeopardy.dtx|. You get files |jeopardy.sty| and |jeopardy.cfg|.
% Copy both files where \LaTeX{} finds them and include your
% customizations into |jeopardy.cfg|.
%
% For sample file look at the files \verb|game*.tex|. The number of
% questions and categories is written into \verb|aux| file and stored
% in macros \verb|\NumberOfQuestions| and \verb|\NumberOfCategories|.
% From this reason, the file has to be two times \verb|pdflatex|-ed to
% build the game.  The |aux| file contains also definitions for the
% category names. These names are not used when |picture| option is
% active. 
%
% \DescribeMacro{\MakeGameBoard} Macro |\MakeGameBoard| typesets the
% game board. This should be at the begin of the file and followed by
% \verb|category| environments. The dimensions of cells are
% \verb|\CellWidth| and \verb|\CellHeight|. The user can set these
% dimensions after \verb|\begin{document}| or with the |\SetGameWidth|
%   and |\SetGameHeight| commands. Write e.g. |\SetGameHeight{10cm}|.
%   The fields are created via \verb|\pushButton| and
%   \verb|\textField| commands and the user may change the default
%   behavior using command available in the package \verb|eforms.sty|.
%   The colors for wrong and right messages are set in \verb|exerquiz|
%   package and stored in \verb|\correctColor| and \verb|\wrongColor|
%   macros. The tokens registers |\GrandPoohbahtoks|, |\Celltoks| and
%   |\Scoretoks| are used to build the GrandPoohbah field (see below),
%   cell fields and score field. You can set it by e.g.
%   |\GrandPoohbahtoks{\Q{0}\textColor{1 0 0 rg}}|. All these
%   registers are empty by default. The exception is if the |picture|
%   option is used, the |\Celltoks| is set to |\BG{0 0 0}|. If you
%   change it, remember to use non-transparent background for cells!
%
%   \DescribeMacro{\AfterGameBoard} Macro |\AfterGameBoard| is
%   execuetd between gameboard and score field.
%
%   \DescribeMacro{\everyCategoryHead} Tokens register
%   |\everyCategoryHead| is used at the begin of every category head.
%   You can set it by something like
%   |\everyCategoryHead{\textrm\footnotesize}|
%
%   \DescribeMacro{\JeopardyTitle} The |\JeopardyTitle| macro contains
%   the title of the game. The title is the hyperlink anchor used to
%   return from questions to the gameboard. You can set it by e.g.
%   |\def\JeopardyTitle{The title of the game}|.
%
%   \DescribeEnv{category} The |category| environment has one
%   parameter -- the name of the category. It encloses \verb|question|
%   environments. The category name is not used if the |picture|
%   option is active. In this case the name is replaced by the capital
%   letter A, B, C, \dots. In this case you (or your students) can
%   refer to the fields like on chessboard.
%
% \DescribeEnv{question} The |question| environment contains a
% question and answers for multiple choice questions. The answers are
% introduced by \verb|\Ans0| (wrong answers) or \verb|\Ans1| (correct
% answers). The environment includes an \verb|oQuestion| environment
% and hence it may contain \verb|\RespBoxMath| or |\RespBoxTxt|
% command.
%
% \DescribeMacro{\Goal} If the user finishes the game with at least
% \verb|\Goal| points, a hidden banner (GrandPoohbah field) with
% message stored in \verb|\ChampionMsg| command is shown. The default
% initial value
% \verb|45*(1+numQuestions)*numQuestions*numCategories*\JeopardyScaleFactor| 
% means 90 percent of the maximal point score.  The banner has height
% \verb|\GrandPoohbahHeight|. This macro is not used if the option
% |picture| is active. In this case the |\ChampionMsg| should contain
% the name of the picture (for example the name of the person on
% photograph) and it can be shown by doubleclicking "Solution"
% button at the bottom.
%
% \DescribeMacro{\SetGameWidth} Macro |\SetGameWidth| sets the
% |\GameWidth| register with the width of the game desk. It evaluates
% the width of cells as quotient of the parameter of the macro and the
% number of categories. Macro |\SetGameHeight| works in a similar way
% if the option |picture| is not active. If the option |picture| is
% active, the height of the game is evaluated from the dimensions of
% the picture. The width of the picture is scaled into |\GameWidth| and
% the height is established from the height of the scaled picture.
%
% \StopEventually{}
%
% \section{Implementation}
%
% Check that we use |pdflatex| and both \verb|exerquiz| and
% \verb|dljslib| packages are loaded.
%    \begin{macrocode}
%<*package>

\ifx\shortquiz\undefined 
\PackageWarning{Jeopardy}{!!!!!!!!!!!!! Load exerquiz package !!!!!!!!!!!}
\def\finito{\@@end}
\expandafter\finito\fi

\ifx\dljsRegister\undefined 
\PackageWarning{Jeopardy}{!!!!!!!!!!!!! Load dljslib package !!!!!!!!!!!}
\def\finito{\@@end}
\expandafter\finito\fi

\if\eq@drivernum1%%% pdftex
  \typeout{*** using pdftex option ***}
  \def\JeopardyNoPeekCommand{
    \edef\ThisPage{/AA<</O<</S/JavaScript/JS(kontrola(
      \the\QuestCount,\the\CatCount);)>> >>}
    \global\pdfpageattr=\expandafter{\ThisPage}%
  }
\else
  \def\JeopardyNoPeekCommand{}
  \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  \typeout{!!!!!!!! The package has been tested with pdflatex only.}
  \typeout{!!!!!!!! Use pdflatex drivers in eforms.sty and exerquiz.sty.}
  \typeout{!!!!!!!! On your own risk you can use other drivers 
    with *allowpeeking* option.}
  \PackageWarning{Jeopardy}{No pdftex drivers for eforms and exerquiz}
\fi

\RequirePackage{multido}

\DeclareOption{czech}{
\def\formessage{za}
\def\Scoremessage{Body}
\def\fairmsg{Nesidit! Odpovidate na jinou otazku!}
\def\who@answers@msg#1{Odpovida hrac #1}
\def\RightWrongMessages{
aCM = new Array\
(   "Spravne! Jen tak dal!",
    "Vyborne! Gratuluji!",
    "Dobre! Pokracujte ve spravne nacate praci!",
    "Ano, ano, ano, ano!",
    "Spravne! Zkuste i tezsi otazky",
    "Spravna odpoved!",
    "Presne tak! Ziskavate dalsi body"
);
aEM = new Array\
(   "To neni spravne! Zkuste jinou otazku.",
    "Chyba. Nehadejte!",
    "Prosim!  Prosim!  Premyslejte nez odpovite!",
    "Dalsi chyba! Hadanim se daleko nedostanete!",
    "Ale ne! Kdepak! Body dolu.",
    "Ne, zkuste jinou otazku.",
    "Zase spatne! Bohuzel, vase konto se opet snizuje!"
);}
\def\NotAllowedMesssage{"Nesmite menit odpovedi!"}
\def\RightMessage{Spravne}
\def\WrongMessage{Spatne}
\def\JeopardyTitle{Tituln\'\i{} strana}
\def\ChampionMsg{Bravo! Mistr nad mistry!}
}

\def\formessage{for}
\def\Scoremessage{Score}
\def\NotAllowedMesssage{"Changing your answer is not allowed!"}
\def\RightMessage{Right}
\def\WrongMessage{Wrong}
\def\fairmsg{Play Fair! Answer the question you have clicked!}
\def\who@answers@msg#1{Player #1}
\def\RightWrongMessages{
aCM = new Array
(   "That's Right!  Way to go, Kiddo!",
    "Wonderfully Done! Congrats!",
    "Very Good! Keep up the good work!",
    "Good, good, good, good!",
    "Gee, you're smart! Try a harder one!",
    "You're pretty sharp! Continuez, s'il vous pla\string\356t!",
    "You're the tops! But wait...try another."
);
aEM = new Array
(   "That's wrong! Sorry. Try Again.",
    "Error again.  Don't guess, I'm watching!",
    "Please!  Please!  Work it out first!",
    "An error has insinuated itself into your calculations. Recalibrate your thinking!",
    "Bah! Humbug!  You're haunted by Errors!",
    "Try again.  This time with order and method.",
    "Wrong again!  Use your little gray cells!"
);
}
\def\JeopardyTitle{Jeopardy Game}
\def\ChampionMsg{You are a Champion!}

\newif\ifJeopardyNoPeeking
\JeopardyNoPeekingtrue
\DeclareOption{allowpeeking}{\JeopardyNoPeekingfalse}

\newif\ifEvalOnBlur
\EvalOnBlurfalse
\DeclareOption{evalonblur}{\EvalOnBlurtrue}

\newif\ifdouble \doublefalse
\def\JeopardyScaleFactor{1}
\DeclareOption{double}{\doubletrue\def\JeopardyScaleFactor{2}}

\newif\ifoneplayer \oneplayertrue
\DeclareOption{twoplayers}{\oneplayerfalse}

\newif\if@jeopardyFineTune  \@jeopardyFineTunefalse
\DeclareOption{finetune}{\@jeopardyFineTunetrue}

\DeclareOption{proofing}{\eq@proofingtrue \JeopardyNoPeekingfalse}
\definecolor{webgreen}{rgb}{0,.5,0}

\newif\if@jeopardyBgPicture
\@jeopardyBgPicturefalse
\DeclareOption{bgpicture}{\@jeopardyBgPicturetrue \everyPushButton{\BC{}}}

\newif\if@jeopardyPicture
\@jeopardyPicturefalse
\def\Picture{0}
\DeclareOption{picture}{\def\Picture{1}\def\formessage#1.{}%
  \@jeopardyPicturetrue
  \@jeopardyBgPicturetrue
  \Celltoks{\BG{0 0 0}}
  \everyPushButton{\BC{}}
}


\newtoks\GrandPoohbahtoks
\newtoks\Scoretoks
\newtoks\Celltoks
\newtoks\Radiotoks
\newtoks\Playertoks


\ProcessOptions
%    \end{macrocode}
% We load |graphicx| package for inserting bitmaps.
%    \begin{macrocode}
\if@jeopardyBgPicture
\RequirePackage{graphicx} 
\fi

\sqTurnOffAlerts

\newcount \CatCount
\newcount \QuestCount
\newcount \NumberOfCategories
\newcount \NumberOfQuestions
\newcount \QuestCountA   \QuestCountA=-1
\newcount \AnswerCount
\newcount \OQuestionCount
\newcount \temporarycount
\newcounter{tempcounter}
\everyRespBoxMath{\BG{1 1 1}}
\everyRespBoxTxt{\BG{1 1 1}}

\newlength \GrandPoohbahHeight
\GrandPoohbahHeight = 10pt

%    \end{macrocode}
% Macros for setting game width and height.
%    \begin{macrocode}
\newlength\GameWidth
\newlength\GameHeight
\newlength\CellWidth 
\newlength\CellHeight
\newlength\ScoreCellHeight
\def\SetGameWidth#1{\GameWidth=#1\relax
  \CellWidth=\GameWidth
  \ifnum\NumberOfCategories=0 
  \divide\CellWidth by 10
  \else
  \divide\CellWidth by \NumberOfCategories
  \fi
}
\def\SetGameHeight#1{\GameHeight=#1\relax
  \CellHeight=\GameHeight
  \ifnum\NumberOfCategories=0 
  \divide\CellHeight by 10
  \else
  \divide\CellHeight by \NumberOfQuestions
  \fi
  \ScoreCellHeight=\CellHeight
}
%    \end{macrocode}
% We do some basic initializations for dimensions of gameboard.
%    \begin{macrocode}
\AtBeginDocument{
\SetGameWidth{0.8\linewidth}
\SetGameHeight{0.6\textheight}
}
%    \end{macrocode}
% Macros to typeset the picture. The default name of the picture is
% |picture.jpg|. You can redefine the command |\insertJeopardyPicture|
% to replace the picture e.g. by a text written in \TeX. To do this,
% replace the |\includegraphics| command by something else, e.g.
% |minipage| environment.
%    \begin{macrocode}
\newbox\JeopardyPictureBox
\def\JeopardyPictureFile{picture.jpg}
\def\insertJeopardyPicture{%
  \setbox\JeopardyPictureBox=%
  \hbox{\includegraphics[width=\GameWidth]{\JeopardyPictureFile}}%
  \SetGameHeight{1.02\ht\JeopardyPictureBox}%
  \dimen0=\CellHeight
  \dimen1=0.5\dimen0
  \hbox to 0 pt{\vbox to 0 pt{\kern -\dimen1\box\JeopardyPictureBox\vss}\hss}%
}

%    \end{macrocode}
% We define |category| and |question| environments. We read the names of the
% categories from the |aux| file and store these names in macros. These
% names are not used when |picture| option is active. In this case we
% convert the number of category into capital letter.
%    \begin{macrocode}
\if@jeopardyPicture
  \def\CategoryNameDef#1#2{%
    \setcounter{tempcounter}{#1}%
    \expandafter\xdef\csname CategoryName#1\endcsname{%
      \Alph{tempcounter}\strut}}%
\else
  \def\CategoryNameDef#1#2{%
    \expandafter\gdef\csname CategoryName#1\endcsname{#2}}%
\fi

%    \end{macrocode}
% The category environment simply increases the counter, writes the
% name into |aux| file and checks the number of questions in the last
% category environment.
%    \begin{macrocode}
\newenvironment{category}[1]{%
  \global\advance \CatCount by 1
  \global\QuestCount=0
  \immediate\write\@auxout{\string\CategoryNameDef{\the\CatCount}{#1}}%
  }
  {%
    \ifnum  \QuestCountA=-1 \global\QuestCountA=\QuestCount
    \else
      \ifnum\QuestCountA=\QuestCount
      \else
        \PackageWarning{Jeopardy}
        {Bad number of questions in Category \the\CatCount.}
      \fi
    \fi
  }
%    \end{macrocode}
% |question| environment increases the counter, places the action to
% check that the page is opened from the gameboard, writes the title
% of the question and defines macro |\Ans| which typesets buttons with
% correct and incorrect answers. It also starts the |oQuestion|
% environment and hence the commands |\RespBoxMath| and |\RespBoxTxt|
% from |exerquiz.sty| can be used. At the end of the environment we
% close the |oQuestion| environment and start new page.
%    \begin{macrocode}
\newenvironment{question}{%
  \global\advance \QuestCount by 1\relax
  \AnswerCount=0
  \ifJeopardyNoPeeking 
    \JeopardyNoPeekCommand
  \fi  
  \begin{center}%
    \hypertarget{\the\QuestCount\the\CatCount}%
    {\csname CategoryName\the\CatCount\endcsname{} %
      \formessage{} \the\QuestCount00.}%
  \end{center}%
\def\Ans##1{\par
\ifnum\AnswerCount=0 \vskip\medskipamount\fi
\advance\AnswerCount by 1% 
\setcounter{tempcounter}{\the\AnswerCount}%
\leavevmode\hbox to 0 pt{%
\hss
\ifeq@proofing \def\temp{##1}\if\temp1$\color{webgreen}\bullet$ \fi\fi
\pushButton[\CA{\alph{tempcounter}}%
  \A{\JS{useranswer(##1,\the\QuestCount,\the\CatCount);}}]%
  {{Answer\the\AnswerCount-\the\QuestCount-\the\CatCount}}%
  {1.3em}{1.3em}%
\hskip1em}%
\leftskip2em}%
\begin{oQuestion}{Q\the\QuestCount\the\CatCount}%
}{\par\end{oQuestion}\newpage}

%    \end{macrocode}
% At the end of document we write the number of questions and
% categories into |aux| file.
%    \begin{macrocode}
\AtEndDocument{
\immediate\write\@auxout{\string\global\string\NumberOfCategories=\the\CatCount}
\immediate\write\@auxout{\string\global\string\NumberOfQuestions=\the\QuestCount}
}
%    \end{macrocode}
% Here we redefine some internal macros of |exerquiz.sty|.
%    \begin{macrocode}
\ifEvalOnBlur
\def\@@RespBoxMathActions
{%
  \AA{
    \AAFormat{\eqFormatArg}%
    \AAOnFocus{\JS{var retn = null;}}%
    \AAOnBlur{\JS{retn = \processJSfunc(\rbArgs,\compareJSfunc);
        if (event.shift){
          if (retn==true) {useranswer(1,\the\QuestCount,\the\CatCount); }
          else {if (retn==false) {useranswer(0,\the\QuestCount,\the\CatCount);}
            else {app.alert("Probably a syntax error somewhere.");}}}
        else
        {app.alert("Exit the field with Shift+Click.");
          this.getField("obj.\oField.\thequestionno").setFocus();
        }}
    }
  }
}
\def\@@RespBoxTxtActions
{%
  \AA{\AAOnBlur{\JS{retn = ProcRespTxt(\rbTxtAlt);
        if (event.shift){
          if (retn==true) {useranswer(1,\the\QuestCount,\the\CatCount); }
          else {if (retn==false) {useranswer(0,\the\QuestCount,\the\CatCount);}
            else {app.alert("Probably a syntax error somewhere.");}}}
        else
        {app.alert("Exit the field with Shift+Click.");
          this.getField("obj.\oField.\thequestionno").setFocus();
        }}    }%
    \AAOnFocus{\JS{var retn = null;}}
  }
}
\def\jsRespBox[#1]#2{%
  \def\compareJSfunc{#1}\def\processJSfunc{#2}%
  \ifeq@proofing\makebox[0pt][l]{\space\math@correctAnswer}\fi
  \eq@TextField % send to the driver-dependent macro
  \ \pushButton{button}{10bp}{10bp}}%
\def\eq@@RespBoxTxt{%
  \ifeq@proofing\makebox[0pt][l]{\space\txt@correctAnswer}\fi
  \eq@TextField
  \ \pushButton{button}{10bp}{10bp}}%
\else
\def\@@RespBoxMathActions
{%
  \AA{\AAKeystroke{if(event.willCommit) {
        retn = \processJSfunc(\rbArgs,\compareJSfunc);
        if (retn==true) {useranswer(1,\the\QuestCount,\the\CatCount); }
        else {if (retn==false) {useranswer(0,\the\QuestCount,\the\CatCount);}
          else {app.alert("Probably a syntax error somewhere.");}}}
      }%
      \AAFormat{\eqFormatArg}%
      \AAOnFocus{\JS{var retn = null;}}%
  }%
}%
\def\@@RespBoxTxtActions
{%
  \AA{\AAKeystroke{if(event.willCommit) {
        retn = ProcRespTxt(\rbTxtAlt);
        if (retn==true) {useranswer(1,\the\QuestCount,\the\CatCount); }
        else {if (retn==false) {useranswer(0,\the\QuestCount,\the\CatCount);}
          else {app.alert("Probably a syntax error somewhere.");}}}
    }%
    \AAOnFocus{\JS{var retn = null;}}
  }
}
\fi %%% \ifEvalOnBlur
%    \end{macrocode}
% Macro for typesetting the page with title (hyperref anchor), hidden
% GrandPoohbah field and gameboard.
%    \begin{macrocode}
\newtoks\everyCategoryHead
\everyCategoryHead{}%
\def\MakeGameBoard{%
  \begin{center}%
    \hypertarget{GameBoard}{\JeopardyTitle}%
    
    \edef\temp{\noexpand\textField[\noexpand\Ff{\noexpand\FfReadOnly}%
      \noexpand\F{\noexpand\FHidden}%
      \noexpand\Q{1}%
      \noexpand\textSize{0}%
      \noexpand\V{\ChampionMsg}\the\GrandPoohbahtoks%
      ]{GrandPoohbah}{\textwidth}{\the\GrandPoohbahHeight}}%
    \temp
    
    \leavevmode
    \ifnum\NumberOfQuestions>0%
    \ifnum\NumberOfCategories>0%
    \multido{\i=1+1}{\NumberOfCategories}{\leavevmode
      \vtop{\hsize=\CellWidth \centering
        \the\everyCategoryHead\csname CategoryName\i\endcsname }}\\%
    \leavevmode
    \if@jeopardyBgPicture\insertJeopardyPicture\fi
    \Multido{\i=1+1}{\NumberOfQuestions}%
    {\edef\j{\i}%
      \if@jeopardyPicture\hbox to 0 pt{\hss$\j$ }\fi
      {\Multido{\i=1+1}{\NumberOfCategories}{%
          \edef\temp{\noexpand\textField[%
            \noexpand\Ff{\noexpand\FfReadOnly}%
            \noexpand\S{S}%
            \noexpand\Q{1}%
            \the\Celltoks]{Field\j\i}{\CellWidth}{\CellHeight}}%
          \hbox to 0 pt{\temp\hss}%
          \if@jeopardyPicture
          \pushButton[\S{B}%
          \A{\JS{kliknuti(\j,\i);}}]{Button\j\i}{\CellWidth}{\CellHeight}%
          \else
          \pushButton[\S{B}\CA{\j00}%
          \A{\JS{kliknuti(\j,\i);}}]{Button\j\i}{\CellWidth}{\CellHeight}%
          \fi
        }\\\leavevmode}%
    }%
    \fi
    \fi
    \par
    \AfterGameBoard
    \if@jeopardyPicture
    \smallskip\leavevmode
    \hfill\pushButton[\A{\JS{hideall();}}\CA{Solution}]{Solution}{1.5cm}{12bp}
    \else
    \@makeScoreField
    \fi
  \end{center}%
  \newpage
}%

\def\@makeScoreField
{
  \ifoneplayer
  \dimen0=\NumberOfCategories\CellWidth
  \edef\temp{\noexpand\textField[\noexpand\V{}\noexpand\textSize{0}
    \noexpand\Q{1}
    \noexpand\Ff{\noexpand\FfReadOnly}
    \the\Scoretoks
    ]{Total.1}{\dimen0}{\ScoreCellHeight}}%
  \temp
  \else%two players
  \dimen0=\NumberOfCategories\CellWidth
  \dimen1=0.5\dimen0
  \edef\temp{\noexpand\textField[\noexpand\V{}\noexpand\textSize{0}
    \noexpand\Q{1}
    \noexpand\Ff{\noexpand\FfReadOnly}
    \the\Scoretoks
    ]{Total.1}{\dimen1}{\ScoreCellHeight}}%
  \temp
  \edef\temp{\noexpand\textField[\noexpand\V{}\noexpand\textSize{0}
    \noexpand\Q{1}
    \noexpand\Ff{\noexpand\FfReadOnly}
    \the\Scoretoks
    ]{Total.2}{\dimen1}{\ScoreCellHeight}}%
  \temp\\
  \hbox to \hsize{\hss\hbox to \dimen0
    {\hss
      \radioButton[\V{1}\Ff{\FfNoToggleToOff}\A{\JS{player=1;this.getField("whoanswers").value= "\who@answers@msg{A}";}}]{radio}{12pt}{12pt}{1}
      \hss
      \hbox % to 0 pt
      {\hss
        \edef\temp{%
          \noexpand\textField[\noexpand\Q{1}\noexpand\Ff{\noexpand\FfReadOnly}\noexpand\V{\who@answers@msg{A}}\the\Playertoks]
          {whoanswers}{0.6\dimen0}{10pt}}\temp\hss
      }
      \hss
      \radioButton[\Ff{\FfNoToggleToOff}\A{\JS{player=2;this.getField("whoanswers").value= "\who@answers@msg{B}";}}]{radio}{12pt}{12pt}{2}
      \hss}\hss
  }%
  \fi
}

\let\AfterGameBoard\relax
\edef\Goal{45*(1+numQuestions)*numQuestions*numCategories*\JeopardyScaleFactor}
%    \end{macrocode}
% Basic Java functionality is rewritten from |jj_game.cls|. We start
% with initial declarations.
%    \begin{macrocode}

\def\update@who@answers{
if (player==1) this.getField("whoanswers").value= "\who@answers@msg{A}";
else this.getField("whoanswers").value= "\who@answers@msg{B}";
}

\edef\JeopardyUpdatescore
{
  \ifoneplayer
  this.getField("Total.1").value="\Scoremessage: "+TotalScoreA;
  if (TotalScoreA>0)
  this.getField("Total.1").textColor=\correctColor;
  else this.getField("Total.1").textColor=\wrongColor;
  \else
  this.getField("Total.1").value="\Scoremessage: "+TotalScoreA;
  if (TotalScoreA>0)
  this.getField("Total.1").textColor=\correctColor;
  else this.getField("Total.1").textColor=\wrongColor;
  this.getField("Total.2").value="\Scoremessage: "+TotalScoreB;
  if (TotalScoreB>0)
  this.getField("Total.2").textColor=\correctColor;
  else this.getField("Total.2").textColor=\wrongColor;
  if (player==1) {player=2; this.getField("radio").value=2;}
  else {player=1; this.getField("radio").value=1};
  \update@who@answers
  \fi
}



\begin{insDLJS}[dljslibRMb]{dljsliRMb}{RMb}
numQuestions = \the\NumberOfQuestions;
numCategories = \the\NumberOfCategories;
var player=1;
RowClick=0;
ColClick=0;
SaveRowClick=0;
SaveColClick=0;
totalQuestions = numQuestions * numCategories;
var QAed ="";
for (var i=0; i< totalQuestions; i++)QAed +="0";
nEM = 0;
nCM = 0;
var submitted = 0;
TotalScoreA = 0;
TotalScoreB = 0;
NumQAed = 0;
Goal = \Goal;
\RightWrongMessages
var Picture=\Picture;
var JeopardyPass=0;
%    \end{macrocode}
% These functions check that the page has been opened from the
% Gameboard and save the row and column number of the button which has
% been clicked. The OpenAction on the page is turned off after
% answering all questions.
%    \begin{macrocode}

function kontrola(row,col)
{
  if (NumQAed<totalQuestions)
  {
    var p = numQuestions*(col-1)+row-1;
    if (row!=RowClick) gotoNamedDest("GameBoard");
    if (col!=ColClick) gotoNamedDest("GameBoard");
    RowClick=0;
    ColClick=0;
  }
};

function kliknuti(row,col)
{RowClick=row;
ColClick=col;
SaveColClick=col;
SaveRowClick=row;
gotoNamedDest(row+""+col);
};

%    \end{macrocode}
% This function notifies the user. If the option |picture| is active,
% it also and hides the field on Gameboard in the case of correct
% answer.
%    \begin{macrocode}
function useranswer(ans,rowans,colans)
{
  if ((rowans!=SaveRowClick) || (colans!=SaveColClick))
  {
    app.alert("\fairmsg"); 
    gotoNamedDest("GameBoard");
    return null;
  }
  row= SaveRowClick;
  col= SaveColClick;
  this.getField("Button"+row+col).hidden=true;
  var p = numQuestions*(col-1)+row-1;
  if (QAed.charAt(p)==0)
  {
    QAed = QAed.substring(0,p)+1+QAed.substring(p+1,totalQuestions);
    if (ans==1)
    {
       if (Picture==1) 
       {
         this.getField("Field"+row+col).hidden=true;
       }
       else
       {
         this.getField("Field"+row+col).textColor=\correctColor;
         this.getField("Field"+row+col).value="\RightMessage";
       }
       if (player==1)
       TotalScoreA += \JeopardyScaleFactor*row*100;
       else
       TotalScoreB += \JeopardyScaleFactor*row*100;
       app.alert(aCM[nCM],3);
       if (++nCM > 6) nCM=0;
     }
    else
    {
      if (Picture!=1)
      {
        this.getField("Field"+row+col).textColor=\wrongColor;
        this.getField("Field"+row+col).value="\WrongMessage";
      }
      if (player==1)
      TotalScoreA -= \JeopardyScaleFactor*row*100;
      else
      TotalScoreB -= \JeopardyScaleFactor*row*100;
      app.alert(aEM[nEM],3);
      if (++nEM > 6) nEM=0;
    }
    if ((++NumQAed>=totalQuestions) && ((TotalScoreA+TotalScoreB)>=Goal))
    {
      if (Picture!=1) this.getField("GrandPoohbah").hidden=false;
    }
  }
  else
  app.alert(\NotAllowedMesssage);
  gotoNamedDest("GameBoard");
  if (Picture!=1)
  {
    \JeopardyUpdatescore
  }
};
%    \end{macrocode}
% This function hides in the first call all fields and buttons on the
% gameboard and after the second call shows the |\ChampionMsg|. In
% addition, it sets |NumQAed=totalQuestions| and the user is allowed to
% go through the pages of the document.
%    \begin{macrocode}
function hideall(){
  NumQAed=totalQuestions;
  var i=0;
  var j=1;
  if (JeopardyPass==0)
  {
    JeopardyPass=1;
    for (var i=0; i< numQuestions; i++)
    {
      for (var j=0; j< numCategories; j++) 
      {
        row=i+1; col=j+1;
        this.getField("Field"+row+col).hidden=true;
        this.getField("Button"+row+col).hidden=true;
      }
    }
  }
  else
  this.getField("GrandPoohbah").hidden=false;
}
%    \end{macrocode}
% We redefine function used in |exerquiz| package. We will turn off
% notification of the correct and incorrect answers by changing the
% strokecolor of the text fields.
%    \begin{macrocode}
function notifyField(success, flag, fieldname) {
  return success;
}
\end{insDLJS}
%    \end{macrocode}
% The fields in Acrobat have bigger dimension than their dimensions
% visible by \TeX. From this reason they overlap a bit. The user may
% try to remove this overlap, which is not nice together with picture,
% using option |finetune|.  This option tries to resolve this problem
% by using smaller buttons than the |\CellWidth| and |\CellHeight|.
% The user has to set manually the dimension |\AditionalShift| which
% is used to shift the image vertically to adjust correct position.
% (Sorry for the inconvenience.) I know that this solution is not
% clean enough but \dots I did my best. At least for this verion of
% |jeopardy| style. Look at the files |game1a.tex| and |game4.tex|.
% You can also try to remove the option |finetune| from these files
% and compaile again to note the difference.
%    \begin{macrocode}
\newlength\AditionalShift
\AditionalShift=0pt

\if@jeopardyFineTune
\newlength \finetunelength
\newlength \finetuneCellWidth
\newlength \finetuneCellHeight
\finetunelength=1pt

\def\insertJeopardyPicture{%
  \dimen1=\finetunelength
  \multiply\dimen1 by \NumberOfCategories
  \advance\dimen1 by \GameWidth
  \setbox\JeopardyPictureBox=%
  \hbox{\includegraphics[width=\dimen1]{\JeopardyPictureFile}}%
  \dimen1=\finetunelength
  \multiply\dimen1 by \NumberOfQuestions
  \dimen2=\ht\JeopardyPictureBox
  \advance\dimen2 by -1.9\dimen1
  \SetGameHeight{\dimen2}%
  \dimen0=\CellHeight
  \divide\dimen0 by 2
  \hbox to 0 pt{\vbox to 0 pt{\kern -\dimen0\kern-\AditionalShift
      \box\JeopardyPictureBox\vss}\hss}%
}



\def\MakeGameBoard{%
  \begin{center}%
    \fboxsep=\finetunelength
    \fboxrule=0pt
    \hypertarget{GameBoard}{\JeopardyTitle}%
    
    \edef\temp{\noexpand\textField[\noexpand\Ff{\noexpand\FfReadOnly}%
      \noexpand\F{\noexpand\FHidden}%
      \noexpand\Q{1}%
      \noexpand\textSize{0}%
      \noexpand\V{\ChampionMsg}\the\GrandPoohbahtoks%
      ]{GrandPoohbah}{\textwidth}{\the\GrandPoohbahHeight}}%
    \temp
    
    \leavevmode
    \ifnum\NumberOfQuestions>0%
    \ifnum\NumberOfCategories>0%
    \multido{\i=1+1}{\NumberOfCategories}{\leavevmode
      \vtop{\hsize=\CellWidth \centering
        \the\everyCategoryHead\csname CategoryName\i\endcsname }}\\%
    \leavevmode
    \if@jeopardyBgPicture\insertJeopardyPicture\fi
    \finetuneCellWidth=\CellWidth
    \advance\finetuneCellWidth by -\finetunelength
    \finetuneCellHeight=\CellHeight
    \vtop{%
      \Multido{\i=1+1}{\NumberOfQuestions}%
      {\edef\j{\i}%
        \hbox{%
          \if@jeopardyPicture\hbox to 0 pt{\hss$\j$ }\fi
          \Multido{\i=1+1}{\NumberOfCategories}{%
            \edef\temp{\noexpand\textField[%
              \noexpand\Ff{\noexpand\FfReadOnly}%
              \noexpand\S{S}%
              \noexpand\Q{1}%
              \the\Celltoks]{Field\j\i}{\finetuneCellWidth}{\finetuneCellHeight}}%
            \fbox{\hbox to 0 pt{\temp\hss}%
              \if@jeopardyPicture
              \pushButton[\S{B}%
              \A{\JS{kliknuti(\j,\i);}}]{Button\j\i}{\finetuneCellWidth}{\finetuneCellHeight}%
              \else
              \pushButton[\S{B}\CA{\j00}%
              \A{\JS{kliknuti(\j,\i);}}]{Button\j\i}{\finetuneCellWidth}{\finetuneCellHeight}%
              \fi%
            }}}\kern-1pt
      }}%
    \fi  %%%   \ifnum\NumberOfQuestions>0%
    \fi  %%%   \ifnum\NumberOfCategories>0%
    \par 
    \AfterGameBoard
    \if@jeopardyPicture
    \smallskip\leavevmode
    \hfill\pushButton[\A{\JS{hideall();}}\CA{Solution}]{Solution}{1.5cm}{12bp}
    \else%not picture
    \@makeScoreField
    \fi
  \end{center}%
  \newpage
}%
\fi

%    \end{macrocode}
% The user may write his/her customizations into jeopardy.cfg.
%    \begin{macrocode}
\IfFileExists{jeopardy.cfg}{%
  \typeout{---------------------------------------------------}
  \typeout{jeopardy: Configuration from the file jeopardy.cfg.}
  \typeout{---------------------------------------------------}
  \input jeopardy.cfg}{}
%</package>
%    \end{macrocode}
% We define shorter navigation panel if |pdfscreen.sty| package is used.
%    \begin{macrocode}
%<*cfg>
\ifx\NavigationPanel\undefined\else
\def\NavigationPanel{\normalsfcodes%
  \href{\@urlid}{\addButton{\buttonwidth}{\tiny\@Panelhomepagename}}\\ \pfill
  \hyperlink{GameBoard}{\addButton{\buttonwidth}{\tiny GameBoard}}\\ \pfill
  \Acrobatmenu{FullScreen}{\addButton{\buttonwidth}{\tiny\@Panelfullscreenname}}\\\pfill
  \Acrobatmenu{Close}{\addButton{\buttonwidth}{\tiny\@Panelclosename}}\\\pfill
  \Acrobatmenu{Quit}{\addButton{\buttonwidth}{\tiny\@Panelquitname}}\\
}
\fi
\def\PDFSCR@Warning#1{}
%</cfg>
%    \end{macrocode}
% \Finale
\endinput