[system] / branches / rel-2-4-patches / pg / macros / alignedChoice.pl Repository:
ViewVC logotype

Annotation of /branches/rel-2-4-patches/pg/macros/alignedChoice.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6432 - (view) (download) (as text)

1 : gage 6432 loadMacros(
2 :     'PGchoicemacros.pl',
3 :     'unionUtils.pl',
4 :     'choiceUtils.pl',
5 :     );
6 :    
7 :     sub _alignedChoice_init {}; # don't reload this file
8 :    
9 :     ######################################################################
10 :     #
11 :     # Prints questions with the answer rule at the right, all aligned.
12 :     # (for use by AlignedList object below)
13 :     #
14 :     sub aligned_print_q {
15 :     my $self = shift;
16 :     my (@questions) = @_;
17 :     my $length = $self->{ans_rule_len};
18 :     my ($numbered,$equals) = ($self->{numbered},$self->{equals});
19 :     my ($valign,$align) = ($self->{valign},$self->{align});
20 :     my ($sep,$tsep) = ($self->{spacing},$self->{tex_spacing});
21 :     my ($rsep) = ($self->{row_spacing});
22 :     my $i=1; my $quest; my $rest;
23 :    
24 :     my $out = "";
25 :     if ($main::displayMode =~ m/^HTML/) {
26 :     $out = "\n<P>\n<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=$sep>\n";
27 :     foreach $quest (@questions) {
28 :     if (ref($quest) eq 'ARRAY') {($quest,$rest) = @{$quest}} else {$rest = ''}
29 :     $out .= "<TR VALIGN=$valign>";
30 :     $out .= "<TD><B>" . $i++ . ".</B> &nbsp;</TD>" if ($numbered);
31 :     $out .= "<TD ALIGN=$align>$quest</TD>";
32 :     $out .= "<TD>=</TD>" if ($equals);
33 :     $out .= "<TD>" . ans_rule($length) . $rest . "</TD></TR>\n";
34 :     $out .= "<TR><TD HEIGHT=\"$rsep\"></TD></TR>\n" if ($rsep);
35 :     }
36 :     $out .= "</TABLE>\n";
37 :     } elsif ($main::displayMode eq 'Latex2HTML') {
38 :     $out = "\\par\n\\begin{rawhtml}".
39 :     "<TABLE BORDER=0 CELLSPACING=$sep CELLPADDING=0>\\end{rawhtml}\n";
40 :     foreach $quest (@questions) {
41 :     if (ref($quest) eq 'ARRAY') {($quest,$rest) = @{$quest}} else {$rest = ''}
42 :     $out .= "\\begin{rawhtml}<TR VALIGN=$valign>";
43 :     $out .= "<TD VALIGN=MIDDLE><B>".$i++.".</B>&nbsp;</TD>" if ($numbered);
44 :     $out .= "<TD ALIGN=$align>\\end{rawhtml}$quest\\begin{rawhtml}</TD>";
45 :     $out .= "<TD>=</TD>" if ($equals);
46 :     $out .= "<TD>\\end{rawhtml}".ans_rule($length).$rest.
47 :     "\\begin{rawhtml}</TD></TR>\\end{rawhtml}";
48 :     $out .= "\\begin{rawhtml}<TR><TD HEIGHT=\"$rsep\"></TD></TR>\\end{rawhtml}\n" if ($rsep);
49 :     }
50 :     $out .= "\\begin{rawhtml}</TABLE>\n\\end{rawhtml}";
51 :     } elsif ($main::displayMode eq 'TeX') {
52 :     my $num = ''; $num = 'r' if ($numbered);
53 :     my $algn = 'r'; $algn = 'l' if (uc($align) eq "LEFT");
54 :     $algn = 'c' if (uc($align) eq "CENTER");
55 :     $algn .= "c" if ($equals);
56 :     $out = "\n\\par\\begin{tabular}{${num}${algn}l}\n";
57 :     foreach $quest (@questions) {
58 :     if (ref($quest) eq 'ARRAY') {($quest,$rest) = @{$quest}} else {$rest = ''}
59 :     $out .= $i++ . ".\\ &" if ($numbered);
60 :     $out .= $quest . "&";
61 :     $out .= "=&" if ($equals);
62 :     $out .= "\\ ". ans_rule($length) . $rest . "\\\\ \\noalign{\\kern $tsep}\n";
63 :     }
64 :     $out .= "\\end{tabular}\n";
65 :     } else {
66 :     $out = "Error: std_aligned_print_q: Unknown displayMode: ".
67 :     $main::displayMode;
68 :     }
69 :     $out;
70 :     }
71 :    
72 :     ######################################################################
73 :     #
74 :     # Genarate a new AlignedList object
75 :     #
76 :     # $al = new_aligned_list(options)
77 :     #
78 :     # Where "options" can be taken from among:
79 :     #
80 :     # valign => "placement" Sets the vertical alignment for the table
81 :     # (default is valign => "MIDDLE")
82 :     #
83 :     # align => "placement" Sets the horizontal aligmnent for the first
84 :     # column of the table
85 :     # (default is align => "RIGHT")
86 :     #
87 :     # spacing => n Sets the CELLSPACING value for the table
88 :     # (default is spacing => 5)
89 :     #
90 :     # tex_spacing => dimen Extra spacing between rows
91 :     # (default is tex_spacing => "0pt")
92 :     #
93 :     # numbered => 1 or 0 1 means the problems should be numbered.
94 :     # 0 means no numbers for the problems.
95 :     #
96 :     # equals => 1 or 0 1 means include a column of equal signs between
97 :     # the questions and the answer blocks.
98 :     # 0 means no column of equals.
99 :     #
100 :     # ans_rule_len => n Sets the length of the answer rule
101 :     #
102 :     #
103 :     sub new_aligned_list {
104 :     new AlignedList(random(1,2000,1), \&aligned_print_q, \&std_print_a, @_);
105 :     }
106 :    
107 :     package AlignedList;
108 :    
109 :     @AlignedList::ISA = qw( List );
110 :    
111 :     sub new {
112 :     my $type = shift;
113 :     my ($rnd,$pq,$pa,@params) = @_;
114 :     my $self = List->new($rnd,$pq,$pa);
115 :     $self = bless $self, $type;
116 :     my ($var,$val);
117 :     @params = (
118 :     valign => "MIDDLE",
119 :     align => "RIGHT",
120 :     numbered => 0,
121 :     equals => 1,
122 :     ans_rule_len => 10,
123 :     spacing => 5,
124 :     tex_spacing => "0pt",
125 :     @params
126 :     );
127 :     while (@params) {
128 :     $var = shift(@params); $val = shift(@params);
129 :     $self->{$var} = $val;
130 :     }
131 :     return $self;
132 :     }
133 :    
134 :     sub qa {
135 :     my $self = shift;
136 :     $self->SUPER::qa(@_);
137 :     my $n = scalar(@{$self->{questions}});
138 :     $self->{selected_q} = [@{$self->{questions}}];
139 :     $self->{selected_a} = [@{$self->{answers}}];
140 :     $self->{slice} = [0..$n];
141 :     $self->{shuffle} = [0..$n];
142 :     $self->{inverted_shuffle} = [0..$n];
143 :     }
144 :    
145 :     sub selectQA {
146 :     my $self = shift;
147 :     $self->{selected_q} = [@{$self->{questions}}[@{$self->{slice}}]];
148 :     $self->{selected_a} = [@{$self->{answers}}[@{$self->{slice}}]];
149 :     $self->{shuffle} = [0..scalar(@{$self->{slice}})];
150 :     $self->{inverted_shuffle} = [0..scalar(@{$self->{slice}})];
151 :     }
152 :    
153 :     sub correct_ans {
154 :     my $self = shift;
155 :     return @{$self->{selected_a}}
156 :     }
157 :    
158 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9