[Aimmath-commit] moodle/mod/aim_quiz lib.php,1.8,1.9
Brought to you by:
gustav_delius,
npstrick
From: <gus...@us...> - 2003-09-09 01:52:59
|
Update of /cvsroot/aimmath/moodle/mod/aim_quiz In directory sc8-pr-cvs1:/tmp/cvs-serv25709/mod/aim_quiz Modified Files: lib.php Log Message: update of AiM to pdf conversion Index: lib.php =================================================================== RCS file: /cvsroot/aimmath/moodle/mod/aim_quiz/lib.php,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** lib.php 6 Sep 2003 08:24:25 -0000 1.8 --- lib.php 8 Sep 2003 17:55:38 -0000 1.9 *************** *** 218,223 **** // set LaTeX output mode required ! if (!function_exists('editer')) ! $mathdisplay = "html"; $postdata= aim_quiz_add_arg_to_url_data($postdata, "MathDisplay", $mathdisplay); set_time_limit(240); --- 218,222 ---- // set LaTeX output mode required ! $postdata= aim_quiz_add_arg_to_url_data($postdata, "MathDisplay", $mathdisplay); set_time_limit(240); *************** *** 516,522 **** } ! function aim_quiz_pdf($aim_quiz, $course, $data) { /// Function which extracts the latex from the AiM quiz page and converts it to pdf ! /// This is not yet complete /// The strategy is: /// 1) use regexps to convert anything on the quiz page that --- 515,521 ---- } ! function aim_quiz_pdf($aim_quiz, $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 *************** *** 526,529 **** --- 525,529 ---- $latex = "\\documentclass[12pt]{article}\n + \\usepackage{amsmath}\n \\begin{document}\n \\begin{center} *************** *** 531,546 **** \\end{center}"; // remove everything before the first question $data = preg_replace("/^[\s\S]*?(?=id=\"question)/", "",$data); ! ! // remove all answers and solutions ! $data = preg_replace("/class=\"lastanswer\"[\s\S]*?((?=id=\"question)|$)/", ! "",$data); ! // remove questionheaders including descriptions $data = preg_replace("/class=\"questionheader\"[\s\S]*?class=\"questionbody/", ! "",$data); ! // Questions $data = preg_replace("/id=\"question(\d+)\"/i", --- 531,567 ---- \\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", *************** *** 549,562 **** // Parts $data = preg_replace("/id=\"question(\d+).(\d+)\"/i", ! "<latex>\n\n\vspace{2mm}{\\bf Part \$2}\n\n</latex>",$data); ! // replace radio buttons by circles ! $data = preg_replace("/(type=\"radio\"[^\/]*value=\")[A-Z]\"/", ! "<latex>\n\n $\circ$ </latex>",$data); // replace checkboxes by diamonds ! $data = preg_replace("/(type=\"checkbox\"[^\/]*value=\")[A-Z]\"/", ! "<latex>\n\n $\diamond$ </latex>",$data); ! // replace input box by .... // preg_match_all("/<latex>([\s\S]*)?<\/latex>/", $data, $matches); // $latex .= implode(" ", $matches[0]); --- 570,588 ---- // 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]); *************** *** 572,587 **** $latex .= "\n\n\\end{document}"; $fp=fopen("temp.tex","w"); fwrite($fp,$latex); fclose($fp); ! // The next step is to call pdflatex to convert the latex to pdf ! // Unfortunately I have the problem that PHP hangs after executing ! // any command using exec or similar. ! // Does anyone know a solution? Is it a problem with the particular ! // version of PHP or apache that I am using? - // $latexoutput = system("pdflatex -interaction=batchmode temp.tex"); - // exec(cmd); return true; } --- 598,612 ---- $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; } |