aboutsummaryrefslogtreecommitdiff
path: root/renderer.php
diff options
context:
space:
mode:
authorJean-Michel Vedrine <vedrine@vedrine.org>2018-02-04 11:13:51 +0100
committerJean-Michel Vedrine <vedrine@vedrine.org>2018-02-04 11:13:51 +0100
commitc3cc23141194f4c0e56d6802f7e9ff082d21c5fb (patch)
treedcca1dd671f1b45608cf1570f927be31f2f6efe4 /renderer.php
parent6e5d28ec5e338854112daaeb237c55fa6990e30c (diff)
Display formula using Ajax
Diffstat (limited to 'renderer.php')
-rw-r--r--renderer.php28
1 files changed, 6 insertions, 22 deletions
diff --git a/renderer.php b/renderer.php
index ec3d57e..e19ae11 100644
--- a/renderer.php
+++ b/renderer.php
@@ -76,14 +76,14 @@ class qtype_algebra_renderer extends qtype_renderer {
}
// Create an array of variable names to use when displaying the function entered.
- $varnames = array();
+ $vars = array();
if ($question and isset($question->variables)) {
$variables = $question->variables;
foreach ($question->variables as $var) {
- $varnames[] = $var->name;
+ $vars[] = $var->name;
}
}
- $varnames = implode(',', $varnames);
+ $varnames = implode(',', $vars);
$questiontext = $question->format_questiontext($qa);
@@ -142,25 +142,9 @@ class qtype_algebra_renderer extends qtype_renderer {
'style' => 'display:none',
)
);
- $p = new qtype_algebra_parser;
- try {
- $vars = explode(',', $varnames);
- if (empty($currentanswer)) {
- $texexp = '';
- } else {
- $exp = $p->parse($currentanswer, $vars);
- $texexp = $exp->tex();
- }
- } catch (Exception $e) {
- $texexp = '';
- }
- if ($CFG->qtype_algebra_texdelimiters == 'old') {
- $texexp = '$$' . $texexp . '$$';
- } else {
- $texexp = '\\[' . $texexp . '\\]';
- }
- $display = $question->format_text("<span class=\"filter_mathjaxloader_equation\">" . $texexp ."</span>",
- 1 ,$qa, 'question', 'questiontext', $question->id);
+
+ $display = $question->format_text("<span class=\"filter_mathjaxloader_equation\">" . $question->formated_expression($currentanswer, $vars) ."</span>",
+ FORMAT_MOODLE ,$qa, 'question', 'questiontext', $question->id);
$result .= html_writer::tag('div', $display ,array(
'type' => 'text',
'name' => $nameprefix . '_display',