[dokuwiki] DokuWiki and LatexRender

  • From: Jan Tammen <jan@xxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Fri, 13 May 2005 21:00:37 +0200

Bonjour.

As I tried to show here [1] (sorry for that shameless advertising ;),
one can easily integrate LatexRender [2] with DokuWiki in order to
render LaTeX formulas (or anything else you do with LaTeX) to images and
stuffing them into your wiki-pages.

Now with the new renderer the hack does not work anymore, of course. So
I'm currently trying to rewrite the instructions so that it will work
with the new release.
Maybe you could give me some hints whether I'm on the right way and not
mis-using the new parser-concept (actually I would be happy if this
'extension' would lose its kind of "dirty-hack"-state ;)

Here's what I did (additionally to the setup of LatexRender, see [1]):

1) Added a method to Doku_Handler, parser/handler.php:
function latex($match, $state, $pos) {
    if ( $state == DOKU_LEXER_UNMATCHED ) {
        $this->_addCall('latex', array($match), $pos);
    }
    return TRUE;
}

2) Added a class to parser/parser.php:
class Doku_Parser_Mode_LaTeX extends Doku_Parser_Mode {
    function connectTo($mode) {
        $this->Lexer->addEntryPattern('<latex>(?=.*\x3C/latex\x3E)',
                                      $mode,
                                      'latex');
    }

    function postConnect() {
        $this->Lexer->addExitPattern('</latex>','latex');
    }
}

4) Added a method to Doku_Renderer, parser/renderer.php:
function latex($text) {}

3) Added a method to Doku_Renderer_xhtml, parser/xhtml.php:
function latex($text) {
    global $conf;
    if ($conf['latexok']) {
        // Render image and get result-path
        include_once($conf['latexdir'] . '/latex.php');
        // this is LatexRender-specific
        $result = latex_content("<tex>".$text."</tex>");

        $this->doc .= $result;
    } else {
        $this->file($result);
    }
}

Actually this seems to work quite good already, although there's one
problem left: <latex>-tags placed inline are not recognized yet (which
is probably due to some missing stuff in Doku_Handler::latex() ?).

Greets & thanks for any comments,
Jan.

[1] http://setiwiki.tammen.net/latexrender
[2] http://www.mayer.dial.pipex.com/tex.htm#latexrender

-- 
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: