Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug with LimitedFraction and MathQuill #1169

Open
Alex-Jordan opened this issue Jan 7, 2025 · 4 comments
Open

bug with LimitedFraction and MathQuill #1169

Alex-Jordan opened this issue Jan 7, 2025 · 4 comments

Comments

@Alex-Jordan
Copy link
Contributor

With the MWE below, it behaves as expected in 2.19. But in develop, when you submit the answer -1/2 with MathQuill, the answer ends up submitted as -(1/2) and is not accepted.

DOCUMENT();

loadMacros(qw(PGstandard.pl PGML.pl contextFraction.pl));

Context("LimitedFraction");
$answer = Fraction(-1/2);

BEGIN_PGML
[`[$answer]={}`][_]{$answer}
END_PGML

ENDDOCUMENT();
@drgrice1
Copy link
Member

drgrice1 commented Jan 7, 2025

What MathQuill does with this hasn't changed from 2.19 to now. I suspect this is another issue with the contextFraction.pl changes, and using the contextExtensions.pl macro.

@somiaj
Copy link
Contributor

somiaj commented Jan 7, 2025

I am able to fix the issue with reverting the following change to the LimitedFraction context, by reverting the change to using an extension of LimitedNumeric. It seems that LimitedNumeric removes ( parens, which is what is causing the error. I tried to just add $context->parens->redefine('(');, but that didn't work. Reverting defining the context to how it was defined before using a copy of LimitedNumeric fixed the issue for me. I have a feeling there is a better way to do this though since I'm not extending LimitedNumeric, directly.

diff --git a/macros/contexts/contextFraction.pl b/macros/contexts/contextFraction.pl
index 3179d09d..49e8e029 100644
--- a/macros/contexts/contextFraction.pl
+++ b/macros/contexts/contextFraction.pl
@@ -345,8 +345,11 @@ sub Init {
        $context->{error}{msg}{"You are not allowed to type decimal numbers in this problem"} =
                "You are only allowed to enter fractions, not decimal numbers";
 
-       $context = $main::context{LimitedFraction} = context::Fraction::extending('LimitedNumeric');
+       $context = $main::context{LimitedFraction} = $context->copy;
        $context->{name} = "LimitedFraction";
+       $context->operators->undefine('+', '-', '*', '* ', '^', '**', 'U', '.', '><', 'u+', '!', '_', ',',);
+       $context->parens->undefine('|', '{', '[');
+       $context->functions->disable('All');
        $context->flags->set(
                strictFractions   => 1,
                allowMixedNumbers => 1,

@dpvc
Copy link
Member

dpvc commented Jan 7, 2025

Here is a change that I think will resolve the issue while still using the LimitedNumeric context.

diff --git a/macros/contexts/contextFraction.pl b/macros/contexts/contextFraction.pl
index 112878a9..2aea9ee8 100644
--- a/macros/contexts/contextFraction.pl
+++ b/macros/contexts/contextFraction.pl
@@ -354,6 +354,7 @@ sub Init {
                showMixedNumbers  => 1,
        );
        $context->{cmpDefaults}{Fraction} = { studentsMustReduceFractions => 1 };
+       $context->parens->redefine('(');
 
        $context = $main::context{LimitedProperFraction} = $context->copy;
        $context->flags->set(requireProperFractions => 1);
@@ -673,7 +674,7 @@ our @ISA = ('context::Fraction::Class', 'Parser::UOP');
 sub _check {
        my $self = shift;
        $self->{hadParens} = 1 if $self->{op}{hadParens};
-       &{ $self->super('_check') }($self);
+       &{ $self->super('_check') }($self) unless $self->extensionClassMatch($self->{op}, 'FRACTION');
        $self->setExtensionClass('MINUS') if $self->{op}->class eq 'Number';
        $self->mutate;
 }

@Alex-Jordan
Copy link
Contributor Author

Thanks @dpvc, that works for the two problems I know of where this issue had bubbled up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants