Exemple #1
0
function latexAppendQuestion($name, $desc, $type, $answer)
{
    $typeArray = getTypeArray($type);
    $question_string = "";
    if ($typeArray['type'] == "text") {
        if ($name != "") {
            $question_string .= '\\textbf{' . latexSpecialChars($name) . '}';
            //add main in bold
        }
        if ($desc != "") {
            if ($name != "") {
                $question_string .= '\\newline';
            }
            $question_string .= '\\emph{' . latexSpecialChars($desc) . '}';
            //add description in italics
        }
        $question_string .= '\\newline\\newline';
        return $question_string;
    } else {
        if ($typeArray['type'] == "latex") {
            $question_string .= $desc;
            return $question_string;
        } else {
            if ($typeArray['type'] == "code") {
                $question_string .= '\\text{' . get_html_to_latex(page_convert($desc)) . '}';
                return $question_string;
            } else {
                if ($typeArray['type'] == "repeat") {
                    $num = $typeArray['num'];
                    $subtype_array = explode("|", $typeArray['subtype']);
                    $desc_array = explode("|", $desc);
                    $name_array = explode("|", $name);
                    if ($answer != '') {
                        $answer_array = toArray($answer, "|", "=");
                    } else {
                        $answer_array = array_fill(0, count($name_array) * $num, '');
                    }
                    //find minimum length, which will be the number to repeat for
                    $min_length = min(count($subtype_array), count($desc_array), count($name_array));
                    for ($i = 0; $i < $min_length * $num; $i++) {
                        $index = $i % $min_length;
                        $n = intval($i / $min_length);
                        $thisName = getRepeatThisValue($name_array, $index, $n);
                        $thisDesc = getRepeatThisValue($desc_array, $index, $n);
                        $thisType = str_replace(",", ";", getRepeatThisValue($subtype_array, $index, $n));
                        $question_string .= latexAppendQuestion($thisName, $thisDesc, $thisType, $answer_array[$i]);
                    }
                } else {
                    if ($name != "") {
                        $question_string .= '\\textbf{' . latexSpecialChars($name) . '}';
                        //add question in bold
                    }
                    //add description (in bold) for essays and short answer
                    if (($typeArray['type'] == "essay" || $typeArray['type'] == "short") && $desc != "") {
                        if ($name != "") {
                            $question_string .= '\\newline';
                        }
                        $question_string .= '\\emph{' . latexSpecialChars($desc) . '}';
                        //add description in italics
                    }
                    //add a separator depending on main type of the question
                    if ($typeArray['type'] == "essay") {
                        $question_string .= "\n\n";
                    }
                    if ($typeArray['type'] == "select" && $typeArray['method'] != "dropdown") {
                        //in this case, we add tick marks and check the correct ones
                        $choices = explode(";", $desc);
                        //get answer as array in case we're using multiple selection
                        $config = $GLOBALS['config'];
                        $answerArray = explode($config['form_array_delimiter'], $answer);
                        //this is used to indent the answer choices
                        $question_string .= "\n\\begin{quote}\n";
                        //output each choice with check box before it on a separate line in the quote
                        for ($i = 0; $i < count($choices); $i++) {
                            $choice = $choices[$i];
                            if ($i != 0) {
                                $question_string .= "\\\\\n ";
                            }
                            if (in_array($choice, $answerArray)) {
                                $question_string .= '\\xbox';
                            } else {
                                $question_string .= '\\tickbox';
                            }
                            $question_string .= " \\hspace{4pt} " . latexSpecialChars($choice);
                        }
                        $question_string .= "\\end{quote}";
                    } else {
                        //append the response
                        if ($typeArray['type'] == "essay") {
                            if ($answer != "") {
                                $question_string .= '\\begin{quote} ' . latexSpecialChars($answer) . '\\end{quote}';
                            } else {
                                $question_string .= '\\vspace{5ex}';
                            }
                        } else {
                            if ($answer != "") {
                                $question_string .= '\\begin{quote} ' . latexSpecialChars($answer) . ' \\end{quote}';
                            } else {
                                $question_string .= '\\vspace{1ex}';
                            }
                        }
                    }
                    $question_string .= "\n\n";
                }
            }
        }
    }
    return $question_string;
}
Exemple #2
0
function html_to_latex($html)
{
    echo get_html_to_latex($html);
}