DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGML.pl", "PGcourse.pl", "parserNumberWithUnits.pl", "parserFormulaWithUnits.pl", "parserOneOf.pl", ); ####################################################################################################### # parserOneOf.pl NumberWithUnits fix by Davide Cervone, June 14, 2020 # For use in an answer field with OneOf and NumberWithUnits math objects. # # Let $T1 and $T2 be NumberWithUnits math objects. # # Usage: Your answer is [__]{ myOneOf($T1, $T2) } # ####################################################################################################### package myOneOf; our @ISA = ('parser::OneOf'); sub cmp_parse { my $self = shift; my $ans = shift; my $student = $ans->{original_student_ans}; my $max = 0; foreach $choice (@{$self->{data}}) { my $hash = $choice->cmp->evaluate($student); if ($hash->{score} >= $max) { foreach my $name ('correct_ans', 'correct_ans_latex_string', 'correct_value') { $hash->{$name} = $ans->{$name}; } $ans = $hash; $max = $hash->{score}; } } return $ans; } package main; sub myOneOf {myOneOf->new(@_)} ####################################################################################################### # End of parserOneOf.pl NumberWithUnits fix ####################################################################################################### Context("Numeric"); $T1 = NumberWithUnits( 1, "degC" ); $T2 = NumberWithUnits( 2, "degK" ); TEXT(beginproblem()); Context()->texStrings; BEGIN_PGML Enter the answer 1 degC or 2 degK. a) What is the answer? [__]{ myOneOf($T1,$T2) }{width => 10} END_PGML ENDDOCUMENT();