/**
  * Replace any $...$ and $$...$$ delimiters in the question text from the
  * form with the recommended delimiters.
  * @param object $fromform the data from the form.
  */
 protected function fix_dollars_in_form_data($fromform)
 {
     $questionfields = array('questiontext', 'generalfeedback', 'specificfeedback', 'prtcorrect', 'prtpartiallycorrect', 'prtincorrect');
     foreach ($questionfields as $field) {
         $fromform->{$field}['text'] = stack_maths::replace_dollars($fromform->{$field}['text']);
     }
     $fromform->questionnote = stack_maths::replace_dollars($fromform->questionnote);
     $prtnames = stack_utils::extract_placeholders($fromform->questiontext['text'] . $fromform->specificfeedback['text'], 'feedback');
     foreach ($prtnames as $prt) {
         foreach ($fromform->{$prt . 'truefeedback'} as &$feedback) {
             $feedback['text'] = stack_maths::replace_dollars($feedback['text']);
         }
         foreach ($fromform->{$prt . 'falsefeedback'} as &$feedback) {
             $feedback['text'] = stack_maths::replace_dollars($feedback['text']);
         }
     }
     foreach ($fromform->hint as &$hint) {
         $hint['text'] = stack_maths::replace_dollars($hint['text']);
     }
 }
 /**
  * Update maths delimiters in one field of an object, outputting the before
  * and after HTML for review.
  * @param stdClass $question an object.
  * @param field $field the name of one of its fields.
  * @return boolean whether any change was made to the field.
  */
 public function fix_question_field($question, $field)
 {
     $newtext = stack_maths::replace_dollars($question->{$field});
     if ($newtext == $question->{$field}) {
         return false;
     }
     $markedup = stack_maths::replace_dollars($question->{$field}, '<ins>', '</ins>');
     echo html_writer::tag('p', stack_string('replacedollarsin', $field));
     echo html_writer::tag('pre', str_replace($this->search, $this->replace, s($markedup)), array('class' => 'questiontext'));
     echo html_writer::tag('div', stack_ouput_castext($newtext), array('class' => 'questiontext'));
     $question->{$field} = $newtext;
     return true;
 }
 public function fix_maths_delimiters($text)
 {
     return stack_maths::replace_dollars($text);
 }
    question_require_capability_on($questiondata, 'view');
}
$context = context_system::instance();
$PAGE->set_context($context);
$PAGE->set_url('/question/type/stack/caschat.php', $urlparams);
$title = stack_string('chattitle');
$PAGE->set_title($title);
$debuginfo = '';
$errs = '';
$varerrs = '';
$vars = optional_param('vars', '', PARAM_RAW);
$string = optional_param('cas', '', PARAM_RAW);
$simp = optional_param('simp', '', PARAM_RAW);
// Always fix dollars in this script.
// Very useful for converting existing text for use elswhere in Moodle, such as in pages of text.
$string = stack_maths::replace_dollars($string);
// Sort out simplification.
if ('on' == $simp) {
    $simp = true;
} else {
    $simp = false;
}
// Initially simplification should be on.
if (!$vars and !$string) {
    $simp = true;
}
if ($string) {
    $options = new stack_options();
    $options->set_site_defaults();
    $options->set_option('simplify', $simp);
    $session = new stack_cas_session(null, $options);