Current as of May 2005
Question
Weirdly, WebCT 4 CE requires you to use different mechanisms to put
MathML in questions and in answers. For the question, you must use the
Equation Editor. According to WebCT technical support, there is no way
to prepare a text file with MathML in the question and then upload it or paste
it in; it simply won't work. You are stuck with the point-and-click tool.
Answers
But the Equation Editor isn't even provided for answers. Instead you must
call
an applet directly to display MathML. Here's the form of the applet, with
some MathML inserted:
<APPLET NAME="eqn_1" CODEBASE="/web-ct/code/WebEQ" CODE="webeq.Main" HEIGHT=40 WIDTH=65 align=middle>
<PARAM NAME=color VALUE="#FFFFFF">
<PARAM NAME=size VALUE="18">
<PARAM NAME=controls VALUE="false">
<PARAM NAME=eq VALUE="
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mfrac><mrow><mn>3</mn>
</mrow><mrow><mn>5</mn>
</mrow></mfrac>
</math>
">
<PARAM NAME=parser VALUE="mathml">
</APPLET>
To use this, replace the MathML (everything in
<math…> … </math>)
with your own. (It may also be necessary to change the HEIGHT and
WIDTH parameters to get it to display correctly.) This code can be placed in a
text file to be uploaded in the usual way, or you can simply paste it in as an
answer while editing a question in WebCT 4 CE.
Making
MathML from LaTeX
If you know LaTeX, the easiest way to write MathML is to write Itex
and use the
itex2mml program to transform it to MathML. Itex is a (rather large)
subset of LaTeX; for many purposes—certainly the simple purposes of
most
answers in WebCT—you can think of them as the same. To convert Itex to MathML
in Windows you need two files,
itex2mml.exe
and cygwin1.dll,
which are included in the
itex2mml download (but see the link at the bottom of this page).
Put them in a directory somewhere, open a DOS window
(Start|Programs|Accessories|Command Prompt),
and navigate to that directory. Assuming that your (well-formed) Itex code is in
the file answers.txt,
you can transform it to MathML by typing
itex2mml <answers.txt >answers.xml
at the DOS command line. The
answers.xml
file will then hold MathML equivalent to the Itex in
answers.txt.
Note that it will not display properly in your browser—for which you would need to enclose
the MathML in some HTML and (very likely) set up your browser to render MathML—but that
does not matter for our purpose here.
There's a bit more information about writing decent Itex at the
Itex
page mentioned above.
At the bottom of this file there's a link to a .zip file containing all that you need.
Many thanks to those who crafted these wonderful free tools!
Semi-automation
You can automate some of the process of producing MathML for answers
from Itex. (Note: if you don't know what some of this section means,
either get help or just don't do it.) First, put the following text into a
file named callItex2mml.bat
in the same directory as
itex2mml.exe:
itex2mml <answers.txt >answers.TEMP
Next, place the following Perl 5 script in a file named
TeX2WebCT.pl
in the same directory as
itex2mml.exe.
#/usr/bin/perl -w
#
# File: TeX2WebCT.pl
# Author: Stephen Corwin
# Date: May 2005
#
# Must be placed in a directory with the files
#
# itex2mml.exe
# cygwin1.dll
# callItex2mml.bat.
#
# Calls a batch file, callItex2mml.bat, to run itex2mml on the file answers.txt. The output of the
# .bat file is the intermediate file $xfname; this script reads in $xfname, formats the results by
# placing them in applet tags usable in WebCT 4 CE answers, and writes the result on WebCTanswers.txt.
# The contents of that file can then simply be pasted in as WebCT 4 CE answers. Deletes the
# intermediate file $xfname.
#
use strict;
my $xfname = 'answers.TEMP'; # name for intermediate file; must match output of callItex2mml.bat
my ($i,$j);
my (@lines);
# call itex2mml to produce MathML from the Itex in answers.txt
# - All that callItex2mml.bat does is this: itex2mml <answers.txt >answers.xml.
# - It's done this way because of problems with Perl's system() on Win32.
$i = `callItex2mml.bat`;
if (!$i) {die("Error in callItex2mml.bat");}
if (! -e $xfname) {die("Error making intermediate file $xfname");}
# slurp the intermediate file into @lines
open(F,"<$xfname") or die("Unable to open $xfname");
@lines = <F>;
close(F);
# clean up the list
$i = @lines-1;
while ($i > -1) {
chomp($lines[$i]);
if (!$lines[$i] || $lines[$i] =~ /^\s+$/) {splice(@lines,$i,1);}
$i--;
}
# open the output file
open(F,">WebCTanswers.txt") or die("Unable to open WebCTanswers.txt");
# write out the MathML, enclosed in <APPLET>...</APPLET>
$i = 0;
$j = 0;
while ($i < @lines) {
$j++;
print F "\n<APPLET NAME=\"eqn_$j\" CODEBASE=\"/web-ct/code/WebEQ\" ";
print F "CODE=\"webeq.Main\" HEIGHT=40 WIDTH=65 align=middle>\n";
print F " <PARAM NAME=color VALUE=\"#FFFFFF\">n";
print F " <PARAM NAME=size VALUE=\"18\">\n";
print F " <PARAM NAME=controls VALUE=\"false\">\n";
print F " <PARAM NAME=eq VALUE=\"\n";
while ($lines[$i] !~ /<math/) {$i++;}
while ($lines[$i] !~ /<\/math/) {
print F " $lines[$i]\n";
$i++;
}
print F " $lines[$i]\n";
$i++;
print F " \">\n";
print F " <PARAM NAME=parser VALUE=\"mathml\">\n";
print F "</APPLET>\n";
}#end - while($i < @lines)
close(F);
# delete the intermediate file
unlink($xfname);
If you use the script as is, you must place the Itex for your answers on separate lines in the file
answers.txt
in the directory containing the script. The script will run itex2mml on that file, place the
necessary applet tags around the MathML produced, and write the results to the file
WebCTanswers.txt,
ready to be pasted into WebCT. This makes for a pretty quick process,
once the question part has been entered with the Equation Editor:
put the answers (in Itex) on separate lines in
answers.txt;
double-click
TeX2WebCT.pl to produce
WebCTanswers.txt;
double-click
WebCTanswers.txt to open it;
paste the text into WebCT.
If the WebCT people would just allow the same mechanism for displaying MathML
in questions as they do in answers, it would be possible to automate the process
of preparing WebCT questions and answers from Itex sources completely. Unfortunately, according to
the tech support person I contacted, there seem to be no plans to do that in the near future.
Get .zip file with all necessary pieces