WeBWorK Problems

extra parens in a formula with fractions

Re: extra parens in a formula with fractions

by Davide Cervone -
Number of replies: 1

You and Jaimos are correct that this comes from the hadParens property. It is possible to remove this programmatically, if your problems include PGcourse.pl as the final macro file being loaded, you could add

$context{Fraction}{parser}{Value} = 'my::context::Frac::Parser::Value'
	if defined $context{Fraction};

package my::context::Frac::Parser::Value;
our @ISA = ('context::Fraction::Parser::Value');

sub string {
	my $self = shift;
	delete $self->{hadParens} if $self->{value}->classMatch('Fraction');
	$self->SUPER::string(@_);
}

sub TeX {
	my $self = shift;
	delete $self->{hadParens} if $self->{value}->classMatch('Fraction');
	$self->SUPER::TeX(@_);
}

package main;
This overrides the object class that is inserting the parentheses and subclasses it, replacing the string and TeX methods to clear the hadParens property. Alternatively, you could make a separate macro file that contains these lines and use loadMacros() to load it in all the problems you are wanting to modify. Or you could put a copy of contextFraction.pl in your course's templates/macros directory and edit it to remove the two references to hadParens. Any of those should work.
In reply to Davide Cervone

Re: extra parens in a formula with fractions

by Alex Jordan -

Can you comment on why we would not want these changes for the distribution in general? Is it because something like Formula("x 2/3") would come out like (x 2)/3 instead of like x (2/3)?