From 76d11db6815360c651a71337fb68163e982b3161 Mon Sep 17 00:00:00 2001 From: "K. Andrew Parker" Date: Thu, 14 Oct 2021 20:25:46 -0700 Subject: [PATCH 1/4] fix calls to Parser::Value::TeX & too many (cooks) --- macros/contextFraction.pl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/macros/contextFraction.pl b/macros/contextFraction.pl index 2c5585a93a..f44686c3b1 100644 --- a/macros/contextFraction.pl +++ b/macros/contextFraction.pl @@ -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}; @@ -627,15 +627,17 @@ 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; + $string = '\left(' . $string . '\right)' + if defined $precedence && $precedence > $frac && $self->context->flag('showExtraParens') > 1; return $string; } @@ -898,7 +900,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"; } @@ -911,7 +912,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"; } From 3edee9166201369b0403e6d8b8374bd37225185b Mon Sep 17 00:00:00 2001 From: "K. Andrew Parker" Date: Fri, 15 Oct 2021 08:54:45 -0700 Subject: [PATCH 2/4] forgot to include explicit parens --- macros/contextFraction.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/macros/contextFraction.pl b/macros/contextFraction.pl index f44686c3b1..03c980499b 100644 --- a/macros/contextFraction.pl +++ b/macros/contextFraction.pl @@ -636,8 +636,8 @@ sub 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 && $self->context->flag('showExtraParens') > 1; + $string = '\left(' . $string . '\right)' if $self->{hadParens} || + (defined $precedence && $precedence > $frac && $self->context->flag('showExtraParens') > 1); return $string; } From c4a26ee75831c336bec50387dbf8191b9fe39247 Mon Sep 17 00:00:00 2001 From: "K. Andrew Parker" Date: Sat, 16 Oct 2021 09:06:45 -0700 Subject: [PATCH 3/4] don't declare outermost parens --- lib/Parser.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Parser.pm b/lib/Parser.pm index d3a249932c..b2d1affd68 100644 --- a/lib/Parser.pm +++ b/lib/Parser.pm @@ -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) { From 7d0d3e4336d1b8d7905d8d6e2caf64f10e1cba25 Mon Sep 17 00:00:00 2001 From: "K. Andrew Parker" Date: Wed, 20 Oct 2021 16:17:54 -0700 Subject: [PATCH 4/4] Update macros/contextFraction.pl Co-authored-by: Davide P. Cervone --- macros/contextFraction.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/macros/contextFraction.pl b/macros/contextFraction.pl index 03c980499b..2644529566 100644 --- a/macros/contextFraction.pl +++ b/macros/contextFraction.pl @@ -636,8 +636,9 @@ sub TeX { return $string unless $self->{value}->classMatch('Fraction'); my $precedence = shift; my $frac = $self->context->operators->get('/')->{precedence}; + my $noparens = shift; $string = '\left(' . $string . '\right)' if $self->{hadParens} || - (defined $precedence && $precedence > $frac && $self->context->flag('showExtraParens') > 1); + (defined $precedence && $precedence > $frac && !$noparens); return $string; }