Parent Directory
|
Revision Log
PGbasicmacros: I've used "\lq\lq{}" instead of "``" in $LQ to prevent conflict with the ``....`` construct.
I also changed $RQ to "\rq\rq{}" for consistency.
In unionMacros.pl I removed the redefinition of $LQ and $RQ
in parserOrientation.pl I changed the definition of ^ to use \char94 instead of \char`\^
In prob6.pg I changed \char`\{ to \char123 and also \char`\} to \char125
In prob10.pg I changed \char`\< to \char60 (and > to \char62)
The pdf file works now for setOrientation.
1 #!/usr/local/bin/perl 2 3 ###################################################################### 4 # 5 # Macros used by the orientation problem set 6 # 7 ###################################################################### 8 9 10 #loadMacros("PGcourse.pl"); 11 12 # 13 # Special use of CARET to have it work in non-math mode 14 # 15 $CARET = MODES( 16 TeX => '\hbox{\texttt{\char94}}', 17 Latex2HTML => '^', 18 HTML => '^' 19 ); 20 21 # 22 # Functions to display student input and computer output 23 # (written as functions so that we change the style without 24 # recoding the problems themselves). 25 # 26 sub student { 27 my $message = shift; 28 MODES( 29 TeX => '\leavevmode\hbox{\texttt{'.$message.'}}', 30 Latex2HTML => 31 $bHTML.'<NOBR><TT>'.$eHTML.$message.$bHTML.'</TT></NOBR>'.$eHTML, 32 HTML => '<NOBR><TT>'.$message.'</TT></NOBR>' 33 ); 34 } 35 36 sub computer { 37 my $message = shift; 38 MODES( 39 TeX => '\hbox{\texttt{'.$message.'}}', 40 Latex2HTML => 41 $bHTML.'<NOBR><TT>'.$eHTML.$message.$bHTML.'</TT></NOBR>'.$eHTML, 42 HTML => '<NOBR><TT>'.$message.'</TT></NOBR>' 43 ); 44 } 45 46 # 47 # This prints things we need to fill in yet in red 48 # 49 sub moreWork { 50 my $message = shift; 51 MODES( 52 TeX => '{\sl ' . $message . '}', 53 Latex2HTML => $bHTML . '<FONT COLOR="#A00000">' . $eHTML . 54 $message . $bHTML . '</FONT>' . $eHTML, 55 HTML => '<FONT COLOR="#A00000">' . $message . '</FONT>' 56 ); 57 } 58 59 # 60 # Temporary macros to mark comments in areas that we are 61 # working on. 62 # 63 $BCOMMENT = MODES( 64 TeX => '{\footnotesize\it', 65 Latex2HTML => $bHTML.'<BLOCKQUOTE><SMALL><I><FONT COLOR="#A00000">'.$eHTML, 66 HTML => '<BLOCKQUOTE><SMALL><I><FONT COLOR="#A00000">' 67 ); 68 69 $ECOMMENT = MODES( 70 TeX => '}', 71 Latex2HTML => $bHTML.'</FONT></I></SMALL></BLOCKQUOTE>'.$eHTML, 72 HTML => '</FONT></I></SMALL></BLOCKQUOTE>' 73 ); 74 75 # $BCOMMENT = MODES( 76 # TeX => '\iffalse', 77 # Latex2HTML => $bHTML.'<!-- '.$eHTML, 78 # HTML => '<!-- ' 79 # ); 80 # 81 # $ECOMMENT = MODES( 82 # TeX => '\fi', 83 # Latex2HTML => $bHTML.' -->'.$eHTML, 84 # HTML => ' -->' 85 # ); 86 87 88 # 89 # Hack to get better spacing in HTML_tth math mode but without 90 # messing up the spacing in other modes. 91 # 92 $SP = MODES( 93 TeX => ' ', Latex2HTML => ' ', 94 HTML => ' ', HTML_tth => '\ ', 95 HTML_jsMath => ' ', HTML_dpng => ' ', 96 ); 97 98 99 # 100 # Special table macros for questions that have 101 # displayed math expressions equal to an answer rule, 102 # with an accompanying explanation on a separate line. 103 # 104 105 sub BeginExamples { 106 return "" if ($displayMode eq "TeX"); 107 BeginTable(@_); 108 } 109 110 sub EndExamples { 111 return "" if ($displayMode eq "TeX"); 112 EndTable(); 113 } 114 115 @ExampleDefaults = (ans_rule_len => 40, ans_rule_height => 1); 116 117 sub BeginExample { 118 my $math = shift; 119 my $ans = shift; 120 my %options = (@ExampleDefaults, @_); 121 my ($cols,$rows) = ($options{ans_rule_len},$options{ans_rule_height}); 122 my $rule; 123 124 if ($rows == 1) {$rule = ans_rule($cols)} 125 else {$rule = ans_box($rows,$cols)} 126 ANS($ans); 127 128 # 129 # HTML_tth puts an unwanted <BR> at the beginning, 130 # and uses a centered table. Remove the <BR> and 131 # align the table to the right. 132 # 133 if ($displayMode eq "HTML_tth") { 134 $math = trimString(EV2('\['.$math.'\]')); 135 $math =~ s!<br clear="all" />!!; 136 $math =~ s!table align="center"!table align="right"!; 137 } elsif ($displayMode eq "HTML") { 138 $math = '\('.$math.'\)' 139 } elsif ($displayMode =~ m/^HTML/) { 140 $math = '\(\displaystyle '.$math.'\)' 141 } 142 143 MODES( 144 TeX => "\n".'\['.$math.'=\hbox to 8em{'.$rule.'}\]', 145 Latex2HTML => $bHTML.'<TR><TD ALIGN="RIGHT">'.$eHTML. 146 '\(\displaystyle '.$math.'\)'.$bHTML.'</TD><TD> = </TD>'. 147 '<TD>'.$eHTML.$rule.$bHTML.'</TD></TR>'. 148 '<TR><TD></TD><TD></TD><TD>'.$eHTML, 149 HTML => 150 '<TR><TD ALIGN="RIGHT">'.$math.'</TD><TD> = </TD>'. 151 '<TD>'.$rule.'</TD></TR><TR><TD COLSPAN="2"></TD><TD>' 152 ); 153 } 154 155 sub EndExample { 156 MODES( 157 TeX => "\n", 158 Latex2HTML => $bHTML.'<BR><BR></TD></TR>'.$eHTML, 159 HTML => '<BR><BR></TD></TR>' 160 ); 161 } 162 163 sub ExampleRule { 164 MODES( 165 TeX => '\par', 166 Latex2HTML => $bHTML.'<TR><TD COLSPAN="3"><HR></TD></TR>'.$eHTML, 167 HTML => '<TR><TD COLSPAN="3"><HR></TD></TR>' 168 ); 169 } 170 171 # 172 # Produce a TeX version and an answer checker for the formula 173 # 174 sub DisplayQA {my $f = shift; return (DMATH($f->TeX),$f->cmp)} 175 sub QA {my $f = shift; return ($f->TeX,$f->cmp)} 176 177 ################################################## 178 # 179 # Insert an image of an equation (but use the equation 180 # in TeX mode). 181 # 182 183 sub MathIMG { 184 my ($img,$text,$tex) = @_; 185 my $useTeX = MODES(TeX => 1, Latex2HTML => 0, HTML => 0, HTML_tth => 0, HTML_dpng => 1); 186 return '\('.$tex.'\)' if $useTeX; 187 $img = alias($img); 188 return qq{<IMG SRC="$img" BORDER="0" ALIGN="MIDDLE" ALT="$text">}; 189 } 190 191 192 ################################################## 193 # 194 # A simple grader that always returns a score of 1. 195 # This is used in the tutorial to give students 196 # credit for reading a problem (even if it doesn't 197 # ask any questions). 198 # 199 sub forgiving_grader { 200 my $rh_evaluated_answers = shift; 201 my $rh_problem_state = shift; 202 my %form_options = @_; 203 my %evaluated_answers = %{$rh_evaluated_answers}; 204 my %problem_state = %{$rh_problem_state}; 205 206 my %problem_result = ( 207 score => 1, # always return 1 208 errors => '', 209 type => 'forgiving_grader', 210 msg => '', 211 ); 212 213 return(\%problem_result,\%problem_state) 214 if (!$form_options{answers_submitted}); 215 216 $problem_state{recorded_score} = $problem_result{score}; 217 $problem_state{num_of_correct_ans}++; 218 219 (\%problem_result, \%problem_state); 220 } 221 222 ################################################## 223 # 224 # Syntactic sugar to avoid ugly ~~& construct in PG. 225 # 226 sub install_forgiving_grader {install_problem_grader(\&forgiving_grader)} 227 228 229 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |