. /** * @package qtype_algebra * @copyright Roger Moore * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * Script which converts the given formula text into LaTeX code and then * displays the appropriate image file. It relies on the LaTeX filter or * the mathJax filter to be present. */ require_once('../../../config.php'); require_once("$CFG->dirroot/question/type/algebra/parser.php"); global $PAGE, $CFG; require_login(); $p = new qtype_algebra_parser; $errmsg = ''; try { $query = urldecode($_SERVER['QUERY_STRING']); $m = array(); if (!preg_match('/vars=([^&]*)&expr=(.*)$/A', $query, $m)) { throw new Exception('Invalid query string received from http server!'); } $vars = explode(',', $m[1]); if (empty($m[2])) { $texexp = ''; } else { $exp = $p->parse($m[2], $vars); $texexp = $exp->tex(); switch($CFG->qtype_algebra_texdelimiters) { case 'old': $texexp = '$$' . $texexp . '$$'; break; case 'new': $texexp = '\\[' . $texexp . '\\]'; break; case 'simple'; $texexp = '$' . $texexp . '$'; break; case 'inline': $texexp = '\\(' . $texexp . '\\)'; break; } } } catch (Exception $e) { $errmsg = $e->getMessage(); } $formatoptions = new stdClass; $formatoptions->para = false; $PAGE->set_context(context_system::instance()); if ($errmsg == '') { $text = format_text($texexp, FORMAT_MOODLE, $formatoptions); } else { $text = get_string('trivial_1', 'qtype_algebra', $errmsg); } ?> Formula additionalhtmlhead) && stripos($CFG->additionalhtmlhead, 'MathJax') !== false) { // For website where Mathjax is enabled using additional HTML in head. echo $CFG->additionalhtmlhead; } else { // For other website directly include MathJax. echo ""; } ?>