[Aimmath-commit] moodle/mod/math_assignment lib.php,1.14,1.15
Brought to you by:
gustav_delius,
npstrick
|
From: <gus...@us...> - 2003-09-20 14:49:10
|
Update of /cvsroot/aimmath/moodle/mod/math_assignment
In directory sc8-pr-cvs1:/tmp/cvs-serv20002/mod/math_assignment
Modified Files:
lib.php
Log Message:
removed pdf output function which is now in pdfgen.php
Index: lib.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/lib.php,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** lib.php 18 Sep 2003 23:57:57 -0000 1.14
--- lib.php 20 Sep 2003 14:49:06 -0000 1.15
***************
*** 777,876 ****
}
- function math_assignment_pdf($math_assignment, $course, $data, $solutions="true") {
- /// Function which extracts the latex from the AiM quiz page and converts it to pdf
- /// This is not yet complete. In particular figures are ignored.
- /// The strategy is:
- /// 1) use regexps to convert anything on the quiz page that
- /// we want to keep into latex,
- /// 2) collect all the latex together
- /// 3) pass it through pdflatex
-
- $latex = "\\documentclass[12pt]{article}\n
- \\usepackage{amsmath}\n
- \\begin{document}\n
- \\begin{center}
- {\\bf " . $course->fullname . ": " . $aim_quiz->name . "}
- \\end{center}";
-
- //echo htmlentities($data);
-
- // remove everything before the first question
- $data = preg_replace("/^[\s\S]*?(?=id=\"question)/",
- "",$data);
-
- if (!$solutions) {
- // remove all answers and solutions
- $data = preg_replace("/class=\"lastanswer\"[\s\S]*?((?=id=\"question)|$)/",
- "",$data);
- }
- else {
- // remove answers but keep solution
- //$data = preg_replace("/class=\"lastanswer\"[\s\S]*?((?=class=\"rightanswer)|$)/",
- // "<latex>\n\n\\noindent{\\bf Right Answer:}\n\n</latex>",$data);
- $data = preg_replace("/class=\"lastanswer/",
- "<latex>\n\n\\noindent{\\bf Your Answer: }</latex>",$data);
- $data = preg_replace("/Your last answer was ([A-Z])/",
- "<latex>$1</latex>",$data);
-
- $data = preg_replace("/class=\"rightanswer/",
- "<latex>\n\n\\noindent{\\bf Right Answer: }</latex>",$data);
- $data = preg_replace("/The correct answer is ([A-Z])/",
- "<latex>$1</latex>",$data);
-
- $data = preg_replace("/class=\"solution/",
- "<latex>\n\n\\noindent{\\bf Solution:}\n\n</latex>",$data);
- }
-
- // remove questionheaders including descriptions
- $data = preg_replace("/class=\"questionheader\"[\s\S]*?class=\"questionbody/",
- "",$data);
-
- // Questions
- $data = preg_replace("/id=\"question(\d+)\"/i",
- "<latex>\n\n\vspace{5mm}\\noindent{\\bf Question \$1:}\n\n</latex>",$data);
-
- // Parts
- $data = preg_replace("/id=\"question(\d+).(\d+)\"/i",
- "<latex>\n\n\vspace{2mm}\\noindent{\\bf Part \$2}\n\n</latex>",$data);
-
- // replace radio buttons
- $data = preg_replace("/(type=\"radio\"[^\/]*value=\")([A-Z])\"/",
- "<latex>\n\n {\bf $2 } </latex>",$data);
-
- // replace checkboxes by diamonds
- $data = preg_replace("/(type=\"checkbox\"[^\/]*value=\")([A-Z])\"/",
- "<latex>\n\n {\bf $2 } </latex>",$data);
-
- // delete AiM syntax hints (identified by \small)
- $data = preg_replace("/\\\\small[^}]*./",
- "",$data);
-
- // We might at some point want to replace input box by ....
- // preg_match_all("/<latex>([\s\S]*)?<\/latex>/", $data, $matches);
- // $latex .= implode(" ", $matches[0]);
-
- // extract anything inside <latex> ..</latex> and append it to $latex
- // this is not done elegantly, but who cares.
- $chunks = explode("</latex>",$data);
- array_pop($chunks);
- foreach ($chunks as $chunk) {
- preg_match("/(?<=<latex>)[\s\S]*$/","$chunk",$piece);
- $latex .= $piece[0];
- }
-
- $latex .= "\n\n\\end{document}";
-
- // Write latex to disk and then convert to pdf
- // The use of the temp file needs to be changed
- $fp=fopen("temp.tex","w");
- fwrite($fp,$latex);
- fclose($fp);
- exec("pdflatex -interaction=batchmode temp.tex");
-
- // The following should be changed to load temp.pdf into a separate window
- redirect("temp.pdf");
-
- return true;
- }
?>
--- 777,780 ----
|