Hi Michitux,
I don't know how this work this work. I try but get something really weird. Here is the render class for mathjax
private static $ENVIRONMENTS = array(
"math",
"displaymath",
"equation",
"equation\*",
"eqnarray",
"eqnarray\*",
"align",
"align\*",
"flalign",
"flalign\*",
"alignat",
"alignat\*",
"multline",
"multline\*",
"gather",
"gather\*",
);
public function connectTo($mode) {
$this->Lexer->addEntryPattern('\$(?=[^\$][^\r\n]*?\$)',$mode,'plugin_mathjax_protecttex');
$this->Lexer->addEntryPattern('\$\$(?=.*?\$\$)',$mode,'plugin_mathjax_protecttex');
$this->Lexer->addEntryPattern('\\\\\((?=.*?\\\\\))',$mode,'plugin_mathjax_protecttex');
$this->Lexer->addEntryPattern('\\\\\[(?=.*?\\\\])',$mode,'plugin_mathjax_protecttex');
foreach (self::$ENVIRONMENTS as $env) {
$this->Lexer->addEntryPattern('\\\\begin{' . $env . '}(?=.*?\\\\end{' . $env . '})',$mode,'plugin_mathjax_protecttex');
}
}
public function postConnect() {
$this->Lexer->addExitPattern('\$(?=[^\$])','plugin_mathjax_protecttex');
$this->Lexer->addExitPattern('\\\\\)','plugin_mathjax_protecttex');
$this->Lexer->addExitPattern('\\\\\]','plugin_mathjax_protecttex');
foreach (self::$ENVIRONMENTS as $env) {
$this->Lexer->addExitPattern('\\\\end{' . $env . '}','plugin_mathjax_protecttex');
}
}
public function handle($match, $state, $pos, &$handler){
// Just pass it through...
return $match;
}
public function render($mode, &$renderer, $data) {
if($mode != 'xhtml') return false;
// Just pass it through, but escape xml entities...
$renderer->doc .= $renderer->_xmlEntities($data);
return true;
}
You will see that the code capture any patterns $ $, $$ $$, \begin{equation} \end{equation} and so on. All these patterns are LaTeX supported pattern or environment, mathjax doesn't require to wrap those LaTeX syntax with a special tag like they did in other plugins (e.g. in latex plugin, they wrap everything as <latex></latex>; in dokutexit, everything wrapped in <texit></textit>)
I like the way mathjax go because I don't have to type additional wrapper. Now my question is: dokutexit only interpret those latex syntax within <texit> </texit> tag, so I either modify mathjax to add additional tag or modify dokutexit to support mathjax's syntax. I think the first one is easier. That's how you propose the idea, doesn't it?
To my understanding (sorry I don't know much about programming), you suggest to modify the mathjax's render function as
public function render($mode, &$renderer, $data) {
if($mode == 'xhtml') {
$renderer->doc .= $renderer->_xmlEntities($data);
return true;
}
if($mode == 'latex') {
$renderer->doc .= "<texit>".$data."</texit>";
return true;
}
return false;
}
I guess $mode=='latex' mean it is dokutexit's turn to take over the renderer, am I correct? So here I wrap the latex stuff and the dokutexit will be able to see that later. But it gives me something really weird while I trace the output. For example, if I do the above trick on the following wiki page with content
<texit info>
title=Just a demo ...
</texit>
Since,
\begin{equation}
a=b^2 + 2
\end{equation}
Therefore,
\begin{equation}
x^2 + a = \int_{-\infty}^{+\infty}y^2dy + \text{const}
\end{equation}
it will show something odd in the PDF though the math will be generated correctly. The capture is shown here
http://postimage.org/image/5azkjj5pn/
if I manually add the <texit> tag
<texit info>
title=Just a demo ...
</texit>
Since,
<texit>
\begin{equation}
a=b^2 + 2
\end{equation}
Therefore,
\begin{equation}
x^2 + a = \int_{-\infty}^{+\infty}y^2dy + \text{const}
\end{equation}
</texit>
everything shown in the pdf looks perfect but the wiki page will not show anything of the math by mathjax. The capture is shown here
http://postimage.org/image/d54rio2wb/
My purpose is to make the first way work because I don't want to add extra tag while typing.