Skip to content

Commit

Permalink
Merge pull request #608 from drdrew42/bugfix/too-many-fraction-parens
Browse files Browse the repository at this point in the history
Fix calls to Parser::Value::TeX & too many (cooks)
  • Loading branch information
drgrice1 authored Dec 2, 2021
2 parents 37637e2 + 7d0d3e4 commit 76ba414
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ sub Close {
($top->type eq 'Comma') ? $top->entryType : $top->typeRef,
($type ne 'start') ? ($open,$paren->{close}) : () )};
} else {
$top->{value}{hadParens} = 1;
}
$top->{value}{hadParens} = 1 unless $open eq 'start';
}
$self->pop; $self->push($top);
$self->CloseFn() if ($paren->{function} && $self->prev->{type} eq 'fn');
} elsif ($paren->{formInterval} eq $type && $self->top->{value}->length == 2) {
Expand Down
13 changes: 7 additions & 6 deletions macros/contextFraction.pl
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ sub reduce {
#
sub string {
my $self = shift;
my $string = $self->SUPER::string($self, @_);
my $string = $self->SUPER::string(@_);
return $string unless $self->{value}->classMatch('Fraction');
my $precedence = shift;
my $frac = $self->context->operators->get('/')->{precedence};
Expand All @@ -627,15 +627,18 @@ sub string {
}

#
# Add parentheses if they are needed by precedence
# Add parentheses if they were there originally, or
# are needed by precedence and we asked for exxxtra parens
#
sub TeX {
my $self = shift;
my $string = $self->SUPER::TeX($self, @_);
my $string = $self->SUPER::TeX(@_);
return $string unless $self->{value}->classMatch('Fraction');
my $precedence = shift;
my $frac = $self->context->operators->get('/')->{precedence};
$string = '\left(' . $string . '\right)' if defined $precedence && $precedence > $frac;
my $noparens = shift;
$string = '\left(' . $string . '\right)' if $self->{hadParens} ||
(defined $precedence && $precedence > $frac && !$noparens);
return $string;
}

Expand Down Expand Up @@ -898,7 +901,6 @@ sub string {
if ($self->getFlagWithAlias("showMixedNumbers","showProperFractions") && CORE::abs($a) > $b)
{$n = int($a/$b); $a = CORE::abs($a) % $b; $n .= " " unless $a == 0}
$n .= "$a/$b" unless $a == 0 && $n ne '';
$n = "($n)" if defined $prec && $prec >= 1;
return "$n";
}

Expand All @@ -911,7 +913,6 @@ sub TeX {
my $s = ""; ($a,$s) = (-$a,"-") if $a < 0;
$n .= ($self->{isHorizontal} ? "$s$a/$b" : "${s}{\\textstyle\\frac{$a}{$b}}")
unless $a == 0 && $n ne '';
$n = "\\left($n\\right)" if defined $prec && $prec >= 1;
return "$n";
}

Expand Down

0 comments on commit 76ba414

Please sign in to comment.