[system] / trunk / pg / macros / PGbasicmacros.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/PGbasicmacros.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1328 Revision 1379
283 $answer_value= '' unless defined($answer_value); 283 $answer_value= '' unless defined($answer_value);
284 } 284 }
285 285
286 $answer_value =~ tr/\\$@`//d; ## make sure student answers can not be interpolated by e.g. EV3 286 $answer_value =~ tr/\\$@`//d; ## make sure student answers can not be interpolated by e.g. EV3
287 $name = RECORD_ANS_NAME($name); 287 $name = RECORD_ANS_NAME($name);
288
289 # incorporated Davide Cervone's changes
290 # removed newlines from around <INPUT> tags
291 # made TeX rule be based on specified width rather than varying size.
292
293 my $tcol = min(max($col/2,3),40);
294
288 MODES( 295 MODES(
289 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ", 296 TeX => "\\mbox{\\parbox[t]{${tcol}ex}{\\hrulefill}}",
290 Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!, 297 Latex2HTML => qq!\\begin{rawhtml}<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\\end{rawhtml}!,
291 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">\n" 298 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">"
292 ); 299 );
293} 300}
294 301
295sub NAMED_ANS_RULE_OPTION { # deprecated 302sub NAMED_ANS_RULE_OPTION { # deprecated
296 &NAMED_ANS_RULE_EXTENSION; 303 &NAMED_ANS_RULE_EXTENSION;
1120} 1127}
1121 1128
1122############################################################### 1129###############################################################
1123# Some constants which are different in tex and in HTML 1130# Some constants which are different in tex and in HTML
1124# The order of arguments is TeX, Latex2HTML, HTML 1131# The order of arguments is TeX, Latex2HTML, HTML
1132# Adopted Davide Cervone's improvements to PAR, BR, LTS, GTS, LTE, GTE, LBRACE, RBRACE, LB, RB. 7-14-03 AKP
1125sub PAR { MODES( TeX => '\\par ',Latex2HTML => '\\par ',HTML => '<P>' ); }; 1133sub PAR { MODES( TeX => '\\par ', Latex2HTML => '\\begin{rawhtml}<P>\\end{rawhtml}', HTML => '<P>'); };
1126sub BR { MODES( TeX => '\\par\\noindent ',Latex2HTML => '\\par\\noindent ',HTML => '<BR>'); }; 1134sub BR { MODES( TeX => '\\\\', Latex2HTML => '\\begin{rawhtml}<BR>\\end{rawhtml}', HTML => '<BR>'); };
1127sub LQ { MODES( TeX => "``", Latex2HTML => '"', HTML => '&quot;' ); }; 1135sub LQ { MODES( TeX => "``", Latex2HTML => '"', HTML => '&quot;' ); };
1128sub RQ { MODES( TeX => "''", Latex2HTML => '"', HTML => '&quot;' ); }; 1136sub RQ { MODES( TeX => "''", Latex2HTML => '"', HTML => '&quot;' ); };
1129sub BM { MODES(TeX => '\\(', Latex2HTML => '\\(', HTML => ''); }; # begin math mode 1137sub BM { MODES(TeX => '\\(', Latex2HTML => '\\(', HTML => ''); }; # begin math mode
1130sub EM { MODES(TeX => '\\)', Latex2HTML => '\\)', HTML => ''); }; # end math mode 1138sub EM { MODES(TeX => '\\)', Latex2HTML => '\\)', HTML => ''); }; # end math mode
1131sub BDM { MODES(TeX => '\\[', Latex2HTML => '\\[', HTML => '<P ALIGN=CENTER>'); }; #begin displayMath mode 1139sub BDM { MODES(TeX => '\\[', Latex2HTML => '\\[', HTML => '<P ALIGN=CENTER>'); }; #begin displayMath mode
1132sub EDM { MODES(TeX => '\\]', Latex2HTML => '\\]', HTML => '</P>'); }; #end displayMath mode 1140sub EDM { MODES(TeX => '\\]', Latex2HTML => '\\]', HTML => '</P>'); }; #end displayMath mode
1133sub LTS { MODES(TeX => ' < ', Latex2HTML => ' \\lt ', HTML => '&lt;'); }; 1141sub LTS { MODES(TeX => '<', Latex2HTML => '\\lt ', HTML => '&lt;', HTML_tth => '<' ); };
1134sub GTS {MODES(TeX => ' > ', Latex2HTML => ' \\gt ', HTML => '&gt;'); }; 1142sub GTS { MODES(TeX => '>', Latex2HTML => '\\gt ', HTML => '&gt;', HTML_tth => '>' ); };
1135sub LTE { MODES(TeX => ' \\le ', Latex2HTML => ' \\le ', HTML => '&lt;=' ); }; 1143sub LTE { MODES(TeX => '\\le ', Latex2HTML => '\\le ', HTML => '<U>&lt;</U>', HTML_tth => '\\le ' ); };
1136sub GTE { MODES(TeX => ' \\ge ', Latex2HTML => ' \\ge ', HTML => '&gt;'); }; 1144sub GTE { MODES(TeX => '\\ge ', Latex2HTML => '\\ge ', HTML => '<U>&gt;</U>', HTML_tth => '\\ge ' ); };
1137sub BEGIN_ONE_COLUMN { MODES(TeX => " \\end{multicols}\n", Latex2HTML => " ", HTML => " "); }; 1145sub BEGIN_ONE_COLUMN { MODES(TeX => " \\end{multicols}\n", Latex2HTML => " ", HTML => " "); };
1138sub END_ONE_COLUMN { MODES(TeX => 1146sub END_ONE_COLUMN { MODES(TeX =>
1139 " \\begin{multicols}{2}\n\\columnwidth=\\linewidth\n", 1147 " \\begin{multicols}{2}\n\\columnwidth=\\linewidth\n",
1140 Latex2HTML => ' ', HTML => ' '); 1148 Latex2HTML => ' ', HTML => ' ');
1141 1149
1152sub BITALIC { MODES(TeX => '{\\it ', Latex2HTML => '{\\it ', HTML => '<I>'); }; 1160sub BITALIC { MODES(TeX => '{\\it ', Latex2HTML => '{\\it ', HTML => '<I>'); };
1153sub EITALIC { MODES(TeX => '} ', Latex2HTML => '} ', HTML => '</I>'); }; 1161sub EITALIC { MODES(TeX => '} ', Latex2HTML => '} ', HTML => '</I>'); };
1154sub BCENTER { MODES(TeX => '\\begin{center} ', Latex2HTML => ' \\begin{rawhtml} <div align="center"> \\end{rawhtml} ', HTML => '<div align="center">'); }; 1162sub BCENTER { MODES(TeX => '\\begin{center} ', Latex2HTML => ' \\begin{rawhtml} <div align="center"> \\end{rawhtml} ', HTML => '<div align="center">'); };
1155sub ECENTER { MODES(TeX => '\\end{center} ', Latex2HTML => ' \\begin{rawhtml} </div> \\end{rawhtml} ', HTML => '</div>'); }; 1163sub ECENTER { MODES(TeX => '\\end{center} ', Latex2HTML => ' \\begin{rawhtml} </div> \\end{rawhtml} ', HTML => '</div>'); };
1156sub HR { MODES(TeX => '\\par\\hrulefill\\par ', Latex2HTML => '\\begin{rawhtml} <HR> \\end{rawhtml}', HTML => '<HR>'); }; 1164sub HR { MODES(TeX => '\\par\\hrulefill\\par ', Latex2HTML => '\\begin{rawhtml} <HR> \\end{rawhtml}', HTML => '<HR>'); };
1157sub LBRACE { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '\{' , HTML_tth=> '\\lbrace' ); }; 1165sub LBRACE { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '{' , HTML_tth=> '\\lbrace' ); };
1158sub RBRACE { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '\}' , HTML_tth=> '\\rbrace',); }; 1166sub RBRACE { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '}' , HTML_tth=> '\\rbrace',); };
1159sub LB { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '\{' , HTML_tth=> '\\lbrace' ); }; 1167sub LB { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '{' , HTML_tth=> '\\lbrace' ); };
1160sub RB { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '\}' , HTML_tth=> '\\rbrace',); }; 1168sub RB { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '}' , HTML_tth=> '\\rbrace',); };
1161sub DOLLAR { MODES( TeX => '\\$', Latex2HTML => '\\$', HTML => '$' ); }; 1169sub DOLLAR { MODES( TeX => '\\$', Latex2HTML => '\\$', HTML => '$' ); };
1162sub PERCENT { MODES( TeX => '\\%', Latex2HTML => '\\%', HTML => '%' ); }; 1170sub PERCENT { MODES( TeX => '\\%', Latex2HTML => '\\%', HTML => '%' ); };
1163sub CARET { MODES( TeX => '\\verb+^+', Latex2HTML => '\\verb+^+', HTML => '^' ); }; 1171sub CARET { MODES( TeX => '\\verb+^+', Latex2HTML => '\\verb+^+', HTML => '^' ); };
1164sub PI {4*atan2(1,1);}; 1172sub PI {4*atan2(1,1);};
1165sub E {exp(1);}; 1173sub E {exp(1);};
1294 my $start_delim = shift; 1302 my $start_delim = shift;
1295 my $end_delim = shift; 1303 my $end_delim = shift;
1296 my $actionRef = shift; 1304 my $actionRef = shift;
1297 my ($eval_out,$PG_eval_errors,$PG_full_error_report)=(); 1305 my ($eval_out,$PG_eval_errors,$PG_full_error_report)=();
1298 my $out = ""; 1306 my $out = "";
1307 #
1308 # DPVC -- 2001/12/07
1309 # original "while ($string)" fails to process the string "0" correctly
1310 #
1299 while ($string) { 1311 while ($string ne "") {
1312 #
1313 # end DPVC
1314 #
1300 if ($string =~ /\Q$start_delim\E/s) { 1315 if ($string =~ /\Q$start_delim\E/s) {
1301 #print "$start_delim $end_delim evaluating_substring=$string<BR>"; 1316 #print "$start_delim $end_delim evaluating_substring=$string<BR>";
1302 $string =~ s/^(.*?)\Q$start_delim\E//s; # get string up to next \{ ---treats string as a single line, ignoring returns 1317 $string =~ s/^(.*?)\Q$start_delim\E//s; # get string up to next \{ ---treats string as a single line, ignoring returns
1303 $out .= $1; 1318 $out .= $1;
1304 #print "$start_delim $end_delim substring_out=$out<BR>"; 1319 #print "$start_delim $end_delim substring_out=$out<BR>";
1400 my $mode = shift || "inline"; 1415 my $mode = shift || "inline";
1401 1416
1402 $in = FEQ($in); # Format EQuations 1417 $in = FEQ($in); # Format EQuations
1403 $in =~ s/%/\\%/g; # avoid % becoming TeX comments 1418 $in =~ s/%/\\%/g; # avoid % becoming TeX comments
1404 1419
1420 ## remove leading and trailing spaces so that HTML mode will
1421 ## not include unwanted spaces as per Davide Cervone.
1422 $in =~ s/^\s+//;
1423 $in =~ s/\s+$//;
1424
1405 # some modes want the delimiters, some don't 1425 # some modes want the delimiters, some don't
1406 my $in_delim = $mode eq "inline" 1426 my $in_delim = $mode eq "inline"
1407 ? "\\($in\\)" 1427 ? "\\($in\\)"
1408 : "\\[$in\\]"; 1428 : "\\[$in\\]";
1409 1429
1410 my $out; 1430 my $out;
1411 if($displayMode eq "HTML_tth") { 1431 if($displayMode eq "HTML_tth") {
1412 $out = tth($in_delim); 1432 $out = tth($in_delim);
1433 ## remove leading and trailing spaces as per Davide Cervone.
1434 $in =~ s/^\s+//;
1435 $in =~ s/\s+$//;
1413 } elsif ($displayMode eq "HTML_dpng") { 1436 } elsif ($displayMode eq "HTML_dpng") {
1414 # for jj's version of ImageGenerator 1437 # for jj's version of ImageGenerator
1415 $out = $envir->{'imagegen'}->add($in_delim); 1438 $out = $envir->{'imagegen'}->add($in_delim);
1416 # for my version of ImageGenerator 1439 # for my version of ImageGenerator
1417 #$out = $envir->{'imagegen'}->add($in, $mode); 1440 #$out = $envir->{'imagegen'}->add($in, $mode);
1658 } 1681 }
1659 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') { 1682 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') {
1660 $out .= "<TABLE BORDER=1>\n" 1683 $out .= "<TABLE BORDER=1>\n"
1661 } 1684 }
1662 else { 1685 else {
1663 $out = "Error: PGchoicemacros: begintable: Unknown displayMode: $displayMode.\n"; 1686 $out = "Error: PGbasicmacros: begintable: Unknown displayMode: $displayMode.\n";
1664 } 1687 }
1665 $out; 1688 $out;
1666 } 1689 }
1667 1690
1668sub endtable { 1691sub endtable {
1675 } 1698 }
1676 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' ||$displayMode eq 'HTML_img') { 1699 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' ||$displayMode eq 'HTML_img') {
1677 $out .= "</TABLE>\n"; 1700 $out .= "</TABLE>\n";
1678 } 1701 }
1679 else { 1702 else {
1680 $out = "Error: PGchoicemacros: endtable: Unknown displayMode: $displayMode.\n"; 1703 $out = "Error: PGbasicmacros: endtable: Unknown displayMode: $displayMode.\n";
1681 } 1704 }
1682 $out; 1705 $out;
1683 } 1706 }
1684 1707
1685 1708
1707 $out .= "<TD>" . shift(@elements) . "</TD>"; 1730 $out .= "<TD>" . shift(@elements) . "</TD>";
1708 } 1731 }
1709 $out .= "\n</TR>\n"; 1732 $out .= "\n</TR>\n";
1710 } 1733 }
1711 else { 1734 else {
1712 $out = "Error: PGchoicemacros: row: Unknown displayMode: $displayMode.\n"; 1735 $out = "Error: PGbasicmacros: row: Unknown displayMode: $displayMode.\n";
1713 } 1736 }
1714 $out; 1737 $out;
1715} 1738}
1716 1739
1717=head2 Macros for displaying static images 1740=head2 Macros for displaying static images
1792 \\end{rawhtml}\n ! 1815 \\end{rawhtml}\n !
1793 } elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') { 1816 } elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') {
1794 $out = qq!<A HREF= "$imageURL" TARGET="ZOOM"><IMG SRC="$imageURL" WIDTH="$width" HEIGHT="$height"></A> 1817 $out = qq!<A HREF= "$imageURL" TARGET="ZOOM"><IMG SRC="$imageURL" WIDTH="$width" HEIGHT="$height"></A>
1795 ! 1818 !
1796 } else { 1819 } else {
1797 $out = "Error: PGchoicemacros: image: Unknown displayMode: $displayMode.\n"; 1820 $out = "Error: PGbasicmacros: image: Unknown displayMode: $displayMode.\n";
1798 } 1821 }
1799 push(@output_list, $out); 1822 push(@output_list, $out);
1800 } 1823 }
1801 return wantarray ? @output_list : $output_list[0]; 1824 return wantarray ? @output_list : $output_list[0];
1802} 1825}
1884 $out .= " <TH>". &caption( shift(@captions) ) ."</TH>"; 1907 $out .= " <TH>". &caption( shift(@captions) ) ."</TH>";
1885 } 1908 }
1886 $out .= "\n</TR></TABLE></P>\n" 1909 $out .= "\n</TR></TABLE></P>\n"
1887 } 1910 }
1888 else { 1911 else {
1889 $out = "Error: PGchoicemacros: imageRow: Unknown languageMode: $displayMode.\n"; 1912 $out = "Error: PGbasicmacros: imageRow: Unknown languageMode: $displayMode.\n";
1890 warn $out; 1913 warn $out;
1891 } 1914 }
1892 $out; 1915 $out;
1893} 1916}
1894 1917

Legend:
Removed from v.1328  
changed lines
  Added in v.1379

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9