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

Add example from issue #1064 (texput and hat) to the docs and test cases.

parent d35c7b22
Branches
Tags
No related merge requests found
...@@ -76,6 +76,11 @@ It is also possible to use an unnamed `lambda` function. E.g. if you have a fun ...@@ -76,6 +76,11 @@ It is also possible to use an unnamed `lambda` function. E.g. if you have a fun
will display `tup(a,b)` as \( \left[a,b\right) \). will display `tup(a,b)` as \( \left[a,b\right) \).
To create a function `hat` so that input `hat(x)` is displayed as \(\hat{x}\) you can use:
/* In question variables. */
texput(hat, lambda([ex], sconcat("\\hat{", tex1(first(ex)), "}")));
As a more complicated example, to typeset `u(A_k,k,1,inf)` as \({\bigcup_{k = 1}^{\infty } {A}_{k}}\) you can use the following: As a more complicated example, to typeset `u(A_k,k,1,inf)` as \({\bigcup_{k = 1}^{\infty } {A}_{k}}\) you can use the following:
texput(u,lambda([ex],if length(ex)<4 then return("\\bigcup_{?=?}^{?} ? ") else texput(u,lambda([ex],if length(ex)<4 then return("\\bigcup_{?=?}^{?} ? ") else
......
...@@ -2025,6 +2025,24 @@ class castext_test extends qtype_stack_testcase { ...@@ -2025,6 +2025,24 @@ class castext_test extends qtype_stack_testcase {
$this->assertEquals('\({bigcup_{k = 1}^{\infty } {A}_{k}}\)', $at2->get_rendered()); $this->assertEquals('\({bigcup_{k = 1}^{\infty } {A}_{k}}\)', $at2->get_rendered());
} }
/**
* @covers \qtype_stack\stack_cas_castext2_latex
* @covers \qtype_stack\stack_cas_keyval
*/
public function test_texput_hat() {
$vars = 'texput(hat, lambda([ex], sconcat("\\\\hat{", tex1(first(ex)), "}")));';
$at1 = new stack_cas_keyval($vars, null, 123);
$this->assertTrue($at1->get_valid());
$cs2 = $at1->get_session();
$at2 = castext2_evaluatable::make_from_source('{@1+hat(s)@}', 'test-case');
$this->assertTrue($at2->get_valid());
$cs2->add_statement($at2);
$cs2->instantiate();
$this->assertEquals('\({\hat{s}+1}\)', $at2->get_rendered());
}
/** /**
* @covers \qtype_stack\stack_cas_castext2_latex * @covers \qtype_stack\stack_cas_castext2_latex
* @covers \qtype_stack\stack_cas_keyval * @covers \qtype_stack\stack_cas_keyval
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment