File tree Expand file tree Collapse file tree 4 files changed +13
-6
lines changed
Expand file tree Collapse file tree 4 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -434,6 +434,7 @@ $flags = {
434434 reduceConstants => 1, # 1 = automatically combine constants
435435 reduceConstantFunctions => 1, # 1 = compute function values of constants
436436 showExtraParens => 1, # 1 = add useful parens, 2 = make things painfully unambiguous
437+ stringifyNoBrackets => 0, # 1 = only use parentheses not brackets when stringifying
437438 formatStudentAnswer => ' evaluated' , # or 'parsed' or 'reduced'
438439 allowMissingOperands => 0, # 1 is used by Typeset context
439440 allowMissingFunctionInputs => 0, # 1 is used by Typeset context
Original file line number Diff line number Diff line change @@ -113,12 +113,12 @@ sub canBeInUnion {0}
113113sub isSetOfReals { (shift )-> type =~ m / ^(Interval|Union|Set)$ / }
114114
115115#
116- # Add parens to an expression (alternating the type of paren)
116+ # Add parens to an expression (alternating the type of paren unless stringifyNoBrackets is set )
117117#
118118sub addParens {
119119 my $self = shift ;
120120 my $string = shift ;
121- if ( $string =~ m / ^[^\[ ] *\( / ) { return ' [ ' . $string . ' ] ' }
121+ return ' [ ' . $string . ' ] ' if $string =~ m / ^[^\[ ] *\( / && ! $self -> context -> flag( ' stringifyNoBrackets ' );
122122 return ' (' . $string . ' )' ;
123123}
124124
Original file line number Diff line number Diff line change @@ -260,7 +260,8 @@ sub function_string {
260260 my $format = $formula -> context-> {format }{number };
261261 $formula -> context-> flags-> set(showExtraParens => 2);
262262 $formula -> context-> {format }{number } = " %f #" ;
263- my $func = $formula -> string;
263+ # Get no bracket string for $formula
264+ my $func = $formula . " " ;
264265 $func =~ s /\s // g ;
265266 $formula -> context-> flags-> set(showExtraParens => $extraParens );
266267 $formula -> context-> {format }{number } = $format ;
@@ -368,8 +369,6 @@ sub function_string {
368369 }
369370 }
370371
371- $out =~ s /\[ / (/ g ;
372- $out =~ s /\] / )/ g ;
373372 return $out ;
374373}
375374
Original file line number Diff line number Diff line change @@ -112,7 +112,14 @@ sub _dot {
112112 $l -> SUPER::_dot($r , $flag );
113113}
114114
115- sub pdot { ' (' . (shift -> stringify) . ' )' }
115+ sub pdot {
116+ my $self = shift ;
117+ my $nobrackets = $self -> context-> flag(' stringifyNoBrackets' );
118+ $self -> context-> flags-> set(stringifyNoBrackets => 1);
119+ my $string = ' (' . ($self -> stringify) . ' )' ;
120+ $self -> context-> flags-> set(stringifyNoBrackets => $nobrackets );
121+ return $string ;
122+ }
116123
117124#
118125# Call the Parser::Function call function
You can’t perform that action at this time.
0 commit comments