From 96bee2b33467a1ce54f88c77b8a867ef1f7a9a97 Mon Sep 17 00:00:00 2001 From: Jean-Michel Vedrine Date: Sun, 9 Sep 2012 16:54:35 +0200 Subject: First version of algebra question type initially written by Roger Moore for Moodle 2.3 --- displayformula.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 displayformula.php (limited to 'displayformula.php') diff --git a/displayformula.php b/displayformula.php new file mode 100644 index 0000000..e5051e5 --- /dev/null +++ b/displayformula.php @@ -0,0 +1,48 @@ + +// License: GNU Public License version 3 + +/** + * Script which converts the given formula text into LaTeX code and then + * displays the appropriate image file. It relies on the LaTeX filter to + * be present. + */ + +require_once('../../../config.php'); +require_once("$CFG->dirroot/question/type/algebra/parser.php"); +global $PAGE; + +$p = new qtype_algebra_parser; +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().'$$'; + } +} catch(Exception $e) { + $texexp = get_string('parseerror','qtype_algebra',$e->getMessage()); +} +$formatoptions = new stdClass; +$formatoptions->para = false; +$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$text = format_text($texexp, FORMAT_MOODLE, $formatoptions); +?> + + + Formula + + + + + + -- cgit v1.2.3