Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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