Ejemplo n.º 1
0
 function render()
 {
     list($success, $res) = $this->invokeBlahtex($this->mr->tex, $this->mr->hash == null);
     if (!$success) {
         $this->errmsg = $res;
     } else {
         $parser = new blahtexOutputParser();
         $output = $parser->parse($res);
         $blahtexErrmsg = $this->processOutput($output);
         if ($blahtexErrmsg && $this->errmsg) {
             $this->errmsg = $blahtexErrmsg;
         } else {
             $this->errmsg = '';
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Main function, which renders the LaTeX fragment.
  * This function renders the LaTeX fragment specified in the
  * constructor. The output depends on the output mode, set with
  * setOutputMode(), as follows:
  *  - @c MW_MATH_PNG : Output is in PNG format, fall back to HTML.
  *  - @c MW_MATH_SIMPLE : Output is in HTML format if the HTML is
  *       simple and in PNG otherwise.
  *  - @c MW_MATH_HTML : Output is in HTML format, fall back to PNG.
  *  - @c MW_MATH_SOURCE : Output the LaTeX fragment verbatim,
  *       surrounded by a pair of @c $ characters.
  *  - @c MW_MATH_MODERN : Output is in HTML format unless the HTML
  *       is complicated, fall back to PNG.
  *  - @c MW_MATH_MATHML : Output is in MathML format, fall back to
  *       PNG.
  *
  * @return String containing HTML fragment, representing the
  * formula in the given LaTeX fragment.
  * @public
  */
 function render()
 {
     global $wgBlahtex;
     $fname = 'MathRenderer::render';
     if ($this->mode == MW_MATH_SOURCE) {
         # No need to render or parse anything more!
         return '$ ' . htmlspecialchars($this->tex) . ' $';
     }
     if (!$this->_recall()) {
         $res = $this->testEnvironment();
         if ($res) {
             return $res;
         }
         // Run texvc
         list($success, $res) = $this->invokeTexvc($this->tex);
         if (!$success) {
             return $res;
         }
         $texvcError = $this->processTexvcOutput($res);
         // Run blahtex, if configured
         if ($wgBlahtex) {
             list($success, $res) = $this->invokeBlahtex($this->tex, $this->hash == NULL);
             if (!$success) {
                 return $res;
             }
             $parser = new blahtexOutputParser();
             $res = $parser->parse($res);
             wfDebug(print_r($res, TRUE));
             $blahtexError = $this->processBlahtexOutput($res);
             if ($blahtexError && $texvcError) {
                 return $blahtexError;
             }
         } else {
             if ($texvcError) {
                 return $texvcError;
             }
         }
         # Now save it back to the DB:
         if (!wfReadOnly()) {
             if ($this->hash) {
                 $outmd5_sql = pack('H32', $this->hash);
             } else {
                 $outmd5_sql = '';
             }
             $md5_sql = pack('H32', $this->md5);
             # Binary packed, not hex
             $dbw =& wfGetDB(DB_MASTER);
             $dbw->replace('math', array('math_inputhash'), array('math_inputhash' => $md5_sql, 'math_outputhash' => $outmd5_sql, 'math_html_conservativeness' => $this->conservativeness, 'math_html' => $this->html, 'math_mathml' => $this->mathml), $fname, array('IGNORE'));
         }
     }
     return $this->_doRender();
 }