From b215c6e4f32a386347baa86fc71b5c9cd77fecac Mon Sep 17 00:00:00 2001 From: Chris Sangwin Date: Fri, 3 Jan 2025 10:58:06 +0000 Subject: [PATCH 1/2] Update assessment.mac Fix spelling mistake. --- stack/maxima/assessment.mac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack/maxima/assessment.mac b/stack/maxima/assessment.mac index 1a3634019d..083e30529e 100644 --- a/stack/maxima/assessment.mac +++ b/stack/maxima/assessment.mac @@ -542,7 +542,7 @@ polarform_simp(ex) := block([%_r, %_theta, %_pf,simp], */ -/* Decides if an expression is precicely of the form a*10^n, where a is an integer, or a float, and n is an integer. */ +/* Decides if an expression is precisely of the form a*10^n, where a is an integer, or a float, and n is an integer. */ scientific_notationp(ex) := block([tn], if not(safe_op(ex)="*") then return(false), if not(length(args(ex))=2) then return(false), From ee4d67e41abea1a324882edf4d64163601ecf10a Mon Sep 17 00:00:00 2001 From: Chris Sangwin Date: Mon, 6 Jan 2025 13:23:25 +0000 Subject: [PATCH 2/2] Fix to issue #1349: support for display of spaces in TeX output of integers. --- doc/en/CAS/Numbers.md | 23 ++++++++++++----------- stack/maxima/stackmaxima.mac | 9 ++++++--- tests/cassession2_test.php | 3 +++ tests/castext_test.php | 29 +++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/doc/en/CAS/Numbers.md b/doc/en/CAS/Numbers.md index 75ed1faa05..115f1ba415 100644 --- a/doc/en/CAS/Numbers.md +++ b/doc/en/CAS/Numbers.md @@ -87,18 +87,19 @@ To force all floating point numbers to decimal floating point numbers use You can also force all integers to be displayed as floating point decimals or in scientific notation using `stackintfmt` and the appropriate template. This function calls the LISP `format` function, which is complex and more example are available [online](http://www.gigamonkeys.com/book/a-few-format-recipes.html) elsewhere. -| Template | Input | TeX Output | Description/notes +| Template | Input | TeX Output | Description/notes | ----------- | ----------- | ---------------- | ---------------------------------------------------------------------------------------------- -| `"~,4f"` | `0.12349` | \(0.1235\) | Output four decimal places: floating point. -| | `0.12345` | \(0.1234\) | Note the rounding. -| | `0.12` | \(0.1200\) | -| `"~,5e"` | `100.34` | \(1.00340e+2\) | Output five decimal places: scientific notation. -| `"~:d"` | `10000000` | \(10,000,000\) | Separate decimal groups of three digits with commas. -| `~r` | `9` | \(\text{nine}\) | Rhetoric. -| `~:r` | `9` | \(\text{ninth}\) | Ordinal rhetoric. -| `~7r` | `9` | \(12\) | Base 7. -| `~@r` | `9` | \(IX\) | Roman numerals. -| `~:@r` | `9` | \(VIIII\) | Old style Roman numerals. +| `"~,4f"` | `0.12349` | \(0.1235\) | Output four decimal places: floating point. +| | `0.12345` | \(0.1234\) | Note the rounding. +| | `0.12` | \(0.1200\) | +| `"~,5e"` | `100.34` | \(1.00340e+2\) | Output five decimal places: scientific notation. +| `"~:d"` | `10000000` | \(10,000,000\) | Separate decimal groups of three digits with commas. +| `"~,,\' ,:d"` | `10000000` | \(10\ 000\ 000\) | Separate decimal groups of three digits with spaces. +| `~r` | `9` | \(\text{nine}\) | Rhetoric. +| `~:r` | `9` | \(\text{ninth}\) | Ordinal rhetoric. +| `~7r` | `9` | \(12\) | Base 7. +| `~@r` | `9` | \(IX\) | Roman numerals. +| `~:@r` | `9` | \(VIIII\) | Old style Roman numerals. There are many other options within the LISP format command. Please note with the rhetoric and Roman numerals that the numbers will be in LaTeX mathematics environments. diff --git a/stack/maxima/stackmaxima.mac b/stack/maxima/stackmaxima.mac index a9d368e038..eb547430d9 100644 --- a/stack/maxima/stackmaxima.mac +++ b/stack/maxima/stackmaxima.mac @@ -768,8 +768,11 @@ texput_decimal(ex):= stackfltsep:ex$ ) else if ev(integerp(x),simp) then ( if (is(stackintfmt="~r") or is(stackintfmt="~:r")) then tx:sconcat("\\text{",ev(printf(false, stackintfmt, x), simp),"}") - else - tx:ev(printf(false, stackintfmt, x), simp) + else ( + /* Protect spaces in integers so TeX (MathJax) displays them as spaces. */ + tx:ev(printf(false, stackintfmt, x), simp), + tx:ssubst("\\ ", " ", tx) + ) ) else tx:string(x), /* We need this separation because validation displays trailing zeros and this is controlled by stackfltfmt. */ @@ -777,7 +780,7 @@ texput_decimal(ex):= stackfltsep:ex$ tx:ssubst("\\ ", ",", tx), tx:ssubst("{,}", ".", tx) ), - tx + tx )$ /* Some systems are throwing an error here, which is spurious. */ errcatch(compile(?texnumformat)); diff --git a/tests/cassession2_test.php b/tests/cassession2_test.php index 89531ddb37..6228a5dbb6 100644 --- a/tests/cassession2_test.php +++ b/tests/cassession2_test.php @@ -2101,6 +2101,9 @@ public function test_stack_stackintfmt(): void { $cases[] = ['(stackintfmt:"~r",n0)', '73', '\text{seventy-three}']; $cases[] = ['(stackintfmt:"~:r",n0)', '73', '\text{seventy-third}']; $cases[] = ['(stackintfmt:"~@R",n0)', '73', 'LXXIII']; + $cases[] = ['(stackintfmt:"~:d",123456789)', '123456789', '123,456,789']; + $cases[] = ['(stackintfmt:"~,,\',,:d",123456789)', '123456789', '123,456,789']; + $cases[] = ['(stackintfmt:"~,,\' ,:d",123456789)', '123456789', '123\\ 456\\ 789']; foreach ($cases as $i => $case) { $s = 'n' . $i . ':' . $case[0]; diff --git a/tests/castext_test.php b/tests/castext_test.php index 6209660a73..fb872fadd1 100644 --- a/tests/castext_test.php +++ b/tests/castext_test.php @@ -1546,6 +1546,35 @@ public function test_numerical_display_commas(): void { $at2->get_rendered()); } + /** + * Fix to issue #1349, actually display spaces in TeX output. + * @covers \qtype_stack\stack_cas_castext2_latex + */ + public function test_numerical_display_group_spaces(): void { + + $st = 'The number {@10000000@} is written with spaces. '; + $st .= 'Sets {@{1200, 45678}@} and lists {@[1200, 45678]@}'; + + $a2 = ['stackintfmt:"~,,\' ,:d"']; + $s2 = []; + foreach ($a2 as $s) { + $s2[] = stack_ast_container::make_from_teacher_source($s, '', new stack_cas_security(), []); + } + $cs2 = new stack_cas_session2($s2, null, 0); + + $at2 = castext2_evaluatable::make_from_source($st, 'test-case'); + + $this->assertTrue($at2->get_valid()); + $cs2->add_statement($at2); + $cs2->instantiate(); + + $this->assertEquals( + 'The number \({10\\ 000\\ 000}\) is written with spaces. ' . + 'Sets \({\left \{1\\ 200 , 45\\ 678 \right \}}\) ' . + 'and lists \({\left[ 1\\ 200 , 45\\ 678 \right]}\)', + $at2->get_rendered()); + } + /** * Add description here. * @covers \qtype_stack\stack_cas_castext2_latex