Skip to content

Commit

Permalink
Fix the sage.pl macro.
Browse files Browse the repository at this point in the history
First, there was an obvious typo that made the macro's ShowAnswerBlank
option fail.

Next, sage uses python3 which requires that the print function have its
arguments parenthesized.  This causes the record_answer method in the
ShowAnswerBlank eq 'none' case to fail.

Next, '<script src="$CellServer/static/jquery.min.js"></script>' was
recently added to this macro before the loading of the sagecell
javascript.  The sagecell javascript internally loads its own jQuery
instance, and so there is no need for that.  Furthermore, that version
of jQuery conflicts with the version currently in use by WeBWorK.

Finally, the sagecell server does not correctly deal with jQuery.  They
recently added the usage of the noConflict method, but then they still
use and modify the global $ variable.  This conflicts with our jQuery
usage.  So our version of jQuery is cached and restored after the
sagecell javascript is loaded and executed.

See https://webwork.maa.org/moodle/mod/forum/discuss.php?d=5011 for some
of my discussion on this.
  • Loading branch information
drgrice1 committed Feb 2, 2021
1 parent 01d8bb1 commit 68245a5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions macros/sage.pl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ sub new {


# handle legacy case where AnswerReturn was used
unless ($options{ShowAnswerBlank} =~ \S){
unless ($options{ShowAnswerBlank} =~ /\S/){
if ($options{AnswerReturn} == 0) {
$options{ShowAnswerBlank} = 'none';
} else {
Expand Down Expand Up @@ -126,7 +126,7 @@ sub new {
if ($recordAnswerBlank eq 'none') {
$sage::recordAnswerString = <<EndOfString;
def record_answer(ansVals):
print '';
print('');
EndOfString
} else {
$sage::recordAnswerString = <<EndOfString;
Expand Down Expand Up @@ -186,10 +186,10 @@ sub sageCode{
sub sagePrint{
my $self = shift;
main::TEXT(main::MODES(TeX=>"", HTML=><<"SAGE_PRINT"));
<script src="$self->{CellServer}/static/jquery.min.js"></script>
<script>var jqSave = \$.noConflict(true)</script>
<script src="$self->{CellServer}/embedded_sagecell.js"> </script>
<script>
\$(function () {
jqSave(function () {
sagecell.makeSagecell({
inputLocation: '#sagecell',
template: sagecell.templates.minimal,
Expand All @@ -198,6 +198,7 @@ sub sagePrint{
evalButtonText: '$self->{ButtonText}'
});
});
\$ = jQuery = jqSave;
</script>
SAGE_PRINT
}
Expand Down Expand Up @@ -244,14 +245,15 @@ package main;
sub sageCalculatorHeader {
$CellServer = 'https://sagecell.sagemath.org';
main::HEADER_TEXT(main::MODES(TeX=>"", HTML=><<"END_OF_FILE"));
<script src="$CellServer/static/jquery.min.js"></script>
<script>var jqSave = \$.noConflict(true)</script>
<script src="$CellServer/static/embedded_sagecell.js"></script>
<script>\$(function () {
<script>jqSave(function () {
// Make *any* div with class 'sage-compute' a Sage cell
sagecell.makeSagecell({inputLocation: 'div.sage-compute',
autoeval: 1,
hide: ["permalink"],
evalButtonText: 'Evaluate'});
\$ = jQuery = jqSave;
});
</script>
END_OF_FILE
Expand Down

0 comments on commit 68245a5

Please sign in to comment.