Skip to content

Commit 76ba414

Browse files
authored
Merge pull request #608 from drdrew42/bugfix/too-many-fraction-parens
Fix calls to Parser::Value::TeX & too many (cooks)
2 parents 37637e2 + 7d0d3e4 commit 76ba414

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/Parser.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ sub Close {
401401
($top->type eq 'Comma') ? $top->entryType : $top->typeRef,
402402
($type ne 'start') ? ($open,$paren->{close}) : () )};
403403
} else {
404-
$top->{value}{hadParens} = 1;
405-
}
404+
$top->{value}{hadParens} = 1 unless $open eq 'start';
405+
}
406406
$self->pop; $self->push($top);
407407
$self->CloseFn() if ($paren->{function} && $self->prev->{type} eq 'fn');
408408
} elsif ($paren->{formInterval} eq $type && $self->top->{value}->length == 2) {

macros/contextFraction.pl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ sub reduce {
618618
#
619619
sub string {
620620
my $self = shift;
621-
my $string = $self->SUPER::string($self, @_);
621+
my $string = $self->SUPER::string(@_);
622622
return $string unless $self->{value}->classMatch('Fraction');
623623
my $precedence = shift;
624624
my $frac = $self->context->operators->get('/')->{precedence};
@@ -627,15 +627,18 @@ sub string {
627627
}
628628

629629
#
630-
# Add parentheses if they are needed by precedence
630+
# Add parentheses if they were there originally, or
631+
# are needed by precedence and we asked for exxxtra parens
631632
#
632633
sub TeX {
633634
my $self = shift;
634-
my $string = $self->SUPER::TeX($self, @_);
635+
my $string = $self->SUPER::TeX(@_);
635636
return $string unless $self->{value}->classMatch('Fraction');
636637
my $precedence = shift;
637638
my $frac = $self->context->operators->get('/')->{precedence};
638-
$string = '\left(' . $string . '\right)' if defined $precedence && $precedence > $frac;
639+
my $noparens = shift;
640+
$string = '\left(' . $string . '\right)' if $self->{hadParens} ||
641+
(defined $precedence && $precedence > $frac && !$noparens);
639642
return $string;
640643
}
641644

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

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

0 commit comments

Comments
 (0)