Skip to content

Commit

Permalink
Merge branch 'dev' into iss1348
Browse files Browse the repository at this point in the history
  • Loading branch information
sangwinc committed Jan 6, 2025
2 parents 629f2ef + 654e189 commit 03fcc14
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
23 changes: 12 additions & 11 deletions doc/en/CAS/Numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion stack/maxima/assessment.mac
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 6 additions & 3 deletions stack/maxima/stackmaxima.mac
Original file line number Diff line number Diff line change
Expand Up @@ -768,16 +768,19 @@ 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. */
if is(stackfltsep = ",") then (
tx:ssubst("\\ ", ",", tx),
tx:ssubst("{,}", ".", tx)
),
tx
tx
)$
/* Some systems are throwing an error here, which is spurious. */
errcatch(compile(?texnumformat));
Expand Down
3 changes: 3 additions & 0 deletions tests/cassession2_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
29 changes: 29 additions & 0 deletions tests/castext_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03fcc14

Please sign in to comment.