/**
  * This function actually evaluates the castext.
  */
 private function instantiate()
 {
     if (!$this->valid) {
         return false;
     }
     // Deal with castext without any CAS variables.
     if (null !== $this->session) {
         $this->session->instantiate();
         $this->errors .= $this->session->get_errors();
     }
     $this->castext = stack_utils::wrap_around($this->trimmedcastext);
     if (null !== $this->session) {
         $this->castext = $this->session->get_display_castext($this->castext);
     }
     // Another modification. Stops <html> tags from being given $ tags.
     $this->castext = str_replace('\\(<html>', '', $this->castext);
     // Bug occurs when maxima returns <html>tags in output, eg plots or div by 0 errors.
     $this->castext = str_replace('</html>\\)', '', $this->castext);
     $this->latex_tidy();
     $this->instantiated = true;
 }