<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I hate to be a downer, but having implemented latex + wiki several times (ZWiki,<br>
jsMath+TiddlyWiki, etc), I can tell you that this solution is a hack that will<br>
fail eventually.  For that matter, it appears that Pagedown itself is a hack<br>
too, that will have bad edge cases.  (In other words it is a pile of<br>
successively applied regular expressions, in which one hopes there are not<br>
overlapping cases -- rather than a grammar which has no overlapping cases by<br>
definition)<br></blockquote><div><br></div><div>The original MarkDown was implemented in Perl and was almost certainly a pile of successively applied regular expressions.  I agree that we get much nicer stuff with a proper parser, but somebody has to support it.  I don't think I have anything against Markdown-js if the IPython developers decide to switch to it (or somebody implements it in the notebook).</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The correct solution to this problem is therefore to use a true grammar that<br>
involves an escape.  Since latex uses the backslash its escape character, and so<br>
does markdown, this seems naively easy, but one must hook into to markdown's<br>
processing stream, and call MathJax from it, rather than invoking two<br>
independent processing sessions (markdown followed by MathJax or v/v).<br></blockquote><div><br></div><div>This isn't that hard.  The document's grammar is in Markdown or LaTeX blocks.  The grammar becomes LaTeX whenever we enter a math-delimited region.  Markdown is NOT allowed in a LaTeX region, and LaTeX is NOT allowed in a Markdown region.  The important thing is to properly decompose the text into Markdown-formatted text and LaTeX-formated text, and hide the LaTeX from the Markdown processor (MathJaX confines itself to its delimited regions).</div>
<div><br></div><div>The way SE does it (which I shamelessly copied), is to pull out all blocks that are either delimited with classic TeX delimiters or contain anything between $ $ that is not in a code block.  This effectively reserves all of the major TeX environment delimiters within Markdown blocks ($$, \[, \begin, etc., ...), which I think most people can live with.</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Markdown-js: <a href="https://github.com/evilstreak/markdown-js" target="_blank">https://github.com/evilstreak/markdown-js</a> appears to be a much<br>
better written parser than Pagedown, in which inserting an extra rule for math,<br>
and calling MathJax would be straightforward (disabling MathJax's document<br>
parsing).<br></blockquote><div><br></div><div>I don't see anything wrong with this approach.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Correct me if I'm wrong, but this penchant for writing functions that generate<br>
classes that everyone is using basically makes it impossible to use inheritance<br>
to extend a Markdown parser.  (I don't understand why iPython, Markdown-js, and<br>
everyone in the known universe has decided this is The Way to write everything<br>
-- maybe someone can enlighten me)  </blockquote><div><br></div><div>functions and classes are first-class objects in Python and Javascript.  You can modify a class or object's function after it has been instantiated without inheriting.  I think this is a separate discussion, though.</div>
<div><br></div><div>-A</div></div>