Skip to content

Commit

Permalink
Merge pull request #532 from drgrice1/update-mathjax
Browse files Browse the repository at this point in the history
Update WeBWorK to use MathJax version 3.
  • Loading branch information
Alex-Jordan authored Mar 3, 2021
2 parents 74a7cee + f313c9c commit d7540b1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
23 changes: 1 addition & 22 deletions macros/PG.pl
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,7 @@ sub DOCUMENT {
#use strict;
#FIXME
# load java script needed for displayModes
if ($envir{displayMode} eq 'HTML_MathJax') {
##
# The following is used to prevent MathJax from being loaded more than one on a page. (Happened in WW3 library browser)
#
# If there are any errors replace the line starting "window.MathJax" with the string in $loadScript.
#
TEXT(
qq?<script type="text/x-mathjax-config">
MathJax.Hub.Config({
MathMenu: {showContext: true}
});
</script>
<script type="text/javascript">
if(!window.MathJax)
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "$envir{MathJaxURL}";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>?."\n");
} elsif ($envir{displayMode} eq 'HTML_jsMath') {
if ($envir{displayMode} eq 'HTML_jsMath') {
my $prefix = "";
if (!$envir{jsMath}{reportMissingFonts}) {
$prefix .= '<script>noFontMessage = 1</script>'."\n";
Expand Down
11 changes: 5 additions & 6 deletions macros/PGbasicmacros.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1534,10 +1534,10 @@ sub ALPHABET {
sub BRBR { MODES( TeX => '\\leavevmode\\\\\\relax \\leavevmode\\\\\\relax ', Latex2HTML => '\\begin{rawhtml}<BR><BR>\\end{rawhtml}', HTML => '<P>', PTX => "\n"); };
sub LQ { MODES( TeX => "\\lq\\lq{}", Latex2HTML => '"', HTML => '&quot;', PTX => '<lq/>' ); };
sub RQ { MODES( TeX => "\\rq\\rq{}", Latex2HTML => '"', HTML => '&quot;', PTX => '<rq/>' ); };
sub BM { MODES(TeX => '\\(', Latex2HTML => '\\(', HTML => '', PTX => '<m>'); }; # begin math mode
sub EM { MODES(TeX => '\\)', Latex2HTML => '\\)', HTML => '', PTX => '</m>'); }; # end math mode
sub BDM { MODES(TeX => '\\[', Latex2HTML => '\\[', HTML => '<P ALIGN=CENTER>', PTX => '<me>'); }; #begin displayMath mode
sub EDM { MODES(TeX => '\\]', Latex2HTML => '\\]', HTML => '</P>', PTX => '</me>'); }; #end displayMath mode
sub BM { MODES(TeX => '\\(', Latex2HTML => '\\(', HTML_MathJax => '\\(', HTML => '', PTX => '<m>'); }; # begin math mode
sub EM { MODES(TeX => '\\)', Latex2HTML => '\\)', HTML_MathJax => '\\)', HTML => '', PTX => '</m>'); }; # end math mode
sub BDM { MODES(TeX => '\\[', Latex2HTML => '\\[', HTML_MathJax => '\\[', HTML => '<P ALIGN=CENTER>', PTX => '<me>'); }; #begin displayMath mode
sub EDM { MODES(TeX => '\\]', Latex2HTML => '\\]', HTML_MathJax => '\\]', HTML => '</P>', PTX => '</me>'); }; #end displayMath mode
sub LTS { MODES(TeX => '<', Latex2HTML => '\\lt ', HTML => '&lt;', HTML_tth => '<', PTX => '\lt' ); }; #only for use in math mode
sub GTS { MODES(TeX => '>', Latex2HTML => '\\gt ', HTML => '&gt;', HTML_tth => '>', PTX => '\gt' ); }; #only for use in math mode
sub LTE { MODES(TeX => '\\le ', Latex2HTML => '\\le ', HTML => '<U>&lt;</U>', HTML_tth => '\\le ', PTX => '\leq' ); }; #only for use in math mode
Expand Down Expand Up @@ -2110,8 +2110,7 @@ sub general_math_ev3 {

my $out;
if($displayMode eq "HTML_MathJax") {
$out = '<span class="MathJax_Preview">[math]</span><script type="math/tex">'.$in.'</script>' if $mode eq "inline";
$out = '<span class="MathJax_Preview">[math]</span><script type="math/tex; mode=display">'.$in.'</script>' if $mode eq "display";
$out = '<span>'.$in_delim.'</span>';
} elsif ($displayMode eq "HTML_dpng" ) {
# for jj's version of ImageGenerator
#$out = $envir->{'imagegen'}->add($in_delim);
Expand Down
14 changes: 3 additions & 11 deletions macros/parserGraphTool.pl
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,9 @@ sub cmp_preprocess {
my $graphObjs = @{$self->{staticObjects}} ?
join(",", @{$self->{staticObjects}}, $ans->{student_ans}) : $ans->{student_ans};

# This first ends the attempts table MathJax_Preview script. Note that the script
# started here is ended by the original script end tag for the MathJax_Preview.
$ans->{preview_latex_string} = <<"END_ANS";
</script>
<div id='${ans_name}_student_ans_graphbox' class='graphtool-answer-container'></div>
<script>
jQuery("#${ans_name}_student_ans_graphbox").parent().find('span').remove();
jQuery("#${ans_name}_student_ans_graphbox").parent().find('script[type^="math/tex"]').remove();
jQuery(function() {
graphTool("${ans_name}_student_ans_graphbox", {
staticObjects: "$graphObjs",
Expand All @@ -542,6 +537,7 @@ sub cmp_preprocess {
JSXGraphOptions: $self->{JSXGraphOptions}
});
});
</script>
END_ANS
}
}
Expand All @@ -552,22 +548,17 @@ sub cmp_preprocess {
# displayed in the "Correct Answer" box of the results table.
sub cmp {
my $self = shift;
my $cmp = $self->SUPER::cmp(%{$self->{cmpOptions}}, @_);
my $cmp = $self->SUPER::cmp(non_tex_preview => 1, %{$self->{cmpOptions}}, @_);

if ($main::displayMode ne 'TeX') {
my $ans_name = $self->ANS_NAME;
$self->constructJSXGraphOptions;
my $graphObjs = @{$self->{staticObjects}} ?
join(",", @{$self->{staticObjects}}, $cmp->{rh_ans}{correct_ans}) : $cmp->{rh_ans}{correct_ans};

# This first ends the attempts table MathJax_Preview script. Note that the script
# started here is ended by the original script end tag for the MathJax_Preview.
$cmp->{rh_ans}{correct_ans_latex_string} = << "END_ANS";
</script>
<div id='${ans_name}_correct_ans_graphbox' class='graphtool-answer-container'></div>
<script>
jQuery("#${ans_name}_correct_ans_graphbox").parent().find('span').remove();
jQuery("#${ans_name}_correct_ans_graphbox").parent().find('script[type^="math/tex"]').remove();
jQuery(function() {
graphTool("${ans_name}_correct_ans_graphbox", {
staticObjects: "$graphObjs",
Expand All @@ -578,6 +569,7 @@ sub cmp {
JSXGraphOptions: $self->{JSXGraphOptions}
});
});
</script>
END_ANS
}

Expand Down

0 comments on commit d7540b1

Please sign in to comment.