Skip to content
Snippets Groups Projects
Commit 856091b6 authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Fix to issue #1060: add parentheses round neatives when displaying without multiplication signs.

parent 9d844cdd
Branches
No related tags found
No related merge requests found
......@@ -226,13 +226,15 @@ texput(multsgnonlyfornumberssym, "\\times")$
multsgnonlyfornumbers(e) := block([arglist, resstr, a, lastisnum, isnum, multsgn, str],
arglist: args(e),
a: pop(arglist),
resstr: if (atom(a) or is(length(args(a))=1) or safe_op(a) = "^") then tex1(a)
resstr: if (safe_op(a) = "-" or (real_numberp(a) and is(a<0))) then sconcat("\\left(", tex1(a), "\\right)")
else if (atom(a) or is(length(args(a))=1) or safe_op(a) = "^") then tex1(a)
else sconcat("\\left(", tex1(a), "\\right)"),
lastisnum: numberp(a),
for a in arglist do (
isnum: numberp(a),
multsgn: if (lastisnum and isnum) then tex1(multsgnonlyfornumberssym) else "\\,",
str: if (atom(a) or is(length(args(a))=1) or safe_op(a) = "^") then tex1(a)
str: if (safe_op(a) = "-" or (real_numberp(a) and is(a<0))) then sconcat("\\left(", tex1(a), "\\right)")
else if (atom(a) or is(length(args(a))=1) or safe_op(a) = "^") then tex1(a)
else sconcat("\\left(", tex1(a), "\\right)"),
resstr: sconcat(resstr, multsgn, " ", str),
lastisnum: isnum
......
......@@ -430,7 +430,7 @@ class cassession2_test extends qtype_stack_testcase {
public function test_multiplication_option_onum() {
$s1 = [];
$cs = array('a:2*x', 'b:2*3*x', 'c:3*5^2', 'd:3*x^2');
$cs = array('a:2*x', 'b:2*3*x', 'c:3*5^2', 'd:3*x^2', 's1:x*(-y)', 's2:3*(-4)*x*(-y)');
foreach ($cs as $s) {
$s1[] = stack_ast_container::make_from_student_source($s, '', new stack_cas_security(), array());
}
......@@ -445,6 +445,8 @@ class cassession2_test extends qtype_stack_testcase {
$this->assertEquals('2\times 3\, x', $s1[1]->get_display());
$this->assertEquals('3\, 5^2', $s1[2]->get_display());
$this->assertEquals('3\, x^2', $s1[3]->get_display());
$this->assertEquals('x\, \left(-y\right)', $s1[4]->get_display());
$this->assertEquals('3\times \left(-4\right)\, x\, \left(-y\right)', $s1[5]->get_display());
$s1 = [];
$cs = array('texput(multsgnonlyfornumberssym, "\\\\cdot")',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment