public function test_maths_rendering() { if (!stack_maths_output_maths::filter_is_installed()) { $this->markTestSkipped('The OU maths filter is not installed.'); } if (!defined('FILTER_MATHS_TEST_SERVICE_URL_BASE')) { $this->markTestSkipped('To run the OU maths filter output tests, ' . 'you must define FILTER_MATHS_TEST_SERVICE_URL_BASE in config.php.'); } $this->resetAfterTest(); set_config('mathsdisplay', 'maths', 'qtype_stack'); set_config('texservice', FILTER_MATHS_TEST_SERVICE_URL_BASE . 'tex', 'filter_maths'); set_config('imageservice', FILTER_MATHS_TEST_SERVICE_URL_BASE . 'imagetex', 'filter_maths'); set_config('englishservice', FILTER_MATHS_TEST_SERVICE_URL_BASE . 'english', 'filter_maths'); stack_utils::clear_config_cache(); filter_set_global_state('mathjaxloader', TEXTFILTER_DISABLED); // Test language string. $this->assertRegExp('~^Your answer needs to be a single fraction of the form <a .*alt="a over b".*</a>\\. $~', stack_string('ATSingleFrac_part')); // Test docs - make sure maths inside <code> is not rendered. $this->assertRegExp('~^<p><code>\\\\\\(x\\^2\\\\\\)</code> gives <a .*alt="x squared".*</a>\\.</p>\\n$~', stack_docs_render_markdown('<code>\\(x^2\\)</code> gives \\(x^2\\).', '')); // Test docs - make sure maths inside <textarea> is not rendered. $this->assertRegExp('~^<p>\\n' . 'Differentiate \\\\\\\\\\[x\\^2 \\+ y\\^2\\\\\\\\\\] with respect to \\\\\\\\\\(x\\\\\\\\\\).</p>\\n$~', stack_docs_render_markdown('<textarea readonly="readonly" rows="3" cols="50">' . "\n" . 'Differentiate \\[x^2 + y^2\\] with respect to \\(x\\).</textarea>', '')); // Test CAS text with inline maths. $this->assertEquals('What is <tex mode="inline">x^2</tex>?', stack_maths::process_display_castext('What is \\(x^2\\)?')); // Test CAS text with display maths. $this->assertEquals('What is <span class="displayequation"><tex mode="display">x^2</tex></span>?', stack_maths::process_display_castext('What is \\[x^2\\]?')); // Test with replacedollars. set_config('replacedollars', '1', 'qtype_stack'); stack_utils::clear_config_cache(); $this->assertEquals('What is <tex mode="inline">x^2</tex> or ' . '<span class="displayequation"><tex mode="display">x^2</tex></span>?', stack_maths::process_display_castext('What is $x^2$ or $$x^2$$?')); stack_utils::clear_config_cache(); }
public function test_maths_output_mathsjax() { filter_set_global_state('mathjaxloader', TEXTFILTER_DISABLED); // MathJax output is the default. $this->assertEquals('Your answer needs to be a single fraction of the form \\( {a}\\over{b} \\). ', stack_string('ATSingleFrac_part')); $this->assertEquals("<p><code>\\(x^2\\)</code> gives \\(x^2\\).</p>\n", stack_docs_render_markdown('`\\(x^2\\)` gives \\(x^2\\).', '')); $this->assertEquals('What is \\(x^2\\)?', stack_maths::process_display_castext('What is \\(x^2\\)?')); $this->resetAfterTest(); set_config('replacedollars', '1', 'qtype_stack'); stack_utils::clear_config_cache(); $this->assertEquals('What is \\(x^2\\) or \\[x^2\\]?', stack_maths::process_display_castext('What is $x^2$ or $$x^2$$?')); stack_utils::clear_config_cache(); }
public function test_tex_rendering() { $this->resetAfterTest(); set_config('mathsdisplay', 'tex', 'qtype_stack'); stack_utils::clear_config_cache(); filter_set_global_state('mathjaxloader', TEXTFILTER_DISABLED); // Test language string. // The <span class="MathJax_Preview"> bit is something that got added in // Moodle 2.8, so match it optionally. $this->assertRegExp('~^Your answer needs to be a single fraction of the form ' . '(<span class="MathJax_Preview">)?<a .*alt=" \\{a\\}\\\\over\\{b\\} ".*</(a|script)> \\. ~', stack_string('ATSingleFrac_part')); // Test docs - make sure maths inside <code> is not rendered. $this->assertRegExp('~^<p><code>\\\\\\(x\\^2\\\\\\)</code> gives (<span class="MathJax_Preview">)?<a .*alt="x\\^2".*</(a|script)> \\.</p>\\n$~', stack_docs_render_markdown('<code>\\(x^2\\)</code> gives \\(x^2\\).', '')); // Test docs - make sure maths inside <textarea> is not rendered. $this->assertRegExp('~^<p>\\n' . 'Differentiate \\\\\\\\\\[x\\^2 \\+ y\\^2\\\\\\\\\\] with respect to \\\\\\\\\\(x\\\\\\\\\\).</p>\\n$~', stack_docs_render_markdown('<textarea readonly="readonly" rows="3" cols="50">' . "\n" . 'Differentiate \\[x^2 + y^2\\] with respect to \\(x\\).</textarea>', '')); // Test CAS text with inline maths. $this->assertEquals('What is \\[x^2\\]?', stack_maths::process_display_castext('What is \\(x^2\\)?')); // Test CAS text with display maths. $this->assertEquals('What is <span class="displayequation">\\[\\displaystyle x^2\\]</span>?', stack_maths::process_display_castext('What is \\[x^2\\]?')); // Test with replacedollars. set_config('replacedollars', '1', 'qtype_stack'); stack_utils::clear_config_cache(); $this->assertEquals('What is \\[x^2\\] or <span class="displayequation">\\[\\displaystyle x^2\\]</span>?', stack_maths::process_display_castext('What is $x^2$ or $$x^2$$?')); stack_utils::clear_config_cache(); }
public function test_fact_sheets() { $cs2 = new stack_cas_session(array(), null, 0); $at1 = new stack_cas_text("[[facts:calc_diff_linearity_rule]]", $cs2, 0); $output = stack_maths::process_display_castext($at1->get_display_castext()); $this->assertContains(stack_string('calc_diff_linearity_rule_name'), $output); $this->assertContains(stack_string('calc_diff_linearity_rule_fact'), $output); }
/** * You need to call this method on the string you get from * $castext->get_display_castext() before you echo it. This ensures that equations * are displayed properly. * @param string $castext the result of calling $castext->get_display_castext(). * @return string HTML ready to output. */ function stack_ouput_castext($castext) { return format_text(stack_maths::process_display_castext($castext), FORMAT_HTML, array('noclean' => true)); }
public function general_feedback(question_attempt $qa) { $question = $qa->get_question(); if (empty($question->generalfeedback)) { return ''; } return $qa->get_question()->format_text(stack_maths::process_display_castext($question->get_generalfeedback_castext()->get_display_castext(), $this), $question->generalfeedbackformat, $qa, 'question', 'generalfeedback', $question->id); }